Fix : stats were wrong if same product on several lines with same quantity because of distinct

This commit is contained in:
Maxime Kohlhaas 2015-10-30 09:50:04 +01:00
parent bd69830cbd
commit c46f9350a5
5 changed files with 14 additions and 9 deletions

View File

@ -118,8 +118,8 @@ if ($id > 0 || ! empty($ref))
print '</div>';
$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, c.rowid, c.total_ht as total_ht, c.ref,";
$sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.qty";
$sql = "SELECT s.nom as name, s.rowid as socid, s.code_client, c.rowid, c.total_ht as total_ht, c.ref,";
$sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, SUM(d.qty) as qty";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."commande as c";
@ -131,6 +131,7 @@ if ($id > 0 || ! empty($ref))
$sql.= " AND d.fk_product =".$product->id;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
$sql.= " GROUP BY c.rowid ";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);

View File

@ -112,7 +112,7 @@ if ($id > 0 || ! empty($ref))
$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,";
$sql.= " c.rowid, c.total_ht as total_ht, c.ref,";
$sql.= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, d.qty";
$sql.= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, SUM(d.qty) as qty";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
@ -124,6 +124,7 @@ if ($id > 0 || ! empty($ref))
$sql.= " AND d.fk_product =".$product->id;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
$sql.= " GROUP BY c.rowid ";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);

View File

@ -124,9 +124,9 @@ if ($id > 0 || ! empty($ref))
if ($user->rights->facture->lire) {
$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,";
$sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,";
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty";
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, SUM(d.qty) as qty";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
@ -138,6 +138,7 @@ if ($id > 0 || ! empty($ref))
$sql.= " AND d.fk_product =".$product->id;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = $socid";
$sql.= " GROUP BY f.rowid ";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);

View File

@ -122,8 +122,8 @@ if ($id > 0 || ! empty($ref))
print '</div>';
$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, f.ref, f.total_ht as total_ht,";
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty";
$sql = "SELECT s.nom as name, s.rowid as socid, s.code_client, f.ref, f.total_ht as total_ht,";
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, SUM(d.qty) as qty";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
@ -135,6 +135,7 @@ if ($id > 0 || ! empty($ref))
$sql.= " AND d.fk_product =".$product->id;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid;
$sql.= " GROUP BY f.rowid ";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);

View File

@ -113,8 +113,8 @@ if ($id > 0 || ! empty($ref))
print '</div>';
$sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, p.total_ht as amount,";
$sql.= "p.datep, p.fk_statut as statut, d.qty";
$sql = "SELECT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, p.total_ht as amount,";
$sql.= "p.datep, p.fk_statut as statut, SUM(d.qty) as qty";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ",".MAIN_DB_PREFIX."propal as p";
@ -126,6 +126,7 @@ if ($id > 0 || ! empty($ref))
$sql.= " AND d.fk_product =".$product->id;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND p.fk_soc = ".$socid;
$sql.= " GROUP BY p.rowid ";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);