39 public $version =
'dolibarr';
45 public $prefix =
'TC';
56 public $nom =
'Simple';
64 public function info($langs)
68 $textinfo = $langs->trans(
'SimpleNumRefModelDesc', $this->prefix.
'0-');
69 $textinfo .=
'<br>'.$langs->trans(
'EachTerminalHasItsOwnCounter');
81 return $this->prefix.
'0-0501-0001';
93 global $conf, $langs, $db;
101 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
103 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
104 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
105 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
106 $sql .=
" AND entity = ".$conf->entity;
108 $resql = $db->query($sql);
110 $row = $db->fetch_row($resql);
112 $pryymm = substr($row[0], 0, 6);
117 if (!$pryymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $pryymm)) {
120 $langs->load(
"errors");
121 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
137 public function getNextValue($objsoc =
null, $invoice =
null, $mode =
'next')
141 $pos_source = is_object($invoice) && $invoice->pos_source > 0 ? $invoice->pos_source : 0;
144 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
145 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
146 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
147 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
148 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
151 $resql = $db->query($sql);
153 $obj = $db->fetch_object($resql);
155 $max = intval($obj->max);
160 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
164 if ($mode ==
'last') {
165 if ($max >= (pow(10, 4) - 1)) {
168 $num = sprintf(
"%04s", $max);
172 $sql =
"SELECT ref as ref";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
174 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-".$num).
"'";
175 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
176 $sql .=
" ORDER BY ref DESC";
178 $resql = $db->query($sql);
180 $obj = $db->fetch_object($resql);
189 } elseif ($mode ==
'next') {
190 $date = $invoice->date;
193 if ($max >= (pow(10, 4) - 1)) {
196 $num = sprintf(
"%04s", $max + 1);
199 dol_syslog(get_class($this).
"::getNextValue return ".$this->prefix.$pos_source.
'-'.$yymm.
'-'.$num);
200 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.
info($langs)
Return description of numbering module.
canBeActivated($object)
Test if the numbers already in the database do not cause any conflicts that will prevent this of conf...
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...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.