dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.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
46// Load translation files required by the page
47$langs->loadLangs(array('products', 'stocks', 'orders'));
48
49$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'replenishorders'; // To manage different context of search
50
51$sall = GETPOST('search_all', 'alphanohtml');
52$sref = GETPOST('search_ref', 'alpha');
53$snom = GETPOST('search_nom', 'alpha');
54$suser = GETPOST('search_user', 'alpha');
55$sttc = GETPOST('search_ttc', 'alpha');
56$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
57$search_product = GETPOSTINT('search_product');
58$search_dateyear = GETPOSTINT('search_dateyear');
59$search_datemonth = GETPOSTINT('search_datemonth');
60$search_dateday = GETPOSTINT('search_dateday');
61$search_date = dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_dateyear);
62$optioncss = GETPOST('optioncss', 'alpha');
63
64$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
65$sortfield = GETPOST('sortfield', 'aZ09comma');
66$sortorder = GETPOST('sortorder', 'aZ09comma');
67if (!$sortorder) {
68 $sortorder = 'DESC';
69}
70if (!$sortfield) {
71 $sortfield = 'cf.date_creation';
72}
73$page = GETPOSTINT('page') ? GETPOSTINT('page') : 0;
74if ($page < 0) {
75 $page = 0;
76}
77$offset = $limit * $page;
78
79// Security check
80if ($user->socid) {
81 $socid = $user->socid;
82}
83$result = restrictedArea($user, 'produit|service');
84
85
86/*
87 * Actions
88 */
89
90if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
91 $sall = "";
92 $sref = "";
93 $snom = "";
94 $suser = "";
95 $sttc = "";
96 $search_date = '';
97 $search_datemonth = '';
98 $search_dateday = '';
99 $search_dateyear = '';
100 $search_product = 0;
101}
102
103
104
105/*
106 * View
107 */
108
109$form = new Form($db);
110
111$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
112$texte = $langs->trans('ReplenishmentOrders');
113
114llxHeader('', $texte, $helpurl, '', 0, 0, '', '', '', 'mod-product page-stock_replenishorders');
115
116print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
117
118$head = array();
119
120$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
121$head[0][1] = $langs->trans('MissingStocks');
122$head[0][2] = 'replenish';
123
124$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
125$head[1][1] = $texte;
126$head[1][2] = 'replenishorders';
127
128print dol_get_fiche_head($head, 'replenishorders', '', -1, '');
129
130$commandestatic = new CommandeFournisseur($db);
131
132$sql = 'SELECT s.rowid as socid, s.nom as name, cf.date_creation as dc,';
133$sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc, cf.fk_user_author,';
134$sql .= ' u.login';
135$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande_fournisseur as cf';
136$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON cf.fk_user_author = u.rowid';
137if (!$user->hasRight('societe', 'client', 'voir')) {
138 $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
139}
140$sql .= ' WHERE cf.fk_soc = s.rowid ';
141$sql .= ' AND cf.entity = '.$conf->entity;
142if (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
143 $sql .= ' AND cf.fk_statut < 3';
144} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
145 $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).
146} else {
147 $sql .= ' AND cf.fk_statut < 5';
148}
149if (!$user->hasRight('societe', 'client', 'voir')) {
150 $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.((int) $user->id);
151}
152if ($sref) {
153 $sql .= natural_search('cf.ref', $sref);
154}
155if ($snom) {
156 $sql .= natural_search('s.nom', $snom);
157}
158if ($suser) {
159 natural_search(array('u.lastname', 'u.firstname', 'u.login'), $suser);
160}
161if ($sttc) {
162 $sql .= natural_search('cf.total_ttc', $sttc, 1);
163}
164$sql .= dolSqlDateFilter('cf.date_creation', $search_dateday, $search_datemonth, $search_dateyear);
165if ($sall) {
166 $sql .= natural_search(array('cf.ref', 'cf.note'), $sall);
167}
168if (!empty($socid)) {
169 $sql .= ' AND s.rowid = '.((int) $socid);
170}
171if (GETPOSTINT('statut')) {
172 $sql .= ' AND fk_statut = '.GETPOSTINT('statut');
173}
174$sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
175$sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
176$sql .= $db->order($sortfield, $sortorder);
177if (!$search_product) {
178 $sql .= $db->plimit($limit + 1, $offset);
179}
180
181$resql = $db->query($sql);
182if ($resql) {
183 $num = $db->num_rows($resql);
184 $i = 0;
185
186 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
187 print '<input type="hidden" name="token" value="'.newToken().'">';
188
189 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ReplenishmentOrdersDesc").'</span><br class="hideonsmartphone">';
190
191 print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, '');
192
193 $param = '';
194 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
195 $param .= '&contextpage='.urlencode($contextpage);
196 }
197 if ($limit > 0 && $limit != $conf->liste_limit) {
198 $param .= '&limit='.((int) $limit);
199 }
200 if ($sref) {
201 $param .= '&search_ref='.urlencode($sref);
202 }
203 if ($snom) {
204 $param .= '&search_nom='.urlencode($snom);
205 }
206 if ($suser) {
207 $param .= '&search_user='.urlencode($suser);
208 }
209 if ($sttc) {
210 $param .= '&search_ttc='.urlencode($sttc);
211 }
212 if ($search_dateyear) {
213 $param .= '&search_dateyear='.urlencode((string) ($search_dateyear));
214 }
215 if ($search_datemonth) {
216 $param .= '&search_datemonth='.urlencode((string) ($search_datemonth));
217 }
218 if ($search_dateday) {
219 $param .= '&search_dateday='.urlencode((string) ($search_dateday));
220 }
221 if ($optioncss != '') {
222 $param .= '&optioncss='.urlencode($optioncss);
223 }
224
225 print '<div class="div-table-responsive-no-min">';
226 print '<table class="noborder centpercent">';
227
228 print '<tr class="liste_titre_filter">';
229 print '<td class="liste_titre">';
230 print '<input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($sref).'">';
231 print '</td>';
232 print '<td class="liste_titre">';
233 print '<input type="text" class="flat maxwidth100" name="search_nom" value="'.dol_escape_htmltag($snom).'">';
234 print '</td>';
235 print '<td class="liste_titre">';
236 print '<input type="text" class="flat maxwidth100" name="search_user" value="'.dol_escape_htmltag($suser).'">';
237 print '</td>';
238 print '<td class="liste_titre right">';
239 print '<input type="text" class="flat width75" name="search_ttc" value="'.dol_escape_htmltag($sttc).'">';
240 print '</td>';
241 print '<td class="liste_titre center">';
242 print $form->selectDate($search_date, 'search_date', 0, 0, 1, '', 1, 0, 0, '');
243 print '</td>';
244 print '<td class="liste_titre right">';
245 $searchpicto = $form->showFilterAndCheckAddButtons(0);
246 print $searchpicto;
247 print '</td>';
248 print '</tr>';
249
250 print '<tr class="liste_titre">';
252 'Ref',
253 $_SERVER['PHP_SELF'],
254 'cf.ref',
255 '',
256 $param,
257 '',
258 $sortfield,
259 $sortorder
260 );
262 'Company',
263 $_SERVER['PHP_SELF'],
264 's.nom',
265 '',
266 $param,
267 '',
268 $sortfield,
269 $sortorder
270 );
272 'Author',
273 $_SERVER['PHP_SELF'],
274 'u.login',
275 '',
276 '',
277 '',
278 $sortfield,
279 $sortorder
280 );
282 'AmountTTC',
283 $_SERVER['PHP_SELF'],
284 'cf.total_ttc',
285 '',
286 $param,
287 '',
288 $sortfield,
289 $sortorder,
290 'right '
291 );
293 'OrderCreation',
294 $_SERVER['PHP_SELF'],
295 'cf.date_creation',
296 '',
297 $param,
298 '',
299 $sortfield,
300 $sortorder,
301 'center '
302 );
304 'Status',
305 $_SERVER['PHP_SELF'],
306 'cf.fk_statut',
307 '',
308 $param,
309 '',
310 $sortfield,
311 $sortorder,
312 'right '
313 );
314 print '</tr>';
315
316 $userstatic = new User($db);
317
318 while ($i < min($num, $search_product ? $num : $conf->liste_limit)) {
319 $obj = $db->fetch_object($resql);
320
321 $showline = dolDispatchToDo($obj->rowid) && (!$search_product || in_array($search_product, getProducts($obj->rowid)));
322
323 if ($showline) {
324 $href = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$obj->rowid;
325
326 print '<tr>';
327
328 // Ref
329 print '<td>';
330 print '<a href="'.$href.'">'.img_object($langs->trans('ShowOrder'), 'order').' '.$obj->ref.'</a>';
331 print '</td>';
332
333 // Company
334 $href = DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid;
335 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->name).'"><a href="'.$href.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$obj->name.'</a></td>';
336
337 // Author
338 $userstatic->id = $obj->fk_user_author;
339 $userstatic->login = $obj->login;
340 if ($userstatic->id) {
341 $txt = $userstatic->getLoginUrl(1);
342 } else {
343 $txt = '&nbsp;';
344 }
345 print '<td>'.$txt.'</td>';
346
347 // Amount
348 print '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
349
350 // Date
351 if ($obj->dc) {
352 $date = dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel');
353 } else {
354 $date = '-';
355 }
356 print '<td class="center">'.$date.'</td>';
357
358 // Statut
359 print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, 5).'</td>';
360
361 print '</tr>';
362 }
363 $i++;
364 }
365 print '</table>';
366 print '</div>';
367
368 print '</form>';
369
370 $db->free($resql);
371
372 print dol_get_fiche_end();
373} else {
374 dol_print_error($db);
375}
376
377// End of page
378llxFooter();
379$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 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:382
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_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=null, $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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.