dolibarr 21.0.0-beta
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 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';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array('commande', 'propal', 'bills', 'other', 'products'));
45
46$backtopage = GETPOST('backtopage', 'alpha');
47$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
48
49$type = GETPOST('type', 'intcomma');
50$mode = GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : '';
51
52// Security check
53if (!empty($user->socid)) {
54 $socid = $user->socid;
55}
56
57$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
58$sortfield = GETPOST('sortfield', 'aZ09comma');
59$sortorder = GETPOST('sortorder', 'aZ09comma');
60$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
61if (empty($page) || $page == -1) {
62 $page = 0;
63} // If $page is not defined, or '' or -1
64if (!$sortfield) {
65 $sortfield = "c";
66}
67if (!$sortorder) {
68 $sortorder = "DESC";
69}
70$offset = $limit * $page;
71$pageprev = $page - 1;
72$pagenext = $page + 1;
73
74restrictedArea($user, 'produit|service', 0, 'product&product', '', '');
75
76
77/*
78 * View
79 */
80
81$form = new Form($db);
82$tmpproduct = new Product($db);
83
84$helpurl = '';
85if ($type == '0') {
86 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
87} else {
88 $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
89}
90$title = $langs->trans("Statistics");
91
92
93llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-popuprop');
94
95print load_fiche_titre($title, '', 'product');
96
97
98$param = '';
99$title = $langs->trans("ListProductServiceByPopularity");
100if ((string) $type == '1') {
101 $title = $langs->trans("ListServiceByPopularity");
102}
103if ((string) $type == '0') {
104 $title = $langs->trans("ListProductByPopularity");
105}
106
107if ($type != '') {
108 $param .= '&type='.urlencode($type);
109}
110if ($mode != '') {
111 $param .= '&mode='.urlencode($mode);
112}
113
114
115$h = 0;
116$head = array();
117
118$head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php?id=all';
119$head[$h][1] = $langs->trans("Chart");
120$head[$h][2] = 'chart';
121$h++;
122
123$head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php';
124$head[$h][1] = $langs->trans("ProductsServicesPerPopularity");
125if ((string) $type == '0') {
126 $head[$h][1] = $langs->trans("ProductsPerPopularity");
127}
128if ((string) $type == '1') {
129 $head[$h][1] = $langs->trans("ServicesPerPopularity");
130}
131$head[$h][2] = 'popularity';
132$h++;
133
134
135print dol_get_fiche_head($head, 'popularity', '', -1);
136
137
138// Array of lines to show
139$infoprod = array();
140
141
142// Add lines for object
143$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";
144$textforqty = 'Qty';
145if ($mode == 'facture') {
146 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd";
147} elseif ($mode == 'commande') {
148 $textforqty = 'NbOfQtyInOrders';
149 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pd";
150} elseif ($mode == 'propal') {
151 $textforqty = 'NbOfQtyInProposals';
152 $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
153}
154$sql .= ", ".MAIN_DB_PREFIX."product as p";
155$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
156$sql .= " AND p.rowid = pd.fk_product";
157if ($type !== '') {
158 $sql .= " AND fk_product_type = ".((int) $type);
159}
160$sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type, p.tobuy, p.tosell, p.tobatch, p.barcode";
161
162$num = 0;
163$totalnboflines = 0;
164
165if (!empty($mode) && $mode != '-1') {
166 $result = $db->query($sql);
167 if ($result) {
168 $totalnboflines = $db->num_rows($result);
169 }
170
171 $sql .= $db->order($sortfield, $sortorder);
172 $sql .= $db->plimit($limit + 1, $offset);
173
174 $resql = $db->query($sql);
175 if ($resql) {
176 $num = $db->num_rows($resql);
177 $i = 0;
178
179 while ($i < $num) {
180 $objp = $db->fetch_object($resql);
181
182 $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);
183 $infoprod[$objp->rowid]['nbline'] = $objp->c;
184
185 $i++;
186 }
187 $db->free($resql);
188 } else {
189 dol_print_error($db);
190 }
191}
192//var_dump($infoprod);
193
194
195$arrayofmode = array(
196 'propal' => 'Proposals',
197 'commande' => 'Orders',
198 'facture' => 'Facture'
199 );
200$title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1, 0, 0, '', 1);
201$title .= ' <input type="submit" class="button small" name="refresh" value="'.$langs->trans("Refresh").'">';
202
203
204print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
205print '<input type="hidden" name="token" value="'.newToken().'">';
206print '<input type="hidden" name="mode" value="'.$mode.'">';
207print '<input type="hidden" name="type" value="'.$type.'">';
208print '<input type="hidden" name="action" value="add">';
209if ($backtopage) {
210 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
211}
212if ($backtopageforcancel) {
213 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
214}
215
216
217print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1);
218
219print '<table class="noborder centpercent">';
220
221print '<tr class="liste_titre">';
222print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
223print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder, 'center ');
224print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
225print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right ');
226print "</tr>\n";
227
228if ($mode && $mode != '-1') {
229 foreach ($infoprod as $prodid => $vals) {
230 // Multilangs
231 if (getDolGlobalInt('MAIN_MULTILANGS')) { // si l'option est active
232 $sql = "SELECT label";
233 $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
234 $sql .= " WHERE fk_product = ".((int) $prodid);
235 $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
236 $sql .= " LIMIT 1";
237
238 $resultp = $db->query($sql);
239 if ($resultp) {
240 $objtp = $db->fetch_object($resultp);
241 if (!empty($objtp->label)) {
242 $vals['label'] = $objtp->label;
243 }
244 }
245 }
246
247 $tmpproduct->id = $prodid;
248 $tmpproduct->ref = $vals['ref'];
249 $tmpproduct->label = $vals['label'];
250 $tmpproduct->type = $vals['type'];
251 $tmpproduct->status = $vals['tosell'];
252 $tmpproduct->status_buy = $vals['tobuy'];
253 $tmpproduct->status_batch = $vals['tobatch'];
254 $tmpproduct->barcode = $vals['barcode'];
255
256 print "<tr>";
257
258 // Product ref
259 print '<td>';
260 print $tmpproduct->getNomUrl(1);
261 print '</td>';
262
263 // Type
264 print '<td class="center">';
265 $s = '';
266 if ($vals['type'] == 1) {
267 $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"');
268 } else {
269 $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"');
270 }
271 print $s;
272 print '</td>';
273 print '<td>'.dol_escape_htmltag($vals['label']).'</td>';
274 print '<td class="right">'.$vals['nbline'].'</td>';
275 print "</tr>\n";
276 }
277} else {
278 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("SelectTheTypeOfObjectToAnalyze").'</span></td></tr>';
279}
280print "</table>";
281
282print '</form>';
283
284print dol_get_fiche_end();
285
286// End of page
287llxFooter();
288$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
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.
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)
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.