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