From ba51c5dc703c426bc424eb38ccc06e55743ed3f0 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 11 Mar 2021 10:44:55 +0100 Subject: [PATCH] differentiate masks for lot management and serial numbers management --- ...atch_advanced.php => mod_lot_advanced.php} | 14 +- .../{mod_batch_free.php => mod_lot_free.php} | 16 +- ...mod_batch_lot.php => mod_lot_standard.php} | 12 +- .../modules/product_batch/mod_sn_advanced.php | 147 ++++++++++++++++++ .../modules/product_batch/mod_sn_free.php | 106 +++++++++++++ .../{mod_batch_sn.php => mod_sn_standard.php} | 12 +- htdocs/langs/en_US/productbatch.lang | 2 + htdocs/langs/fr_FR/productbatch.lang | 2 + htdocs/product/admin/product_lot.php | 146 +++++++++++++++-- 9 files changed, 413 insertions(+), 44 deletions(-) rename htdocs/core/modules/product_batch/{mod_batch_advanced.php => mod_lot_advanced.php} (90%) rename htdocs/core/modules/product_batch/{mod_batch_free.php => mod_lot_free.php} (88%) rename htdocs/core/modules/product_batch/{mod_batch_lot.php => mod_lot_standard.php} (91%) create mode 100644 htdocs/core/modules/product_batch/mod_sn_advanced.php create mode 100644 htdocs/core/modules/product_batch/mod_sn_free.php rename htdocs/core/modules/product_batch/{mod_batch_sn.php => mod_sn_standard.php} (91%) diff --git a/htdocs/core/modules/product_batch/mod_batch_advanced.php b/htdocs/core/modules/product_batch/mod_lot_advanced.php similarity index 90% rename from htdocs/core/modules/product_batch/mod_batch_advanced.php rename to htdocs/core/modules/product_batch/mod_lot_advanced.php index cdf0ce3a70b..67ce3dd3704 100644 --- a/htdocs/core/modules/product_batch/mod_batch_advanced.php +++ b/htdocs/core/modules/product_batch/mod_lot_advanced.php @@ -22,9 +22,9 @@ */ /** - * \file htdocs/core/modules/product_batch/mod_batch_advanced.php + * \file htdocs/core/modules/product_batch/mod_lot_advanced.php * \ingroup productbatch - * \brief File containing class for numbering model of Batch advanced + * \brief File containing class for numbering model of Lot advanced */ require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; @@ -33,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batc /** * Class to manage Batch numbering rules advanced */ -class mod_batch_advanced extends ModeleNumRefBatch +class mod_lot_advanced extends ModeleNumRefBatch { /** * Dolibarr version of the loaded document @@ -49,7 +49,7 @@ class mod_batch_advanced extends ModeleNumRefBatch /** * @var string name */ - public $name = 'advanced'; + public $name = 'lot_advanced'; /** @@ -68,8 +68,8 @@ class mod_batch_advanced extends ModeleNumRefBatch $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; $texte .= '
'; $texte .= ''; - $texte .= ''; - $texte .= ''; + $texte .= ''; + $texte .= ''; $texte .= ''; $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch")); @@ -80,7 +80,7 @@ class mod_batch_advanced extends ModeleNumRefBatch // Parametrage du prefix $texte .= ''; - $texte .= ''; + $texte .= ''; $texte .= ''; diff --git a/htdocs/core/modules/product_batch/mod_batch_free.php b/htdocs/core/modules/product_batch/mod_lot_free.php similarity index 88% rename from htdocs/core/modules/product_batch/mod_batch_free.php rename to htdocs/core/modules/product_batch/mod_lot_free.php index 13df9b11a55..6bb9539f3df 100644 --- a/htdocs/core/modules/product_batch/mod_batch_free.php +++ b/htdocs/core/modules/product_batch/mod_lot_free.php @@ -18,9 +18,9 @@ */ /** - * \file htdocs/core/modules/product/mod_batch_free.php - * \ingroup product - * \brief Fichier de la classe des gestion leopard des codes produits + * \file htdocs/core/modules/product/mod_lot_free.php + * \ingroup productbatch + * \brief File containing class for numbering model of Lot free */ require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; @@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batc * \class mod_codeproduct_leopard * \brief Classe permettant la gestion leopard des codes produits */ -class mod_batch_free extends ModeleNumRefBatch +class mod_lot_free extends ModeleNumRefBatch { /* * Attention ce module est utilise par defaut si aucun module n'a @@ -38,17 +38,11 @@ class mod_batch_free extends ModeleNumRefBatch * Le fonctionnement de celui-ci doit donc rester le plus ouvert possible */ - /** - * @var string Nom du modele - * @deprecated - * @see $name - */ - public $nom = 'Free'; /** * @var string model name */ - public $name = 'Free'; + public $name = 'lot_free'; public $code_modifiable; // Code modifiable diff --git a/htdocs/core/modules/product_batch/mod_batch_lot.php b/htdocs/core/modules/product_batch/mod_lot_standard.php similarity index 91% rename from htdocs/core/modules/product_batch/mod_batch_lot.php rename to htdocs/core/modules/product_batch/mod_lot_standard.php index ceca5c16e08..43c3ca49314 100644 --- a/htdocs/core/modules/product_batch/mod_batch_lot.php +++ b/htdocs/core/modules/product_batch/mod_lot_standard.php @@ -19,16 +19,16 @@ */ /** - * \file htdocs/core/modules/product_batch/mod_batch_lot.php + * \file htdocs/core/modules/product_batch/mod_lot_standard.php * \ingroup productbatch - * \brief File of class to manage MO numbering rules standard + * \brief File of class to manage Lot numbering rules standard */ require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; /** * Class to manage MO numbering rules standard */ -class mod_batch_lot extends ModeleNumRefBatch +class mod_lot_standard extends ModeleNumRefBatch { /** * Dolibarr version of the loaded document @@ -46,7 +46,7 @@ class mod_batch_lot extends ModeleNumRefBatch /** * @var string name */ - public $name = 'Lot number'; + public $name = 'lot_standard'; /** @@ -133,7 +133,7 @@ class mod_batch_lot extends ModeleNumRefBatch } else { - dol_syslog("mod_mo_standard::getNextValue", LOG_DEBUG); + dol_syslog("mod_lot_standard::getNextValue", LOG_DEBUG); return -1; } @@ -144,7 +144,7 @@ class mod_batch_lot extends ModeleNumRefBatch 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 else $num = sprintf("%04s", $max + 1); - dol_syslog("mod_mo_standard::getNextValue return ".$this->prefix.$yymm."-".$num); + dol_syslog("mod_lot_standard::getNextValue return ".$this->prefix.$yymm."-".$num); return $this->prefix.$yymm."-".$num; } } diff --git a/htdocs/core/modules/product_batch/mod_sn_advanced.php b/htdocs/core/modules/product_batch/mod_sn_advanced.php new file mode 100644 index 00000000000..2dcf6433ea7 --- /dev/null +++ b/htdocs/core/modules/product_batch/mod_sn_advanced.php @@ -0,0 +1,147 @@ + + * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2008 Raphael Bertrand (Resultic) + * Copyright (C) 2019 Frédéric France + * Copyright (C) 2021 Christophe Battarel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see https://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/product_batch/mod_batch_advanced.php + * \ingroup productbatch + * \brief File containing class for numbering model of SN advanced + */ + +require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; + + +/** + * Class to manage Batch numbering rules advanced + */ +class mod_sn_advanced extends ModeleNumRefBatch +{ + /** + * Dolibarr version of the loaded document + * @var string + */ + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' + + /** + * @var string Error message + */ + public $error = ''; + + /** + * @var string name + */ + public $name = 'sn_advanced'; + + + /** + * Returns the description of the numbering model + * + * @return string Texte descripif + */ + public function info() + { + global $conf, $langs, $db; + + $langs->load("bills"); + + $form = new Form($db); + + $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= '
'.$langs->trans("Mask").':'.$form->textwithpicto('', $tooltip, 1, 1).''.$form->textwithpicto('', $tooltip, 1, 1).' 
'; + + $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch")); + $tooltip .= $langs->trans("GenericMaskCodes2"); + $tooltip .= $langs->trans("GenericMaskCodes3"); + $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch")); + $tooltip .= $langs->trans("GenericMaskCodes5"); + + // Parametrage du prefix + $texte .= ''; + $texte .= ''; + + $texte .= ''; + + $texte .= ''; + + $texte .= '
'.$langs->trans("Mask").':'.$form->textwithpicto('', $tooltip, 1, 1).' 
'; + $texte .= '
'; + + return $texte; + } + + /** + * Return an example of numbering + * + * @return string Example + */ + public function getExample() + { + global $conf, $langs, $mysoc; + + $old_code_client = $mysoc->code_client; + $old_code_type = $mysoc->typent_code; + $mysoc->code_client = 'CCCCCCCCCC'; + $mysoc->typent_code = 'TTTTTTTTTT'; + $numExample = $this->getNextValue($mysoc, ''); + $mysoc->code_client = $old_code_client; + $mysoc->typent_code = $old_code_type; + + if (!$numExample) + { + $numExample = $langs->trans('NotConfigured'); + } + return $numExample; + } + + /** + * Return next free value + * + * @param Product $objprod Object product + * @param Object $object Object we need next value for + * @return string Value if KO, <0 if KO + */ + public function getNextValue($objprod, $object) + { + global $db, $conf; + + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + + // We get cursor rule + $mask = $conf->global->BATCH_ADVANCED_MASK; + + if (!$mask) + { + $this->error = 'NotConfigured'; + return 0; + } + + $date = $object->date; + + $numFinal = get_next_value($db, $mask, 'product_sn', 'ref', '', null, $date); + + return $numFinal; + } +} diff --git a/htdocs/core/modules/product_batch/mod_sn_free.php b/htdocs/core/modules/product_batch/mod_sn_free.php new file mode 100644 index 00000000000..9f34d4dc532 --- /dev/null +++ b/htdocs/core/modules/product_batch/mod_sn_free.php @@ -0,0 +1,106 @@ + + * Copyright (C) 2006-2009 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see https://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/product/mod_sn_free.php + * \ingroup productbatch + * \brief File containing class for numbering model of SN free + */ + +require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; + +/** + * \class mod_codeproduct_leopard + * \brief Classe permettant la gestion leopard des codes produits + */ +class mod_sn_free extends ModeleNumRefBatch +{ + /* + * Attention ce module est utilise par defaut si aucun module n'a + * ete definit dans la configuration + * + * Le fonctionnement de celui-ci doit donc rester le plus ouvert possible + */ + + /** + * @var string model name + */ + public $name = 'sn_free'; + + public $code_modifiable; // Code modifiable + + public $code_modifiable_invalide; // Code modifiable si il est invalide + + public $code_modifiable_null; // Code modifiables si il est null + + public $code_null; // Code facultatif + + /** + * Dolibarr version of the loaded document + * @var string + */ + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' + + /** + * @var int Automatic numbering + */ + public $code_auto; + + + /** + * Constructor + */ + public function __construct() + { + $this->code_null = 1; + $this->code_modifiable = 1; + $this->code_modifiable_invalide = 1; + $this->code_modifiable_null = 1; + $this->code_auto = 0; + } + + + /** + * Return description of module + * + * @param Translate $langs Object langs + * @return string Description of module + */ + public function info() + { + global $langs; + $langs->load("companies"); + return $langs->trans("LeopardNumRefModelDesc"); + } + + + /** + * Return an example of result returned by getNextValue + * + * @param product $objproduct Object product + * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) + * @return string Return next value + */ + public function getNextValue($objproduct = 0, $type = -1) + { + global $langs; + return ''; + } + +} diff --git a/htdocs/core/modules/product_batch/mod_batch_sn.php b/htdocs/core/modules/product_batch/mod_sn_standard.php similarity index 91% rename from htdocs/core/modules/product_batch/mod_batch_sn.php rename to htdocs/core/modules/product_batch/mod_sn_standard.php index 43fa2e2a06e..fc2f8f3156d 100644 --- a/htdocs/core/modules/product_batch/mod_batch_sn.php +++ b/htdocs/core/modules/product_batch/mod_sn_standard.php @@ -19,16 +19,16 @@ */ /** - * \file htdocs/core/modules/product_batch/mod_batch_sn.php + * \file htdocs/core/modules/product_batch/mod_sn_standard.php * \ingroup productbatch - * \brief File of class to manage MO numbering rules standard + * \brief File of class to manage SN numbering rules standard */ require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; /** * Class to manage MO numbering rules standard */ -class mod_batch_sn extends ModeleNumRefBatch +class mod_sn_standard extends ModeleNumRefBatch { /** * Dolibarr version of the loaded document @@ -46,7 +46,7 @@ class mod_batch_sn extends ModeleNumRefBatch /** * @var string name */ - public $name = 'Serial number'; + public $name = 'sn_standard'; /** @@ -133,7 +133,7 @@ class mod_batch_sn extends ModeleNumRefBatch } else { - dol_syslog("mod_mo_standard::getNextValue", LOG_DEBUG); + dol_syslog("mod_sn_standard::getNextValue", LOG_DEBUG); return -1; } @@ -144,7 +144,7 @@ class mod_batch_sn extends ModeleNumRefBatch 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 else $num = sprintf("%04s", $max + 1); - dol_syslog("mod_mo_standard::getNextValue return ".$this->prefix.$yymm."-".$num); + dol_syslog("mod_sn_standard::getNextValue return ".$this->prefix.$yymm."-".$num); return $this->prefix.$yymm."-".$num; } } diff --git a/htdocs/langs/en_US/productbatch.lang b/htdocs/langs/en_US/productbatch.lang index 36adfd571fb..9e299baf8f3 100644 --- a/htdocs/langs/en_US/productbatch.lang +++ b/htdocs/langs/en_US/productbatch.lang @@ -26,3 +26,5 @@ 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 \ No newline at end of file diff --git a/htdocs/langs/fr_FR/productbatch.lang b/htdocs/langs/fr_FR/productbatch.lang index 94ceb434bfd..eed5a063318 100644 --- a/htdocs/langs/fr_FR/productbatch.lang +++ b/htdocs/langs/fr_FR/productbatch.lang @@ -26,3 +26,5 @@ ShowLogOfMovementIfLot=Afficher l'historique des mouvements de couple produit / StockDetailPerBatch=Stock détaillé par lot SerialNumberAlreadyInUse=Le numéro de série %s est déjà utilisé pour le produit %s TooManyQtyForSerialNumber=Vous ne pouvez avoir qu'un produit %s avec le numéro de série %s +BatchLotNumberingModules=Modèle de génération et contrôle des numéros de lot +BatchSerialNumberingModules=Modèle de génération et contrôle des numéros de série \ No newline at end of file diff --git a/htdocs/product/admin/product_lot.php b/htdocs/product/admin/product_lot.php index 04c089a0528..7fcd04b32f9 100644 --- a/htdocs/product/admin/product_lot.php +++ b/htdocs/product/admin/product_lot.php @@ -42,10 +42,10 @@ $value = GETPOST('value', 'alpha'); include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; -if ($action == 'updateMask') +if ($action == 'updateMaskLot') { - $maskconstbatch = GETPOST('maskconstBatch', 'alpha'); - $maskbatch = GETPOST('maskMo', 'alpha'); + $maskconstbatch = GETPOST('maskconstLot', 'alpha'); + $maskbatch = GETPOST('maskLot', 'alpha'); if ($maskconstbatch) $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity); @@ -59,17 +59,34 @@ if ($action == 'updateMask') { setEventMessages($langs->trans("Error"), null, 'errors'); } -} -elseif ($action == 'setmod') +} elseif ($action == 'updateMaskSN') { - // TODO Check if numbering module chosen can be activated - // by calling method canBeActivated + $maskconstbatch = GETPOST('maskconstSN', 'alpha'); + $maskbatch = GETPOST('maskSN', 'alpha'); - dolibarr_set_const($db, "BATCH_ADDON", $value, 'chaine', 0, '', $conf->entity); + if ($maskconstbatch) $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity); + + if (!$res > 0) $error++; + + if (!$error) + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans("Error"), null, 'errors'); + } + +} elseif ($action == 'setmodlot') +{ + dolibarr_set_const($db, "LOT_ADDON", $value, 'chaine', 0, '', $conf->entity); + +} elseif ($action == 'setmodsn') +{ + dolibarr_set_const($db, "SN_ADDON", $value, 'chaine', 0, '', $conf->entity); } - /* * View */ @@ -88,10 +105,10 @@ $head = product_lot_admin_prepare_head(); dol_fiche_head($head, 'settings', $langs->trans("Batch"), -1, 'productbatch'); /* - * MOs Numbering model + * Lot Numbering models */ -print load_fiche_titre($langs->trans("BatchNumberingModules"), '', ''); +print load_fiche_titre($langs->trans("BatchLotNumberingModules"), '', ''); print ''; print ''; @@ -115,7 +132,7 @@ foreach ($dirmodels as $reldir) { while (($file = readdir($handle)) !== false) { - if (substr($file, 0, 10) == 'mod_batch_' && substr($file, dol_strlen($file) - 3, 3) == 'php') + if (substr($file, 0, 8) == 'mod_lot_' && substr($file, dol_strlen($file) - 3, 3) == 'php') { $file = substr($file, 0, dol_strlen($file) - 4); @@ -142,13 +159,114 @@ foreach ($dirmodels as $reldir) print ''."\n"; print ''; + + $batch = new Productlot($db); + $batch->initAsSpecimen(); + + // Info + $htmltooltip = ''; + $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; + $nextval = $module->getNextValue($mysoc, $batch); + if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval + $htmltooltip .= ''.$langs->trans("NextValue").': '; + if ($nextval) { + if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') + $nextval = $langs->trans($nextval); + $htmltooltip .= $nextval.'
'; + } else { + $htmltooltip .= $langs->trans($module->error).'
'; + } + } + + print ''; + + print "\n"; + } + } + } + closedir($handle); + } + } +} + +print "
'; - if ($conf->global->BATCH_ADDON == $file) + if ($conf->global->LOT_ADDON == $file) { print img_picto($langs->trans("Activated"), 'switch_on'); } else { - print ''; + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; + } + print ''; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print '

\n"; + + +/* + * Serials Numbering models + */ + +print load_fiche_titre($langs->trans("BatchSerialNumberingModules"), '', ''); + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''."\n"; + +clearstatcache(); + +foreach ($dirmodels as $reldir) +{ + $dir = dol_buildpath($reldir."core/modules/product_batch/"); + + if (is_dir($dir)) + { + $handle = opendir($dir); + if (is_resource($handle)) + { + while (($file = readdir($handle)) !== false) + { + if (substr($file, 0, 7) == 'mod_sn_' && substr($file, dol_strlen($file) - 3, 3) == 'php') + { + $file = substr($file, 0, dol_strlen($file) - 4); + + require_once $dir.$file.'.php'; + + $module = new $file($db); + + // 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; + + if ($module->isEnabled()) + { + print ''; + + // Show example of numbering model + print ''."\n"; + + print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'.$module->name."\n"; + print $module->info(); + print ''; + $tmp = $module->getExample(); + if (preg_match('/^Error/', $tmp)) print '
'.$langs->trans($tmp).'
'; + elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); + else print $tmp; + print '
'; + if ($conf->global->SN_ADDON == $file) + { + print img_picto($langs->trans("Activated"), 'switch_on'); + } + else + { + print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; }