From c46f9350a583a6bcbd92ba2dc1af3bc75e3d7607 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 30 Oct 2015 09:50:04 +0100 Subject: [PATCH] Fix : stats were wrong if same product on several lines with same quantity because of distinct --- htdocs/product/stats/commande.php | 5 +++-- htdocs/product/stats/commande_fournisseur.php | 3 ++- htdocs/product/stats/facture.php | 5 +++-- htdocs/product/stats/facture_fournisseur.php | 5 +++-- htdocs/product/stats/propal.php | 5 +++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php index 472b9ce4a45..d219088f9f9 100644 --- a/htdocs/product/stats/commande.php +++ b/htdocs/product/stats/commande.php @@ -118,8 +118,8 @@ if ($id > 0 || ! empty($ref)) print ''; - $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); diff --git a/htdocs/product/stats/commande_fournisseur.php b/htdocs/product/stats/commande_fournisseur.php index 73de0374ebe..92179547e58 100644 --- a/htdocs/product/stats/commande_fournisseur.php +++ b/htdocs/product/stats/commande_fournisseur.php @@ -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); diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index 49e5651b065..034ab4d9f30 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -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); diff --git a/htdocs/product/stats/facture_fournisseur.php b/htdocs/product/stats/facture_fournisseur.php index d8e30bdae6a..f1a8d908744 100644 --- a/htdocs/product/stats/facture_fournisseur.php +++ b/htdocs/product/stats/facture_fournisseur.php @@ -122,8 +122,8 @@ if ($id > 0 || ! empty($ref)) print ''; - $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); diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index 566961d9c5f..1e76071c682 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -113,8 +113,8 @@ if ($id > 0 || ! empty($ref)) print ''; - $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);