26require_once DOL_DOCUMENT_ROOT.
'/core/modules/product_batch/modules_product_batch.class.php';
37 public $version =
'dolibarr';
39 public $prefix =
'SN';
49 public $name =
'sn_standard';
58 public function info($langs)
61 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
72 return $this->prefix.
"0501-0001";
85 global $conf, $langs, $db;
90 $posindice = strlen($this->prefix) + 6;
91 $sql =
"SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.
") AS SIGNED)) as max";
92 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lot";
93 $sql .=
" WHERE batch LIKE '".$db->escape($this->prefix).
"____-%'";
94 $sql .=
" AND entity = ".$conf->entity;
96 $resql = $db->query($sql);
98 $obj = $db->fetch_object($resql);
100 $max = intval($obj->max);
105 if ($max && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $max)) {
106 $langs->load(
"errors");
107 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
126 $posindice = strlen($this->prefix) + 6;
127 $sql =
"SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.
") AS SIGNED)) as max";
128 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lot";
129 $sql .=
" WHERE batch LIKE '".$db->escape($this->prefix).
"____-%'";
130 $sql .=
" AND entity = ".$conf->entity;
132 $resql = $db->query($sql);
134 $obj = $db->fetch_object($resql);
136 $max = intval($obj->max);
141 dol_syslog(
"mod_sn_standard::getNextValue", LOG_DEBUG);
147 $yymm = strftime(
"%y%m", $date);
149 if ($max >= (pow(10, 4) - 1)) {
152 $num = sprintf(
"%04s", $max + 1);
155 dol_syslog(
"mod_sn_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
156 return $this->prefix.$yymm.
"-".$num;
Parent class to manage numbering of batch products.
Class to manage MO numbering rules standard.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
info($langs)
Return description of numbering module.
getNextValue($objsoc, $object)
Return next free value.
getExample()
Return an example of numbering.
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.