28require_once DOL_DOCUMENT_ROOT.
'/core/modules/product_batch/modules_product_batch.class.php';
39 public $version =
'dolibarr';
41 public $prefix =
'SN';
51 public $name =
'sn_standard';
60 public function info($langs)
63 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
74 return $this->prefix.
"0501-0001";
87 global
$conf, $langs, $db;
92 $posindice = strlen($this->prefix) + 6;
93 $sql =
"SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.
") AS SIGNED)) as max";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lot";
95 $sql .=
" WHERE batch LIKE '".$db->escape($this->prefix).
"____-%'";
96 $sql .=
" AND entity = ".$conf->entity;
98 $resql = $db->query($sql);
100 $obj = $db->fetch_object($resql);
102 $max = intval($obj->max);
107 if ($max && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', (
string) $max)) {
108 $langs->load(
"errors");
109 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
128 $posindice = strlen($this->prefix) + 6;
129 $sql =
"SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.
") AS SIGNED)) as max";
130 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lot";
131 $sql .=
" WHERE batch LIKE '".$db->escape($this->prefix).
"____-%'";
132 $sql .=
" AND entity = ".$conf->entity;
134 $resql = $db->query($sql);
136 $obj = $db->fetch_object($resql);
138 $max = intval($obj->max);
143 dol_syslog(
"mod_sn_standard::getNextValue", LOG_DEBUG);
151 if ($max >= (pow(10, 4) - 1)) {
154 $num = sprintf(
"%04d", $max + 1);
157 dol_syslog(
"mod_sn_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
158 return $this->prefix.$yymm.
"-".$num;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...