Task numbering

Is it posible to add a ‘Project Ref’. tag, in your ‘Tasks numbering module’ ?
“On this way you can see from the task reference to what project it belongs”

Maybe there is a special tag for this?

EXAMPLE: [PROJECT REF]-{000}

Ver. Dolibarr 4.0.4

This is something I’m also very interested into.
My projects are numbered {yy}_{000@1}, so for example “18_025”

I would need my tasks to be numbered “18_025_001”, “18_025_002” and so on… then “18_026_001” etc.

Is there someone who can help?

Many thanks.

+1
I need for the same things. PR101-# where # is the task number and resets for each referenced project…

Hoping this can help someone, I’ve finally been able to sort out this issue.
I created a new task numbering module by slightly modifying an existing one as follows.
The next lines are the whole getNextValue function.

They need to be customized on the specific project and task pattern requirements.

Assuming you are creating the task from the project page, the solution is getting the project number with:

$id = GETPOST('id', 'int'); // Getting the project id
		
$sql = "SELECT ref";
$sql.= " FROM ".MAIN_DB_PREFIX."projet";
$sql.= " WHERE rowid=".$id;

$resql=$db->query($sql);
$obj = $db->fetch_object($resql);
$prjref = $obj->ref;
	
if ($prjref=="") $prjref="00_000";

The last line is needed in case the task is created through the “New task” without being in a specific process.
Pretty useless but it maintains the same numbering scheme by using a generic project “00_000”.

Then we can look for the highest existing number for that project with:

$posindice=10;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task";
$sql.= " WHERE ref like '".$this->prefix.$prjref."_%'";

$resql=$db->query($sql);

if ($resql)
{
	$obj = $db->fetch_object($resql);
	if ($obj) $max = intval($obj->max);
	else $max=0;
}
else
{
	dol_syslog("mod_task_ipeprogetti::getNextValue", LOG_DEBUG);
	return -1;
}

and then generate the new task number:

		
if ($max >= (pow(10, 3) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
else $num = sprintf("%03s",$max+1);

// We've got all the data to output the new task number

dol_syslog("mod_task_ipeprogetti::getNextValue return ".$this->prefix.$prjref."_".$num);
return $this->prefix.$prjref."_".$num;

The same procedure can be adopted for other modules. For instance, I created a very similar numbering module for the orders.

2 Likes

Thank you for the info. I think this might be beyond what I am able to do at the moment as I only suceded in getting my project module page to stop loading. For those who are fluent in php I suspect it’s a breeze however.