dolibarr  13.0.2
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 // Security check
41 if ($user->socid) $socid = $user->socid;
42 $result = restrictedArea($user, 'produit|service');
43 
44 $sall = GETPOST('search_all', 'alphanohtml');
45 $sref = GETPOST('search_ref', 'alpha');
46 $snom = GETPOST('search_nom', 'alpha');
47 $suser = GETPOST('search_user', 'alpha');
48 $sttc = GETPOST('search_ttc', 'alpha');
49 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
50 $search_product = GETPOST('search_product', 'int');
51 $search_dateyear = GETPOST('search_dateyear', 'int');
52 $search_datemonth = GETPOST('search_datemonth', 'int');
53 $search_dateday = GETPOST('search_dateday', 'int');
54 $search_date = dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_dateyear);
55 
56 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
57 $sortfield = GETPOST("sortfield", 'alpha');
58 $sortorder = GETPOST("sortorder", 'alpha');
59 if (!$sortorder) $sortorder = 'DESC';
60 if (!$sortfield) $sortfield = 'cf.date_creation';
61 $page = GETPOST('page', 'int') ? GETPOST('page', 'int') : 0;
62 if ($page < 0) $page = 0;
63 $offset = $limit * $page;
64 
65 
66 /*
67  * Actions
68  */
69 
70 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
71 {
72  $sall = "";
73  $sref = "";
74  $snom = "";
75  $suser = "";
76  $sttc = "";
77  $search_date = '';
78  $search_datemonth = '';
79  $search_dateday = '';
80  $search_dateyear = '';
81  $search_product = 0;
82 }
83 
84 
85 
86 /*
87  * View
88  */
89 
90 $form = new Form($db);
91 
92 $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
93 $texte = $langs->trans('ReplenishmentOrders');
94 
95 llxHeader('', $texte, $helpurl, '');
96 
97 print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
98 
99 $head = array();
100 
101 $head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
102 $head[0][1] = $langs->trans('MissingStocks');
103 $head[0][2] = 'replenish';
104 
105 $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
106 $head[1][1] = $texte;
107 $head[1][2] = 'replenishorders';
108 
109 print dol_get_fiche_head($head, 'replenishorders', '', -1, '');
110 
111 $commandestatic = new CommandeFournisseur($db);
112 
113 $sql = 'SELECT s.rowid as socid, s.nom as name, cf.date_creation as dc,';
114 $sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc, cf.fk_user_author,';
115 $sql .= ' u.login';
116 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande_fournisseur as cf';
117 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON cf.fk_user_author = u.rowid';
118 if (!$user->rights->societe->client->voir && !$socid) {
119  $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
120 }
121 $sql .= ' WHERE cf.fk_soc = s.rowid ';
122 $sql .= ' AND cf.entity = '.$conf->entity;
123 if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
124  $sql .= ' AND cf.fk_statut < 3';
125 } elseif ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
126  $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).
127 } else {
128  $sql .= ' AND cf.fk_statut < 5';
129 }
130 if (!$user->rights->societe->client->voir && !$socid) {
131  $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.$user->id;
132 }
133 if ($sref) $sql .= natural_search('cf.ref', $sref);
134 if ($snom) $sql .= natural_search('s.nom', $snom);
135 if ($suser) $sql .= natural_search('u.login', $suser);
136 if ($sttc) $sql .= natural_search('cf.total_ttc', $sttc, 1);
137 $sql .= dolSqlDateFilter('cf.date_creation', $search_dateday, $search_datemonth, $search_dateyear);
138 if ($sall) $sql .= natural_search(array('cf.ref', 'cf.note'), $sall);
139 if (!empty($socid)) $sql .= ' AND s.rowid = '.$socid;
140 if (GETPOST('statut', 'int')) {
141  $sql .= ' AND fk_statut = '.GETPOST('statut', 'int');
142 }
143 $sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
144 $sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
145 $sql .= $db->order($sortfield, $sortorder);
146 if (!$search_product) {
147  $sql .= $db->plimit($limit + 1, $offset);
148 }
149 
150 $resql = $db->query($sql);
151 if ($resql)
152 {
153  $num = $db->num_rows($resql);
154  $i = 0;
155 
156  print '<span class="opacitymedium">'.$langs->trans("ReplenishmentOrdersDesc").'</span><br><br>';
157 
158  print '<form action="'.$_SERVER["PHP_SELF"].'" method="GET">';
159 
160  print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, '');
161 
162  $param = '';
163  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
164  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
165  if ($sref) $param .= '&search_ref='.urlencode($sref);
166  if ($snom) $param .= '&search_nom='.urlencode($snom);
167  if ($suser) $param .= '&search_user='.urlencode($suser);
168  if ($sttc) $param .= '&search_ttc='.urlencode($sttc);
169  if ($search_dateyear) $param .= '&search_dateyear='.urlencode($search_dateyear);
170  if ($search_datemonth) $param .= '&search_datemonth='.urlencode($search_datemonth);
171  if ($search_dateday) $param .= '&search_dateday='.urlencode($search_dateday);
172  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
173 
174  print '<table class="noborder centpercent">';
175 
176  print '<tr class="liste_titre_filter">';
177  print '<td class="liste_titre">';
178  print '<input type="text" class="flat" name="search_ref" value="'.dol_escape_htmltag($sref).'">';
179  print '</td>';
180  print '<td class="liste_titre">';
181  print '<input type="text" class="flat" name="search_nom" value="'.dol_escape_htmltag($snom).'">';
182  print '</td>';
183  print '<td class="liste_titre">';
184  print '<input type="text" class="flat" name="search_user" value="'.dol_escape_htmltag($suser).'">';
185  print '</td>';
186  print '<td class="liste_titre">';
187  print '<input type="text" class="flat" name="search_ttc" value="'.dol_escape_htmltag($sttc).'">';
188  print '</td>';
189  print '<td class="liste_titre">';
190  print $form->selectDate($search_date, 'search_date', 0, 0, 1, '', 1, 0, 0, '');
191  print '</td>';
192  print '<td class="liste_titre right">';
193  $searchpicto = $form->showFilterAndCheckAddButtons(0);
194  print $searchpicto;
195  print '</td>';
196  print '</tr>';
197 
198  print '<tr class="liste_titre">';
200  'Ref',
201  $_SERVER['PHP_SELF'],
202  'cf.ref',
203  '',
204  $param,
205  '',
206  $sortfield,
207  $sortorder
208  );
210  'Company',
211  $_SERVER['PHP_SELF'],
212  's.nom',
213  '',
214  $param,
215  '',
216  $sortfield,
217  $sortorder
218  );
220  'Author',
221  $_SERVER['PHP_SELF'],
222  'u.login',
223  '',
224  '',
225  '',
226  $sortfield,
227  $sortorder
228  );
230  'AmountTTC',
231  $_SERVER['PHP_SELF'],
232  'cf.total_ttc',
233  '',
234  $param,
235  '',
236  $sortfield,
237  $sortorder
238  );
240  'OrderCreation',
241  $_SERVER['PHP_SELF'],
242  'cf.date_creation',
243  '',
244  $param,
245  '',
246  $sortfield,
247  $sortorder
248  );
250  'Status',
251  $_SERVER['PHP_SELF'],
252  'cf.fk_statut',
253  '',
254  $param,
255  '',
256  $sortfield,
257  $sortorder,
258  'right '
259  );
260  print '</tr>';
261 
262  $userstatic = new User($db);
263 
264  while ($i < min($num, $search_product ? $num : $conf->liste_limit))
265  {
266  $obj = $db->fetch_object($resql);
267 
268  $showline = dolDispatchToDo($obj->rowid) && (!$search_product || in_array($search_product, getProducts($obj->rowid)));
269 
270  if ($showline)
271  {
272  $href = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$obj->rowid;
273 
274  print '<tr>';
275 
276  // Ref
277  print '<td>';
278  print '<a href="'.$href.'">'.img_object($langs->trans('ShowOrder'), 'order').' '.$obj->ref.'</a>';
279  print '</td>';
280 
281  // Company
282  $href = DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid;
283  print '<td><a href="'.$href.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$obj->name.'</a></td>';
284 
285  // Author
286  $userstatic->id = $obj->fk_user_author;
287  $userstatic->login = $obj->login;
288  if ($userstatic->id) {
289  $txt = $userstatic->getLoginUrl(1);
290  } else {
291  $txt = '&nbsp;';
292  }
293  print '<td>'.$txt.'</td>';
294 
295  // Amount
296  print '<td>'.price($obj->total_ttc).'</td>';
297 
298  // Date
299  if ($obj->dc) {
300  $date = dol_print_date($db->jdate($obj->dc), 'dayhour');
301  } else {
302  $date = '-';
303  }
304  print '<td>'.$date.'</td>';
305 
306  // Statut
307  print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, 5).'</td>';
308 
309  print '</tr>';
310  }
311  $i++;
312  }
313  print '</table>';
314  print '</form>';
315 
316  $db->free($resql);
317 
319 } else {
320  dol_print_error($db);
321 }
322 
323 // End of page
324 llxFooter();
325 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dolDispatchToDo($order_id)
Check if there is still some dispatching of stock to do.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
Class to manage predefined suppliers products.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getProducts($order_id)
getProducts
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.