28require_once DOL_DOCUMENT_ROOT.
'/core/modules/product_batch/modules_product_batch.class.php';
39 public $version =
'dolibarr';
44 public $prefix =
'LOT';
54 public $name =
'lot_standard';
63 public function info($langs)
66 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
77 return $this->prefix.
"0501-0001";
90 global $conf, $langs, $db;
95 $posindice = strlen($this->prefix) + 6;
96 $sql =
"SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.
") AS SIGNED)) as max";
97 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lot";
98 $sql .=
" WHERE batch LIKE '".$db->escape($this->prefix).
"____-%'";
99 $sql .=
" AND entity = ".$conf->entity;
101 $resql = $db->query($sql);
103 $obj = $db->fetch_object($resql);
105 $max = intval($obj->max);
110 if ($max && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', (
string) $max)) {
111 $langs->load(
"errors");
112 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
131 $posindice = strlen($this->prefix) + 6;
132 $sql =
"SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.
") AS SIGNED)) as max";
133 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lot";
134 $sql .=
" WHERE batch LIKE '".$db->escape($this->prefix).
"____-%'";
135 $sql .=
" AND entity = ".$conf->entity;
137 $resql = $db->query($sql);
139 $obj = $db->fetch_object($resql);
141 $max = intval($obj->max);
146 dol_syslog(
"mod_lot_standard::getNextValue", LOG_DEBUG);
154 if ($max >= (pow(10, 4) - 1)) {
157 $num = sprintf(
"%04d", $max + 1);
160 dol_syslog(
"mod_lot_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
161 return $this->prefix.$yymm.
"-".$num;
if(! $sortfield) if(! $sortorder) $object
Parent class to manage numbering of batch products.
Class to manage MO numbering rules standard.
info($langs)
Return description of numbering module.
getNextValue($objsoc, $object)
Return next free value.
getExample()
Return an example of numbering.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.