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