dolibarr 20.0.0
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014-2016 Charlie BENKE <charlie@patas-monkey.com>
6 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7 * Copyright (C) 2019 Pierre Ardoin <mapiolca@me.com>
8 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
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
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
38
39$type = GETPOST("type", 'intcomma');
40if ($type == '' && !$user->hasRight('produit', 'lire') && $user->hasRight('service', 'lire')) {
41 $type = '1'; // Force global page on service page only
42}
43if ($type == '' && !$user->hasRight('service', 'lire') && $user->hasRight('produit', 'lire')) {
44 $type = '0'; // Force global page on product page only
45}
46
47// Load translation files required by the page
48$langs->loadLangs(array('products', 'stocks'));
49
50// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
51$hookmanager->initHooks(array('productindex'));
52
53// Initialize objects
54$product_static = new Product($db);
55
56// Security check
57if ($type == '0') {
58 $result = restrictedArea($user, 'produit');
59} elseif ($type == '1') {
60 $result = restrictedArea($user, 'service');
61} else {
62 $result = restrictedArea($user, 'produit|service|expedition|reception');
63}
64
65// Load $resultboxes
66$resultboxes = FormOther::getBoxesArea($user, "4");
67
68if (GETPOST('addbox')) {
69 // Add box (when submit is done from a form when ajax disabled)
70 require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
71 $zone = GETPOST('areacode', 'int');
72 $userid = GETPOST('userid', 'int');
73 $boxorder = GETPOST('boxorder', 'aZ09');
74 $boxorder .= GETPOST('boxcombo', 'aZ09');
75 $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
76 if ($result > 0) {
77 setEventMessages($langs->trans("BoxAdded"), null);
78 }
79}
80
81$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
82
83
84/*
85 * View
86 */
87
88$producttmp = new Product($db);
89$warehouse = new Entrepot($db);
90
91$transAreaType = $langs->trans("ProductsAndServicesArea");
92
93$helpurl = '';
94if (!GETPOSTISSET("type")) {
95 $transAreaType = $langs->trans("ProductsAndServicesArea");
96 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
97}
98if ((GETPOSTISSET("type") && GETPOST("type") == '0') || !isModEnabled("service")) {
99 $transAreaType = $langs->trans("ProductsArea");
100 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
101}
102if ((GETPOSTISSET("type") && GETPOST("type") == '1') || !isModEnabled("product")) {
103 $transAreaType = $langs->trans("ServicesArea");
104 $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
105}
106
107llxHeader("", $langs->trans("ProductsAndServices"), $helpurl, '', 0, 0, '', '', '', 'mod-product page-index');
108
109print load_fiche_titre($transAreaType, $resultboxes['selectboxlist'], 'product');
110
111
112if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // This may be useless due to the global search combo
113 if (!isset($listofsearchfields) || !is_array($listofsearchfields)) {
114 // Ensure $listofsearchfields is set and array
115 $listofsearchfields = array();
116 }
117 // Search contract
118 if ((isModEnabled("product") || isModEnabled("service")) && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
119 $listofsearchfields['search_product'] = array('text' => 'ProductOrService');
120 }
121
122 if (count($listofsearchfields)) {
123 print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
124 print '<input type="hidden" name="token" value="'.newToken().'">';
125 print '<div class="div-table-responsive-no-min">';
126 print '<table class="noborder nohover centpercent">';
127 $i = 0;
128 foreach ($listofsearchfields as $key => $value) {
129 if ($i == 0) {
130 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
131 }
132 print '<tr class="oddeven">';
133 print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td>';
134 print '<td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
135 if ($i == 0) {
136 print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
137 }
138 print '</tr>';
139 $i++;
140 }
141 print '</table>';
142 print '</div>';
143 print '</form>';
144 print '<br>';
145 }
146}
147
148/*
149 * Number of products and/or services
150 */
151$graph = '';
152if ((isModEnabled("product") || isModEnabled("service")) && ($user->hasRight("produit", "lire") || $user->hasRight("service", "lire"))) {
153 $prodser = array();
154 $prodser[0][0] = $prodser[0][1] = $prodser[0][2] = $prodser[0][3] = 0;
155 $prodser[0]['sell'] = 0;
156 $prodser[0]['buy'] = 0;
157 $prodser[0]['none'] = 0;
158 $prodser[1][0] = $prodser[1][1] = $prodser[1][2] = $prodser[1][3] = 0;
159 $prodser[1]['sell'] = 0;
160 $prodser[1]['buy'] = 0;
161 $prodser[1]['none'] = 0;
162
163 $sql = "SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy";
164 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
165 $sql .= ' WHERE p.entity IN ('.getEntity($product_static->element, 1).')';
166 // Add where from hooks
167 $parameters = array();
168 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $product_static); // Note that $action and $object may have been modified by hook
169 $sql .= $hookmanager->resPrint;
170 $sql .= " GROUP BY p.fk_product_type, p.tosell, p.tobuy";
171 $result = $db->query($sql);
172 while ($objp = $db->fetch_object($result)) {
173 $status = 3; // On sale + On purchase
174 if (!$objp->tosell && !$objp->tobuy) {
175 $status = 0; // Not on sale, not on purchase
176 }
177 if ($objp->tosell && !$objp->tobuy) {
178 $status = 1; // On sale only
179 }
180 if (!$objp->tosell && $objp->tobuy) {
181 $status = 2; // On purchase only
182 }
183 $prodser[$objp->fk_product_type][$status] = $objp->total;
184 if ($objp->tosell) {
185 $prodser[$objp->fk_product_type]['sell'] += $objp->total;
186 }
187 if ($objp->tobuy) {
188 $prodser[$objp->fk_product_type]['buy'] += $objp->total;
189 }
190 if (!$objp->tosell && !$objp->tobuy) {
191 $prodser[$objp->fk_product_type]['none'] += $objp->total;
192 }
193 }
194
195 if ($conf->use_javascript_ajax) {
196 $graph .= '<div class="div-table-responsive-no-min">';
197 $graph .= '<table class="noborder centpercent">';
198 $graph .= '<tr class="liste_titre"><th>'.$langs->trans("Statistics").'</th></tr>';
199 $graph .= '<tr><td class="center nopaddingleftimp nopaddingrightimp">';
200
201 $SommeA = $prodser[0]['sell'];
202 $SommeB = $prodser[0]['buy'];
203 $SommeC = $prodser[0]['none'];
204 $SommeD = $prodser[1]['sell'];
205 $SommeE = $prodser[1]['buy'];
206 $SommeF = $prodser[1]['none'];
207 $total = 0;
208 $dataval = array();
209 $datalabels = array();
210 $i = 0;
211
212 $total = $SommeA + $SommeB + $SommeC + $SommeD + $SommeE + $SommeF;
213 $dataseries = array();
214 if (isModEnabled("product")) {
215 $dataseries[] = array($langs->transnoentitiesnoconv("ProductsOnSale"), round($SommeA));
216 $dataseries[] = array($langs->transnoentitiesnoconv("ProductsOnPurchase"), round($SommeB));
217 $dataseries[] = array($langs->transnoentitiesnoconv("ProductsNotOnSell"), round($SommeC));
218 }
219 if (isModEnabled("service")) {
220 $dataseries[] = array($langs->transnoentitiesnoconv("ServicesOnSale"), round($SommeD));
221 $dataseries[] = array($langs->transnoentitiesnoconv("ServicesOnPurchase"), round($SommeE));
222 $dataseries[] = array($langs->transnoentitiesnoconv("ServicesNotOnSell"), round($SommeF));
223 }
224 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
225 $dolgraph = new DolGraph();
226 $dolgraph->SetData($dataseries);
227 $dolgraph->setShowLegend(2);
228 $dolgraph->setShowPercent(0);
229 $dolgraph->SetType(array('pie'));
230 $dolgraph->setHeight('200');
231 $dolgraph->draw('idgraphstatus');
232 $graph .= $dolgraph->show($total ? 0 : 1);
233
234 $graph .= '</td></tr>';
235 $graph .= '</table>';
236 $graph .= '</div>';
237 $graph .= '<br>';
238 }
239}
240
241$graphcat = '';
242if (isModEnabled('category') && getDolGlobalString('CATEGORY_GRAPHSTATS_ON_PRODUCTS') && $user->hasRight('categorie', 'read')) {
243 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
244 $graphcat .= '<br>';
245 $graphcat .= '<div class="div-table-responsive-no-min">';
246 $graphcat .= '<table class="noborder centpercent">';
247 $graphcat .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
248 $graphcat .= '<tr><td class="center" colspan="2">';
249 $sql = "SELECT c.label, count(*) as nb";
250 $sql .= " FROM ".MAIN_DB_PREFIX."categorie_product as cs";
251 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
252 $sql .= " WHERE c.type = 0";
253 $sql .= " AND c.entity IN (".getEntity('category').")";
254 $sql .= " GROUP BY c.label";
255 $sql .= " ORDER BY nb desc";
256 $total = 0;
257 $result = $db->query($sql);
258 if ($result) {
259 $num = $db->num_rows($result);
260 $i = 0;
261 if (!empty($conf->use_javascript_ajax)) {
262 $dataseries = array();
263 $rest = 0;
264 $nbmax = 10;
265
266 while ($i < $num) {
267 $obj = $db->fetch_object($result);
268 if ($i < $nbmax) {
269 $dataseries[] = array($obj->label, round($obj->nb));
270 } else {
271 $rest += $obj->nb;
272 }
273 $total += $obj->nb;
274 $i++;
275 }
276 if ($i > $nbmax) {
277 $dataseries[] = array($langs->transnoentitiesnoconv("Other"), round($rest));
278 }
279 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
280 $dolgraph = new DolGraph();
281 $dolgraph->SetData($dataseries);
282 $dolgraph->setShowLegend(2);
283 $dolgraph->setShowPercent(1);
284 $dolgraph->SetType(array('pie'));
285 $dolgraph->setHeight('200');
286 $dolgraph->draw('idstatscategproduct');
287 $graphcat .= $dolgraph->show($total ? 0 : 1);
288 } else {
289 while ($i < $num) {
290 $obj = $db->fetch_object($result);
291
292 $graphcat .= '<tr><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
293 $total += $obj->nb;
294 $i++;
295 }
296 }
297 }
298 $graphcat .= '</td></tr>';
299 $graphcat .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
300 $graphcat .= $total;
301 $graphcat .= '</td></tr>';
302 $graphcat .= '</table>';
303 $graphcat .= '</div>';
304 $graphcat .= '<br>';
305}
306
307
308/*
309 * Latest modified products
310 */
311if ((isModEnabled("product") || isModEnabled("service")) && ($user->hasRight("produit", "lire") || $user->hasRight("service", "lire"))) {
312 $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy, p.tobatch, p.fk_price_expression,";
313 $sql .= " p.entity,";
314 $sql .= " p.tms as datem";
315 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
316 $sql .= " WHERE p.entity IN (".getEntity($product_static->element, 1).")";
317 /*if ($type != '') {
318 $sql .= " AND p.fk_product_type = ".((int) $type);
319 }*/
320 if (!$user->hasRight("produit", "lire")) {
321 $sql .= " AND p.fk_product_type <> ".((int) Product::TYPE_PRODUCT);
322 }
323 if (!$user->hasRight("service", "lire")) {
324 $sql .= " AND p.fk_product_type <> ".((int) Product::TYPE_SERVICE);
325 }
326
327 // Add where from hooks
328 $parameters = array();
329 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $product_static); // Note that $action and $object may have been modified by hook
330 $sql .= $hookmanager->resPrint;
331 $sql .= $db->order("p.tms", "DESC");
332 $sql .= $db->plimit($max, 0);
333
334 //print $sql;
335 $lastmodified="";
336 $result = $db->query($sql);
337 if ($result) {
338 $num = $db->num_rows($result);
339
340 $i = 0;
341
342 if ($num > 0) {
343 $transRecordedType = $langs->trans("LastModifiedProductsAndServices", $max);
344 if (!isModEnabled('service')) {
345 $transRecordedType = $langs->trans("LastRecordedProducts", $max);
346 }
347 if (!isModEnabled('product')) {
348 $transRecordedType = $langs->trans("LastRecordedServices", $max);
349 }
350
351 $lastmodified .= '<div class="div-table-responsive-no-min">';
352 $lastmodified .= '<table class="noborder centpercent">';
353
354 $colnb = 2;
355 if (!getDolGlobalString('PRODUIT_MULTIPRICES')) {
356 $colnb++;
357 }
358
359 $lastmodified .= '<tr class="liste_titre"><th colspan="'.$colnb.'">';
360 $lastmodified .= $transRecordedType;
361 $lastmodified .= '<a href="'.DOL_URL_ROOT.'/product/list.php?sortfield=p.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
362 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
363 $lastmodified .= '</a>';
364 /*$lastmodified .= '<a href="'.DOL_URL_ROOT.'/product/list.php?sortfield=p.tms&sortorder=DESC&type=0" title="'.$langs->trans("FullList").' - '.$langs->trans("Products").'">';
365 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
366 //$lastmodified .= img_picto($langs->trans("FullList").' - '.$langs->trans("Products"), 'product');
367 $lastmodified .= '</a> &nbsp; ';
368 $lastmodified .= '<a href="'.DOL_URL_ROOT.'/product/list.php?sortfield=p.tms&sortorder=DESC&type=1" title="'.$langs->trans("FullList").' - '.$langs->trans("Services").'">';
369 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
370 //$lastmodified .= img_picto($langs->trans("FullList").' - '.$langs->trans("Services"), 'service');
371 */
372 $lastmodified .= '</th>';
373 $lastmodified .= '<th>';
374 $lastmodified .= '</th>';
375 $lastmodified .= '<th>';
376 $lastmodified .= '</th>';
377 $lastmodified .= '<th>';
378 $lastmodified .= '</th>';
379 $lastmodified .= '</tr>';
380
381 while ($i < $num) {
382 $objp = $db->fetch_object($result);
383
384 $product_static->id = $objp->rowid;
385 $product_static->ref = $objp->ref;
386 $product_static->label = $objp->label;
387 $product_static->type = $objp->fk_product_type;
388 $product_static->entity = $objp->entity;
389 $product_static->status = $objp->tosell;
390 $product_static->status_buy = $objp->tobuy;
391 $product_static->status_batch = $objp->tobatch;
392
393 $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('product', 'product_advance', 'read_prices') : $user->hasRight('product', 'read');
394 if ($product_static->isService()) {
395 $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('service', 'service_advance', 'read_prices') : $user->hasRight('service', 'read');
396 }
397
398 // Multilangs
399 if (getDolGlobalInt('MAIN_MULTILANGS')) {
400 $sql = "SELECT label";
401 $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
402 $sql .= " WHERE fk_product = ".((int) $objp->rowid);
403 $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
404
405 $resultd = $db->query($sql);
406 if ($resultd) {
407 $objtp = $db->fetch_object($resultd);
408 if ($objtp && $objtp->label != '') {
409 $objp->label = $objtp->label;
410 }
411 }
412 }
413
414
415 $lastmodified .= '<tr class="oddeven">';
416 $lastmodified .= '<td class="nowraponall tdoverflowmax100">';
417 $lastmodified .= $product_static->getNomUrl(1);
418 $lastmodified .= "</td>\n";
419 $lastmodified .= '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objp->label).'">'.dol_escape_htmltag($objp->label).'</td>';
420 $lastmodified .= '<td title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($db->jdate($objp->datem), 'dayhour', 'tzuserrel')).'">';
421 $lastmodified .= dol_print_date($db->jdate($objp->datem), 'day', 'tzuserrel');
422 $lastmodified .= "</td>";
423 // Sell price
424 if (!getDolGlobalString('PRODUIT_MULTIPRICES')) {
425 if (isModEnabled('dynamicprices') && !empty($objp->fk_price_expression)) {
426 $product = new Product($db);
427 $product->fetch($objp->rowid);
428
429 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
430 $priceparser = new PriceParser($db);
431 $price_result = $priceparser->parseProduct($product);
432 if ($price_result >= 0) {
433 $objp->price = $price_result;
434 }
435 }
436 $lastmodified .= '<td class="nowraponall amount right">';
437 if ($usercancreadprice) {
438 if (isset($objp->price_base_type) && $objp->price_base_type == 'TTC') {
439 $lastmodified .= price($objp->price_ttc).' '.$langs->trans("TTC");
440 } else {
441 $lastmodified .= price($objp->price).' '.$langs->trans("HT");
442 }
443 }
444 $lastmodified .= '</td>';
445 }
446 $lastmodified .= '<td class="right nowrap width25"><span class="statusrefsell">';
447 $lastmodified .= $product_static->LibStatut($objp->tosell, 3, 0);
448 $lastmodified .= "</span></td>";
449 $lastmodified .= '<td class="right nowrap width25"><span class="statusrefbuy">';
450 $lastmodified .= $product_static->LibStatut($objp->tobuy, 3, 1);
451 $lastmodified .= "</span></td>";
452 $lastmodified .= "</tr>\n";
453 $i++;
454 }
455
456 $db->free($result);
457
458 $lastmodified .= "</table>";
459 $lastmodified .= '</div>';
460 $lastmodified .= '<br>';
461 }
462 } else {
463 dol_print_error($db);
464 }
465}
466
467// Latest modified warehouses
468$latestwarehouse = '';
469if (isModEnabled('stock') && $user->hasRight('stock', 'read')) {
470 $sql = "SELECT e.rowid, e.ref as label, e.lieu, e.statut as status";
471 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
472 $sql .= " WHERE e.statut in (".Entrepot::STATUS_CLOSED.",".Entrepot::STATUS_OPEN_ALL.")";
473 $sql .= " AND e.entity IN (".getEntity('stock').")";
474 $sql .= $db->order('e.tms', 'DESC');
475 $sql .= $db->plimit($max + 1, 0);
476
477 $result = $db->query($sql);
478
479 if ($result) {
480 $num = $db->num_rows($result);
481
482 $latestwarehouse .= '<div class="div-table-responsive-no-min">';
483 $latestwarehouse .= '<table class="noborder centpercent">';
484 $latestwarehouse .= '<tr class="liste_titre">';
485 $latestwarehouse .= '<th>';
486 $latestwarehouse .= $langs->trans("LatestModifiedWarehouses", $max);
487 //$latestwarehouse .= '<a href="'.DOL_URL_ROOT.'/product/stock/list.php">';
488 // TODO: "search_status" on "/product/stock/list.php" currently only accept a single integer value
489 //print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?search_status='.Entrepot::STATUS_CLOSED.','.Entrepot::STATUS_OPEN_ALL.'">';
490 //$latestwarehouse .= '<span class="badge">'.$num.'</span>';
491 $latestwarehouse .= '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?sortfield=p.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
492 $latestwarehouse .= '<span class="badge marginleftonlyshort">...</span>';
493 $latestwarehouse .= '</a>';
494 $latestwarehouse .= '</th><th class="right">';
495 $latestwarehouse .= '</th>';
496 $latestwarehouse .= '</tr>';
497
498 $i = 0;
499 if ($num) {
500 while ($i < min($max, $num)) {
501 $objp = $db->fetch_object($result);
502
503 $warehouse->id = $objp->rowid;
504 $warehouse->statut = $objp->status;
505 $warehouse->label = $objp->label;
506 $warehouse->lieu = $objp->lieu;
507
508 $latestwarehouse .= '<tr class="oddeven">';
509 $latestwarehouse .= '<td>';
510 $latestwarehouse .= $warehouse->getNomUrl(1);
511 $latestwarehouse .= '</td>'."\n";
512 $latestwarehouse .= '<td class="right">';
513 $latestwarehouse .= $warehouse->getLibStatut(5);
514 $latestwarehouse .= '</td>';
515 $latestwarehouse .= "</tr>\n";
516 $i++;
517 }
518 $db->free($result);
519 } else {
520 $latestwarehouse .= '<tr><td>'.$langs->trans("None").'</td><td></td></tr>';
521 }
522 /*if ($num > $max) {
523 $latestwarehouse .= '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td></tr>';
524 }*/
525
526 $latestwarehouse .= "</table>";
527 $latestwarehouse .= '</div>';
528 $latestwarehouse .= '<br>';
529 } else {
530 dol_print_error($db);
531 }
532}
533
534// Latest movements
535$latestmovement = '';
536if (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'read')) {
537 include_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
538
539 $sql = "SELECT p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.tobatch, p.tosell, p.tobuy,";
540 $sql .= " e.ref as warehouse_ref, e.rowid as warehouse_id, e.ref as warehouse_label, e.lieu, e.statut as warehouse_status,";
541 $sql .= " m.rowid as mid, m.label as mlabel, m.inventorycode as mcode, m.value as qty, m.datem, m.batch, m.eatby, m.sellby";
542 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
543 $sql .= ", ".MAIN_DB_PREFIX."stock_mouvement as m";
544 $sql .= ", ".MAIN_DB_PREFIX."product as p";
545 $sql .= " WHERE m.fk_product = p.rowid";
546 $sql .= " AND m.fk_entrepot = e.rowid";
547 $sql .= " AND e.entity IN (".getEntity('stock').")";
548 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
549 $sql .= " AND p.fk_product_type = ".Product::TYPE_PRODUCT;
550 }
551 $sql .= $db->order("datem", "DESC");
552 $sql .= $db->plimit($max, 0);
553
554 dol_syslog("Index:list stock movements", LOG_DEBUG);
555
556 $resql = $db->query($sql);
557 if ($resql) {
558 $num = $db->num_rows($resql);
559
560 $latestmovement .= '<div class="div-table-responsive-no-min">';
561 $latestmovement .= '<table class="noborder centpercent">';
562 $latestmovement .= '<tr class="liste_titre">';
563 $latestmovement .= '<th colspan="3">'.$langs->trans("LatestStockMovements", min($num, $max));
564 $latestmovement .= '<a class="notasortlink" href="'.DOL_URL_ROOT.'/product/stock/movement_list.php">';
565 $latestmovement .= '<span class="badge marginleftonlyshort">...</span>';
566 //$latestmovement .= img_picto($langs->trans("FullList"), 'movement');
567 $latestmovement .= '</a>';
568 $latestmovement .= '</th>';
569 if (isModEnabled('productbatch')) {
570 $latestmovement .= '<th></th>';
571 }
572 $latestmovement .= '<th></th>';
573 $latestmovement .= '<th class="right">';
574 $latestmovement .= '</th>';
575 $latestmovement .= "</tr>\n";
576
577 $tmplotstatic = new Productlot($db);
578 $tmpstockmovement = new MouvementStock($db);
579
580 $i = 0;
581 while ($i < min($num, $max)) {
582 $objp = $db->fetch_object($resql);
583
584 $tmpstockmovement->id = $objp->mid;
585 $tmpstockmovement->date = $db->jdate($objp->datem);
586 $tmpstockmovement->label = $objp->mlabel;
587 $tmpstockmovement->inventorycode = $objp->mcode;
588 $tmpstockmovement->qty = $objp->qty;
589
590 $producttmp->id = $objp->product_id;
591 $producttmp->ref = $objp->product_ref;
592 $producttmp->label = $objp->product_label;
593 $producttmp->status_batch = $objp->tobatch;
594 $producttmp->status_sell = $objp->tosell;
595 $producttmp->status_buy = $objp->tobuy;
596
597 $warehouse->id = $objp->warehouse_id;
598 $warehouse->ref = $objp->warehouse_ref;
599 $warehouse->statut = $objp->warehouse_status;
600 $warehouse->label = $objp->warehouse_label;
601 $warehouse->lieu = $objp->lieu;
602
603 $tmplotstatic->batch = $objp->batch;
604 $tmplotstatic->sellby = $objp->sellby;
605 $tmplotstatic->eatby = $objp->eatby;
606
607 $latestmovement .= '<tr class="oddeven">';
608 $latestmovement .= '<td class="nowraponall">';
609 $latestmovement .= $tmpstockmovement->getNomUrl(1);
610 //$latestmovement .= img_picto($langs->trans("Ref").' '.$objp->mid, 'movement', 'class="pictofixedwidth"').dol_print_date($db->jdate($objp->datem), 'dayhour');
611 $latestmovement .= '</td>';
612 $latestmovement .= '<td class="nowraponall">';
613 $latestmovement .= dol_print_date($tmpstockmovement->date, 'dayhour', 'tzuserrel');
614 $latestmovement .= "</td>\n";
615 $latestmovement .= '<td class="tdoverflowmax150">';
616 $latestmovement .= $producttmp->getNomUrl(1);
617 $latestmovement .= "</td>\n";
618 if (isModEnabled('productbatch')) {
619 $latestmovement .= '<td>';
620 $latestmovement .= $tmplotstatic->getNomUrl(0, 'nolink');
621 $latestmovement .= '</td>';
622 /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
623 print '<td>'.dol_print_date($db->jdate($objp->sellby), 'day').'</td>';
624 }
625 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
626 print '<td>'.dol_print_date($db->jdate($objp->eatby), 'day').'</td>';
627 }*/
628 }
629 $latestmovement .= '<td class="tdoverflowmax150">';
630 $latestmovement .= $warehouse->getNomUrl(1);
631 $latestmovement .= "</td>\n";
632 $latestmovement .= '<td class="right">';
633 if ($objp->qty < 0) {
634 $latestmovement .= '<span class="stockmovementexit">';
635 }
636 if ($objp->qty > 0) {
637 $latestmovement .= '<span class="stockmovemententry">';
638 $latestmovement .= '+';
639 }
640 $latestmovement .= $objp->qty;
641 $latestmovement .= '</span>';
642 $latestmovement .= '</td>';
643 $latestmovement .= "</tr>\n";
644 $i++;
645 }
646 $db->free($resql);
647
648 if (empty($num)) {
649 $colspan = 4;
650 if (isModEnabled('productbatch')) {
651 $colspan++;
652 }
653 $latestmovement .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
654 }
655
656 $latestmovement .= "</table>";
657 $latestmovement .= '</div>';
658 $latestmovement .= '<br>';
659 } else {
660 dol_print_error($db);
661 }
662}
663
664// TODO Move this into a page that should be available into menu "accountancy - report - turnover - per quarter"
665// Also method used for counting must provide the 2 possible methods like done by all other reports into menu "accountancy - report - turnover":
666// "commitment engagement" method and "cash accounting" method
667$activity = '';
668if (isModEnabled("invoice") && $user->hasRight('facture', 'lire') && getDolGlobalString('MAIN_SHOW_PRODUCT_ACTIVITY_TRIM')) {
669 if (isModEnabled("product")) {
670 $activity .= activitytrim(0);
671 }
672 if (isModEnabled("service")) {
673 $activity .= activitytrim(1);
674 }
675}
676
677
678// print '</div></div>';
679
680// boxes
681print '<div class="clearboth"></div>';
682print '<div class="fichecenter fichecenterbis">';
683
684$boxlist = '<div class="twocolumns">';
685
686$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
687$boxlist .= $graph;
688$boxlist .= $graphcat;
689$boxlist .= $activity;
690$boxlist .= '<br>';
691$boxlist .= $resultboxes['boxlista'];
692$boxlist .= "</div>\n";
693
694$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
695$boxlist .= $lastmodified;
696$boxlist .= $latestwarehouse;
697$boxlist .= $latestmovement;
698$boxlist .= $resultboxes['boxlistb'];
699$boxlist .= '</div>'."\n";
700
701$boxlist .= "</div>\n";
702
703print $boxlist;
704
705print '</div>';
706
707$parameters = array('type' => $type, 'user' => $user);
708$reshook = $hookmanager->executeHooks('dashboardProductsServices', $parameters, $product_static); // Note that $action and $object may have been modified by hook
709
710// End of page
711llxFooter();
712$db->close();
713
714
721function activitytrim($product_type)
722{
723 global $conf, $langs, $db;
724
725 // We display the last 3 years
726 $yearofbegindate = date('Y', dol_time_plus_duree(time(), -3, "y"));
727 $out = '';
728 // breakdown by quarter
729 $sql = "SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as Mnttot";
730 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
731 $sql .= " , ".MAIN_DB_PREFIX."paiement as p,".MAIN_DB_PREFIX."paiement_facture as pf";
732 $sql .= " WHERE f.entity IN (".getEntity('invoice').")";
733 $sql .= " AND f.rowid = fd.fk_facture";
734 $sql .= " AND pf.fk_facture = f.rowid";
735 $sql .= " AND pf.fk_paiement = p.rowid";
736 $sql .= " AND fd.product_type = ".((int) $product_type);
737 $sql .= " AND p.datep >= '".$db->idate(dol_get_first_day($yearofbegindate), 1)."'";
738 $sql .= " GROUP BY annee, mois ";
739 $sql .= " ORDER BY annee, mois ";
740
741 $result = $db->query($sql);
742 if ($result) {
743 $tmpyear = 0;
744 $trim1 = 0;
745 $trim2 = 0;
746 $trim3 = 0;
747 $trim4 = 0;
748 $lgn = 0;
749 $num = $db->num_rows($result);
750
751 if ($num > 0) {
752 $out .= '<div class="div-table-responsive-no-min">';
753 $out .= '<table class="noborder" width="75%">';
754
755 if ($product_type == 0) {
756 $out .= '<tr class="liste_titre"><td class=left>'.$langs->trans("ProductSellByQuarterHT").'</td>';
757 } else {
758 $out .= '<tr class="liste_titre"><td class=left>'.$langs->trans("ServiceSellByQuarterHT").'</td>';
759 }
760 $out .= '<td class=right>'.$langs->trans("Quarter1").'</td>';
761 $out .= '<td class=right>'.$langs->trans("Quarter2").'</td>';
762 $out .= '<td class=right>'.$langs->trans("Quarter3").'</td>';
763 $out .= '<td class=right>'.$langs->trans("Quarter4").'</td>';
764 $out .= '<td class=right>'.$langs->trans("Total").'</td>';
765 $out .= '</tr>';
766 }
767 $i = 0;
768
769 while ($i < $num) {
770 $objp = $db->fetch_object($result);
771 if ($tmpyear != $objp->annee) {
772 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
773 $out .= '<tr class="oddeven"><td class=left>'.$tmpyear.'</td>';
774 $out .= '<td class="nowrap right">'.price($trim1).'</td>';
775 $out .= '<td class="nowrap right">'.price($trim2).'</td>';
776 $out .= '<td class="nowrap right">'.price($trim3).'</td>';
777 $out .= '<td class="nowrap right">'.price($trim4).'</td>';
778 $out .= '<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).'</td>';
779 $out .= '</tr>';
780 $lgn++;
781 }
782 // We go to the following year
783 $tmpyear = $objp->annee;
784 $trim1 = 0;
785 $trim2 = 0;
786 $trim3 = 0;
787 $trim4 = 0;
788 }
789
790 if ($objp->mois == "01" || $objp->mois == "02" || $objp->mois == "03") {
791 $trim1 += $objp->Mnttot;
792 }
793
794 if ($objp->mois == "04" || $objp->mois == "05" || $objp->mois == "06") {
795 $trim2 += $objp->Mnttot;
796 }
797
798 if ($objp->mois == "07" || $objp->mois == "08" || $objp->mois == "09") {
799 $trim3 += $objp->Mnttot;
800 }
801
802 if ($objp->mois == "10" || $objp->mois == "11" || $objp->mois == "12") {
803 $trim4 += $objp->Mnttot;
804 }
805
806 $i++;
807 }
808 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
809 $out .= '<tr class="oddeven"><td class=left>'.$tmpyear.'</td>';
810 $out .= '<td class="nowrap right">'.price($trim1).'</td>';
811 $out .= '<td class="nowrap right">'.price($trim2).'</td>';
812 $out .= '<td class="nowrap right">'.price($trim3).'</td>';
813 $out .= '<td class="nowrap right">'.price($trim4).'</td>';
814 $out .= '<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).'</td>';
815 $out .= '</tr>';
816 }
817 if ($num > 0) {
818 $out .= '</table></div>';
819 $out .= '<br>';
820 }
821 }
822
823 return $out;
824}
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 build graphs.
Class to manage warehouses.
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
static getBoxesArea($user, $areacode)
Get array with HTML tabs with boxes of a particular area including personalized choices of user.
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
Class to manage stock movements.
Class to parse product price expressions.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class with list of lots and properties.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:594
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:124
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
activitytrim($product_type)
Print html activity for product type.
Definition index.php:721
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.