diff --git a/htdocs/margin/productMargins.php b/htdocs/margin/productMargins.php index cb67cb0d58f..25176220d49 100644 --- a/htdocs/margin/productMargins.php +++ b/htdocs/margin/productMargins.php @@ -1,6 +1,7 @@ * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2020 Alexandre Spangaro * * 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 ''; 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 "\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 "\n"; //print "".$product_static->getNomUrl(1)."\n"; } - print "".price(price2num($pv, 'MT'))."\n"; - print "".price(price2num($pa, 'MT'))."\n"; - print "".price(price2num($marge, 'MT'))."\n"; + print "".$qty."\n"; + print "".price(price2num($pv, 'MT'))."\n"; + print "".price(price2num($pa, 'MT'))."\n"; + print "".price(price2num($marge, 'MT'))."\n"; if (!empty($conf->global->DISPLAY_MARGIN_RATES)) print "".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."\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 ''; else print ''; print $langs->trans('TotalMargin').""; - print "".price(price2num($cumul_vente, 'MT'))."\n"; - print "".price(price2num($cumul_achat, 'MT'))."\n"; - print "".price(price2num($totalMargin, 'MT'))."\n"; + print "".$cumul_qty.""; + print "".price(price2num($cumul_vente, 'MT'))."\n"; + print "".price(price2num($cumul_achat, 'MT'))."\n"; + print "".price(price2num($totalMargin, 'MT'))."\n"; if (!empty($conf->global->DISPLAY_MARGIN_RATES)) print "".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."\n"; if (!empty($conf->global->DISPLAY_MARK_RATES))