dolibarr 25.0.0-alpha
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 * Copyright (C) 2026 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/class/product.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
34require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
35require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
36require_once DOL_DOCUMENT_ROOT.'/product/stock/lib/replenishment.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38
47// Load translation files required by the page
48$langs->loadLangs(array('products', 'stocks', 'orders'));
49
50$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'replenishorders'; // To manage different context of search
51
52$sall = GETPOST('search_all', 'alphanohtml');
53$sref = GETPOST('search_ref', 'alpha');
54$snom = GETPOST('search_nom', 'alpha');
55$suser = GETPOST('search_user', 'alpha');
56$sttc = GETPOST('search_ttc', 'alpha');
57$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
58$search_product = GETPOSTINT('search_product');
59$search_dateyear = GETPOSTINT('search_dateyear');
60$search_datemonth = GETPOSTINT('search_datemonth');
61$search_dateday = GETPOSTINT('search_dateday');
62$search_date = dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_dateyear);
63$optioncss = GETPOST('optioncss', 'alpha');
64
65$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
66$sortfield = GETPOST('sortfield', 'aZ09comma');
67$sortorder = GETPOST('sortorder', 'aZ09comma');
68if (!$sortorder) {
69 $sortorder = 'DESC';
70}
71if (!$sortfield) {
72 $sortfield = 'cf.date_creation';
73}
74$page = GETPOSTINT('page') ? GETPOSTINT('page') : 0;
75if ($page < 0) {
76 $page = 0;
77}
78$offset = $limit * $page;
79
80// Security check
81if ($user->socid) {
82 $socid = $user->socid;
83}
84
85if (!isModEnabled('stock')) {
86 accessforbidden("Module stock must be enabled to use this feature");
87}
88if (!$user->hasRight('stock', 'read')) {
89 accessforbidden("You need permission to read stock to access this feature");
90}
91
92restrictedArea($user, 'produit|service');
93
94
95/*
96 * Actions
97 */
98
99if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
100 $sall = "";
101 $sref = "";
102 $snom = "";
103 $suser = "";
104 $sttc = "";
105 $search_date = '';
106 $search_datemonth = '';
107 $search_dateday = '';
108 $search_dateyear = '';
109 $search_product = 0;
110}
111
112
113/*
114 * View
115 */
116
117$form = new Form($db);
118
119$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
120$texte = $langs->trans('ReplenishmentOrders');
121
122llxHeader('', $texte, $helpurl, '', 0, 0, '', '', '', 'mod-product page-stock_replenishorders');
123
124print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
125
126$head = array();
127
128$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
129$head[0][1] = $langs->trans('MissingStocks');
130$head[0][2] = 'replenish';
131
132$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
133$head[1][1] = $texte;
134$head[1][2] = 'replenishorders';
135
136print dol_get_fiche_head($head, 'replenishorders', '', -1, '');
137
138$commandestatic = new CommandeFournisseur($db);
139
140$sql = 'SELECT s.rowid as socid, s.nom as name, cf.date_creation as dc,';
141$sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc, cf.fk_user_author,';
142$sql .= ' u.login';
143$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande_fournisseur as cf';
144$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON cf.fk_user_author = u.rowid';
145if (!$user->hasRight('societe', 'client', 'voir')) {
146 $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
147}
148$sql .= ' WHERE cf.fk_soc = s.rowid ';
149$sql .= ' AND cf.entity = '.((int) $conf->entity);
150if (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
151 $sql .= ' AND cf.fk_statut < 3';
152} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
153 $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).
154} else {
155 $sql .= ' AND cf.fk_statut < 5';
156}
157if (!$user->hasRight('societe', 'client', 'voir')) {
158 $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.((int) $user->id);
159}
160if ($sref) {
161 $sql .= natural_search('cf.ref', $sref);
162}
163if ($snom) {
164 $sql .= natural_search('s.nom', $snom);
165}
166if ($suser) {
167 natural_search(array('u.lastname', 'u.firstname', 'u.login'), $suser);
168}
169if ($sttc) {
170 $sql .= natural_search('cf.total_ttc', $sttc, 1);
171}
172$sql .= dolSqlDateFilter('cf.date_creation', $search_dateday, $search_datemonth, $search_dateyear);
173if ($sall) {
174 $sql .= natural_search(array('cf.ref', 'cf.note'), $sall);
175}
176if (!empty($socid)) {
177 $sql .= ' AND s.rowid = '.((int) $socid);
178}
179if (GETPOSTINT('statut')) {
180 $sql .= ' AND fk_statut = '.GETPOSTINT('statut');
181}
182$sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
183$sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
184$sql .= $db->order($sortfield, $sortorder);
185if (!$search_product) {
186 $sql .= $db->plimit($limit + 1, $offset);
187}
188
189$resql = $db->query($sql);
190if ($resql) {
191 $num = $db->num_rows($resql);
192 $i = 0;
193
194 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
195 print '<input type="hidden" name="token" value="'.newToken().'">';
196
197 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ReplenishmentOrdersDesc").'</span><br class="hideonsmartphone">';
198
199 print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, '');
200
201 $param = '';
202 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
203 $param .= '&contextpage='.urlencode($contextpage);
204 }
205 if ($limit > 0 && $limit != $conf->liste_limit) {
206 $param .= '&limit='.((int) $limit);
207 }
208 if ($sref) {
209 $param .= '&search_ref='.urlencode($sref);
210 }
211 if ($snom) {
212 $param .= '&search_nom='.urlencode($snom);
213 }
214 if ($suser) {
215 $param .= '&search_user='.urlencode($suser);
216 }
217 if ($sttc) {
218 $param .= '&search_ttc='.urlencode($sttc);
219 }
220 if ($search_dateyear) {
221 $param .= '&search_dateyear='.urlencode((string) ($search_dateyear));
222 }
223 if ($search_datemonth) {
224 $param .= '&search_datemonth='.urlencode((string) ($search_datemonth));
225 }
226 if ($search_dateday) {
227 $param .= '&search_dateday='.urlencode((string) ($search_dateday));
228 }
229 if ($optioncss != '') {
230 $param .= '&optioncss='.urlencode($optioncss);
231 }
232
233 print '<div class="div-table-responsive-no-min">';
234 print '<table class="noborder centpercent">';
235
236 print '<tr class="liste_titre_filter">';
237 print '<td class="liste_titre">';
238 print '<input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($sref).'">';
239 print '</td>';
240 print '<td class="liste_titre">';
241 print '<input type="text" class="flat maxwidth100" name="search_nom" value="'.dol_escape_htmltag($snom).'">';
242 print '</td>';
243 print '<td class="liste_titre">';
244 print '<input type="text" class="flat maxwidth100" name="search_user" value="'.dol_escape_htmltag($suser).'">';
245 print '</td>';
246 print '<td class="liste_titre right">';
247 print '<input type="text" class="flat width75" name="search_ttc" value="'.dol_escape_htmltag($sttc).'">';
248 print '</td>';
249 print '<td class="liste_titre center">';
250 print $form->selectDate($search_date, 'search_date', 0, 0, 1, '', 1, 0, 0, '');
251 print '</td>';
252 print '<td class="liste_titre right">';
253 $searchpicto = $form->showFilterAndCheckAddButtons(0);
254 print $searchpicto;
255 print '</td>';
256 print '</tr>';
257
258 print '<tr class="liste_titre">';
260 'Ref',
261 $_SERVER['PHP_SELF'],
262 'cf.ref',
263 '',
264 $param,
265 '',
266 $sortfield,
267 $sortorder
268 );
270 'Company',
271 $_SERVER['PHP_SELF'],
272 's.nom',
273 '',
274 $param,
275 '',
276 $sortfield,
277 $sortorder
278 );
280 'Author',
281 $_SERVER['PHP_SELF'],
282 'u.login',
283 '',
284 '',
285 '',
286 $sortfield,
287 $sortorder
288 );
290 'AmountTTC',
291 $_SERVER['PHP_SELF'],
292 'cf.total_ttc',
293 '',
294 $param,
295 '',
296 $sortfield,
297 $sortorder,
298 'right '
299 );
301 'OrderCreation',
302 $_SERVER['PHP_SELF'],
303 'cf.date_creation',
304 '',
305 $param,
306 '',
307 $sortfield,
308 $sortorder,
309 'center '
310 );
312 'Status',
313 $_SERVER['PHP_SELF'],
314 'cf.fk_statut',
315 '',
316 $param,
317 '',
318 $sortfield,
319 $sortorder,
320 'right '
321 );
322 print '</tr>';
323
324 $userstatic = new User($db);
325
326 while ($i < min($num, $search_product ? $num : $conf->liste_limit)) {
327 $obj = $db->fetch_object($resql);
328
329 $showline = dolDispatchToDo($obj->rowid) && (!$search_product || in_array($search_product, getProducts($obj->rowid)));
330
331 if ($showline) {
332 $href = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$obj->rowid;
333
334 print '<tr>';
335
336 // Ref
337 print '<td>';
338 print '<a href="'.$href.'">'.img_object($langs->trans('ShowOrder'), 'order').' '.$obj->ref.'</a>';
339 print '</td>';
340
341 // Company
342 $href = DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid;
343 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->name).'"><a href="'.$href.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$obj->name.'</a></td>';
344
345 // Author
346 $userstatic->id = $obj->fk_user_author;
347 $userstatic->login = $obj->login;
348 if ($userstatic->id) {
349 $txt = $userstatic->getLoginUrl(1);
350 } else {
351 $txt = '&nbsp;';
352 }
353 print '<td>'.$txt.'</td>';
354
355 // Amount
356 print '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
357
358 // Date
359 if ($obj->dc) {
360 $date = dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel');
361 } else {
362 $date = '-';
363 }
364 print '<td class="center">'.$date.'</td>';
365
366 // Statut
367 print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, 5).'</td>';
368
369 print '</tr>';
370 }
371 $i++;
372 }
373 print '</table>';
374 print '</div>';
375
376 print '</form>';
377
378 $db->free($resql);
379
380 print dol_get_fiche_end();
381} else {
383}
384
385// End of page
386llxFooter();
387$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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:386
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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...
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:519
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.