dolibarr  16.0.5
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', 'products'));
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)) {
43  $socid = $user->socid;
44 }
45 
46 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
47 $sortfield = GETPOST('sortfield', 'aZ09comma');
48 $sortorder = GETPOST('sortorder', 'aZ09comma');
49 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
50 if (empty($page) || $page == -1) {
51  $page = 0;
52 } // If $page is not defined, or '' or -1
53 if (!$sortfield) {
54  $sortfield = "c";
55 }
56 if (!$sortorder) {
57  $sortorder = "DESC";
58 }
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 
63 restrictedArea($user, 'produit|service', 0, 'product&product', '', '');
64 
65 
66 /*
67  * View
68  */
69 
70 $form = new Form($db);
71 $tmpproduct = new Product($db);
72 
73 $helpurl = '';
74 if ($type == '0') {
75  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
76 } elseif ($type == '1') {
77  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
78 } else {
79  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
80 }
81 $title = $langs->trans("Statistics");
82 
83 
84 llxHeader('', $title, $helpurl);
85 
86 print load_fiche_titre($title, '', 'product');
87 
88 
89 $param = '';
90 $title = $langs->trans("ListProductServiceByPopularity");
91 if ((string) $type == '1') {
92  $title = $langs->trans("ListServiceByPopularity");
93 }
94 if ((string) $type == '0') {
95  $title = $langs->trans("ListProductByPopularity");
96 }
97 
98 if ($type != '') {
99  $param .= '&type='.urlencode($type);
100 }
101 if ($mode != '') {
102  $param .= '&mode='.urlencode($mode);
103 }
104 
105 
106 $h = 0;
107 $head = array();
108 
109 $head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php?id=all';
110 $head[$h][1] = $langs->trans("Chart");
111 $head[$h][2] = 'chart';
112 $h++;
113 
114 $head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php';
115 $head[$h][1] = $langs->trans("ProductsPerPopularity");
116 $head[$h][2] = 'popularity';
117 $h++;
118 
119 
120 print dol_get_fiche_head($head, 'popularity', '', -1);
121 
122 
123 // Array of liens to show
124 $infoprod = array();
125 
126 
127 // Add lines for object
128 $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type as type, p.tobuy, p.tosell, p.tobatch, p.barcode, SUM(pd.qty) as c";
129 $textforqty = 'Qty';
130 if ($mode == 'facture') {
131  $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd";
132 } elseif ($mode == 'commande') {
133  $textforqty = 'NbOfQtyInOrders';
134  $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pd";
135 } elseif ($mode == 'propal') {
136  $textforqty = 'NbOfQtyInProposals';
137  $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
138 }
139 $sql .= ", ".MAIN_DB_PREFIX."product as p";
140 $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
141 $sql .= " AND p.rowid = pd.fk_product";
142 if ($type !== '') {
143  $sql .= " AND fk_product_type = ".((int) $type);
144 }
145 $sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type, p.tobuy, p.tosell, p.tobatch, p.barcode";
146 
147 $num = 0;
148 $totalnboflines = 0;
149 
150 if (!empty($mode) && $mode != '-1') {
151  $result = $db->query($sql);
152  if ($result) {
153  $totalnboflines = $db->num_rows($result);
154  }
155 
156  $sql .= $db->order($sortfield, $sortorder);
157  $sql .= $db->plimit($limit + 1, $offset);
158 
159  $resql = $db->query($sql);
160  if ($resql) {
161  $num = $db->num_rows($resql);
162  $i = 0;
163 
164  while ($i < $num) {
165  $objp = $db->fetch_object($resql);
166 
167  $infoprod[$objp->rowid] = array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label, 'tobuy'=>$objp->tobuy, 'tosell'=>$objp->tobuy, 'tobatch'=>$objp->tobatch, 'barcode'=>$objp->barcode);
168  $infoprod[$objp->rowid]['nbline'] = $objp->c;
169 
170  $i++;
171  }
172  $db->free($resql);
173  } else {
174  dol_print_error($db);
175  }
176 }
177 //var_dump($infoprod);
178 
179 
180 $arrayofmode = array(
181  'propal' => 'Proposals',
182  'commande' => 'Orders',
183  'facture' => 'Facture'
184  );
185 $title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1, 0, 0, '', 1);
186 $title .= ' <input type="submit" class="button small" name="refresh" value="'.$langs->trans("Refresh").'">';
187 
188 
189 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
190 print '<input type="hidden" name="token" value="'.newToken().'">';
191 print '<input type="hidden" name="mode" value="'.$mode.'">';
192 print '<input type="hidden" name="type" value="'.$type.'">';
193 print '<input type="hidden" name="action" value="add">';
194 if ($backtopage) {
195  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
196 }
197 if ($backtopageforcancel) {
198  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
199 }
200 
201 
202 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1);
203 
204 print '<table class="noborder centpercent">';
205 
206 print '<tr class="liste_titre">';
207 print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
208 print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder);
209 print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
210 print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right ');
211 print "</tr>\n";
212 
213 if ($mode && $mode != '-1') {
214  foreach ($infoprod as $prodid => $vals) {
215  // Multilangs
216  if (!empty($conf->global->MAIN_MULTILANGS)) { // si l'option est active
217  $sql = "SELECT label";
218  $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
219  $sql .= " WHERE fk_product = ".((int) $prodid);
220  $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
221  $sql .= " LIMIT 1";
222 
223  $resultp = $db->query($sql);
224  if ($resultp) {
225  $objtp = $db->fetch_object($resultp);
226  if (!empty($objtp->label)) {
227  $vals['label'] = $objtp->label;
228  }
229  }
230  }
231 
232  $tmpproduct->id = $prodid;
233  $tmpproduct->ref = $vals['ref'];
234  $tmpproduct->label = $vals['label'];
235  $tmpproduct->type = $vals['type'];
236  $tmpproduct->status = $vals['tosell'];
237  $tmpproduct->status_buy = $vals['tobuy'];
238  $tmpproduct->status_batch = $vals['tobatch'];
239  $tmpproduct->barcode = $vals['barcode'];
240 
241  print "<tr>";
242  print '<td>';
243  print $tmpproduct->getNomUrl(1);
244  print '</td>';
245  print '<td>';
246  $s = '';
247  if ($vals['type'] == 1) {
248  $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"');
249  } else {
250  $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"');
251  }
252  print $s;
253  print '</td>';
254  print '<td>'.dol_escape_htmltag($vals['label']).'</td>';
255  print '<td class="right">'.$vals['nbline'].'</td>';
256  print "</tr>\n";
257  $i++;
258  }
259 } else {
260  print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("SelectTheTypeOfObjectToAnalyze").'</span></td></tr>';
261 }
262 print "</table>";
263 
264 print '</form>';
265 
266 print dol_get_fiche_end();
267 
268 // End of page
269 llxFooter();
270 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
print_barre_liste
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.
Definition: functions.lib.php:5257
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59