26 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/modules_project.php';
38 public $version =
'dolibarr';
40 public $prefix =
'PJ';
52 public $nom =
'Simple';
57 public $name =
'Simple';
68 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
79 return $this->prefix.
"0501-0001";
91 global $conf, $langs, $db;
96 $posindice = strlen($this->prefix) + 6;
97 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
98 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
99 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
100 $sql .=
" AND entity = ".$conf->entity;
101 $resql = $db->query($sql);
103 $row = $db->fetch_row(
$resql);
105 $coyymm = substr($row[0], 0, 6);
109 if (!$coyymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
112 $langs->load(
"errors");
113 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
131 $posindice = strlen($this->prefix) + 6;
132 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
133 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
134 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
135 $sql .=
" AND entity IN (".getEntity(
'projectnumber', 1, $project).
")";
137 $resql = $db->query($sql);
139 $obj = $db->fetch_object(
$resql);
141 $max = intval($obj->max);
146 dol_syslog(
"mod_project_simple::getNextValue", LOG_DEBUG);
150 $date = (empty($project->date_c) ?
dol_now() : $project->date_c);
153 $yymm = strftime(
"%y%m", $date);
155 if ($max >= (pow(10, 4) - 1)) {
158 $num = sprintf(
"%04s", $max + 1);
161 dol_syslog(
"mod_project_simple::getNextValue return ".$this->prefix.$yymm.
"-".$num);
162 return $this->prefix.$yymm.
"-".$num;