diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 605be7e9b3f..bbdc0f84caf 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3854,6 +3854,7 @@ class OrderLine extends CommonOrderLine { $objp = $this->db->fetch_object($result); $this->rowid = $objp->rowid; + $this->id = $objp->rowid; $this->fk_commande = $objp->fk_commande; $this->fk_parent_line = $objp->fk_parent_line; $this->label = $objp->custom_label; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4edce36b82f..32c36b477a4 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4331,6 +4331,7 @@ class FactureLigne extends CommonInvoiceLine $objp = $this->db->fetch_object($result); $this->rowid = $objp->rowid; + $this->id = $objp->rowid; $this->fk_facture = $objp->fk_facture; $this->fk_parent_line = $objp->fk_parent_line; $this->label = $objp->custom_label; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6b00474effe..a58eb656a07 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2573,7 +2573,7 @@ abstract class CommonObject */ function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) { - global $conf; + global $conf, $hookmanager, $action; // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) $MODULE = ""; @@ -2664,7 +2664,10 @@ abstract class CommonObject $obj = $this->db->fetch_object($resql); // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' - if ($forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' + $parameters=array('fk_element' => $obj->rowid); + $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + + if (empty($reshook) && $forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' { $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); $tmpcal=calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx); diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 4cd4f6cb8a8..e7b3a292df1 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -50,6 +50,7 @@ class ProductFournisseur extends Product var $fourn_ref; var $delivery_time_days; var $ref_supplier; // ref supplier (can be set by get_buyprice) + var $desc_supplier; var $vatrate_supplier; // default vat rate for this supplier/qty/product (can be set by get_buyprice) var $fourn_id; //supplier id @@ -196,9 +197,10 @@ class ProductFournisseur extends Product * @param string $multicurrency_price_base_type HT or TTC in currency * @param float $multicurrency_tx Rate currency * @param string $multicurrency_code Currency code + * @param string $desc_fourn Custom description for product_fourn_price * @return int <0 if KO, >=0 if OK */ - 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='') + 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='') { global $conf, $langs; //global $mysoc; @@ -270,6 +272,7 @@ class ProductFournisseur extends Product $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql.= " SET fk_user = " . $user->id." ,"; $sql.= " ref_fourn = '" . $this->db->escape($ref_fourn) . "',"; + $sql.= " desc_fourn = '" . $this->db->escape($desc_fourn) . "',"; $sql.= " price = ".price2num($buyprice).","; $sql.= " quantity = ".$qty.","; $sql.= " remise_percent = ".$remise_percent.","; @@ -336,7 +339,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, 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)"; $sql .= " values("; $sql.= (isset($multicurrency_buyprice)?"'".$this->db->escape(price2num($multicurrency_buyprice))."'":'null').","; $sql.= (isset($multicurrency_unitBuyPrice)?"'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'":'null').","; @@ -347,6 +350,7 @@ class ProductFournisseur extends Product $sql .= " " . $this->id . ","; $sql .= " " . $fourn->id . ","; $sql .= " '" . $this->db->escape($ref_fourn) . "',"; + $sql .= " '" . $this->db->escape($desc_fourn) . "',"; $sql .= " " . $user->id . ","; $sql .= " " . $buyprice . ","; $sql .= " " . $qty . ","; @@ -436,7 +440,7 @@ class ProductFournisseur extends Product global $conf; $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.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,"; + $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"; $sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; @@ -456,6 +460,7 @@ class ProductFournisseur extends Product $this->fourn_id = $obj->fk_soc; $this->fourn_ref = $obj->ref_fourn; // deprecated $this->ref_supplier = $obj->ref_fourn; + $this->desc_supplier = $obj->desc_fourn; $this->fourn_price = $obj->price; $this->fourn_charges = $obj->charges; // deprecated $this->fourn_qty = $obj->quantity; @@ -525,7 +530,7 @@ class ProductFournisseur extends Product global $conf; $sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,"; - $sql.= " pfp.rowid as product_fourn_pri_id, pfp.ref_fourn, pfp.fk_product as product_fourn_id, pfp.fk_supplier_price_expression,"; + $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"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; @@ -553,6 +558,7 @@ class ProductFournisseur extends Product $prodfourn->product_fourn_id = $record["product_fourn_id"]; $prodfourn->fourn_ref = $record["ref_fourn"]; $prodfourn->ref_supplier = $record["ref_fourn"]; + $prodfourn->desc_supplier = $record["desc_fourn"]; $prodfourn->fourn_price = $record["price"]; $prodfourn->fourn_qty = $record["quantity"]; $prodfourn->fourn_remise_percent = $record["remise_percent"]; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 6dd13b4cb7d..7f4b3a0d37d 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -399,7 +399,11 @@ if (empty($reshook)) { $label = $productsupplier->label; - $desc = $productsupplier->description; + // if we use supplier description of the products + if(!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) { + $desc = $productsupplier->desc_supplier; + } else $desc = $productsupplier->description; + if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc); $type = $productsupplier->type; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index e8046aa9bd8..12a3e913e68 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1207,7 +1207,11 @@ if (empty($reshook)) { $label = $productsupplier->label; - $desc = $productsupplier->description; + // if we use supplier description of the products + if(!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) { + $desc = $productsupplier->desc_supplier; + } else $desc = $productsupplier->description; + if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc); $type = $productsupplier->type; 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 cbcb3bcacbb..f67839073f0 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 @@ -38,6 +38,7 @@ ALTER TABLE llx_accounting_account MODIFY COLUMN account_parent varchar(32) DEFA ALTER TABLE llx_extrafields ADD COLUMN help text NULL; ALTER TABLE llx_extrafields ADD COLUMN totalizable boolean DEFAULT FALSE after list; +ALTER TABLE llx_product_fournisseur_price ADD COLUMN desc_fourn text after ref_fourn; ALTER TABLE llx_user ADD COLUMN dateemploymentend date after dateemployment; diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql index ab2efba1455..daccb2d7927 100755 --- a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql +++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql @@ -28,6 +28,7 @@ create table llx_product_fournisseur_price fk_product integer, fk_soc integer, ref_fourn varchar(30), + desc_fourn text, fk_availability integer, price double(24,8) DEFAULT 0, -- price without tax for quantity quantity double, diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index ec890377d70..0dde8ad538a 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -293,7 +293,8 @@ ProductSheet=Product sheet ServiceSheet=Service sheet PossibleValues=Possible values GoOnMenuToCreateVairants=Go on menu %s - %s to prepare attribute variants (like colors, size, ...) - +UseProductFournDesc=Use supplier descriptions of products in supplier documents +ProductSupplierDescription=Supplier description for the product #Attributes VariantAttributes=Variant attributes ProductAttributes=Variant attributes for products diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 9b32720a9a8..ea3539d193e 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -144,6 +144,18 @@ if ($action == 'other') $value = GETPOST('activate_usesearchtoselectproduct','alpha'); $res = dolibarr_set_const($db, "PRODUIT_USE_SEARCH_TO_SELECT", $value,'chaine',0,'',$conf->entity); + + $value = GETPOST('activate_useProdFournDesc', 'alpha'); + $res = dolibarr_set_const($db, "PRODUIT_FOURN_TEXTS", $value,'chaine',0,'',$conf->entity); + if ($value) { + $sql_test = "SELECT count(desc_fourn) as cpt FROM ".MAIN_DB_PREFIX."product_fournisseur_price WHERE 1"; + $resql = $db->query($sql_test); + if (!$resql && $db->lasterrno == 'DB_ERROR_NOSUCHFIELD') // if the field does not exist, we create it + { + $sql_new = "ALTER TABLE ".MAIN_DB_PREFIX."product_fournisseur_price ADD COLUMN desc_fourn text"; + $resql_new = $db->query($sql_new); + } + } } if ($action == 'specimen') // For products @@ -541,6 +553,7 @@ $rowspan = 4; if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $rowspan++; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) $rowspan++; if (! empty($conf->global->MAIN_MULTILANGS)) $rowspan++; +if (! empty($conf->fournisseur->enabled)) $rowspan++; print '