From 2b010c9ba492aaa1f28e399a5fff54c659813fbd Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 6 Sep 2012 13:49:39 +0200 Subject: [PATCH] dont use lines without buying price for margin calculation if ForceBuyPriceIfNull is set --- htdocs/commissions/index.php | 2 ++ htdocs/margin/agentMargins.php | 2 ++ htdocs/margin/customerMargins.php | 2 ++ htdocs/margin/productMargins.php | 2 ++ htdocs/margin/tabs/productMargins.php | 2 ++ htdocs/margin/tabs/thirdpartyMargins.php | 2 ++ 6 files changed, 12 insertions(+) diff --git a/htdocs/commissions/index.php b/htdocs/commissions/index.php index c2ec0e4ef88..0a9c37abb4b 100644 --- a/htdocs/commissions/index.php +++ b/htdocs/commissions/index.php @@ -166,6 +166,8 @@ if (!empty($startdate)) $sql.= " AND f.datef >= '".$startdate."'"; if (!empty($enddate)) $sql.= " AND f.datef <= '".$enddate."'"; +if (($conf->global->COMMISSION_BASE == "MARGIN") && isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) + $sql .= " AND d.buy_price_ht <> 0"; if ($agentid > 0) $sql.= " GROUP BY s.rowid"; else diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index 1ee828a95a2..5d7e4d389fe 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -141,6 +141,8 @@ if (!empty($startdate)) $sql.= " AND f.datef >= '".$startdate."'"; if (!empty($enddate)) $sql.= " AND f.datef <= '".$enddate."'"; +if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) + $sql .= " AND d.buy_price_ht <> 0"; if ($agentid > 0) $sql.= " GROUP BY s.rowid"; else diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php index 0bfc0178be1..665624ffa53 100644 --- a/htdocs/margin/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -158,6 +158,8 @@ if (!empty($startdate)) $sql.= " AND f.datef >= '".$startdate."'"; if (!empty($enddate)) $sql.= " AND f.datef <= '".$enddate."'"; +if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) + $sql .= " AND d.buy_price_ht <> 0"; if ($client) $sql.= " GROUP BY f.rowid"; else diff --git a/htdocs/margin/productMargins.php b/htdocs/margin/productMargins.php index bf6e96726fb..d91cec567e0 100644 --- a/htdocs/margin/productMargins.php +++ b/htdocs/margin/productMargins.php @@ -162,6 +162,8 @@ if (!empty($startdate)) $sql.= " AND f.datef >= '".$startdate."'"; if (!empty($enddate)) $sql.= " AND f.datef <= '".$enddate."'"; +if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) + $sql .= " AND d.buy_price_ht <> 0"; if ($id > 0) $sql.= " GROUP BY f.rowid"; else diff --git a/htdocs/margin/tabs/productMargins.php b/htdocs/margin/tabs/productMargins.php index 732589eabc4..646b84fee88 100644 --- a/htdocs/margin/tabs/productMargins.php +++ b/htdocs/margin/tabs/productMargins.php @@ -142,6 +142,8 @@ if ($id > 0 || ! empty($ref)) $sql.= " AND s.entity = ".$conf->entity; $sql.= " AND d.fk_facture = f.rowid"; $sql.= " AND d.fk_product =".$object->id; + if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) + $sql .= " AND d.buy_price_ht <> 0"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (! empty($socid)) $sql.= " AND f.fk_soc = $socid"; $sql.= " ORDER BY $sortfield $sortorder "; diff --git a/htdocs/margin/tabs/thirdpartyMargins.php b/htdocs/margin/tabs/thirdpartyMargins.php index ff6aa959b09..3689afd240f 100644 --- a/htdocs/margin/tabs/thirdpartyMargins.php +++ b/htdocs/margin/tabs/thirdpartyMargins.php @@ -138,6 +138,8 @@ if ($socid > 0) $sql.= " AND s.entity = ".$conf->entity; $sql.= " AND d.fk_facture = f.rowid"; $sql.= " AND f.fk_soc = $socid"; + if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) + $sql .= " AND d.buy_price_ht <> 0"; $sql.= " GROUP BY f.rowid"; $sql.= " ORDER BY $sortfield $sortorder "; $sql.= $db->plimit($conf->liste_limit +1, $offset);