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