dolibarr 20.0.0
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array('commande', 'propal', 'bills', 'other', 'products'));
36
37$backtopage = GETPOST('backtopage', 'alpha');
38$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
39
40$type = GETPOST('type', 'intcomma');
41$mode = GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : '';
42
43// Security check
44if (!empty($user->socid)) {
45 $socid = $user->socid;
46}
47
48$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
49$sortfield = GETPOST('sortfield', 'aZ09comma');
50$sortorder = GETPOST('sortorder', 'aZ09comma');
51$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
52if (empty($page) || $page == -1) {
53 $page = 0;
54} // If $page is not defined, or '' or -1
55if (!$sortfield) {
56 $sortfield = "c";
57}
58if (!$sortorder) {
59 $sortorder = "DESC";
60}
61$offset = $limit * $page;
62$pageprev = $page - 1;
63$pagenext = $page + 1;
64
65restrictedArea($user, 'produit|service', 0, 'product&product', '', '');
66
67
68/*
69 * View
70 */
71
72$form = new Form($db);
73$tmpproduct = new Product($db);
74
75$helpurl = '';
76if ($type == '0') {
77 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
78} else {
79 $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
80}
81$title = $langs->trans("Statistics");
82
83
84llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-popuprop');
85
86print load_fiche_titre($title, '', 'product');
87
88
89$param = '';
90$title = $langs->trans("ListProductServiceByPopularity");
91if ((string) $type == '1') {
92 $title = $langs->trans("ListServiceByPopularity");
93}
94if ((string) $type == '0') {
95 $title = $langs->trans("ListProductByPopularity");
96}
97
98if ($type != '') {
99 $param .= '&type='.urlencode($type);
100}
101if ($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("ProductsServicesPerPopularity");
116if ((string) $type == '0') {
117 $head[$h][1] = $langs->trans("ProductsPerPopularity");
118}
119if ((string) $type == '1') {
120 $head[$h][1] = $langs->trans("ServicesPerPopularity");
121}
122$head[$h][2] = 'popularity';
123$h++;
124
125
126print dol_get_fiche_head($head, 'popularity', '', -1);
127
128
129// Array of liens to show
130$infoprod = array();
131
132
133// Add lines for object
134$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";
135$textforqty = 'Qty';
136if ($mode == 'facture') {
137 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd";
138} elseif ($mode == 'commande') {
139 $textforqty = 'NbOfQtyInOrders';
140 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pd";
141} elseif ($mode == 'propal') {
142 $textforqty = 'NbOfQtyInProposals';
143 $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
144}
145$sql .= ", ".MAIN_DB_PREFIX."product as p";
146$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
147$sql .= " AND p.rowid = pd.fk_product";
148if ($type !== '') {
149 $sql .= " AND fk_product_type = ".((int) $type);
150}
151$sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type, p.tobuy, p.tosell, p.tobatch, p.barcode";
152
153$num = 0;
154$totalnboflines = 0;
155
156if (!empty($mode) && $mode != '-1') {
157 $result = $db->query($sql);
158 if ($result) {
159 $totalnboflines = $db->num_rows($result);
160 }
161
162 $sql .= $db->order($sortfield, $sortorder);
163 $sql .= $db->plimit($limit + 1, $offset);
164
165 $resql = $db->query($sql);
166 if ($resql) {
167 $num = $db->num_rows($resql);
168 $i = 0;
169
170 while ($i < $num) {
171 $objp = $db->fetch_object($resql);
172
173 $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);
174 $infoprod[$objp->rowid]['nbline'] = $objp->c;
175
176 $i++;
177 }
178 $db->free($resql);
179 } else {
180 dol_print_error($db);
181 }
182}
183//var_dump($infoprod);
184
185
186$arrayofmode = array(
187 'propal' => 'Proposals',
188 'commande' => 'Orders',
189 'facture' => 'Facture'
190 );
191$title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1, 0, 0, '', 1);
192$title .= ' <input type="submit" class="button small" name="refresh" value="'.$langs->trans("Refresh").'">';
193
194
195print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
196print '<input type="hidden" name="token" value="'.newToken().'">';
197print '<input type="hidden" name="mode" value="'.$mode.'">';
198print '<input type="hidden" name="type" value="'.$type.'">';
199print '<input type="hidden" name="action" value="add">';
200if ($backtopage) {
201 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
202}
203if ($backtopageforcancel) {
204 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
205}
206
207
208print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1);
209
210print '<table class="noborder centpercent">';
211
212print '<tr class="liste_titre">';
213print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
214print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder);
215print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
216print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right ');
217print "</tr>\n";
218
219if ($mode && $mode != '-1') {
220 foreach ($infoprod as $prodid => $vals) {
221 // Multilangs
222 if (getDolGlobalInt('MAIN_MULTILANGS')) { // si l'option est active
223 $sql = "SELECT label";
224 $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
225 $sql .= " WHERE fk_product = ".((int) $prodid);
226 $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
227 $sql .= " LIMIT 1";
228
229 $resultp = $db->query($sql);
230 if ($resultp) {
231 $objtp = $db->fetch_object($resultp);
232 if (!empty($objtp->label)) {
233 $vals['label'] = $objtp->label;
234 }
235 }
236 }
237
238 $tmpproduct->id = $prodid;
239 $tmpproduct->ref = $vals['ref'];
240 $tmpproduct->label = $vals['label'];
241 $tmpproduct->type = $vals['type'];
242 $tmpproduct->status = $vals['tosell'];
243 $tmpproduct->status_buy = $vals['tobuy'];
244 $tmpproduct->status_batch = $vals['tobatch'];
245 $tmpproduct->barcode = $vals['barcode'];
246
247 print "<tr>";
248 print '<td>';
249 print $tmpproduct->getNomUrl(1);
250 print '</td>';
251 print '<td>';
252 $s = '';
253 if ($vals['type'] == 1) {
254 $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"');
255 } else {
256 $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"');
257 }
258 print $s;
259 print '</td>';
260 print '<td>'.dol_escape_htmltag($vals['label']).'</td>';
261 print '<td class="right">'.$vals['nbline'].'</td>';
262 print "</tr>\n";
263 }
264} else {
265 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("SelectTheTypeOfObjectToAnalyze").'</span></td></tr>';
266}
267print "</table>";
268
269print '</form>';
270
271print dol_get_fiche_end();
272
273// End of page
274llxFooter();
275$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.