diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 1e76e7d9cf9..765bd307464 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2636,6 +2636,7 @@ class Form $sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,"; $sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,"; $sql.= " pfp.supplier_reputation"; + if (! empty($conf->barcode->enabled)) $sql.= " ,pfp.barcode"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; if ($socid) $sql.= " AND pfp.fk_soc = ".$socid; @@ -2660,7 +2661,10 @@ class Form $i++; } if (count($scrit) > 1) $sql.=")"; - if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; + if (! empty($conf->barcode->enabled)){ + $sql.= " OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; + $sql.= " OR pfp.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; + } $sql.=')'; } $sql.= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; @@ -2780,6 +2784,11 @@ class Form $opt .= " - ".dol_trunc($objp->name, 8); $outval.=" - ".dol_trunc($objp->name, 8); } + if (! empty($conf->barcode->enabled) && !empty($objp->barcode)) + { + $opt .= " - ".$objp->barcode; + $outval.=" - ".$objp->barcode; + } if ($objp->supplier_reputation) { //TODO dictionary diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 6eaba659de0..388a9228024 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -278,6 +278,21 @@ else { } $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1, $alsoproductwithnosupplierprice, 'maxwidth300'); + ?> + + '; echo ''; diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index bbdea07270e..358b836b3f5 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -227,9 +227,11 @@ class ProductFournisseur extends Product * @param float $multicurrency_tx Rate currency * @param string $multicurrency_code Currency code * @param string $desc_fourn Custom description for product_fourn_price + * @param string $barcode Barcode + * @param int $fk_barcode_type Barcode type * @return int <0 if KO, >=0 if OK */ - public function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges = 0, $remise_percent = 0, $remise = 0, $newnpr = 0, $delivery_time_days = 0, $supplier_reputation = '', $localtaxes_array = array(), $newdefaultvatcode = '', $multicurrency_buyprice = 0, $multicurrency_price_base_type = 'HT', $multicurrency_tx = 1, $multicurrency_code = '', $desc_fourn = '') + public function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges = 0, $remise_percent = 0, $remise = 0, $newnpr = 0, $delivery_time_days = 0, $supplier_reputation = '', $localtaxes_array = array(), $newdefaultvatcode = '', $multicurrency_buyprice = 0, $multicurrency_price_base_type = 'HT', $multicurrency_tx = 1, $multicurrency_code = '', $desc_fourn = '', $barcode='', $fk_barcode_type='') { // phpcs:enable global $conf, $langs; @@ -350,7 +352,9 @@ class ProductFournisseur extends Product $sql.= " info_bits = ".$newnpr.","; $sql.= " charges = ".$charges.","; // deprecated $sql.= " delivery_time_days = ".($delivery_time_days != '' ? $delivery_time_days : 'null').","; - $sql.= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'"); + $sql.= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").","; + $sql.= " barcode = ".(empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").","; + $sql.= " fk_barcode_type = ".(empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'"); $sql.= " WHERE rowid = ".$this->product_fourn_price_id; // TODO Add price_base_type and price_ttc @@ -400,7 +404,7 @@ class ProductFournisseur extends Product // Add price for this quantity to supplier $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_fournisseur_price("; $sql.= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,"; - $sql .= "datec, fk_product, fk_soc, ref_fourn, desc_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, fk_availability, default_vat_code, info_bits, entity, delivery_time_days, supplier_reputation)"; + $sql .= "datec, fk_product, fk_soc, ref_fourn, desc_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, fk_availability, default_vat_code, info_bits, entity, delivery_time_days, supplier_reputation, barcode, fk_barcode_type)"; $sql .= " values("; $sql.= (isset($multicurrency_buyprice)?"'".$this->db->escape(price2num($multicurrency_buyprice))."'":'null').","; $sql.= (isset($multicurrency_unitBuyPrice)?"'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'":'null').","; @@ -426,6 +430,8 @@ class ProductFournisseur extends Product $sql .= $conf->entity . ","; $sql .= $delivery_time_days . ","; $sql .= (empty($supplier_reputation) ? 'NULL' : "'" . $this->db->escape($supplier_reputation) . "'"); + $sql .= (empty($barcode) ? 'NULL' : "'" . $this->db->escape($barcode) . "'"); + $sql .= (empty($fk_barcode_type) ? 'NULL' : "'" . $this->db->escape($fk_barcode_type) . "'"); $sql .= ")"; $idinserted = 0; @@ -488,8 +494,9 @@ class ProductFournisseur extends Product $sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.default_vat_code, pfp.info_bits as fourn_tva_npr, pfp.fk_availability,"; $sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,"; - $sql.= " pfp.supplier_reputation, pfp.fk_user, pfp.datec"; - $sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code"; + $sql.= " pfp.supplier_reputation, pfp.fk_user, pfp.datec,"; + $sql.= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,"; + $sql.=" pfp.barcode, pfp.fk_barcode_type"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " WHERE pfp.rowid = ".$rowid; @@ -529,7 +536,10 @@ class ProductFournisseur extends Product $this->fourn_multicurrency_tx = $obj->multicurrency_tx; $this->fourn_multicurrency_id = $obj->fk_multicurrency; $this->fourn_multicurrency_code = $obj->multicurrency_code; - + if($conf->barcode->enabled) { + $this->fourn_barcode = $obj->barcode; + $this->fourn_fk_barcode_type = $obj->fk_barcode_type; + } if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) { $priceparser = new PriceParser($this->db); @@ -582,7 +592,8 @@ class ProductFournisseur extends Product $sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,"; $sql.= " pfp.rowid as product_fourn_pri_id, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product as product_fourn_id, pfp.fk_supplier_price_expression,"; $sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation,"; - $sql.= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms"; + $sql.= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,"; + $sql.= " pfp.barcode, pfp.fk_barcode_type"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")"; $sql.= " AND pfp.fk_soc = s.rowid"; @@ -632,6 +643,11 @@ class ProductFournisseur extends Product $prodfourn->fourn_multicurrency_id = $record["fk_multicurrency"]; $prodfourn->fourn_multicurrency_code = $record["multicurrency_code"]; + if($conf->barcode->enabled){ + $prodfourn->barcode = $record["barcode"]; + $prodfourn->fk_barcode_type = $record["fk_barcode_type"]; + } + if (!empty($conf->dynamicprices->enabled) && !empty($prodfourn->fk_supplier_price_expression)) { $priceparser = new PriceParser($this->db); $price_result = $priceparser->parseProductSupplier($prodfourn); diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 7c4b09a6f6c..bdf480ccfc4 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2769,6 +2769,8 @@ elseif (! empty($object->id)) } } + + // End of page llxFooter(); $db->close(); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 2fc36516bc6..71abab3a065 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -3235,6 +3235,7 @@ else } } + // End of page llxFooter(); $db->close(); diff --git a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql index 937d7cbc401..49fe291d906 100644 --- a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql +++ b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql @@ -282,4 +282,3 @@ ALTER TABLE llx_accounting_account DROP INDEX uk_accounting_account; ALTER TABLE llx_accounting_account ADD UNIQUE INDEX uk_accounting_account (account_number, entity, fk_pcg_version); - diff --git a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql index f88b7113037..6f90b41f62b 100644 --- a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql +++ b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql @@ -235,6 +235,13 @@ ALTER TABLE llx_bom_bomline ADD INDEX idx_bom_bomline_rowid (rowid); ALTER TABLE llx_bom_bomline ADD INDEX idx_bom_bomline_fk_product (fk_product); ALTER TABLE llx_bom_bomline ADD INDEX idx_bom_bomline_fk_bom (fk_bom); +ALTER TABLE llx_product_fournisseur_price ADD COLUMN barcode varchar(180) DEFAULT NULL; +ALTER TABLE llx_product_fournisseur_price ADD COLUMN fk_barcode_type integer DEFAULT NULL; +ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_barcode (barcode); +ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fk_barcode_type (fk_barcode_type); +ALTER TABLE llx_product_fournisseur_price ADD UNIQUE INDEX uk_product_barcode (barcode, fk_barcode_type, entity); +ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type (rowid); + ALTER TABLE llx_facturedet_rec ADD COLUMN buy_price_ht double(24,8) DEFAULT 0; ALTER TABLE llx_facturedet_rec ADD COLUMN fk_product_fournisseur_price integer DEFAULT NULL; diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price.key.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price.key.sql index 110736718d1..67817733255 100644 --- a/htdocs/install/mysql/tables/llx_product_fournisseur_price.key.sql +++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price.key.sql @@ -31,3 +31,8 @@ ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fourn_price_fk_p ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fourn_price_fk_soc (fk_soc, entity); ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid); + +ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_barcode (barcode); +ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fk_barcode_type (fk_barcode_type); +ALTER TABLE llx_product_fournisseur_price ADD UNIQUE INDEX uk_product_barcode (barcode, fk_barcode_type, entity); +ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type (rowid); diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql index 940967b13d4..af5aa743db2 100755 --- a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql +++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql @@ -37,6 +37,8 @@ create table llx_product_fournisseur_price unitprice double(24,8) DEFAULT 0, -- unit price without tax charges double(24,8) DEFAULT 0, -- to store transport cost. Constant PRODUCT_CHARGES must be set to see it. default_vat_code varchar(10), + barcode varchar(180) DEFAULT NULL, -- barcode + fk_barcode_type integer DEFAULT NULL, -- barcode type tva_tx double(6,3) NOT NULL, localtax1_tx double(6,3) DEFAULT 0, localtax1_type varchar(10) NOT NULL DEFAULT '0', diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index 7a423b0b007..f88f418e8d3 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -103,6 +103,7 @@ WrongSupplierCode=Code fournisseur incorrect CustomerCodeModel=Modèle de code client SupplierCodeModel=Modèle de code fournisseur Gencod=Code-barres +GencodBuyPrice=Code-barres lié au prix d'achat ##### Professional ID ##### ProfId1Short=Id. prof. 1 ProfId2Short=Id. prof. 2 diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index c0e4c7fabb2..0be06145886 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -37,7 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; - +if(!empty($conf->barcode->enabled)) dol_include_once('/core/class/html.formbarcode.class.php'); // Load translation files required by the page $langs->loadLangs(array('products', 'suppliers', 'bills', 'margins')); @@ -158,6 +158,8 @@ if (empty($reshook)) $delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : ''; $supplier_reputation = GETPOST('supplier_reputation'); $supplier_description = GETPOST('supplier_description', 'alpha'); + $barcode=GETPOST('barcode', 'alpha'); + $fk_barcode_type=GETPOST('fk_barcode_type', 'int'); if ($tva_tx == '') { @@ -258,9 +260,9 @@ if (empty($reshook)) $multicurrency_price = price2num(GETPOST("multicurrency_price", 'alpha')); $multicurrency_code = GETPOST("multicurrency_code", 'alpha'); - $ret = $object->update_buyprice($quantity, $newprice, $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $multicurrency_price, $_POST["multicurrency_price_base_type"], $multicurrency_tx, $multicurrency_code, $supplier_description); + $ret = $object->update_buyprice($quantity, $newprice, $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $multicurrency_price, $_POST["multicurrency_price_base_type"], $multicurrency_tx, $multicurrency_code, $supplier_description, $barcode, $fk_barcode_type); } else { - $ret = $object->update_buyprice($quantity, $newprice, $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description); + $ret = $object->update_buyprice($quantity, $newprice, $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description, $barcode, $fk_barcode_type); } if ($ret < 0) { @@ -666,8 +668,24 @@ SCRIPT; print ''.$langs->trans("SupplierReputation").''; echo $form->selectarray('supplier_reputation', $object->reputations, $supplier_reputation?$supplier_reputation:$object->supplier_reputation); print ''; + if(!empty($conf->barcode->enabled)) { // Option to define a transport cost on supplier price + print ''; + print '' . $langs->trans('BarcodeValue') . ''; + print ''; + print ''; + $formbarcode = new FormBarCode($db); + + // Barcode type + print ''; + print '' . $langs->trans('BarcodeType') . ''; + print ''; + print $formbarcode->selectBarcodeType(($rowid ? $object->fourn_fk_barcode_type : ''), 'fk_barcode_type', 1); + print ''; + print ''; + } + // Option to define a transport cost on supplier price if ($conf->global->PRODUCT_CHARGES) { if (! empty($conf->margin->enabled)) @@ -780,6 +798,10 @@ SCRIPT; print_liste_field_titre("DiscountQtyMin", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center '); + if($conf->barcode->enabled) { + print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, 'align="center"', $sortfield, $sortorder); + } print_liste_field_titre(''); print "\n"; @@ -871,6 +893,23 @@ SCRIPT; } print''; + if($conf->barcode->enabled) { + // Barcode + print ''; + print $productfourn->barcode; + print ''; + + + + // Barcode type + print ''; + + $productfourn->barcode_type = !empty($productfourn->fk_barcode_type) ? $productfourn->fk_barcode_type:0; + $productfourn->fetch_barcode(); + print $productfourn->barcode_type_label?$productfourn->barcode_type_label:($productfourn->barcode?'
'.$langs->trans("SetDefaultBarcodeType").'
':''); + print ''; + } + if (is_object($hookmanager)) { $parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$object->id); diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 45066e5ccdc..d7b6fc14cf5 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -142,6 +142,7 @@ if (! empty($conf->global->MAIN_MULTILANGS)) } if (! empty($conf->barcode->enabled)) { $fieldstosearchall['p.barcode']='Gencod'; + $fieldstosearchall['pfp.barcode']='GencodBuyPrice'; } if (empty($conf->global->PRODUIT_MULTIPRICES))