Skip to content

Commit

Permalink
Fix: fields into group by of sql requests for module margins must be
Browse files Browse the repository at this point in the history
same than fields into select.
  • Loading branch information
eldy committed Mar 30, 2014
1 parent c506e59 commit 95793a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
7 changes: 4 additions & 3 deletions htdocs/margin/agentMargins.php
Expand Up @@ -105,7 +105,8 @@
print "</table>";
print '</form>';

$sql = "SELECT s.rowid as socid, s.nom, s.code_client, s.client, ";
$sql = "SELECT";
if ($agentid > 0) $sql.= " s.rowid as socid, s.nom, s.code_client, s.client,";
$sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,";
$sql.= " sum(d.total_ht) as selling_price,";
$sql.= " sum(".$db->ifsql('d.total_ht <=0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
Expand Down Expand Up @@ -137,9 +138,9 @@
$sql.= " AND f.datef <= '".$db->idate($enddate)."'";
$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";
if($agentid) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
else $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname";
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
$sql.=$db->order($sortfield,$sortorder);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);

Expand Down
8 changes: 4 additions & 4 deletions htdocs/margin/customerMargins.php
Expand Up @@ -160,9 +160,9 @@
print "</table>";
print '</form>';

$sql = "SELECT s.rowid as socid, s.nom, s.code_client, s.client,";
$sql.= " f.rowid as facid, f.facnumber, f.total as total_ht,";
$sql.= " f.datef, f.paye, f.fk_statut as statut,";
$sql = "SELECT";
$sql.= " s.rowid as socid, s.nom, s.code_client, s.client,";
if ($client) $sql.= " f.rowid as facid, f.facnumber, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
$sql.= " sum(d.total_ht) as selling_price,";
$sql.= " sum(".$db->ifsql('d.total_ht <=0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
$sql.= " sum(".$db->ifsql('d.total_ht <=0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge";
Expand All @@ -184,7 +184,7 @@
$sql .= " AND d.buy_price_ht <> 0";
if ($client) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut";
else $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.=$db->order($sortfield,$sortorder);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);

Expand Down
13 changes: 5 additions & 8 deletions htdocs/margin/productMargins.php
Expand Up @@ -164,9 +164,8 @@
print '</form>';

$sql = "SELECT p.label, p.rowid, p.fk_product_type, p.ref,";
$sql.= " d.fk_product,";
$sql.= " f.rowid as facid, f.facnumber, f.total as total_ht,";
$sql.= " f.datef, f.paye, f.fk_statut as statut,";
if ($id > 0) $sql.= " d.fk_product,";
if ($id > 0) $sql.= " f.rowid as facid, f.facnumber, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
$sql.= " sum(d.total_ht) as selling_price,";
$sql.= " sum(".$db->ifsql('d.total_ht <=0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
$sql.= " sum(".$db->ifsql('d.total_ht <=0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge";
Expand All @@ -188,11 +187,9 @@
$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";
if ($id > 0)
$sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, d.fk_product, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut";
else
$sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref";
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
if ($id > 0) $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, d.fk_product, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut";
else $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref";
$sql.=$db->order($sortfield,$sortorder);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);

Expand Down

0 comments on commit 95793a5

Please sign in to comment.