update inventory add replace work
This commit is contained in:
parent
0d65fdad23
commit
c529d1a928
@ -50,8 +50,6 @@ if (!defined('NOBROWSERNOTIF')) {
|
|||||||
define('NOBROWSERNOTIF', '1');
|
define('NOBROWSERNOTIF', '1');
|
||||||
}
|
}
|
||||||
require '../../../main.inc.php';
|
require '../../../main.inc.php';
|
||||||
//include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
|
|
||||||
$object = new Inventory($db);
|
|
||||||
|
|
||||||
|
|
||||||
$action = GETPOST("action", "alpha");
|
$action = GETPOST("action", "alpha");
|
||||||
@ -87,12 +85,11 @@ if ($action == "existbarcode" && !empty($barcode)) {
|
|||||||
} else {
|
} else {
|
||||||
$response = array('status'=>'success','message'=>'Warehouse found','warehouse'=>$warehouseid);
|
$response = array('status'=>'success','message'=>'Warehouse found','warehouse'=>$warehouseid);
|
||||||
}
|
}
|
||||||
$response = json_encode($response);
|
|
||||||
} else {
|
} else {
|
||||||
$response = "No results found for barcode";
|
$response = array('status'=>'error','errorcode'=>'NotFound','message'=>"No results found for barcode");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$response = "Error on action";
|
$response = array('status'=>'error','errorcode'=>'ActionError','message'=>"Error on action");
|
||||||
}
|
}
|
||||||
|
$response = json_encode($response);
|
||||||
echo $response;
|
echo $response;
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
// Put here all includes required by your class file
|
// Put here all includes required by your class file
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
|
||||||
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
|
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
|
||||||
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
|
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
|
||||||
|
|
||||||
|
|||||||
@ -571,19 +571,19 @@ if ($object->id > 0) {
|
|||||||
if(productinput == ""){
|
if(productinput == ""){
|
||||||
productinput = 0
|
productinput = 0
|
||||||
}
|
}
|
||||||
tabproduct.push({\'Id\':id,\'Warehouse\':warehouse,\'Barcode\':productbarcode,\'Batch\':productbatchcode,\'Qty\':productinput});
|
tabproduct.push({\'Id\':id,\'Warehouse\':warehouse,\'Barcode\':productbarcode,\'Batch\':productbatchcode,\'Qty\':productinput,\'fetched\':false});
|
||||||
})
|
})
|
||||||
tabproduct.forEach(product => {
|
textarray.forEach(function(element,index){
|
||||||
switch(barcodemode){
|
switch(barcodemode){
|
||||||
case "barcodeforautodetect":
|
case "barcodeforautodetect":
|
||||||
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode",true);
|
barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,selectaddorreplace,"barcode",true);
|
||||||
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial",true);
|
barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,selectaddorreplace,"lotserial",true);
|
||||||
break;
|
break;
|
||||||
case "barcodeforproduct": //TODO: create product !exist + ajout
|
case "barcodeforproduct": //TODO: create product !exist + ajout
|
||||||
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode");
|
barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,selectaddorreplace,"barcode");
|
||||||
break;
|
break;
|
||||||
case "barcodeforlotserial":
|
case "barcodeforlotserial":
|
||||||
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial");
|
barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,selectaddorreplace,"lotserial");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
alert("'.$langs->trans("ErrorWrongBarcodemode").' \""+barcodemode+"\"");
|
alert("'.$langs->trans("ErrorWrongBarcodemode").' \""+barcodemode+"\"");
|
||||||
@ -601,8 +601,10 @@ if ($object->id > 0) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,mode,autodetect=false){
|
function barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,selectaddorreplace,mode,autodetect=false){
|
||||||
textarray.forEach(function(element,index){
|
BarcodeIsInProduct=0;
|
||||||
|
BarcodeSuccess=false;
|
||||||
|
tabproduct.forEach(product => {
|
||||||
$.ajax({ url: \''.DOL_URL_ROOT.'/product/inventory/ajax/searchfrombarcode.php\',
|
$.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},
|
data: { "action":"existbarcode",'.(!empty($object->fk_warehouse)?'"fk_entrepot":'.$object->fk_warehouse.',':'').'"barcode":element,"product":product},
|
||||||
type: \'POST\',
|
type: \'POST\',
|
||||||
@ -611,6 +613,7 @@ if ($object->id > 0) {
|
|||||||
response = JSON.parse(response);
|
response = JSON.parse(response);
|
||||||
if(response.status == "success"){
|
if(response.status == "success"){
|
||||||
console.log(response.message);
|
console.log(response.message);
|
||||||
|
BarcodeSucess=true;
|
||||||
}else{
|
}else{
|
||||||
console.error(response.message);
|
console.error(response.message);
|
||||||
}
|
}
|
||||||
@ -618,9 +621,8 @@ if ($object->id > 0) {
|
|||||||
error : function(output) {
|
error : function(output) {
|
||||||
console.error("Error on barcodeserialforproduct function");
|
console.error("Error on barcodeserialforproduct function");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log("Product "+(index+=1)+": "+element);
|
console.log("Product "+(index+=1)+": "+element);
|
||||||
BarCodeDoesNotExist=0;
|
|
||||||
if(mode == "barcode"){
|
if(mode == "barcode"){
|
||||||
testonproduct = product.Barcode
|
testonproduct = product.Barcode
|
||||||
}else if (mode == "lotserial"){
|
}else if (mode == "lotserial"){
|
||||||
@ -628,15 +630,23 @@ if ($object->id > 0) {
|
|||||||
}
|
}
|
||||||
if(testonproduct == element){
|
if(testonproduct == element){
|
||||||
if(selectaddorreplace == "add"){
|
if(selectaddorreplace == "add"){
|
||||||
productqty = parseInt(product.Qty,10)
|
productqty = parseInt(product.Qty,10);
|
||||||
product.Qty = productqty + barcodeproductqty
|
product.Qty = productqty + parseInt(barcodeproductqty,10);
|
||||||
}else if(selectaddorreplace == "replace"){
|
}else if(selectaddorreplace == "replace"){
|
||||||
product.Qty = barcodeproductqty
|
if(product.fetched == false){
|
||||||
|
product.Qty = barcodeproductqty
|
||||||
|
product.fetched=true
|
||||||
|
}else{
|
||||||
|
productqty = parseInt(product.Qty,10);
|
||||||
|
product.Qty = productqty + parseInt(barcodeproductqty,10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
BarcodeIsInProduct+=1;
|
||||||
BarCodeDoesNotExist+=1;
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if(BarcodeIsInProduct==0 && BarcodeSuccess){
|
||||||
|
//addproduct to db and tabproduct
|
||||||
|
}
|
||||||
}
|
}
|
||||||
';
|
';
|
||||||
print '</script>';
|
print '</script>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user