dolibarr 18.0.6
replenishorders.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
4 * Copyright (C) 2014 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
6 * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
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/class/product.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
33require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/stock/lib/replenishment.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37
38// Load translation files required by the page
39$langs->loadLangs(array('products', 'stocks', 'orders'));
40
41$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'replenishorders'; // To manage different context of search
42
43$sall = GETPOST('search_all', 'alphanohtml');
44$sref = GETPOST('search_ref', 'alpha');
45$snom = GETPOST('search_nom', 'alpha');
46$suser = GETPOST('search_user', 'alpha');
47$sttc = GETPOST('search_ttc', 'alpha');
48$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
49$search_product = GETPOST('search_product', 'int');
50$search_dateyear = GETPOST('search_dateyear', 'int');
51$search_datemonth = GETPOST('search_datemonth', 'int');
52$search_dateday = GETPOST('search_dateday', 'int');
53$search_date = dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_dateyear);
54$optioncss = GETPOST('optioncss', 'alpha');
55
56$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
57$sortfield = GETPOST('sortfield', 'aZ09comma');
58$sortorder = GETPOST('sortorder', 'aZ09comma');
59if (!$sortorder) {
60 $sortorder = 'DESC';
61}
62if (!$sortfield) {
63 $sortfield = 'cf.date_creation';
64}
65$page = GETPOST('page', 'int') ? GETPOST('page', 'int') : 0;
66if ($page < 0) {
67 $page = 0;
68}
69$offset = $limit * $page;
70
71// Security check
72if ($user->socid) {
73 $socid = $user->socid;
74}
75$result = restrictedArea($user, 'produit|service');
76
77
78/*
79 * Actions
80 */
81
82if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
83 $sall = "";
84 $sref = "";
85 $snom = "";
86 $suser = "";
87 $sttc = "";
88 $search_date = '';
89 $search_datemonth = '';
90 $search_dateday = '';
91 $search_dateyear = '';
92 $search_product = 0;
93}
94
95
96
97/*
98 * View
99 */
100
101$form = new Form($db);
102
103$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
104$texte = $langs->trans('ReplenishmentOrders');
105
106llxHeader('', $texte, $helpurl, '');
107
108print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
109
110$head = array();
111
112$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
113$head[0][1] = $langs->trans('MissingStocks');
114$head[0][2] = 'replenish';
115
116$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
117$head[1][1] = $texte;
118$head[1][2] = 'replenishorders';
119
120print dol_get_fiche_head($head, 'replenishorders', '', -1, '');
121
122$commandestatic = new CommandeFournisseur($db);
123
124$sql = 'SELECT s.rowid as socid, s.nom as name, cf.date_creation as dc,';
125$sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc, cf.fk_user_author,';
126$sql .= ' u.login';
127$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande_fournisseur as cf';
128$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON cf.fk_user_author = u.rowid';
129if (empty($user->rights->societe->client->voir) && !$socid) {
130 $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
131}
132$sql .= ' WHERE cf.fk_soc = s.rowid ';
133$sql .= ' AND cf.entity = '.$conf->entity;
134if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
135 $sql .= ' AND cf.fk_statut < 3';
136} elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
137 $sql .= ' AND cf.fk_statut < 6'; // We want also status 5, we will keep them visible if dispatching is not yet finished (tested with function dolDispatchToDo).
138} else {
139 $sql .= ' AND cf.fk_statut < 5';
140}
141if (empty($user->rights->societe->client->voir) && !$socid) {
142 $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.((int) $user->id);
143}
144if ($sref) {
145 $sql .= natural_search('cf.ref', $sref);
146}
147if ($snom) {
148 $sql .= natural_search('s.nom', $snom);
149}
150if ($suser) {
151 natural_search(array('u.lastname', 'u.firstname', 'u.login'), $suser);
152}
153if ($sttc) {
154 $sql .= natural_search('cf.total_ttc', $sttc, 1);
155}
156$sql .= dolSqlDateFilter('cf.date_creation', $search_dateday, $search_datemonth, $search_dateyear);
157if ($sall) {
158 $sql .= natural_search(array('cf.ref', 'cf.note'), $sall);
159}
160if (!empty($socid)) {
161 $sql .= ' AND s.rowid = '.((int) $socid);
162}
163if (GETPOST('statut', 'int')) {
164 $sql .= ' AND fk_statut = '.GETPOST('statut', 'int');
165}
166$sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
167$sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
168$sql .= $db->order($sortfield, $sortorder);
169if (!$search_product) {
170 $sql .= $db->plimit($limit + 1, $offset);
171}
172
173$resql = $db->query($sql);
174if ($resql) {
175 $num = $db->num_rows($resql);
176 $i = 0;
177
178 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
179 print '<input type="hidden" name="token" value="'.newToken().'">';
180
181 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ReplenishmentOrdersDesc").'</span><br class="hideonsmartphone">';
182
183 print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, '');
184
185 $param = '';
186 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
187 $param .= '&contextpage='.urlencode($contextpage);
188 }
189 if ($limit > 0 && $limit != $conf->liste_limit) {
190 $param .= '&limit='.((int) $limit);
191 }
192 if ($sref) {
193 $param .= '&search_ref='.urlencode($sref);
194 }
195 if ($snom) {
196 $param .= '&search_nom='.urlencode($snom);
197 }
198 if ($suser) {
199 $param .= '&search_user='.urlencode($suser);
200 }
201 if ($sttc) {
202 $param .= '&search_ttc='.urlencode($sttc);
203 }
204 if ($search_dateyear) {
205 $param .= '&search_dateyear='.urlencode($search_dateyear);
206 }
207 if ($search_datemonth) {
208 $param .= '&search_datemonth='.urlencode($search_datemonth);
209 }
210 if ($search_dateday) {
211 $param .= '&search_dateday='.urlencode($search_dateday);
212 }
213 if ($optioncss != '') {
214 $param .= '&optioncss='.urlencode($optioncss);
215 }
216
217 print '<div class="div-table-responsive-no-min">';
218 print '<table class="noborder centpercent">';
219
220 print '<tr class="liste_titre_filter">';
221 print '<td class="liste_titre">';
222 print '<input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($sref).'">';
223 print '</td>';
224 print '<td class="liste_titre">';
225 print '<input type="text" class="flat maxwidth100" name="search_nom" value="'.dol_escape_htmltag($snom).'">';
226 print '</td>';
227 print '<td class="liste_titre">';
228 print '<input type="text" class="flat maxwidth100" name="search_user" value="'.dol_escape_htmltag($suser).'">';
229 print '</td>';
230 print '<td class="liste_titre right">';
231 print '<input type="text" class="flat width75" name="search_ttc" value="'.dol_escape_htmltag($sttc).'">';
232 print '</td>';
233 print '<td class="liste_titre center">';
234 print $form->selectDate($search_date, 'search_date', 0, 0, 1, '', 1, 0, 0, '');
235 print '</td>';
236 print '<td class="liste_titre right">';
237 $searchpicto = $form->showFilterAndCheckAddButtons(0);
238 print $searchpicto;
239 print '</td>';
240 print '</tr>';
241
242 print '<tr class="liste_titre">';
244 'Ref',
245 $_SERVER['PHP_SELF'],
246 'cf.ref',
247 '',
248 $param,
249 '',
250 $sortfield,
251 $sortorder
252 );
254 'Company',
255 $_SERVER['PHP_SELF'],
256 's.nom',
257 '',
258 $param,
259 '',
260 $sortfield,
261 $sortorder
262 );
264 'Author',
265 $_SERVER['PHP_SELF'],
266 'u.login',
267 '',
268 '',
269 '',
270 $sortfield,
271 $sortorder
272 );
274 'AmountTTC',
275 $_SERVER['PHP_SELF'],
276 'cf.total_ttc',
277 '',
278 $param,
279 '',
280 $sortfield,
281 $sortorder,
282 'right '
283 );
285 'OrderCreation',
286 $_SERVER['PHP_SELF'],
287 'cf.date_creation',
288 '',
289 $param,
290 '',
291 $sortfield,
292 $sortorder,
293 'center '
294 );
296 'Status',
297 $_SERVER['PHP_SELF'],
298 'cf.fk_statut',
299 '',
300 $param,
301 '',
302 $sortfield,
303 $sortorder,
304 'right '
305 );
306 print '</tr>';
307
308 $userstatic = new User($db);
309
310 while ($i < min($num, $search_product ? $num : $conf->liste_limit)) {
311 $obj = $db->fetch_object($resql);
312
313 $showline = dolDispatchToDo($obj->rowid) && (!$search_product || in_array($search_product, getProducts($obj->rowid)));
314
315 if ($showline) {
316 $href = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$obj->rowid;
317
318 print '<tr>';
319
320 // Ref
321 print '<td>';
322 print '<a href="'.$href.'">'.img_object($langs->trans('ShowOrder'), 'order').' '.$obj->ref.'</a>';
323 print '</td>';
324
325 // Company
326 $href = DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid;
327 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->name).'"><a href="'.$href.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$obj->name.'</a></td>';
328
329 // Author
330 $userstatic->id = $obj->fk_user_author;
331 $userstatic->login = $obj->login;
332 if ($userstatic->id) {
333 $txt = $userstatic->getLoginUrl(1);
334 } else {
335 $txt = '&nbsp;';
336 }
337 print '<td>'.$txt.'</td>';
338
339 // Amount
340 print '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
341
342 // Date
343 if ($obj->dc) {
344 $date = dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel');
345 } else {
346 $date = '-';
347 }
348 print '<td class="center">'.$date.'</td>';
349
350 // Statut
351 print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, 5).'</td>';
352
353 print '</tr>';
354 }
355 $i++;
356 }
357 print '</table>';
358 print '</div>';
359
360 print '</form>';
361
362 $db->free($resql);
363
364 print dol_get_fiche_end();
365} else {
366 dol_print_error($db);
367}
368
369// End of page
370llxFooter();
371$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage predefined suppliers products.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:361
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dolDispatchToDo($order_id)
Check if there is still some dispatching of stock to do.
getProducts($order_id)
getProducts
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.