From eccbe941313f47216e32d253bcda6be0137eb463 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 3 May 2023 04:51:15 +0200 Subject: [PATCH] Debug v18 --- htdocs/fourn/commande/dispatch.php | 7 ++--- htdocs/fourn/js/lib_dispatch.js.php | 20 +++++++++----- htdocs/langs/en_US/receptions.lang | 4 +-- htdocs/product/inventory/inventory.php | 1 - htdocs/reception/card.php | 4 ++- htdocs/reception/dispatch.php | 37 +++++++++++++++++--------- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 25fb890698a..e262c64e89e 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -663,7 +663,7 @@ if ($id > 0 || !empty($ref)) { if ($num) { while ($i < $num) { $objd = $db->fetch_object($resql); - $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); + $products_dispatched[$objd->rowid] = price2num($objd->qty, 'MS'); $i++; } } @@ -780,6 +780,7 @@ if ($id > 0 || !empty($ref)) { $conf->cache['product'] = array(); + // Loop on each source order line (may be more or less than current number of lines in llx_commande_fournisseurdet) while ($i < $num) { $objp = $db->fetch_object($resql); @@ -873,7 +874,7 @@ if ($id > 0 || !empty($ref)) { print ''; print ''; // Qty to dispatch print ''; - //print img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"'); + //print img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"'); print ''; // Dispatch column print ''; // Warehouse column @@ -936,7 +937,7 @@ if ($id > 0 || !empty($ref)) { print ''; print ''; // Qty to dispatch print ''; - //print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"'); + //print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"'); print ''; // Dispatch column print ''; // Warehouse column diff --git a/htdocs/fourn/js/lib_dispatch.js.php b/htdocs/fourn/js/lib_dispatch.js.php index f1b70fa0ceb..e99c32f02d9 100644 --- a/htdocs/fourn/js/lib_dispatch.js.php +++ b/htdocs/fourn/js/lib_dispatch.js.php @@ -62,20 +62,26 @@ if (empty($dolibarr_nocache)) { * Adds new table row for dispatching to multiple stock locations or multiple lot/serial * * @param index int index of product line. 0 = first product line - * @param type string type of dispatch (batch = batch dispatch, dispatch = non batch dispatch) + * @param type string type of dispatch ('batch' = batch dispatch, 'dispatch' = non batch dispatch) * @param mode string 'qtymissing' will create new line with qty missing, 'lessone' will keep 1 in old line and the rest in new one */ function addDispatchLine(index, type, mode) { mode = mode || 'qtymissing' + console.log("fourn/js/lib_dispatch.js.php addDispatchLine Split line type="+type+" index="+index+" mode="+mode); + var $row0 = $("tr[name='"+type+'_0_'+index+"']"); var $dpopt = $row0.find('.hasDatepicker').first().datepicker('option', 'all'); // get current datepicker options to apply the same to the cloned datepickers var $row = $row0.clone(true); // clone first batch line to jQuery object - var nbrTrs = $("tr[name^='"+type+"_'][name$='_"+index+"']").length; // position of line for batch + var nbrTrs = $("tr[name^='"+type+"_'][name$='_"+index+"']").length; // count nb of tr line with attribute name that starts with 'batch_' or 'dispatch_', and end with _index var qtyOrdered = parseFloat($("#qty_ordered_0_"+index).val()); // Qty ordered is same for all rows - var qty = parseFloat($("#qty_"+(nbrTrs - 1)+"_"+index).val()); - console.log("fourn/js/lib_dispatch.js.php Split line type="+type+" index="+index+" mode="+mode+" qtyOrdered="+qtyOrdered+" qty="+qty); + var qty = parseFloat($("#qty_"+(nbrTrs - 1)+"_"+index).val()); + if (isNaN(qty)) { + qty = ''; + } + + console.log("fourn/js/lib_dispatch.js.php addDispatchLine Split line nbrTrs="+nbrTrs+" qtyOrdered="+qtyOrdered+" qty="+qty); var qtyDispatched; @@ -90,7 +96,7 @@ function addDispatchLine(index, type, mode) { mode = 'lessone'; } } - console.log("qtyDispatched=" + qtyDispatched + " qtyOrdered=" + qtyOrdered); + console.log("qtyDispatched=" + qtyDispatched + " qtyOrdered=" + qtyOrdered+ " qty=" + qty); if (qty <= 1) { window.alert("Remain quantity to dispatch is too low to be split"); @@ -187,7 +193,6 @@ function addDispatchLine(index, type, mode) { * * element requires arbitrary data qty (value before change), type (type of dispatch) and index (index of product line) */ - function onChangeDispatchLineQty(element) { var type = $(element).data('type'), qty = parseFloat($(element).data('expected')), @@ -208,7 +213,8 @@ function onChangeDispatchLineQty(element) { if ((qtyChanged) <= (qtyOrdered - (qtyDispatched + qtyDispatching))) { $("#qty_dispatched_0_" + index).val(qtyDispatched + qtyChanged); } else { - $(element).val($(element).data('expected')); + /*console.log("eee"); + $(element).val($(element).data('expected'));*/ } $(element).data('expected', $(element).val()); } diff --git a/htdocs/langs/en_US/receptions.lang b/htdocs/langs/en_US/receptions.lang index cd4c860e82f..9301067b43e 100644 --- a/htdocs/langs/en_US/receptions.lang +++ b/htdocs/langs/en_US/receptions.lang @@ -52,6 +52,6 @@ ReceptionExist=A reception exists ReceptionBackToDraftInDolibarr=Reception %s back to draft ReceptionClassifyClosedInDolibarr=Reception %s classified Closed ReceptionUnClassifyCloseddInDolibarr=Reception %s re-open -ResetQtyToDispatch=Reset all quantities to dispatch +RestoreWithCurrentQtySaved=Fill quantities with lastest saved values ReceptionUpdated=Reception sucessfully updated -DispatchCard=Dispatch card \ No newline at end of file +DispatchCard=Reception distribution \ No newline at end of file diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 89f59239e7c..00b2a544d6e 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -415,7 +415,6 @@ if (empty($reshook)) { - /* * View */ diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index 4280dabfc9d..52a831a950b 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -735,7 +735,9 @@ if (empty($reshook)) { * View */ -llxHeader('', $langs->trans('Reception'), 'Reception'); +$title = $object->ref.' - '.$langs->trans('Reception'); + +llxHeader('', $title, 'Reception'); $form = new Form($db); $formfile = new FormFile($db); diff --git a/htdocs/reception/dispatch.php b/htdocs/reception/dispatch.php index 4457a5b1303..b6806e2e805 100644 --- a/htdocs/reception/dispatch.php +++ b/htdocs/reception/dispatch.php @@ -297,7 +297,7 @@ $formproduct = new FormProduct($db); $warehouse_static = new Entrepot($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db); -$title = $object->ref." - ".$langs->trans('OrderDispatch'); +$title = $object->ref." - ".$langs->trans('DispatchCard'); $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores'; $morejs = array('/fourn/js/lib_dispatch.js.php'); @@ -427,8 +427,9 @@ if ($id > 0 || !empty($ref)) { print ''; print ''; print '
'; - print ''.img_picto("", 'eraser', 'class="pictofixedwidth"').$langs->trans("ResetQtyToDispatch").''; - print ''.img_picto("", 'eraser', 'class="pictofixedwidth"').$langs->trans("Reset").''; + print ''.img_picto("", 'autofill', 'class="pictofixedwidth"').$langs->trans("RestoreWithCurrentQtySaved").''; + // Link to clear qty + print ''.img_picto("", 'eraser', 'class="pictofixedwidth"').$langs->trans("ClearQtys").''; print '
'; print '
'; @@ -453,7 +454,7 @@ if ($id > 0 || !empty($ref)) { print '
'; print ''; - // Set $products_dispatched with qty dispatched for each product id + // Get list of lines from the original Order into $products_dispatched with qty dispatched for each product id $products_dispatched = array(); $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; @@ -469,17 +470,17 @@ if ($id > 0 || !empty($ref)) { if ($num) { while ($i < $num) { $objd = $db->fetch_object($resql); - $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); + $products_dispatched[$objd->rowid] = price2num($objd->qty, 'MS'); $i++; } } $db->free($resql); } + //$sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, SUM(l.qty) as qty,"; $sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, l.qty as qty,"; $sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse"; - // Enable hooks to alter the SQL query (SELECT) $parameters = array(); $reshook = $hookmanager->executeHooks( @@ -492,14 +493,12 @@ if ($id > 0 || !empty($ref)) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } $sql .= $hookmanager->resPrint; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid"; $sql .= " WHERE l.fk_commande = ".((int) $objectsrc->id); if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $sql .= " AND l.product_type = 0"; } - // Enable hooks to alter the SQL query (WHERE) $parameters = array(); $reshook = $hookmanager->executeHooks( @@ -520,7 +519,6 @@ if ($id > 0 || !empty($ref)) { if ($resql) { $num = $db->num_rows($resql); $i = 0; - $numline = 1; if ($num) { print ''; @@ -543,6 +541,7 @@ if ($id > 0 || !empty($ref)) { print ''; print ''; print ' '; print ''; if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { @@ -586,6 +585,7 @@ if ($id > 0 || !empty($ref)) { $conf->cache['product'] = array(); + // Loop on each source order line (may be more or less than current number of lines in llx_commande_fournisseurdet) while ($i < $num) { $objp = $db->fetch_object($resql); @@ -611,7 +611,7 @@ if ($id > 0 || !empty($ref)) { print ''."\n"; // hidden fields for js function print ''; - print ''; + print ''; print ''; if (empty($conf->cache['product'][$objp->fk_product])) { @@ -644,7 +644,7 @@ if ($id > 0 || !empty($ref)) { print $linktoprod; print ""; print ''; if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { print ''; @@ -682,7 +682,11 @@ if ($id > 0 || !empty($ref)) { $sql = "SELECT cfd.rowid, cfd.qty, cfd.fk_entrepot, cfd.batch, cfd.eatby, cfd.sellby, cfd.fk_product"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; - $sql .= " WHERE cfd.fk_commandefourndet = ".(int) $objp->rowid; + $sql .= " WHERE cfd.fk_reception = ".((int) $object->id); + $sql .= " AND cfd.fk_commande = ".((int) $objectsrc->id); + $sql .= " AND cfd.fk_commandefourndet = ".(int) $objp->rowid; + + //print $sql; $resultsql = $db->query($sql); $j = 0; if ($resultsql) { @@ -691,6 +695,7 @@ if ($id > 0 || !empty($ref)) { while ($j < $numd) { $suffix = "_".$j."_".$i; $objd = $db->fetch_object($resultsql); + if (isModEnabled('productbatch') && !empty($objd->batch)) { $type = 'batch'; @@ -862,6 +867,7 @@ if ($id > 0 || !empty($ref)) { } $suffix = "_".$j."_".$i; } + if ($j == 0) { if (isModEnabled('productbatch') && !empty($objp->batch)) { $type = 'batch'; @@ -1105,19 +1111,23 @@ if ($id > 0 || !empty($ref)) { $(".autoresettr").each(function(){ id = $(this).attr("name"); idtab = id.split("_"); - if($(this).data("remove") == "clear"){ + if ($(this).data("remove") == "clear"){ console.log("We clear the object to expected value") + $("#qty_"+idtab[1]+"_"+idtab[2]).val(""); + /* qtyexpected = $("#qty_"+idtab[1]+"_"+idtab[2]).data("expected") console.log(qtyexpected); $("#qty_"+idtab[1]+"_"+idtab[2]).val(qtyexpected); qtydispatched = $("#qty_dispatched_0_"+idtab[2]).data("dispatched") $("#qty_dispatched_0_"+idtab[2]).val(qtydispatched); + */ } else { console.log("We remove the object") $(this).remove(); $("tr[name^=\'"+idtab[0]+"_\'][name$=\'_"+idtab[2]+"\']:last .splitbutton").show(); } }); + return false; }); $("#resetalltoexpected").click(function(){ @@ -1125,6 +1135,7 @@ if ($id > 0 || !empty($ref)) { console.log("We reset to expected "+$(this).attr("id")+" qty to dispatch"); $(this).val($(this).data("expected")); }); + return false; }); $(".resetline").click(function(){
'.$langs->trans("QtyOrdered").''.$langs->trans("QtyDispatchedShort").''.$langs->trans("QtyToDispatchShort"); + //print '
'.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').$langs->trans("Reset").'
'; - print $langs->trans("ProductDoesNotUseBatchSerial"); + print ''.$langs->trans("ProductDoesNotUseBatchSerial").''; print '