dolibarr 23.0.3
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';
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)) { // @phan-suppress-current-line PhanPluginUndeclaredVariableIsset
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 */
320$lastmodified = "";
321if ((isModEnabled("product") || isModEnabled("service")) && ($user->hasRight("produit", "lire") || $user->hasRight("service", "lire"))) {
322 $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy, p.tobatch, p.fk_price_expression,";
323 $sql .= " p.entity,";
324 $sql .= " GREATEST(p.tms, pef.tms) as datem";
325 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
326 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as pef ON pef.fk_object=p.rowid";
327 $sql .= " WHERE p.entity IN (".getEntity($product_static->element, 1).")";
328 /*if ($type != '') {
329 $sql .= " AND p.fk_product_type = ".((int) $type);
330 }*/
331 if (!$user->hasRight("produit", "lire")) {
332 $sql .= " AND p.fk_product_type <> ".((int) Product::TYPE_PRODUCT);
333 }
334 if (!$user->hasRight("service", "lire")) {
335 $sql .= " AND p.fk_product_type <> ".((int) Product::TYPE_SERVICE);
336 }
337
338 // Add where from hooks
339 $parameters = array();
340 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $product_static); // Note that $action and $object may have been modified by hook
341 $sql .= $hookmanager->resPrint;
342 $sql .= $db->order("datem", "DESC");
343 $sql .= $db->plimit($max, 0);
344
345 //print $sql;
346 $result = $db->query($sql);
347 if ($result) {
348 $num = $db->num_rows($result);
349
350 $i = 0;
351
352 if ($num > 0) {
353 $transRecordedType = $langs->trans("LastModifiedProductsAndServices", $max);
354 if (!isModEnabled('service')) {
355 $transRecordedType = $langs->trans("LastRecordedProducts", $max);
356 }
357 if (!isModEnabled('product')) {
358 $transRecordedType = $langs->trans("LastRecordedServices", $max);
359 }
360
361 $lastmodified .= '<div class="div-table-responsive-no-min">';
362 $lastmodified .= '<table class="noborder centpercent">';
363
364 $colnb = 2;
365 if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
366 $colnb++;
367 }
368
369 $lastmodified .= '<tr class="liste_titre"><th colspan="'.$colnb.'">';
370 $lastmodified .= $transRecordedType;
371 $lastmodified .= '<a href="'.DOL_URL_ROOT.'/product/list.php?sortfield=p.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
372 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
373 $lastmodified .= '</a>';
374 /*$lastmodified .= '<a href="'.DOL_URL_ROOT.'/product/list.php?sortfield=p.tms&sortorder=DESC&type=0" title="'.$langs->trans("FullList").' - '.$langs->trans("Products").'">';
375 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
376 //$lastmodified .= img_picto($langs->trans("FullList").' - '.$langs->trans("Products"), 'product');
377 $lastmodified .= '</a> &nbsp; ';
378 $lastmodified .= '<a href="'.DOL_URL_ROOT.'/product/list.php?sortfield=p.tms&sortorder=DESC&type=1" title="'.$langs->trans("FullList").' - '.$langs->trans("Services").'">';
379 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
380 //$lastmodified .= img_picto($langs->trans("FullList").' - '.$langs->trans("Services"), 'service');
381 */
382 $lastmodified .= '</th>';
383 $lastmodified .= '<th>';
384 $lastmodified .= '</th>';
385 $lastmodified .= '<th>';
386 $lastmodified .= '</th>';
387 $lastmodified .= '<th>';
388 $lastmodified .= '</th>';
389 $lastmodified .= '</tr>';
390
391 while ($i < $num) {
392 $objp = $db->fetch_object($result);
393
394 $product_static->id = $objp->rowid;
395 $product_static->ref = $objp->ref;
396 $product_static->label = $objp->label;
397 $product_static->type = $objp->fk_product_type;
398 $product_static->entity = $objp->entity;
399 $product_static->status = $objp->tosell;
400 $product_static->status_buy = $objp->tobuy;
401 $product_static->status_batch = $objp->tobatch;
402
403 $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('product', 'product_advance', 'read_prices') : $user->hasRight('product', 'read');
404 if ($product_static->isService()) {
405 $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('service', 'service_advance', 'read_prices') : $user->hasRight('service', 'read');
406 }
407
408 // Multilangs
409 if (getDolGlobalInt('MAIN_MULTILANGS')) {
410 $sql = "SELECT label";
411 $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
412 $sql .= " WHERE fk_product = ".((int) $objp->rowid);
413 $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
414
415 $resultd = $db->query($sql);
416 if ($resultd) {
417 $objtp = $db->fetch_object($resultd);
418 if ($objtp && $objtp->label != '') {
419 $objp->label = $objtp->label;
420 }
421 }
422 }
423
424
425 $lastmodified .= '<tr class="oddeven">';
426 $lastmodified .= '<td class="nowraponall tdoverflowmax100">';
427 $lastmodified .= $product_static->getNomUrl(1);
428 $lastmodified .= "</td>\n";
429 $lastmodified .= '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objp->label).'">'.dol_escape_htmltag($objp->label).'</td>';
430 $lastmodified .= '<td title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($db->jdate($objp->datem), 'dayhour', 'tzuserrel')).'">';
431 $lastmodified .= dol_print_date($db->jdate($objp->datem), 'day', 'tzuserrel');
432 $lastmodified .= "</td>";
433 // Sell price
434 if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
435 if (isModEnabled('dynamicprices') && !empty($objp->fk_price_expression)) {
436 $product = new Product($db);
437 $product->fetch($objp->rowid);
438
439 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
440 $priceparser = new PriceParser($db);
441 $price_result = $priceparser->parseProduct($product);
442 if ($price_result >= 0) {
443 $objp->price = $price_result;
444 }
445 }
446 $lastmodified .= '<td class="nowraponall amount right">';
447 if ($usercancreadprice) {
448 if (isset($objp->price_base_type) && $objp->price_base_type == 'TTC') {
449 $lastmodified .= price($objp->price_ttc).' '.$langs->trans("TTC");
450 } else {
451 $lastmodified .= price($objp->price).' '.$langs->trans("HT");
452 }
453 }
454 $lastmodified .= '</td>';
455 }
456 $lastmodified .= '<td class="right nowrap width25"><span class="statusrefsell">';
457 $lastmodified .= $product_static->LibStatut($objp->tosell, 3, 0);
458 $lastmodified .= "</span></td>";
459 $lastmodified .= '<td class="right nowrap width25"><span class="statusrefbuy">';
460 $lastmodified .= $product_static->LibStatut($objp->tobuy, 3, 1);
461 $lastmodified .= "</span></td>";
462 $lastmodified .= "</tr>\n";
463 $i++;
464 }
465
466 $db->free($result);
467
468 $lastmodified .= "</table>";
469 $lastmodified .= '</div>';
470 $lastmodified .= '<br>';
471 }
472 } else {
473 dol_print_error($db);
474 }
475}
476
477// Latest modified warehouses
478$latestwarehouse = '';
479if (isModEnabled('stock') && $user->hasRight('stock', 'read')) {
480 $sql = "SELECT e.rowid, e.ref as label, e.lieu, e.statut as status";
481 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
482 $sql .= " WHERE e.statut in (".Entrepot::STATUS_CLOSED.",".Entrepot::STATUS_OPEN_ALL.")";
483 $sql .= " AND e.entity IN (".getEntity('stock').")";
484 $sql .= $db->order('e.tms', 'DESC');
485 $sql .= $db->plimit($max + 1, 0);
486
487 $result = $db->query($sql);
488
489 if ($result) {
490 $num = $db->num_rows($result);
491
492 $latestwarehouse .= '<div class="div-table-responsive-no-min">';
493 $latestwarehouse .= '<table class="noborder centpercent">';
494 $latestwarehouse .= '<tr class="liste_titre">';
495 $latestwarehouse .= '<th>';
496 $latestwarehouse .= $langs->trans("LatestModifiedWarehouses", $max);
497 //$latestwarehouse .= '<a href="'.DOL_URL_ROOT.'/product/stock/list.php">';
498 // TODO: "search_status" on "/product/stock/list.php" currently only accept a single integer value
499 //print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?search_status='.Entrepot::STATUS_CLOSED.','.Entrepot::STATUS_OPEN_ALL.'">';
500 //$latestwarehouse .= '<span class="badge">'.$num.'</span>';
501 $latestwarehouse .= '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?sortfield=p.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
502 $latestwarehouse .= '<span class="badge marginleftonlyshort">...</span>';
503 $latestwarehouse .= '</a>';
504 $latestwarehouse .= '</th><th class="right">';
505 $latestwarehouse .= '</th>';
506 $latestwarehouse .= '</tr>';
507
508 $i = 0;
509 if ($num) {
510 while ($i < min($max, $num)) {
511 $objp = $db->fetch_object($result);
512
513 $warehouse->id = $objp->rowid;
514 $warehouse->statut = $objp->status;
515 $warehouse->label = $objp->label;
516 $warehouse->lieu = $objp->lieu;
517
518 $latestwarehouse .= '<tr class="oddeven">';
519 $latestwarehouse .= '<td>';
520 $latestwarehouse .= $warehouse->getNomUrl(1);
521 $latestwarehouse .= '</td>'."\n";
522 $latestwarehouse .= '<td class="right">';
523 $latestwarehouse .= $warehouse->getLibStatut(5);
524 $latestwarehouse .= '</td>';
525 $latestwarehouse .= "</tr>\n";
526 $i++;
527 }
528 $db->free($result);
529 } else {
530 $latestwarehouse .= '<tr><td>'.$langs->trans("None").'</td><td></td></tr>';
531 }
532 /*if ($num > $max) {
533 $latestwarehouse .= '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td></tr>';
534 }*/
535
536 $latestwarehouse .= "</table>";
537 $latestwarehouse .= '</div>';
538 $latestwarehouse .= '<br>';
539 } else {
540 dol_print_error($db);
541 }
542}
543
544// Latest movements
545$latestmovement = '';
546if (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'read')) {
547 include_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
548
549 $sql = "SELECT p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.tobatch, p.tosell, p.tobuy,";
550 $sql .= " e.ref as warehouse_ref, e.rowid as warehouse_id, e.ref as warehouse_label, e.lieu, e.statut as warehouse_status,";
551 $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";
552 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
553 $sql .= ", ".MAIN_DB_PREFIX."stock_mouvement as m";
554 $sql .= ", ".MAIN_DB_PREFIX."product as p";
555 $sql .= " WHERE m.fk_product = p.rowid";
556 $sql .= " AND m.fk_entrepot = e.rowid";
557 $sql .= " AND e.entity IN (".getEntity('stock').")";
558 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
559 $sql .= " AND p.fk_product_type = ".Product::TYPE_PRODUCT;
560 }
561 $sql .= $db->order("datem", "DESC");
562 $sql .= $db->plimit($max, 0);
563
564 dol_syslog("Index:list stock movements", LOG_DEBUG);
565
566 $resql = $db->query($sql);
567 if ($resql) {
568 $num = $db->num_rows($resql);
569
570 $latestmovement .= '<div class="div-table-responsive-no-min">';
571 $latestmovement .= '<table class="noborder centpercent">';
572 $latestmovement .= '<tr class="liste_titre">';
573 $latestmovement .= '<th colspan="3">'.$langs->trans("LatestStockMovements", min($num, $max));
574 $latestmovement .= '<a class="notasortlink" href="'.DOL_URL_ROOT.'/product/stock/movement_list.php">';
575 $latestmovement .= '<span class="badge marginleftonlyshort">...</span>';
576 //$latestmovement .= img_picto($langs->trans("FullList"), 'movement');
577 $latestmovement .= '</a>';
578 $latestmovement .= '</th>';
579 if (isModEnabled('productbatch')) {
580 $latestmovement .= '<th></th>';
581 }
582 $latestmovement .= '<th></th>';
583 $latestmovement .= '<th class="right">';
584 $latestmovement .= '</th>';
585 $latestmovement .= "</tr>\n";
586
587 $tmplotstatic = new Productlot($db);
588 $tmpstockmovement = new MouvementStock($db);
589
590 $i = 0;
591 while ($i < min($num, $max)) {
592 $objp = $db->fetch_object($resql);
593
594 $tmpstockmovement->id = $objp->mid;
595 $tmpstockmovement->date = $db->jdate($objp->datem);
596 $tmpstockmovement->label = $objp->mlabel;
597 $tmpstockmovement->inventorycode = $objp->mcode;
598 $tmpstockmovement->qty = $objp->qty;
599
600 $producttmp->id = $objp->product_id;
601 $producttmp->ref = $objp->product_ref;
602 $producttmp->label = $objp->product_label;
603 $producttmp->status_batch = $objp->tobatch;
604 $producttmp->status_sell = $objp->tosell;
605 $producttmp->status_buy = $objp->tobuy;
606
607 $warehouse->id = $objp->warehouse_id;
608 $warehouse->ref = $objp->warehouse_ref;
609 $warehouse->statut = $objp->warehouse_status;
610 $warehouse->label = $objp->warehouse_label;
611 $warehouse->lieu = $objp->lieu;
612
613 $tmplotstatic->batch = $objp->batch;
614 $tmplotstatic->sellby = $objp->sellby;
615 $tmplotstatic->eatby = $objp->eatby;
616
617 $latestmovement .= '<tr class="oddeven">';
618 $latestmovement .= '<td class="nowraponall">';
619 $latestmovement .= $tmpstockmovement->getNomUrl(1);
620 //$latestmovement .= img_picto($langs->trans("Ref").' '.$objp->mid, 'movement', 'class="pictofixedwidth"').dol_print_date($db->jdate($objp->datem), 'dayhour');
621 $latestmovement .= '</td>';
622 $latestmovement .= '<td class="nowraponall">';
623 $latestmovement .= dol_print_date($tmpstockmovement->date, 'dayhour', 'tzuserrel');
624 $latestmovement .= "</td>\n";
625 $latestmovement .= '<td class="tdoverflowmax150">';
626 $latestmovement .= $producttmp->getNomUrl(1);
627 $latestmovement .= "</td>\n";
628 if (isModEnabled('productbatch')) {
629 $latestmovement .= '<td>';
630 $latestmovement .= $tmplotstatic->getNomUrl(0, 'nolink');
631 $latestmovement .= '</td>';
632 /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
633 print '<td>'.dol_print_date($db->jdate($objp->sellby), 'day').'</td>';
634 }
635 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
636 print '<td>'.dol_print_date($db->jdate($objp->eatby), 'day').'</td>';
637 }*/
638 }
639 $latestmovement .= '<td class="tdoverflowmax150">';
640 $latestmovement .= $warehouse->getNomUrl(1);
641 $latestmovement .= "</td>\n";
642 $latestmovement .= '<td class="right">';
643 if ($objp->qty < 0) {
644 $latestmovement .= '<span class="stockmovementexit">';
645 }
646 if ($objp->qty > 0) {
647 $latestmovement .= '<span class="stockmovemententry">';
648 $latestmovement .= '+';
649 }
650 $latestmovement .= $objp->qty;
651 $latestmovement .= '</span>';
652 $latestmovement .= '</td>';
653 $latestmovement .= "</tr>\n";
654 $i++;
655 }
656 $db->free($resql);
657
658 if (empty($num)) {
659 $colspan = 5;
660 if (isModEnabled('productbatch')) {
661 $colspan++;
662 }
663 $latestmovement .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
664 }
665
666 $latestmovement .= "</table>";
667 $latestmovement .= '</div>';
668 $latestmovement .= '<br>';
669 } else {
670 dol_print_error($db);
671 }
672}
673
674// TODO Move this into a page that should be available into menu "accountancy - report - turnover - per quarter"
675// Also method used for counting must provide the 2 possible methods like done by all other reports into menu "accountancy - report - turnover":
676// "commitment engagement" method and "cash accounting" method
677$activity = '';
678if (isModEnabled("invoice") && $user->hasRight('facture', 'lire') && getDolGlobalString('MAIN_SHOW_PRODUCT_ACTIVITY_TRIM')) {
679 if (isModEnabled("product")) {
680 $activity .= activitytrim(0);
681 }
682 if (isModEnabled("service")) {
683 $activity .= activitytrim(1);
684 }
685}
686
687
688// print '</div></div>';
689
690// boxes
691print '<div class="clearboth"></div>';
692print '<div class="fichecenter fichecenterbis">';
693
694$boxlist = '<div class="twocolumns">';
695
696$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
697$boxlist .= $graph;
698$boxlist .= $graphcat;
699$boxlist .= $activity;
700$boxlist .= '<br>';
701$boxlist .= $resultboxes['boxlista'];
702$boxlist .= "</div>\n";
703
704$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
705$boxlist .= $lastmodified;
706$boxlist .= $latestwarehouse;
707$boxlist .= $latestmovement;
708$boxlist .= $resultboxes['boxlistb'];
709$boxlist .= '</div>'."\n";
710
711$boxlist .= "</div>\n";
712
713print $boxlist;
714
715print '</div>';
716
717$parameters = array('type' => $type, 'user' => $user);
718$reshook = $hookmanager->executeHooks('dashboardProductsServices', $parameters, $product_static); // Note that $action and $object may have been modified by hook
719
720// End of page
721llxFooter();
722$db->close();
723
724
731function activitytrim($product_type)
732{
733 global $conf, $langs, $db;
734
735 // We display the last 3 years
736 $yearofbegindate = (int) date('Y', dol_time_plus_duree(time(), -3, "y"));
737 $out = '';
738 // breakdown by quarter
739 $sql = "SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as mnttot";
740 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
741 $sql .= " , ".MAIN_DB_PREFIX."paiement as p,".MAIN_DB_PREFIX."paiement_facture as pf";
742 $sql .= " WHERE f.entity IN (".getEntity('invoice').")";
743 $sql .= " AND f.rowid = fd.fk_facture";
744 $sql .= " AND pf.fk_facture = f.rowid";
745 $sql .= " AND pf.fk_paiement = p.rowid";
746 $sql .= " AND fd.product_type = ".((int) $product_type);
747 $sql .= " AND p.datep >= '".$db->idate(dol_get_first_day($yearofbegindate, 1))."'";
748 $sql .= " GROUP BY annee, mois ";
749 $sql .= " ORDER BY annee, mois ";
750
751 $result = $db->query($sql);
752 if ($result) {
753 $tmpyear = 0;
754 $trim1 = 0;
755 $trim2 = 0;
756 $trim3 = 0;
757 $trim4 = 0;
758 $lgn = 0;
759 $num = $db->num_rows($result);
760
761 if ($num > 0) {
762 $out .= '<div class="div-table-responsive-no-min">';
763 $out .= '<table class="noborder" width="75%">';
764
765 if ($product_type == 0) {
766 $out .= '<tr class="liste_titre"><td class=left>'.$langs->trans("ProductSellByQuarterHT").'</td>';
767 } else {
768 $out .= '<tr class="liste_titre"><td class=left>'.$langs->trans("ServiceSellByQuarterHT").'</td>';
769 }
770 $out .= '<td class=right>'.$langs->trans("Quarter1").'</td>';
771 $out .= '<td class=right>'.$langs->trans("Quarter2").'</td>';
772 $out .= '<td class=right>'.$langs->trans("Quarter3").'</td>';
773 $out .= '<td class=right>'.$langs->trans("Quarter4").'</td>';
774 $out .= '<td class=right>'.$langs->trans("Total").'</td>';
775 $out .= '</tr>';
776 }
777 $i = 0;
778
779 while ($i < $num) {
780 $objp = $db->fetch_object($result);
781 if ($tmpyear != $objp->annee) {
782 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
783 $out .= '<tr class="oddeven"><td class=left>'.$tmpyear.'</td>';
784 $out .= '<td class="nowrap right">'.price($trim1).'</td>';
785 $out .= '<td class="nowrap right">'.price($trim2).'</td>';
786 $out .= '<td class="nowrap right">'.price($trim3).'</td>';
787 $out .= '<td class="nowrap right">'.price($trim4).'</td>';
788 $out .= '<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).'</td>';
789 $out .= '</tr>';
790 $lgn++;
791 }
792 // We go to the following year
793 $tmpyear = $objp->annee;
794 $trim1 = 0;
795 $trim2 = 0;
796 $trim3 = 0;
797 $trim4 = 0;
798 }
799
800 if ($objp->mois == "01" || $objp->mois == "02" || $objp->mois == "03") {
801 $trim1 += $objp->mnttot;
802 }
803
804 if ($objp->mois == "04" || $objp->mois == "05" || $objp->mois == "06") {
805 $trim2 += $objp->mnttot;
806 }
807
808 if ($objp->mois == "07" || $objp->mois == "08" || $objp->mois == "09") {
809 $trim3 += $objp->mnttot;
810 }
811
812 if ($objp->mois == "10" || $objp->mois == "11" || $objp->mois == "12") {
813 $trim4 += $objp->mnttot;
814 }
815
816 $i++;
817 }
818 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
819 $out .= '<tr class="oddeven"><td class=left>'.$tmpyear.'</td>';
820 $out .= '<td class="nowrap right">'.price($trim1).'</td>';
821 $out .= '<td class="nowrap right">'.price($trim2).'</td>';
822 $out .= '<td class="nowrap right">'.price($trim3).'</td>';
823 $out .= '<td class="nowrap right">'.price($trim4).'</td>';
824 $out .= '<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).'</td>';
825 $out .= '</tr>';
826 }
827 if ($num > 0) {
828 $out .= '</table></div>';
829 $out .= '<br>';
830 }
831 }
832
833 return $out;
834}
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:603
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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:731
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:464
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.