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