From 3827a0679682a3602b134572e7347ae484441b23 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Fri, 8 Apr 2016 22:18:36 +0200
Subject: [PATCH] Debug the supplier ref reputation feature.

---
 .../fourn/class/fournisseur.product.class.php |  2 +-
 htdocs/product/fournisseurs.php               | 55 +++++++++----------
 2 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php
index 69208e5278e..d346d885a4f 100644
--- a/htdocs/fourn/class/fournisseur.product.class.php
+++ b/htdocs/fourn/class/fournisseur.product.class.php
@@ -192,7 +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 (empty($supplier_reputation) || $supplier_reputation == -1) $supplier_reputation='';
         if ($delivery_time_days != '' && ! is_numeric($delivery_time_days)) $delivery_time_days = '';
         if ($price_base_type == 'TTC')
 		{
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index 34f9995267c..ff37543f42e 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -77,7 +77,7 @@ 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'));
+$reputations=array('-1'=>'', 'FAVORITE'=>$langs->trans('Favorite'),'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier'));
 
 if (! $sortfield) $sortfield="s.nom";
 if (! $sortorder) $sortorder="ASC";
@@ -219,7 +219,7 @@ if (empty($reshook))
 				if (isset($_POST['ref_fourn_price_id']))
 					$object->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
 
-				$ret=$object->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days);
+				$ret=$object->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation);
 				if ($ret < 0)
 				{
 
@@ -352,6 +352,7 @@ if ($id > 0 || $ref)
 
 				print '<table class="border" width="100%">';
 
+				// Supplier
 				print '<tr><td class="fieldrequired" width="25%">'.$langs->trans("Supplier").'</td><td>';
 				if ($rowid)
 				{
@@ -368,7 +369,7 @@ if ($id > 0 || $ref)
 				{
 					$events=array();
 					$events[]=array('method' => 'getVatRates', 'url' => dol_buildpath('/core/ajax/vatrates.php',1), 'htmlname' => 'tva_tx', 'params' => array());
-					print $form->select_company(GETPOST("id_fourn"),'id_fourn','fournisseur=1',1,0,0,$events);
+					print $form->select_company(GETPOST("id_fourn"),'id_fourn','fournisseur=1','SelectThirdParty',0,0,$events);
 
 					$parameters=array('filtre'=>"fournisseur=1",'html_name'=>'id_fourn','selected'=>GETPOST("id_fourn"),'showempty'=>1,'prod_id'=>$object->id);
 				    $reshook=$hookmanager->executeHooks('formCreateThirdpartyOptions',$parameters,$object,$action);
@@ -382,11 +383,6 @@ if ($id > 0 || $ref)
 				}
 				print '</td></tr>';
 
-				//reputation
-				print '<tr><td class="fieldrequired">'.$langs->trans("SupplierReputation").'</td><td>';
-				echo $form->selectarray('supplier_reputation', $reputations,$product->supplier_reputation);
-				print '</td></tr>';
-
 				// Ref supplier
 				print '<tr><td class="fieldrequired">'.$langs->trans("SupplierRef").'</td><td>';
 				if ($rowid)
@@ -510,6 +506,11 @@ if ($id > 0 || $ref)
 				print '<td><input class="flat" name="delivery_time_days" size="4" value="'.($rowid ? $object->delivery_time_days : '').'">&nbsp;'.$langs->trans('days').'</td>';
 				print '</tr>';
 
+				// Reputation
+				print '<tr><td>'.$langs->trans("SupplierReputation").'</td><td>';
+				echo $form->selectarray('supplier_reputation', $reputations, $supplier_reputation?$supplier_reputation:$object->supplier_reputation);
+				print '</td></tr>';
+
 				// Option to define a transport cost on supplier price
 				if ($conf->global->PRODUCT_CHARGES)
 				{
@@ -574,7 +575,6 @@ if ($id > 0 || $ref)
 				$param="&id=".$object->id;
 				print '<tr class="liste_titre">';
 				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);
@@ -583,7 +583,8 @@ if ($id > 0 || $ref)
 				print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
 				print_liste_field_titre($langs->trans("DiscountQtyMin"),$_SERVER["PHP_SELF"],'','',$param,'align="right"',$sortfield,$sortorder);
 				print_liste_field_titre($langs->trans("NbDaysToDelivery"),$_SERVER["PHP_SELF"],"pfp.delivery_time_days","",$param,'align="right"',$sortfield,$sortorder);
-
+				print_liste_field_titre($langs->trans("ReputationForThisProduct"),$_SERVER["PHP_SELF"],"pfp.supplier_reputation","",$param,'align="center"',$sortfield,$sortorder);
+				
 				// Charges ????
 				if ($conf->global->PRODUCT_CHARGES)
 				{
@@ -595,7 +596,7 @@ if ($id > 0 || $ref)
 				$product_fourn = new ProductFournisseur($db);
 				$product_fourn_list = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder);
 
-				if (count($product_fourn_list)>0)
+				if (is_array($product_fourn_list))
 				{
 					$var=true;
 
@@ -605,17 +606,13 @@ if ($id > 0 || $ref)
 
 						print "<tr ".$bc[$var].">";
 
+						// Supplier
 						print '<td>'.$productfourn->getSocNomUrl(1,'supplier').'</td>';
-						print '<td>';
-						if(!empty($productfourn->supplier_reputation) && !empty($reputations[$productfourn->supplier_reputation])) {
-							print $reputations[$productfourn->supplier_reputation];	
-						}  
-						print'</td>';
-
+						
 						// Supplier
 						print '<td align="left">'.$productfourn->fourn_ref.'</td>';
 
-						//Availability
+						// Availability
 						if(!empty($conf->global->FOURN_PRODUCT_AVAILABILITY))
 						{
 							$form->load_cache_availability();
@@ -638,17 +635,6 @@ if ($id > 0 || $ref)
 						print $productfourn->fourn_price?price($productfourn->fourn_price):"";
 						print '</td>';
 
-						// Charges ????
-						if ($conf->global->PRODUCT_CHARGES)
-						{
-							if (! empty($conf->margin->enabled))
-							{
-								print '<td align="right">';
-								print $productfourn->fourn_charges?price($productfourn->fourn_charges):"";
-								print '</td>';
-							}
-						}
-
 						// Unit price
 						print '<td align="right">';
 						print price($productfourn->fourn_unitprice);
@@ -665,6 +651,13 @@ if ($id > 0 || $ref)
 						print $productfourn->delivery_time_days;
 						print '</td>';
 
+						// Reputation
+						print '<td align="center">';
+						if (!empty($productfourn->supplier_reputation) && !empty($reputations[$productfourn->supplier_reputation])) {
+							print $reputations[$productfourn->supplier_reputation];	
+						}  
+						print'</td>';
+
 						// Charges ????
 						if ($conf->global->PRODUCT_CHARGES)
 						{
@@ -695,6 +688,10 @@ if ($id > 0 || $ref)
 						print '</tr>';
 					}
 				}
+				else
+				{
+				    dol_print_error($db);
+				}
 
 				print '</table>';
 			}
-- 
GitLab