From 61a077b0ee563a7f24e3ca96040d9bd9717044bb Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Mon, 4 Apr 2016 15:06:54 +0200 Subject: [PATCH 1/4] NEW reputation for price supplier --- .../fourn/class/fournisseur.product.class.php | 21 ++++++++++++------- htdocs/langs/en_US/suppliers.lang | 4 ++++ htdocs/product/fournisseurs.php | 14 +++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 857544aa1bc..69208e5278e 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -178,9 +178,10 @@ class ProductFournisseur extends Product * @param float $remise Discount regarding qty (amount) * @param int $newnpr Set NPR or not * @param int $delivery_time_days Delay in days for delivery (max). May be '' if not defined. + * @param string $supplier_reputation Reputation with this product to the defined supplier (empty, FAVORITE, DONOTORDER) * @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) + 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='') { global $conf, $langs; //global $mysoc; @@ -191,6 +192,7 @@ class ProductFournisseur extends Product if (empty($charges)) $charges=0; if (empty($availability)) $availability=0; if (empty($remise_percent)) $remise_percent=0; + if (empty($supplier_reputation)) $supplier_reputation=''; if ($delivery_time_days != '' && ! is_numeric($delivery_time_days)) $delivery_time_days = ''; if ($price_base_type == 'TTC') { @@ -225,7 +227,8 @@ class ProductFournisseur extends Product $sql.= " entity = ".$conf->entity.","; $sql.= " info_bits = ".$newnpr.","; $sql.= " charges = ".$charges.","; - $sql.= " delivery_time_days = ".($delivery_time_days != '' ? $delivery_time_days : 'null'); + $sql.= " delivery_time_days = ".($delivery_time_days != '' ? $delivery_time_days : 'null').","; + $sql.= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'"); $sql.= " WHERE rowid = ".$this->product_fourn_price_id; // TODO Add price_base_type and price_ttc @@ -268,7 +271,7 @@ class ProductFournisseur extends Product { // Add price for this quantity to supplier $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price("; - $sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, unitcharges, fk_availability, info_bits, entity, delivery_time_days)"; + $sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, unitcharges, fk_availability, info_bits, entity, delivery_time_days,supplier_reputation)"; $sql.= " values('".$this->db->idate($now)."',"; $sql.= " ".$this->id.","; $sql.= " ".$fourn->id.","; @@ -285,8 +288,9 @@ class ProductFournisseur extends Product $sql.= " ".$availability.","; $sql.= " ".$newnpr.","; $sql.= $conf->entity.","; - $sql.= $delivery_time_days; - $sql.=")"; + $sql.= $delivery_time_days.","; + $sql.= (empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'"); + $sql.=")"; dol_syslog(get_class($this)."::update_buyprice", LOG_DEBUG); if (! $this->db->query($sql)) @@ -359,7 +363,8 @@ 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.fk_availability,"; - $sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges, pfp.fk_supplier_price_expression, pfp.delivery_time_days"; // , pfp.recuperableonly as fourn_tva_npr"; FIXME this field not exist in llx_product_fournisseur_price + $sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,"; // , pfp.recuperableonly as fourn_tva_npr"; FIXME this field not exist in llx_product_fournisseur_price + $sql.=" pfp.supplier_reputation"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " WHERE pfp.rowid = ".$rowid; @@ -389,6 +394,7 @@ class ProductFournisseur extends Product $this->delivery_time_days = $obj->delivery_time_days; //$this->fourn_tva_npr = $obj->fourn_tva_npr; // TODO this field not exist in llx_product_fournisseur_price. We should add it ? $this->fk_supplier_price_expression = $obj->fk_supplier_price_expression; + $this->supplier_reputation = $obj->supplier_reputation; if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) { @@ -437,7 +443,7 @@ 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.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.unitcharges, pfp.info_bits, pfp.delivery_time_days"; + $sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.unitcharges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= ", ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE pfp.entity IN (".getEntity('product', 1).")"; @@ -476,6 +482,7 @@ class ProductFournisseur extends Product $prodfourn->id = $prodid; $prodfourn->fourn_tva_npr = $record["info_bits"]; $prodfourn->fk_supplier_price_expression = $record["fk_supplier_price_expression"]; + $prodfourn->supplier_reputation = $record["supplier_reputation"]; if (!empty($conf->dynamicprices->enabled) && !empty($prodfourn->fk_supplier_price_expression)) { $priceparser = new PriceParser($this->db); diff --git a/htdocs/langs/en_US/suppliers.lang b/htdocs/langs/en_US/suppliers.lang index 46b7eb676d4..759c3c54fc5 100644 --- a/htdocs/langs/en_US/suppliers.lang +++ b/htdocs/langs/en_US/suppliers.lang @@ -45,3 +45,7 @@ MenuOrdersSupplierToBill=Supplier orders to invoice NbDaysToDelivery=Delivery delay in days DescNbDaysToDelivery=The biggest deliver delay of the products from this order UseDoubleApproval=Use double approval when amount (without tax) is higher than (The second approval can be done by any user with the dedicated permission. Set to 0 for no double approval) +SupplierReputation=Supplier reputation +DoNotOrderThisProductToThisSupplier=Do not order +NotTheGoodQualitySupplier=Wrong quality +ReputationForThisProduct=Reputation \ No newline at end of file diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index f5fc8c8655c..34f9995267c 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -77,6 +77,8 @@ if ($id > 0 || $ref) $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); +$reputations=array(''=>$langs->trans('Standard'),'FAVORITE'=>$langs->trans('Favorite'),'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier')); + if (! $sortfield) $sortfield="s.nom"; if (! $sortorder) $sortorder="ASC"; @@ -141,6 +143,7 @@ if (empty($reshook)) $tva_tx = price2num($tva_tx); $price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode $delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : ''; + $supplier_reputation = GETPOST('supplier_reputation'); if ($tva_tx == '') { @@ -379,6 +382,11 @@ if ($id > 0 || $ref) } print ''; + //reputation + print ''.$langs->trans("SupplierReputation").''; + echo $form->selectarray('supplier_reputation', $reputations,$product->supplier_reputation); + print ''; + // Ref supplier print ''.$langs->trans("SupplierRef").''; if ($rowid) @@ -566,6 +574,7 @@ if ($id > 0 || $ref) $param="&id=".$object->id; print ''; print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("ReputationForThisProduct")); print_liste_field_titre($langs->trans("SupplierRef")); if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder); @@ -597,6 +606,11 @@ if ($id > 0 || $ref) print ""; print ''.$productfourn->getSocNomUrl(1,'supplier').''; + print ''; + if(!empty($productfourn->supplier_reputation) && !empty($reputations[$productfourn->supplier_reputation])) { + print $reputations[$productfourn->supplier_reputation]; + } + print''; // Supplier print ''.$productfourn->fourn_ref.''; From c2a5ad7d9c800c32cadc6cabc0d456d9c6a32358 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Wed, 6 Apr 2016 10:05:03 +0200 Subject: [PATCH 2/4] FIX sql --- htdocs/install/mysql/migration/3.9.0-4.0.0.sql | 1 + htdocs/install/mysql/tables/llx_product_fournisseur_price.sql | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index 298ffda51cf..fd144ec5479 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -353,3 +353,4 @@ CREATE UNIQUE INDEX uk_bordereau_cheque ON llx_bordereau_cheque (ref, entity); ALTER TABLE llx_societe_rib ADD COLUMN date_rum date after rum; +ALTER TABLE llx_product_fournisseur_price ADD supplier_reputation varchar(10) NULL; diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql index e7cf555d24e..717f0617c83 100755 --- a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql +++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql @@ -41,5 +41,6 @@ create table llx_product_fournisseur_price fk_user integer, fk_supplier_price_expression integer, -- Link to the rule for dynamic price calculation import_key varchar(14), -- Import key - delivery_time_days integer + delivery_time_days integer, + supplier_reputation varchar(10) )ENGINE=innodb; From 11bb4d1cfb425025f3906ffd3832270d63af2056 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Wed, 6 Apr 2016 10:17:13 +0200 Subject: [PATCH 3/4] Show in select --- htdocs/core/class/html.form.class.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 1e60fb11377..8ba5766e826 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2095,7 +2095,8 @@ class Form $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration, p.fk_product_type,"; $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.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,"; + $sql.= " pfp.supplier_reputation"; $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; @@ -2234,6 +2235,15 @@ class Form $opt .= " - ".dol_trunc($objp->name,8); $outval.=" - ".dol_trunc($objp->name,8); } + if ($objp->supplier_reputation) + { + //TODO dictionnary + $reputations=array(''=>$langs->trans('Standard'),'FAVORITE'=>$langs->trans('Favorite'),'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier')); + + $opt .= " - ".$reputations[$objp->supplier_reputation] + $outval.=" - ".$reputations[$objp->supplier_reputation]; + } + } else { From a2c5bfa72c971ae2575159d2a23c91ec391dd9a2 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Wed, 6 Apr 2016 10:20:38 +0200 Subject: [PATCH 4/4] FIX parse error --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8ba5766e826..81c0735b9a0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2240,7 +2240,7 @@ class Form //TODO dictionnary $reputations=array(''=>$langs->trans('Standard'),'FAVORITE'=>$langs->trans('Favorite'),'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier')); - $opt .= " - ".$reputations[$objp->supplier_reputation] + $opt .= " - ".$reputations[$objp->supplier_reputation]; $outval.=" - ".$reputations[$objp->supplier_reputation]; }