From 196a745086c4fb7faab3bacc173ee8158b570bd7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Jul 2015 22:07:13 +0200 Subject: [PATCH] NEW Can filter proposal, orders or invoices with criteria "contain at least one product with following tag" --- htdocs/commande/list.php | 28 ++++++++++++++++++++++++---- htdocs/compta/facture/list.php | 29 ++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 1b3f8432b52..0ba8600e778 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -46,6 +46,7 @@ $orderyear=GETPOST("orderyear","int"); $ordermonth=GETPOST("ordermonth","int"); $deliveryyear=GETPOST("deliveryyear","int"); $deliverymonth=GETPOST("deliverymonth","int"); +$search_product_category=GETPOST('search_product_category','int'); $search_ref=GETPOST('search_ref','alpha')!=''?GETPOST('search_ref','alpha'):GETPOST('sref','alpha'); $search_ref_customer=GETPOST('search_ref_customer','alpha'); $search_company=GETPOST('search_company','alpha'); @@ -79,6 +80,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $search_categ=''; $search_user=''; $search_sale=''; + $search_product_category=''; $search_ref=''; $search_ref_customer=''; $search_company=''; @@ -115,10 +117,14 @@ $companystatic = new Societe($db); $help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes"; llxHeader('',$langs->trans("Orders"),$help_url); -$sql = 'SELECT s.nom as name, s.rowid as socid, s.client, s.code_client, c.rowid, c.ref, c.total_ht, c.tva as total_tva, c.total_ttc, c.ref_client,'; +$sql = 'SELECT'; +if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +$sql.= ' s.nom as name, s.rowid as socid, s.client, s.code_client, c.rowid, c.ref, c.total_ht, c.tva as total_tva, c.total_ttc, c.ref_client,'; $sql.= ' c.date_valid, c.date_commande, c.note_private, c.date_livraison as date_delivery, c.fk_statut, c.facture as facturee'; $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql.= ', '.MAIN_DB_PREFIX.'commande as c'; +if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande'; +if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if ($search_user > 0) @@ -128,7 +134,8 @@ if ($search_user > 0) } $sql.= ' WHERE c.fk_soc = s.rowid'; $sql.= ' AND c.entity IN ('.getEntity('commande', 1).')'; -if ($socid) $sql.= ' AND s.rowid = '.$socid; +if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; +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; if ($search_ref) $sql .= natural_search('c.ref', $search_ref); if ($sall) $sql .= natural_search(array('c.ref', 'c.note_private'), $sall); @@ -260,15 +267,28 @@ if ($resql) if ($user->rights->societe->client->voir || $socid) { $langs->load("commercial"); + $moreforfilter.='
'; $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user); - $moreforfilter.='       '; + $moreforfilter.='
'; } // If the user can view prospects other than his' if ($user->rights->societe->client->voir || $socid) { - $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; $moreforfilter.=$form->select_dolusers($search_user,'search_user',1); + $moreforfilter.='
'; + } + // If the user can view prospects other than his' + if ($conf->categorie->enabled && $user->rights->produit->lire) + { + include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': '; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); + $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1); + $moreforfilter.='
'; } if (! empty($moreforfilter)) { diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index a38049ae10f..fb2650b48ac 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -63,6 +63,7 @@ $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $lineid=GETPOST('lineid','int'); $userid=GETPOST('userid','int'); +$search_product_category=GETPOST('search_product_category','int'); $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha'); $search_refcustomer=GETPOST('search_refcustomer','alpha'); $search_societe=GETPOST('search_societe','alpha'); @@ -121,6 +122,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $search_categ=''; $search_user=''; $search_sale=''; + $search_product_category=''; $search_ref=''; $search_refcustomer=''; $search_societe=''; @@ -144,8 +146,8 @@ $formfile = new FormFile($db); $bankaccountstatic=new Account($db); $facturestatic=new Facture($db); -if (! $sall) $sql = 'SELECT'; -else $sql = 'SELECT DISTINCT'; +$sql = 'SELECT'; +if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; $sql.= ' f.rowid as facid, f.facnumber, f.ref_client, f.type, f.note_private, f.increment, f.total as total_ht, f.tva as total_tva, f.total_ttc,'; $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; $sql.= ' f.paye as paye, f.fk_statut,'; @@ -155,6 +157,8 @@ $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql.= ', '.MAIN_DB_PREFIX.'facture as f'; if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid'; +if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture'; +if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if ($search_user > 0) @@ -165,7 +169,8 @@ if ($search_user > 0) $sql.= ' WHERE f.fk_soc = s.rowid'; $sql.= " AND f.entity = ".$conf->entity; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; -if ($socid) $sql.= ' AND s.rowid = '.$socid; +if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; +if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; if ($userid) { if ($userid == -1) $sql.=' AND f.fk_user_author IS NULL'; @@ -275,16 +280,30 @@ if ($resql) if ($user->rights->societe->client->voir || $socid) { $langs->load("commercial"); + $moreforfilter.='
'; $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user); - $moreforfilter.='       '; + $moreforfilter.='
'; } // If the user can view prospects other than his' if ($user->rights->societe->client->voir || $socid) { - $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; $moreforfilter.=$form->select_dolusers($search_user,'search_user',1); + $moreforfilter.='
'; } + // If the user can view prospects other than his' + if ($conf->categorie->enabled && $user->rights->produit->lire) + { + include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': '; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); + $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1); + $moreforfilter.='
'; + } + if ($moreforfilter) { print '';