24require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
35 public $version =
'dolibarr';
37 public $prefix =
'CT';
49 public $nom =
'Serpis';
54 public $name =
'Serpis';
59 public $code_auto = 1;
70 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
81 return $this->prefix.
"0501-0001";
92 global $conf, $langs, $db;
97 $posindice = strlen($this->prefix) + 6;
98 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
99 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
100 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
101 $sql .=
" AND entity = ".$conf->entity;
103 $resql = $db->query($sql);
105 $row = $db->fetch_row($resql);
107 $coyymm = substr($row[0], 0, 6);
111 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.
"contrat";
134 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
135 $sql .=
" AND entity = ".$conf->entity;
137 $resql = $db->query($sql);
139 $obj = $db->fetch_object($resql);
141 $max = intval($obj->max);
146 dol_syslog(
"mod_contract_serpis::getNextValue", LOG_DEBUG);
150 $date = $contract->date_contrat;
151 $yymm = strftime(
"%y%m", $date);
153 if ($max >= (pow(10, 4) - 1)) {
156 $num = sprintf(
"%04s", $max + 1);
159 dol_syslog(
"mod_contract_serpis::getNextValue return ".$this->prefix.$yymm.
"-".$num);
160 return $this->prefix.$yymm.
"-".$num;
Parent class for all contract numbering modules.
Class to manage contract numbering rules Serpis.
canBeActivated()
Test if existing numbers make problems with numbering.
contract_get_num($objsoc, $objforref)
Return next value.
info()
Return default description of numbering model.
getExample()
Return numbering example.
getNextValue($objsoc, $contract)
Return next value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.