From 4e95108eb04ea80c95a79f046caa2caa58d58d1b Mon Sep 17 00:00:00 2001 From: zuiko Date: Wed, 6 Jan 2021 23:33:04 +0100 Subject: [PATCH 01/18] Update mod_barcode_product_standard.php Fix #15633 --- .../barcode/mod_barcode_product_standard.php | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 5b561f90c1c..ce9cae8dd1d 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -99,9 +99,9 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("BarCode"), $langs->transnoentities("BarCode")); $tooltip .= $langs->trans("GenericMaskCodes3"); $tooltip .= ''.$langs->trans("Example").':
'; - $tooltip .= '020{000000000} (for internal use)
'; - $tooltip .= '9771234{00000} (example of ISSN code with prefix 1234)
'; - $tooltip .= '9791234{00000} (example of ISMN code with prefix 1234)
'; + $tooltip .= '020{000000000}* (for internal use)
'; + $tooltip .= '9771234{00000}* (example of ISSN code with prefix 1234)
'; + $tooltip .= '9791234{00000}* (example of ISMN code with prefix 1234)
'; //$tooltip.=$langs->trans("GenericMaskCodes5"); // Mask parameter @@ -153,7 +153,8 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode global $db, $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - + require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean) + // TODO // Get Mask value @@ -171,7 +172,22 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $now = dol_now(); $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); - + //if EAN13 calculate and substitute the last 13th character (* or ?) used in the mask by the EAN13 key + $type=$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; //get barcode type configuration for products + if ($type==2) //2 = EAN13 + { + if (strlen($numFinal)==13) + { + if ((substr($numFinal, -1)=='*') or (substr($numFinal, -1)=='?')) // if last mask character is * or ? + { + $ean = substr($numFinal, 0, 12); //take first 12 digits + $eansum = barcode_gen_ean_sum($ean); + $ean .= $eansum; //substitute the last character by the key + $numFinal = $ean; + } + } + } + //EAN13 end return $numFinal; } From e861248af8058657cd748391add0b8420d2c1645 Mon Sep 17 00:00:00 2001 From: zuiko Date: Wed, 6 Jan 2021 23:37:58 +0100 Subject: [PATCH 02/18] Update admin.lang Fix #15633 --- htdocs/langs/fr_FR/admin.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index c4025fb1577..c6afd025e5b 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -342,7 +342,7 @@ UpdateServerOffline=Serveur de mise à jour hors ligne WithCounter=Gérer un compteur GenericMaskCodes=Vous pouvez saisir tout masque de numérotation. Dans ce masque, les balises suivantes peuvent être utilisées:
{000000} correspond à un numéro qui sera incrémenté à chaque %s. Mettre autant de zéro que la longueur désirée du compteur. Le compteur sera complété par des 0 à gauche afin d'avoir autant de zéro que dans le masque.
{000000+000} idem que précédemment mais un décalage correspondant au nombre à droite du + est appliqué dès la première %s.
{000000@x} idem que précédemment mais le compteur est remis à zéro le xème mois de l'année (x entre 1 et 12, ou 0 pour utiliser le mois de début d'exercice fiscal défini dans votre configuration, ou 99 pour remise à zéro chaque mois). Si cette option est utilisée et x vaut 2 ou plus, alors la séquence {yy}{mm} ou {yyyy}{mm} est obligatoire.
{dd} jour (01 à 31).
{mm} mois (01 à 12).
{yy}, {yyyy} ou {y} année sur 2, 4 ou 1 chiffres.
GenericMaskCodes2={cccc} : code client sur n caractères
{cccc000} : code client sur n caractères suivi d'un compteur propre au client. Ce compteur propre au client est remis à zéro en même temps que le compteur général.
{tttt} code du type de tiers sur n caractères (Voir menu Accueil > Configuration > Dictionnaires > Types de tiers). Si vous ajoutez cet élément au masque de numérotation, le compteur sera différent pour chaque type de tiers.
-GenericMaskCodes3=Tout autre caractère dans le masque sera laissé inchangé.
Les espaces ne sont pas permis.
+GenericMaskCodes3=Tout autre caractère dans le masque sera laissé inchangé (sauf * ou ? en 13ème position en EAN13).
Les espaces ne sont pas permis.
En EAN13 le dernier caractère après la dernière } se plaçant en 13ème position
devra être * ou ? il sera remplacé par la clé calculée.
GenericMaskCodes4a=Exemple sur la 99eme %s du tiers LaCompanie faite le 31/01/2007:
GenericMaskCodes4b=Exemple sur un tiers créé le 31/03/2007 :
GenericMaskCodes4c=Exemple sur un produit/service créé le 31/03/2007 :
From 2300c040b3f12db648a9ea755d8e280491295caf Mon Sep 17 00:00:00 2001 From: zuiko Date: Wed, 6 Jan 2021 23:40:27 +0100 Subject: [PATCH 03/18] Update admin.lang --- htdocs/langs/en_US/admin.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 431ef75ac63..5509b0c84c8 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -343,7 +343,7 @@ UpdateServerOffline=Update server offline WithCounter=Manage a counter GenericMaskCodes=You may enter any numbering mask. In this mask, the following tags could be used:
{000000} corresponds to a number which will be incremented on each %s. Enter as many zeros as the desired length of the counter. The counter will be completed by zeros from the left in order to have as many zeros as the mask.
{000000+000} same as previous but an offset corresponding to the number to the right of the + sign is applied starting on first %s.
{000000@x} same as previous but the counter is reset to zero when month x is reached (x between 1 and 12, or 0 to use the early months of fiscal year defined in your configuration, or 99 to reset to zero every month). If this option is used and x is 2 or higher, then sequence {yy}{mm} or {yyyy}{mm} is also required.
{dd} day (01 to 31).
{mm} month (01 to 12).
{yy}, {yyyy} or {y} year over 2, 4 or 1 numbers.
GenericMaskCodes2={cccc} the client code on n characters
{cccc000} the client code on n characters is followed by a counter dedicated for customer. This counter dedicated to customer is reset at same time than global counter.
{tttt} The code of third party type on n characters (see menu Home - Setup - Dictionary - Types of third parties). If you add this tag, the counter will be different for each type of third party.
-GenericMaskCodes3=All other characters in the mask will remain intact.
Spaces are not allowed.
+GenericMaskCodes3=All other characters in the mask will remain intact (except * or ? in 13th position in EAN13).
Spaces are not allowed.
In EAN13 the last character after the last } in 13th position
should be * or ? it will be replaced by the calculated key.
GenericMaskCodes4a=Example on the 99th %s of the third party TheCompany, with date 2007-01-31:
GenericMaskCodes4b=Example on third party created on 2007-03-01:
GenericMaskCodes4c=Example on product created on 2007-03-01:
From 07ddb1fd2b00f12bdd768d77d2a9496a556b2b11 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 6 Jan 2021 23:17:16 +0000 Subject: [PATCH 04/18] Fixing style errors. --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index ce9cae8dd1d..78ef63724c8 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -154,7 +154,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean) - + // TODO // Get Mask value From 73e69f83897c677901da21db4b0cbb5162b9dcbe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jan 2021 10:23:38 +0100 Subject: [PATCH 05/18] Update mod_barcode_product_standard.php --- .../core/modules/barcode/mod_barcode_product_standard.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 78ef63724c8..6ba20997b47 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -99,9 +99,9 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("BarCode"), $langs->transnoentities("BarCode")); $tooltip .= $langs->trans("GenericMaskCodes3"); $tooltip .= ''.$langs->trans("Example").':
'; - $tooltip .= '020{000000000}* (for internal use)
'; - $tooltip .= '9771234{00000}* (example of ISSN code with prefix 1234)
'; - $tooltip .= '9791234{00000}* (example of ISMN code with prefix 1234)
'; + $tooltip .= '020{000000000}? (for internal use)
'; + $tooltip .= '9771234{00000}? (example of ISSN code with prefix 1234)
'; + $tooltip .= '9791234{00000}? (example of ISMN code with prefix 1234)
'; //$tooltip.=$langs->trans("GenericMaskCodes5"); // Mask parameter From bcff65c3d33ec21652f0e3ce9aa6495426a23e2d Mon Sep 17 00:00:00 2001 From: zuiko Date: Sat, 9 Jan 2021 01:01:14 +0100 Subject: [PATCH 06/18] Update mod_barcode_product_standard.php get barcode type configuration for products only if $type not set --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 6ba20997b47..a4c56928688 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -173,7 +173,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); //if EAN13 calculate and substitute the last 13th character (* or ?) used in the mask by the EAN13 key - $type=$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; //get barcode type configuration for products + if ($type=='') {$type=$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;} //get barcode type configuration for products if $type not set if ($type==2) //2 = EAN13 { if (strlen($numFinal)==13) From 50461931b0604f06a0b77d24e399ac7aa392ae93 Mon Sep 17 00:00:00 2001 From: zuiko Date: Sat, 9 Jan 2021 01:13:02 +0100 Subject: [PATCH 07/18] Update card.php $type replaced by $fk_barcode_type in $tmpcode = $modBarCodeProduct->getNextValue($object, $type); in order to set it --- htdocs/product/card.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index d6f62b34769..4a964250cfd 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1052,7 +1052,7 @@ else if ($conf->browser->layout == 'phone') print ''; print ''.$langs->trans("BarcodeValue").''; $tmpcode = isset($_POST['barcode']) ?GETPOST('barcode') : $object->barcode; - if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $type); + if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); print ''; print ''; } @@ -1491,7 +1491,7 @@ else print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1); print ''.$langs->trans("BarcodeValue").''; $tmpcode = isset($_POST['barcode']) ?GETPOST('barcode') : $object->barcode; - if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $type); + if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); print ''; print ''; } @@ -1805,13 +1805,16 @@ else require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; $formbarcode = new FormBarCode($db); } + $fk_barcode_type=''; if ($action == 'editbarcodetype') { print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type'); + $fk_barcode_type=$object->barcode_type; } else { $object->fetch_barcode(); + $fk_barcode_type = $object->barcode_type; print $object->barcode_type_label ? $object->barcode_type_label : ($object->barcode ? '
'.$langs->trans("SetDefaultBarcodeType").'
' : ''); } print ''."\n"; @@ -1827,7 +1830,7 @@ else if ($action == 'editbarcode') { $tmpcode = isset($_POST['barcode']) ?GETPOST('barcode') : $object->barcode; - if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $type); + if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); print '
'; print ''; From 5ee97dfd4a6917e512024e12e0093f97280d6bad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Jan 2021 16:27:37 +0100 Subject: [PATCH 08/18] Update mod_barcode_product_standard.php --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index a4c56928688..0c91f0210f4 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -155,6 +155,10 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean) + if (empty($type)) { + $type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; + } //get barcode type configuration for products if $type not set + // TODO // Get Mask value @@ -173,7 +177,6 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); //if EAN13 calculate and substitute the last 13th character (* or ?) used in the mask by the EAN13 key - if ($type=='') {$type=$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;} //get barcode type configuration for products if $type not set if ($type==2) //2 = EAN13 { if (strlen($numFinal)==13) From f5fa7928cad9e15e351c599cea1e76af8da714e8 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 11 Jan 2021 15:29:33 +0000 Subject: [PATCH 09/18] Fixing style errors. --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 0c91f0210f4..0f7024b13cf 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -155,7 +155,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean) - if (empty($type)) { + if (empty($type)) { $type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; } //get barcode type configuration for products if $type not set From e012ce242d692d35914f4b2d51f71b213a583cbf Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 11 Jan 2021 16:17:43 +0000 Subject: [PATCH 10/18] Fixing style errors. --- htdocs/product/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 8ec74ff95ef..fbcf7e5dddf 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1843,10 +1843,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if ($action == 'editbarcodetype') { print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type'); - $fk_barcode_type = $object->barcode_type; + $fk_barcode_type = $object->barcode_type; } else { $object->fetch_barcode(); - $fk_barcode_type = $object->barcode_type; + $fk_barcode_type = $object->barcode_type; print $object->barcode_type_label ? $object->barcode_type_label : ($object->barcode ? '
'.$langs->trans("SetDefaultBarcodeType").'
' : ''); } print ''."\n"; From ff0679866093847907bacd9164098f44f9c930f6 Mon Sep 17 00:00:00 2001 From: zuiko Date: Tue, 12 Jan 2021 21:14:43 +0100 Subject: [PATCH 11/18] Update mod_barcode_product_standard.php More evolving coding by testing the type of barcode in literal form. Does not change deeply the #15918 correction principle in order to fix bug #15633. --- .../barcode/mod_barcode_product_standard.php | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 4642fde6ccc..3940677e458 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -140,7 +140,37 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode return $examplebarcode; } + /** + * Return literal barcode type code from numerical rowid type of barcode + * + * @param Database $db Database + * @param int $type Type of barcode (EAN, ISBN, ...) as rowid + * @return string + */ + public function literalBarcodeType($db, $type = '') + { + global $conf; + $out = ''; + $this->db = $db; + $sql = "SELECT rowid, code, libelle"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; + $sql .= " WHERE rowid = '".$type."'"; + $sql .= " AND entity = ".$conf->entity; + $result = $this->db->query($sql); + if ($result) { + $num = $this->db->num_rows($result); + + if ($num > 0) { + $obj = $this->db->fetch_object($result); + $out .= $obj->code; + } + } + else { + dol_print_error($this->db); + } + return $out; + } /** * Return next value * @@ -177,7 +207,9 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); //if EAN13 calculate and substitute the last 13th character (* or ?) used in the mask by the EAN13 key - if ($type==2) //2 = EAN13 + $literaltype = ''; + $literaltype = $this->literalBarcodeType($db,$type);//get literal_Barcode_Type + if ($literaltype=='EAN13') //EAN13 rowid = 2 { if (strlen($numFinal)==13) { From 14e3be630c91cc3cff4da4783349719c12f48af9 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 12 Jan 2021 20:16:34 +0000 Subject: [PATCH 12/18] Fixing style errors. --- .../core/modules/barcode/mod_barcode_product_standard.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 3940677e458..4c384d1611f 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -142,10 +142,10 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode } /** * Return literal barcode type code from numerical rowid type of barcode - * - * @param Database $db Database + * + * @param Database $db Database * @param int $type Type of barcode (EAN, ISBN, ...) as rowid - * @return string + * @return string */ public function literalBarcodeType($db, $type = '') @@ -208,7 +208,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); //if EAN13 calculate and substitute the last 13th character (* or ?) used in the mask by the EAN13 key $literaltype = ''; - $literaltype = $this->literalBarcodeType($db,$type);//get literal_Barcode_Type + $literaltype = $this->literalBarcodeType($db, $type);//get literal_Barcode_Type if ($literaltype=='EAN13') //EAN13 rowid = 2 { if (strlen($numFinal)==13) From 364158c35be28e88770545738886ca5e3c26b63a Mon Sep 17 00:00:00 2001 From: zuiko Date: Tue, 12 Jan 2021 21:24:55 +0100 Subject: [PATCH 13/18] Update mod_barcode_product_standard.php Blank line after comment removed... --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 4c384d1611f..de2b3b7a1b9 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -147,7 +147,6 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode * @param int $type Type of barcode (EAN, ISBN, ...) as rowid * @return string */ - public function literalBarcodeType($db, $type = '') { global $conf; From f718a396d5a5ba0bb433ccf93be31bdd8d9cc1ee Mon Sep 17 00:00:00 2001 From: zuiko Date: Tue, 12 Jan 2021 21:59:09 +0100 Subject: [PATCH 14/18] Update mod_barcode_product_standard.php $out .= $obj->libelle; //take the libelle corresponding to the type rowid in the database Take the libelle instead the code for the litteral value of the barcode type rowid. --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index de2b3b7a1b9..8b851e0fec1 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -162,7 +162,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode if ($num > 0) { $obj = $this->db->fetch_object($result); - $out .= $obj->code; + $out .= $obj->libelle; //take the libelle corresponding to the type rowid in the database } } else { From 1499998a99f856f8bb95dba1f1a9dbc3091152c7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Jan 2021 12:17:45 +0100 Subject: [PATCH 15/18] Debug --- .../barcode/mod_barcode_product_standard.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 8b851e0fec1..6de9ed06792 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -151,23 +151,24 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode { global $conf; $out = ''; - $this->db = $db; - $sql = "SELECT rowid, code, libelle"; + + $sql = "SELECT rowid, code, libelle as label"; $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; - $sql .= " WHERE rowid = '".$type."'"; - $sql .= " AND entity = ".$conf->entity; - $result = $this->db->query($sql); + $sql .= " WHERE rowid = '".$db->escape($type)."'"; + $sql .= " AND entity = ".((int) $conf->entity); + $result = $db->query($sql); if ($result) { - $num = $this->db->num_rows($result); + $num = $db->num_rows($result); if ($num > 0) { - $obj = $this->db->fetch_object($result); - $out .= $obj->libelle; //take the libelle corresponding to the type rowid in the database + $obj = $db->fetch_object($result); + $out .= $obj->label; //take the label corresponding to the type rowid in the database } } else { - dol_print_error($this->db); + dol_print_error($db); } + return $out; } /** From 432d45b2894bef61eb3c9bf8f66038d48d7b007f Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 13 Jan 2021 11:19:39 +0000 Subject: [PATCH 16/18] Fixing style errors. --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 6de9ed06792..c1b6aae2f06 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -151,7 +151,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode { global $conf; $out = ''; - + $sql = "SELECT rowid, code, libelle as label"; $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; $sql .= " WHERE rowid = '".$db->escape($type)."'"; @@ -168,7 +168,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode else { dol_print_error($db); } - + return $out; } /** From 21fac1ff7ac81b29d591db2f573d976ee967b570 Mon Sep 17 00:00:00 2001 From: zuiko Date: Tue, 19 Jan 2021 11:40:53 +0100 Subject: [PATCH 17/18] Update mod_barcode_product_standard.php Fix #15633: Product creation: EAN13 barcode automatic generation incompatible with EAN13 existing barcode scanning, unusable function. #15918 ok with @eldy Avoid sql call if no joker at the end of mask Treat EAN13 in a more evolutive code form to prepare needs for other barcodes with key --- .../barcode/mod_barcode_product_standard.php | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index c1b6aae2f06..27fc67c8f24 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -206,23 +206,28 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $now = dol_now(); $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); - //if EAN13 calculate and substitute the last 13th character (* or ?) used in the mask by the EAN13 key - $literaltype = ''; - $literaltype = $this->literalBarcodeType($db, $type);//get literal_Barcode_Type - if ($literaltype=='EAN13') //EAN13 rowid = 2 + //Begin barcode with key: for barcode with key (EAN13...) calculate and substitute the last character (* or ?) used in the mask by the key + if ((substr($numFinal, -1)=='*') or (substr($numFinal, -1)=='?')) // if last mask character is * or ? a joker, probably we have to calculate a key as last character (EAN13...) { - if (strlen($numFinal)==13) + $literaltype = ''; + $literaltype = $this->literalBarcodeType($db,$type);//get literal_Barcode_Type + switch ($literaltype) { - if ((substr($numFinal, -1)=='*') or (substr($numFinal, -1)=='?')) // if last mask character is * or ? - { - $ean = substr($numFinal, 0, 12); //take first 12 digits - $eansum = barcode_gen_ean_sum($ean); - $ean .= $eansum; //substitute the last character by the key - $numFinal = $ean; - } + case 'EAN13': //EAN13 rowid = 2 + if (strlen($numFinal)==13)// be sure that the mask length is correct for EAN13 + { + $ean = substr($numFinal, 0, 12); //take first 12 digits + $eansum = barcode_gen_ean_sum($ean); + $ean .= $eansum; //substitute the las character by the key + $numFinal = $ean; + } + break; + // Other barcode cases with key could be written here + default: + break; } } - //EAN13 end + //End barcode with key return $numFinal; } From 0cdd9f864072cddfad0563d68c4e73834e6c6ff3 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 19 Jan 2021 10:43:03 +0000 Subject: [PATCH 18/18] Fixing style errors. --- htdocs/core/modules/barcode/mod_barcode_product_standard.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index 27fc67c8f24..c09239a8d68 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -210,7 +210,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode if ((substr($numFinal, -1)=='*') or (substr($numFinal, -1)=='?')) // if last mask character is * or ? a joker, probably we have to calculate a key as last character (EAN13...) { $literaltype = ''; - $literaltype = $this->literalBarcodeType($db,$type);//get literal_Barcode_Type + $literaltype = $this->literalBarcodeType($db, $type);//get literal_Barcode_Type switch ($literaltype) { case 'EAN13': //EAN13 rowid = 2 @@ -222,7 +222,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $numFinal = $ean; } break; - // Other barcode cases with key could be written here + // Other barcode cases with key could be written here default: break; }