From f5d7e94d7e26f8fcd2a7445c2f27bb87b2d79e6f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 30 Jul 2020 19:32:06 +0200 Subject: [PATCH] NEW Add a stat page to list popularity of products on invoices Merge duplicate pages into 1. --- htdocs/langs/en_US/other.lang | 2 + htdocs/product/popucom.php | 212 ---------------------------------- htdocs/product/popuprop.php | 189 +++++++++++++++++------------- htdocs/product/stats/card.php | 9 +- 4 files changed, 114 insertions(+), 298 deletions(-) delete mode 100644 htdocs/product/popucom.php diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 5dc70fa068f..4555d3a6bc5 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -280,7 +280,9 @@ LinesToImport=Lines to import MemoryUsage=Memory usage RequestDuration=Duration of request +ProductsPerPopularity=Products/Services by popularity PopuProp=Products/Services by popularity in Proposals PopuCom=Products/Services by popularity in Orders ProductStatistics=Products/Services Statistics NbOfQtyInOrders=Qty in orders +SelectTheTypeOfObjectToAnalyze=Select the type of object to analyze... diff --git a/htdocs/product/popucom.php b/htdocs/product/popucom.php deleted file mode 100644 index a0ee53a5758..00000000000 --- a/htdocs/product/popucom.php +++ /dev/null @@ -1,212 +0,0 @@ - - * Copyright (C) 2004-2005 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2014 Marcos García - * Copyright (C) 2015 Jean-François Ferry - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/product/popucom.php - * \ingroup commande, produit - * \brief Liste des produits/services par popularite - */ - -require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - -// Load translation files required by the page -//Required to translate NbOfCommande -$langs->load('commande'); - -$type = GETPOST("type", "int"); - -// Security check -if (!empty($user->socid)) $socid = $user->socid; -$result = restrictedArea($user, 'produit|service'); - -$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 -if (!$sortfield) $sortfield = "c"; -if (!$sortorder) $sortorder = "DESC"; -$offset = $limit * $page; -$pageprev = $page - 1; -$pagenext = $page + 1; - - -$staticproduct = new Product($db); - - -/* - * View - */ - -$helpurl = ''; -if ($type == '0') -{ - $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; -} elseif ($type == '1') -{ - $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; -} else { - $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; -} -$title = $langs->trans("Statistics"); - - -llxHeader('', $title, $helpurl); - -print load_fiche_titre($title, $mesg, 'product'); - - -$param = ''; -$title = $langs->trans("ListProductServiceByPopularity"); -if ((string) $type == '1') { - $title = $langs->trans("ListServiceByPopularity"); -} -if ((string) $type == '0') { - $title = $langs->trans("ListProductByPopularity"); -} - -if ($type != '') $param .= '&type='.$type; - - -$h = 0; -$head = array(); - -$head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php?id=all'; -$head[$h][1] = $langs->trans("Chart"); -$head[$h][2] = 'chart'; -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'; -$head[$h][1] = $langs->trans("PopuProp"); -$head[$h][2] = 'popularityprop'; -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/product/popucom.php'; -$head[$h][1] = $langs->trans("PopuCom"); -$head[$h][2] = 'popularitycommande'; -$h++; - -dol_fiche_head($head, 'popularitycommande', $langs->trans("Statistics"), -1); - - -// Array of liens to show -$infoprod = array(); - - -// Add lines for commande -$sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type as type, SUM(pd.qty) as c"; -$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pd"; -$sql .= ", ".MAIN_DB_PREFIX."product as p"; -$sql .= ' WHERE p.entity IN ('.getEntity('product').')'; -$sql .= " AND p.rowid = pd.fk_product"; -if ($type !== '') { - $sql .= " AND fk_product_type = ".$type; -} -$sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type"; - -$result = $db->query($sql); -if ($result) -{ - $totalnboflines = $db->num_rows($result); -} - -$sql .= $db->order($sortfield, $sortorder); -$sql .= $db->plimit($limit + 1, $offset); - -$resql = $db->query($sql); -if ($resql) -{ - $num = $db->num_rows($resql); - $i = 0; - - while ($i < $num) - { - $objp = $db->fetch_object($resql); - - $infoprod[$objp->rowid] = array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label); - $infoprod[$objp->rowid]['nblinecommande'] = $objp->c; - - $i++; - } - $db->free($resql); -} else { - dol_print_error($db); -} -//var_dump($infoprod); - - -print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, ''); - -print ''; - -print ""; -print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder); -print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder); -print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder); -print_liste_field_titre('NbOfQtyInOrders', $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right '); -print "\n"; - -foreach ($infoprod as $prodid => $vals) -{ - // Multilangs - if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { - $sql = "SELECT label"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql .= " WHERE fk_product=".$prodid; - $sql .= " AND lang='".$langs->getDefaultLang()."'"; - $sql .= " LIMIT 1"; - - $resultp = $db->query($sql); - if ($resultp) - { - $objtp = $db->fetch_object($resultp); - if (!empty($objtp->label)) $vals['label'] = $objtp->label; - } - } - - print ""; - print ''; - print ''; - print ''; - print ''; - print "\n"; - $i++; -} - -print "
'; - if ($vals['type'] == 1) print img_object($langs->trans("ShowService"), "service"); - else print img_object($langs->trans("ShowProduct"), "product"); - print " "; - print $vals['ref'].''; - if ($vals['type'] == 1) print $langs->trans("Service"); - else print $langs->trans("Product"); - print ''.$vals['label'].''.$vals['nblinecommande'].'
"; - - - -dol_fiche_end(); - -// End of page -llxFooter(); -$db->close(); diff --git a/htdocs/product/popuprop.php b/htdocs/product/popuprop.php index b48afc6d162..affd5a8b3f2 100644 --- a/htdocs/product/popuprop.php +++ b/htdocs/product/popuprop.php @@ -1,10 +1,10 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2020 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2014 Marcos García - * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Jean-François Ferry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,18 +22,21 @@ /** * \file htdocs/product/popuprop.php - * \ingroup propal, produit - * \brief Liste des produits/services par popularite + * \ingroup propal, commande, facture, produit + * \brief List of products or services by popularity */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; // Load translation files required by the page -//Required to translate NbOfProposals -$langs->load('propal'); +$langs->loadLangs(array('commande', 'propal', 'bills', 'other')); + +$backtopage = GETPOST('backtopage', 'alpha'); +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); $type = GETPOST("type", "int"); +$mode = GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : ''; // Security check if (!empty($user->socid)) $socid = $user->socid; @@ -58,12 +61,12 @@ $staticproduct = new Product($db); * View */ +$form = new Form($db); + $helpurl = ''; -if ($type == '0') -{ +if ($type == '0') { $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; -} elseif ($type == '1') -{ +} elseif ($type == '1') { $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } else { $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; @@ -85,8 +88,8 @@ if ((string) $type == '0') { $title = $langs->trans("ListProductByPopularity"); } -if ($type != '') $param .= '&type='.$type; - +if ($type != '') $param .= '&type='.urlencode($type); +if ($mode != '') $param .= '&mode='.urlencode($mode); $h = 0; $head = array(); @@ -97,25 +100,30 @@ $head[$h][2] = 'chart'; $h++; $head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'; -$head[$h][1] = $langs->trans("PopuProp"); -$head[$h][2] = 'popularityprop'; +$head[$h][1] = $langs->trans("ProductsPerPopularity"); +$head[$h][2] = 'popularity'; $h++; -$head[$h][0] = DOL_URL_ROOT.'/product/popucom.php'; -$head[$h][1] = $langs->trans("PopuCom"); -$head[$h][2] = 'popularitycommande'; -$h++; -dol_fiche_head($head, 'popularityprop', $langs->trans("Statistics"), -1); +dol_fiche_head($head, 'popularity', $langs->trans("Statistics"), -1); // Array of liens to show $infoprod = array(); -// Add lines for proposals +// Add lines for object $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type as type, SUM(pd.qty) as c"; -$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd"; +$textforqty = 'Qty'; +if ($mode == 'facture') { + $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd"; +} elseif ($mode == 'commande') { + $textforqty = 'NbOfQtyInOrders'; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pd"; +} elseif ($mode == 'propal') { + $textforqty = 'NbOfQtyInProposals'; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd"; +} $sql .= ", ".MAIN_DB_PREFIX."product as p"; $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; $sql .= " AND p.rowid = pd.fk_product"; @@ -124,38 +132,58 @@ if ($type !== '') { } $sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type"; -$result = $db->query($sql); -if ($result) -{ - $totalnboflines = $db->num_rows($result); -} - -$sql .= $db->order($sortfield, $sortorder); -$sql .= $db->plimit($limit + 1, $offset); - -$resql = $db->query($sql); -if ($resql) -{ - $num = $db->num_rows($resql); - $i = 0; - - while ($i < $num) +if (! empty($mode) && $mode != '-1') { + $result = $db->query($sql); + if ($result) { - $objp = $db->fetch_object($resql); - - $infoprod[$objp->rowid] = array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label); - $infoprod[$objp->rowid]['nblineproposal'] = $objp->c; - - $i++; + $totalnboflines = $db->num_rows($result); + } + + $sql .= $db->order($sortfield, $sortorder); + $sql .= $db->plimit($limit + 1, $offset); + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $infoprod[$objp->rowid] = array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label); + $infoprod[$objp->rowid]['nbline'] = $objp->c; + + $i++; + } + $db->free($resql); + } else { + dol_print_error($db); } - $db->free($resql); -} else { - dol_print_error($db); } //var_dump($infoprod); -print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, ''); +$arrayofmode = array( + 'propal' => 'Proposals', + 'commande' => 'Orders', + 'facture' => 'Facture' + ); +$title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1); +$title .= ' '; + + +print '
'; +print ''; +print ''; +print ''; +print ''; +if ($backtopage) print ''; +if ($backtopageforcancel) print ''; + + +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1); print ''; @@ -163,47 +191,50 @@ print ""; print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder); print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder); print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder); -print_liste_field_titre('NbOfQtyInProposals', $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right '); +print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right '); print "\n"; -foreach ($infoprod as $prodid => $vals) -{ - // Multilangs - if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active +if ($mode && $mode != '-1') { + foreach ($infoprod as $prodid => $vals) { - $sql = "SELECT label"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql .= " WHERE fk_product=".$prodid; - $sql .= " AND lang='".$langs->getDefaultLang()."'"; - $sql .= " LIMIT 1"; - - $resultp = $db->query($sql); - if ($resultp) + // Multilangs + if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active { - $objtp = $db->fetch_object($resultp); - if (!empty($objtp->label)) $vals['label'] = $objtp->label; + $sql = "SELECT label"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " WHERE fk_product=".$prodid; + $sql .= " AND lang='".$langs->getDefaultLang()."'"; + $sql .= " LIMIT 1"; + + $resultp = $db->query($sql); + if ($resultp) + { + $objtp = $db->fetch_object($resultp); + if (!empty($objtp->label)) $vals['label'] = $objtp->label; + } } + + print ""; + print ''; + print ''; + print ''; + print ''; + print "\n"; + $i++; } - - print ""; - print ''; - print ''; - print ''; - print ''; - print "\n"; - $i++; +} else { + print ''; } - print "
'; + if ($vals['type'] == 1) print img_object($langs->trans("ShowService"), "service"); + else print img_object($langs->trans("ShowProduct"), "product"); + print " "; + print $vals['ref'].''; + if ($vals['type'] == 1) print $langs->trans("Service"); + else print $langs->trans("Product"); + print ''.$vals['label'].''.$vals['nbline'].'
'; - if ($vals['type'] == 1) print img_object($langs->trans("ShowService"), "service"); - else print img_object($langs->trans("ShowProduct"), "product"); - print " "; - print $vals['ref'].''; - if ($vals['type'] == 1) print $langs->trans("Service"); - else print $langs->trans("Product"); - print ''.$vals['label'].''.$vals['nblineproposal'].'
'.$langs->trans("SelectTheTypeOfObjectToAnalyze").'
"; - +print '
'; dol_fiche_end(); diff --git a/htdocs/product/stats/card.php b/htdocs/product/stats/card.php index d77c03f4d0d..4d4b0820e18 100644 --- a/htdocs/product/stats/card.php +++ b/htdocs/product/stats/card.php @@ -159,13 +159,8 @@ if (empty($id) & empty($ref)) } $head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'.($type != '' ? '?type='.$type : ''); - $head[$h][1] = $langs->trans("PopuProp"); - $head[$h][2] = 'popularityprop'; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/product/popucom.php'.($type != '' ? '?type='.$type : ''); - $head[$h][1] = $langs->trans("PopuCom"); - $head[$h][2] = 'popularitycommande'; + $head[$h][1] = $langs->trans("ProductsPerPopularity"); + $head[$h][2] = 'popularity'; $h++; dol_fiche_head($head, 'chart', $langs->trans("Statistics"), -1);