32 require
'../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
38 require_once
'./lib/replenishment.lib.php';
41 $langs->loadLangs(array(
'products',
'stocks',
'orders'));
45 $socid = $user->socid;
50 $hookmanager->initHooks(array(
'stockreplenishlist'));
54 $action =
GETPOST(
'action',
'aZ09');
55 $search_ref =
GETPOST(
'search_ref',
'alpha');
56 $search_label =
GETPOST(
'search_label',
'alpha');
57 $sall = trim((
GETPOST(
'search_all',
'alphanohtml') !=
'') ?
GETPOST(
'search_all',
'alphanohtml') :
GETPOST(
'sall',
'alphanohtml'));
59 $tobuy =
GETPOST(
'tobuy',
'int');
60 $salert =
GETPOST(
'salert',
'alpha');
61 $includeproductswithoutdesiredqty =
GETPOST(
'includeproductswithoutdesiredqty',
'alpha');
62 $mode =
GETPOST(
'mode',
'alpha');
63 $draftorder =
GETPOST(
'draftorder',
'alpha');
66 $fourn_id =
GETPOST(
'fourn_id',
'int');
67 $fk_supplier =
GETPOST(
'fk_supplier',
'int');
68 $fk_entrepot =
GETPOST(
'fk_entrepot',
'int');
71 $resWar = $db->query(
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"entrepot WHERE entity IN (" . $db->sanitize(
getEntity(
'stock')) .
")");
72 $listofqualifiedwarehousesid =
"";
74 while ($tmpobj = $db->fetch_object($resWar)) {
75 if (!empty($listofqualifiedwarehousesid)) {
76 $listofqualifiedwarehousesid .=
",";
78 $listofqualifiedwarehousesid .= $tmpobj->rowid;
79 $lastWarehouseID = $tmpobj->rowid;
84 if ($count == 1 && (empty($fk_entrepot) || $fk_entrepot <= 0) && !empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) {
85 $fk_entrepot = $lastWarehouseID;
90 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
91 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
93 if (empty($page) || $page == -1) {
96 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
97 $offset = $limit * $page;
100 $sortfield =
'p.ref';
108 $virtualdiffersfromphysical = 0;
109 if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
110 || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
111 || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
112 || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
113 || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
115 $virtualdiffersfromphysical = 1;
118 if ($virtualdiffersfromphysical) {
119 $usevirtualstock = empty($conf->global->STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT) ? 1 : 0;
121 $usevirtualstock = 0;
123 if ($mode ==
'physical') {
124 $usevirtualstock = 0;
126 if ($mode ==
'virtual') {
127 $usevirtualstock = 1;
130 $parameters = array();
131 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
141 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
146 $includeproductswithoutdesiredqty =
'';
150 if ($draftorder ==
'on') {
151 $draftchecked =
"checked";
155 if ($action ==
'order' &&
GETPOST(
'valid')) {
156 $linecount =
GETPOST(
'linecount',
'int');
159 unset($_POST[
'linecount']);
160 if ($linecount > 0) {
163 $suppliers = array();
164 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
166 for ($i = 0; $i < $linecount; $i++) {
167 if (
GETPOST(
'choose'.$i,
'alpha') ===
'on' &&
GETPOST(
'fourn'.$i,
'int') > 0) {
170 $supplierpriceid =
GETPOST(
'fourn'.$i,
'int');
172 $qty =
GETPOST(
'tobuy'.$i,
'int');
173 $idprod = $productsupplier->get_buyprice($supplierpriceid, $qty);
174 $res = $productsupplier->fetch($idprod);
175 if ($res && $idprod > 0) {
180 $line->fk_product = $idprod;
185 $productsupplier->getMultiLangs();
189 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
190 $desc = $productsupplier->desc_supplier;
192 $desc = $productsupplier->description;
199 $line->tva_tx = $productsupplier->vatrate_supplier;
200 $line->subprice = $productsupplier->fourn_pu;
201 $line->total_ht = $productsupplier->fourn_pu * $qty;
202 $tva = $line->tva_tx / 100;
203 $line->total_tva = $line->total_ht * $tva;
204 $line->total_ttc = $line->total_ht + $line->total_tva;
205 $line->remise_percent = $productsupplier->remise_percent;
206 $line->ref_fourn = $productsupplier->ref_supplier;
207 $line->type = $productsupplier->type;
208 $line->fk_unit = $productsupplier->fk_unit;
209 $suppliers[$productsupplier->fourn_socid][
'lines'][] = $line;
211 } elseif ($idprod == -1) {
214 $error = $db->lasterror();
218 unset($_POST[
'fourn'.$i]);
227 $suppliersid = array_keys($suppliers);
228 foreach ($suppliers as $supplier) {
232 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur";
233 $sql .=
" WHERE fk_soc = ".((int) $suppliersid[$i]);
234 $sql .=
" AND source = ".((int) $order::SOURCE_ID_REPLENISHMENT).
" AND fk_statut = ".((int) $order::STATUS_DRAFT);
235 $sql .=
" AND entity IN (".getEntity(
'commande_fournisseur').
")";
236 $sql .=
" ORDER BY date_creation DESC";
237 $resql = $db->query(
$sql);
238 if ($resql && $db->num_rows($resql) > 0) {
239 $obj = $db->fetch_object($resql);
241 $order->fetch($obj->rowid);
242 $order->fetch_thirdparty();
244 foreach ($supplier[
'lines'] as $line) {
245 if (empty($line->remise_percent)) {
246 $line->remise_percent = $order->thirdparty->remise_supplier_percent;
248 $result = $order->addline(
258 $line->remise_percent,
272 $msg = $langs->trans(
'OrderFail').
" : ";
273 $msg .= $order->error;
279 $order->socid = $suppliersid[$i];
280 $order->fetch_thirdparty();
283 $order->source = $order::SOURCE_ID_REPLENISHMENT;
285 foreach ($supplier[
'lines'] as $line) {
286 if (empty($line->remise_percent)) {
287 $line->remise_percent = $order->thirdparty->remise_supplier_percent;
289 $order->lines[] = $line;
291 $order->cond_reglement_id = $order->thirdparty->cond_reglement_supplier_id;
292 $order->mode_reglement_id = $order->thirdparty->mode_reglement_supplier_id;
294 $id = $order->create($user);
297 $msg = $langs->trans(
'OrderFail').
" : ";
298 $msg .= $order->error;
306 setEventMessages($langs->trans(
'ErrorOrdersNotCreatedQtyTooLow'),
null,
'warnings');
313 header(
'Location: replenishorders.php');
320 setEventMessages($langs->trans(
'SelectProductWithNotNullQty'),
null,
'warnings');
333 $title = $langs->trans(
'MissingStocks');
335 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
336 $sqldesiredtock = $db->ifsql(
"pse.desiredstock IS NULL",
"p.desiredstock",
"pse.desiredstock");
337 $sqlalertstock = $db->ifsql(
"pse.seuil_stock_alerte IS NULL",
"p.seuil_stock_alerte",
"pse.seuil_stock_alerte");
339 $sqldesiredtock =
'p.desiredstock';
340 $sqlalertstock =
'p.seuil_stock_alerte';
343 $sql =
'SELECT p.rowid, p.ref, p.label, p.description, p.price,';
344 $sql .=
' p.price_ttc, p.price_base_type, p.fk_product_type,';
345 $sql .=
' p.tms as datem, p.duration, p.tobuy,';
346 $sql .=
' p.desiredstock, p.seuil_stock_alerte,';
347 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
348 $sql .=
' pse.desiredstock as desiredstockpse, pse.seuil_stock_alerte as seuil_stock_alertepse,';
350 $sql .=
" ".$sqldesiredtock.
" as desiredstockcombined, ".$sqlalertstock.
" as seuil_stock_alertecombined,";
351 $sql .=
' s.fk_product,';
352 $sql .=
" SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
') as stock_physique';
353 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
354 $sql .=
", SUM(".$db->ifsql(
"s.reel IS NULL OR s.fk_entrepot <> ".$fk_entrepot,
"0",
"s.reel").
') as stock_real_warehouse';
358 $parameters = array();
359 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
360 $sql .= $hookmanager->resPrint;
362 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
363 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_stock as s ON p.rowid = s.fk_product';
364 $list_warehouse = (empty($listofqualifiedwarehousesid) ?
'0' : $listofqualifiedwarehousesid);
365 $sql .=
' AND s.fk_entrepot IN ('.$db->sanitize($list_warehouse) .
')';
368 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
369 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.((int) $fk_entrepot).
')';
372 $parameters = array();
373 $reshook = $hookmanager->executeHooks(
'printFieldListJoin', $parameters);
374 $sql .= $hookmanager->resPrint;
376 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
383 $sql .=
' AND p.fk_product_type = 1';
385 $sql .=
' AND p.fk_product_type <> 1';
394 $sql .=
' AND p.tobuy = 1';
395 if (!empty($conf->variants->eabled) && empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) {
396 $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').
'))';
398 if ($fk_supplier > 0) {
399 $sql .=
' AND EXISTS (SELECT pfp.rowid FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp WHERE pfp.fk_product = p.rowid AND pfp.fk_soc = '.((int) $fk_supplier).
' AND pfp.entity IN ('.
getEntity(
'product_fournisseur_price').
'))';
402 $parameters = array();
403 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
404 $sql .= $hookmanager->resPrint;
406 $sql .=
' GROUP BY p.rowid, p.ref, p.label, p.description, p.price';
407 $sql .=
', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
408 $sql .=
', p.duration, p.tobuy';
409 $sql .=
', p.desiredstock';
410 $sql .=
', p.seuil_stock_alerte';
411 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
412 $sql .=
', pse.desiredstock';
413 $sql .=
', pse.seuil_stock_alerte';
415 $sql .=
', s.fk_product';
417 if ($usevirtualstock) {
419 $sqlCommandesCli =
"(SELECT ".$db->ifsql(
"SUM(cd1.qty) IS NULL",
"0",
"SUM(cd1.qty)").
" as qty";
420 $sqlCommandesCli .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd1, ".MAIN_DB_PREFIX.
"commande as c1";
421 $sqlCommandesCli .=
" WHERE c1.rowid = cd1.fk_commande AND c1.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'commande').
")";
422 $sqlCommandesCli .=
" AND cd1.fk_product = p.rowid";
423 $sqlCommandesCli .=
" AND c1.fk_statut IN (1,2))";
425 $sqlCommandesCli =
'0';
429 $sqlExpeditionsCli =
"(SELECT ".$db->ifsql(
"SUM(ed2.qty) IS NULL",
"0",
"SUM(ed2.qty)").
" as qty";
430 $sqlExpeditionsCli .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e2,";
431 $sqlExpeditionsCli .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed2,";
432 $sqlExpeditionsCli .=
" ".MAIN_DB_PREFIX.
"commande as c2,";
433 $sqlExpeditionsCli .=
" ".MAIN_DB_PREFIX.
"commandedet as cd2";
434 $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').
")";
435 $sqlExpeditionsCli .=
" AND cd2.fk_commande = c2.rowid";
436 $sqlExpeditionsCli .=
" AND c2.fk_statut IN (1,2)";
437 $sqlExpeditionsCli .=
" AND cd2.fk_product = p.rowid";
438 $sqlExpeditionsCli .=
" AND e2.fk_statut IN (1,2))";
440 $sqlExpeditionsCli =
'0';
444 $sqlCommandesFourn =
"(SELECT ".$db->ifsql(
"SUM(cd3.qty) IS NULL",
"0",
"SUM(cd3.qty)").
" as qty";
445 $sqlCommandesFourn .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd3,";
446 $sqlCommandesFourn .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur as c3";
447 $sqlCommandesFourn .=
" WHERE c3.rowid = cd3.fk_commande";
448 $sqlCommandesFourn .=
" AND c3.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'supplier_order').
")";
449 $sqlCommandesFourn .=
" AND cd3.fk_product = p.rowid";
450 $sqlCommandesFourn .=
" AND c3.fk_statut IN (3,4))";
452 $sqlReceptionFourn =
"(SELECT ".$db->ifsql(
"SUM(fd4.qty) IS NULL",
"0",
"SUM(fd4.qty)").
" as qty";
453 $sqlReceptionFourn .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as cf4,";
454 $sqlReceptionFourn .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as fd4";
455 $sqlReceptionFourn .=
" WHERE fd4.fk_commande = cf4.rowid AND cf4.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'supplier_order').
")";
456 $sqlReceptionFourn .=
" AND fd4.fk_product = p.rowid";
457 $sqlReceptionFourn .=
" AND cf4.fk_statut IN (3,4))";
459 $sqlCommandesFourn =
'0';
460 $sqlReceptionFourn =
'0';
464 $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";
465 $sqlProductionToConsume .=
" FROM ".MAIN_DB_PREFIX.
"mrp_mo as mm5,";
466 $sqlProductionToConsume .=
" ".MAIN_DB_PREFIX.
"mrp_production as mp5";
467 $sqlProductionToConsume .=
" WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'mo').
")";
468 $sqlProductionToConsume .=
" AND mp5.fk_product = p.rowid";
469 $sqlProductionToConsume .=
" AND mp5.role IN ('toconsume', 'consumed')";
470 $sqlProductionToConsume .=
" AND mm5.status IN (1,2))";
472 $sqlProductionToProduce =
"(SELECT GREATEST(0, ".$db->ifsql(
"SUM(".$db->ifsql(
"mp5.role = 'toproduce'",
'mp5.qty',
'- mp5.qty').
") IS NULL",
"0",
"SUM(".$db->ifsql(
"mp5.role = 'toproduce'",
'mp5.qty',
'- mp5.qty').
")").
") as qty";
473 $sqlProductionToProduce .=
" FROM ".MAIN_DB_PREFIX.
"mrp_mo as mm5,";
474 $sqlProductionToProduce .=
" ".MAIN_DB_PREFIX.
"mrp_production as mp5";
475 $sqlProductionToProduce .=
" WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'mo').
")";
476 $sqlProductionToProduce .=
" AND mp5.fk_product = p.rowid";
477 $sqlProductionToProduce .=
" AND mp5.role IN ('toproduce', 'produced')";
478 $sqlProductionToProduce .=
" AND mm5.status IN (1,2))";
480 $sqlProductionToConsume =
'0';
481 $sqlProductionToProduce =
'0';
485 $sql .=
" (".$sqldesiredtock.
" >= 0 AND (".$sqldesiredtock.
" > SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
')';
486 $sql .=
" - (".$sqlCommandesCli.
" - ".$sqlExpeditionsCli.
") + (".$sqlCommandesFourn.
" - ".$sqlReceptionFourn.
") + (".$sqlProductionToProduce.
" - ".$sqlProductionToConsume.
")))";
488 if ($includeproductswithoutdesiredqty ==
'on') {
489 $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").
")";
491 $sql .=
" (".$sqlalertstock.
" >= 0 AND (".$sqlalertstock.
" > SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
')';
493 $sql .=
" - (".$sqlCommandesCli.
" - ".$sqlExpeditionsCli.
") + (".$sqlCommandesFourn.
" - ".$sqlReceptionFourn.
") + (".$sqlProductionToProduce.
" - ".$sqlProductionToConsume.
")))";
496 if ($salert ==
'on') {
498 if ($includeproductswithoutdesiredqty ==
'on') {
499 $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").
")";
501 $sql .= $sqlalertstock.
" >= 0 AND (".$sqlalertstock.
" > SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
")";
503 $sql .=
" - (".$sqlCommandesCli.
" - ".$sqlExpeditionsCli.
") + (".$sqlCommandesFourn.
" - ".$sqlReceptionFourn.
") + (".$sqlProductionToProduce.
" - ".$sqlProductionToConsume.
"))";
505 $alertchecked =
'checked';
509 $sql .=
"(".$sqldesiredtock.
" >= 0 AND (".$sqldesiredtock.
" > SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
")))";
511 if ($includeproductswithoutdesiredqty ==
'on') {
512 $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").
')))';
514 $sql .=
" (".$sqlalertstock.
" >= 0 AND (".$sqlalertstock.
" > SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
')))';
518 if ($salert ==
'on') {
520 if ($includeproductswithoutdesiredqty ==
'on') {
521 $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").
"))";
523 $sql .=
" ".$sqlalertstock.
" >= 0 AND (".$sqlalertstock.
" > SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
'))';
526 $alertchecked =
'checked';
530 $includeproductswithoutdesiredqtychecked =
'';
531 if ($includeproductswithoutdesiredqty ==
'on') {
532 $includeproductswithoutdesiredqtychecked =
'checked';
535 $nbtotalofrecords =
'';
537 $result = $db->query(
$sql);
538 $nbtotalofrecords = $db->num_rows($result);
539 if (($page * $limit) > $nbtotalofrecords) {
545 $sql .= $db->order($sortfield, $sortorder);
546 $sql .= $db->plimit($limit + 1, $offset);
549 $resql = $db->query(
$sql);
555 $num = $db->num_rows($resql);
558 $helpurl =
'EN:Module_Stocks_En|FR:Module_Stock|';
559 $helpurl .=
'ES:Módulo_Stocks';
565 $head[0][0] = DOL_URL_ROOT.
'/product/stock/replenish.php';
566 $head[0][1] = $title;
567 $head[0][2] =
'replenish';
569 $head[1][0] = DOL_URL_ROOT.
'/product/stock/replenishorders.php';
570 $head[1][1] = $langs->trans(
"ReplenishmentOrders");
571 $head[1][2] =
'replenishorders';
578 print
'<span class="opacitymedium">'.$langs->trans(
"ReplenishmentStatusDesc").
'</span>'.
"\n";
582 if (empty($fk_entrepot) && !empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) {
583 print
'<span class="opacitymedium">'.$langs->trans(
"ReplenishmentStatusDescPerWarehouse").
'</span>'.
"\n";
586 if ($usevirtualstock == 1) {
587 print $langs->trans(
"CurentSelectionMode").
': ';
588 print
'<span class="a-mesure">'.$langs->trans(
"UseVirtualStock").
'</span>';
589 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>';
592 if ($usevirtualstock == 0) {
593 print $langs->trans(
"CurentSelectionMode").
': ';
594 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>';
595 print
' <span class="a-mesure">'.$langs->trans(
"UsePhysicalStock").
'</span>';
600 print
'<form name="formFilterWarehouse" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
601 print
'<input type="hidden" name="token" value="'.newToken().
'">';
602 print
'<input type="hidden" name="action" value="filter">';
603 print
'<input type="hidden" name="search_ref" value="'.$search_ref.
'">';
604 print
'<input type="hidden" name="search_label" value="'.$search_label.
'">';
605 print
'<input type="hidden" name="salert" value="'.$salert.
'">';
606 print
'<input type="hidden" name="includeproductswithoutdesiredqty" value="'.$includeproductswithoutdesiredqty.
'">';
607 print
'<input type="hidden" name="draftorder" value="'.$draftorder.
'">';
608 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
609 if ($limit > 0 && $limit != $conf->liste_limit) {
610 print
'<input type="hidden" name="limit" value="'.$limit.
'">';
612 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) {
613 print
'<div class="inline-block valignmiddle" style="padding-right: 20px;">';
614 print $langs->trans(
'Warehouse').
' '.$formproduct->selectWarehouses($fk_entrepot,
'fk_entrepot',
'', 1);
617 print
'<div class="inline-block valignmiddle" style="padding-right: 20px;">';
618 $filter =
'(fournisseur:=:1)';
619 print $langs->trans(
'Supplier').
' '.
$form->select_company($fk_supplier,
'fk_supplier', $filter, 1);
622 $parameters = array();
623 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
624 if (empty($reshook)) {
625 print $hookmanager->resPrint;
628 print
'<div class="inline-block valignmiddle">';
629 print
'<input type="submit" class="button smallpaddingimp" name="valid" value="'.$langs->trans(
'ToFilter').
'">';
634 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="formulaire">';
635 print
'<input type="hidden" name="token" value="'.newToken().
'">';
636 print
'<input type="hidden" name="fk_supplier" value="'.$fk_supplier.
'">';
637 print
'<input type="hidden" name="fk_entrepot" value="'.$fk_entrepot.
'">';
638 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
639 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
640 print
'<input type="hidden" name="type" value="'.$type.
'">';
641 print
'<input type="hidden" name="linecount" value="'.$num.
'">';
642 print
'<input type="hidden" name="action" value="order">';
643 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
646 if ($search_ref || $search_label || $sall || $salert || $draftorder ||
GETPOST(
'search',
'alpha')) {
647 $filters =
'&search_ref='.urlencode($search_ref).
'&search_label='.urlencode($search_label);
648 $filters .=
'&sall='.urlencode($sall);
649 $filters .=
'&salert='.urlencode($salert);
650 $filters .=
'&draftorder='.urlencode($draftorder);
651 $filters .=
'&mode='.urlencode($mode);
652 if ($fk_supplier > 0) {
653 $filters .=
'&fk_supplier='.urlencode($fk_supplier);
655 if ($fk_entrepot > 0) {
656 $filters .=
'&fk_entrepot='.urlencode($fk_entrepot);
659 $filters =
'&search_ref='.urlencode($search_ref).
'&search_label='.urlencode($search_label);
660 $filters .=
'&fourn_id='.urlencode($fourn_id);
661 $filters .= (isset($type) ?
'&type='.urlencode($type) :
'');
662 $filters .=
'&='.urlencode($salert);
663 $filters .=
'&draftorder='.urlencode($draftorder);
664 $filters .=
'&mode='.urlencode($mode);
665 if ($fk_supplier > 0) {
666 $filters .=
'&fk_supplier='.urlencode($fk_supplier);
668 if ($fk_entrepot > 0) {
669 $filters .=
'&fk_entrepot='.urlencode($fk_entrepot);
672 if ($limit > 0 && $limit != $conf->liste_limit) {
673 $filters .=
'&limit='.((int) $limit);
675 if (!empty($includeproductswithoutdesiredqty)) $filters .=
'&includeproductswithoutdesiredqty='.urlencode($includeproductswithoutdesiredqty);
676 if (!empty($salert)) $filters .=
'&salert='.urlencode($salert);
678 $param = (isset($type) ?
'&type='.urlencode($type) :
'');
679 $param .=
'&fourn_id='.urlencode($fourn_id).
'&search_label='.urlencode($search_label).
'&includeproductswithoutdesiredqty='.urlencode($includeproductswithoutdesiredqty).
'&salert='.urlencode($salert).
'&draftorder='.urlencode($draftorder);
680 $param .=
'&search_ref='.urlencode($search_ref);
681 $param .=
'&mode='.urlencode($mode);
682 $param .=
'&fk_supplier='.urlencode($fk_supplier);
683 $param .=
'&fk_entrepot='.urlencode($fk_entrepot);
684 if (!empty($includeproductswithoutdesiredqty)) $param .=
'&includeproductswithoutdesiredqty='.urlencode($includeproductswithoutdesiredqty);
685 if (!empty($salert)) $param .=
'&salert='.urlencode($salert);
687 $stocklabel = $langs->trans(
'Stock');
688 $stocklabelbis = $langs->trans(
'Stock');
690 if ($usevirtualstock == 1) {
691 $stocklabel = $langs->trans(
'VirtualStock');
692 $stocktooltip = $langs->trans(
"VirtualStockDesc");
694 if ($usevirtualstock == 0) {
695 $stocklabel = $langs->trans(
'PhysicalStock');
697 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
698 $stocklabelbis = $stocklabel.
' (Selected warehouse)';
699 $stocklabel .=
' ('.$langs->trans(
"AllWarehouses").
')';
701 $texte = $langs->trans(
'Replenishment');
706 if (!empty($conf->global->REPLENISH_ALLOW_VARIABLESIZELIST)) {
739 print
'<div class="div-table-responsive-no-min">';
740 print
'<table class="liste centpercent">';
743 print
'<tr class="liste_titre_filter">';
744 print
'<td class="liste_titre"> </td>';
745 print
'<td class="liste_titre"><input class="flat" type="text" name="search_ref" size="8" value="'.dol_escape_htmltag($search_ref).
'"></td>';
746 print
'<td class="liste_titre"><input class="flat" type="text" name="search_label" size="8" value="'.dol_escape_htmltag($search_label).
'"></td>';
748 print
'<td class="liste_titre"> </td>';
750 print
'<td class="liste_titre right">'.$form->textwithpicto($langs->trans(
'IncludeEmptyDesiredStock'), $langs->trans(
'IncludeProductWithUndefinedAlerts')).
' <input type="checkbox" id="includeproductswithoutdesiredqty" name="includeproductswithoutdesiredqty" '.(!empty($includeproductswithoutdesiredqtychecked) ? $includeproductswithoutdesiredqtychecked :
'').
'></td>';
751 print
'<td class="liste_titre right"></td>';
752 print
'<td class="liste_titre right">'.$langs->trans(
'AlertOnly').
' <input type="checkbox" id="salert" name="salert" '.(!empty($alertchecked) ? $alertchecked :
'').
'></td>';
753 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
754 print
'<td class="liste_titre"> </td>';
756 print
'<td class="liste_titre right">';
757 if (!empty($conf->global->STOCK_REPLENISH_ADD_CHECKBOX_INCLUDE_DRAFT_ORDER)) {
758 print $langs->trans(
'IncludeAlsoDraftOrders').
' <input type="checkbox" id="draftorder" name="draftorder" '.(!empty($draftchecked) ? $draftchecked :
'').
'>';
761 print
'<td class="liste_titre"> </td>';
763 $parameters = array(
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
764 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
765 print $hookmanager->resPrint;
767 print
'<td class="liste_titre maxwidthsearch right">';
768 $searchpicto =
$form->showFilterAndCheckAddButtons(0);
774 print
'<tr class="liste_titre">';
779 print_liste_field_titre(
'Duration', $_SERVER[
"PHP_SELF"],
'p.duration', $param,
'',
'', $sortfield, $sortorder,
'center ');
781 print_liste_field_titre(
'DesiredStock', $_SERVER[
"PHP_SELF"],
'p.desiredstock', $param,
'',
'', $sortfield, $sortorder,
'right ');
782 print_liste_field_titre(
'StockLimitShort', $_SERVER[
"PHP_SELF"],
'p.seuil_stock_alerte', $param,
'',
'', $sortfield, $sortorder,
'right ');
783 print_liste_field_titre($stocklabel, $_SERVER[
"PHP_SELF"],
'stock_physique', $param,
'',
'', $sortfield, $sortorder,
'right ', $stocktooltip);
784 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
785 print_liste_field_titre($stocklabelbis, $_SERVER[
"PHP_SELF"],
'stock_real_warehouse', $param,
'',
'', $sortfield, $sortorder,
'right ');
787 print_liste_field_titre(
'Ordered', $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'right ');
788 print_liste_field_titre(
'StockToBuy', $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'right ');
789 print_liste_field_titre(
'SupplierRef', $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'right ');
792 $parameters = array(
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
793 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
794 print $hookmanager->resPrint;
798 while ($i < ($limit ? min($num, $limit) : $num)) {
799 $objp = $db->fetch_object($resql);
801 if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) {
802 $result = $prod->fetch($objp->rowid);
808 $prod->load_stock(
'warehouseopen, warehouseinternal'.(!$usevirtualstock?
', novirtual':
''), $draftchecked);
812 $sql =
'SELECT label,description';
813 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_lang';
814 $sql .=
' WHERE fk_product = '.((int) $objp->rowid);
815 $sql .=
" AND lang = '".$db->escape($langs->getDefaultLang()).
"'";
818 $resqlm = $db->query(
$sql);
820 $objtp = $db->fetch_object($resqlm);
821 if (!empty($objtp->description)) {
822 $objp->description = $objtp->description;
824 if (!empty($objtp->label)) {
825 $objp->label = $objtp->label;
831 if ($usevirtualstock) {
833 $stock = $prod->stock_theorique;
836 $stock = $prod->stock_reel;
837 $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->real;
841 if (isset($draftchecked)) {
842 $result = $prod->load_stats_commande_fournisseur(0,
'0,1,2,3,4');
843 } elseif (!$usevirtualstock) {
844 $result = $prod->load_stats_commande_fournisseur(0,
'1,2,3,4');
847 if (!$usevirtualstock) {
848 $result = $prod->load_stats_reception(0,
'4');
853 $ordered = $prod->stats_commande_fournisseur[
'qty'] - $prod->stats_reception[
'qty'];
855 $desiredstock = $objp->desiredstock;
856 $alertstock = $objp->seuil_stock_alerte;
857 $desiredstockwarehouse = (!empty($objp->desiredstockpse) ? $objp->desiredstockpse : 0);
858 $alertstockwarehouse = (!empty($objp->seuil_stock_alertepse) ? $objp->seuil_stock_alertepse : 0);
861 if ($alertstock && ($stock < $alertstock)) {
862 $warning =
img_warning($langs->trans(
'StockTooLow')).
' ';
864 $warningwarehouse =
'';
865 if ($alertstockwarehouse && ($stockwarehouse < $alertstockwarehouse)) {
866 $warningwarehouse =
img_warning($langs->trans(
'StockTooLow')).
' ';
872 if (empty($usevirtualstock)) {
873 $stocktobuy = max(max($desiredstock, $alertstock) - $stock - $ordered, 0);
875 $stocktobuy = max(max($desiredstock, $alertstock) - $stock, 0);
877 if (empty($usevirtualstock)) {
878 $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse - $ordered, 0);
880 $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse, 0);
885 $stockforcompare = ($usevirtualstock ? $stock : $stock + $ordered);
893 $picto =
img_picto($langs->trans(
"NoPendingReceptionOnSupplierOrder"),
'help');
896 print
'<tr class="oddeven">';
899 print
'<td><input type="checkbox" class="check" name="choose'.$i.
'"></td>';
901 print
'<td class="nowrap">'.$prod->getNomUrl(1,
'stock').
'</td>';
903 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objp->label).
'">';
905 print
'<input type="hidden" name="desc'.$i.
'" value="'.
dol_escape_htmltag($objp->description).
'">';
910 if (preg_match(
'/([0-9]+)y/i', $objp->duration, $regs)) {
911 $duration = $regs[1].
' '.$langs->trans(
'DurationYear');
912 } elseif (preg_match(
'/([0-9]+)m/i', $objp->duration, $regs)) {
913 $duration = $regs[1].
' '.$langs->trans(
'DurationMonth');
914 } elseif (preg_match(
'/([0-9]+)d/i', $objp->duration, $regs)) {
915 $duration = $regs[1].
' '.$langs->trans(
'DurationDay');
917 $duration = $objp->duration;
919 print
'<td class="center">'.$duration.
'</td>';
923 print
'<td class="right">'.((!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) > 0 ? $desiredstockwarehouse : $desiredstock).
'</td>';
926 print
'<td class="right">'.((!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) > 0 ? $alertstockwarehouse : $alertstock).
'</td>';
929 print
'<td class="right">'.$warning.$stock;
930 print
'<!-- stock returned by main sql is '.$objp->stock_physique.
' -->';
934 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
935 print
'<td class="right">'.$warningwarehouse.$stockwarehouse.
'</td>';
939 print
'<td class="right"><a href="replenishorders.php?search_product='.$prod->id.
'">'.$ordered.
'</a> '.$picto.
'</td>';
942 print
'<td class="right"><input type="text" size="4" name="tobuy'.$i.
'" value="'.((!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) > 0 ? $stocktobuywarehouse : $stocktobuy).
'"></td>';
945 print
'<td class="right">';
946 print
$form->select_product_fourn_price($prod->id,
'fourn'.$i, $fk_supplier);
950 $parameters = array(
'objp'=>$objp);
951 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters);
952 print $hookmanager->resPrint;
964 if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
967 print
'<tr><td colspan="'.$colspan.
'">';
968 print
'<span class="opacitymedium">';
969 print $langs->trans(
"None");
974 $parameters = array(
'sql'=>
$sql);
975 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters);
976 print $hookmanager->resPrint;
986 $value = $langs->trans(
"CreateOrders");
987 print
'<div class="center"><input type="submit" class="button" name="valid" value="'.$value.
'"></div>';
995 <script type="text/javascript">
996 function toggle(source)
998 checkboxes = document.getElementsByClassName("check");
999 for (var i=0; i < checkboxes.length;i++) {
1000 if (!checkboxes[i].disabled) {
1001 checkboxes[i].checked = source.checked;
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage predefined suppliers products.
Class to manage line orders.
Class to manage predefined suppliers products.
Class to manage products or services.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
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...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.