Barcode Operations

This commit is contained in:
Thanakorn S
2026-05-06 15:27:52 +07:00
parent d8131a01b7
commit ada701bd53
22 changed files with 2449 additions and 35 deletions
+127 -2
View File
@@ -30,8 +30,13 @@
<!-- Product Name -->
<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>
@@ -130,6 +135,8 @@
var label_rack = 'Location';
var label_zone = 'Zone';
var label_aisle = 'Aisle';
var scan_sku_ready = false;
var scan_location_ready = false;
function load_location_config(callback) {
return ajax_request({
@@ -166,6 +173,100 @@
}
}
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);
}
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 || '');
$('#lot_number').val(data.lot_number || '');
$('#serial_number').val(data.serial_number || '');
$('#quantity').val($('#quantity').val() || 1);
scan_sku_ready = true;
scan_location_ready = false;
$('#warehouse').val('');
$('#zone').val('');
$('#aisle').val('');
$('#rack').val('');
$('#product_sku').trigger('blur');
}
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('in', 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_in_inputs() {
$('form')[0].reset();
$('#product_sku').removeAttr('secondary').prop('disabled', false);
$('#product_name').removeAttr('secondary').val('');
$('#lot_number, #serial_number, #expiry_date').prop('disabled', false);
$('#contact').removeAttr('secondary data-id');
if (expiryPicker) expiryPicker.clear();
if (!advanced) {
$('#zone').val('');
$('#aisle').val('');
}
$('#warehouse').val('');
$('#zone').val('');
$('#aisle').val('');
$('#rack').val('');
scan_sku_ready = false;
scan_location_ready = false;
$('#product_sku').focus();
}
function save_scanned_stock_in() {
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_in();
}
function manage_stock_in() {
var rack_val = $('#rack').val();
@@ -200,7 +301,11 @@
},
action: 'manage',
onSuccess: function() {
<?php if(empty($_GET["id"])){ ?>
reset_stock_in_inputs();
<?php } else { ?>
window.location.href = '<?php echo $server_url?>ics/stock_in.php';
<?php } ?>
}
});
@@ -238,6 +343,8 @@
url: "<?php echo $server_url?>ics/api/engine/retrieve_warehouse.php",
autoPrepare: true,
checkRequired: 0,
noLoading: true,
queueLock: false,
data: {
"type": type
},
@@ -262,6 +369,7 @@
autoPrepare: true,
checkRequired: 0,
noLoading: true,
queueLock: false,
data : {
"type": type
},
@@ -289,6 +397,7 @@
autoPrepare: true,
checkRequired: 0,
noLoading: true,
queueLock: false,
data: {
"type": type
},
@@ -315,6 +424,7 @@
autoPrepare: true,
checkRequired: 0,
noLoading: true,
queueLock: false,
data: {
"type": type
},
@@ -462,6 +572,14 @@
await load_location_config(apply_location_labels);
await retrieve_warehouse('to');
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);
}
});
<?php if(!empty($_GET["sku"])){ ?>
prefill_from_restock();
@@ -488,6 +606,13 @@
<?php if(empty($_GET["id"])){ ?>
$(document).on('keydown', function(e) {
if (e.key === 'F2') {
e.preventDefault();
save_scanned_stock_in();
}
});
$("select#warehouse").change(function() {
if (advanced) {
retrieve_zone('to');