33 require
'../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
35 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
42 if (!empty($conf->project->enabled)) {
43 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
47 $langs->loadLangs(array(
"bills",
"orders",
"sendings",
"companies",
"deliveries",
"products",
"stocks",
"receptions"));
49 if (!empty($conf->productbatch->enabled)) {
50 $langs->load(
'productbatch');
56 $lineid =
GETPOST(
'lineid',
'int');
57 $action =
GETPOST(
'action',
'aZ09');
58 $fk_default_warehouse =
GETPOST(
'fk_default_warehouse',
'int');
59 $cancel =
GETPOST(
'cancel',
'alpha');
60 $confirm =
GETPOST(
'confirm',
'alpha');
63 $socid = $user->socid;
66 $hookmanager->initHooks(array(
'ordersupplierdispatch'));
70 if ($_GET[
"projectid"]) {
71 $projectid =
GETPOST(
"projectid",
'int');
76 if ($id > 0 || !empty($ref)) {
77 $result = $object->fetch($id, $ref);
81 $result = $object->fetch_thirdparty();
87 if (empty($conf->reception->enabled)) {
88 $permissiontoreceive = $user->rights->fournisseur->commande->receptionner;
89 $permissiontocontrol = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->commande_advance->check)));
91 $permissiontoreceive = $user->rights->reception->creer;
92 $permissiontocontrol = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)));
96 $result =
restrictedArea($user,
'fournisseur', $id,
'commande_fournisseur',
'commande');
98 if (empty($conf->stock->enabled)) {
107 $parameters = array();
108 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
113 if ($action ==
'checkdispatchline' && $permissiontocontrol) {
119 $result = $supplierorderdispatch->fetch($lineid);
122 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
127 $result = $supplierorderdispatch->setStatut(1);
129 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
136 $result = $object->calcAndSetStatusDispatch($user);
150 if ($action ==
'uncheckdispatchline' && $permissiontocontrol) {
156 $result = $supplierorderdispatch->fetch($lineid);
159 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
164 $result = $supplierorderdispatch->setStatut(0);
166 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
172 $result = $object->calcAndSetStatusDispatch($user);
186 if ($action ==
'denydispatchline' && $permissiontocontrol) {
192 $result = $supplierorderdispatch->fetch($lineid);
195 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
200 $result = $supplierorderdispatch->setStatut(2);
202 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
208 $result = $object->calcAndSetStatusDispatch($user);
222 if ($action ==
'dispatch' && $permissiontoreceive) {
229 foreach ($_POST as $key => $value) {
232 if (preg_match(
'/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
237 $prod =
"product_".$reg[1].
'_'.$reg[2];
238 $qty =
"qty_".$reg[1].
'_'.$reg[2];
239 $ent =
"entrepot_".$reg[1].
'_'.$reg[2];
241 $ent = $fk_default_warehouse;
243 $pu =
"pu_".$reg[1].
'_'.$reg[2];
244 $fk_commandefourndet =
"fk_commandefourndet_".$reg[1].
'_'.$reg[2];
246 if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
247 if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
248 $dto =
GETPOST(
"dto_".$reg[1].
'_'.$reg[2],
'int');
252 $saveprice =
"saveprice_".$reg[1].
'_'.$reg[2];
258 if (!(
GETPOST($ent,
'int') > 0)) {
259 dol_syslog(
'No dispatch for line '.$key.
' as no warehouse was chosen.');
260 $text = $langs->transnoentities(
'Warehouse').
', '.$langs->transnoentities(
'Line').
' '.($numline);
261 setEventMessages($langs->trans(
'ErrorFieldRequired', $text),
null,
'errors');
266 $result = $object->dispatchProduct($user,
GETPOST($prod,
'int'),
GETPOST($qty),
GETPOST($ent,
'int'),
GETPOST($pu),
GETPOST(
'comment'),
'',
'',
'',
GETPOST($fk_commandefourndet,
'int'), $notrigger);
272 if (!$error && !empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
273 if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
282 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_fournisseur_price";
283 $sql .=
" SET unitprice='".price2num(
GETPOST($pu),
'MU').
"'";
284 $sql .=
", price=".price2num(
GETPOST($pu),
'MU').
"*quantity";
285 $sql .=
", remise_percent = ".((float) $dto);
286 $sql .=
" WHERE fk_soc=".((int) $object->socid);
287 $sql .=
" AND fk_product=".((int)
GETPOST($prod,
'int'));
289 $resql = $db->query($sql);
297 if (preg_match(
'/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
303 $prod =
'product_batch_'.$reg[1].
'_'.$reg[2];
304 $qty =
'qty_'.$reg[1].
'_'.$reg[2];
305 $ent =
'entrepot_'.$reg[1].
'_'.$reg[2];
306 $pu =
'pu_'.$reg[1].
'_'.$reg[2];
307 $fk_commandefourndet =
'fk_commandefourndet_'.$reg[1].
'_'.$reg[2];
308 $lot =
'lot_number_'.$reg[1].
'_'.$reg[2];
309 $dDLUO =
dol_mktime(12, 0, 0,
GETPOST(
'dluo_'.$reg[1].
'_'.$reg[2].
'month',
'int'),
GETPOST(
'dluo_'.$reg[1].
'_'.$reg[2].
'day',
'int'),
GETPOST(
'dluo_'.$reg[1].
'_'.$reg[2].
'year',
'int'));
310 $dDLC =
dol_mktime(12, 0, 0,
GETPOST(
'dlc_'.$reg[1].
'_'.$reg[2].
'month',
'int'),
GETPOST(
'dlc_'.$reg[1].
'_'.$reg[2].
'day',
'int'),
GETPOST(
'dlc_'.$reg[1].
'_'.$reg[2].
'year',
'int'));
312 $fk_commandefourndet =
'fk_commandefourndet_'.$reg[1].
'_'.$reg[2];
314 if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
315 if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
316 $dto =
GETPOST(
"dto_".$reg[1].
'_'.$reg[2],
'int');
320 $saveprice =
"saveprice_".$reg[1].
'_'.$reg[2];
326 if (!(
GETPOST($ent,
'int') > 0)) {
327 dol_syslog(
'No dispatch for line '.$key.
' as no warehouse was chosen.');
328 $text = $langs->transnoentities(
'Warehouse').
', '.$langs->transnoentities(
'Line').
' '.($numline).
'-'.($reg[1] + 1);
329 setEventMessages($langs->trans(
'ErrorFieldRequired', $text),
null,
'errors');
333 if (!(
GETPOST($lot,
'alpha') || $dDLUO || $dDLC)) {
334 dol_syslog(
'No dispatch for line '.$key.
' as serial/eat-by/sellby date are not set');
335 $text = $langs->transnoentities(
'atleast1batchfield').
', '.$langs->transnoentities(
'Line').
' '.($numline).
'-'.($reg[1] + 1);
336 setEventMessages($langs->trans(
'ErrorFieldRequired', $text),
null,
'errors');
341 $result = $object->dispatchProduct($user,
GETPOST($prod,
'int'),
GETPOST($qty),
GETPOST($ent,
'int'),
GETPOST($pu),
GETPOST(
'comment'), $dDLUO, $dDLC,
GETPOST($lot,
'alpha'),
GETPOST($fk_commandefourndet,
'int'), $notrigger);
347 if (!$error && !empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
348 if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
349 $dto =
GETPOST(
"dto_".$reg[1].
'_'.$reg[2],
'int');
353 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_fournisseur_price";
354 $sql .=
" SET unitprice = ".price2num(
GETPOST($pu),
'MU', 2);
355 $sql .=
", price = ".price2num(
GETPOST($pu),
'MU', 2).
" * quantity";
356 $sql .=
", remise_percent = ".price2num((empty($dto) ? 0 : $dto), 3, 2).
"'";
357 $sql .=
" WHERE fk_soc = ".((int) $object->socid);
358 $sql .=
" AND fk_product=".((int)
GETPOST($prod,
'int'));
360 $resql = $db->query($sql);
370 $result = $object->calcAndSetStatusDispatch($user,
GETPOST(
'closeopenorder') ? 1 : 0,
GETPOST(
'comment'));
378 global $conf, $langs, $user;
381 $result = $object->call_trigger(
'ORDER_SUPPLIER_DISPATCH', $user);
390 if ($result >= 0 && !$error) {
393 header(
"Location: dispatch.php?id=".$id);
401 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $permissiontoreceive) {
405 $result = $supplierorderdispatch->fetch($lineid);
407 $qty = $supplierorderdispatch->qty;
408 $entrepot = $supplierorderdispatch->fk_entrepot;
409 $product = $supplierorderdispatch->fk_product;
411 $comment = $supplierorderdispatch->comment;
412 $eatby = $supplierorderdispatch->eatby;
413 $sellby = $supplierorderdispatch->sellby;
414 $batch = $supplierorderdispatch->batch;
416 $result = $supplierorderdispatch->delete($user);
419 $errors = $object->errors;
423 if ($entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) && empty($supplierorderdispatch->fk_reception)) {
426 $mouv->origin = &$object;
427 $mouv->setOrigin($object->element, $object->id);
428 $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment,
'', $eatby, $sellby, $batch);
430 $errors = $mouv->errors;
445 if ($action ==
'updateline' && $permissiontoreceive) {
450 $result = $supplierorderdispatch->fetch($lineid);
452 $qty = $supplierorderdispatch->qty;
453 $entrepot = $supplierorderdispatch->fk_entrepot;
454 $product = $supplierorderdispatch->fk_product;
456 $comment = $supplierorderdispatch->comment;
457 $eatby = $supplierorderdispatch->eatby;
458 $sellby = $supplierorderdispatch->sellby;
459 $batch = $supplierorderdispatch->batch;
462 $supplierorderdispatch->fk_entrepot =
GETPOST(
'fk_entrepot');
463 $result = $supplierorderdispatch->update($user);
467 $errors = $supplierorderdispatch->errors;
470 if ($entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
473 $mouv->origin = &$object;
474 $mouv->setOrigin($object->element, $object->id);
475 $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment,
'', $eatby, $sellby, $batch);
477 $errors = $mouv->errors;
480 $mouv->origin = &$object;
481 $result = $mouv->reception($user, $product, $supplierorderdispatch->fk_entrepot, $supplierorderdispatch->qty, $price, $comment, $eatby, $sellby, $batch);
483 $errors = $mouv->errors;
506 $warehouse_static =
new Entrepot($db);
509 $help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
510 $morejs = array(
'/fourn/js/lib_dispatch.js.php');
514 if ($id > 0 || !empty($ref)) {
516 $soc->fetch($object->socid);
518 $author =
new User($db);
519 $author->fetch($object->user_author_id);
523 $title = $langs->trans(
"SupplierOrder");
529 if ($action ==
'ask_deleteline') {
530 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
534 $parameters = array(
'lineid' => $lineid);
536 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
537 if (empty($reshook)) {
539 } elseif ($reshook > 0) {
548 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php'.(!empty($socid) ?
'?socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
550 $morehtmlref =
'<div class="refidno">';
552 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, 0,
'string',
'', 0, 1);
553 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, 0,
'string',
'',
null,
null,
'', 1);
555 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1);
557 if (!empty($conf->project->enabled)) {
558 $langs->load(
"projects");
559 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
560 if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) {
561 if ($action !=
'classify') {
563 $morehtmlref .=
' : ';
565 if ($action ==
'classify') {
567 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
568 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
569 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
570 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
571 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
572 $morehtmlref .=
'</form>';
574 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
577 if (!empty($object->fk_project)) {
579 $proj->fetch($object->fk_project);
580 $morehtmlref .=
' : '.$proj->getNomUrl(1);
582 $morehtmlref .=
' - '.$proj->title;
589 $morehtmlref .=
'</div>';
592 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
595 print
'<div class="fichecenter">';
596 print
'<div class="underbanner clearboth"></div>';
598 print
'<table class="border tableforfield" width="100%">';
601 if ($object->methode_commande_id > 0) {
602 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
603 if ($object->date_commande) {
608 if ($object->methode_commande) {
609 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.$object->getInputMethod().
'</td></tr>';
614 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
615 print
'<td>'.$author->getNomUrl(1,
'', 0, 0, 0).
'</td>';
618 $parameters = array();
619 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
636 print
'<br><span class="opacitymedium">'.$langs->trans(
"OrderStatusNotReadyToDispatch").
'</span>';
642 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
644 $formproduct->loadWarehouses();
646 $listwarehouses = $entrepot->list_array(1);
649 if (empty($conf->reception->enabled)) {
650 print
'<form method="POST" action="dispatch.php?id='.$object->id.
'">';
652 print
'<form method="post" action="'.dol_buildpath(
'/reception/card.php', 1).
'?originid='.$object->id.
'&origin=supplierorder">';
655 print
'<input type="hidden" name="token" value="'.newToken().
'">';
656 if (empty($conf->reception->enabled)) {
657 print
'<input type="hidden" name="action" value="dispatch">';
659 print
'<input type="hidden" name="action" value="create">';
662 print
'<div class="div-table-responsive-no-min">';
663 print
'<table class="noborder centpercent">';
666 $products_dispatched = array();
667 $sql =
"SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
668 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as cfd";
669 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet";
670 $sql .=
" WHERE cfd.fk_commande = ".((int) $object->id);
671 $sql .=
" GROUP BY l.rowid, cfd.fk_product";
673 $resql = $db->query($sql);
675 $num = $db->num_rows(
$resql);
680 $objd = $db->fetch_object(
$resql);
681 $products_dispatched[$objd->rowid] =
price2num($objd->qty, 5);
689 $sql =
"SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, l.qty as qty,";
690 $sql .=
" p.ref, p.label, p.tobatch, p.fk_default_warehouse";
693 $parameters = array();
694 $reshook = $hookmanager->executeHooks(
695 'printFieldListSelect',
703 $sql .= $hookmanager->resPrint;
705 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l";
706 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product=p.rowid";
707 $sql .=
" WHERE l.fk_commande = ".((int) $object->id);
708 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
709 $sql .=
" AND l.product_type = 0";
713 $parameters = array();
714 $reshook = $hookmanager->executeHooks(
715 'printFieldListWhere',
723 $sql .= $hookmanager->resPrint;
726 $sql .=
" ORDER BY l.rang, p.ref, p.label";
728 $resql = $db->query($sql);
730 $num = $db->num_rows(
$resql);
734 print
'<tr class="liste_titre">';
736 print
'<td>'.$langs->trans(
"Description").
'</td>';
737 if (!empty($conf->productbatch->enabled)) {
738 print
'<td class="dispatch_batch_number_title">'.$langs->trans(
"batch_number").
'</td>';
739 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
740 print
'<td class="dispatch_dlc_title">'.$langs->trans(
"SellByDate").
'</td>';
742 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
743 print
'<td class="dispatch_dluo_title">'.$langs->trans(
"EatByDate").
'</td>';
750 print
'<td class="right">'.$langs->trans(
"SupplierRef").
'</td>';
751 print
'<td class="right">'.$langs->trans(
"QtyOrdered").
'</td>';
752 print
'<td class="right">'.$langs->trans(
"QtyDispatchedShort").
'</td>';
753 print
' <td class="right">'.$langs->trans(
"QtyToDispatchShort");
754 print
'<br><a href="#" id="autoreset">'.$langs->trans(
"Reset").
'</a></td>';
755 print
'<td width="32"></td>';
757 if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
758 if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
759 print
'<td class="right">'.$langs->trans(
"Price").
'</td>';
760 print
'<td class="right">'.$langs->trans(
"ReductionShort").
' (%)</td>';
761 print
'<td class="right">'.$langs->trans(
"UpdatePrice").
'</td>';
765 print
'<td align="right">'.$langs->trans(
"Warehouse");
768 if (count($listwarehouses) > 1) {
769 print
'<br><span class="opacitymedium">'.$langs->trans(
"ForceTo").
'</span> '.
$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 1, 0, 0,
'', 0, 0, $disabled,
'',
'minwidth100 maxwidth300', 1);
770 } elseif (count($listwarehouses) == 1) {
771 print
'<br><span class="opacitymedium">'.$langs->trans(
"ForceTo").
'</span> '.
$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0,
'', 0, 0, $disabled,
'',
'minwidth100 maxwidth300', 1);
777 $parameters = array();
778 $reshook = $hookmanager->executeHooks(
779 'printFieldListTitle',
787 print $hookmanager->resPrint;
796 $conf->cache[
'product'] = array();
799 $objp = $db->fetch_object(
$resql);
802 if (!$objp->fk_product > 0) {
805 $remaintodispatch =
price2num($objp->qty - ((
float) $products_dispatched[$objp->rowid]), 5);
806 if ($remaintodispatch < 0 && empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN)) {
807 $remaintodispatch = 0;
810 if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
819 print
'<!-- Line to dispatch '.$suffix.
' -->'.
"\n";
821 print
'<input id="qty_ordered'.$suffix.
'" type="hidden" value="'.$objp->qty.
'">';
822 print
'<input id="qty_dispatched'.$suffix.
'" type="hidden" value="'.(
float) $products_dispatched[$objp->rowid].
'">';
823 print
'<tr class="oddeven">';
825 if (empty($conf->cache[
'product'][$objp->fk_product])) {
826 $tmpproduct =
new Product($db);
827 $tmpproduct->fetch($objp->fk_product);
828 $conf->cache[
'product'][$objp->fk_product] = $tmpproduct;
830 $tmpproduct = $conf->cache[
'product'][$objp->fk_product];
833 $linktoprod = $tmpproduct->getNomUrl(1);
834 $linktoprod .=
' - '.$objp->label.
"\n";
836 if (!empty($conf->productbatch->enabled)) {
837 if ($objp->tobatch) {
842 print
'<td class="dispatch_batch_number"></td>';
843 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
844 print
'<td class="dispatch_dlc"></td>';
846 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
847 print
'<td class="dispatch_dluo"></td>';
854 print
'<td class="dispatch_batch_number">';
855 print $langs->trans(
"ProductDoesNotUseBatchSerial");
857 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
858 print
'<td class="dispatch_dlc"></td>';
860 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
861 print
'<td class="dispatch_dluo"></td>';
865 print
'<td colspan="4">';
871 $up_ht_disc = $objp->subprice;
872 if (!empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
873 $up_ht_disc =
price2num($up_ht_disc * (100 - $objp->remise_percent) / 100,
'MU');
877 print
'<td class="right">'.$objp->sref.
'</td>';
880 print
'<td class="right">'.$objp->qty.
'</td>';
883 print
'<td class="right">'.$products_dispatched[$objp->rowid].
'</td>';
885 if (!empty($conf->productbatch->enabled) && $objp->tobatch > 0) {
887 print
'<td class="right">';
896 'is_information_row' =>
true,
901 $reshook = $hookmanager->executeHooks(
902 'printFieldListValue',
910 print $hookmanager->resPrint;
914 print
'<tr class="oddeven" name="'.$type.$suffix.
'">';
916 print
'<input name="fk_commandefourndet'.$suffix.
'" type="hidden" value="'.$objp->rowid.
'">';
917 print
'<input name="product_batch'.$suffix.
'" type="hidden" value="'.$objp->fk_product.
'">';
919 print
'<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
920 if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) {
921 print $langs->trans(
"BuyingPrice").
': <input class="maxwidth75" name="pu'.$suffix.
'" type="text" value="'.
price2num($up_ht_disc,
'MU').
'">';
923 print
'<input class="maxwidth75" name="pu'.$suffix.
'" type="hidden" value="'.
price2num($up_ht_disc,
'MU').
'">';
929 print
'<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.
'" name="lot_number'.$suffix.
'" value="'.
GETPOST(
'lot_number'.$suffix).
'">';
931 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
932 print
'<td class="nowraponall">';
934 print
$form->selectDate($dlcdatesuffix,
'dlc'.$suffix,
'',
'', 1,
'');
937 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
938 print
'<td class="nowraponall">';
940 print
$form->selectDate($dluodatesuffix,
'dluo'.$suffix,
'',
'', 1,
'');
943 print
'<td colspan="3"> </td>';
947 $colspan = (!empty($conf->global->PRODUCT_DISABLE_SELLBY)) ? --$colspan : $colspan;
948 $colspan = (!empty($conf->global->PRODUCT_DISABLE_EATBY)) ? --$colspan : $colspan;
949 print
'<td class="right">';
958 'is_information_row' =>
true,
963 $reshook = $hookmanager->executeHooks(
964 'printFieldListValue',
972 print $hookmanager->resPrint;
976 print
'<tr class="oddeven" name="'.$type.$suffix.
'">';
977 print
'<td colspan="'.$colspan.
'">';
978 print
'<input name="fk_commandefourndet'.$suffix.
'" type="hidden" value="'.$objp->rowid.
'">';
979 print
'<input name="product'.$suffix.
'" type="hidden" value="'.$objp->fk_product.
'">';
981 print
'<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
982 if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) {
983 print $langs->trans(
"BuyingPrice").
': <input class="maxwidth75" name="pu'.$suffix.
'" type="text" value="'.
price2num($up_ht_disc,
'MU').
'">';
985 print
'<input class="maxwidth75" name="pu'.$suffix.
'" type="hidden" value="'.
price2num($up_ht_disc,
'MU').
'">';
992 print
'<td class="right">';
993 print
'<input id="qty'.$suffix.
'" name="qty'.$suffix.
'" type="text" class="width50 right" value="'.(
GETPOSTISSET(
'qty'.$suffix) ?
GETPOST(
'qty'.$suffix,
'int') : (empty($conf->global->SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO) ? $remaintodispatch : 0)).
'">';
997 if (!empty($conf->productbatch->enabled) && $objp->tobatch > 0) {
999 print
img_picto($langs->trans(
'AddStockLocationLine'),
'split.png',
'class="splitbutton" onClick="addDispatchLine('.$i.
', \''.$type.
'\')
"');
1002 print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton
" onClick="addDispatchLine(
'.$i.', \
''.$type.
'\')
"');
1006 if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
1007 if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
1009 print '<td class="right
">';
1010 print '<input id="pu
'.$suffix.'" name="pu
'.$suffix.'" type="text
" size="8
" value="'.price((GETPOST('pu
'.$suffix) != '' ? price2num(GETPOST('pu
'.$suffix)) : $up_ht_disc)).'">';
1014 print '<td class="right
">';
1015 print '<input id="dto
'.$suffix.'" name="dto
'.$suffix.'" type="text
" size="8
" value="'.(GETPOST('dto
'.$suffix) != '' ? GETPOST('dto
'.$suffix) : '').'">';
1019 print '<td class="center
">';
1020 print '<input class="flat checkformerge
" type="checkbox
" name="saveprice
'.$suffix.'" value="'.(GETPOST('saveprice
'.$suffix) != '' ? GETPOST('saveprice
'.$suffix) : '').'">';
1026 print '<td class="right
">';
1027 if (count($listwarehouses) > 1) {
1028 print $formproduct->selectWarehouses(GETPOST("entrepot
".$suffix) ?GETPOST("entrepot
".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot
".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix);
1029 } elseif (count($listwarehouses) == 1) {
1030 print $formproduct->selectWarehouses(GETPOST("entrepot
".$suffix) ?GETPOST("entrepot
".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot
".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix);
1032 $langs->load("errors
");
1033 print $langs->trans("ErrorNoWarehouseDefined
");
1037 // Enable hooks to append additional columns
1038 $parameters = array(
1039 'is_information_row' => false // this is a dispatch form row
1041 $reshook = $hookmanager->executeHooks(
1042 'printFieldListValue',
1048 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1050 print $hookmanager->resPrint;
1059 dol_print_error($db);
1066 $checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically
", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
1068 print '<div class="center
">';
1069 $parameters = array();
1070 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1072 if (empty($reshook)) {
1073 if (empty($conf->reception->enabled)) {
1074 print $langs->trans("Comment").' : ';
1075 print '<input type="text
" class="minwidth400
" maxlength="128
" name="comment
" value="';
1076 print GETPOSTISSET("comment") ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $object->ref);
1077 // print ' /
'.$object->ref_supplier; // Not yet available
1078 print '" class="flat
"><br>';
1080 print '<input type="checkbox
" checked="checked
" name="closeopenorder
"> '.$checkboxlabel;
1083 $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive
") : $langs->trans("CreateReception
");
1086 print '<input type="submit
" class="button
" name="dispatch
" value="'.dol_escape_htmltag($dispatchBt).'"';
1088 if (!$permissiontoreceive) {
1091 if (count($listwarehouses) <= 0) {
1103 // Message if nothing to dispatch
1106 if (empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
1107 print '<div class="opacitymedium
">'.$langs->trans("NoPredefinedProductToDispatch
").'</div>'; // No predefined line at all
1109 print '<div class="opacitymedium
">'.$langs->trans("NoMorePredefinedProductToDispatch
").'</div>'; // No predefined line that remain to be dispatched.
1116 print dol_get_fiche_end();
1118 // traitement entrepot par défaut
1119 print '<script type="text/javascript
">
1120 $(document).ready(function () {
1121 $("select[
name=fk_default_warehouse]
").change(function() {
1122 var fk_default_warehouse = $("option:selected
", this).val();
1123 $("select[
name^=entrepot_]
").val(fk_default_warehouse).change();
1126 jQuery("#autoreset
").click(function() {';
1128 while ($i < $nbproduct) {
1129 print ' jQuery("#qty_0_
'.$i.'").val("");';
1137 // List of lines already dispatched
1138 $sql = "SELECT p.rowid as pid, p.ref, p.label,
";
1139 $sql .= " e.rowid as warehouse_id, e.ref as entrepot,
";
1140 $sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec
";
1141 $sql .= " ,cd.rowid, cd.subprice
";
1142 if ($conf->reception->enabled) {
1143 $sql .= " ,cfd.fk_reception, r.date_delivery
";
1145 $sql .= " FROM
".MAIN_DB_PREFIX."product as p,
";
1146 $sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd
";
1147 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."commande_fournisseurdet as cd ON cd.rowid = cfd.fk_commandefourndet
";
1148 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid
";
1149 if ($conf->reception->enabled) {
1150 $sql .= " LEFT JOIN
".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid
";
1152 $sql .= " WHERE cfd.fk_commande =
".((int) $object->id);
1153 $sql .= " AND cfd.fk_product = p.rowid
";
1154 $sql .= " ORDER BY cfd.rowid ASC
";
1156 $resql = $db->query($sql);
1158 $num = $db->num_rows($resql);
1164 print load_fiche_titre($langs->trans("ReceivingForSameOrder
"));
1166 print '<div class="div-table-responsive
">';
1167 print '<table id="dispatch_received_products
" class="noborder centpercent
">';
1169 print '<tr class="liste_titre
">';
1171 if ($conf->reception->enabled) {
1172 print '<td>'.$langs->trans("Reception").'</td>';
1175 print '<td>'.$langs->trans("Product").'</td>';
1176 print '<td>'.$langs->trans("DateCreation
").'</td>';
1177 print '<td>'.$langs->trans("DateDeliveryPlanned
").'</td>';
1178 if (!empty($conf->productbatch->enabled)) {
1179 print '<td class="dispatch_batch_number_title
">'.$langs->trans("batch_number
").'</td>';
1180 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
1181 print '<td class="dispatch_dlc_title
">'.$langs->trans("SellByDate
").'</td>';
1183 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
1184 print '<td class="dispatch_dluo_title
">'.$langs->trans("EatByDate
").'</td>';
1187 print '<td class="right
">'.$langs->trans("QtyDispatched
").'</td>';
1188 print '<td>'.$langs->trans("Warehouse
").'</td>';
1189 print '<td>'.$langs->trans("Comment").'</td>';
1192 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && empty($reception->rowid)) {
1193 print '<td class="center
" colspan="2
">'.$langs->trans("Status").'</td>';
1194 } elseif (!empty($conf->reception->enabled)) {
1195 print '<td class="center
"></td>';
1198 print '<td class="center
" colspan="2
"></td>';
1204 $objp = $db->fetch_object($resql);
1206 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1207 print '<form name="editdispatchedlines
" id="editdispatchedlines
" action="'.$_SERVER["PHP_SELF"].'?
id=
'.$object->id.'#line_
'.GETPOST('lineid
', 'int').'" method="POST
">
1208 <input type="hidden
" name="token
" value="'.newToken().'">
1209 <input type="hidden
" name="action
" value="updateline
">
1210 <input type="hidden
" name="mode
" value="">
1211 <input type="hidden
" name="lineid
" value="'.$objp->dispatchlineid.'">';
1214 print '<tr class="oddeven
" id="line_
'.$objp->dispatchlineid.'" >';
1217 if (!empty($conf->reception->enabled)) {
1219 if (!empty($objp->fk_reception)) {
1220 $reception = new Reception($db);
1221 $reception->fetch($objp->fk_reception);
1222 print $reception->getNomUrl(1);
1230 if (empty($conf->cache['product'][$objp->fk_product])) {
1231 $tmpproduct = new Product($db);
1232 $tmpproduct->fetch($objp->fk_product);
1233 $conf->cache['product'][$objp->fk_product] = $tmpproduct;
1235 $tmpproduct = $conf->cache['product'][$objp->fk_product];
1237 print $tmpproduct->getNomUrl(1);
1238 print ' - '.$objp->label;
1240 print '<td>'.dol_print_date($db->jdate($objp->datec), 'day').'</td>';
1241 print '<td>'.dol_print_date($db->jdate($objp->date_delivery), 'day').'</td>';
1243 if (!empty($conf->productbatch->enabled)) {
1245 include_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
1246 $lot = new Productlot($db);
1247 $lot->fetch(0, $objp->pid, $objp->batch);
1248 print '<td class="dispatch_batch_number
">'.$lot->getNomUrl(1).'</td>';
1249 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
1250 print '<td class="dispatch_dlc
">'.dol_print_date($lot->sellby, 'day').'</td>';
1252 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
1253 print '<td class="dispatch_dluo
">'.dol_print_date($lot->eatby, 'day').'</td>';
1256 print '<td class="dispatch_batch_number
"></td>';
1257 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
1258 print '<td class="dispatch_dlc
"></td>';
1260 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
1261 print '<td class="dispatch_dluo
"></td>';
1267 print '<td class="right
">';
1268 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1269 print '<input style="width: 50px;
" type="text
" min="1
" name="qty
" value="'.$objp->qty.'" />';
1273 print '<input type="hidden
" name="price" value="'.$objp->subprice.'" />';
1278 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1279 if (count($listwarehouses) > 1) {
1280 print $formproduct->selectWarehouses(GETPOST("fk_entrepot
") ?GETPOST("fk_entrepot
") : ($objp->warehouse_id ? $objp->warehouse_id : ''), "fk_entrepot
", '', 1, 0, $objp->fk_product, '', 1, 1, null, 'csswarehouse');
1281 } elseif (count($listwarehouses) == 1) {
1282 print $formproduct->selectWarehouses(GETPOST("fk_entrepot
") ?GETPOST("fk_entrepot
") : ($objp->warehouse_id ? $objp->warehouse_id : ''), "fk_entrepot
", '', 0, 0, $objp->fk_product, '', 1, 1, null, 'csswarehouse');
1284 $langs->load("errors
");
1285 print $langs->trans("ErrorNoWarehouseDefined
");
1288 $warehouse_static->id = $objp->warehouse_id;
1289 $warehouse_static->label = $objp->entrepot;
1290 print $warehouse_static->getNomUrl(1);
1295 print '<td class="tdoverflowmax300
" style="white-space: pre;
">'.$objp->comment.'</td>';
1298 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && empty($reception->rowid)) {
1299 print '<td class="right
">';
1300 $supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status);
1301 // print $supplierorderdispatch->status;
1302 print $supplierorderdispatch->getLibStatut(5);
1305 // Add button to check/uncheck disaptching
1306 print '<td class="center
">';
1307 if (!$permissiontocontrol) {
1308 if (empty($objp->status)) {
1309 print '<a class="button buttonRefused
" href="#
">'.$langs->trans("Approve
").'</a>';
1310 print '<a class="button buttonRefused
" href="#
">'.$langs->trans("Deny
").'</a>';
1312 print '<a class="button buttonRefused
" href="#
">'.$langs->trans("Disapprove
").'</a>';
1313 print '<a class="button buttonRefused
" href="#
">'.$langs->trans("Deny
").'</a>';
1317 if ($object->statut == 5) {
1320 if (empty($objp->status)) {
1321 print '<a class="button
'.($disabled ? ' buttonRefused
' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=checkdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Approve
").'</a>';
1322 print '<a class="button
'.($disabled ? ' buttonRefused
' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=denydispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Deny
").'</a>';
1324 if ($objp->status == 1) {
1325 print '<a class="button
'.($disabled ? ' buttonRefused
' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Reinit
").'</a>';
1326 print '<a class="button
'.($disabled ? ' buttonRefused
' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=denydispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Deny
").'</a>';
1328 if ($objp->status == 2) {
1329 print '<a class="button
'.($disabled ? ' buttonRefused
' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Reinit
").'</a>';
1330 print '<a class="button
'.($disabled ? ' buttonRefused
' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=checkdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Approve
").'</a>';
1334 } elseif (!empty($conf->reception->enabled)) {
1335 print '<td class="right
">';
1336 if (!empty($reception->id)) {
1337 print $reception->getLibStatut(5);
1341 if ($action != 'editline' || $lineid != $objp->dispatchlineid) {
1342 if (empty($reception->id) || ($reception->statut == Reception::STATUS_DRAFT)) { // only allow edit on draft reception
1343 print '<td class="linecoledit center
">';
1344 print '<a class="reposition
" href="'.$_SERVER["PHP_SELF"].'?
id=
'.$object->id.'&action=editline&token=
'.newToken().'&lineid=
'.$objp->dispatchlineid.'#line_
'.$objp->dispatchlineid.'">';
1349 print '<td class="linecoldelete center
">';
1350 print '<a href="'.$_SERVER["PHP_SELF"].'?
id=
'.$object->id.'&action=ask_deleteline&token=
'.newToken().'&lineid=
'.$objp->dispatchlineid.'#dispatch_received_products
">';
1355 print '<td></td><td></td>';
1358 print '<td class="center valignmiddle
">';
1359 print '<input type="submit
" class="button button-save
" id="savelinebutton
" name="save
" value="'.$langs->trans("Save").'" />';
1361 print '<td class="center valignmiddle
">';
1362 print '<input type="submit
" class="button button-cancel
" id="cancellinebutton
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1368 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1380 dol_print_error($db);