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