differentiate masks for lot management and serial numbers management

This commit is contained in:
Christophe Battarel 2021-03-11 10:44:55 +01:00
parent 2c711f1a2d
commit ba51c5dc70
9 changed files with 413 additions and 44 deletions

View File

@ -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')."<br>\n";
$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte .= '<input type="hidden" name="token" value="'.newToken().'">';
$texte .= '<input type="hidden" name="action" value="updateMask">';
$texte .= '<input type="hidden" name="maskconstBatch" value="BATCH_ADVANCED_MASK">';
$texte .= '<input type="hidden" name="action" value="updateMaskLot">';
$texte .= '<input type="hidden" name="maskconstLot" value="LOT_ADVANCED_MASK">';
$texte .= '<table class="nobordernopadding" width="100%">';
$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
@ -80,7 +80,7 @@ class mod_batch_advanced extends ModeleNumRefBatch
// Parametrage du prefix
$texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskMo" value="'.$conf->global->BATCH_ADVANCED_MASK.'">', $tooltip, 1, 1).'</td>';
$texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskLot" value="'.$conf->global->LOT_ADVANCED_MASK.'">', $tooltip, 1, 1).'</td>';
$texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';

View File

@ -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

View File

@ -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;
}
}

View File

@ -0,0 +1,147 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2021 Christophe Battarel <christophe@altairis.fr>
*
* 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 <https://www.gnu.org/licenses/>.
* 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')."<br>\n";
$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte .= '<input type="hidden" name="token" value="'.newToken().'">';
$texte .= '<input type="hidden" name="action" value="updateMaskSN">';
$texte .= '<input type="hidden" name="maskconstSN" value="SN_ADVANCED_MASK">';
$texte .= '<table class="nobordernopadding" width="100%">';
$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 .= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskSN" value="'.$conf->global->SN_ADVANCED_MASK.'">', $tooltip, 1, 1).'</td>';
$texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte .= '</tr>';
$texte .= '</table>';
$texte .= '</form>';
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;
}
}

View File

@ -0,0 +1,106 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 <https://www.gnu.org/licenses/>.
* 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 '';
}
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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 '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
@ -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 '</td>'."\n";
print '<td class="center">';
if ($conf->global->BATCH_ADDON == $file)
if ($conf->global->LOT_ADDON == $file)
{
print img_picto($langs->trans("Activated"), 'switch_on');
}
else
{
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodlot&amp;value='.$file.'">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a>';
}
print '</td>';
$batch = new Productlot($db);
$batch->initAsSpecimen();
// Info
$htmltooltip = '';
$htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
$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.'<br>';
} else {
$htmltooltip .= $langs->trans($module->error).'<br>';
}
}
print '<td class="center">';
print $form->textwithpicto('', $htmltooltip, 1, 0);
print '</td>';
print "</tr>\n";
}
}
}
closedir($handle);
}
}
}
print "</table><br>\n";
/*
* Serials Numbering models
*/
print load_fiche_titre($langs->trans("BatchSerialNumberingModules"), '', '');
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td class="nowrap">'.$langs->trans("Example").'</td>';
print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
print '</tr>'."\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 '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
print $module->info();
print '</td>';
// Show example of numbering model
print '<td class="nowrap">';
$tmp = $module->getExample();
if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
else print $tmp;
print '</td>'."\n";
print '<td class="center">';
if ($conf->global->SN_ADDON == $file)
{
print img_picto($langs->trans("Activated"), 'switch_on');
}
else
{
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodsn&amp;value='.$file.'">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a>';
}