dolibarr 25.0.0-alpha
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-2026 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
228
229
230
231$arrayofmode = array(
232 'propal' => 'Proposals',
233 'commande' => 'Orders',
234 'facture' => 'Facture'
235 );
236$title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1, 0, 0, '', 1);
237$title .= ' <input type="submit" class="button smallpaddingimp" name="refresh" value="'.$langs->trans("Refresh").'">';
238
239
240print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
241print '<input type="hidden" name="token" value="'.newToken().'">';
242print '<input type="hidden" name="mode" value="'.$mode.'">';
243print '<input type="hidden" name="type" value="'.$type.'">';
244print '<input type="hidden" name="action" value="add">';
245if ($backtopage) {
246 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
247}
248if ($backtopageforcancel) {
249 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
250}
251
252
253print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1);
254
255print '<table class="noborder centpercent">';
256
257print '<tr class="liste_titre">';
258print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
259print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder, 'center ');
260print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
261print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right ');
262print "</tr>\n";
263
264if ($mode && $mode != '-1') {
265 foreach ($infoprod as $prodid => $vals) {
266 // Multilangs
267 if (getDolGlobalInt('MAIN_MULTILANGS')) { // si l'option est active
268 $sql = "SELECT label";
269 $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
270 $sql .= " WHERE fk_product = ".((int) $prodid);
271 $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
272 $sql .= " LIMIT 1";
273
274 $resultp = $db->query($sql);
275 if ($resultp) {
276 $objtp = $db->fetch_object($resultp);
277 if (!empty($objtp->label)) {
278 $vals['label'] = $objtp->label;
279 }
280 }
281 }
282
283 $tmpproduct->id = (int) $prodid;
284 $tmpproduct->ref = $vals['ref'];
285 $tmpproduct->label = $vals['label'];
286 $tmpproduct->type = $vals['type'];
287 $tmpproduct->status = $vals['tosell'];
288 $tmpproduct->status_buy = $vals['tobuy'];
289 $tmpproduct->status_batch = $vals['tobatch'];
290 $tmpproduct->barcode = $vals['barcode'];
291
292 print "<tr>";
293
294 // Product ref
295 print '<td>';
296 print $tmpproduct->getNomUrl(1);
297 print '</td>';
298
299 // Type
300 print '<td class="center">';
301 $s = '';
302 if ($vals['type'] == 1) {
303 $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"');
304 } else {
305 $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"');
306 }
307 print $s;
308 print '</td>';
309 print '<td>'.dol_escape_htmltag($vals['label']).'</td>';
310 print '<td class="right">'.$vals['nbline'].'</td>';
311 print "</tr>\n";
312 }
313
314 if (count($infoprod) == 0) {
315 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
316 }
317} else {
318 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("SelectTheTypeOfObjectToAnalyze").'</span></td></tr>';
319}
320print "</table>";
321
322print '</form>';
323
324print dol_get_fiche_end();
325
326// End of page
327llxFooter();
328$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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
isModEnabled($module)
Is Dolibarr module enabled.
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)
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.
Definition html.lib.php:519
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
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.