warehouse layers [switchable]
This commit is contained in:
+136
-82
@@ -68,22 +68,22 @@
|
||||
<select name="warehouse" id="warehouse" class="form-select" required></select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 col-lg-6">
|
||||
<label for="zone" class="form-label">Zone</label>
|
||||
<select name="zone" id="zone" class="form-select" required>
|
||||
<div class="mb-3 col-lg-6" id="group_zone">
|
||||
<label for="zone" class="form-label" id="label_zone">Zone</label>
|
||||
<select name="zone" id="zone" class="form-select">
|
||||
<option value="">Please select zone</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 col-lg-6">
|
||||
<label for="aisle" class="form-label">Aisle</label>
|
||||
<select name="aisle" id="aisle" class="form-select" required>
|
||||
<div class="mb-3 col-lg-6" id="group_aisle">
|
||||
<label for="aisle" class="form-label" id="label_aisle">Aisle</label>
|
||||
<select name="aisle" id="aisle" class="form-select">
|
||||
<option value="">Please select aisle</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 col-lg-6">
|
||||
<label for="rack" class="form-label">Rack</label>
|
||||
<div class="mb-3 col-lg-6" id="group_rack">
|
||||
<label for="rack" class="form-label" id="label_rack">Rack</label>
|
||||
<select name="rack" id="rack" class="form-select" required>
|
||||
<option value="">Please select rack</option>
|
||||
</select>
|
||||
@@ -118,24 +118,72 @@
|
||||
<?php require "../include_ending.php";?>
|
||||
|
||||
<script>
|
||||
|
||||
var advanced = false;
|
||||
var label_rack = 'Location';
|
||||
var label_zone = 'Zone';
|
||||
var label_aisle = 'Aisle';
|
||||
|
||||
function load_location_config(callback) {
|
||||
return ajax_request({
|
||||
url: server_url + 'setting/api/engine/company_setting.php',
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var s = res.output;
|
||||
advanced = s.advanced_location == 1;
|
||||
label_rack = s.location_label_rack || (advanced ? 'Rack' : 'Location');
|
||||
label_zone = s.location_label_zone || 'Zone';
|
||||
label_aisle = s.location_label_aisle || 'Aisle';
|
||||
if (callback) callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apply_location_labels() {
|
||||
if (advanced) {
|
||||
$('#group_zone').show();
|
||||
$('#group_aisle').show();
|
||||
$('#label_zone').text(label_zone);
|
||||
$('#label_aisle').text(label_aisle);
|
||||
$('#label_rack').text(label_rack);
|
||||
$('#zone').attr('placeholder', 'Please select ' + label_zone.toLowerCase());
|
||||
$('#aisle').attr('placeholder', 'Please select ' + label_aisle.toLowerCase());
|
||||
$('#rack').attr('placeholder', 'Please select ' + label_rack.toLowerCase());
|
||||
} else {
|
||||
$('#group_zone').hide();
|
||||
$('#group_aisle').hide();
|
||||
$('#label_rack').text(label_rack);
|
||||
$('#rack').attr('placeholder', 'Please select ' + label_rack.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
function manage_stock_in() {
|
||||
|
||||
// In simple mode, mirror rack value to zone and aisle
|
||||
if (!advanced) {
|
||||
var rack_val = $('#rack').val();
|
||||
$('#zone').val(rack_val);
|
||||
$('#aisle').val(rack_val);
|
||||
}
|
||||
|
||||
return ajax_request({
|
||||
url: "<?php echo $server_url?>ics/api/engine/manage_stock_in.php",
|
||||
url: '<?php echo $server_url?>ics/api/engine/manage_stock_in.php',
|
||||
autoPrepare: true,
|
||||
checkRequired: 1,
|
||||
debugMode: 0,
|
||||
data: {
|
||||
"contact_id": $("#contact").attr('data-id'),
|
||||
"lot_number": $("#lot_number").val(),
|
||||
"expiry_date": $("#expiry_date").val(),
|
||||
"serial_number": $("#serial_number").val()
|
||||
'contact_id': $('#contact').attr('data-id'),
|
||||
'lot_number': $('#lot_number').val(),
|
||||
'expiry_date': $('#expiry_date').val(),
|
||||
'serial_number': $('#serial_number').val(),
|
||||
'zone': $('#zone').val(),
|
||||
'aisle': $('#aisle').val(),
|
||||
},
|
||||
action: 'manage',
|
||||
onSuccess: function(res) {
|
||||
|
||||
window.location.href = "<?php echo $server_url?>ics/stock_in.php";
|
||||
|
||||
onSuccess: function() {
|
||||
window.location.href = '<?php echo $server_url?>ics/stock_in.php';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -179,11 +227,11 @@
|
||||
debugMode: 0,
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var option = `<option value="">Please select zone</option>`;
|
||||
var option = '<option value="">Please select ' + label_zone.toLowerCase() + '</option>';
|
||||
$.each(res.output, function(key, item) {
|
||||
option += `<option value='${item.zone}'>${item.zone}</option>`;
|
||||
})
|
||||
$(`select#zone`).html(option);
|
||||
option += '<option value="' + item.zone + '">' + item.zone + '</option>';
|
||||
});
|
||||
$('select#zone').html(option);
|
||||
|
||||
if (callback) callback(); // ← add this
|
||||
}
|
||||
@@ -205,11 +253,11 @@
|
||||
},
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var option = `<option value="">Please select aisle</option>`;
|
||||
var option = '<option value="">Please select ' + label_aisle.toLowerCase() + '</option>';
|
||||
$.each(res.output, function(key, item) {
|
||||
option += `<option value='${item}'>${item}</option>`;
|
||||
})
|
||||
$(`select#aisle`).html(option);
|
||||
option += '<option value="' + item + '">' + item + '</option>';
|
||||
});
|
||||
$('select#aisle').html(option);
|
||||
|
||||
if (callback) callback(); // ← add this
|
||||
}
|
||||
@@ -231,11 +279,11 @@
|
||||
},
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var option = `<option value="">Please select rack</option>`;
|
||||
var option = '<option value="">Please select ' + label_rack.toLowerCase() + '</option>';
|
||||
$.each(res.output, function(key, item) {
|
||||
option += `<option value='${item}'>${item}</option>`;
|
||||
})
|
||||
$(`select#rack`).html(option);
|
||||
option += '<option value="' + item + '">' + item + '</option>';
|
||||
});
|
||||
$('select#rack').html(option);
|
||||
|
||||
if (callback) callback(); // ← add this
|
||||
}
|
||||
@@ -261,55 +309,53 @@
|
||||
|
||||
var data = res.output;
|
||||
|
||||
// 1. Set warehouse (already populated from page load)
|
||||
$('#warehouse').val('<?php echo $_GET["wh"];?>').attr('disabled', true);
|
||||
|
||||
$(`#warehouse`).val('<?php echo $_GET["wh"];?>').attr('disabled', true); // set warehouse BEFORE retrieve_zone
|
||||
function populate_fields() {
|
||||
$.each(data, function(key, item) {
|
||||
if (!['warehouse', 'zone', 'aisle', 'rack'].includes(key)) {
|
||||
$('#' + key).val(item);
|
||||
}
|
||||
});
|
||||
$('#contact').val(data.contact_name)
|
||||
.attr('secondary', data.contact_name)
|
||||
.attr('data-id', data.contact_id);
|
||||
$('#product_name').val(data.product_name);
|
||||
$('#lot_number').val(data.lot_number || '').prop('disabled', true);
|
||||
$('#serial_number').val(data.serial_number || '').prop('disabled', true);
|
||||
if (data.lot_number) {
|
||||
if (expiryPicker) { expiryPicker.setDate(data.expiry_date || '', true, 'Y-m-d'); }
|
||||
$('#expiry_date').prop('disabled', true)
|
||||
.attr('title', 'Expiry date is locked for existing lots')
|
||||
.val(data.expiry_date);
|
||||
if (expiryPicker && expiryPicker.altInput) { expiryPicker.altInput.disabled = true; }
|
||||
} else {
|
||||
if (expiryPicker) { expiryPicker.clear(); }
|
||||
}
|
||||
$('#product_sku').attr('secondary', data.product_sku);
|
||||
$('#product_sku, #quantity').prop('disabled', true);
|
||||
$('button[type=submit]').text('Update');
|
||||
$('button[type=reset]').hide();
|
||||
}
|
||||
|
||||
// 2. Retrieve zone (autoPrepare reads warehouse value)
|
||||
retrieve_zone('to', function() {
|
||||
$(`select#zone`).val(data.zone).attr('disabled', true); // set zone BEFORE retrieve_aisle
|
||||
|
||||
// 3. Retrieve aisle (autoPrepare reads zone value)
|
||||
retrieve_aisle('to', function() {
|
||||
$(`#aisle`).val(data.aisle).attr('disabled', true); // set aisle BEFORE retrieve_rack
|
||||
|
||||
// 4. Retrieve rack (autoPrepare reads aisle value)
|
||||
retrieve_rack('to', function() {
|
||||
$(`#rack`).val(data.rack).attr('disabled', true);
|
||||
|
||||
// retrieve for edit
|
||||
$.each(data, function(key, item) {
|
||||
if (!['warehouse', 'zone', 'aisle', 'rack'].includes(key)) {
|
||||
$(`#${key}`).val(item);
|
||||
}
|
||||
if (advanced) {
|
||||
retrieve_zone('to', function() {
|
||||
$('select#zone').val(data.zone).attr('disabled', true);
|
||||
retrieve_aisle('to', function() {
|
||||
$('#aisle').val(data.aisle).attr('disabled', true);
|
||||
retrieve_rack('to', function() {
|
||||
$('#rack').val(data.rack).attr('disabled', true);
|
||||
populate_fields();
|
||||
});
|
||||
|
||||
$('#contact').val(data.contact_name)
|
||||
.attr('secondary', data.contact_name)
|
||||
.attr('data-id', data.contact_id);
|
||||
|
||||
$('#product_name').val(data.product_name);
|
||||
$('#lot_number').val(data.lot_number || '').prop('disabled', true);
|
||||
$('#serial_number').val(data.serial_number || '').prop('disabled', true);
|
||||
if (data.lot_number) {
|
||||
if (expiryPicker) { expiryPicker.setDate(data.expiry_date || '', true, 'Y-m-d'); }
|
||||
$('#expiry_date').prop('disabled', true).attr('title', 'Expiry date is locked for existing lots')
|
||||
.val(data.expiry_date);
|
||||
if (expiryPicker && expiryPicker.altInput) { expiryPicker.altInput.disabled = true; }
|
||||
} else {
|
||||
if (expiryPicker) { expiryPicker.clear(); }
|
||||
}
|
||||
$('#product_sku').attr('secondary', data.product_sku);
|
||||
|
||||
$('#product_sku,#quantity').prop('disabled', true);
|
||||
|
||||
$(`button[type=submit]`).text('Update');
|
||||
$(`button[type=reset]`).hide();
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
// Set re
|
||||
} else {
|
||||
// Simple mode — skip zone/aisle cascade
|
||||
retrieve_rack('to', function() {
|
||||
$('#rack').val(data.rack).attr('disabled', true);
|
||||
populate_fields();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -351,13 +397,16 @@
|
||||
if (wh) {
|
||||
$('#warehouse').val(wh).prop('disabled', true);
|
||||
|
||||
// Chain-load location selects for the locked warehouse.
|
||||
// Unlike edit mode, we DON'T preselect zone/aisle/rack — the user picks.
|
||||
retrieve_zone('to', function() {
|
||||
retrieve_aisle('to', function() {
|
||||
retrieve_rack('to');
|
||||
// Chain-load location selects — skip zone/aisle in simple mode
|
||||
if (advanced) {
|
||||
retrieve_zone('to', function() {
|
||||
retrieve_aisle('to', function() {
|
||||
retrieve_rack('to');
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
retrieve_rack('to');
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -366,6 +415,7 @@
|
||||
|
||||
$(async function() {
|
||||
try {
|
||||
await load_location_config(apply_location_labels);
|
||||
await retrieve_warehouse('to');
|
||||
await retrieve_for_edit();
|
||||
|
||||
@@ -395,15 +445,19 @@
|
||||
|
||||
<?php if(empty($_GET["id"])){ ?>
|
||||
$("select#warehouse").change(function() {
|
||||
retrieve_zone('to');
|
||||
if (advanced) {
|
||||
retrieve_zone('to');
|
||||
} else {
|
||||
retrieve_rack('to');
|
||||
}
|
||||
});
|
||||
|
||||
$("select#zone").change(function() {
|
||||
retrieve_aisle('to');
|
||||
if (advanced) retrieve_aisle('to');
|
||||
});
|
||||
|
||||
$("select#aisle").change(function() {
|
||||
retrieve_rack('to');
|
||||
if (advanced) retrieve_rack('to');
|
||||
});
|
||||
|
||||
<?php } ?>
|
||||
|
||||
Reference in New Issue
Block a user