From 163faf24014854857ade3e97b11a504920161873 Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Mon, 4 Mar 2019 11:19:54 +0100 Subject: [PATCH 1/2] Fix remove "canceled" invoices in margin by user --- htdocs/margin/agentMargins.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index 687a381d790..d2d125f38c0 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -132,6 +132,8 @@ dol_fiche_end(); print ''; +$invoice_status_except_list = array(Facture::STATUS_DRAFT, Facture::STATUS_ABANDONED); + $sql = "SELECT"; $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; $sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,"; @@ -153,7 +155,7 @@ if (! empty($conf->global->AGENT_CONTACT_TYPE)) $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; else $sql .= " AND sc.fk_user = u.rowid"; -$sql.= " AND f.fk_statut > 0"; +$sql.= " AND f.fk_statut NOT IN (" . implode(', ', $invoice_status_except_list) . ")"; $sql.= ' AND s.entity IN ('.getEntity('societe').')'; $sql.= " AND d.fk_facture = f.rowid"; if ($agentid > 0) { From 5cf8421d87d76853a977e20566fb14ddd193a7a5 Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Tue, 5 Mar 2019 09:56:49 +0100 Subject: [PATCH 2/2] Fix remove "canceled" invoices in all reports --- htdocs/margin/checkMargins.php | 3 ++- htdocs/margin/customerMargins.php | 4 +++- htdocs/margin/productMargins.php | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/margin/checkMargins.php b/htdocs/margin/checkMargins.php index d418aba780e..a05762b4bb5 100644 --- a/htdocs/margin/checkMargins.php +++ b/htdocs/margin/checkMargins.php @@ -183,6 +183,7 @@ dol_fiche_end(); $arrayfields=array(); $massactionbutton=''; +$invoice_status_except_list = array(Facture::STATUS_DRAFT, Facture::STATUS_ABANDONED); $sql = "SELECT"; $sql .= " f.ref, f.rowid as invoiceid, d.rowid as invoicedetid, d.buy_price_ht, d.total_ht, d.subprice, d.label, d.description , d.qty"; @@ -190,7 +191,7 @@ $sql .= " ,d.fk_product"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f "; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as d ON d.fk_facture = f.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid"; -$sql .= " WHERE f.fk_statut > 0"; +$sql .= " WHERE f.fk_statut NOT IN (" . implode(', ', $invoice_status_except_list) . ")"; $sql .= " AND f.entity IN (" . getEntity('invoice') . ") "; if (! empty($startdate)) $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'"; if (! empty($enddate)) $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'"; diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php index fa264a81920..cc5abb0ee38 100644 --- a/htdocs/margin/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -200,6 +200,8 @@ dol_fiche_end(); print ''; +$invoice_status_except_list = array(Facture::STATUS_DRAFT, Facture::STATUS_ABANDONED); + $sql = "SELECT"; $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; if ($client) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,"; @@ -218,7 +220,7 @@ if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PRE $sql.= " WHERE f.fk_soc = s.rowid"; if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; -$sql.= " AND f.fk_statut > 0"; +$sql.= " AND f.fk_statut NOT IN (" . implode(', ', $invoice_status_except_list) . ")"; $sql.= ' AND s.entity IN ('.getEntity('societe').')'; $sql.= " AND d.fk_facture = f.rowid"; $sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; diff --git a/htdocs/margin/productMargins.php b/htdocs/margin/productMargins.php index 95686967fd9..547bd3d205b 100644 --- a/htdocs/margin/productMargins.php +++ b/htdocs/margin/productMargins.php @@ -174,6 +174,8 @@ dol_fiche_end(); print ''; +$invoice_status_except_list = array(Facture::STATUS_DRAFT, Facture::STATUS_ABANDONED); + $sql = "SELECT p.label, p.rowid, p.fk_product_type, p.ref, p.entity as pentity,"; 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,"; @@ -190,7 +192,7 @@ if (! empty($TSelectedCats)) { } $sql.= " WHERE f.fk_soc = s.rowid"; $sql.= ' AND f.entity IN ('.getEntity('invoice').')'; -$sql.= " AND f.fk_statut > 0"; +$sql.= " AND f.fk_statut NOT IN (" . implode(', ', $invoice_status_except_list) . ")"; $sql.= " AND d.fk_facture = f.rowid"; if ($id > 0) $sql.= " AND d.fk_product =".$id;