diff --git a/htdocs/product/inventory/ajax/searchfrombarcode.php b/htdocs/product/inventory/ajax/searchfrombarcode.php index 73b1943f4c7..559bf8b72da 100644 --- a/htdocs/product/inventory/ajax/searchfrombarcode.php +++ b/htdocs/product/inventory/ajax/searchfrombarcode.php @@ -50,23 +50,29 @@ if (!defined('NOBROWSERNOTIF')) { define('NOBROWSERNOTIF', '1'); } require '../../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; +//require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; $action = GETPOST("action", "alpha"); $barcode = GETPOST("barcode", "aZ09"); +$product = GETPOST("product"); $response = ""; -$fk_entrepot = -1; +$fk_entrepot = GETPOST("fk_entrepot", "int"); if ($action == "existbarcode" && !empty($barcode)) { - $sql = "SELECT *"; + $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"; - " WHERE p.barcode = '".$db->escape($barcode)."'"; + $sql .= " WHERE p.barcode = '".$db->escape($barcode)."'"; + if (!empty($fk_entrepot)) { + $sql .= "AND ps.fk_entrepot = '".$db->escape($fk_entrepot)."'"; + } $result = $db->query($sql); if ($result) { - $objecttab = $db->fetch_row($resql); $nbline = $db->num_rows($resql); for ($i=0; $i < $nbline; $i++) { - if ($fk_entrepot != $objecttab[$i]) { - // code... + $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 + } } } } else { diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index f2702fbc0db..8adf1ebc67c 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -572,21 +572,23 @@ if ($object->id > 0) { } tabproduct.push({\'Id\':id,\'Warehouse\':warehouse,\'Barcode\':productbarcode,\'Batch\':productbatchcode,\'Qty\':productinput}); }) - switch(barcodemode){ - case "barcodeforautodetect": - barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"barcode",true); - barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"lotserial",true); - break; - case "barcodeforproduct": //TODO: create product !exist + ajout - barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"barcode"); - break; - case "barcodeforlotserial": - barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"lotserial"); - break; - default: - alert("'.$langs->trans("ErrorWrongBarcodemode").' \""+barcodemode+"\""); - throw"'.$langs->trans('ErrorWrongBarcodemode').' \""+barcodemode+"\""; - } + tabproduct.forEach(product => { + switch(barcodemode){ + case "barcodeforautodetect": + barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode",true); + barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial",true); + break; + case "barcodeforproduct": //TODO: create product !exist + ajout + barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode"); + break; + case "barcodeforlotserial": + barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial"); + break; + default: + 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"); @@ -598,13 +600,14 @@ if ($object->id > 0) { } - function barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,mode,autodetect=false){ + function barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,mode,autodetect=false){ textarray.forEach(function(element,index){ $.ajax({ url: \''.DOL_URL_ROOT.'/product/inventory/ajax/searchfrombarcode.php\', - data: { "action":"existbarcode","barcode":element}, + data: { "action":"existbarcode",'.(!empty($object->fk_warehouse)?'"fk_entrepot":'.$object->fk_warehouse.',':'').'"barcode":element,"product":product}, type: \'POST\', success: function(response) { console.log("test+1"); + //gerer erreur si entrepot different }, error : function(output) { console.error("Error on Fetch of KM articles"); @@ -612,23 +615,21 @@ if ($object->id > 0) { }); console.log("Product "+(index+=1)+": "+element); BarCodeDoesNotExist=0; - tabproduct.forEach(product => { - if(mode == "barcode"){ - testonproduct = product.Barcode - }else if (mode == "lotserial"){ - testonproduct = product.Batch + if(mode == "barcode"){ + testonproduct = product.Barcode + }else if (mode == "lotserial"){ + testonproduct = product.Batch + } + if(testonproduct == element){ + if(selectaddorreplace == "add"){ + productqty = parseInt(product.Qty,10) + product.Qty = productqty + (1*barcodeproductqty) + }else if(selectaddorreplace == "replace"){ + product.Qty = (1*barcodeproductqty) } - if(testonproduct == element){ - if(selectaddorreplace == "add"){ - productqty = parseInt(product.Qty,10) - product.Qty = productqty + (1*barcodeproductqty) - }else if(selectaddorreplace == "replace"){ - product.Qty = (1*barcodeproductqty) - } - }else{ - BarCodeDoesNotExist+=1; - } - }) + }else{ + BarCodeDoesNotExist+=1; + } if(autodetect == false){ if(BarCodeDoesNotExist >= tabproduct.length && mode == "barcode"){ alert("'.$langs->trans('ProductBarcodeDoesNotExist').': "+element);