From 21fac1ff7ac81b29d591db2f573d976ee967b570 Mon Sep 17 00:00:00 2001 From: zuiko Date: Tue, 19 Jan 2021 11:40:53 +0100 Subject: [PATCH] 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; }