41 public $version =
'dolibarr';
47 public $prefix =
'TC';
58 public $nom =
'Simple';
66 public function info($langs)
70 $textinfo = $langs->trans(
'SimpleNumRefModelDesc', $this->prefix.
'0-');
71 $textinfo .=
'<br>'.$langs->trans(
'EachTerminalHasItsOwnCounter');
83 return $this->prefix.
'0-0501-0001';
95 global
$conf, $langs, $db;
103 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
105 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
106 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
107 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
108 $sql .=
" AND entity = ".$conf->entity;
110 $resql = $db->query($sql);
112 $row = $db->fetch_row($resql);
114 $pryymm = substr($row[0], 0, 6);
119 if (!$pryymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $pryymm)) {
122 $langs->load(
"errors");
123 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
139 public function getNextValue($objsoc =
null, $invoice =
null, $mode =
'next')
143 $pos_source = is_object($invoice) && $invoice->pos_source > 0 ? $invoice->pos_source : 0;
146 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
147 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
148 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
149 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
150 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
153 $resql = $db->query($sql);
155 $obj = $db->fetch_object($resql);
157 $max = intval($obj->max);
162 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
166 if ($mode ==
'last') {
167 if ($max >= (pow(10, 4) - 1)) {
170 $num = sprintf(
"%04d", $max);
174 $sql =
"SELECT ref as ref";
175 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
176 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-".$num).
"'";
177 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
178 $sql .=
" ORDER BY ref DESC";
180 $resql = $db->query($sql);
182 $obj = $db->fetch_object($resql);
191 } elseif ($mode ==
'next') {
192 $date = $invoice->date;
195 if ($max >= (pow(10, 4) - 1)) {
198 $num = sprintf(
"%04d", $max + 1);
201 dol_syslog(get_class($this).
"::getNextValue return ".$this->prefix.$pos_source.
'-'.$yymm.
'-'.$num);
202 return $this->prefix.$pos_source.
'-'.$yymm.
'-'.$num;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent Class of the models to number the cash register receipts.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...