Barcode Operations
This commit is contained in:
@@ -28,8 +28,13 @@
|
||||
<!-- Step 1: Product -->
|
||||
<div class="mb-3 col-lg-3">
|
||||
<label for="product_sku" class="form-label">SKU</label>
|
||||
<input type="text" id="product_sku" class="form-control product_search"
|
||||
placeholder="Type product sku..." autocomplete="off" required>
|
||||
<div class="input-group">
|
||||
<input type="text" id="product_sku" class="form-control product_search"
|
||||
placeholder="Type product sku..." autocomplete="off" required>
|
||||
<button class="btn btn-outline-secondary" type="button" onclick="scanner.open_camera()" title="Scan barcode label">
|
||||
<i class="ti ti-scan"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 col-lg-3">
|
||||
<label for="product_name" class="form-label">Name</label>
|
||||
@@ -117,6 +122,97 @@
|
||||
var label_rack = 'Location';
|
||||
var label_zone = 'Zone';
|
||||
var label_aisle = 'Aisle';
|
||||
var scan_sku_ready = false;
|
||||
var scan_location_ready = false;
|
||||
var pending_scan_lot = '';
|
||||
var pending_scan_serial = '';
|
||||
|
||||
function set_select_value(selector, value, label) {
|
||||
if (!value) return;
|
||||
var $select = $(selector);
|
||||
if (!$select.find(`option[value="${value}"]`).length) {
|
||||
$select.append(`<option value="${value}">${label || value}</option>`);
|
||||
}
|
||||
$select.val(value).prop('disabled', false);
|
||||
}
|
||||
|
||||
function apply_sku_label_scan(data) {
|
||||
$('#product_sku').val(data.sku).attr('secondary', data.sku);
|
||||
$('#product_name').val(data.product_name || '').attr('secondary', data.product_name || '');
|
||||
pending_scan_lot = data.lot_number || '';
|
||||
pending_scan_serial = data.serial_number || '';
|
||||
set_select_value('#lot_number', data.lot_number, data.lot_number);
|
||||
set_select_value('#serial_number', data.serial_number, data.serial_number);
|
||||
scan_sku_ready = true;
|
||||
scan_location_ready = false;
|
||||
reset_location();
|
||||
retrieve_active_lot();
|
||||
}
|
||||
|
||||
function apply_location_label_scan(data) {
|
||||
if (!scan_sku_ready && !($('#product_sku').attr('secondary') || $('#product_sku').val())) {
|
||||
bootbox.alert('Scan the SKU label first, then scan the location label.');
|
||||
return;
|
||||
}
|
||||
validate_scanned_location('out', data, function() {
|
||||
set_select_value('#warehouse', data.warehouse_id, data.warehouse_id);
|
||||
if (advanced) {
|
||||
set_select_value('#zone', data.zone, data.zone);
|
||||
set_select_value('#aisle', data.aisle, data.aisle);
|
||||
}
|
||||
set_select_value('#rack', data.rack, data.rack);
|
||||
scan_location_ready = true;
|
||||
});
|
||||
}
|
||||
|
||||
function validate_scanned_location(mode, data, onSuccess) {
|
||||
ajax_request({
|
||||
url: '<?php echo $server_url?>ics/api/engine/validate_scan_location.php',
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
queueLock: false,
|
||||
noLoading: true,
|
||||
data: {
|
||||
mode: mode,
|
||||
warehouse_id: data.warehouse_id,
|
||||
zone: data.zone,
|
||||
aisle: data.aisle,
|
||||
rack: data.rack,
|
||||
product_sku: $('#product_sku').attr('secondary') || $('#product_sku').val(),
|
||||
lot_number: $('#lot_number').val(),
|
||||
serial_number: $('#serial_number').val()
|
||||
},
|
||||
onSuccess: onSuccess
|
||||
});
|
||||
}
|
||||
|
||||
function reset_stock_out_inputs() {
|
||||
$('form')[0].reset();
|
||||
$('#product_sku').removeAttr('secondary').prop('disabled', false);
|
||||
$('#product_name').removeAttr('secondary').val('');
|
||||
$('#lot_number').html('<option value="">Select lot...</option>').prop('disabled', false);
|
||||
$('#serial_number').html('<option value="">Select serial...</option>').prop('disabled', false);
|
||||
$('#contact').removeAttr('secondary data-id');
|
||||
reset_location();
|
||||
scan_sku_ready = false;
|
||||
scan_location_ready = false;
|
||||
pending_scan_lot = '';
|
||||
pending_scan_serial = '';
|
||||
$('#product_sku').focus();
|
||||
}
|
||||
|
||||
function save_scanned_stock_out() {
|
||||
if (!scan_sku_ready && !($('#product_sku').attr('secondary') || $('#product_sku').val())) {
|
||||
bootbox.alert('Scan the SKU label first.');
|
||||
return;
|
||||
}
|
||||
if (!scan_location_ready && !$('#rack').val()) {
|
||||
bootbox.alert('Scan the location label before saving.');
|
||||
return;
|
||||
}
|
||||
manage_stock_out();
|
||||
}
|
||||
|
||||
function load_location_config(callback) {
|
||||
return ajax_request({
|
||||
@@ -171,10 +267,16 @@
|
||||
'rack': rack_val,
|
||||
'product_sku': sku_val,
|
||||
'warehouse': wh_val,
|
||||
'lot_number': $('#lot_number').val(),
|
||||
'serial_number': $('#serial_number').val(),
|
||||
},
|
||||
action: 'manage',
|
||||
onSuccess: function() {
|
||||
<?php if(empty($_GET["id"])){ ?>
|
||||
reset_stock_out_inputs();
|
||||
<?php } else { ?>
|
||||
window.location.href = '<?php echo $server_url?>ics/stock_out.php';
|
||||
<?php } ?>
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -215,6 +317,7 @@
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
noLoading: true,
|
||||
queueLock: false,
|
||||
action: 'read',
|
||||
data: { "product_sku": sku },
|
||||
onSuccess: function(res) {
|
||||
@@ -226,10 +329,18 @@
|
||||
option += `<option value="${item.lot_number}">${label}</option>`;
|
||||
});
|
||||
$('#lot_number').html(option).prop('disabled', false);
|
||||
if (pending_scan_lot) {
|
||||
set_select_value('#lot_number', pending_scan_lot, pending_scan_lot);
|
||||
}
|
||||
$('#serial_number').html('<option value="">Select serial... (optional)</option>').prop('disabled', false);
|
||||
|
||||
// Reset downstream
|
||||
reset_location();
|
||||
if (!scan_location_ready) reset_location();
|
||||
if (pending_scan_lot) {
|
||||
retrieve_active_serial();
|
||||
} else {
|
||||
retrieve_warehouse();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -248,6 +359,7 @@
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
noLoading: true,
|
||||
queueLock: false,
|
||||
action: 'read',
|
||||
data: { "product_sku": sku, "lot_number": lot },
|
||||
onSuccess: function(res) {
|
||||
@@ -257,9 +369,14 @@
|
||||
option += `<option value="${serial}">${serial}</option>`;
|
||||
});
|
||||
$('#serial_number').html(option).prop('disabled', false);
|
||||
if (pending_scan_serial) {
|
||||
set_select_value('#serial_number', pending_scan_serial, pending_scan_serial);
|
||||
pending_scan_serial = '';
|
||||
}
|
||||
|
||||
// Reset downstream
|
||||
reset_location();
|
||||
if (!scan_location_ready) reset_location();
|
||||
retrieve_warehouse();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -273,6 +390,7 @@
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
noLoading: true,
|
||||
queueLock: false,
|
||||
data: {
|
||||
"type": 'from',
|
||||
"product_sku": $('#product_sku').attr('secondary') || $('#product_sku').val(),
|
||||
@@ -280,11 +398,13 @@
|
||||
},
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var current = $('#warehouse').val();
|
||||
var option = '<option value="">Select warehouse...</option>';
|
||||
$.each(res.output, function(key, item) {
|
||||
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
|
||||
});
|
||||
$('#warehouse').html(option).prop('disabled', false);
|
||||
if (current) set_select_value('#warehouse', current, current);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -298,6 +418,7 @@
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
noLoading: true,
|
||||
queueLock: false,
|
||||
data: {
|
||||
"warehouse": $('#warehouse').val(),
|
||||
"type": 'from',
|
||||
@@ -324,6 +445,7 @@
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
noLoading: true,
|
||||
queueLock: false,
|
||||
data: {
|
||||
"warehouse": $('#warehouse').val(),
|
||||
"zone": $('#zone').val(),
|
||||
@@ -351,6 +473,7 @@
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
noLoading: true,
|
||||
queueLock: false,
|
||||
data: {
|
||||
"warehouse": $('#warehouse').val(),
|
||||
"zone": $('#zone').val(),
|
||||
@@ -454,6 +577,14 @@
|
||||
await load_location_config(apply_location_labels);
|
||||
await retrieve_warehouse();
|
||||
await retrieve_for_edit();
|
||||
scanner.init({
|
||||
allowRaw: false,
|
||||
allowedTypes: ['sku', 'loc'],
|
||||
onScan: function(sku, product_name, uom, data) {
|
||||
if (data.type === 'sku') apply_sku_label_scan(data);
|
||||
if (data.type === 'loc') apply_location_label_scan(data);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
@@ -462,6 +593,12 @@
|
||||
|
||||
// ── Change handlers (create mode only) ───────────────────────────────
|
||||
<?php if(empty($_GET["id"])){ ?>
|
||||
$(document).on('keydown', function(e) {
|
||||
if (e.key === 'F2') {
|
||||
e.preventDefault();
|
||||
save_scanned_stock_out();
|
||||
}
|
||||
});
|
||||
|
||||
// SKU selected → load lots
|
||||
$('input#product_sku').on('blur', function() {
|
||||
|
||||
Reference in New Issue
Block a user