28require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/modules_project.php';
40 public $version =
'dolibarr';
45 public $prefix =
'PJ';
55 public $position = 10;
60 public $name =
'Simple';
70 public function info($langs)
73 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
84 return $this->prefix.
"0501-0001";
97 global
$conf, $langs, $db;
102 $posindice = strlen($this->prefix) + 6;
103 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".((int) $posindice).
") AS SIGNED)) as max";
104 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
105 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
106 $sql .=
" AND entity = ".((int)
$conf->entity);
107 $resql = $db->query($sql);
109 $row = $db->fetch_row($resql);
111 $coyymm = substr($row[0], 0, 6);
115 if (!$coyymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
118 $langs->load(
"errors");
119 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
137 $posindice = strlen($this->prefix) + 6;
138 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".((int) $posindice).
") AS SIGNED)) as max";
139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
140 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
141 $sql .=
" AND entity IN (".getEntity(
'projectnumber', 1, $project).
")";
143 $resql = $db->query($sql);
145 $obj = $db->fetch_object($resql);
147 $max = intval($obj->max);
152 dol_syslog(
"mod_project_simple::getNextValue", LOG_DEBUG);
156 $date = (empty($project->date_c) ?
dol_now() : $project->date_c);
162 if ($max >= (pow(10, 4) - 1)) {
165 $num = sprintf(
"%04d", $max + 1);
168 dol_syslog(
"mod_project_simple::getNextValue return ".$this->prefix.$yymm.
"-".$num);
169 return $this->prefix.$yymm.
"-".$num;
if(! $sortfield) if(! $sortorder) $object
Class parent for numbering modules of tasks.
Class to manage the numbering module Simple for project references.
info($langs)
Return description of numbering module.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getExample()
Return an example of numbering module values.
getNextValue($objsoc, $project)
Return next value.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.