Skip to content

Commit

Permalink
Fix: [ bug #1651 ] Can't display margins in thirdparty card
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Nov 21, 2014
1 parent f7a74a9 commit 32f4db2
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions htdocs/margin/tabs/thirdpartyMargins.php
Expand Up @@ -128,10 +128,10 @@

$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
$sql.= " f.rowid as facid, f.facnumber, f.total as total_ht,";
$sql.= " f.datef, f.paye, f.fk_statut as statut,";
$sql.= " sum(d.total_ht) as selling_price,";
$sql.= " ".$db->ifsql('f.type =2','sum(d.qty * d.buy_price_ht *-1)','sum(d.qty * d.buy_price_ht)')." as buying_price,";
$sql.= " ".$db->ifsql('f.type =2','sum(-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty)))','sum(d.total_ht - (d.buy_price_ht * d.qty))')." as marge";
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,";
$sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive
$sql.= " sum(d.qty * d.buy_price_ht) as buying_price,"; // always positive
$sql.= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // always positive
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
Expand All @@ -140,9 +140,9 @@
$sql.= " AND s.entity = ".$conf->entity;
$sql.= " AND d.fk_facture = f.rowid";
$sql.= " AND f.fk_soc = $socid";
$sql .= " AND d.buy_price_ht IS NOT NULL";
$sql.= " AND d.buy_price_ht IS NOT NULL";
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
$sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut";
$sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut, f.type";
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
Expand All @@ -153,7 +153,7 @@
{
$num = $db->num_rows($result);

print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=$societe->id",$sortfield,$sortorder,'',0,0,'');
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=".$societe->id,$sortfield,$sortorder,'',0,0,'');

$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
Expand Down Expand Up @@ -183,16 +183,8 @@
{
$objp = $db->fetch_object($result);

if ($objp->marge < 0)
{
$marginRate = ($objp->buying_price != 0)?-1*(100 * $objp->marge / $objp->buying_price):'' ;
$markRate = ($objp->selling_price != 0)?-1*(100 * $objp->marge / $objp->selling_price):'' ;
}
else
{
$marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
$markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;
}
$marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
$markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;

$var=!$var;

Expand All @@ -205,7 +197,7 @@
print "<td align=\"center\">";
print dol_print_date($db->jdate($objp->datef),'day')."</td>";
print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n";
print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n";
print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n";
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
Expand All @@ -214,7 +206,7 @@
print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
print "</tr>\n";
$i++;
$cumul_achat += $objp->buying_price;
$cumul_achat += (($objp->type == 2 ? -1 : 1) * $objp->buying_price);
$cumul_vente += $objp->selling_price;
}
}
Expand Down

0 comments on commit 32f4db2

Please sign in to comment.