From ff0679866093847907bacd9164098f44f9c930f6 Mon Sep 17 00:00:00 2001 From: zuiko Date: Tue, 12 Jan 2021 21:14:43 +0100 Subject: [PATCH] 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) {