dolibarr 21.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array('stocks', 'productbatch'));
46
47// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
48$hookmanager->initHooks(array('stockindex'));
49
50// Security check
51$result = restrictedArea($user, 'stock');
52
53
54/*
55 * View
56 */
57
58$producttmp = new Product($db);
59$warehouse = new Entrepot($db);
60
61$help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
62llxHeader("", $langs->trans("Stocks"), $help_url, '', 0, 0, '', '', '', 'mod-product page-stock');
63
64print load_fiche_titre($langs->trans("StocksArea"), '', 'stock');
65
66
67//print '<table border="0" width="100%" class="notopnoleftnoright">';
68//print '<tr><td valign="top" width="30%" class="notopnoleft">';
69print '<div class="fichecenter"><div class="fichethirdleft">';
70
71
72if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // This may be useless due to the global search combo
73 print '<form method="post" action="'.DOL_URL_ROOT.'/product/stock/list.php">';
74 print '<input type="hidden" name="token" value="'.newToken().'">';
75 print '<div class="div-table-responsive-no-min">';
76 print '<table class="noborder nohover centpercent">';
77 print "<tr class=\"liste_titre\">";
78 print '<td colspan="3">'.$langs->trans("Search").'</td></tr>';
79 print '<tr class="oddeven"><td>';
80 print $langs->trans("Warehouse").':</td><td><input class="flat" type="text" size="18" name="sall"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
81 print "</table></div></form><br>";
82}
83
84$max = 15;
85
86$sql = "SELECT e.rowid, e.ref as label, e.lieu, e.statut as status";
87$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
88$sql .= " WHERE e.statut in (".Entrepot::STATUS_CLOSED.",".Entrepot::STATUS_OPEN_ALL.")";
89$sql .= " AND e.entity IN (".getEntity('stock').")";
90$sql .= $db->order('e.statut', 'DESC');
91$sql .= $db->plimit($max + 1, 0);
92
93$result = $db->query($sql);
94
95if ($result) {
96 $num = $db->num_rows($result);
97
98 print '<div class="div-table-responsive-no-min">';
99 print '<table class="noborder centpercent">';
100 print '<tr class="liste_titre">';
101 print '<th colspan="2">';
102 print $langs->trans("Warehouses").' ';
103 print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php">';
104 // TODO: "search_status" on "/product/stock/list.php" currently only accept a single integer value
105 //print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?search_status='.Entrepot::STATUS_CLOSED.','.Entrepot::STATUS_OPEN_ALL.'">';
106 print '<span class="badge">'.$num.'</span>';
107 print '</a>';
108 print '</th>';
109 print '</tr>';
110
111 $i = 0;
112 if ($num) {
113 while ($i < min($max, $num)) {
114 $objp = $db->fetch_object($result);
115
116 $warehouse->id = $objp->rowid;
117 $warehouse->statut = $objp->status;
118 $warehouse->label = $objp->label;
119 $warehouse->lieu = $objp->lieu;
120
121 print '<tr class="oddeven">';
122 print '<td>';
123 print $warehouse->getNomUrl(1);
124 print '</td>'."\n";
125 print '<td class="right">';
126 print $warehouse->getLibStatut(5);
127 print '</td>';
128 print "</tr>\n";
129 $i++;
130 }
131 $db->free($result);
132 } else {
133 print '<tr><td>'.$langs->trans("None").'</td><td></td></tr>';
134 }
135 if ($num > $max) {
136 print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td></tr>';
137 }
138
139 print "</table>";
140 print '</div>';
141} else {
142 dol_print_error($db);
143}
144
145
146print '</div><div class="fichetwothirdright">';
147
148
149// Latest movements
150$max = 10;
151$sql = "SELECT p.rowid, p.label as produit, p.tobatch, p.tosell, p.tobuy,";
152$sql .= " e.ref as warehouse_ref, e.rowid as warehouse_id, e.ref as warehouse_label, e.lieu, e.statut as warehouse_status,";
153$sql .= " m.rowid as mid, m.value as qty, m.datem, m.batch, m.eatby, m.sellby";
154$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
155$sql .= ", ".MAIN_DB_PREFIX."stock_mouvement as m";
156$sql .= ", ".MAIN_DB_PREFIX."product as p";
157$sql .= " WHERE m.fk_product = p.rowid";
158$sql .= " AND m.fk_entrepot = e.rowid";
159$sql .= " AND e.entity IN (".getEntity('stock').")";
160if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
161 $sql .= " AND p.fk_product_type = ".Product::TYPE_PRODUCT;
162}
163$sql .= $db->order("datem", "DESC");
164$sql .= $db->plimit($max, 0);
165
166dol_syslog("Index:list stock movements", LOG_DEBUG);
167$resql = $db->query($sql);
168if ($resql) {
169 $num = $db->num_rows($resql);
170
171 print '<div class="div-table-responsive-no-min">';
172 print '<table class="noborder centpercent">';
173 print '<tr class="liste_titre">';
174 print '<th>'.$langs->trans("LastMovements", min($num, $max)).'</th>';
175 print '<th>'.$langs->trans("Product").'</th>';
176 if (isModEnabled('productbatch')) {
177 print '<th>'.$langs->trans("Batch").'</th>';
178 /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
179 print '<th>'.$langs->trans("SellByDate").'</th>';
180 }
181 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
182 print '<th>'.$langs->trans("EatByDate").'</th>';
183 }*/
184 }
185 print '<th>'.$langs->trans("Warehouse").'</th>';
186 print '<th class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/product/stock/movement_list.php">'.$langs->trans("FullList").'</a></th>';
187 print "</tr>\n";
188
189 $tmplotstatic = new Productlot($db);
190
191 $i = 0;
192 while ($i < min($num, $max)) {
193 $objp = $db->fetch_object($resql);
194
195 $producttmp->id = $objp->rowid;
196 $producttmp->ref = $objp->produit;
197 $producttmp->status_batch = $objp->tobatch;
198 $producttmp->status_sell = $objp->tosell;
199 $producttmp->status_buy = $objp->tobuy;
200
201 $warehouse->id = $objp->warehouse_id;
202 $warehouse->ref = $objp->warehouse_ref;
203 $warehouse->statut = $objp->warehouse_status;
204 $warehouse->label = $objp->warehouse_label;
205 $warehouse->lieu = $objp->lieu;
206
207 $tmplotstatic->batch = $objp->batch;
208 $tmplotstatic->sellby = $objp->sellby;
209 $tmplotstatic->eatby = $objp->eatby;
210
211 print '<tr class="oddeven">';
212 print '<td class="nowraponall">'.img_picto($langs->trans("Ref").' '.$objp->mid, 'movement', 'class="pictofixedwidth"').dol_print_date($db->jdate($objp->datem), 'dayhour').'</td>';
213 print '<td class="tdoverflowmax150">';
214 print $producttmp->getNomUrl(1);
215 print "</td>\n";
216 if (isModEnabled('productbatch')) {
217 print '<td>';
218 print $tmplotstatic->getNomUrl(0, 'nolink');
219 print '</td>';
220 /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
221 print '<td>'.dol_print_date($db->jdate($objp->sellby), 'day').'</td>';
222 }
223 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
224 print '<td>'.dol_print_date($db->jdate($objp->eatby), 'day').'</td>';
225 }*/
226 }
227 print '<td class="tdoverflowmax150">';
228 print $warehouse->getNomUrl(1);
229 print "</td>\n";
230 print '<td class="right">';
231 if ($objp->qty > 0) {
232 print '+';
233 }
234 print $objp->qty.'</td>';
235 print "</tr>\n";
236 $i++;
237 }
238 $db->free($resql);
239
240 print "</table>";
241 print '</div>';
242} else {
243 dol_print_error($db);
244}
245
246print '</div></div>';
247
248$parameters = array('user' => $user);
249$reshook = $hookmanager->executeHooks('dashboardWarehouse', $parameters, $object); // Note that $action and $object may have been modified by hook
250
251// End of page
252llxFooter();
253$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage warehouses.
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
Class to manage products or services.
Class with list of lots and properties.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
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.