update inventory

This commit is contained in:
lmarcouiller 2021-11-15 14:23:52 +01:00
parent 238996b351
commit 694ce9be17
2 changed files with 47 additions and 40 deletions

View File

@ -50,23 +50,29 @@ if (!defined('NOBROWSERNOTIF')) {
define('NOBROWSERNOTIF', '1'); define('NOBROWSERNOTIF', '1');
} }
require '../../../main.inc.php'; 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"); $action = GETPOST("action", "alpha");
$barcode = GETPOST("barcode", "aZ09"); $barcode = GETPOST("barcode", "aZ09");
$product = GETPOST("product");
$response = ""; $response = "";
$fk_entrepot = -1; $fk_entrepot = GETPOST("fk_entrepot", "int");
if ($action == "existbarcode" && !empty($barcode)) { 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"; $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); $result = $db->query($sql);
if ($result) { if ($result) {
$objecttab = $db->fetch_row($resql);
$nbline = $db->num_rows($resql); $nbline = $db->num_rows($resql);
for ($i=0; $i < $nbline; $i++) { for ($i=0; $i < $nbline; $i++) {
if ($fk_entrepot != $objecttab[$i]) { $object = $db->fetch_object($resql);
// code... if ($barcode == $object->barcode) {
if (!empty($object->fk_entrepot) && $product["Warehouse"] == $object->fk_entrepot) {
//si warehouse !=$object->fk_entrepot erreur
}
} }
} }
} else { } else {

View File

@ -572,21 +572,23 @@ if ($object->id > 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});
}) })
tabproduct.forEach(product => {
switch(barcodemode){ switch(barcodemode){
case "barcodeforautodetect": case "barcodeforautodetect":
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"barcode",true); barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode",true);
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"lotserial",true); barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial",true);
break; break;
case "barcodeforproduct": //TODO: create product !exist + ajout case "barcodeforproduct": //TODO: create product !exist + ajout
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"barcode"); barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode");
break; break;
case "barcodeforlotserial": case "barcodeforlotserial":
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"lotserial"); barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial");
break; break;
default: default:
alert("'.$langs->trans("ErrorWrongBarcodemode").' \""+barcodemode+"\""); alert("'.$langs->trans("ErrorWrongBarcodemode").' \""+barcodemode+"\"");
throw"'.$langs->trans('ErrorWrongBarcodemode').' \""+barcodemode+"\""; throw"'.$langs->trans('ErrorWrongBarcodemode').' \""+barcodemode+"\"";
} }
)}
tabproduct.forEach(product => { tabproduct.forEach(product => {
if(product.Qty!=0){ if(product.Qty!=0){
console.log("We change #"+product.Id+"_input to match input in scanner box"); 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){ textarray.forEach(function(element,index){
$.ajax({ url: \''.DOL_URL_ROOT.'/product/inventory/ajax/searchfrombarcode.php\', $.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\', type: \'POST\',
success: function(response) { success: function(response) {
console.log("test+1"); console.log("test+1");
//gerer erreur si entrepot different
}, },
error : function(output) { error : function(output) {
console.error("Error on Fetch of KM articles"); console.error("Error on Fetch of KM articles");
@ -612,7 +615,6 @@ if ($object->id > 0) {
}); });
console.log("Product "+(index+=1)+": "+element); console.log("Product "+(index+=1)+": "+element);
BarCodeDoesNotExist=0; BarCodeDoesNotExist=0;
tabproduct.forEach(product => {
if(mode == "barcode"){ if(mode == "barcode"){
testonproduct = product.Barcode testonproduct = product.Barcode
}else if (mode == "lotserial"){ }else if (mode == "lotserial"){
@ -628,7 +630,6 @@ if ($object->id > 0) {
}else{ }else{
BarCodeDoesNotExist+=1; BarCodeDoesNotExist+=1;
} }
})
if(autodetect == false){ if(autodetect == false){
if(BarCodeDoesNotExist >= tabproduct.length && mode == "barcode"){ if(BarCodeDoesNotExist >= tabproduct.length && mode == "barcode"){
alert("'.$langs->trans('ProductBarcodeDoesNotExist').': "+element); alert("'.$langs->trans('ProductBarcodeDoesNotExist').': "+element);