dolibarr  13.0.2
popuprop.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('commande', 'propal', 'bills', 'other'));
34 
35 $backtopage = GETPOST('backtopage', 'alpha');
36 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
37 
38 $type = GETPOST("type", "int");
39 $mode = GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : '';
40 
41 // Security check
42 if (!empty($user->socid)) $socid = $user->socid;
43 $result = restrictedArea($user, 'produit|service');
44 
45 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
46 $sortfield = GETPOST("sortfield", 'alpha');
47 $sortorder = GETPOST("sortorder", 'alpha');
48 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 if (!$sortfield) $sortfield = "c";
51 if (!$sortorder) $sortorder = "DESC";
52 $offset = $limit * $page;
53 $pageprev = $page - 1;
54 $pagenext = $page + 1;
55 
56 
57 $staticproduct = new Product($db);
58 
59 
60 /*
61  * View
62  */
63 
64 $form = new Form($db);
65 
66 $helpurl = '';
67 if ($type == '0') {
68  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
69 } elseif ($type == '1') {
70  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
71 } else {
72  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
73 }
74 $title = $langs->trans("Statistics");
75 
76 
77 llxHeader('', $title, $helpurl);
78 
79 print load_fiche_titre($title, $mesg, 'product');
80 
81 
82 $param = '';
83 $title = $langs->trans("ListProductServiceByPopularity");
84 if ((string) $type == '1') {
85  $title = $langs->trans("ListServiceByPopularity");
86 }
87 if ((string) $type == '0') {
88  $title = $langs->trans("ListProductByPopularity");
89 }
90 
91 if ($type != '') $param .= '&type='.urlencode($type);
92 if ($mode != '') $param .= '&mode='.urlencode($mode);
93 
94 $h = 0;
95 $head = array();
96 
97 $head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php?id=all';
98 $head[$h][1] = $langs->trans("Chart");
99 $head[$h][2] = 'chart';
100 $h++;
101 
102 $head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php';
103 $head[$h][1] = $langs->trans("ProductsPerPopularity");
104 $head[$h][2] = 'popularity';
105 $h++;
106 
107 
108 print dol_get_fiche_head($head, 'popularity', $langs->trans("Statistics"), -1);
109 
110 
111 // Array of liens to show
112 $infoprod = array();
113 
114 
115 // Add lines for object
116 $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type as type, SUM(pd.qty) as c";
117 $textforqty = 'Qty';
118 if ($mode == 'facture') {
119  $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd";
120 } elseif ($mode == 'commande') {
121  $textforqty = 'NbOfQtyInOrders';
122  $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pd";
123 } elseif ($mode == 'propal') {
124  $textforqty = 'NbOfQtyInProposals';
125  $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
126 }
127 $sql .= ", ".MAIN_DB_PREFIX."product as p";
128 $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
129 $sql .= " AND p.rowid = pd.fk_product";
130 if ($type !== '') {
131  $sql .= " AND fk_product_type = ".$type;
132 }
133 $sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type";
134 
135 if (!empty($mode) && $mode != '-1') {
136  $result = $db->query($sql);
137  if ($result)
138  {
139  $totalnboflines = $db->num_rows($result);
140  }
141 
142  $sql .= $db->order($sortfield, $sortorder);
143  $sql .= $db->plimit($limit + 1, $offset);
144 
145  $resql = $db->query($sql);
146  if ($resql)
147  {
148  $num = $db->num_rows($resql);
149  $i = 0;
150 
151  while ($i < $num)
152  {
153  $objp = $db->fetch_object($resql);
154 
155  $infoprod[$objp->rowid] = array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label);
156  $infoprod[$objp->rowid]['nbline'] = $objp->c;
157 
158  $i++;
159  }
160  $db->free($resql);
161  } else {
162  dol_print_error($db);
163  }
164 }
165 //var_dump($infoprod);
166 
167 
168 $arrayofmode = array(
169  'propal' => 'Proposals',
170  'commande' => 'Orders',
171  'facture' => 'Facture'
172  );
173 $title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1);
174 $title .= ' <input type="submit" class="button" name="refresh" value="'.$langs->trans("Refresh").'">';
175 
176 
177 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
178 print '<input type="hidden" name="token" value="'.newToken().'">';
179 print '<input type="hidden" name="mode" value="'.$mode.'">';
180 print '<input type="hidden" name="type" value="'.$type.'">';
181 print '<input type="hidden" name="action" value="add">';
182 if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
183 if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
184 
185 
186 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1);
187 
188 print '<table class="noborder centpercent">';
189 
190 print "<tr class=\"liste_titre\">";
191 print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
192 print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder);
193 print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
194 print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right ');
195 print "</tr>\n";
196 
197 if ($mode && $mode != '-1') {
198  foreach ($infoprod as $prodid => $vals)
199  {
200  // Multilangs
201  if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
202  {
203  $sql = "SELECT label";
204  $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
205  $sql .= " WHERE fk_product=".$prodid;
206  $sql .= " AND lang='".$db->escape($langs->getDefaultLang())."'";
207  $sql .= " LIMIT 1";
208 
209  $resultp = $db->query($sql);
210  if ($resultp)
211  {
212  $objtp = $db->fetch_object($resultp);
213  if (!empty($objtp->label)) $vals['label'] = $objtp->label;
214  }
215  }
216 
217  print "<tr>";
218  print '<td><a href="'.DOL_URL_ROOT.'/product/stats/card.php?id='.$prodid.'">';
219  if ($vals['type'] == 1) print img_object($langs->trans("ShowService"), "service");
220  else print img_object($langs->trans("ShowProduct"), "product");
221  print " ";
222  print $vals['ref'].'</a></td>';
223  print '<td>';
224  if ($vals['type'] == 1) print $langs->trans("Service");
225  else print $langs->trans("Product");
226  print '</td>';
227  print '<td>'.$vals['label'].'</td>';
228  print '<td class="right">'.$vals['nbline'].'</td>';
229  print "</tr>\n";
230  $i++;
231  }
232 } else {
233  print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("SelectTheTypeOfObjectToAnalyze").'</span></td></tr>';
234 }
235 print "</table>";
236 
237 print '</form>';
238 
239 print dol_get_fiche_end();
240 
241 // End of page
242 llxFooter();
243 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
llxHeader()
Empty header.
Definition: wrapper.php:45
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59