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