FIX compatibility with multicompany sharings

This commit is contained in:
Regis Houssin 2022-04-21 14:52:06 +02:00
parent ad7fcd264b
commit 8878eb6d76
2 changed files with 8 additions and 5 deletions

View File

@ -125,14 +125,14 @@ class mod_project_simple extends ModeleNumRefProjects
*/
public function getNextValue($objsoc, $project)
{
global $db, $conf;
global $db;
// First, we get the max value
$posindice = strlen($this->prefix) + 6;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql .= " FROM ".MAIN_DB_PREFIX."projet";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
$sql .= " AND entity = ".$conf->entity;
$sql .= " AND entity IN (".getEntity('projectnumber', 1, $project).")";
$resql = $db->query($sql);
if ($resql) {
@ -147,7 +147,7 @@ class mod_project_simple extends ModeleNumRefProjects
return -1;
}
$date = empty($project->date_c) ?dol_now() : $project->date_c;
$date = (empty($project->date_c) ? dol_now() : $project->date_c);
//$yymm = strftime("%y%m",time());
$yymm = strftime("%y%m", $date);

View File

@ -136,8 +136,11 @@ class mod_project_universal extends ModeleNumRefProjects
return 0;
}
$date = empty($project->date_c) ?dol_now() : $project->date_c;
$numFinal = get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc->code_client : ''), $date);
// Get entities
$entity = getEntity('projectnumber', 1, $project);
$date = (empty($project->date_c) ? dol_now() : $project->date_c);
$numFinal = get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc : ''), $date, 'next', false, null, $entity);
return $numFinal;
}