From 3e77a6cbd43c11f69cf29266ccbfc3ae805eb552 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 4 Apr 2023 18:42:55 +0200 Subject: [PATCH] FIX Reception process loose some lines on first error. --- htdocs/fourn/js/lib_dispatch.js.php | 4 +- htdocs/reception/card.php | 72 ++++++++++++++++++----------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/htdocs/fourn/js/lib_dispatch.js.php b/htdocs/fourn/js/lib_dispatch.js.php index 01af2ee5d91..ff822543ddb 100644 --- a/htdocs/fourn/js/lib_dispatch.js.php +++ b/htdocs/fourn/js/lib_dispatch.js.php @@ -93,8 +93,8 @@ function addDispatchLine(index, type, mode) } console.log("qtyDispatched="+qtyDispatched+" qtyOrdered="+qtyOrdered); - if (qtyOrdered <= 1) { - window.alert("Quantity can't be split"); + if (qtyDispatched >= qtyOrdered || qtyOrdered <= 1) { + window.alert("Remain quantity to dispatch is too low to be split"); } else if (qtyDispatched < qtyOrdered) { //replace tr suffix nbr $row.html($row.html().replace(/_0_/g,"_"+nbrTrs+"_")); diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index f28b51a7a97..13f2a280629 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -339,16 +339,17 @@ if (empty($reshook)) { } } + // Loop lines to calculate $totalqty for ($i = 1; $i <= $num; $i++) { - $idl = "idl".$i; + $idl = "idl".$i; // id line source - $sub_qty = array(); - $subtotalqty = 0; + //$sub_qty = array(); + //$subtotalqty = 0; - $j = 0; - $batch = "batchl".$i."_0"; - $stockLocation = "ent1".$i."_0"; - $qty = "qtyl".$i; + //$j = 0; + //$batch = "batchl".$i."_0"; + //$stockLocation = "ent1".$i."_0"; + $qty = "qtyl".$i; // qty //reception line for product with no batch management and no multiple stock location if (GETPOST($qty, 'alpha') > 0) { @@ -362,6 +363,7 @@ if (empty($reshook)) { if ($totalqty > 0) { // There is at least one thing to ship for ($i = 1; $i <= $num; $i++) { + $idl = "idl".$i; // id line source $lineToTest = ''; $lineId = GETPOST($idl, 'int'); foreach ($objectsrc->lines as $linesrc) { @@ -375,26 +377,28 @@ if (empty($reshook)) { } $qty = "qtyl".$i; $comment = "comment".$i; - // EATBY <-> DLUO see productbatch.class.php - // SELLBY <-> DLC + // EATBY <-> DLUO and SELLBY <-> DLC, see productbatch.class.php $eatby = "dluo".$i; $sellby = "dlc".$i; $batch = "batch".$i; $cost_price = "cost_price".$i; - //if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) { - if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS)) { - $ent = "entl".$i; + //var_dump(GETPOST("productl".$i, 'int').' '.GETPOST('entl'.$i, 'int').' '.GETPOST($idl, 'int').' '.GETPOST($qty, 'int').' '.GETPOST($batch, 'alpha')); + //if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) { + if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS'))) { + $ent = "entl".$i; $idl = "idl".$i; $entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int'); + /* if (!empty($lineToTest)) { $fk_product = $lineToTest->fk_product; } else { $fk_product = $linesrc->fk_product; - } + }*/ + $fk_product = GETPOST("productl".$i, 'int'); if ($entrepot_id < 0) { $entrepot_id = ''; @@ -402,6 +406,7 @@ if (empty($reshook)) { if (!($fk_product > 0) && empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $entrepot_id = 0; } + $eatby = GETPOST($eatby, 'alpha'); $sellby = GETPOST($sellby, 'alpha'); $eatbydate = str_replace('/', '-', $eatby); @@ -419,7 +424,6 @@ if (empty($reshook)) { } } - // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) { @@ -941,7 +945,7 @@ if ($action == 'create') { print dol_get_fiche_end(); - // Reception lines + // Number of lines show on the reception card $numAsked = 0; /** @@ -954,7 +958,7 @@ if ($action == 'create') { foreach ($_POST as $key => $value) { // If create form is coming from the button "Create Reception" of previous page - // without batch module enabled + // without batch module enabled or product with no lot/serial $reg = array(); if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) { $numAsked++; @@ -969,10 +973,10 @@ if ($action == 'create') { $ent = "entrepot_" . $paramSuffix; $pu = "pu_" . $paramSuffix; // This is unit price including discount $fk_commandefourndet = "fk_commandefourndet_" . $paramSuffix; - $dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int')); + $dispatchLines[$numAsked] = array('paramSuffix'=>$paramSuffix, 'prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int')); } - // with batch module enabled + // with batch module enabled and product with lot/serial if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) { $numAsked++; $paramSuffix = $reg[1] . '_' . $reg[2]; @@ -990,11 +994,11 @@ if ($action == 'create') { $dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo_'.$paramSuffix.'month', 'int'), GETPOST('dluo_'.$paramSuffix.'day', 'int'), GETPOST('dluo_'.$paramSuffix.'year', 'int')); $dDLC = dol_mktime(12, 0, 0, GETPOST('dlc_'.$paramSuffix.'month', 'int'), GETPOST('dlc_'.$paramSuffix.'day', 'int'), GETPOST('dlc_'.$paramSuffix.'year', 'int')); $fk_commandefourndet = 'fk_commandefourndet_'.$paramSuffix; - $dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha')); + $dispatchLines[$numAsked] = array('paramSuffix'=>$paramSuffix, 'prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha')); } // If create form is coming from same page, it means that post was sent but an error occured - if (preg_match('/^productid([0-9]+)$/i', $key, $reg)) { + if (preg_match('/^productl([0-9]+)$/i', $key, $reg)) { $numAsked++; $paramSuffix = $reg[1]; $suffix2numAsked[$paramSuffix] = $numAsked; @@ -1116,9 +1120,13 @@ if ($action == 'create') { $product->fetch($line->fk_product); $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch //var_dump($product->stock_warehouse[1]); + //var_dump($dispatchLines[$indiceAsked]); print ''; print ''; // ancre pour retourner sur la ligne + + print ''; + if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice print ''; @@ -1977,12 +1985,24 @@ if ($action == 'create') { if (isModEnabled('productbatch')) { if (isset($lines[$i]->batch)) { print ''; - print ''; - $detail = ''; - if ($lines[$i]->product->status_batch) { - $detail .= $langs->trans("Batch").': '.$lines[$i]->batch; - if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { - $detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day"); + print ''; + $detail = $langs->trans("NA"); + if ($lines[$i]->product->status_batch > 0 && $lines[$i]->fk_product > 0) { + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; + $productlot = new Productlot($db); + $reslot = $productlot->fetch(0, $lines[$i]->fk_product, $lines[$i]->batch); + if ($reslot > 0) { + $detail = $productlot->getNomUrl(1); + } else { + // lot is not created and info is only in reception lines + $batchinfo = $langs->trans("Batch").': '.$lines[$i]->batch; + if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { + $batchinfo .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day"); + } + if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { + $batchinfo .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day"); + } + $detail = $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $batchinfo); } if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { $detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day");