NEW: Add column quantity in product margin page
This commit is contained in:
parent
cb5577826d
commit
e4cc3e1b2c
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
|
||||
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
|
||||
* Copyright (C) 2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -180,6 +181,7 @@ if ($id > 0) $sql .= " d.fk_product,";
|
||||
if ($id > 0) $sql .= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
|
||||
$sql .= " SUM(d.total_ht) as selling_price,";
|
||||
// Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this)
|
||||
$sql .= " SUM(d.qty) as product_qty,";
|
||||
$sql .= " SUM(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1 * (d.situation_percent / 100)', 'd.qty * d.buy_price_ht * (d.situation_percent / 100)').") as buying_price,";
|
||||
$sql .= " SUM(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100)))', 'd.total_ht - (d.buy_price_ht * d.qty * (d.situation_percent / 100))').") as marge";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
@ -235,27 +237,30 @@ if ($result)
|
||||
print '<tr class="liste_titre">';
|
||||
if ($id > 0) {
|
||||
print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&id=".$id, '', $sortfield, $sortorder);
|
||||
print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&id=".$id, 'align="center"', $sortfield, $sortorder);
|
||||
print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&id=".$id, '', $sortfield, $sortorder, 'center ');
|
||||
} else {
|
||||
print_liste_field_titre("ProductService", $_SERVER["PHP_SELF"], "p.ref", "", "&id=".$id, '', $sortfield, $sortorder);
|
||||
}
|
||||
print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&id=".$id, 'align="right"', $sortfield, $sortorder);
|
||||
print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", "&id=".$id, 'align="right"', $sortfield, $sortorder);
|
||||
print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&id=".$id, 'align="right"', $sortfield, $sortorder);
|
||||
print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "product_qty", "", "&id=".$id, '', $sortfield, $sortorder,'center ');
|
||||
print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&id=".$id, '', $sortfield, $sortorder, 'right ');
|
||||
print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", "&id=".$id, '', $sortfield, $sortorder, 'right ');
|
||||
print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&id=".$id, '', $sortfield, $sortorder, 'right ');
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&id=".$id, 'align="right"', $sortfield, $sortorder);
|
||||
print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&id=".$id, '', $sortfield, $sortorder, 'right ');
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&id=".$id, 'align="right"', $sortfield, $sortorder);
|
||||
print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&id=".$id, '', $sortfield, $sortorder, 'right ');
|
||||
print "</tr>\n";
|
||||
|
||||
$cumul_achat = 0;
|
||||
$cumul_vente = 0;
|
||||
$cumul_qty = 0;
|
||||
|
||||
if ($num > 0)
|
||||
{
|
||||
while ($i < $num /*&& $i < $conf->liste_limit*/)
|
||||
{
|
||||
$objp = $db->fetch_object($result);
|
||||
$qty = $objp->product_qty;
|
||||
$pa = $objp->buying_price;
|
||||
$pv = $objp->selling_price;
|
||||
$marge = $objp->marge;
|
||||
@ -295,9 +300,10 @@ if ($result)
|
||||
print "</td>\n";
|
||||
//print "<td>".$product_static->getNomUrl(1)."</td>\n";
|
||||
}
|
||||
print "<td class=\"right\">".price(price2num($pv, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($pa, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($marge, 'MT'))."</td>\n";
|
||||
print "<td class=\"center\">".$qty."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($pv, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($pa, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($marge, 'MT'))."</td>\n";
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
@ -307,6 +313,7 @@ if ($result)
|
||||
$i++;
|
||||
$cumul_achat += $objp->buying_price;
|
||||
$cumul_vente += $objp->selling_price;
|
||||
$cumul_qty += $objp->product_qty;
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,9 +329,10 @@ if ($result)
|
||||
print '<td colspan=2>';
|
||||
else print '<td>';
|
||||
print $langs->trans('TotalMargin')."</td>";
|
||||
print "<td class=\"right\">".price(price2num($cumul_vente, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($cumul_achat, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($totalMargin, 'MT'))."</td>\n";
|
||||
print "<td class=\"center\">".$cumul_qty."</td>";
|
||||
print "<td class=\"nowrap right\">".price(price2num($cumul_vente, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($cumul_achat, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($totalMargin, 'MT'))."</td>\n";
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user