update inventory 19 11

This commit is contained in:
lmarcouiller 2021-11-19 13:55:59 +01:00
parent 694ce9be17
commit 5b1028611a
2 changed files with 26 additions and 15 deletions

View File

@ -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";
}

View File

@ -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);
}
}
})
}
';