From 5b1028611aacd583fa9d7bde4f225e50770a65df Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 19 Nov 2021 13:55:59 +0100 Subject: [PATCH] update inventory 19 11 --- .../inventory/ajax/searchfrombarcode.php | 17 +++++++++++-- htdocs/product/inventory/inventory.php | 24 +++++++++---------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/htdocs/product/inventory/ajax/searchfrombarcode.php b/htdocs/product/inventory/ajax/searchfrombarcode.php index 559bf8b72da..884aff9ec12 100644 --- a/htdocs/product/inventory/ajax/searchfrombarcode.php +++ b/htdocs/product/inventory/ajax/searchfrombarcode.php @@ -50,13 +50,17 @@ if (!defined('NOBROWSERNOTIF')) { define('NOBROWSERNOTIF', '1'); } require '../../../main.inc.php'; -//require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; +//include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; +$object = new Inventory($db); + $action = GETPOST("action", "alpha"); $barcode = GETPOST("barcode", "aZ09"); $product = GETPOST("product"); $response = ""; $fk_entrepot = GETPOST("fk_entrepot", "int"); +$warehousefound = 0; +$warehouseid = 0; if ($action == "existbarcode" && !empty($barcode)) { $sql = "SELECT ps.fk_entrepot, ps.fk_product, p.barcode"; $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid"; @@ -71,10 +75,19 @@ if ($action == "existbarcode" && !empty($barcode)) { $object = $db->fetch_object($resql); if ($barcode == $object->barcode) { if (!empty($object->fk_entrepot) && $product["Warehouse"] == $object->fk_entrepot) { - //si warehouse !=$object->fk_entrepot erreur + $warehousefound++; + $warehouseid = $object->fk_entrepot; } } } + if ($warehousefound < 1) { + $response = array('status'=>'error','errorcode'=>'NotFound','message'=>'No warehouse found for barcode'.$barcode); + } elseif ($warehousefound > 1) { + $response = array('status'=>'error','errorcode'=>'TooManyWarehouse','message'=>'Too many warehouse found'); + } else { + $response = array('status'=>'success','message'=>'Warehouse found','warehouse'=>$warehouseid); + } + $response = json_encode($response); } else { $response = "No results found for barcode"; } diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 8adf1ebc67c..76e3d53de2f 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -588,7 +588,7 @@ if ($object->id > 0) { alert("'.$langs->trans("ErrorWrongBarcodemode").' \""+barcodemode+"\""); throw"'.$langs->trans('ErrorWrongBarcodemode').' \""+barcodemode+"\""; } - )} + }); tabproduct.forEach(product => { if(product.Qty!=0){ console.log("We change #"+product.Id+"_input to match input in scanner box"); @@ -605,12 +605,17 @@ if ($object->id > 0) { $.ajax({ url: \''.DOL_URL_ROOT.'/product/inventory/ajax/searchfrombarcode.php\', data: { "action":"existbarcode",'.(!empty($object->fk_warehouse)?'"fk_entrepot":'.$object->fk_warehouse.',':'').'"barcode":element,"product":product}, type: \'POST\', + async: false, success: function(response) { - console.log("test+1"); - //gerer erreur si entrepot different + response = JSON.parse(response); + if(response.status == "success"){ + console.log(response.message); + }else{ + console.error(response.message); + } }, error : function(output) { - console.error("Error on Fetch of KM articles"); + console.error("Error on barcodeserialforproduct function"); }, }); console.log("Product "+(index+=1)+": "+element); @@ -623,20 +628,13 @@ if ($object->id > 0) { if(testonproduct == element){ if(selectaddorreplace == "add"){ productqty = parseInt(product.Qty,10) - product.Qty = productqty + (1*barcodeproductqty) + product.Qty = productqty + barcodeproductqty }else if(selectaddorreplace == "replace"){ - product.Qty = (1*barcodeproductqty) + product.Qty = barcodeproductqty } }else{ BarCodeDoesNotExist+=1; } - if(autodetect == false){ - if(BarCodeDoesNotExist >= tabproduct.length && mode == "barcode"){ - alert("'.$langs->trans('ProductBarcodeDoesNotExist').': "+element); - }else if(BarCodeDoesNotExist >= tabproduct.length && mode == "lotserial"){ - alert("'.$langs->trans('ProductBatchDoesNotExist').': "+element); - } - } }) } ';