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