26require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
34 public $name =
'Serpis';
36 public $version =
'dolibarr';
41 public $position = 10;
48 public $prefix =
'CT';
64 public function info($langs)
67 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
78 return $this->prefix.
"0501-0001";
90 global
$conf, $langs, $db;
95 $posindice = strlen($this->prefix) + 6;
96 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".((int) $posindice).
") AS SIGNED)) as max";
97 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
98 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
99 $sql .=
" AND entity = ".((int)
$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)) {
110 $langs->load(
"errors");
111 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
129 $posindice = strlen($this->prefix) + 6;
130 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".((int) $posindice).
") AS SIGNED)) as max";
131 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
132 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
133 $sql .=
" AND entity = ".((int)
$conf->entity);
135 $resql = $db->query($sql);
137 $obj = $db->fetch_object($resql);
139 $max = intval($obj->max);
144 dol_syslog(
"mod_contract_serpis::getNextValue", LOG_DEBUG);
148 $date = $contract->date_contrat;
151 if ($max >= (pow(10, 4) - 1)) {
154 $num = sprintf(
"%04d", $max + 1);
157 dol_syslog(
"mod_contract_serpis::getNextValue return ".$this->prefix.$yymm.
"-".$num);
158 return $this->prefix.$yymm.
"-".$num;
if(! $sortfield) if(! $sortorder) $object
Parent class for all contract numbering modules.
Class to manage contract numbering rules Serpis.
info($langs)
Return default description of numbering model.
getExample()
Return numbering example.
getNextValue($objsoc, $contract)
Return next value.
canBeActivated($object)
Test if existing numbers make problems with numbering.
__construct()
Constructor.
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.