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;
68 public function info($langs)
71 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
82 return $this->prefix.
"0501-0001";
94 global $conf, $langs, $db;
99 $posindice = strlen($this->prefix) + 6;
100 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
101 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
102 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
103 $sql .=
" AND entity = ".$conf->entity;
105 $resql = $db->query($sql);
107 $row = $db->fetch_row($resql);
109 $coyymm = substr($row[0], 0, 6);
113 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
114 $langs->load(
"errors");
115 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
133 $posindice = strlen($this->prefix) + 6;
134 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
135 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
136 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
137 $sql .=
" AND entity = ".$conf->entity;
139 $resql = $db->query($sql);
141 $obj = $db->fetch_object($resql);
143 $max = intval($obj->max);
148 dol_syslog(
"mod_contract_serpis::getNextValue", LOG_DEBUG);
152 $date = $contract->date_contrat;
155 if ($max >= (pow(10, 4) - 1)) {
158 $num = sprintf(
"%04s", $max + 1);
161 dol_syslog(
"mod_contract_serpis::getNextValue return ".$this->prefix.$yymm.
"-".$num);
162 return $this->prefix.$yymm.
"-".$num;
Parent class for all contract numbering modules.
Class to manage contract numbering rules Serpis.
info($langs)
Return default description of numbering model.
contract_get_num($objsoc, $objforref)
Return next value.
getExample()
Return numbering example.
getNextValue($objsoc, $contract)
Return next value.
canBeActivated($object)
Test if existing numbers make problems with numbering.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
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.