From 49703240f7dc9b627a2ef79e97d1c97dd4f426ba Mon Sep 17 00:00:00 2001
From: Christophe Battarel <christophe.battarel@altairis.fr>
Date: Fri, 11 Jan 2013 15:39:11 +0100
Subject: [PATCH] show costprice instead of buyingprice if setup of margin
 module is costprice

---
 htdocs/core/class/commonobject.class.php             |  7 +++++--
 htdocs/core/tpl/freeproductline_create.tpl.php       |  8 +++++++-
 htdocs/core/tpl/predefinedproductline_create.tpl.php | 10 ++++++++--
 htdocs/fourn/ajax/getSupplierPrices.php              |  7 ++-----
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index d83208c5c1b..9a6838d4886 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2629,7 +2629,7 @@ abstract class CommonObject
 			if ($conf->global->MARGIN_TYPE == "1")
 				print '<td align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
 			else
-				print '<td align="right" width="80">'.$langs->trans('BuyingCost').'</td>';
+				print '<td align="right" width="80">'.$langs->trans('CostPrice').'</td>';
 			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
 				print '<td align="right" width="50">'.$langs->trans('MarginRate').'</td>';
 			if (! empty($conf->global->DISPLAY_MARK_RATES))
@@ -3029,7 +3029,10 @@ abstract class CommonObject
     print '<tr class="liste_titre">';
     print '<td width="30%">'.$langs->trans('Margins').'</td>';
     print '<td width="20%" align="right">'.$langs->trans('SellingPrice').'</td>';
-    print '<td width="20%" align="right">'.$langs->trans('BuyingPrice').'</td>';
+	if ($conf->global->MARGIN_TYPE == "1")
+		print '<td width="20%" align="right">'.$langs->trans('BuyingPrice').'</td>';
+	else
+		print '<td width="20%" align="right">'.$langs->trans('CostPrice').'</td>';
     print '<td width="20%" align="right">'.$langs->trans('Margin').'</td>';
     if (! empty($conf->global->DISPLAY_MARGIN_RATES))
       print '<td align="right">'.$langs->trans('MarginRate').'</td>';
diff --git a/htdocs/core/tpl/freeproductline_create.tpl.php b/htdocs/core/tpl/freeproductline_create.tpl.php
index 5c4b055ddf0..1b8e4e6f2e9 100644
--- a/htdocs/core/tpl/freeproductline_create.tpl.php
+++ b/htdocs/core/tpl/freeproductline_create.tpl.php
@@ -44,7 +44,13 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
 	if (! empty($usemargins))
 	{
 		?>
-		<td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td>
+		<td align="right">
+		<?php
+		if ($conf->global->MARGIN_TYPE == "1")
+			echo $langs->trans('BuyingPrice');
+		else
+			echo $langs->trans('CostPrice');
+		?>
 		<?php
 		if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
 		if (! empty($conf->global->DISPLAY_MARK_RATES))   $colspan++;
diff --git a/htdocs/core/tpl/predefinedproductline_create.tpl.php b/htdocs/core/tpl/predefinedproductline_create.tpl.php
index 6bfd94fa817..0aa4dc107c2 100644
--- a/htdocs/core/tpl/predefinedproductline_create.tpl.php
+++ b/htdocs/core/tpl/predefinedproductline_create.tpl.php
@@ -50,8 +50,14 @@ if (! empty($usemargins))
 	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
 	if (! empty($conf->global->DISPLAY_MARK_RATES))   $colspan++;
 	?>
-	<td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td>
-	<?php 
+	<td align="right">
+	<?php
+	if ($conf->global->MARGIN_TYPE == "1")
+		echo $langs->trans('BuyingPrice');
+	else
+		echo $langs->trans('CostPrice');
+	?>
+	<?php
 } 
 ?>
 	<td colspan="<?php echo $colspan; ?>">&nbsp;</td>
diff --git a/htdocs/fourn/ajax/getSupplierPrices.php b/htdocs/fourn/ajax/getSupplierPrices.php
index 3dfe6de2d64..67ffbad93ce 100644
--- a/htdocs/fourn/ajax/getSupplierPrices.php
+++ b/htdocs/fourn/ajax/getSupplierPrices.php
@@ -73,12 +73,9 @@ if (! empty($idprod))
 				$objp = $db->fetch_object($result);
 
 				$title = $objp->nom.' - '.$objp->ref_fourn.' - ';
-				$label = '';
 
 				if ($objp->quantity == 1)
 				{
-					$label.= price($objp->fprice).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit"));
-
 					$title.= price($objp->fprice);
 					$title.= getCurrencySymbol($conf->currency)."/";
 
@@ -100,8 +97,6 @@ if (! empty($idprod))
 					$title.=" - ";
 					$title.= price($objp->unitprice).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit"));
 
-					$label.= price($objp->unitprice).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit"));
-
 					$price = $objp->unitprice;
 				}
 				if ($objp->unitcharges > 0 && ($conf->global->MARGIN_TYPE == "2")) {
@@ -111,6 +106,8 @@ if (! empty($idprod))
 				}
 				if ($objp->duration) $label .= " - ".$objp->duration;
 
+				$label = price($price).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit"));
+
 				$prices[] = array("id" => $objp->idprodfournprice, "price" => price($price,0,'',0), "label" => $label, "title" => $title);
 				$i++;
 			}
-- 
GitLab