35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
37require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
45if (isModEnabled(
'project')) {
46 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
50$langs->loadLangs(array(
"bills",
"orders",
"sendings",
"companies",
"deliveries",
"products",
"stocks",
"receptions"));
52if (isModEnabled(
'productbatch')) {
53 $langs->load(
'productbatch');
60$action =
GETPOST(
'action',
'aZ09');
61$fk_default_warehouse =
GETPOSTINT(
'fk_default_warehouse');
62$cancel =
GETPOST(
'cancel',
'alpha');
63$confirm =
GETPOST(
'confirm',
'alpha');
66 $socid = $user->socid;
69$hookmanager->initHooks(array(
'ordersupplierdispatch'));
73if (GETPOSTISSET(
"projectid")) {
79if ($id > 0 || !empty($ref)) {
80 $result =
$object->fetch($id, $ref);
84 $result =
$object->fetch_thirdparty();
90if (empty($conf->reception->enabled)) {
91 $permissiontoreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
92 $permissiontocontrol = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"commande",
"receptionner")) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"commande_advance",
"check")));
94 $permissiontoreceive = $user->hasRight(
"reception",
"creer");
95 $permissiontocontrol = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"reception",
"creer")) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"reception",
"reception_advance",
"validate")));
99$result =
restrictedArea($user,
'fournisseur', $object,
'commande_fournisseur',
'commande');
101if (!isModEnabled(
'stock')) {
105$usercancreate = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
106$permissiontoadd = $usercancreate;
113$parameters = array();
114$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
119if ($action ==
'checkdispatchline' && $permissiontocontrol) {
125 $result = $supplierorderdispatch->fetch($lineid);
128 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
133 $result = $supplierorderdispatch->setStatut(1);
135 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
142 $result =
$object->calcAndSetStatusDispatch($user);
156if ($action ==
'uncheckdispatchline' && $permissiontocontrol) {
162 $result = $supplierorderdispatch->fetch($lineid);
165 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
170 $result = $supplierorderdispatch->setStatut(0);
172 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
178 $result =
$object->calcAndSetStatusDispatch($user);
192if ($action ==
'denydispatchline' && $permissiontocontrol) {
198 $result = $supplierorderdispatch->fetch($lineid);
201 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
206 $result = $supplierorderdispatch->setStatut(2);
208 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors,
'errors');
214 $result =
$object->calcAndSetStatusDispatch($user);
228if ($action ==
'dispatch' && $permissiontoreceive) {
235 foreach ($_POST as $key => $value) {
238 if (preg_match(
'/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
243 $prod =
"product_".$reg[1].
'_'.$reg[2];
244 $qty =
"qty_".$reg[1].
'_'.$reg[2];
245 $ent =
"entrepot_".$reg[1].
'_'.$reg[2];
247 $ent = $fk_default_warehouse;
249 $pu =
"pu_".$reg[1].
'_'.$reg[2];
250 $fk_commandefourndet =
"fk_commandefourndet_".$reg[1].
'_'.$reg[2];
253 if (!isModEnabled(
"multicurrency") && empty($conf->dynamicprices->enabled)) {
254 $dto =
GETPOSTINT(
"dto_".$reg[1].
'_'.$reg[2]);
258 $saveprice =
"saveprice_".$reg[1].
'_'.$reg[2];
265 if ($qtytomove != 0) {
267 dol_syslog(
'No dispatch for line '.$key.
' as no warehouse was chosen.');
268 $text = $langs->transnoentities(
'Warehouse').
', '.$langs->transnoentities(
'Line').
' '.($numline);
269 setEventMessages($langs->trans(
'ErrorFieldRequired', $text),
null,
'errors');
274 $result =
$object->dispatchProduct($user,
GETPOSTINT($prod), $qtytomove,
GETPOSTINT($ent), $puformove,
GETPOST(
'comment'),
'',
'',
'',
GETPOSTINT($fk_commandefourndet), $notrigger);
280 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
281 if (!isModEnabled(
"multicurrency") && empty($conf->dynamicprices->enabled)) {
288 if (GETPOSTISSET($saveprice)) {
290 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_fournisseur_price";
291 $sql .=
" SET unitprice='".price2num(
GETPOST($pu),
'MU').
"'";
292 $sql .=
", price=".price2num(
GETPOST($pu),
'MU').
"*quantity";
293 $sql .=
", remise_percent = ".((float) $dto);
294 $sql .=
" WHERE fk_soc=".((int)
$object->socid);
295 $sql .=
" AND fk_product=".(GETPOSTINT($prod));
297 $resql = $db->query($sql);
305 if (preg_match(
'/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
311 $prod =
'product_batch_'.$reg[1].
'_'.$reg[2];
312 $qty =
'qty_'.$reg[1].
'_'.$reg[2];
313 $ent =
'entrepot_'.$reg[1].
'_'.$reg[2];
314 $pu =
'pu_'.$reg[1].
'_'.$reg[2];
315 $fk_commandefourndet =
'fk_commandefourndet_'.$reg[1].
'_'.$reg[2];
316 $lot =
'lot_number_'.$reg[1].
'_'.$reg[2];
320 $fk_commandefourndet =
'fk_commandefourndet_'.$reg[1].
'_'.$reg[2];
323 if (!isModEnabled(
"multicurrency") && empty($conf->dynamicprices->enabled)) {
324 $dto =
GETPOSTINT(
"dto_".$reg[1].
'_'.$reg[2]);
328 $saveprice =
"saveprice_".$reg[1].
'_'.$reg[2];
335 if ($qtytomove > 0) {
339 dol_syslog(
'No dispatch for line '.$key.
' as no warehouse was chosen.');
340 $text = $langs->transnoentities(
'Warehouse').
', '.$langs->transnoentities(
'Line').
' '.($numline).
'-'.((
int) $reg[1] + 1);
341 setEventMessages($langs->trans(
'ErrorFieldRequired', $text),
null,
'errors');
354 if (!
GETPOST($lot,
'alpha') && !$dDLUO && !$dDLC) {
355 dol_syslog(
'No dispatch for line '.$key.
' as serial/eat-by/sellby date are not set');
356 $text = $langs->transnoentities(
'atleast1batchfield').
', '.$langs->transnoentities(
'Line').
' '.($numline).
'-'.((
int) $reg[1] + 1);
357 setEventMessages($langs->trans(
'ErrorFieldRequired', $text),
null,
'errors');
362 $result =
$object->dispatchProduct($user, $productId, $qtytomove,
GETPOSTINT($ent), $puformove,
GETPOST(
'comment'), $dDLUO, $dDLC,
GETPOST($lot,
'alpha'),
GETPOSTINT($fk_commandefourndet), $notrigger);
368 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
369 if (!isModEnabled(
"multicurrency") && empty($conf->dynamicprices->enabled)) {
370 $dto =
GETPOSTINT(
"dto_".$reg[1].
'_'.$reg[2]);
372 if (GETPOSTISSET($saveprice)) {
374 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_fournisseur_price";
375 $sql .=
" SET unitprice = ".price2num(
GETPOST($pu),
'MU', 2);
376 $sql .=
", price = ".price2num(
GETPOST($pu),
'MU', 2).
" * quantity";
377 $sql .=
", remise_percent = ".price2num((empty($dto) ? 0 : $dto), 3, 2).
"'";
378 $sql .=
" WHERE fk_soc = ".((int)
$object->socid);
379 $sql .=
" AND fk_product=".((int) $productId);
381 $resql = $db->query($sql);
391 $result =
$object->calcAndSetStatusDispatch($user,
GETPOST(
'closeopenorder') ? 1 : 0,
GETPOST(
'comment'));
398 if ($result >= 0 && !$error) {
403 header(
"Location: dispatch.php?id=".$id);
411if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $permissiontoreceive) {
415 $result = $supplierorderdispatch->fetch($lineid);
417 $qty = $supplierorderdispatch->qty;
418 $entrepot = $supplierorderdispatch->fk_entrepot;
419 $product = $supplierorderdispatch->fk_product;
421 $comment = $supplierorderdispatch->comment;
422 $eatby = $supplierorderdispatch->eatby;
423 $sellby = $supplierorderdispatch->sellby;
424 $batch = $supplierorderdispatch->batch;
426 $result = $supplierorderdispatch->delete($user);
433 if ($entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') && empty($supplierorderdispatch->fk_reception)) {
438 $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment,
'', $eatby, $sellby, $batch);
440 $errors = $mouv->errors;
455if ($action ==
'updateline' && $permissiontoreceive && empty($cancel)) {
460 $result = $supplierorderdispatch->fetch($lineid);
462 $qty = $supplierorderdispatch->qty;
463 $entrepot = $supplierorderdispatch->fk_entrepot;
464 $product = $supplierorderdispatch->fk_product;
466 $comment = $supplierorderdispatch->comment;
467 $eatby = $supplierorderdispatch->eatby;
468 $sellby = $supplierorderdispatch->sellby;
469 $batch = $supplierorderdispatch->batch;
471 $supplierorderdispatch->qty =
GETPOSTFLOAT(
'qty',
'MS');
472 $supplierorderdispatch->fk_entrepot =
GETPOSTINT(
'fk_entrepot');
473 $result = $supplierorderdispatch->update($user);
477 $errors = $supplierorderdispatch->errors;
480 if ($entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
485 $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment,
'', $eatby, $sellby, $batch);
487 $errors = $mouv->errors;
491 $result = $mouv->reception($user, $product, $supplierorderdispatch->fk_entrepot, $supplierorderdispatch->qty, $price, $comment, $eatby, $sellby, $batch);
493 $errors = $mouv->errors;
515$form =
new Form($db);
517$warehouse_static =
new Entrepot($db);
520$title =
$object->ref.
" - ".$langs->trans(
'OrderDispatch');
521$help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
522$morejs = array(
'/fourn/js/lib_dispatch.js.php');
524llxHeader(
'', $title, $help_url,
'', 0, 0, $morejs,
'',
'',
'mod-supplier-order page-card_dispatch');
526if ($id > 0 || !empty($ref)) {
530 $author =
new User($db);
531 $author->fetch(
$object->user_author_id);
535 $title = $langs->trans(
"SupplierOrder");
541 if ($action ==
'ask_deleteline') {
542 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
546 $parameters = array(
'lineid' => $lineid);
548 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
549 if (empty($reshook)) {
550 $formconfirm .= $hookmanager->resPrint;
551 } elseif ($reshook > 0) {
552 $formconfirm = $hookmanager->resPrint;
560 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php'.(!empty($socid) ?
'?socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
562 $morehtmlref =
'<div class="refidno">';
564 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier, $object, 0,
'string',
'', 0, 1);
565 $morehtmlref .= $form->editfieldval(
"RefSupplier",
'ref_supplier',
$object->ref_supplier, $object, 0,
'string',
'',
null,
null,
'', 1);
567 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1);
569 if (isModEnabled(
'project')) {
570 $langs->load(
"projects");
571 $morehtmlref .=
'<br>';
573 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
574 if ($action !=
'classify' && $caneditproject) {
575 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
577 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ?
$object->socid : -1),
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
579 if (!empty(
$object->fk_project)) {
581 $proj->fetch(
$object->fk_project);
582 $morehtmlref .= $proj->getNomUrl(1);
584 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
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>';
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>';
646 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
648 $formproduct->loadWarehouses();
650 $listwarehouses = $entrepot->list_array(1);
653 if (empty($conf->reception->enabled)) {
654 print
'<form method="POST" action="dispatch.php?id='.$object->id.
'">';
656 print
'<form method="post" action="'.dol_buildpath(
'/reception/card.php', 1).
'?originid='.
$object->id.
'&origin=supplierorder">';
659 print
'<input type="hidden" name="token" value="'.newToken().
'">';
660 if (empty($conf->reception->enabled)) {
661 print
'<input type="hidden" name="action" value="dispatch">';
663 print
'<input type="hidden" name="action" value="create">';
666 print
'<div class="div-table-responsive-no-min">';
667 print
'<table class="noborder centpercent">';
670 $products_dispatched = array();
671 $sql =
"SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
672 $sql .=
" FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as cfd";
673 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l on l.rowid = cfd.fk_elementdet";
674 $sql .=
" WHERE cfd.fk_element = ".((int)
$object->id);
675 $sql .=
" GROUP BY l.rowid, cfd.fk_product";
677 $resql = $db->query($sql);
679 $num = $db->num_rows($resql);
684 $objd = $db->fetch_object($resql);
685 $products_dispatched[$objd->rowid] =
price2num($objd->qty,
'MS');
693 $sql =
"SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, l.qty as qty,";
694 $sql .=
" p.ref, p.label, p.tobatch, p.fk_default_warehouse";
697 $parameters = array();
698 $reshook = $hookmanager->executeHooks(
699 'printFieldListSelect',
707 $sql .= $hookmanager->resPrint;
709 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l";
710 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product=p.rowid";
711 $sql .=
" WHERE l.fk_commande = ".((int)
$object->id);
713 $sql .=
" AND l.product_type = 0";
717 $parameters = array();
718 $reshook = $hookmanager->executeHooks(
719 'printFieldListWhere',
727 $sql .= $hookmanager->resPrint;
730 $sql .=
" ORDER BY l.rang, p.ref, p.label";
732 $resql = $db->query($sql);
734 $num = $db->num_rows($resql);
738 print
'<tr class="liste_titre">';
740 print
'<td>'.$langs->trans(
"Description").
'</td>';
741 if (isModEnabled(
'productbatch')) {
742 print
'<td class="dispatch_batch_number_title">'.$langs->trans(
"batch_number").
'</td>';
744 print
'<td class="dispatch_dlc_title">'.$langs->trans(
"SellByDate").
'</td>';
747 print
'<td class="dispatch_dluo_title">'.$langs->trans(
"EatByDate").
'</td>';
754 print
'<td class="right">'.$langs->trans(
"SupplierRef").
'</td>';
755 print
'<td class="right">'.$langs->trans(
"QtyOrdered").
'</td>';
756 print
'<td class="right">'.$langs->trans(
"QtyDispatchedShort").
'</td>';
757 print
' <td class="right">'.$langs->trans(
"QtyToDispatchShort");
758 print
'<br><a href="#" id="autoreset">'.img_picto($langs->trans(
"Reset"),
'eraser',
'class="pictofixedwidth opacitymedium"').$langs->trans(
"Reset").
'</a></td>';
759 print
'<td width="32"></td>';
762 if (!isModEnabled(
"multicurrency") && empty($conf->dynamicprices->enabled)) {
763 print
'<td class="right">'.$langs->trans(
"Price").
'</td>';
764 print
'<td class="right">'.$langs->trans(
"ReductionShort").
' (%)</td>';
765 print
'<td class="right">'.$langs->trans(
"UpdatePrice").
'</td>';
769 print
'<td align="right">'.$langs->trans(
"Warehouse");
772 if (count($listwarehouses) > 1) {
773 print
'<br>'.$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, $langs->trans(
"ForceTo"), 0, 0,
'', 0, 0, $disabled,
'',
'minwidth100 maxwidth300', 1);
774 } elseif (count($listwarehouses) == 1) {
775 print
'<br>'.$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0,
'', 0, 0, $disabled,
'',
'minwidth100 maxwidth300', 1);
781 $parameters = array();
782 $reshook = $hookmanager->executeHooks(
783 'printFieldListTitle',
791 print $hookmanager->resPrint;
800 $conf->cache[
'product'] = array();
804 $objp = $db->fetch_object($resql);
807 if (!$objp->fk_product > 0) {
810 $alreadydispatched = isset($products_dispatched[$objp->rowid]) ? $products_dispatched[$objp->rowid] : 0;
811 $remaintodispatch =
price2num($objp->qty - ((
float) $alreadydispatched), 5);
812 if ($remaintodispatch < 0 && !
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN')) {
813 $remaintodispatch = 0;
816 if ($remaintodispatch || !
getDolGlobalString(
'SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED')) {
825 print
'<!-- Line to dispatch '.$suffix.
' -->'.
"\n";
827 print
'<input id="qty_ordered'.$suffix.
'" type="hidden" value="'.$objp->qty.
'">';
828 print
'<input id="qty_dispatched'.$suffix.
'" type="hidden" value="'.(float) $alreadydispatched.
'">';
829 print
'<tr class="oddeven">';
831 if (empty($conf->cache[
'product'][$objp->fk_product])) {
832 $tmpproduct =
new Product($db);
833 $tmpproduct->fetch($objp->fk_product);
834 $conf->cache[
'product'][$objp->fk_product] = $tmpproduct;
836 $tmpproduct = $conf->cache[
'product'][$objp->fk_product];
839 $linktoprod = $tmpproduct->getNomUrl(1);
840 $linktoprod .=
' - '.$objp->label.
"\n";
842 if (isModEnabled(
'productbatch')) {
843 if ($objp->tobatch) {
848 print
'<td class="dispatch_batch_number"></td>';
850 print
'<td class="dispatch_dlc"></td>';
853 print
'<td class="dispatch_dluo"></td>';
860 print
'<td class="dispatch_batch_number">';
861 print
'<span class="opacitymedium small">'.$langs->trans(
"ProductDoesNotUseBatchSerial").
'</small>';
864 print
'<td class="dispatch_dlc"></td>';
867 print
'<td class="dispatch_dluo"></td>';
871 print
'<td colspan="4">';
877 $up_ht_disc = $objp->subprice;
878 if (!empty($objp->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
879 $up_ht_disc =
price2num($up_ht_disc * (100 - $objp->remise_percent) / 100,
'MU');
883 print
'<td class="right">'.$objp->sref.
'</td>';
886 print
'<td class="right">'.$objp->qty.
'</td>';
889 print
'<td class="right">'.$alreadydispatched.
'</td>';
891 if (isModEnabled(
'productbatch') && $objp->tobatch > 0) {
893 print
'<td class="right">';
903 'is_information_row' =>
true,
908 $reshook = $hookmanager->executeHooks(
909 'printFieldListValue',
917 print $hookmanager->resPrint;
921 print
'<tr class="oddeven" name="'.$type.$suffix.
'">';
923 print
'<input name="fk_commandefourndet'.$suffix.
'" type="hidden" value="'.$objp->rowid.
'">';
924 print
'<input name="product_batch'.$suffix.
'" type="hidden" value="'.$objp->fk_product.
'">';
926 print
'<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
928 print $langs->trans(
"BuyingPrice").
': <input class="maxwidth75" name="pu'.$suffix.
'" type="text" value="'.
price2num($up_ht_disc,
'MU').
'">';
930 print
'<input class="maxwidth75" name="pu'.$suffix.
'" type="hidden" value="'.
price2num($up_ht_disc,
'MU').
'">';
936 print
'<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.
'" name="lot_number'.$suffix.
'" value="'.
GETPOST(
'lot_number'.$suffix).
'">';
939 print
'<td class="nowraponall">';
941 print $form->selectDate($dlcdatesuffix,
'dlc'.$suffix, 0, 0, 1,
'');
945 print
'<td class="nowraponall">';
947 print $form->selectDate($dluodatesuffix,
'dluo'.$suffix, 0, 0, 1,
'');
950 print
'<td colspan="3"> </td>';
956 print
'<td class="right">';
966 'is_information_row' =>
true,
971 $reshook = $hookmanager->executeHooks(
972 'printFieldListValue',
980 print $hookmanager->resPrint;
984 print
'<tr class="oddeven" name="'.$type.$suffix.
'">';
985 print
'<td colspan="'.$colspan.
'">';
986 print
'<input name="fk_commandefourndet'.$suffix.
'" type="hidden" value="'.$objp->rowid.
'">';
987 print
'<input name="product'.$suffix.
'" type="hidden" value="'.$objp->fk_product.
'">';
989 print
'<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
991 print $langs->trans(
"BuyingPrice").
': <input class="maxwidth75" name="pu'.$suffix.
'" type="text" value="'.
price2num($up_ht_disc,
'MU').
'">';
993 print
'<input class="maxwidth75" name="pu'.$suffix.
'" type="hidden" value="'.
price2num($up_ht_disc,
'MU').
'">';
1000 print
'<td class="right">';
1001 print
'<a href="#" id="reset'.$suffix.
'" class="resetline">'.
img_picto($langs->trans(
"Reset"),
'eraser',
'class="pictofixedwidth opacitymedium"').
'</a>';
1002 print
'<input id="qty'.$suffix.
'" name="qty'.$suffix.
'" type="text" class="width50 right qtydispatchinput" value="'.(GETPOSTISSET(
'qty'.$suffix) ?
GETPOSTINT(
'qty'.$suffix) : (!
getDolGlobalString(
'SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO') ? $remaintodispatch : 0)).
'">';
1006 if (isModEnabled(
'productbatch') && $objp->tobatch > 0) {
1008 print
img_picto($langs->trans(
'AddStockLocationLine'),
'split.png',
'class="splitbutton" onClick="addDispatchLine('.$i.
', \''.$type.
'\')
"');
1011 print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton
" onClick="addDispatchLine(
'.$i.', \
''.$type.
'\')
"');
1015 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
1016 if (!isModEnabled("multicurrency
") && empty($conf->dynamicprices->enabled)) {
1018 print '<td class="right
">';
1019 print '<input id="pu
'.$suffix.'" name="pu
'.$suffix.'" type="text
" size="8
" value="'.price((GETPOST('pu
'.$suffix) != '' ? price2num(GETPOST('pu
'.$suffix)) : $up_ht_disc)).'">';
1023 print '<td class="right
">';
1024 print '<input id="dto
'.$suffix.'" name="dto
'.$suffix.'" type="text
" size="8
" value="'.(GETPOST('dto
'.$suffix) != '' ? GETPOST('dto
'.$suffix) : '').'">';
1028 print '<td class="center
">';
1029 print '<input class="flat checkformerge
" type="checkbox
" name="saveprice
'.$suffix.'" value="'.(GETPOST('saveprice
'.$suffix) != '' ? GETPOST('saveprice
'.$suffix) : '').'">';
1035 print '<td class="right
">';
1036 if (count($listwarehouses) > 1) {
1037 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);
1038 } elseif (count($listwarehouses) == 1) {
1039 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);
1041 $langs->load("errors
");
1042 print $langs->trans("ErrorNoWarehouseDefined
");
1046 // Enable hooks to append additional columns
1047 $parameters = array(
1048 'is_information_row' => false, // this is a dispatch form row
1050 'suffix' => $suffix,
1053 $reshook = $hookmanager->executeHooks(
1054 'printFieldListValue',
1060 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1062 print $hookmanager->resPrint;
1071 dol_print_error($db);
1078 $checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically
", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
1080 print '<div class="center
">';
1081 $parameters = array();
1082 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1084 if (empty($reshook)) {
1085 if (empty($conf->reception->enabled)) {
1086 print $langs->trans("Comment").' : ';
1087 print '<input type="text
" class="minwidth400
" maxlength="128
" name="comment
" value="';
1088 print GETPOSTISSET("comment") ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $object->ref);
1089 // print ' /
'.$object->ref_supplier; // Not yet available
1090 print '" class="flat
"><br>';
1092 print '<input type="checkbox
" checked="checked
" name="closeopenorder
"> '.$checkboxlabel;
1095 $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive
") : $langs->trans("CreateReception
");
1098 print '<input type="hidden
" name="backtopageforcancel
" value="'.$_SERVER["PHP_SELF"].'?
id=
'.$object->id.'">';
1099 print '<input type="submit
" class="button" name="dispatch
" value="'.dol_escape_htmltag($dispatchBt).'"';
1101 if (!$permissiontoreceive) {
1104 if (count($listwarehouses) <= 0) {
1116 // Message if nothing to dispatch
1119 if (!getDolGlobalString('SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED')) {
1120 print '<div class="opacitymedium
">'.$langs->trans("NoPredefinedProductToDispatch
").'</div>'; // No predefined line at all
1122 print '<div class="opacitymedium
">'.$langs->trans("NoMorePredefinedProductToDispatch
").'</div>'; // No predefined line that remain to be dispatched.
1129 print dol_get_fiche_end();
1131 // traitement entrepot par défaut
1132 print '<script type="text/javascript
">
1133 $(document).ready(function () {
1134 $("select[
name=fk_default_warehouse]
").change(function() {
1135 var fk_default_warehouse = $("option:selected
", this).val();
1136 $("select[
name^=entrepot_]
").val(fk_default_warehouse).change();
1139 $("#autoreset
").click(function() {
1140 $(".qtydispatchinput
").each(function(){
1141 id = $(this).attr("id");
1142 idtab = id.split("_
");
1146 $("#qty_dispatched_0_
"+idtab[2]).val("0
");
1148 obj = $(this).parent().parent();
1149 nameobj = obj.attr("name");
1150 nametab = nameobj.split("_
");
1152 $("tr[
name^=\
'"+nametab[0]+"_\'][name$=\'_"+nametab[2]+"\']:last .splitbutton").show();
1157 $(".resetline").click(function(){
1158 id = $(this).attr("id");
1159 id = id.split("reset_");
1160 console.log("Reset trigger for id = qty_"+id[1]);
1161 $("#qty_"+id[1]).val("");
1167 $sql =
"SELECT p.rowid as pid, p.ref, p.label,";
1168 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
1169 $sql .=
" cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec";
1170 $sql .=
" ,cd.rowid, cd.subprice";
1171 if (isModEnabled(
'reception')) {
1172 $sql .=
" ,cfd.fk_reception, r.date_delivery";
1174 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p,";
1175 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as cfd";
1176 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd ON cd.rowid = cfd.fk_elementdet";
1177 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"entrepot as e ON cfd.fk_entrepot = e.rowid";
1178 if (isModEnabled(
'reception')) {
1179 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"reception as r ON cfd.fk_reception = r.rowid";
1181 $sql .=
" WHERE cfd.fk_element = ".((int)
$object->id);
1182 $sql .=
" AND cfd.fk_product = p.rowid";
1183 $sql .=
" ORDER BY cfd.rowid ASC";
1185 $resql = $db->query($sql);
1187 $num = $db->num_rows($resql);
1195 print
'<div class="div-table-responsive">';
1196 print
'<table id="dispatch_received_products" class="noborder centpercent">';
1198 print
'<tr class="liste_titre">';
1200 if ($conf->reception->enabled) {
1201 print
'<td>'.$langs->trans(
"Reception").
'</td>';
1204 print
'<td>'.$langs->trans(
"Product").
'</td>';
1205 print
'<td class="center">'.$langs->trans(
"DateCreation").
'</td>';
1206 print
'<td class="center">'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1207 if (isModEnabled(
'productbatch')) {
1208 print
'<td class="dispatch_batch_number_title">'.$langs->trans(
"batch_number").
'</td>';
1210 print
'<td class="dispatch_dlc_title">'.$langs->trans(
"SellByDate").
'</td>';
1213 print
'<td class="dispatch_dluo_title">'.$langs->trans(
"EatByDate").
'</td>';
1216 print
'<td class="right">'.$langs->trans(
"QtyDispatched").
'</td>';
1217 print
'<td>'.$langs->trans(
"Warehouse").
'</td>';
1218 print
'<td>'.$langs->trans(
"Comment").
'</td>';
1221 if (
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS') && empty($reception->rowid)) {
1222 print
'<td class="center" colspan="2">'.$langs->trans(
"Status").
'</td>';
1223 } elseif (isModEnabled(
"reception")) {
1224 print
'<td class="center"></td>';
1227 print
'<td class="center" colspan="2"></td>';
1233 $objp = $db->fetch_object($resql);
1235 if ($action ==
'editline' && $lineid == $objp->dispatchlineid) {
1236 print
'<form name="editdispatchedlines" id="editdispatchedlines" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'#line_'.
GETPOSTINT(
'lineid').
'" method="POST">
1237 <input type="hidden" name="token" value="'.
newToken().
'">
1238 <input type="hidden" name="action" value="updateline">
1239 <input type="hidden" name="mode" value="">
1240 <input type="hidden" name="lineid" value="'.$objp->dispatchlineid.
'">';
1243 print
'<tr class="oddeven" id="line_'.$objp->dispatchlineid.
'" >';
1246 if (isModEnabled(
"reception")) {
1247 print
'<td class="nowraponall">';
1248 if (!empty($objp->fk_reception)) {
1250 $reception->fetch($objp->fk_reception);
1251 print $reception->getNomUrl(1);
1258 print
'<td class="tdoverflowmax150">';
1259 if (empty($conf->cache[
'product'][$objp->fk_product])) {
1260 $tmpproduct =
new Product($db);
1261 $tmpproduct->fetch($objp->fk_product);
1262 $conf->cache[
'product'][$objp->fk_product] = $tmpproduct;
1264 $tmpproduct = $conf->cache[
'product'][$objp->fk_product];
1266 print $tmpproduct->getNomUrl(1);
1267 print
' - '.$objp->label;
1271 print
'<td class="center">'.dol_print_date($db->jdate($objp->datec),
'day').
'</td>';
1274 print
'<td class="center">'.dol_print_date($db->jdate($objp->date_delivery),
'day').
'</td>';
1277 if (isModEnabled(
'productbatch')) {
1279 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
1281 $lot->fetch(0, $objp->pid, $objp->batch);
1282 print
'<td class="dispatch_batch_number">'.$lot->getNomUrl(1).
'</td>';
1284 print
'<td class="dispatch_dlc">'.dol_print_date($lot->sellby,
'day').
'</td>';
1287 print
'<td class="dispatch_dluo">'.dol_print_date($lot->eatby,
'day').
'</td>';
1290 print
'<td class="dispatch_batch_number"></td>';
1292 print
'<td class="dispatch_dlc"></td>';
1295 print
'<td class="dispatch_dluo"></td>';
1301 print
'<td class="right">';
1302 if ($action ==
'editline' && $lineid == $objp->dispatchlineid) {
1303 print
'<input style="width: 50px;" type="text" min="1" name="qty" value="'.$objp->qty.
'" />';
1307 print
'<input type="hidden" name="price" value="'.$objp->subprice.
'" />';
1311 print
'<td class="tdoverflowmax150">';
1312 if ($action ==
'editline' && $lineid == $objp->dispatchlineid) {
1313 if (count($listwarehouses) > 1) {
1314 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');
1315 } elseif (count($listwarehouses) == 1) {
1316 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');
1318 $langs->load(
"errors");
1319 print $langs->trans(
"ErrorNoWarehouseDefined");
1322 $warehouse_static->id = $objp->warehouse_id;
1323 $warehouse_static->label = $objp->entrepot;
1324 print $warehouse_static->getNomUrl(1);
1329 print
'<td class="tdoverflowmax300" style="white-space: pre;">'.$objp->comment.
'</td>';
1332 if (
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS') && empty($reception->rowid)) {
1333 print
'<td class="right">';
1334 $supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status);
1336 print $supplierorderdispatch->getLibStatut(5);
1340 print
'<td class="center">';
1341 if (!$permissiontocontrol) {
1342 if (empty($objp->status)) {
1343 print
'<a class="button buttonRefused" href="#">'.$langs->trans(
"Approve").
'</a>';
1344 print
'<a class="button buttonRefused" href="#">'.$langs->trans(
"Deny").
'</a>';
1346 print
'<a class="button buttonRefused" href="#">'.$langs->trans(
"Disapprove").
'</a>';
1347 print
'<a class="button buttonRefused" href="#">'.$langs->trans(
"Deny").
'</a>';
1354 if (empty($objp->status)) {
1355 print
'<a class="button'.($disabled ?
' buttonRefused' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
"?id=".$id.
"&action=checkdispatchline&lineid=".$objp->dispatchlineid.
'">'.$langs->trans(
"Approve").
'</a>';
1356 print
'<a class="button'.($disabled ?
' buttonRefused' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
"?id=".$id.
"&action=denydispatchline&lineid=".$objp->dispatchlineid.
'">'.$langs->trans(
"Deny").
'</a>';
1358 if ($objp->status == 1) {
1359 print
'<a class="button'.($disabled ?
' buttonRefused' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
"?id=".$id.
"&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.
'">'.$langs->trans(
"Reinit").
'</a>';
1360 print
'<a class="button'.($disabled ?
' buttonRefused' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
"?id=".$id.
"&action=denydispatchline&lineid=".$objp->dispatchlineid.
'">'.$langs->trans(
"Deny").
'</a>';
1362 if ($objp->status == 2) {
1363 print
'<a class="button'.($disabled ?
' buttonRefused' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
"?id=".$id.
"&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.
'">'.$langs->trans(
"Reinit").
'</a>';
1364 print
'<a class="button'.($disabled ?
' buttonRefused' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
"?id=".$id.
"&action=checkdispatchline&lineid=".$objp->dispatchlineid.
'">'.$langs->trans(
"Approve").
'</a>';
1368 } elseif (isModEnabled(
"reception")) {
1369 print
'<td class="right">';
1370 if (!empty($reception->id)) {
1371 print $reception->getLibStatut(5);
1377 if ($action !=
'editline' || $lineid != $objp->dispatchlineid) {
1378 if (empty($reception->id) || ($reception->statut == Reception::STATUS_DRAFT)) {
1379 print
'<td class="linecoledit center">';
1380 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&lineid='.$objp->dispatchlineid.
'#line_'.$objp->dispatchlineid.
'">';
1385 print
'<td class="linecoldelete center">';
1386 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=ask_deleteline&token='.
newToken().
'&lineid='.$objp->dispatchlineid.
'#dispatch_received_products">';
1391 print
'<td></td><td></td>';
1394 print
'<td class="center valignmiddle">';
1395 print
'<input type="submit" class="button button-save" id="savelinebutton" name="save" value="'.$langs->trans(
"Save").
'" />';
1397 print
'<td class="center valignmiddle">';
1398 print
'<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="'.$langs->trans(
"Cancel").
'" />';
1404 if ($action ==
'editline' && $lineid == $objp->dispatchlineid) {
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()
Empty header.
Class to manage table ReceptionLineBatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_CANCELED
Order canceled.
const STATUS_RECEIVED_COMPLETELY
Received completely.
const STATUS_ACCEPTED
Accepted.
const STATUS_ORDERSENT
Order sent, shipment on process.
Class to manage warehouses.
Class to manage stock movements.
Class to manage products or services.
Class with list of lots and properties.
Class to manage projects.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete 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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
treeview li table
No Email.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
$conf db name
Only used if Module[ID]Name translation string is not found.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.