33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formother.class.php';
36require_once DOL_DOCUMENT_ROOT .
'/core/class/html.form.class.php';
37require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.commande.class.php';
38require_once DOL_DOCUMENT_ROOT .
'/product/class/html.formproduct.class.php';
39require_once
'./lib/replenishment.lib.php';
42$langs->loadLangs(array(
'products',
'stocks',
'orders'));
46 $socid = $user->socid;
50$hookmanager->initHooks(array(
'stockreplenishlist'));
56$action =
GETPOST(
'action',
'aZ09');
57$search_ref =
GETPOST(
'search_ref',
'alpha');
58$search_label =
GETPOST(
'search_label',
'alpha');
59$sall = trim((
GETPOST(
'search_all',
'alphanohtml') !=
'') ?
GETPOST(
'search_all',
'alphanohtml') :
GETPOST(
'sall',
'alphanohtml'));
62$salert =
GETPOST(
'salert',
'alpha');
63$includeproductswithoutdesiredqty =
GETPOST(
'includeproductswithoutdesiredqty',
'alpha');
64$mode =
GETPOST(
'mode',
'alpha');
65$draftorder =
GETPOST(
'draftorder',
'alpha');
73$resWar = $db->query(
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"entrepot WHERE entity IN (" . $db->sanitize(
getEntity(
'stock')) .
")");
74$listofqualifiedwarehousesid =
"";
76while ($tmpobj = $db->fetch_object($resWar)) {
77 if (!empty($listofqualifiedwarehousesid)) {
78 $listofqualifiedwarehousesid .=
",";
80 $listofqualifiedwarehousesid .= $tmpobj->rowid;
81 $lastWarehouseID = $tmpobj->rowid;
86if ($count == 1 && (empty($fk_entrepot) || $fk_entrepot <= 0) &&
getDolGlobalString(
'MULTICOMPANY_PRODUCT_SHARING_ENABLED')) {
87 $fk_entrepot = $lastWarehouseID;
90if (!GETPOSTISSET(
'fk_warehouse') && (empty($fk_entrepot) || $fk_entrepot <= 0) &&
getDolGlobalString(
'MAIN_DEFAULT_WAREHOUSE_USER')) {
91 $fk_entrepot = $user->fk_warehouse;
96$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
97$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
99if (empty($page) || $page == -1) {
103$offset = $limit * $page;
106 $sortfield =
'p.ref';
114$virtualdiffersfromphysical = 0;
120 || isModEnabled(
'mrp')) {
121 $virtualdiffersfromphysical = 1;
124if ($virtualdiffersfromphysical) {
125 $usevirtualstock =
getDolGlobalString(
'STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT') ? 0 : 1;
127 $usevirtualstock = 0;
129if ($mode ==
'physical') {
130 $usevirtualstock = 0;
132if ($mode ==
'virtual') {
133 $usevirtualstock = 1;
136$parameters = array();
137$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
147if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
152 $includeproductswithoutdesiredqty =
'';
156if ($draftorder ==
'on') {
157 $draftchecked =
"checked";
161if ($action ==
'order' &&
GETPOST(
'valid') && $user->hasRight(
'fournisseur',
'commande',
'creer')) {
165 unset($_POST[
'linecount']);
166 if ($linecount > 0) {
169 $suppliers = array();
170 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
172 for ($i = 0; $i < $linecount; $i++) {
179 $idprod = $productsupplier->get_buyprice($supplierpriceid, $qty);
180 $res = $productsupplier->fetch($idprod);
181 if ($res && $idprod > 0) {
186 $line->fk_product = $idprod;
191 $productsupplier->getMultiLangs();
195 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
196 $desc = $productsupplier->desc_supplier;
198 $desc = $productsupplier->description;
205 $line->tva_tx = $productsupplier->vatrate_supplier;
206 $tva = $line->tva_tx / 100;
209 if (isModEnabled(
'multicurrency') && !empty($productsupplier->fourn_multicurrency_code) && $productsupplier->fourn_multicurrency_code != $conf->currency) {
210 $line->multicurrency_code = $productsupplier->fourn_multicurrency_code;
211 $line->fk_multicurrency = (int) $productsupplier->fourn_multicurrency_id;
212 $line->multicurrency_subprice = $productsupplier->fourn_multicurrency_unitprice;
213 $line->multicurrency_total_ht = $line->multicurrency_subprice * $qty;
214 $line->multicurrency_total_tva = $line->multicurrency_total_ht * $tva;
215 $line->multicurrency_total_ttc = $line->multicurrency_total_ht + $line->multicurrency_total_tva;
217 $line->subprice = $productsupplier->fourn_pu;
218 $line->total_ht = $productsupplier->fourn_pu * $qty;
219 $line->total_tva = $line->total_ht * $tva;
220 $line->total_ttc = $line->total_ht + $line->total_tva;
221 $line->remise_percent = (float) $productsupplier->remise_percent;
222 $line->ref_fourn = $productsupplier->ref_supplier;
223 $line->ref_supplier = $productsupplier->ref_supplier;
224 $line->type = $productsupplier->type;
225 $line->fk_unit = $productsupplier->fk_unit;
227 $suppliers[$productsupplier->fourn_socid][
'lines'][] = $line;
229 } elseif ($idprod == -1) {
232 $error = $db->lasterror();
236 unset($_POST[
'fourn' . $i]);
245 $suppliersid = array_keys($suppliers);
246 foreach ($suppliers as $supplier) {
250 $sql =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"commande_fournisseur";
251 $sql .=
" WHERE fk_soc = " . ((int) $suppliersid[$i]);
252 $sql .=
" AND source = " . ((int) $order::SOURCE_ID_REPLENISHMENT) .
" AND fk_statut = " . ((int) $order::STATUS_DRAFT);
253 $sql .=
" AND entity IN (" .
getEntity(
'commande_fournisseur') .
")";
254 $sql .=
" ORDER BY date_creation DESC";
255 $resql = $db->query($sql);
256 if ($resql && $db->num_rows($resql) > 0) {
257 $obj = $db->fetch_object($resql);
259 $order->fetch($obj->rowid);
260 $order->fetch_thirdparty();
262 foreach ($supplier[
'lines'] as $line) {
263 if (empty($line->remise_percent)) {
264 $line->remise_percent = (float) $order->thirdparty->remise_supplier_percent;
266 $result = $order->addline(
276 $line->remise_percent,
286 $line->multicurrency_subprice
291 $msg = $langs->trans(
'OrderFail') .
" : ";
292 $msg .= $order->error;
299 $order->socid = $suppliersid[$i];
300 $order->fetch_thirdparty();
301 $order->multicurrency_code = $order->thirdparty->multicurrency_code;
304 $order->source = $order::SOURCE_ID_REPLENISHMENT;
306 foreach ($supplier[
'lines'] as $line) {
307 if (empty($line->remise_percent)) {
308 $line->remise_percent = (float) $order->thirdparty->remise_supplier_percent;
310 $order->lines[] = $line;
312 $order->cond_reglement_id = (int) $order->thirdparty->cond_reglement_supplier_id;
313 $order->mode_reglement_id = (int) $order->thirdparty->mode_reglement_supplier_id;
315 $id = $order->create($user);
318 $msg = $langs->trans(
'OrderFail') .
" : ";
319 $msg .= $order->error;
327 setEventMessages($langs->trans(
'ErrorOrdersNotCreatedQtyTooLow'),
null,
'warnings');
334 header(
'Location: replenishorders.php');
341 setEventMessages($langs->trans(
'SelectProductWithNotNullQty'),
null,
'warnings');
350$form =
new Form($db);
354$title = $langs->trans(
'MissingStocks');
356if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
357 $sqldesiredtock = $db->ifsql(
"pse.desiredstock IS NULL",
"p.desiredstock",
"pse.desiredstock");
358 $sqlalertstock = $db->ifsql(
"pse.seuil_stock_alerte IS NULL",
"p.seuil_stock_alerte",
"pse.seuil_stock_alerte");
360 $sqldesiredtock =
'p.desiredstock';
361 $sqlalertstock =
'p.seuil_stock_alerte';
364$sql =
'SELECT p.rowid, p.ref, p.label, p.description, p.price,';
365$sql .=
' p.price_ttc, p.price_base_type, p.fk_product_type,';
366$sql .=
' p.tms as datem, p.duration, p.tobuy,';
367$sql .=
' p.desiredstock, p.seuil_stock_alerte,';
368if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
369 $sql .=
' pse.desiredstock as desiredstockpse, pse.seuil_stock_alerte as seuil_stock_alertepse,';
371$sql .=
" " . $sqldesiredtock .
" as desiredstockcombined, " . $sqlalertstock .
" as seuil_stock_alertecombined,";
372$sql .=
' s.fk_product,';
373$sql .=
" SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
') as stock_physique';
374if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
375 $sql .=
", SUM(".$db->ifsql(
"s.reel IS NULL OR s.fk_entrepot <> ".((
int) $fk_entrepot),
"0",
"s.reel").
') as stock_real_warehouse';
379$parameters = array();
380$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
381$sql .= $hookmanager->resPrint;
383$list_warehouse = (empty($listofqualifiedwarehousesid) ?
'0' : $listofqualifiedwarehousesid);
385$sql .=
' FROM ' . MAIN_DB_PREFIX .
'product as p';
386$sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'product_stock as s ON p.rowid = s.fk_product';
387$sql .=
' AND s.fk_entrepot IN (' . $db->sanitize($list_warehouse) .
')';
389$list_warehouse_selected = ($fk_entrepot < 0 || empty($fk_entrepot)) ? $list_warehouse : $fk_entrepot;
390$sql .=
' AND s.fk_entrepot IN (' . $db->sanitize($list_warehouse_selected) .
')';
394if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
395 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.((int) $fk_entrepot).
')';
398$parameters = array();
399$reshook = $hookmanager->executeHooks(
'printFieldListJoin', $parameters);
400$sql .= $hookmanager->resPrint;
402$sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
404 $sql .=
natural_search(array(
'p.ref',
'p.label',
'p.description',
'p.note'), $sall);
409 $sql .=
' AND p.fk_product_type = 1';
411 $sql .=
' AND p.fk_product_type <> 1';
420$sql .=
' AND p.tobuy = 1';
421if (isModEnabled(
'variants') && !
getDolGlobalString(
'VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) {
422 $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').
'))';
424if ($fk_supplier > 0) {
425 $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') .
'))';
428$parameters = array();
429$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
430$sql .= $hookmanager->resPrint;
432$sql .=
' GROUP BY p.rowid, p.ref, p.label, p.description, p.price';
433$sql .=
', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
434$sql .=
', p.duration, p.tobuy';
435$sql .=
', p.desiredstock';
436$sql .=
', p.seuil_stock_alerte';
437if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
438 $sql .=
', pse.desiredstock';
439 $sql .=
', pse.seuil_stock_alerte';
441$sql .=
', s.fk_product';
443if ($usevirtualstock) {
444 if (isModEnabled(
'order')) {
445 $sqlCommandesCli =
"(SELECT ".$db->ifsql(
"SUM(cd1.qty) IS NULL",
"0",
"SUM(cd1.qty)").
" as qty";
446 $sqlCommandesCli .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd1, ".MAIN_DB_PREFIX.
"commande as c1";
447 $sqlCommandesCli .=
" WHERE c1.rowid = cd1.fk_commande AND c1.entity IN (".getEntity(
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'commande').
")";
448 $sqlCommandesCli .=
" AND cd1.fk_product = p.rowid";
449 $sqlCommandesCli .=
" AND c1.fk_statut IN (1,2))";
451 $sqlCommandesCli =
'0';
454 if (isModEnabled(
"shipping")) {
455 $sqlExpeditionsCli =
"(SELECT ".$db->ifsql(
"SUM(ed2.qty) IS NULL",
"0",
"SUM(ed2.qty)").
" as qty";
456 $sqlExpeditionsCli .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e2,";
457 $sqlExpeditionsCli .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed2,";
458 $sqlExpeditionsCli .=
" ".MAIN_DB_PREFIX.
"commande as c2,";
459 $sqlExpeditionsCli .=
" ".MAIN_DB_PREFIX.
"commandedet as cd2";
460 $sqlExpeditionsCli .=
" WHERE ed2.fk_expedition = e2.rowid AND cd2.rowid = ed2.fk_elementdet AND e2.entity IN (".getEntity(
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'expedition').
")";
461 $sqlExpeditionsCli .=
" AND cd2.fk_commande = c2.rowid";
462 $sqlExpeditionsCli .=
" AND c2.fk_statut IN (1,2)";
463 $sqlExpeditionsCli .=
" AND cd2.fk_product = p.rowid";
464 $sqlExpeditionsCli .=
" AND e2.fk_statut IN (1,2))";
466 $sqlExpeditionsCli =
'0';
469 if (isModEnabled(
"supplier_order")) {
470 $sqlCommandesFourn =
"(SELECT " . $db->ifsql(
"SUM(cd3.qty) IS NULL",
"0",
"SUM(cd3.qty)") .
" as qty";
471 $sqlCommandesFourn .=
" FROM " . MAIN_DB_PREFIX .
"commande_fournisseurdet as cd3,";
472 $sqlCommandesFourn .=
" " . MAIN_DB_PREFIX .
"commande_fournisseur as c3";
473 $sqlCommandesFourn .=
" WHERE c3.rowid = cd3.fk_commande";
474 $sqlCommandesFourn .=
" AND c3.entity IN (".getEntity(
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'supplier_order').
")";
475 $sqlCommandesFourn .=
" AND cd3.fk_product = p.rowid";
476 $sqlCommandesFourn .=
" AND c3.fk_statut IN (3,4))";
478 $sqlReceptionFourn =
"(SELECT ".$db->ifsql(
"SUM(fd4.qty) IS NULL",
"0",
"SUM(fd4.qty)").
" as qty";
479 $sqlReceptionFourn .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as cf4,";
480 $sqlReceptionFourn .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as fd4";
481 $sqlReceptionFourn .=
" WHERE fd4.fk_element = cf4.rowid AND cf4.entity IN (".getEntity(
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'supplier_order').
")";
482 $sqlReceptionFourn .=
" AND fd4.fk_product = p.rowid";
483 $sqlReceptionFourn .=
" AND cf4.fk_statut IN (3,4))";
485 $sqlCommandesFourn =
'0';
486 $sqlReceptionFourn =
'0';
489 if (isModEnabled(
'mrp')) {
490 $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";
491 $sqlProductionToConsume .=
" FROM ".MAIN_DB_PREFIX.
"mrp_mo as mm5,";
492 $sqlProductionToConsume .=
" ".MAIN_DB_PREFIX.
"mrp_production as mp5";
493 $sqlProductionToConsume .=
" WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'mo').
")";
494 $sqlProductionToConsume .=
" AND mp5.fk_product = p.rowid";
495 $sqlProductionToConsume .=
" AND mp5.role IN ('toconsume', 'consumed')";
496 $sqlProductionToConsume .=
" AND mm5.status IN (1,2))";
498 $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";
499 $sqlProductionToProduce .=
" FROM ".MAIN_DB_PREFIX.
"mrp_mo as mm5,";
500 $sqlProductionToProduce .=
" ".MAIN_DB_PREFIX.
"mrp_production as mp5";
501 $sqlProductionToProduce .=
" WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'mo').
")";
502 $sqlProductionToProduce .=
" AND mp5.fk_product = p.rowid";
503 $sqlProductionToProduce .=
" AND mp5.role IN ('toproduce', 'produced')";
504 $sqlProductionToProduce .=
" AND mm5.status IN (1,2))";
506 $sqlProductionToConsume =
'0';
507 $sqlProductionToProduce =
'0';
511 $sql .=
" (" . $sqldesiredtock .
" >= 0 AND (" . $sqldesiredtock .
" > SUM(" . $db->ifsql(
"s.reel IS NULL",
"0",
"s.reel") .
')';
512 $sql .=
" - (" . $sqlCommandesCli .
" - " . $sqlExpeditionsCli .
") + (" . $sqlCommandesFourn .
" - " . $sqlReceptionFourn .
") + (" . $sqlProductionToProduce .
" - " . $sqlProductionToConsume .
")))";
514 if ($includeproductswithoutdesiredqty ==
'on') {
515 $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") .
")";
517 $sql .=
" (" . $sqlalertstock .
" >= 0 AND (" . $sqlalertstock .
" > SUM(" . $db->ifsql(
"s.reel IS NULL",
"0",
"s.reel") .
')';
519 $sql .=
" - (" . $sqlCommandesCli .
" - " . $sqlExpeditionsCli .
") + (" . $sqlCommandesFourn .
" - " . $sqlReceptionFourn .
") + (" . $sqlProductionToProduce .
" - " . $sqlProductionToConsume .
")))";
521 if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
523 $sql .=
" pse.desiredstock > 0)";
526 if ($salert ==
'on') {
528 if ($includeproductswithoutdesiredqty ==
'on') {
529 $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") .
")";
531 $sql .= $sqlalertstock .
" >= 0 AND (" . $sqlalertstock .
" > SUM(" . $db->ifsql(
"s.reel IS NULL",
"0",
"s.reel") .
")";
533 $sql .=
" - (" . $sqlCommandesCli .
" - " . $sqlExpeditionsCli .
") + (" . $sqlCommandesFourn .
" - " . $sqlReceptionFourn .
") + (" . $sqlProductionToProduce .
" - " . $sqlProductionToConsume .
"))";
535 $alertchecked =
'checked';
539 $sql .=
"(" . $sqldesiredtock .
" >= 0 AND (" . $sqldesiredtock .
" > SUM(" . $db->ifsql(
"s.reel IS NULL",
"0",
"s.reel") .
")))";
541 if ($includeproductswithoutdesiredqty ==
'on') {
542 $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") .
')))';
544 $sql .=
" (" . $sqlalertstock .
" >= 0 AND (" . $sqlalertstock .
" > SUM(" . $db->ifsql(
"s.reel IS NULL",
"0",
"s.reel") .
')))';
547 if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
549 $sql .=
" pse.desiredstock > 0)";
552 if ($salert ==
'on') {
554 if ($includeproductswithoutdesiredqty ==
'on') {
555 $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") .
"))";
557 $sql .=
" " . $sqlalertstock .
" >= 0 AND (" . $sqlalertstock .
" > SUM(" . $db->ifsql(
"s.reel IS NULL",
"0",
"s.reel") .
'))';
560 $alertchecked =
'checked';
564$includeproductswithoutdesiredqtychecked =
'';
565if ($includeproductswithoutdesiredqty ==
'on') {
566 $includeproductswithoutdesiredqtychecked =
'checked';
569$nbtotalofrecords =
'';
571 $result = $db->query($sql);
572 $nbtotalofrecords = $db->num_rows($result);
573 if (($page * $limit) > $nbtotalofrecords) {
579$sql .= $db->order($sortfield, $sortorder);
580$sql .= $db->plimit($limit + 1, $offset);
583$resql = $db->query($sql);
589$num = $db->num_rows($resql);
592$helpurl =
'EN:Module_Stocks_En|FR:Module_Stock|';
593$helpurl .=
'ES:Módulo_Stocks';
595llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-stock_replenish');
599$head[0][0] = DOL_URL_ROOT .
'/product/stock/replenish.php';
601$head[0][2] =
'replenish';
603$head[1][0] = DOL_URL_ROOT .
'/product/stock/replenishorders.php';
604$head[1][1] = $langs->trans(
"ReplenishmentOrders");
605$head[1][2] =
'replenishorders';
612print
'<span class="opacitymedium">' . $langs->trans(
"ReplenishmentStatusDesc") .
'</span>' .
"\n";
616if (empty($fk_entrepot) &&
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE')) {
617 print
'<span class="opacitymedium">'.$langs->trans(
"ReplenishmentStatusDescPerWarehouse").
'</span>'.
"\n";
620if ($usevirtualstock == 1) {
621 print $langs->trans(
"CurentSelectionMode") .
': ';
622 print
'<span class="a-mesure">' . $langs->trans(
"UseVirtualStock") .
'</span>';
623 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>';
626if ($usevirtualstock == 0) {
627 print $langs->trans(
"CurentSelectionMode") .
': ';
628 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>';
629 print
' <span class="a-mesure">' . $langs->trans(
"UsePhysicalStock") .
'</span>';
634print
'<form name="formFilterWarehouse" method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
635print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
636print
'<input type="hidden" name="action" value="filter">';
637print
'<input type="hidden" name="search_ref" value="' . $search_ref .
'">';
638print
'<input type="hidden" name="search_label" value="' . $search_label .
'">';
639print
'<input type="hidden" name="salert" value="' . $salert .
'">';
640print
'<input type="hidden" name="includeproductswithoutdesiredqty" value="' . $includeproductswithoutdesiredqty .
'">';
641print
'<input type="hidden" name="draftorder" value="' . $draftorder .
'">';
642print
'<input type="hidden" name="mode" value="' . $mode .
'">';
643if ($limit > 0 && $limit != $conf->liste_limit) {
644 print
'<input type="hidden" name="limit" value="' . $limit .
'">';
647 print
'<div class="inline-block valignmiddle" style="padding-right: 20px;">';
648 print $langs->trans(
'Warehouse') .
' ' . $formproduct->selectWarehouses($fk_entrepot,
'fk_entrepot',
'', 1);
651print
'<div class="inline-block valignmiddle" style="padding-right: 20px;">';
652$filter =
'(fournisseur:=:1)';
653print $langs->trans(
'Supplier') .
' ' . $form->select_company($fk_supplier,
'fk_supplier', $filter, 1);
656$parameters = array();
657$reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
658if (empty($reshook)) {
659 print $hookmanager->resPrint;
662print
'<div class="inline-block valignmiddle">';
663print
'<input type="submit" class="button smallpaddingimp" name="valid" value="' . $langs->trans(
'ToFilter') .
'">';
668print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formulaire">';
669print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
670print
'<input type="hidden" name="fk_supplier" value="' . $fk_supplier .
'">';
671print
'<input type="hidden" name="fk_entrepot" value="' . $fk_entrepot .
'">';
672print
'<input type="hidden" name="sortfield" value="' . $sortfield .
'">';
673print
'<input type="hidden" name="sortorder" value="' . $sortorder .
'">';
674print
'<input type="hidden" name="type" value="' . $type .
'">';
675print
'<input type="hidden" name="linecount" value="' . $num .
'">';
676print
'<input type="hidden" name="action" value="order">';
677print
'<input type="hidden" name="mode" value="' . $mode .
'">';
680if ($search_ref || $search_label || $sall || $salert || $draftorder ||
GETPOST(
'search',
'alpha')) {
681 $filters =
'&search_ref=' . urlencode($search_ref) .
'&search_label=' . urlencode($search_label);
682 $filters .=
'&sall=' . urlencode($sall);
683 $filters .=
'&salert=' . urlencode($salert);
684 $filters .=
'&draftorder=' . urlencode($draftorder);
685 $filters .=
'&mode=' . urlencode($mode);
686 if ($fk_supplier > 0) {
687 $filters .=
'&fk_supplier='.urlencode((
string) ($fk_supplier));
689 if ($fk_entrepot > 0) {
690 $filters .=
'&fk_entrepot='.urlencode((
string) ($fk_entrepot));
693 $filters =
'&search_ref='.urlencode($search_ref).
'&search_label='.urlencode($search_label);
694 $filters .=
'&fourn_id='.urlencode((
string) ($fourn_id));
695 $filters .= (isset($type) ?
'&type='.urlencode((
string) ($type)) :
'');
696 $filters .=
'&salert='.urlencode($salert);
697 $filters .=
'&draftorder='.urlencode($draftorder);
698 $filters .=
'&mode='.urlencode($mode);
699 if ($fk_supplier > 0) {
700 $filters .=
'&fk_supplier='.urlencode((
string) ($fk_supplier));
702 if ($fk_entrepot > 0) {
703 $filters .=
'&fk_entrepot='.urlencode((
string) ($fk_entrepot));
706if ($limit > 0 && $limit != $conf->liste_limit) {
707 $filters .=
'&limit=' . ((int) $limit);
709if (!empty($includeproductswithoutdesiredqty)) {
710 $filters .=
'&includeproductswithoutdesiredqty='.urlencode($includeproductswithoutdesiredqty);
712if (!empty($salert)) {
713 $filters .=
'&salert='.urlencode($salert);
716$param = (isset($type) ?
'&type='.urlencode((
string) ($type)) :
'');
717$param .=
'&fourn_id='.urlencode((
string) ($fourn_id)).
'&search_label='.urlencode((
string) ($search_label)).
'&includeproductswithoutdesiredqty='.urlencode((
string) ($includeproductswithoutdesiredqty)).
'&salert='.urlencode((
string) ($salert)).
'&draftorder='.urlencode((
string) ($draftorder));
718$param .=
'&search_ref='.urlencode($search_ref);
719$param .=
'&mode='.urlencode($mode);
720$param .=
'&fk_supplier='.urlencode((
string) ($fk_supplier));
721$param .=
'&fk_entrepot='.urlencode((
string) ($fk_entrepot));
722if (!empty($includeproductswithoutdesiredqty)) {
723 $param .=
'&includeproductswithoutdesiredqty='.urlencode($includeproductswithoutdesiredqty);
725if (!empty($salert)) {
726 $param .=
'&salert='.urlencode($salert);
729$stocklabel = $langs->trans(
'Stock');
730$stocklabelbis = $langs->trans(
'Stock');
732if ($usevirtualstock == 1) {
733 $stocklabel = $langs->trans(
'VirtualStock');
734 $stocktooltip = $langs->trans(
"VirtualStockDesc");
736if ($usevirtualstock == 0) {
737 $stocklabel = $langs->trans(
'PhysicalStock');
739if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
740 $stocklabelbis = $stocklabel.
' (Selected warehouse)';
741 $stocklabel .=
' ('.$langs->trans(
"AllWarehouses").
')';
743$texte = $langs->trans(
'Replenishment');
781print
'<div class="div-table-responsive-no-min">';
782print
'<table class="liste centpercent">';
785print
'<tr class="liste_titre_filter">';
786print
'<td class="liste_titre"> </td>';
787print
'<td class="liste_titre"><input class="flat" type="text" name="search_ref" size="8" value="' .
dol_escape_htmltag($search_ref) .
'"></td>';
788print
'<td class="liste_titre"><input class="flat" type="text" name="search_label" size="8" value="' .
dol_escape_htmltag($search_label) .
'"></td>';
789if (isModEnabled(
"service") && $type == 1) {
790 print
'<td class="liste_titre"> </td>';
792print
'<td class="liste_titre right">' . $form->textwithpicto($langs->trans(
'IncludeEmptyDesiredStock'), $langs->trans(
'IncludeProductWithUndefinedAlerts')) .
' <input type="checkbox" id="includeproductswithoutdesiredqty" name="includeproductswithoutdesiredqty" ' . (!empty($includeproductswithoutdesiredqtychecked) ? $includeproductswithoutdesiredqtychecked :
'') .
'></td>';
793print
'<td class="liste_titre right"></td>';
794print
'<td class="liste_titre right">'.$langs->trans(
'AlertOnly').
' <input type="checkbox" id="salert" name="salert" '.(!empty($alertchecked) ? $alertchecked :
'').
'></td>';
795if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
796 print
'<td class="liste_titre"> </td>';
798print
'<td class="liste_titre right">';
800 print $langs->trans(
'IncludeAlsoDraftOrders').
' <input type="checkbox" id="draftorder" name="draftorder" '.(!empty($draftchecked) ? $draftchecked :
'').
'>';
803print
'<td class="liste_titre"> </td>';
805$parameters = array(
'param' => $param,
'sortfield' => $sortfield,
'sortorder' => $sortorder);
806$reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
807print $hookmanager->resPrint;
809print
'<td class="liste_titre maxwidthsearch right">';
810$searchpicto = $form->showFilterAndCheckAddButtons(0);
816print
'<tr class="liste_titre">';
820if (isModEnabled(
"service") && $type == 1) {
821 print_liste_field_titre(
'Duration', $_SERVER[
"PHP_SELF"],
'p.duration', $param,
'',
'', $sortfield, $sortorder,
'center ');
823print_liste_field_titre(
'DesiredStock', $_SERVER[
"PHP_SELF"],
'p.desiredstock', $param,
'',
'', $sortfield, $sortorder,
'right ');
824print_liste_field_titre(
'StockLimitShort', $_SERVER[
"PHP_SELF"],
'p.seuil_stock_alerte', $param,
'',
'', $sortfield, $sortorder,
'right ');
825print_liste_field_titre($stocklabel, $_SERVER[
"PHP_SELF"],
'stock_physique', $param,
'',
'', $sortfield, $sortorder,
'right ', $stocktooltip);
826if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
827 print_liste_field_titre($stocklabelbis, $_SERVER[
"PHP_SELF"],
'stock_real_warehouse', $param,
'',
'', $sortfield, $sortorder,
'right ');
830print_liste_field_titre(
'StockToBuy', $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'right ');
831print_liste_field_titre(
'SupplierRef', $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'right ');
834$parameters = array(
'param' => $param,
'sortfield' => $sortfield,
'sortorder' => $sortorder);
835$reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
836print $hookmanager->resPrint;
840while ($i < ($limit ? min($num, $limit) : $num)) {
841 $objp = $db->fetch_object($resql);
844 $result = $prod->fetch($objp->rowid);
850 $prod->load_stock(
'warehouseopen, warehouseinternal'.(!$usevirtualstock ?
', novirtual' :
''), $draftchecked);
854 $sql =
'SELECT label,description';
855 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'product_lang';
856 $sql .=
' WHERE fk_product = ' . ((int) $objp->rowid);
857 $sql .=
" AND lang = '" . $db->escape($langs->getDefaultLang()) .
"'";
860 $resqlm = $db->query($sql);
862 $objtp = $db->fetch_object($resqlm);
863 if (!empty($objtp->description)) {
864 $objp->description = $objtp->description;
866 if (!empty($objtp->label)) {
867 $objp->label = $objtp->label;
873 if ($usevirtualstock) {
875 $stock = $prod->stock_theorique;
878 $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->virtual;
881 $stock = $prod->stock_reel;
882 if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
883 $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->real;
888 if (isset($draftchecked)) {
889 $result = $prod->load_stats_commande_fournisseur(0,
'0,1,2,3,4');
890 } elseif (!$usevirtualstock) {
891 $result = $prod->load_stats_commande_fournisseur(0,
'1,2,3,4');
894 if (!$usevirtualstock) {
895 $result = $prod->load_stats_reception(0,
'4');
900 $ordered = $prod->stats_commande_fournisseur[
'qty'] - $prod->stats_reception[
'qty'];
902 $desiredstock = $objp->desiredstock;
903 $alertstock = $objp->seuil_stock_alerte;
904 $desiredstockwarehouse = (!empty($objp->desiredstockpse) ? $objp->desiredstockpse : 0);
905 $alertstockwarehouse = (!empty($objp->seuil_stock_alertepse) ? $objp->seuil_stock_alertepse : 0);
908 if ($alertstock && ($stock < $alertstock)) {
909 $warning =
img_warning($langs->trans(
'StockTooLow')) .
' ';
911 $warningwarehouse =
'';
912 if ($alertstockwarehouse && ($stockwarehouse < $alertstockwarehouse)) {
913 $warningwarehouse =
img_warning($langs->trans(
'StockTooLow')) .
' ';
919 if (empty($usevirtualstock)) {
920 $stocktobuy = max(max($desiredstock, $alertstock) - $stock - $ordered, 0);
922 $stocktobuy = max(max($desiredstock, $alertstock) - $stock, 0);
924 if (empty($usevirtualstock)) {
925 $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse - $ordered, 0);
927 $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse, 0);
932 $stockforcompare = ($usevirtualstock ? $stock : $stock + $ordered);
940 $picto =
img_picto($langs->trans(
"NoPendingReceptionOnSupplierOrder"),
'help');
943 print
'<tr class="oddeven">';
946 print
'<td><input type="checkbox" class="check" name="choose' . $i .
'"></td>';
948 print
'<td class="nowrap">' . $prod->getNomUrl(1,
'stock') .
'</td>';
950 print
'<td class="tdoverflowmax200" title="' .
dol_escape_htmltag($objp->label) .
'">';
952 print
'<input type="hidden" name="desc' . $i .
'" value="' .
dol_escape_htmltag($objp->description) .
'">';
955 if (isModEnabled(
"service") && $type == 1) {
957 if (preg_match(
'/([0-9]+)y/i', $objp->duration, $regs)) {
958 $duration = $regs[1] .
' ' . $langs->trans(
'DurationYear');
959 } elseif (preg_match(
'/([0-9]+)m/i', $objp->duration, $regs)) {
960 $duration = $regs[1] .
' ' . $langs->trans(
'DurationMonth');
961 } elseif (preg_match(
'/([0-9]+)d/i', $objp->duration, $regs)) {
962 $duration = $regs[1] .
' ' . $langs->trans(
'DurationDay');
964 $duration = $objp->duration;
966 print
'<td class="center">' . $duration .
'</td>';
970 print
'<td class="right">'.((getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) > 0 ? ($objp->desiredstockpse ? $desiredstockwarehouse :
img_info($langs->trans(
'ProductValuesUsedBecauseNoValuesForThisWarehouse')) .
'0') : $desiredstock).
'</td>';
973 print
'<td class="right">'.((getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) > 0 ? ($objp->seuil_stock_alertepse ? $alertstockwarehouse :
img_info($langs->trans(
'ProductValuesUsedBecauseNoValuesForThisWarehouse')) .
'0') : $alertstock).
'</td>';
976 print
'<td class="right">' . $warning . $stock;
977 print
'<!-- stock returned by main sql is ' . $objp->stock_physique .
' -->';
981 if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
982 print
'<td class="right">'.$warningwarehouse.$stockwarehouse.
'</td>';
986 print
'<td class="right"><a href="replenishorders.php?search_product=' . $prod->id .
'">' . $ordered .
'</a> ' . $picto .
'</td>';
989 $tobuy = ((
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) > 0 ? $stocktobuywarehouse : $stocktobuy);
990 print
'<td class="right"><input type="text" size="4" name="tobuy'.$i.
'" value="'.$tobuy.
'"></td>';
993 print
'<td class="right">';
994 print $form->select_product_fourn_price($prod->id,
'fourn' . $i, $fk_supplier);
998 $parameters = array(
'objp' => $objp,
'i' => $i,
'tobuy' => $tobuy);
999 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters);
1000 print $hookmanager->resPrint;
1009 if (isModEnabled(
"service") && $type == 1) {
1012 if (
getDolGlobalString(
'STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
1015 print
'<tr><td colspan="' . $colspan .
'">';
1016 print
'<span class="opacitymedium">';
1017 print $langs->trans(
"None");
1022$parameters = array(
'sql' => $sql);
1023$reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters);
1024print $hookmanager->resPrint;
1034$value = $langs->trans(
"CreateOrders");
1035print
'<div class="center"><input type="submit" class="button" name="valid" value="' . $value .
'"></div>';
1043<script type="text/javascript">
1044function toggle(source)
1046 checkboxes = document.getElementsByClassName("check");
1047 for (var i=0; i < checkboxes.length;i++) {
1048 if (!checkboxes[i].disabled) {
1049 checkboxes[i].checked = source.checked;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage predefined suppliers products.
Class to manage line orders.
Class to manage predefined suppliers products.
Class to manage products or services.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_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 a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
img_info($titlealt='default')
Show info logo.
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.