From c1859d361a82e9c7380f509ecdb1711208da13aa Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 28 Aug 2012 10:13:58 +0200 Subject: [PATCH] modify margin management for global discount + correct bug (wrong constant name) --- htdocs/comm/propal/class/propal.class.php | 8 ++++---- htdocs/commande/class/commande.class.php | 8 ++++---- htdocs/compta/facture/class/facture.class.php | 8 ++++---- htdocs/core/class/commonobject.class.php | 18 +++++++++--------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index c87c18d3d05..44d3c2f3f68 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2617,9 +2617,9 @@ class PropaleLigne if (empty($this->pa_ht)) $this->pa_ht=0; - // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente (idem pour remises) + // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { - if ($this->subprice < 0 || (isset($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice) && $conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1)) + if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } @@ -2754,9 +2754,9 @@ class PropaleLigne if (empty($this->pa_ht)) $this->pa_ht=0; - // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente (idem pour remises) + // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { - if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1)) + if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 877fd376942..a38422cd0eb 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3013,9 +3013,9 @@ class OrderLine if (empty($this->pa_ht)) $this->pa_ht=0; - // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente (idem pour remises) + // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { - if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1)) + if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } @@ -3115,9 +3115,9 @@ class OrderLine if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->pa_ht)) $this->pa_ht=0; - // si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises) + // si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { - if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1)) + if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index fcd550e6734..04fc64cdc6b 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3261,9 +3261,9 @@ class FactureLigne if (empty($this->pa_ht)) $this->pa_ht=0; - // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente (idem pour remises) + // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { - if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1)) + if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } @@ -3415,9 +3415,9 @@ class FactureLigne if (empty($this->pa_ht)) $this->pa_ht=0; - // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente (idem pour remises) + // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { - if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1)) + if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1fc0023ac3a..b6de06ce26b 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2888,26 +2888,26 @@ abstract class CommonObject $line->pa_ht += $product->fourn_unitcharges; } // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente - if ((!isset($line->pa_ht) || $line->pa_ht == 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { + if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100)); } // calcul des marges if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit - $marginInfos['pa_products'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); + $marginInfos['pa_products'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); $marginInfos['pv_products'] += $line->subprice * (1 - $line->remise_percent / 100); - $marginInfos['pa_total'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); + $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100); } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service - $marginInfos['pa_services'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); + $marginInfos['pa_services'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); $marginInfos['pv_services'] += $line->subprice * (1 - ($line->remise_percent / 100)); - $marginInfos['pa_total'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); + $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100); } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total - $marginInfos['pa_total'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); + $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100); $marginInfos['pv_total'] += $line->subprice * (1 - ($line->remise_percent / 100)); } } @@ -2963,8 +2963,8 @@ abstract class CommonObject print ''.$langs->trans('MarginRate').''; if($conf->global->DISPLAY_MARK_RATES) print ''.$langs->trans('MarkRate').''; - print ''; - if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { + print ''; + //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { print ''; print ''.$langs->trans('MarginOnProducts').''; print ''.price($marginInfo['pv_products']).''; @@ -2985,7 +2985,7 @@ abstract class CommonObject if($conf->global->DISPLAY_MARK_RATES) print ''.(($marginInfo['mark_rate_services'] == '')?'n/a':price($marginInfo['mark_rate_services']).'%').''; print ''; - } + //} print ''; print ''.$langs->trans('TotalMargin').''; print ''.price($marginInfo['pv_total']).'';