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