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$result = restrictedArea($user, 'produit|service');
85
86
87/*
88 * Actions
89 */
90
91if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
92 $sall = "";
93 $sref = "";
94 $snom = "";
95 $suser = "";
96 $sttc = "";
97 $search_date = '';
98 $search_datemonth = '';
99 $search_dateday = '';
100 $search_dateyear = '';
101 $search_product = 0;
102}
103
104
105
106/*
107 * View
108 */
109
110$form = new Form($db);
111
112$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
113$texte = $langs->trans('ReplenishmentOrders');
114
115llxHeader('', $texte, $helpurl, '', 0, 0, '', '', '', 'mod-product page-stock_replenishorders');
116
117print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
118
119$head = array();
120
121$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
122$head[0][1] = $langs->trans('MissingStocks');
123$head[0][2] = 'replenish';
124
125$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
126$head[1][1] = $texte;
127$head[1][2] = 'replenishorders';
128
129print dol_get_fiche_head($head, 'replenishorders', '', -1, '');
130
131$commandestatic = new CommandeFournisseur($db);
132
133$sql = 'SELECT s.rowid as socid, s.nom as name, cf.date_creation as dc,';
134$sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc, cf.fk_user_author,';
135$sql .= ' u.login';
136$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande_fournisseur as cf';
137$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON cf.fk_user_author = u.rowid';
138if (!$user->hasRight('societe', 'client', 'voir')) {
139 $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
140}
141$sql .= ' WHERE cf.fk_soc = s.rowid ';
142$sql .= ' AND cf.entity = '.((int) $conf->entity);
143if (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
144 $sql .= ' AND cf.fk_statut < 3';
145} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
146 $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).
147} else {
148 $sql .= ' AND cf.fk_statut < 5';
149}
150if (!$user->hasRight('societe', 'client', 'voir')) {
151 $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.((int) $user->id);
152}
153if ($sref) {
154 $sql .= natural_search('cf.ref', $sref);
155}
156if ($snom) {
157 $sql .= natural_search('s.nom', $snom);
158}
159if ($suser) {
160 natural_search(array('u.lastname', 'u.firstname', 'u.login'), $suser);
161}
162if ($sttc) {
163 $sql .= natural_search('cf.total_ttc', $sttc, 1);
164}
165$sql .= dolSqlDateFilter('cf.date_creation', $search_dateday, $search_datemonth, $search_dateyear);
166if ($sall) {
167 $sql .= natural_search(array('cf.ref', 'cf.note'), $sall);
168}
169if (!empty($socid)) {
170 $sql .= ' AND s.rowid = '.((int) $socid);
171}
172if (GETPOSTINT('statut')) {
173 $sql .= ' AND fk_statut = '.GETPOSTINT('statut');
174}
175$sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
176$sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
177$sql .= $db->order($sortfield, $sortorder);
178if (!$search_product) {
179 $sql .= $db->plimit($limit + 1, $offset);
180}
181
182$resql = $db->query($sql);
183if ($resql) {
184 $num = $db->num_rows($resql);
185 $i = 0;
186
187 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
188 print '<input type="hidden" name="token" value="'.newToken().'">';
189
190 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ReplenishmentOrdersDesc").'</span><br class="hideonsmartphone">';
191
192 print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, '');
193
194 $param = '';
195 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
196 $param .= '&contextpage='.urlencode($contextpage);
197 }
198 if ($limit > 0 && $limit != $conf->liste_limit) {
199 $param .= '&limit='.((int) $limit);
200 }
201 if ($sref) {
202 $param .= '&search_ref='.urlencode($sref);
203 }
204 if ($snom) {
205 $param .= '&search_nom='.urlencode($snom);
206 }
207 if ($suser) {
208 $param .= '&search_user='.urlencode($suser);
209 }
210 if ($sttc) {
211 $param .= '&search_ttc='.urlencode($sttc);
212 }
213 if ($search_dateyear) {
214 $param .= '&search_dateyear='.urlencode((string) ($search_dateyear));
215 }
216 if ($search_datemonth) {
217 $param .= '&search_datemonth='.urlencode((string) ($search_datemonth));
218 }
219 if ($search_dateday) {
220 $param .= '&search_dateday='.urlencode((string) ($search_dateday));
221 }
222 if ($optioncss != '') {
223 $param .= '&optioncss='.urlencode($optioncss);
224 }
225
226 print '<div class="div-table-responsive-no-min">';
227 print '<table class="noborder centpercent">';
228
229 print '<tr class="liste_titre_filter">';
230 print '<td class="liste_titre">';
231 print '<input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($sref).'">';
232 print '</td>';
233 print '<td class="liste_titre">';
234 print '<input type="text" class="flat maxwidth100" name="search_nom" value="'.dol_escape_htmltag($snom).'">';
235 print '</td>';
236 print '<td class="liste_titre">';
237 print '<input type="text" class="flat maxwidth100" name="search_user" value="'.dol_escape_htmltag($suser).'">';
238 print '</td>';
239 print '<td class="liste_titre right">';
240 print '<input type="text" class="flat width75" name="search_ttc" value="'.dol_escape_htmltag($sttc).'">';
241 print '</td>';
242 print '<td class="liste_titre center">';
243 print $form->selectDate($search_date, 'search_date', 0, 0, 1, '', 1, 0, 0, '');
244 print '</td>';
245 print '<td class="liste_titre right">';
246 $searchpicto = $form->showFilterAndCheckAddButtons(0);
247 print $searchpicto;
248 print '</td>';
249 print '</tr>';
250
251 print '<tr class="liste_titre">';
253 'Ref',
254 $_SERVER['PHP_SELF'],
255 'cf.ref',
256 '',
257 $param,
258 '',
259 $sortfield,
260 $sortorder
261 );
263 'Company',
264 $_SERVER['PHP_SELF'],
265 's.nom',
266 '',
267 $param,
268 '',
269 $sortfield,
270 $sortorder
271 );
273 'Author',
274 $_SERVER['PHP_SELF'],
275 'u.login',
276 '',
277 '',
278 '',
279 $sortfield,
280 $sortorder
281 );
283 'AmountTTC',
284 $_SERVER['PHP_SELF'],
285 'cf.total_ttc',
286 '',
287 $param,
288 '',
289 $sortfield,
290 $sortorder,
291 'right '
292 );
294 'OrderCreation',
295 $_SERVER['PHP_SELF'],
296 'cf.date_creation',
297 '',
298 $param,
299 '',
300 $sortfield,
301 $sortorder,
302 'center '
303 );
305 'Status',
306 $_SERVER['PHP_SELF'],
307 'cf.fk_statut',
308 '',
309 $param,
310 '',
311 $sortfield,
312 $sortorder,
313 'right '
314 );
315 print '</tr>';
316
317 $userstatic = new User($db);
318
319 while ($i < min($num, $search_product ? $num : $conf->liste_limit)) {
320 $obj = $db->fetch_object($resql);
321
322 $showline = dolDispatchToDo($obj->rowid) && (!$search_product || in_array($search_product, getProducts($obj->rowid)));
323
324 if ($showline) {
325 $href = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$obj->rowid;
326
327 print '<tr>';
328
329 // Ref
330 print '<td>';
331 print '<a href="'.$href.'">'.img_object($langs->trans('ShowOrder'), 'order').' '.$obj->ref.'</a>';
332 print '</td>';
333
334 // Company
335 $href = DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid;
336 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->name).'"><a href="'.$href.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$obj->name.'</a></td>';
337
338 // Author
339 $userstatic->id = $obj->fk_user_author;
340 $userstatic->login = $obj->login;
341 if ($userstatic->id) {
342 $txt = $userstatic->getLoginUrl(1);
343 } else {
344 $txt = '&nbsp;';
345 }
346 print '<td>'.$txt.'</td>';
347
348 // Amount
349 print '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
350
351 // Date
352 if ($obj->dc) {
353 $date = dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel');
354 } else {
355 $date = '-';
356 }
357 print '<td class="center">'.$date.'</td>';
358
359 // Statut
360 print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, 5).'</td>';
361
362 print '</tr>';
363 }
364 $i++;
365 }
366 print '</table>';
367 print '</div>';
368
369 print '</form>';
370
371 $db->free($resql);
372
373 print dol_get_fiche_end();
374} else {
376}
377
378// End of page
379llxFooter();
380$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...
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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).
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.