39 public $version =
'dolibarr';
45 public $prefix =
'TC';
56 public $nom =
'Simple';
67 $textinfo = $langs->trans(
'SimpleNumRefModelDesc', $this->prefix.
'0-');
68 $textinfo .=
'<br>'.$langs->trans(
'EachTerminalHasItsOwnCounter');
80 return $this->prefix.
'0-0501-0001';
91 global $conf, $langs, $db;
99 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
101 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
102 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
103 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
104 $sql .=
" AND entity = ".$conf->entity;
106 $resql = $db->query($sql);
108 $row = $db->fetch_row($resql);
110 $pryymm = substr($row[0], 0, 6);
115 if (!$pryymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $pryymm)) {
118 $langs->load(
"errors");
119 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
135 public function getNextValue($objsoc =
null, $invoice =
null, $mode =
'next')
139 $pos_source = is_object($invoice) && $invoice->pos_source > 0 ? $invoice->pos_source : 0;
142 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
143 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
144 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
145 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
146 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
149 $resql = $db->query($sql);
151 $obj = $db->fetch_object($resql);
153 $max = intval($obj->max);
158 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
162 if ($mode ==
'last') {
163 if ($max >= (pow(10, 4) - 1)) {
166 $num = sprintf(
"%04s", $max);
170 $sql =
"SELECT ref as ref";
171 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
172 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-".$num).
"'";
173 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
174 $sql .=
" ORDER BY ref DESC";
176 $resql = $db->query($sql);
178 $obj = $db->fetch_object($resql);
187 } elseif ($mode ==
'next') {
188 $date = $invoice->date;
189 $yymm = strftime(
"%y%m", $date);
191 if ($max >= (pow(10, 4) - 1)) {
194 $num = sprintf(
"%04s", $max + 1);
197 dol_syslog(get_class($this).
"::getNextValue return ".$this->prefix.$pos_source.
'-'.$yymm.
'-'.$num);
198 return $this->prefix.$pos_source.
'-'.$yymm.
'-'.$num;
Classe mere des modeles de numerotation des tickets de caisse.
Class to manage ref numbering of takepos cards with rule Simple.
getNextValue($objsoc=null, $invoice=null, $mode='next')
Return next value.
canBeActivated()
Test if the numbers already in the database do not cause any conflicts that will prevent this of conf...
info()
Return description of numbering module.
getNumRef($objsoc, $objforref)
Return next free value.
getExample()
Return an example of numbering module values.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.