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