26require_once DOL_DOCUMENT_ROOT.
'/core/modules/ticket/modules_ticket.php';
37 public $version =
'dolibarr';
39 public $prefix =
'TS';
51 public $nom =
'Simple';
56 public $name =
'Simple';
66 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
76 return $this->prefix.
"0501-0001";
87 global $conf, $langs, $db;
92 $posindice = strlen($this->prefix) + 6;
93 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
95 $search = $this->prefix.
"____-%";
96 $sql .=
" WHERE ref LIKE '".$db->escape($search).
"'";
97 $sql .=
" AND entity = ".$conf->entity;
98 $resql = $db->query($sql);
100 $row = $db->fetch_row($resql);
102 $coyymm = substr($row[0], 0, 6);
106 if (!$coyymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
109 $langs->load(
"errors");
110 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
127 $posindice = strlen($this->prefix) + 6;
128 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
130 $search = $this->prefix.
"____-%";
131 $sql .=
" WHERE ref LIKE '".$db->escape($search).
"'";
132 $sql .=
" AND entity IN (".getEntity(
'ticketnumber', 1, $ticket).
")";
134 $resql = $db->query($sql);
136 $obj = $db->fetch_object($resql);
138 $max = intval($obj->max);
143 dol_syslog(
"mod_ticket_simple::getNextValue", LOG_DEBUG);
147 $date = empty($ticket->datec) ?
dol_now() : $ticket->datec;
152 if ($max >= (pow(10, 4) - 1)) {
156 $num = sprintf(
"%04s", $max + 1);
159 dol_syslog(
"mod_ticket_simple::getNextValue return ".$this->prefix.$yymm.
"-".$num);
160 return $this->prefix.$yymm.
"-".$num;
Classe mere des modeles de numerotation des references de projets.
Class to manage the numbering module Simple for ticket references.
getExample()
Return an example of numbering module values.
getNextValue($objsoc, $ticket)
Return next value.
info()
Return description of numbering module.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
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_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.