diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index d132a87233f..596e657f2e3 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -8,7 +8,7 @@ * Copyright (C) 2016 Florian Henry * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2018 Frédéric France - * Copyright (C) 2019 Christophe Battarel + * Copyright (C) 2019-2020 Christophe Battarel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,6 +53,8 @@ $ref = GETPOST('ref'); $lineid = GETPOST('lineid', 'int'); $action = GETPOST('action', 'aZ09'); $fk_default_warehouse = GETPOST('fk_default_warehouse', 'int'); +$cancel = GETPOST('cancel', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); if ($user->socid) $socid = $user->socid; @@ -366,6 +368,34 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) } } +// Remove a dispatched line +if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->commande->receptionner) +{ + $supplierorderdispatch = new CommandeFournisseurDispatch($db); + $result = $supplierorderdispatch->fetch($lineid); + if ($result > 0) $result = $supplierorderdispatch->delete($user); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +// Update a dispatched line +if ($action == 'updateline' && $user->rights->fournisseur->commande->receptionner) +{ + $supplierorderdispatch = new CommandeFournisseurDispatch($db); + $result = $supplierorderdispatch->fetch($lineid); + if ($result > 0) + { + $supplierorderdispatch->qty = GETPOST('qty', 'int'); + $supplierorderdispatch->fk_entrepot = GETPOST('fk_entrepot'); + $result = $supplierorderdispatch->update($user); + } + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} /* * View @@ -379,7 +409,7 @@ $warehouse_static = new Entrepot($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db); $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores'; -llxHeader('', $langs->trans("Order"), $help_url, '', 0, 0, array('/fourn/js/lib_dispatch.js.php')); +llxHeader('', $langs->trans("OrderDispatch"), $help_url, '', 0, 0, array('/fourn/js/lib_dispatch.js.php')); if ($id > 0 || !empty($ref)) { $soc = new Societe($db); @@ -393,6 +423,23 @@ if ($id > 0 || !empty($ref)) { $title = $langs->trans("SupplierOrder"); dol_fiche_head($head, 'dispatch', $title, -1, 'order'); + $formconfirm=''; + + // Confirmation to delete line + if ($action == 'ask_deleteline') + { + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); + } + + // Call Hook formConfirm + $parameters = array('lineid' => $lineid); + // Note that $action and $object may be modified by hook + $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); + if (empty($reshook)) $formconfirm.=$hookmanager->resPrint; + elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint; + + // Print form confirm + print $formconfirm; // Supplier order card @@ -493,6 +540,9 @@ if ($id > 0 || !empty($ref)) { require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct = new FormProduct($db); $formproduct->loadWarehouses(); + $entrepot = new Entrepot($db); + $listwarehouses=$entrepot->list_array(1); + if (empty($conf->reception->enabled))print '
'; else print ''; @@ -567,8 +617,6 @@ if ($id > 0 || !empty($ref)) { $i = 0; if ($num) { - $entrepot = new Entrepot($db); - $listwarehouses = $entrepot->list_array(1); print ''; @@ -965,7 +1013,6 @@ if ($id > 0 || !empty($ref)) { print ''.$langs->trans("SellByDate").''; } print ''.$langs->trans("QtyDispatched").''; - print ''; print ''.$langs->trans("Warehouse").''; print ''.$langs->trans("Comment").''; @@ -977,14 +1024,23 @@ if ($id > 0 || !empty($ref)) { print ''; } - print ''; + print ''; print "\n"; while ($i < $num) { $objp = $db->fetch_object($resql); - print ""; + if ($action == 'editline' && $lineid == $objp->dispatchlineid) + { + print ' + + + + '; + } + + print ''; if (!empty($conf->reception->enabled)) { print ''; @@ -1011,14 +1067,34 @@ if ($id > 0 || !empty($ref)) { } // Qty - print ''.$objp->qty.''; - print ' '; + if ($action == 'editline' && $lineid == $objp->dispatchlineid) + { + print ''; + } + else + { + print ''.$objp->qty.''; + } // Warehouse print ''; - $warehouse_static->id = $objp->warehouse_id; - $warehouse_static->libelle = $objp->entrepot; - print $warehouse_static->getNomUrl(1); + if ($action == 'editline' && $lineid == $objp->dispatchlineid) + { + if (count($listwarehouses) > 1) { + 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'); + } elseif (count($listwarehouses) == 1) { + 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'); + } else { + $langs->load("errors"); + print $langs->trans("ErrorNoWarehouseDefined"); + } + } + else + { + $warehouse_static->id = $objp->warehouse_id; + $warehouse_static->libelle = $objp->entrepot; + print $warehouse_static->getNomUrl(1); + } print ''; // Comment @@ -1069,9 +1145,33 @@ if ($id > 0 || !empty($ref)) { print ''; } - print ''; + if ($action != 'editline' ||  && $lineid != $objp->dispatchlineid) + { + print ''; + print 'dispatchlineid .'#line_'. $objp->dispatchlineid . '">'; + print img_edit(); + print ''; + print ''; + + print ''; + print 'dispatchlineid . '#dispatch_received_products">'; + print img_delete(); + print ''; + print ''; + } + else + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + print "\n"; + if ($action == 'editline' && $lineid == $objp->dispatchlineid) print '
'; $i++; }