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