26require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
34 public $name =
'Serpis';
35 public $version =
'dolibarr';
42 public $prefix =
'CT';
58 public function info($langs)
61 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
72 return $this->prefix.
"0501-0001";
84 global $conf, $langs, $db;
89 $posindice = strlen($this->prefix) + 6;
90 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
91 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
92 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
93 $sql .=
" AND entity = ".$conf->entity;
95 $resql = $db->query($sql);
97 $row = $db->fetch_row($resql);
99 $coyymm = substr($row[0], 0, 6);
103 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
104 $langs->load(
"errors");
105 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
123 $posindice = strlen($this->prefix) + 6;
124 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
126 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
127 $sql .=
" AND entity = ".$conf->entity;
129 $resql = $db->query($sql);
131 $obj = $db->fetch_object($resql);
133 $max = intval($obj->max);
138 dol_syslog(
"mod_contract_serpis::getNextValue", LOG_DEBUG);
142 $date = $contract->date_contrat;
145 if ($max >= (pow(10, 4) - 1)) {
148 $num = sprintf(
"%04d", $max + 1);
151 dol_syslog(
"mod_contract_serpis::getNextValue return ".$this->prefix.$yymm.
"-".$num);
152 return $this->prefix.$yymm.
"-".$num;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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)
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.