dolibarr  13.0.2
replenish.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
3  * Copyright (C) 2013-2018 Laurent Destaileur <ely@users.sourceforge.net>
4  * Copyright (C) 2014 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2016 ATM Consulting <support@atm-consulting.fr>
7  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
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 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
35 require_once './lib/replenishment.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) {
42  $socid = $user->socid;
43 }
44 $result = restrictedArea($user, 'produit|service');
45 
46 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
47 $hookmanager->initHooks(array('stockreplenishlist'));
48 
49 //checks if a product has been ordered
50 
51 $action = GETPOST('action', 'aZ09');
52 $search_ref = GETPOST('search_ref', 'alpha');
53 $search_label = GETPOST('search_label', 'alpha');
54 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
55 $type = GETPOST('type', 'int');
56 $tobuy = GETPOST('tobuy', 'int');
57 $salert = GETPOST('salert', 'alpha');
58 $includeproductswithoutdesiredqty = GETPOST('includeproductswithoutdesiredqty', 'alpha');
59 $mode = GETPOST('mode', 'alpha');
60 $draftorder = GETPOST('draftorder', 'alpha');
61 
62 
63 $fourn_id = GETPOST('fourn_id', 'int');
64 $fk_supplier = GETPOST('fk_supplier', 'int');
65 $fk_entrepot = GETPOST('fk_entrepot', 'int');
66 $texte = '';
67 
68 $sortfield = GETPOST('sortfield', 'aZ09comma');
69 $sortorder = GETPOST('sortorder', 'aZ09comma');
70 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
71 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
72 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
73 $offset = $limit * $page;
74 
75 if (!$sortfield) {
76  $sortfield = 'p.ref';
77 }
78 
79 if (!$sortorder) {
80  $sortorder = 'ASC';
81 }
82 
83 $virtualdiffersfromphysical = 0;
84 if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
85  || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
86  || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
87  || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
88  || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
89  || !empty($conf->mrp->enabled))
90 {
91  $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
92 }
93 
94 if ($virtualdiffersfromphysical) {
95  $usevirtualstock = empty($conf->global->STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT) ? 1 : 0;
96 } else {
97  $usevirtualstock = 0;
98 }
99 if ($mode == 'physical') $usevirtualstock = 0;
100 if ($mode == 'virtual') $usevirtualstock = 1;
101 
102 $parameters = array();
103 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
104 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
105 
106 
107 /*
108  * Actions
109  */
110 
111 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('valid')) // Both test are required to be compatible with all browsers
112 {
113  $search_ref = '';
114  $search_label = '';
115  $sall = '';
116  $salert = '';
117  $includeproductswithoutdesiredqty = '';
118  $draftorder = '';
119 }
120 if ($draftorder == 'on') $draftchecked = "checked";
121 
122 // Create orders
123 if ($action == 'order' && GETPOST('valid'))
124 {
125  $linecount = GETPOST('linecount', 'int');
126  $box = 0;
127  $errorQty = 0;
128  unset($_POST['linecount']);
129  if ($linecount > 0)
130  {
131  $db->begin();
132 
133  $suppliers = array();
134  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
135  $productsupplier = new ProductFournisseur($db);
136  for ($i = 0; $i < $linecount; $i++)
137  {
138  if (GETPOST('choose'.$i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0)
139  {
140  //one line
141  $box = $i;
142  $supplierpriceid = GETPOST('fourn'.$i, 'int');
143  //get all the parameters needed to create a line
144  $qty = GETPOST('tobuy'.$i, 'int');
145  $idprod = $productsupplier->get_buyprice($supplierpriceid, $qty);
146  $res = $productsupplier->fetch($idprod);
147  if ($res && $idprod > 0)
148  {
149  if ($qty)
150  {
151  //might need some value checks
152  $line = new CommandeFournisseurLigne($db);
153  $line->qty = $qty;
154  $line->fk_product = $idprod;
155 
156  //$product = new Product($db);
157  //$product->fetch($obj->fk_product);
158  if (!empty($conf->global->MAIN_MULTILANGS))
159  {
160  $productsupplier->getMultiLangs();
161  }
162 
163  // if we use supplier description of the products
164  if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
165  $desc = $productsupplier->desc_supplier;
166  } else {
167  $desc = $productsupplier->description;
168  }
169  $line->desc = $desc;
170  if (!empty($conf->global->MAIN_MULTILANGS))
171  {
172  // TODO Get desc in language of thirdparty
173  }
174 
175  $line->tva_tx = $productsupplier->vatrate_supplier;
176  $line->subprice = $productsupplier->fourn_pu;
177  $line->total_ht = $productsupplier->fourn_pu * $qty;
178  $tva = $line->tva_tx / 100;
179  $line->total_tva = $line->total_ht * $tva;
180  $line->total_ttc = $line->total_ht + $line->total_tva;
181  $line->remise_percent = $productsupplier->remise_percent;
182  $line->ref_fourn = $productsupplier->ref_supplier;
183  $line->type = $productsupplier->type;
184  $line->fk_unit = $productsupplier->fk_unit;
185  $suppliers[$productsupplier->fourn_socid]['lines'][] = $line;
186  }
187  } elseif ($idprod == -1)
188  {
189  $errorQty++;
190  } else {
191  $error = $db->lasterror();
192  dol_print_error($db);
193  }
194 
195  unset($_POST['fourn'.$i]);
196  }
197  unset($_POST[$i]);
198  }
199 
200  //we now know how many orders we need and what lines they have
201  $i = 0;
202  $fail = 0;
203  $orders = array();
204  $suppliersid = array_keys($suppliers);
205  foreach ($suppliers as $supplier)
206  {
207  $order = new CommandeFournisseur($db);
208  // Check if an order for the supplier exists
209  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur";
210  $sql .= " WHERE fk_soc = ".$suppliersid[$i];
211  $sql .= " AND source = 42 AND fk_statut = 0";
212  $sql .= " AND entity IN (".getEntity('commande_fournisseur').")";
213  $sql .= " ORDER BY date_creation DESC";
214  $resql = $db->query($sql);
215  if ($resql && $db->num_rows($resql) > 0) {
216  $obj = $db->fetch_object($resql);
217  $order->fetch($obj->rowid);
218  foreach ($supplier['lines'] as $line) {
219  $result = $order->addline(
220  $line->desc,
221  $line->subprice,
222  $line->qty,
223  $line->tva_tx,
224  $line->localtax1_tx,
225  $line->localtax2_tx,
226  $line->fk_product,
227  0,
228  $line->ref_fourn,
229  $line->remise_percent,
230  'HT',
231  0,
232  $line->type,
233  0,
234  false,
235  null,
236  null,
237  0,
238  $line->fk_unit
239  );
240  }
241  if ($result < 0) {
242  $fail++;
243  $msg = $langs->trans('OrderFail')."&nbsp;:&nbsp;";
244  $msg .= $order->error;
245  setEventMessages($msg, null, 'errors');
246  } else {
247  $id = $result;
248  }
249  } else {
250  $order->socid = $suppliersid[$i];
251  $order->fetch_thirdparty();
252  //trick to know which orders have been generated this way
253  $order->source = 42;
254  foreach ($supplier['lines'] as $line) {
255  $order->lines[] = $line;
256  }
257  $order->cond_reglement_id = $order->thirdparty->cond_reglement_supplier_id;
258  $order->mode_reglement_id = $order->thirdparty->mode_reglement_supplier_id;
259  $id = $order->create($user);
260  if ($id < 0) {
261  $fail++;
262  $msg = $langs->trans('OrderFail')."&nbsp;:&nbsp;";
263  $msg .= $order->error;
264  setEventMessages($msg, null, 'errors');
265  }
266  $i++;
267  }
268  }
269 
270  if ($errorQty) setEventMessages($langs->trans('ErrorOrdersNotCreatedQtyTooLow'), null, 'warnings');
271 
272  if (!$fail && $id)
273  {
274  $db->commit();
275 
276  setEventMessages($langs->trans('OrderCreated'), null, 'mesgs');
277  header('Location: replenishorders.php');
278  exit;
279  } else {
280  $db->rollback();
281  }
282  }
283  if ($box == 0)
284  {
285  setEventMessages($langs->trans('SelectProductWithNotNullQty'), null, 'warnings');
286  }
287 }
288 
289 
290 /*
291  * View
292  */
293 
294 $form = new Form($db);
295 $formproduct = new FormProduct($db);
296 $prod = new Product($db);
297 
298 $title = $langs->trans('MissingStocks');
299 
300 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
301  $sqldesiredtock = $db->ifsql("pse.desiredstock IS NULL", "p.desiredstock", "pse.desiredstock");
302  $sqlalertstock = $db->ifsql("pse.seuil_stock_alerte IS NULL", "p.seuil_stock_alerte", "pse.seuil_stock_alerte");
303 } else {
304  $sqldesiredtock = 'p.desiredstock';
305  $sqlalertstock = 'p.seuil_stock_alerte';
306 }
307 
308 $sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,';
309 $sql .= ' p.price_ttc, p.price_base_type,p.fk_product_type,';
310 $sql .= ' p.tms as datem, p.duration, p.tobuy,';
311 $sql .= ' p.desiredstock, p.seuil_stock_alerte,';
312 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
313  $sql .= ' pse.desiredstock as desiredstockpse, pse.seuil_stock_alerte as seuil_stock_alertepse,';
314 }
315 $sql .= ' '.$sqldesiredtock.' as desiredstockcombined, '.$sqlalertstock.' as seuil_stock_alertecombined,';
316 $sql .= ' s.fk_product,';
317 $sql .= ' SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique';
318 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
319  $sql .= ', SUM('.$db->ifsql("s.reel IS NULL OR s.fk_entrepot <> ".$fk_entrepot, "0", "s.reel").') as stock_real_warehouse';
320 }
321 
322 // Add fields from hooks
323 $parameters = array();
324 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
325 $sql .= $hookmanager->resPrint;
326 
327 $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
328 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product';
329 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot AS ent ON s.fk_entrepot = ent.rowid AND ent.entity IN('.getEntity('stock').')';
330 if ($fk_supplier > 0) {
331  $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price pfp ON (pfp.fk_product = p.rowid AND pfp.fk_soc = '.$fk_supplier.')';
332 }
333 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
334  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.$fk_entrepot.')';
335 }
336 
337 // Add fields from hooks
338 $parameters = array();
339 $reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters); // Note that $action and $object may have been modified by hook
340 $sql .= $hookmanager->resPrint;
341 
342 $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
343 if ($sall) $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall);
344 // if the type is not 1, we show all products (type = 0,2,3)
345 if (dol_strlen($type)) {
346  if ($type == 1) {
347  $sql .= ' AND p.fk_product_type = 1';
348  } else {
349  $sql .= ' AND p.fk_product_type <> 1';
350  }
351 }
352 if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
353 if ($search_label) $sql .= natural_search('p.label', $search_label);
354 $sql .= ' AND p.tobuy = 1';
355 if (empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { // Add test to exclude products that has variants
356  $sql .= ' AND p.rowid NOT IN (SELECT pac.fk_product_parent FROM '.MAIN_DB_PREFIX.'product_attribute_combination as pac WHERE pac.entity IN ('.getEntity('product').'))';
357 }
358 $sql .= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price';
359 $sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
360 $sql .= ', p.duration, p.tobuy';
361 $sql .= ', p.desiredstock';
362 $sql .= ', p.seuil_stock_alerte';
363 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
364  $sql .= ', pse.desiredstock';
365  $sql .= ', pse.seuil_stock_alerte';
366 }
367 $sql .= ', s.fk_product';
368 
369 if ($usevirtualstock)
370 {
371  if (!empty($conf->commande->enabled)) {
372  $sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd1.qty) IS NULL", "0", "SUM(cd1.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
373  $sqlCommandesCli .= " FROM ".MAIN_DB_PREFIX."commandedet as cd1, ".MAIN_DB_PREFIX."commande as c1";
374  $sqlCommandesCli .= " WHERE c1.rowid = cd1.fk_commande AND c1.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'commande').")";
375  $sqlCommandesCli .= " AND cd1.fk_product = p.rowid";
376  $sqlCommandesCli .= " AND c1.fk_statut IN (1,2))";
377  } else {
378  $sqlCommandesCli = '0';
379  }
380 
381  if (!empty($conf->expedition->enabled)) {
382  $sqlExpeditionsCli = "(SELECT ".$db->ifsql("SUM(ed2.qty) IS NULL", "0", "SUM(ed2.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
383  $sqlExpeditionsCli .= " FROM ".MAIN_DB_PREFIX."expedition as e2,";
384  $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."expeditiondet as ed2,";
385  $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commande as c2,";
386  $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commandedet as cd2";
387  $sqlExpeditionsCli .= " WHERE ed2.fk_expedition = e2.rowid AND cd2.rowid = ed2.fk_origin_line AND e2.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'expedition').")";
388  $sqlExpeditionsCli .= " AND cd2.fk_commande = c2.rowid";
389  $sqlExpeditionsCli .= " AND c2.fk_statut IN (1,2)";
390  $sqlExpeditionsCli .= " AND cd2.fk_product = p.rowid";
391  $sqlExpeditionsCli .= " AND e2.fk_statut IN (1,2))";
392  } else {
393  $sqlExpeditionsCli = '0';
394  }
395 
396  if (!empty($conf->fournisseur->enabled)) {
397  $sqlCommandesFourn = "(SELECT ".$db->ifsql("SUM(cd3.qty) IS NULL", "0", "SUM(cd3.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
398  $sqlCommandesFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd3,";
399  $sqlCommandesFourn .= " ".MAIN_DB_PREFIX."commande_fournisseur as c3";
400  $sqlCommandesFourn .= " WHERE c3.rowid = cd3.fk_commande";
401  $sqlCommandesFourn .= " AND c3.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")";
402  $sqlCommandesFourn .= " AND cd3.fk_product = p.rowid";
403  $sqlCommandesFourn .= " AND c3.fk_statut IN (3,4))";
404 
405  $sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd4.qty) IS NULL", "0", "SUM(fd4.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
406  $sqlReceptionFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf4,";
407  $sqlReceptionFourn .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd4";
408  $sqlReceptionFourn .= " WHERE fd4.fk_commande = cf4.rowid AND cf4.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")";
409  $sqlReceptionFourn .= " AND fd4.fk_product = p.rowid";
410  $sqlReceptionFourn .= " AND cf4.fk_statut IN (3,4))";
411  } else {
412  $sqlCommandesFourn = '0';
413  $sqlReceptionFourn = '0';
414  }
415 
416  if (!empty($conf->mrp->enabled)) {
417  $sqlProductionToConsume = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
418  $sqlProductionToConsume .= " FROM ".MAIN_DB_PREFIX."mrp_mo as mm5,";
419  $sqlProductionToConsume .= " ".MAIN_DB_PREFIX."mrp_production as mp5";
420  $sqlProductionToConsume .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")";
421  $sqlProductionToConsume .= " AND mp5.fk_product = p.rowid";
422  $sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consummed')";
423  $sqlProductionToConsume .= " AND mm5.status IN (1,2))";
424 
425  $sqlProductionToProduce = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
426  $sqlProductionToProduce .= " FROM ".MAIN_DB_PREFIX."mrp_mo as mm5,";
427  $sqlProductionToProduce .= " ".MAIN_DB_PREFIX."mrp_production as mp5";
428  $sqlProductionToProduce .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")";
429  $sqlProductionToProduce .= " AND mp5.fk_product = p.rowid";
430  $sqlProductionToProduce .= " AND mp5.role IN ('toproduce', 'produced')";
431  $sqlProductionToProduce .= " AND mm5.status IN (1,2))";
432  } else {
433  $sqlProductionToConsume = '0';
434  $sqlProductionToProduce = '0';
435  }
436 
437  $sql .= ' HAVING (';
438  $sql .= ' ('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
439  $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.') + ('.$sqlProductionToProduce.' - '.$sqlProductionToConsume.')))';
440  $sql .= ' OR';
441  if ($includeproductswithoutdesiredqty == 'on') {
442  $sql .= ' (('.$sqlalertstock.' >= 0 OR '.$sqlalertstock.' IS NULL) AND ('.$db->ifsql("$sqlalertstock IS NULL", "0", $sqlalertstock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
443  } else {
444  $sql .= ' ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
445  }
446  $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.') + ('.$sqlProductionToProduce.' - '.$sqlProductionToConsume.')))';
447  $sql .= ')';
448 
449  if ($salert == 'on') // Option to see when stock is lower than alert
450  {
451  $sql .= ' AND (';
452  if ($includeproductswithoutdesiredqty == 'on') {
453  $sql .= '('.$sqlalertstock.' >= 0 OR '.$sqlalertstock.' IS NULL) AND ('.$db->ifsql("$sqlalertstock IS NULL", "0", $sqlalertstock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
454  } else {
455  $sql .= $sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
456  }
457  $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.') + ('.$sqlProductionToProduce.' - '.$sqlProductionToConsume.'))';
458  $sql .= ')';
459  $alertchecked = 'checked';
460  }
461 } else {
462  $sql .= ' HAVING (';
463  $sql .= '('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
464  $sql .= ' OR';
465  if ($includeproductswithoutdesiredqty == 'on') {
466  $sql .= ' (('.$sqlalertstock.' >= 0 OR '.$sqlalertstock.' IS NULL) AND ('.$db->ifsql("$sqlalertstock IS NULL", "0", $sqlalertstock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
467  } else {
468  $sql .= ' ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
469  }
470  $sql .= ')';
471 
472  if ($salert == 'on') // Option to see when stock is lower than alert
473  {
474  $sql .= ' AND (';
475  if ($includeproductswithoutdesiredqty == 'on') {
476  $sql .= ' ('.$sqlalertstock.' >= 0 OR '.$sqlalertstock.' IS NULL) AND ('.$db->ifsql("$sqlalertstock IS NULL", "0", $sqlalertstock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))';
477  } else {
478  $sql .= ' '.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))';
479  }
480  $sql .= ')';
481  $alertchecked = 'checked';
482  }
483 }
484 
485 $includeproductswithoutdesiredqtychecked = '';
486 if ($includeproductswithoutdesiredqty == 'on') {
487  $includeproductswithoutdesiredqtychecked = 'checked';
488 }
489 
490 // Add where from hooks
491 $parameters = array();
492 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
493 $sql .= $hookmanager->resPrint;
494 
495 $nbtotalofrecords = '';
496 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
497  $result = $db->query($sql);
498  $nbtotalofrecords = $db->num_rows($result);
499  if (($page * $limit) > $nbtotalofrecords) {
500  $page = 0;
501  $offset = 0;
502  }
503 }
504 
505 $sql .= $db->order($sortfield, $sortorder);
506 $sql .= $db->plimit($limit + 1, $offset);
507 
508 //print $sql;
509 $resql = $db->query($sql);
510 if (empty($resql))
511 {
512  dol_print_error($db);
513  exit;
514 }
515 
516 $num = $db->num_rows($resql);
517 $i = 0;
518 
519 $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|';
520 $helpurl .= 'ES:M&oacute;dulo_Stocks';
521 
522 llxHeader('', $title, $helpurl, '');
523 
524 $head = array();
525 
526 $head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
527 $head[0][1] = $title;
528 $head[0][2] = 'replenish';
529 
530 $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
531 $head[1][1] = $langs->trans("ReplenishmentOrders");
532 $head[1][2] = 'replenishorders';
533 
534 
535 print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
536 
537 print dol_get_fiche_head($head, 'replenish', '', -1, '');
538 
539 print '<span class="opacitymedium">'.$langs->trans("ReplenishmentStatusDesc").'</span>'."\n";
540 if (empty($fk_warhouse) && !empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) {
541  print '<span class="opacitymedium">'.$langs->trans("ReplenishmentStatusDescPerWarehouse").'</span>'."\n";
542 }
543 print '<br><br>';
544 if ($usevirtualstock == 1)
545 {
546  print $langs->trans("CurentSelectionMode").': ';
547  print '<span class="a-mesure">'.$langs->trans("UseVirtualStock").'</span>';
548  print ' <a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?mode=physical'.($fk_supplier > 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UsePhysicalStock").'</a>';
549  print '<br>';
550 }
551 if ($usevirtualstock == 0)
552 {
553  print $langs->trans("CurentSelectionMode").': ';
554  print '<a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?mode=virtual'.($fk_supplier > 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UseVirtualStock").'</a>';
555  print ' <span class="a-mesure">'.$langs->trans("UsePhysicalStock").'</span>';
556  print '<br>';
557 }
558 print '<br>'."\n";
559 
560 print '<form name="formFilterWarehouse" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
561 print '<input type="hidden" name="token" value="'.newToken().'">';
562 print '<input type="hidden" name="action" value="filter">';
563 print '<input type="hidden" name="search_ref" value="'.$search_ref.'">';
564 print '<input type="hidden" name="search_label" value="'.$search_label.'">';
565 print '<input type="hidden" name="salert" value="'.$salert.'">';
566 print '<input type="hidden" name="includeproductswithoutdesiredqty" value="'.$includeproductswithoutdesiredqty.'">';
567 print '<input type="hidden" name="draftorder" value="'.$draftorder.'">';
568 print '<input type="hidden" name="mode" value="'.$mode.'">';
569 if ($limit > 0 && $limit != $conf->liste_limit) {
570  print '<input type="hidden" name="limit" value="'.$limit.'">';
571 }
572 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE))
573 {
574  print '<div class="inline-block valignmiddle" style="padding-right: 20px;">';
575  print $langs->trans('Warehouse').' '.$formproduct->selectWarehouses($fk_entrepot, 'fk_entrepot', '', 1);
576  print '</div>';
577 }
578 print '<div class="inline-block valignmiddle" style="padding-right: 20px;">';
579 print $langs->trans('Supplier').' '.$form->select_company($fk_supplier, 'fk_supplier', 'fournisseur=1', 1);
580 print '</div>';
581 
582 $parameters = array();
583 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
584 if (empty($reshook)) print $hookmanager->resPrint;
585 
586 print '<div class="inline-block valignmiddle">';
587 print '<input class="button" type="submit" name="valid" value="'.$langs->trans('ToFilter').'">';
588 print '</div>';
589 
590 print '</form>';
591 
592 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
593 print '<input type="hidden" name="token" value="'.newToken().'">';
594 print '<input type="hidden" name="fk_supplier" value="'.$fk_supplier.'">';
595 print '<input type="hidden" name="fk_entrepot" value="'.$fk_entrepot.'">';
596 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
597 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
598 print '<input type="hidden" name="type" value="'.$type.'">';
599 print '<input type="hidden" name="linecount" value="'.$num.'">';
600 print '<input type="hidden" name="action" value="order">';
601 print '<input type="hidden" name="mode" value="'.$mode.'">';
602 
603 
604 if ($search_ref || $search_label || $sall || $salert || $draftorder || GETPOST('search', 'alpha')) {
605  $filters = '&search_ref='.urlencode($search_ref).'&search_label='.urlencode($search_label);
606  $filters .= '&sall='.urlencode($sall);
607  $filters .= '&salert='.urlencode($salert);
608  $filters .= '&draftorder='.urlencode($draftorder);
609  $filters .= '&mode='.urlencode($mode);
610  if ($fk_supplier > 0) $filters .= '&fk_supplier='.urlencode($fk_supplier);
611  if ($fk_entrepot > 0) $filters .= '&fk_entrepot='.urlencode($fk_entrepot);
612 } else {
613  $filters = '&search_ref='.urlencode($search_ref).'&search_label='.urlencode($search_label);
614  $filters .= '&fourn_id='.urlencode($fourn_id);
615  $filters .= (isset($type) ? '&type='.urlencode($type) : '');
616  $filters .= '&='.urlencode($salert);
617  $filters .= '&draftorder='.urlencode($draftorder);
618  $filters .= '&mode='.urlencode($mode);
619  if ($fk_supplier > 0) $filters .= '&fk_supplier='.urlencode($fk_supplier);
620  if ($fk_entrepot > 0) $filters .= '&fk_entrepot='.urlencode($fk_entrepot);
621 }
622 if ($limit > 0 && $limit != $conf->liste_limit) {
623  $filters .= '&limit='.urlencode($limit);
624 }
625 
626 $param = (isset($type) ? '&type='.urlencode($type) : '');
627 $param .= '&fourn_id='.urlencode($fourn_id).'&search_label='.urlencode($search_label).'&includeproductswithoutdesiredqty='.urlencode($includeproductswithoutdesiredqty).'&salert='.urlencode($salert).'&draftorder='.urlencode($draftorder);
628 $param .= '&search_ref='.urlencode($search_ref);
629 $param .= '&mode='.urlencode($mode);
630 $param .= '&fk_supplier='.urlencode($fk_supplier);
631 $param .= '&fk_entrepot='.urlencode($fk_entrepot);
632 
633 $stocklabel = $langs->trans('Stock');
634 $stocklabelbis = $langs->trans('Stock');
635 if ($usevirtualstock == 1) $stocklabel = $langs->trans('VirtualStock');
636 if ($usevirtualstock == 0) $stocklabel = $langs->trans('PhysicalStock');
637 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0)
638 {
639  $stocklabelbis = $stocklabel.' (Selected warehouse)';
640  $stocklabel .= ' ('.$langs->trans("AllWarehouses").')';
641 }
642 $texte = $langs->trans('Replenishment');
643 
644 print '<br>';
645 
646 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
647 
648 if (!empty($conf->global->REPLENISH_ALLOW_VARIABLESIZELIST)) {
650  $texte,
651  $page,
652  'replenish.php',
653  $filters,
654  $sortfield,
655  $sortorder,
656  '',
657  $num,
658  $nbtotalofrecords,
659  '',
660  0,
661  '',
662  '',
663  $limit
664  );
665 } else {
667  $texte,
668  $page,
669  'replenish.php',
670  $filters,
671  $sortfield,
672  $sortorder,
673  '',
674  $num,
675  $nbtotalofrecords,
676  ''
677  );
678 }
679 
680 print '<table class="liste centpercent">';
681 
682 // Fields title search
683 print '<tr class="liste_titre_filter">';
684 print '<td class="liste_titre">&nbsp;</td>';
685 print '<td class="liste_titre"><input class="flat" type="text" name="search_ref" size="8" value="'.dol_escape_htmltag($search_ref).'"></td>';
686 print '<td class="liste_titre"><input class="flat" type="text" name="search_label" size="8" value="'.dol_escape_htmltag($search_label).'"></td>';
687 if (!empty($conf->service->enabled) && $type == 1) print '<td class="liste_titre">&nbsp;</td>';
688 print '<td class="liste_titre right">'.$form->textwithpicto($langs->trans('IncludeEmptyDesiredStock'), $langs->trans('IncludeProductWithUndefinedAlerts')).'&nbsp;<input type="checkbox" id="includeproductswithoutdesiredqty" name="includeproductswithoutdesiredqty" '.(!empty($includeproductswithoutdesiredqtychecked) ? $includeproductswithoutdesiredqtychecked : '').'></td>';
689 print '<td class="liste_titre right"></td>';
690 print '<td class="liste_titre right">'.$langs->trans('AlertOnly').'&nbsp;<input type="checkbox" id="salert" name="salert" '.(!empty($alertchecked) ? $alertchecked : '').'></td>';
691 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0)
692 {
693  print '<td class="liste_titre">&nbsp;</td>';
694 }
695 print '<td class="liste_titre right">';
696 if (!empty($conf->global->STOCK_REPLENISH_ADD_CHECKBOX_INCLUDE_DRAFT_ORDER)) {
697  print $langs->trans('IncludeAlsoDraftOrders').'&nbsp;<input type="checkbox" id="draftorder" name="draftorder" '.(!empty($draftchecked) ? $draftchecked : '').'>';
698 }
699 print '</td>';
700 print '<td class="liste_titre">&nbsp;</td>';
701 // Fields from hook
702 $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
703 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
704 print $hookmanager->resPrint;
705 
706 print '<td class="liste_titre maxwidthsearch right">';
707 $searchpicto = $form->showFilterAndCheckAddButtons(0);
708 print $searchpicto;
709 print '</td>';
710 print '</tr>';
711 
712 // Lines of title
713 print '<tr class="liste_titre">';
714 print_liste_field_titre('<input type="checkbox" onClick="toggle(this)" />', $_SERVER["PHP_SELF"], '');
715 print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', $param, '', '', $sortfield, $sortorder);
716 print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', $param, '', '', $sortfield, $sortorder);
717 if (!empty($conf->service->enabled) && $type == 1) print_liste_field_titre('Duration', $_SERVER["PHP_SELF"], 'p.duration', $param, '', '', $sortfield, $sortorder, 'center ');
718 print_liste_field_titre('DesiredStock', $_SERVER["PHP_SELF"], 'p.desiredstock', $param, '', '', $sortfield, $sortorder, 'right ');
719 print_liste_field_titre('StockLimitShort', $_SERVER["PHP_SELF"], 'p.seuil_stock_alerte', $param, '', '', $sortfield, $sortorder, 'right ');
720 print_liste_field_titre($stocklabel, $_SERVER["PHP_SELF"], 'stock_physique', $param, '', '', $sortfield, $sortorder, 'right ');
721 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0)
722 {
723  print_liste_field_titre($stocklabelbis, $_SERVER["PHP_SELF"], 'stock_real_warehouse', $param, '', '', $sortfield, $sortorder, 'right ');
724 }
725 print_liste_field_titre('Ordered', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right ');
726 print_liste_field_titre('StockToBuy', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right ');
727 print_liste_field_titre('SupplierRef', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right ');
728 
729 // Hook fields
730 $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
731 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
732 print $hookmanager->resPrint;
733 
734 print "</tr>\n";
735 
736 while ($i < ($limit ? min($num, $limit) : $num))
737 {
738  $objp = $db->fetch_object($resql);
739 
740  if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0)
741  {
742  $prod->fetch($objp->rowid);
743  $prod->load_stock('warehouseopen, warehouseinternal', $draftchecked);
744 
745  // Multilangs
746  if (!empty($conf->global->MAIN_MULTILANGS))
747  {
748  $sql = 'SELECT label,description';
749  $sql .= ' FROM '.MAIN_DB_PREFIX.'product_lang';
750  $sql .= ' WHERE fk_product = '.$objp->rowid;
751  $sql .= ' AND lang = "'.$langs->getDefaultLang().'"';
752  $sql .= ' LIMIT 1';
753 
754  $resqlm = $db->query($sql);
755  if ($resqlm)
756  {
757  $objtp = $db->fetch_object($resqlm);
758  if (!empty($objtp->description)) $objp->description = $objtp->description;
759  if (!empty($objtp->label)) $objp->label = $objtp->label;
760  }
761  }
762 
763  $stockwarehouse = 0;
764  if ($usevirtualstock)
765  {
766  // If option to increase/decrease is not on an object validation, virtual stock may differs from physical stock.
767  $stock = $prod->stock_theorique;
768  //TODO $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->;
769  } else {
770  $stock = $prod->stock_reel;
771  $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->real;
772  }
773 
774  // Force call prod->load_stats_xxx to choose status to count (otherwise it is loaded by load_stock function)
775  if (isset($draftchecked)) {
776  $result = $prod->load_stats_commande_fournisseur(0, '0,1,2,3,4');
777  } else {
778  $result = $prod->load_stats_commande_fournisseur(0, '1,2,3,4');
779  }
780 
781  $result = $prod->load_stats_reception(0, '4');
782 
783  //print $prod->stats_commande_fournisseur['qty'].'<br>'."\n";
784  //print $prod->stats_reception['qty'];
785  $ordered = $prod->stats_commande_fournisseur['qty'] - $prod->stats_reception['qty'];
786 
787  $desiredstock = $objp->desiredstock;
788  $alertstock = $objp->seuil_stock_alerte;
789  $desiredstockwarehouse = ($objp->desiredstockpse ? $objp->desiredstockpse : 0);
790  $alertstockwarehouse = ($objp->seuil_stock_alertepse ? $objp->seuil_stock_alertepse : 0);
791 
792  $warning = '';
793  if ($alertstock && ($stock < $alertstock))
794  {
795  $warning = img_warning($langs->trans('StockTooLow')).' ';
796  }
797  $warningwarehouse = '';
798  if ($alertstockwarehouse && ($stockwarehouse < $alertstockwarehouse))
799  {
800  $warningwarehouse = img_warning($langs->trans('StockTooLow')).' ';
801  }
802 
803  //depending on conf, use either physical stock or
804  //virtual stock to compute the stock to buy value
805 
806  if (empty($usevirtualstock)) $stocktobuy = max(max($desiredstock, $alertstock) - $stock - $ordered, 0);
807  else $stocktobuy = max(max($desiredstock, $alertstock) - $stock, 0); //ordered is already in $stock in virtual mode
808  if (empty($usevirtualstock)) $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse - $ordered, 0);
809  else $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse, 0); //ordered is already in $stock in virtual mode
810 
811  $picto = '';
812  if ($ordered > 0)
813  {
814  $stockforcompare = ($usevirtualstock ? $stock : $stock + $ordered);
815  /*if ($stockforcompare >= $desiredstock)
816  {
817  $picto = img_picto('', 'help');
818  } else {
819  $picto = img_picto('', 'help');
820  }*/
821  } else {
822  $picto = img_picto($langs->trans("NoPendingReceptionOnSupplierOrder"), 'help');
823  }
824 
825  print '<tr class="oddeven">';
826 
827  // Select field
828  print '<td><input type="checkbox" class="check" name="choose'.$i.'"></td>';
829 
830  print '<td class="nowrap">'.$prod->getNomUrl(1, 'stock').'</td>';
831 
832  print '<td>'.$objp->label;
833  print '<input type="hidden" name="desc'.$i.'" value="'.dol_escape_htmltag($objp->description).'">'; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST
834  print '</td>';
835 
836  if (!empty($conf->service->enabled) && $type == 1)
837  {
838  $regs = array();
839  if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
840  $duration = $regs[1].' '.$langs->trans('DurationYear');
841  } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
842  $duration = $regs[1].' '.$langs->trans('DurationMonth');
843  } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
844  $duration = $regs[1].' '.$langs->trans('DurationDay');
845  } else {
846  $duration = $objp->duration;
847  }
848  print '<td class="center">'.$duration.'</td>';
849  }
850 
851  // Desired stock
852  print '<td class="right">'.($fk_entrepot > 0 ? $desiredstockwarehouse : $desiredstock).'</td>';
853 
854  // Limit stock for alert
855  print '<td class="right">'.($fk_entrepot > 0 ? $alertstockwarehouse : $alertstock).'</td>';
856 
857  // Current stock (all warehouses)
858  print '<td class="right">'.$warning.$stock.'</td>';
859 
860  // Current stock (warehouse selected only)
861  if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0)
862  {
863  print '<td class="right">'.$warningwarehouse.$stockwarehouse.'</td>';
864  }
865 
866  // Already ordered
867  print '<td class="right"><a href="replenishorders.php?search_product='.$prod->id.'">'.$ordered.'</a> '.$picto.'</td>';
868 
869  // To order
870  print '<td class="right"><input type="text" size="4" name="tobuy'.$i.'" value="'.($fk_entrepot > 0 ? $stocktobuywarehouse : $stocktobuy).'"></td>';
871 
872  // Supplier
873  print '<td class="right">';
874  print $form->select_product_fourn_price($prod->id, 'fourn'.$i, $fk_supplier);
875  print '</td>';
876 
877  // Fields from hook
878  $parameters = array('objp'=>$objp);
879  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
880  print $hookmanager->resPrint;
881 
882  print '</tr>';
883  }
884  $i++;
885 }
886 
887 $parameters = array('sql'=>$sql);
888 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
889 print $hookmanager->resPrint;
890 
891 print '</table>';
892 print '</div>';
893 
894 $db->free($resql);
895 
897 
898 
899 $value = $langs->trans("CreateOrders");
900 print '<div class="center"><input class="button" type="submit" name="valid" value="'.$value.'"></div>';
901 
902 
903 print '</form>';
904 
905 
906 // TODO Replace this with jquery
907 print '
908 <script type="text/javascript">
909 function toggle(source)
910 {
911  checkboxes = document.getElementsByClassName("check");
912  for (var i=0; i < checkboxes.length;i++) {
913  if (!checkboxes[i].disabled) {
914  checkboxes[i].checked = source.checked;
915  }
916  }
917 }
918 </script>';
919 
920 
921 llxFooter();
922 
923 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
Class with static methods for building HTML components related to products Only components common to ...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (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...
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
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage predefined suppliers products.
Class to manage line orders.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...