dolibarr 24.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-2026 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 < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
61 // If $page is not defined, or '' or -1 or if we click on clear filters
62 $page = 0;
63}
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$help_url = '';
85if ($type === "" || $type === "-1") {
86 $help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
87 $title = $langs->trans("ProductsAndServices");
88} elseif ($type == '0') {
89 $help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
90 //$title=$langs->trans("StatisticsOfProducts");
91 $title = $langs->trans("Products");
92} else {
93 $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
94 //$title=$langs->trans("StatisticsOfProductsOrServices");
95 $title = $langs->trans("Services");
96}
97
98llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-popuprop');
99
100
101$picto = 'product';
102if ($type == 1) {
103 $picto = 'service';
104}
105
106$param = '';
107if ($type != '') {
108 $param .= '&type='.urlencode($type);
109}
110if ($mode != '') {
111 $param .= '&mode='.urlencode($mode);
112}
113
114$param .= ($type === '' ? '' : '&type='.((int) $type));
115$massactionbutton = '';
116$num = 0;
117$nbtotalofrecords = $langs->trans("Statistics");
118
119$newcardbutton = '';
120$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/product/list.php?&mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'common' ? 2 : 1), array('morecss' => 'reposition'));
121$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/product/list.php?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
122$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/product/stats/index.php?id=all'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', 2, array('morecss' => 'reposition'));
123
124$perm = false;
125if ($type === "") {
126 $perm = ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'));
127} elseif ($type == Product::TYPE_SERVICE) {
128 $perm = $user->hasRight('service', 'creer');
129} elseif ($type == Product::TYPE_PRODUCT) {
130 $perm = $user->hasRight('produit', 'creer');
131}
132$params = array();
133if ($type === "") {
134 $params['forcenohideoftext'] = 1;
135}
136$newcardbutton .= dolGetButtonTitleSeparator();
137if ((isModEnabled('product') && $type === "") || $type == Product::TYPE_PRODUCT) {
138 $label = 'NewProduct';
139 $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', (int) $perm, $params);
140}
141if ((isModEnabled('service') && $type === "") || $type == Product::TYPE_SERVICE) {
142 $label = 'NewService';
143 $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=1', '', (int) $perm, $params);
144}
145
146print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
147
148
149
150$h = 0;
151$head = array();
152
153$head[$h][0] = DOL_URL_ROOT.'/product/stats/index.php'.($type != '' ? '?type='.((int) $type) : '');
154$head[$h][1] = $langs->trans("Chart");
155$head[$h][2] = 'chart';
156$h++;
157
158$head[$h][0] = DOL_URL_ROOT.'/product/stats/popuprop.php'.($type != '' ? '?type='.((int) $type) : '');
159$head[$h][1] = $langs->trans("ProductsServicesPerPopularity");
160if ((string) $type == '0') {
161 $head[$h][1] = $langs->trans("ProductsPerPopularity");
162}
163if ((string) $type == '1') {
164 $head[$h][1] = $langs->trans("ServicesPerPopularity");
165}
166$head[$h][2] = 'popularity';
167$h++;
168
169
170print dol_get_fiche_head($head, 'popularity', '', -1);
171
172
173// Array of lines to show
174$infoprod = array();
175
176
177// Add lines for object
178$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";
179$textforqty = 'Qty';
180if ($mode == 'facture') {
181 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd";
182} elseif ($mode == 'commande') {
183 $textforqty = 'NbOfQtyInOrders';
184 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pd";
185} elseif ($mode == 'propal') {
186 $textforqty = 'NbOfQtyInProposals';
187 $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
188}
189$sql .= ", ".MAIN_DB_PREFIX."product as p";
190$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
191$sql .= " AND p.rowid = pd.fk_product";
192if ($type !== '' && $type !== '-1') {
193 $sql .= " AND p.fk_product_type = ".((int) $type);
194}
195$sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type, p.tobuy, p.tosell, p.tobatch, p.barcode";
196
197$num = 0;
198$totalnboflines = 0;
199
200if (!empty($mode) && $mode != '-1') {
201 $result = $db->query($sql);
202 if ($result) {
203 $totalnboflines = $db->num_rows($result);
204 }
205
206 $sql .= $db->order($sortfield.', rowid', $sortorder);
207 $sql .= $db->plimit($limit + 1, $offset);
208
209 $resql = $db->query($sql);
210 if ($resql) {
211 $num = $db->num_rows($resql);
212 $i = 0;
213
214 while ($i < $num) {
215 $objp = $db->fetch_object($resql);
216
217 $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);
218 $infoprod[$objp->rowid]['nbline'] = $objp->c;
219
220 $i++;
221 }
222 $db->free($resql);
223 } else {
225 }
226}
227//var_dump($infoprod);
228
229
230
231
232$arrayofmode = array(
233 'propal' => 'Proposals',
234 'commande' => 'Orders',
235 'facture' => 'Facture'
236 );
237$title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1, 0, 0, '', 1);
238$title .= ' <input type="submit" class="button smallpaddingimp" name="refresh" value="'.$langs->trans("Refresh").'">';
239
240
241print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
242print '<input type="hidden" name="token" value="'.newToken().'">';
243print '<input type="hidden" name="mode" value="'.$mode.'">';
244print '<input type="hidden" name="type" value="'.$type.'">';
245print '<input type="hidden" name="action" value="add">';
246if ($backtopage) {
247 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
248}
249if ($backtopageforcancel) {
250 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
251}
252
253
254print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1);
255
256print '<table class="noborder centpercent">';
257
258print '<tr class="liste_titre">';
259print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
260print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder, 'center ');
261print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
262print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right ');
263print "</tr>\n";
264
265if ($mode && $mode != '-1') {
266 foreach ($infoprod as $prodid => $vals) {
267 // Multilangs
268 if (getDolGlobalInt('MAIN_MULTILANGS')) { // si l'option est active
269 $sql = "SELECT label";
270 $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
271 $sql .= " WHERE fk_product = ".((int) $prodid);
272 $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
273 $sql .= " LIMIT 1";
274
275 $resultp = $db->query($sql);
276 if ($resultp) {
277 $objtp = $db->fetch_object($resultp);
278 if (!empty($objtp->label)) {
279 $vals['label'] = $objtp->label;
280 }
281 }
282 }
283
284 $tmpproduct->id = (int) $prodid;
285 $tmpproduct->ref = $vals['ref'];
286 $tmpproduct->label = $vals['label'];
287 $tmpproduct->type = $vals['type'];
288 $tmpproduct->status = $vals['tosell'];
289 $tmpproduct->status_buy = $vals['tobuy'];
290 $tmpproduct->status_batch = $vals['tobatch'];
291 $tmpproduct->barcode = $vals['barcode'];
292
293 print "<tr>";
294
295 // Product ref
296 print '<td>';
297 print $tmpproduct->getNomUrl(1);
298 print '</td>';
299
300 // Type
301 print '<td class="center">';
302 $s = '';
303 if ($vals['type'] == 1) {
304 $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"');
305 } else {
306 $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"');
307 }
308 print $s;
309 print '</td>';
310 print '<td>'.dol_escape_htmltag($vals['label']).'</td>';
311 print '<td class="right">'.$vals['nbline'].'</td>';
312 print "</tr>\n";
313 }
314
315 if (count($infoprod) == 0) {
316 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
317 }
318} else {
319 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("SelectTheTypeOfObjectToAnalyze").'</span></td></tr>';
320}
321print "</table>";
322
323print '</form>';
324
325print dol_get_fiche_end();
326
327// End of page
328llxFooter();
329$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.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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...
isModEnabled($module)
Is Dolibarr module enabled.
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.