From 30c6891b957bd33579ced61d98033508c2bd8970 Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Wed, 10 Jan 2018 10:24:42 +0100 Subject: [PATCH 1/2] NEW : Add product categories filter on product margin --- htdocs/langs/fr_FR/categories.lang | 1 + htdocs/margin/productMargins.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/htdocs/langs/fr_FR/categories.lang b/htdocs/langs/fr_FR/categories.lang index 10ab0fd65e4..99d1375b28c 100644 --- a/htdocs/langs/fr_FR/categories.lang +++ b/htdocs/langs/fr_FR/categories.lang @@ -85,3 +85,4 @@ CategorieRecursivHelp=Si activé : quand un élément est ajouté dans une cat AddProductServiceIntoCategory=Ajouter le produit/service suivant ShowCategory=Afficher tag/catégorie ByDefaultInList=Par défaut dans la liste +ChooseCategory=Choisissez les catégories diff --git a/htdocs/margin/productMargins.php b/htdocs/margin/productMargins.php index 9d52b25de36..ef99e593b82 100644 --- a/htdocs/margin/productMargins.php +++ b/htdocs/margin/productMargins.php @@ -37,6 +37,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); +$TSelectedCats=GETPOST('categories', 'array'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); @@ -121,6 +122,16 @@ else { } +// Categories +$TCats = $form->select_all_categories(0, array(), '', 64, 0, 1); + +print ''; +print ''.$langs->trans('ChooseCategory').''; +print ''; +print $form->multiselectarray('categories', $TCats, $TSelectedCats, 0, 0, 'minwidth500'); +print ''; +print ''; + // Start date print ''; print ''.$langs->trans('DateStart').' ('.$langs->trans("DateValidation").')'; @@ -177,12 +188,18 @@ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = d.fk_product"; +if (! empty($TSelectedCats)) { + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=p.rowid'; +} $sql.= " WHERE f.fk_soc = s.rowid"; $sql.= ' AND f.entity IN ('.getEntity('facture').')'; $sql.= " AND f.fk_statut > 0"; $sql.= " AND d.fk_facture = f.rowid"; if ($id > 0) $sql.= " AND d.fk_product =".$id; +if (! empty($TSelectedCats)) { + $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; +} if (!empty($startdate)) $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; if (!empty($enddate)) From 2c473d35cc7468b15be0082796dc135c04e2df3d Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Wed, 10 Jan 2018 12:11:02 +0100 Subject: [PATCH 2/2] NEW : Add product and product categories filters on customer margins --- htdocs/margin/customerMargins.php | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php index c83ca406347..b216db9d430 100644 --- a/htdocs/margin/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -35,6 +35,9 @@ $langs->load("margins"); // Security check $socid = GETPOST('socid','int'); +$TSelectedProducts = GETPOST('products', 'array'); +$TSelectedCats = GETPOST('categories', 'array'); + if (! empty($user->societe_id)) $socid=$user->societe_id; $result = restrictedArea($user, 'societe','',''); $result = restrictedArea($user,'margins'); @@ -132,6 +135,29 @@ if (! $sortfield) } } +// Products +$TRes = $form->select_produits_list('','','',20,0,'',1,2,1,0,'', 1); + +$TProducts = array(); +foreach($TRes as $prod) { + $TProducts[$prod['key']] = $prod['label']; +} + +print ''.$langs->trans('ChooseProduct/Service').''; +print ''; +print $form->multiselectarray('products', $TProducts, $TSelectedProducts, 0, 0, 'minwidth500'); +print ''; + +// Categories +$TCats = $form->select_all_categories(0, array(), '', 64, 0, 1); + +print ''; +print ''.$langs->trans('ChooseCategory').''; +print ''; +print $form->multiselectarray('categories', $TCats, $TSelectedCats, 0, 0, 'minwidth500'); +print ''; +print ''; + // Start date print ''.$langs->trans('DateStart').' ('.$langs->trans("DateValidation").')'; print ''; @@ -186,6 +212,10 @@ $sql.= " sum(".$db->ifsql('d.total_ht < 0','-1 * (abs(d.total_ht) - (d.buy_price $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; +if(! empty($TSelectedCats)) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product'; +} + if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.fk_soc = s.rowid"; if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; @@ -194,6 +224,12 @@ $sql.= " AND f.fk_statut > 0"; $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)"; +if(! empty($TSelectedProducts)) { + $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')'; +} +if(! empty($TSelectedCats)) { + $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; +} if (!empty($startdate)) $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; if (!empty($enddate))