38 public $version =
'dolibarr';
44 public $prefix =
'TC';
55 public $nom =
'Simple';
66 $textinfo = $langs->trans(
'SimpleNumRefModelDesc', $this->prefix.
'0-');
67 $textinfo .=
'<br>'.$langs->trans(
'EachTerminalHasItsOwnCounter');
79 return $this->prefix.
'0-0501-0001';
90 global $conf, $langs, $db;
98 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
100 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
101 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
102 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
103 $sql .=
" AND entity = ".$conf->entity;
105 $resql = $db->query($sql);
107 $row = $db->fetch_row(
$resql);
109 $pryymm = substr($row[0], 0, 6);
114 if (!$pryymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $pryymm)) {
117 $langs->load(
"errors");
118 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
134 public function getNextValue($objsoc =
null, $invoice =
null, $mode =
'next')
138 $pos_source = is_object($invoice) && $invoice->pos_source > 0 ? $invoice->pos_source : 0;
141 $posindice = strlen($this->prefix.$pos_source.
'-____-') + 1;
142 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
143 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
144 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-%").
"'";
145 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
148 $resql = $db->query($sql);
150 $obj = $db->fetch_object(
$resql);
152 $max = intval($obj->max);
157 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
161 if ($mode ==
'last') {
162 if ($max >= (pow(10, 4) - 1)) {
165 $num = sprintf(
"%04s", $max);
169 $sql =
"SELECT ref as ref";
170 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
171 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix.$pos_source.
"-____-".$num).
"'";
172 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
173 $sql .=
" ORDER BY ref DESC";
175 $resql = $db->query($sql);
177 $obj = $db->fetch_object(
$resql);
186 } elseif ($mode ==
'next') {
187 $date = $invoice->date;
188 $yymm = strftime(
"%y%m", $date);
190 if ($max >= (pow(10, 4) - 1)) {
193 $num = sprintf(
"%04s", $max + 1);
196 dol_syslog(get_class($this).
"::getNextValue return ".$this->prefix.$pos_source.
'-'.$yymm.
'-'.$num);
197 return $this->prefix.$pos_source.
'-'.$yymm.
'-'.$num;