Fix: Bug into sql request because of incomplete group by
This commit is contained in:
parent
ccc40362e7
commit
be97066a74
@ -130,10 +130,8 @@ if ($agentid > 0) {
|
|||||||
else
|
else
|
||||||
$sql .= " AND sc.fk_user = ".$agentid;
|
$sql .= " AND sc.fk_user = ".$agentid;
|
||||||
}
|
}
|
||||||
if (!empty($startdate))
|
if (!empty($startdate)) $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
|
||||||
$sql.= " AND f.datef >= '".$db->idate($startdate)."'";
|
if (!empty($enddate)) $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
|
||||||
if (!empty($enddate))
|
|
||||||
$sql.= " AND f.datef <= '".$db->idate($enddate)."'";
|
|
||||||
$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";
|
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
|
||||||
$sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
|
$sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
|
||||||
|
|||||||
@ -172,17 +172,13 @@ $sql.= " WHERE f.fk_soc = s.rowid";
|
|||||||
$sql.= " AND f.fk_statut > 0";
|
$sql.= " AND f.fk_statut > 0";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND d.fk_facture = f.rowid";
|
$sql.= " AND d.fk_facture = f.rowid";
|
||||||
if ($client)
|
if ($client) $sql.= " AND f.fk_soc = ".$socid;
|
||||||
$sql.= " AND f.fk_soc = ".$socid;
|
if (!empty($startdate)) $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
|
||||||
if (!empty($startdate))
|
if (!empty($enddate)) $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
|
||||||
$sql.= " AND f.datef >= '".$db->idate($startdate)."'";
|
|
||||||
if (!empty($enddate))
|
|
||||||
$sql.= " AND f.datef <= '".$db->idate($enddate)."'";
|
|
||||||
$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)
|
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
|
||||||
$sql .= " AND d.buy_price_ht <> 0";
|
$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";
|
||||||
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";
|
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
|
||||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
|
|
||||||
|
|||||||
@ -178,17 +178,12 @@ $sql.= " AND f.fk_soc = s.rowid";
|
|||||||
$sql.= " AND d.fk_product = p.rowid";
|
$sql.= " AND d.fk_product = p.rowid";
|
||||||
$sql.= " AND f.fk_statut > 0";
|
$sql.= " AND f.fk_statut > 0";
|
||||||
$sql.= " AND d.fk_facture = f.rowid";
|
$sql.= " AND d.fk_facture = f.rowid";
|
||||||
if ($id > 0)
|
if ($id > 0) $sql.= " AND d.fk_product =".$id;
|
||||||
$sql.= " AND d.fk_product =".$id;
|
if (!empty($startdate)) $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
|
||||||
if (!empty($startdate))
|
if (!empty($enddate)) $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
|
||||||
$sql.= " AND f.datef >= '".$db->idate($startdate)."'";
|
|
||||||
if (!empty($enddate))
|
|
||||||
$sql.= " AND f.datef <= '".$db->idate($enddate)."'";
|
|
||||||
$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)
|
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
|
||||||
$sql .= " AND d.buy_price_ht <> 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";
|
||||||
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";
|
|
||||||
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
|
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
|
|||||||
@ -129,13 +129,13 @@ if ($id > 0 || ! empty($ref))
|
|||||||
|
|
||||||
|
|
||||||
$sql = "SELECT s.nom, s.rowid as socid, s.code_client,";
|
$sql = "SELECT s.nom, s.rowid as socid, s.code_client,";
|
||||||
$sql.= " f.facnumber, f.total as total_ht,";
|
$sql.= " f.rowid as facid, f.facnumber, f.total as total_ht,";
|
||||||
|
$sql.= " f.datef, f.paye, f.fk_statut as statut,";
|
||||||
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,";
|
||||||
$sql.= " sum(d.total_ht) as selling_price,";
|
$sql.= " sum(d.total_ht) as selling_price,";
|
||||||
$sql.= $db->ifsql('f.type =2','sum(d.qty *-1)','sum(d.qty)')." as qty,";
|
$sql.= $db->ifsql('f.type =2','sum(d.qty *-1)','sum(d.qty)')." as qty,";
|
||||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid,";
|
|
||||||
$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(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.= $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" ;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
|
$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
|
||||||
@ -148,10 +148,10 @@ if ($id > 0 || ! empty($ref))
|
|||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
|
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";
|
if (! empty($socid)) $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)
|
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
|
||||||
$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 f.rowid";
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user";
|
||||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
dol_syslog('margin:tabs:productMargins.php sql='.$sql,LOG_DEBUG);
|
dol_syslog('margin:tabs:productMargins.php sql='.$sql,LOG_DEBUG);
|
||||||
|
|||||||
@ -127,12 +127,11 @@ if ($socid > 0)
|
|||||||
|
|
||||||
|
|
||||||
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
|
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
|
||||||
$sql.= " f.facnumber, f.total as total_ht,";
|
$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.= " 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(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.= $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.rowid as facid";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
|
$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
|
||||||
@ -142,10 +141,9 @@ if ($socid > 0)
|
|||||||
$sql.= " AND d.fk_facture = f.rowid";
|
$sql.= " AND d.fk_facture = f.rowid";
|
||||||
$sql.= " AND f.fk_soc = $socid";
|
$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)
|
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
|
||||||
$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 f.rowid";
|
$sql.= " ORDER BY ".$sortfield." ".$sortorder;
|
||||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user