diff --git a/htdocs/core/modules/modProductBatch.class.php b/htdocs/core/modules/modProductBatch.class.php index 79529898bb0..4b508d79d7c 100644 --- a/htdocs/core/modules/modProductBatch.class.php +++ b/htdocs/core/modules/modProductBatch.class.php @@ -84,14 +84,14 @@ class modProductBatch extends DolibarrModules $this->const[$r][0] = "PRODUCTBATCH_LOT_ADDON"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "mod_lot_free"; - $this->const[$r][3] = 'Module to control product codes'; + $this->const[$r][3] = 'Module to control lot number'; $this->const[$r][4] = 0; $r++; $this->const[$r][0] = "PRODUCTBATCH_SN_ADDON"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "mod_sn_free"; - $this->const[$r][3] = 'Module to control product codes'; + $this->const[$r][3] = 'Module to control serial number'; $this->const[$r][4] = 0; $r++; diff --git a/htdocs/core/modules/product_batch/mod_lot_advanced.php b/htdocs/core/modules/product_batch/mod_lot_advanced.php index 0bbb124d14b..8ee857bfbea 100644 --- a/htdocs/core/modules/product_batch/mod_lot_advanced.php +++ b/htdocs/core/modules/product_batch/mod_lot_advanced.php @@ -128,27 +128,27 @@ class mod_lot_advanced extends ModeleNumRefBatch /** * Return next free value * - * @param Product $objprod Object product + * @param Societe $objsoc Object Societe * @param Object $object Object we need next value for * @return string Value if KO, <0 if KO */ - public function getNextValue($objprod, $object) + public function getNextValue($objsoc, $object) { global $db, $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // We get cursor rule - $mask = $conf->global->BATCH_ADVANCED_MASK; + $mask = $conf->global->LOT_ADVANCED_MASK; if (!$mask) { $this->error = 'NotConfigured'; return 0; } - $date = $object->date; + $date = dol_now(); - $numFinal = get_next_value($db, $mask, 'product_lot', 'ref', '', null, $date); + $numFinal = get_next_value($db, $mask, 'product_lot', 'batch', '', null, $date); return $numFinal; } diff --git a/htdocs/core/modules/product_batch/mod_lot_standard.php b/htdocs/core/modules/product_batch/mod_lot_standard.php index 0d2b5a55139..59de1965a6e 100644 --- a/htdocs/core/modules/product_batch/mod_lot_standard.php +++ b/htdocs/core/modules/product_batch/mod_lot_standard.php @@ -85,17 +85,21 @@ class mod_lot_standard extends ModeleNumRefBatch $coyymm = ''; $max = ''; $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { - $row = $db->fetch_row($resql); - if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; } + $obj = $db->fetch_object($resql); + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } - if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) { + if ($max && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $max)) { $langs->load("errors"); $this->error = $langs->trans('ErrorNumRefModel', $max); return false; @@ -117,23 +121,26 @@ class mod_lot_standard extends ModeleNumRefBatch // First, we get the max value $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); - if ($obj) $max = intval($obj->max); - else $max = 0; + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } else { dol_syslog("mod_lot_standard::getNextValue", LOG_DEBUG); return -1; } //$date=time(); - $date = $object->date_creation; + $date = dol_now(); $yymm = strftime("%y%m", $date); if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is diff --git a/htdocs/core/modules/product_batch/mod_sn_advanced.php b/htdocs/core/modules/product_batch/mod_sn_advanced.php index 8117b9e6c6e..54c67291d9a 100644 --- a/htdocs/core/modules/product_batch/mod_sn_advanced.php +++ b/htdocs/core/modules/product_batch/mod_sn_advanced.php @@ -139,16 +139,16 @@ class mod_sn_advanced extends ModeleNumRefBatch require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // We get cursor rule - $mask = $conf->global->BATCH_ADVANCED_MASK; + $mask = $conf->global->SN_ADVANCED_MASK; if (!$mask) { $this->error = 'NotConfigured'; return 0; } - $date = $object->date; + $date = dol_now(); - $numFinal = get_next_value($db, $mask, 'product_sn', 'ref', '', null, $date); + $numFinal = get_next_value($db, $mask, 'product_lot', 'batch', '', null, $date); return $numFinal; } diff --git a/htdocs/core/modules/product_batch/mod_sn_standard.php b/htdocs/core/modules/product_batch/mod_sn_standard.php index bef5efcd9f8..845044c39f3 100644 --- a/htdocs/core/modules/product_batch/mod_sn_standard.php +++ b/htdocs/core/modules/product_batch/mod_sn_standard.php @@ -85,17 +85,21 @@ class mod_sn_standard extends ModeleNumRefBatch $coyymm = ''; $max = ''; $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { - $row = $db->fetch_row($resql); - if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; } + $obj = $db->fetch_object($resql); + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } - if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) { + if ($max && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $max)) { $langs->load("errors"); $this->error = $langs->trans('ErrorNumRefModel', $max); return false; @@ -107,33 +111,36 @@ class mod_sn_standard extends ModeleNumRefBatch /** * Return next free value * - * @param Product $objprod Object product + * @param Societe $objsoc Object product * @param Object $object Object we need next value for * @return string Value if KO, <0 if KO */ - public function getNextValue($objprod, $object) + public function getNextValue($objsoc, $object) { global $db, $conf; // First, we get the max value $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); - if ($obj) $max = intval($obj->max); - else $max = 0; + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } else { dol_syslog("mod_sn_standard::getNextValue", LOG_DEBUG); return -1; } //$date=time(); - $date = $object->date_creation; + $date = dol_now(); $yymm = strftime("%y%m", $date); if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is diff --git a/htdocs/langs/en_US/productbatch.lang b/htdocs/langs/en_US/productbatch.lang index 450d0285819..763af20c6b4 100644 --- a/htdocs/langs/en_US/productbatch.lang +++ b/htdocs/langs/en_US/productbatch.lang @@ -26,12 +26,10 @@ ShowLogOfMovementIfLot=Show log of movements for couple product/lot StockDetailPerBatch=Stock detail per lot SerialNumberAlreadyInUse=Serial number %s is already used for product %s TooManyQtyForSerialNumber=You can only have one product %s for serial number %s -BatchLotNumberingModules=Options for automatic generation of batch products managed by lots -BatchSerialNumberingModules=Options for automatic generation of batch products managed by serial numbers ManageLotMask=Custom mask -CustomMasks=Adds an option to define mask in the product card -LotProductTooltip=Adds an option in the product card to define a dedicated batch number mask -SNProductTooltip=Adds an option in the product card to define a dedicated serial number mask +CustomMasks=Option to define a different numbering mask for each product +BatchLotNumberingModules=Numbering rule for automatic generation of lot number +BatchSerialNumberingModules=Numbering rule for automatic generation of serial number (for products with property 1 unique lot/serial for each product) QtyToAddAfterBarcodeScan=Qty to add for each barcode/lot/serial scanned LifeTime=Life span (in days) EndOfLife=End of life diff --git a/htdocs/product/admin/product_lot.php b/htdocs/product/admin/product_lot.php index 8cafa97e077..3f4fd636de4 100644 --- a/htdocs/product/admin/product_lot.php +++ b/htdocs/product/admin/product_lot.php @@ -101,188 +101,197 @@ $head = product_lot_admin_prepare_head(); print dol_get_fiche_head($head, 'settings', $langs->trans("Batch"), -1, 'lot'); -/* - * Lot Numbering models - */ -print load_fiche_titre($langs->trans("BatchLotNumberingModules"), '', ''); +if ($conf->global->MAIN_FEATURES_LEVEL < 2) { + // The feature to define the numbering module of lot or serial is no enabled bcause it is not used anywhere in Dolibarr code: You can set it + // but the numbering module is not used. + // TODO Use it on lot creation page, when you create a lot and when the lot number is kept empty to define the lot according + // to the selected product. + print $langs->trans("NothingToSetup"); +} else { + /* + * Lot Numbering models + */ -print '
| '.$langs->trans("Name").' | '; -print ''.$langs->trans("Description").' | '; -print ''.$langs->trans("Example").' | '; -print ''.$langs->trans("Status").' | '; -print ''.$langs->trans("ShortInfo").' | '; -print '
| '.$langs->trans("Name").' | '; + print ''.$langs->trans("Description").' | '; + print ''.$langs->trans("Example").' | '; + print ''.$langs->trans("Status").' | '; + print ''.$langs->trans("ShortInfo").' | '; + print '|
| '.$module->name." | \n"; - print $module->info(); - print ' | '; + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - // Show example of numbering model - print '';
- $tmp = $module->getExample();
- if (preg_match('/^Error/', $tmp)) print ' '.$langs->trans($tmp).' ';
- elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
- else print $tmp;
- print ' | '."\n";
+ if ($module->isEnabled()) {
+ print '|||
| '.$module->name." | \n"; + print $module->info(); + print ' | '; - print ''; - if ($conf->global->PRODUCTBATCH_LOT_ADDON == $file) { - print img_picto($langs->trans("Activated"), 'switch_on'); - } else { - print ''; - print img_picto($langs->trans("Disabled"), 'switch_off'); - print ''; - } - print ' | '; + // Show example of numbering model + print '';
+ $tmp = $module->getExample();
+ if (preg_match('/^Error/', $tmp)) print ' '.$langs->trans($tmp).' ';
+ elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
+ else print $tmp;
+ print ' | '."\n";
- $batch = new Productlot($db);
- $batch->initAsSpecimen();
-
- // Info
- $htmltooltip = '';
- $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'';
+ if ($conf->global->PRODUCTBATCH_LOT_ADDON == $file) {
+ print img_picto($langs->trans("Activated"), 'switch_on');
} else {
- $htmltooltip .= $langs->trans($module->error).' '; + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; } + print ' | ';
+
+ $batch = new Productlot($db);
+ $batch->initAsSpecimen();
+
+ // Info
+ $htmltooltip = '';
+ $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().''; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print ' | '; + + print "'; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print ' | '; - - print "\n"; } } + closedir($handle); } - closedir($handle); } } -} -print "
| '.$langs->trans("Name").' | '; -print ''.$langs->trans("Description").' | '; -print ''.$langs->trans("Example").' | '; -print ''.$langs->trans("Status").' | '; -print ''.$langs->trans("ShortInfo").' | '; -print '
| '.$langs->trans("Name").' | '; + print ''.$langs->trans("Description").' | '; + print ''.$langs->trans("Example").' | '; + print ''.$langs->trans("Status").' | '; + print ''.$langs->trans("ShortInfo").' | '; + print '||
| '.$module->name." | \n"; - print $module->info(); - print ' | '; + if ($module->isEnabled()) { + print '|||||
| '.$module->name." | \n"; + print $module->info(); + print ' | '; - // Show example of numbering model - print '';
- $tmp = $module->getExample();
- if (preg_match('/^Error/', $tmp)) print ' '.$langs->trans($tmp).' ';
- elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
- else print $tmp;
- print ' | '."\n";
+ // Show example of numbering model
+ print '';
+ $tmp = $module->getExample();
+ if (preg_match('/^Error/', $tmp)) print ' '.$langs->trans($tmp).' ';
+ elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
+ else print $tmp;
+ print ' | '."\n";
- print ''; - if ($conf->global->PRODUCTBATCH_SN_ADDON == $file) { - print img_picto($langs->trans("Activated"), 'switch_on'); - } else { - print ''; - print img_picto($langs->trans("Disabled"), 'switch_off'); - print ''; - } - print ' | '; - - $batch = new Productlot($db); - $batch->initAsSpecimen(); - - // Info - $htmltooltip = ''; - $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'';
+ if ($conf->global->PRODUCTBATCH_SN_ADDON == $file) {
+ print img_picto($langs->trans("Activated"), 'switch_on');
} else {
- $htmltooltip .= $langs->trans($module->error).' '; + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; } + print ' | ';
+
+ $batch = new Productlot($db);
+ $batch->initAsSpecimen();
+
+ // Info
+ $htmltooltip = '';
+ $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().''; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print ' | '; + + print "'; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print ' | '; - - print "\n"; } } + closedir($handle); } - closedir($handle); } } -} -print "