Barcode scanner tool update

This commit is contained in:
lmarcouiller 2021-07-20 14:43:36 +02:00
parent b309af0ab8
commit dd9eb28230
3 changed files with 109 additions and 57 deletions

View File

@ -92,10 +92,6 @@ class FormOther
$out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.$langs->trans("Cancel").'">'; $out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.$langs->trans("Cancel").'">';
$out .= '<br>'; $out .= '<br>';
$out .= '<span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span>';
// TODO Add call of javascript $jstoexecuteonadd so each scan will add qty into the inventory page + an ajax save.
$out .= '<script>'; $out .= '<script>';
$out .= '$("#exec'.dol_escape_js($jstoexecuteonadd).'").click(function(){ $out .= '$("#exec'.dol_escape_js($jstoexecuteonadd).'").click(function(){
console.log("We call js to execute '.dol_escape_js($jstoexecuteonadd).'"); console.log("We call js to execute '.dol_escape_js($jstoexecuteonadd).'");

View File

@ -258,3 +258,6 @@ CollapseBatchDetailHelp=You can set batch detail default display in stocks modul
FieldCannotBeNegative=Field "%s" cannot be negative FieldCannotBeNegative=Field "%s" cannot be negative
ErrorWrongBarcodemode=Unknown Barcode mode ErrorWrongBarcodemode=Unknown Barcode mode
ProductDoesNotExist=Product does not exist ProductDoesNotExist=Product does not exist
ErrorSameBatchNumber=Same batch number found in inventory list
ProductBatchDoesNotExist=Product with batch/serial does not exist
ProductBarcodeDoesNotExist=Product with barcode does not exist

View File

@ -537,8 +537,10 @@ if ($object->id > 0) {
// Popup for mass barcode scanning // Popup for mass barcode scanning
if ($action == 'updatebyscaning') { if ($action == 'updatebyscaning') {
if ($permissiontoadd) {
print '<script>'; print '<script>';
print 'function barcodescannerjs(){ print 'function barcodescannerjs(){
console.log("We catch inputs in sacnner box");
var barcodemode = $("input[name=barcodemode]:checked").val(); var barcodemode = $("input[name=barcodemode]:checked").val();
var barcodeproductqty = $("input[name=barcodeproductqty]").val(); var barcodeproductqty = $("input[name=barcodeproductqty]").val();
var textarea = $("textarea[name=barcodelist]").val(); var textarea = $("textarea[name=barcodelist]").val();
@ -558,35 +560,72 @@ if ($object->id > 0) {
if(productbatchcode != null){ if(productbatchcode != null){
productbatchcode = productbatchcode.data; productbatchcode = productbatchcode.data;
} }
if(barcodemode != "barcodeforproduct"){
tabproduct.push({\'Id\':id,\'Warehouse\':warehouse,\'Barecode\':productbarcode,\'Batch\':productbatchcode,\'Qty\':0}); tabproduct.forEach(product=>{
if(product.Batch == productbatchcode){
alert("'.$langs->trans('ErrorSameBatchNumber').': "+productbatchcode);
throw"'.$langs->trans('ErrorSameBatchNumber').': "+productbatchcode;
}
})
}
tabproduct.push({\'Id\':id,\'Warehouse\':warehouse,\'Barcode\':productbarcode,\'Batch\':productbatchcode,\'Qty\':0});
}) })
switch(barcodemode){ switch(barcodemode){
case "barcodeforautodetect": case "barcodeforautodetect":
textarray.forEach(function(element,index){
console.log("Product autodetect "+(index+=1)+": "+element);
BatchCodeDoesNotExist=0;
tabproduct.forEach(product => {
if(product.Batch == element || product.Barcode == element){
product.Qty+=1;
}else{
BatchCodeDoesNotExist+=1;
}
})
if(BatchCodeDoesNotExist >= tabproduct.length){
alert("'.$langs->trans('ProductDoesNotExist').': "+element);
}
})
break; break;
case "barcodeforproduct": case "barcodeforproduct":
textarray.forEach(function(element,index){ textarray.forEach(function(element,index){
console.log("Product "+(index+=1)+": "+element); console.log("Product "+(index+=1)+": "+element);
BarCodeDoesNotExist=0; BarCodeDoesNotExist=0;
tabproduct.forEach(product => { tabproduct.forEach(product => {
if(product.Barecode == element){ if(product.Barcode == element){
product.Qty+=1; product.Qty+=1;
}else{ }else{
BarCodeDoesNotExist+=1; BarCodeDoesNotExist+=1;
} }
}) })
if(BarCodeDoesNotExist >= tabproduct.length){ if(BarCodeDoesNotExist >= tabproduct.length){
alert("'.$langs->trans('ProductDoesNotExist').': "+element); alert("'.$langs->trans('ProductBarcodeDoesNotExist').': "+element);
} }
}) })
break; break;
case "barcodeforlotserial": case "barcodeforlotserial":
textarray.forEach(function(element,index){
console.log("Product batch/serial "+(index+=1)+": "+element);
BatchCodeDoesNotExist=0;
tabproduct.forEach(product => {
if(product.Batch == element){
product.Qty+=1;
}else{
BatchCodeDoesNotExist+=1;
}
})
if(BatchCodeDoesNotExist >= tabproduct.length){
alert("'.$langs->trans('ProductBatchDoesNotExist').': "+element);
}
})
break; break;
default: default:
alert("'.$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");
$("#"+product.Id+"_input")[0].value = product.Qty*barcodeproductqty; $("#"+product.Id+"_input")[0].value = product.Qty*barcodeproductqty;
} }
}) })
@ -594,11 +633,24 @@ if ($object->id > 0) {
} }
}'; }';
print '</script>'; print '</script>';
}
include DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; include DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$formother = new FormOther($db); $formother = new FormOther($db);
print $formother->getHTMLScannerForm(); print $formother->getHTMLScannerForm();
} }
//Call method to undo changes in real qty
print '<script>';
print 'jQuery(document).ready(function() {
$(".undochangesqty").on("click",function undochangesqty(){
id = this.id;
id = id.split("_")[1];
tmpvalue = $("#id_"+id+"_input_tmp").val()
$("#id_"+id+"_input")[0].value = tmpvalue;
document.forms["formrecord"].submit();
});
});';
print '</script>';
print '<div class="fichecenter">'; print '<div class="fichecenter">';
//print '<div class="fichehalfleft">'; //print '<div class="fichehalfleft">';
@ -722,9 +774,10 @@ if ($object->id > 0) {
print '<input type="text" class="maxwidth75 right realqty" name="id_'.$obj->rowid.'" id="id_'.$obj->rowid.'_input" value="'.$qty_view.'">'; print '<input type="text" class="maxwidth75 right realqty" name="id_'.$obj->rowid.'" id="id_'.$obj->rowid.'_input" value="'.$qty_view.'">';
print '</td>'; print '</td>';
print '<td class="right">'; print '<td class="right">';
print '<a id="undochangesqty_'.$obj->rowid.'" href="#" class="undochangesqty"><span class="fas fa-undo pictoundo" ></span></a> &nbsp';
print '<a class="reposition" href="'.DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&lineid='.$obj->rowid.'&action=deleteline&token='.newToken().'">'.img_delete().'</a>'; print '<a class="reposition" href="'.DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&lineid='.$obj->rowid.'&action=deleteline&token='.newToken().'">'.img_delete().'</a>';
print '</td>'; print '</td>';
$qty_tmp = GETPOST("id_".$obj->rowid."_input_tmp") && price2num(GETPOST("id_".$obj->rowid."_input_tmp", 'MS')) >= 0 ? GETPOST("id_".$obj->rowid."_input_tmp") : $qty_view; $qty_tmp = price2num(GETPOST("id_".$obj->rowid."_input_tmp", 'MS')) >= 0 ? GETPOST("id_".$obj->rowid."_input_tmp") : $qty_view;
print '<input type="hidden" class="maxwidth75 right realqty" name="id_'.$obj->rowid.'_input_tmp" id="id_'.$obj->rowid.'_input_tmp" value="'.$qty_tmp.'">'; print '<input type="hidden" class="maxwidth75 right realqty" name="id_'.$obj->rowid.'_input_tmp" id="id_'.$obj->rowid.'_input_tmp" value="'.$qty_tmp.'">';
} else { } else {
print $obj->qty_view; print $obj->qty_view;