update inventory
This commit is contained in:
parent
238996b351
commit
694ce9be17
@ -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 {
|
||||||
|
|||||||
@ -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});
|
||||||
})
|
})
|
||||||
switch(barcodemode){
|
tabproduct.forEach(product => {
|
||||||
case "barcodeforautodetect":
|
switch(barcodemode){
|
||||||
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"barcode",true);
|
case "barcodeforautodetect":
|
||||||
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"lotserial",true);
|
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode",true);
|
||||||
break;
|
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial",true);
|
||||||
case "barcodeforproduct": //TODO: create product !exist + ajout
|
break;
|
||||||
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"barcode");
|
case "barcodeforproduct": //TODO: create product !exist + ajout
|
||||||
break;
|
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"barcode");
|
||||||
case "barcodeforlotserial":
|
break;
|
||||||
barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,"lotserial");
|
case "barcodeforlotserial":
|
||||||
break;
|
barcodeserialforproduct(textarray,product,barcodeproductqty,selectaddorreplace,"lotserial");
|
||||||
default:
|
break;
|
||||||
alert("'.$langs->trans("ErrorWrongBarcodemode").' \""+barcodemode+"\"");
|
default:
|
||||||
throw"'.$langs->trans('ErrorWrongBarcodemode').' \""+barcodemode+"\"";
|
alert("'.$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,23 +615,21 @@ 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"){
|
testonproduct = product.Batch
|
||||||
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){
|
}else{
|
||||||
if(selectaddorreplace == "add"){
|
BarCodeDoesNotExist+=1;
|
||||||
productqty = parseInt(product.Qty,10)
|
}
|
||||||
product.Qty = productqty + (1*barcodeproductqty)
|
|
||||||
}else if(selectaddorreplace == "replace"){
|
|
||||||
product.Qty = (1*barcodeproductqty)
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user