dolibarr  16.0.5
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 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
32 
33 $hookmanager = new HookManager($db);
34 
35 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
36 $hookmanager->initHooks(array('stockindex'));
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('stocks', 'productbatch'));
40 
41 // Security check
42 $result = restrictedArea($user, 'stock');
43 
44 
45 /*
46  * View
47  */
48 
49 $producttmp = new Product($db);
50 $warehouse = new Entrepot($db);
51 
52 $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
53 llxHeader("", $langs->trans("Stocks"), $help_url);
54 
55 print load_fiche_titre($langs->trans("StocksArea"), '', 'stock');
56 
57 
58 //print '<table border="0" width="100%" class="notopnoleftnoright">';
59 //print '<tr><td valign="top" width="30%" class="notopnoleft">';
60 print '<div class="fichecenter"><div class="fichethirdleft">';
61 
62 
63 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This may be useless due to the global search combo
64  print '<form method="post" action="'.DOL_URL_ROOT.'/product/stock/list.php">';
65  print '<input type="hidden" name="token" value="'.newToken().'">';
66  print '<div class="div-table-responsive-no-min">';
67  print '<table class="noborder nohover centpercent">';
68  print "<tr class=\"liste_titre\">";
69  print '<td colspan="3">'.$langs->trans("Search").'</td></tr>';
70  print '<tr class="oddevene"><td>';
71  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>';
72  print "</table></div></form><br>";
73 }
74 
75 $max = 15;
76 
77 $sql = "SELECT e.rowid, e.ref as label, e.lieu, e.statut as status";
78 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
79 $sql .= " WHERE e.statut in (".Entrepot::STATUS_CLOSED.",".Entrepot::STATUS_OPEN_ALL.")";
80 $sql .= " AND e.entity IN (".getEntity('stock').")";
81 $sql .= $db->order('e.statut', 'DESC');
82 $sql .= $db->plimit($max + 1, 0);
83 
84 $result = $db->query($sql);
85 
86 if ($result) {
87  $num = $db->num_rows($result);
88 
89  print '<div class="div-table-responsive-no-min">';
90  print '<table class="noborder centpercent">';
91  print '<tr class="liste_titre">';
92  print '<th colspan="2">';
93  print $langs->trans("Warehouses").' ';
94  print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php">';
95  // TODO: "search_status" on "/product/stock/list.php" currently only accept a single integer value
96  //print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?search_status='.Entrepot::STATUS_CLOSED.','.Entrepot::STATUS_OPEN_ALL.'">';
97  print '<span class="badge">'.$num.'</span>';
98  print '</a>';
99  print '</th>';
100  print '</tr>';
101 
102  $i = 0;
103  if ($num) {
104  while ($i < min($max, $num)) {
105  $objp = $db->fetch_object($result);
106 
107  $warehouse->id = $objp->rowid;
108  $warehouse->statut = $objp->status;
109  $warehouse->label = $objp->label;
110  $warehouse->lieu = $objp->lieu;
111 
112  print '<tr class="oddeven">';
113  print '<td>';
114  print $warehouse->getNomUrl(1);
115  print '</td>'."\n";
116  print '<td class="right">';
117  print $warehouse->getLibStatut(5);
118  print '</td>';
119  print "</tr>\n";
120  $i++;
121  }
122  $db->free($result);
123  } else {
124  print '<tr><td>'.$langs->trans("None").'</td><td></td></tr>';
125  }
126  if ($num > $max) {
127  print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td></tr>';
128  }
129 
130  print "</table>";
131  print '</div>';
132 } else {
133  dol_print_error($db);
134 }
135 
136 
137 print '</div><div class="fichetwothirdright">';
138 
139 
140 // Latest movements
141 $max = 10;
142 $sql = "SELECT p.rowid, p.label as produit, p.tobatch, p.tosell, p.tobuy,";
143 $sql .= " e.ref as warehouse_ref, e.rowid as warehouse_id, e.ref as warehouse_label, e.lieu, e.statut as warehouse_status,";
144 $sql .= " m.rowid as mid, m.value as qty, m.datem, m.batch, m.eatby, m.sellby";
145 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
146 $sql .= ", ".MAIN_DB_PREFIX."stock_mouvement as m";
147 $sql .= ", ".MAIN_DB_PREFIX."product as p";
148 $sql .= " WHERE m.fk_product = p.rowid";
149 $sql .= " AND m.fk_entrepot = e.rowid";
150 $sql .= " AND e.entity IN (".getEntity('stock').")";
151 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
152  $sql .= " AND p.fk_product_type = ".Product::TYPE_PRODUCT;
153 }
154 $sql .= $db->order("datem", "DESC");
155 $sql .= $db->plimit($max, 0);
156 
157 dol_syslog("Index:list stock movements", LOG_DEBUG);
158 $resql = $db->query($sql);
159 if ($resql) {
160  $num = $db->num_rows($resql);
161 
162  print '<div class="div-table-responsive-no-min">';
163  print '<table class="noborder centpercent">';
164  print "<tr class=\"liste_titre\">";
165  print '<th>'.$langs->trans("LastMovements", min($num, $max)).'</th>';
166  print '<th>'.$langs->trans("Product").'</th>';
167  if (!empty($conf->productbatch->enabled)) {
168  print '<th>'.$langs->trans("Batch").'</th>';
169  /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
170  print '<th>'.$langs->trans("SellByDate").'</th>';
171  }
172  if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
173  print '<th>'.$langs->trans("EatByDate").'</th>';
174  }*/
175  }
176  print '<th>'.$langs->trans("Warehouse").'</th>';
177  print '<th class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/product/stock/movement_list.php">'.$langs->trans("FullList").'</a></th>';
178  print "</tr>\n";
179 
180  $tmplotstatic = new Productlot($db);
181 
182  $i = 0;
183  while ($i < min($num, $max)) {
184  $objp = $db->fetch_object($resql);
185 
186  $producttmp->id = $objp->rowid;
187  $producttmp->ref = $objp->produit;
188  $producttmp->status_batch = $objp->tobatch;
189  $producttmp->status_sell = $objp->tosell;
190  $producttmp->status_buy = $objp->tobuy;
191 
192  $warehouse->id = $objp->warehouse_id;
193  $warehouse->ref = $objp->warehouse_ref;
194  $warehouse->statut = $objp->warehouse_status;
195  $warehouse->label = $objp->warehouse_label;
196  $warehouse->lieu = $objp->lieu;
197 
198  $tmplotstatic->batch = $objp->batch;
199  $tmplotstatic->sellby = $objp->sellby;
200  $tmplotstatic->eatby = $objp->eatby;
201 
202  print '<tr class="oddeven">';
203  print '<td class="nowraponall">'.img_picto($langs->trans("Ref").' '.$objp->mid, 'movement', 'class="pictofixedwidth"').dol_print_date($db->jdate($objp->datem), 'dayhour').'</td>';
204  print '<td class="tdoverflowmax200">';
205  print $producttmp->getNomUrl(1);
206  print "</td>\n";
207  if (!empty($conf->productbatch->enabled)) {
208  print '<td>';
209  print $tmplotstatic->getNomUrl(0, 'nolink');
210  print '</td>';
211  /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
212  print '<td>'.dol_print_date($db->jdate($objp->sellby), 'day').'</td>';
213  }
214  if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
215  print '<td>'.dol_print_date($db->jdate($objp->eatby), 'day').'</td>';
216  }*/
217  }
218  print '<td class="tdoverflowmax200">';
219  print $warehouse->getNomUrl(1);
220  print "</td>\n";
221  print '<td class="right">';
222  if ($objp->qty > 0) {
223  print '+';
224  }
225  print $objp->qty.'</td>';
226  print "</tr>\n";
227  $i++;
228  }
229  $db->free($resql);
230 
231  print "</table>";
232  print '</div>';
233 } else {
234  dol_print_error($db);
235 }
236 
237 print '</div></div>';
238 
239 $parameters = array('user' => $user);
240 $reshook = $hookmanager->executeHooks('dashboardWarehouse', $parameters, $object); // Note that $action and $object may have been modified by hook
241 
242 // End of page
243 llxFooter();
244 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
Productlot
Class with list of lots and properties.
Definition: productlot.class.php:36
Entrepot\STATUS_OPEN_ALL
const STATUS_OPEN_ALL
Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corr...
Definition: entrepot.class.php:156
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
Product
Class to manage products or services.
Definition: product.class.php:46
Entrepot
Class to manage warehouses.
Definition: entrepot.class.php:35
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30