From b79a30c0f96d701171ec52bf3d30d395b3df04d2 Mon Sep 17 00:00:00 2001 From: altairis Date: Tue, 19 May 2020 14:18:06 +0200 Subject: [PATCH 1/2] edit and delete dispatched lines --- htdocs/fourn/commande/dispatch.php | 126 ++++++++++++++++++++++++++--- 1 file changed, 113 insertions(+), 13 deletions(-) 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++; } From 80c56b30179b9c5baa619a9c7be1d1cb41f6a88b Mon Sep 17 00:00:00 2001 From: altairis Date: Tue, 19 May 2020 15:59:03 +0200 Subject: [PATCH 2/2] manage stock on edit and delete dispatched lines --- htdocs/fourn/commande/dispatch.php | 109 +++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 5 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 596e657f2e3..088cff61ee6 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -38,6 +38,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; + if (!empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; @@ -371,29 +373,121 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) // Remove a dispatched line if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->commande->receptionner) { + $db->begin(); + $supplierorderdispatch = new CommandeFournisseurDispatch($db); $result = $supplierorderdispatch->fetch($lineid); - if ($result > 0) $result = $supplierorderdispatch->delete($user); + if ($result > 0) + { + $qty = $supplierorderdispatch->qty; + $entrepot = $supplierorderdispatch->fk_entrepot; + $product = $supplierorderdispatch->fk_product; + $price = GETPOST('price'); + $comment = $supplierorderdispatch->comment; + $eatby = $supplierorderdispatch->fk_product; + $sellby = $supplierorderdispatch->sellby; + $batch = $supplierorderdispatch->batch; + + $result = $supplierorderdispatch->delete($user); + } if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); + $errors = $object->errors; + $error++; + } + else + { + // If module stock is enabled and the stock increase is done on purchase order dispatching + if ($entrepot > 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) + { + $mouv = new MouvementStock($db); + if ($product > 0) + { + $mouv->origin = &$object; + $result=$mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch); + if ($result < 0) + { + $errors=$mouv->errors; + $error++; + } + } + } + } + if ($error > 0) + { + $db->rollback(); + setEventMessages($error, $errors, 'errors'); + } + else + { + $db->commit(); } } // Update a dispatched line if ($action == 'updateline' && $user->rights->fournisseur->commande->receptionner) { + $db->begin(); + $error = 0; + $supplierorderdispatch = new CommandeFournisseurDispatch($db); $result = $supplierorderdispatch->fetch($lineid); if ($result > 0) { + $qty = $supplierorderdispatch->qty; + $entrepot = $supplierorderdispatch->fk_entrepot; + $product = $supplierorderdispatch->fk_product; + $price = GETPOST('price'); + $comment = $supplierorderdispatch->comment; + $eatby = $supplierorderdispatch->fk_product; + $sellby = $supplierorderdispatch->sellby; + $batch = $supplierorderdispatch->batch; + $supplierorderdispatch->qty = GETPOST('qty', 'int'); $supplierorderdispatch->fk_entrepot = GETPOST('fk_entrepot'); $result = $supplierorderdispatch->update($user); } if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); + $error++; + $errors=$supplierorderdispatch->errors; + } + else + { + // If module stock is enabled and the stock increase is done on purchase order dispatching + if ($entrepot > 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) + { + $mouv = new MouvementStock($db); + if ($product > 0) + { + $mouv->origin = &$object; + $result=$mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch); + if ($result < 0) + { + $errors=$mouv->errors; + $error++; + } + else + { + $mouv->origin = &$object; + $result=$mouv->reception($user, $product, $supplierorderdispatch->fk_entrepot, $supplierorderdispatch->qty, $price, $comment, $eatby, $sellby, $batch); + if ($result < 0) + { + $errors=$mouv->errors; + $error++; + } + } + } + } + } + if ($error > 0) + { + $db->rollback(); + setEventMessages($error, $errors, 'errors'); + } + else + { + $db->commit(); } } @@ -979,9 +1073,11 @@ if ($id > 0 || !empty($ref)) { $sql = "SELECT p.ref, p.label,"; $sql .= " e.rowid as warehouse_id, e.ref as entrepot,"; $sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec"; + $sql.=" ,cd.rowid, cd.subprice"; if ($conf->reception->enabled)$sql .= " ,cfd.fk_reception, r.date_delivery"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p,"; $sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "commande_fournisseurdet as cd ON cd.rowid = cfd.fk_commandefourndet"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid"; if ($conf->reception->enabled)$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid"; $sql .= " WHERE cfd.fk_commande = ".$object->id; @@ -1067,14 +1163,17 @@ if ($id > 0 || !empty($ref)) { } // Qty + print ''; if ($action == 'editline' && $lineid == $objp->dispatchlineid) { - print ''; + print ''; } else { - print ''.$objp->qty.''; + print $objp->qty; } + print ''; + print ''; // Warehouse print '';