400 lines
12 KiB
PHP
400 lines
12 KiB
PHP
<?php
|
|
session_start();
|
|
require '../config.php';
|
|
require '../include_header.php';
|
|
|
|
?>
|
|
|
|
<body>
|
|
<?php require '../include_topbar.php';?>
|
|
<?php require '../include_sidebar.php';?>
|
|
|
|
|
|
<!-- MAIN CONTENT -->
|
|
<main id="content" class="content py-15">
|
|
<div class="container-fluid">
|
|
<div class="row ">
|
|
<div class="col-12">
|
|
<div class="mb-6">
|
|
<h1 class="fs-3 mb-0">Stock Transfer</h1>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row g">
|
|
<div class="col-lg-8 col-12">
|
|
<div class="card">
|
|
<div class="card-body p-5">
|
|
<h2 class="fs-5 mb-4">Move Stock</h2>
|
|
<form class="row gx-5">
|
|
<!-- 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>
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="product_name" class="form-label">Name</label>
|
|
<input type="text" id="product_name" class="form-control" autocomplete="off" disabled>
|
|
</div>
|
|
|
|
<!-- SKU or Product Code -->
|
|
<div class="mb-3 col-lg-6">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Warehouse -->
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="warehouse" class="form-label">From Warehouse</label>
|
|
<select name="warehouse" id="warehouse_from" role="from" class="form-select" required>
|
|
<option value="">Please select warehouse</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="zone" class="form-label">From Zone</label>
|
|
<select name="zone" id="zone_from" role="from" class="form-select" required>
|
|
<option value="">Please select zone</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="aisle" class="form-label">From Aisle</label>
|
|
<select name="aisle" id="aisle_from" role="from" class="form-select" required>
|
|
<option value="">Please select aisle</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="rack" class="form-label">From Rack</label>
|
|
<select name="rack" id="rack_from" role="from" class="form-select" required>
|
|
<option value="">Please select rack</option>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
<!-- Warehouse -->
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="warehouse" class="form-label">To Warehouse</label>
|
|
<select name="warehouse" id="warehouse_to" role="to" class="form-select" required>
|
|
<option value="">Please select warehouse</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="zone" class="form-label">To Zone</label>
|
|
<select name="zone" id="zone_to" role="to" class="form-select" required>
|
|
<option value="">Please select zone</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="aisle" class="form-label">To Aisle</label>
|
|
<select name="aisle" id="aisle_to" role="to" class="form-select" required>
|
|
<option value="">Please select aisle</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3 col-lg-3">
|
|
<label for="rack" class="form-label">To Rack</label>
|
|
<select name="rack" id="rack_to" role="to" class="form-select" required>
|
|
<option value="">Please select rack</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Contact -->
|
|
<div class="mb-3 col-lg-6">
|
|
<label for="contact" class="form-label">Contact</label>
|
|
<input type="text" class="form-control contact_search" id="contact" placeholder="Enter contact name">
|
|
</div>
|
|
|
|
|
|
<!-- Notes / Description -->
|
|
<div class="mb-3 col-lg-12">
|
|
<label for="description" class="form-label">Notes / Description</label>
|
|
<textarea class="form-control" id="description" rows="3" placeholder="Enter any notes"></textarea>
|
|
</div>
|
|
|
|
<!-- Submit Button -->
|
|
<div class="mb-3 col-lg-12">
|
|
<button type="submit" class="btn btn-primary" onclick="manage_stock_transfer();">Add Stock</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
|
|
<?php require "../include_ending.php";?>
|
|
|
|
<script>
|
|
function manage_stock_transfer() {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/manage_stock_transfer.php",
|
|
autoPrepare: true,
|
|
checkRequired: 1,
|
|
debugMode: 0,
|
|
data: {
|
|
"contact_id": $("#contact").attr('data-id')
|
|
},
|
|
action: 'manage',
|
|
onSuccess: function(res) {
|
|
|
|
window.location.href = "<?php echo $server_url?>ics/stock_transfer.php";
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieve_warehouse(type) {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/retrieve_warehouse.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
data: {
|
|
"type": type
|
|
},
|
|
action: 'read',
|
|
debugMode: 0,
|
|
onSuccess: function(res) {
|
|
var option = `<option value="">Please select warehouse</option>`;
|
|
$.each(res.output, function(key, item) {
|
|
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
|
|
})
|
|
$(`select[name='warehouse'][role='${type}']`).html(option);
|
|
if(!type) {
|
|
$(`select[name='warehouse']`).html(option);
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieve_zone(type, callback) {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/retrieve_zone.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
data: {
|
|
"type": type
|
|
},
|
|
noLoading: true,
|
|
debugMode: 0,
|
|
action: 'read',
|
|
onSuccess: function(res) {
|
|
var option = `<option value="">Please select zone</option>`;
|
|
$.each(res.output, function(key, item) {
|
|
option += `<option value='${item.zone}'>${item.zone}</option>`;
|
|
})
|
|
$(`select[name='zone'][role='${type}']`).html(option);
|
|
|
|
if(!type) {
|
|
$(`select[name='zone']`).html(option);
|
|
}
|
|
|
|
if (callback) callback(); // ← add this
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieve_aisle(type, callback) {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/retrieve_aisle.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
data: {
|
|
"type": type
|
|
},
|
|
noLoading: true,
|
|
action: 'read',
|
|
debugMode: 0,
|
|
onSuccess: function(res) {
|
|
var option = `<option value="">Please select aisle</option>`;
|
|
$.each(res.output, function(key, item) {
|
|
option += `<option value='${item}'>${item}</option>`;
|
|
})
|
|
$(`select[name='aisle'][role='${type}']`).html(option);
|
|
|
|
if(!type) {
|
|
$(`select[name='aisle']`).html(option);
|
|
}
|
|
|
|
if (callback) callback(); // ← add this
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieve_rack(type, callback) {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/retrieve_rack.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
data: {
|
|
"type": type
|
|
},
|
|
noLoading: true,
|
|
action: 'read',
|
|
onSuccess: function(res) {
|
|
var option = `<option value="">Please select rack</option>`;
|
|
$.each(res.output, function(key, item) {
|
|
option += `<option value='${item}'>${item}</option>`;
|
|
})
|
|
$(`select[name='rack'][role='${type}']`).html(option);
|
|
|
|
if(!type) {
|
|
$(`select[name='rack']`).html(option);
|
|
}
|
|
|
|
if (callback) callback(); // ← add this
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieve_for_edit() {
|
|
|
|
<?php if(empty($_GET["id"])){ ?>
|
|
return false;
|
|
<?php } ?>
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/retrieve_stock_transfer.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
debugMode: 0,
|
|
action: 'read',
|
|
onSuccess: function(res) {
|
|
|
|
var type = 'from';
|
|
var warehouse = res.output.ref.ref_warehouse;
|
|
var data = res.output;
|
|
|
|
/**
|
|
* From warehouse
|
|
*/
|
|
$(`select[name='warehouse'][role=${type}]`).val(warehouse).attr('disabled', true);
|
|
|
|
retrieve_zone(type, function() {
|
|
$(`select[name='zone'][role=${type}]`).val(data.zone).attr('disabled', true);
|
|
|
|
retrieve_aisle(type, function() {
|
|
$(`select[name='aisle'][role=${type}]`).val(data.aisle).attr('disabled', true);
|
|
|
|
retrieve_rack(type, function() {
|
|
$(`select[name='rack'][role=${type}]`).val(data.rack).attr('disabled', true);
|
|
|
|
type = 'to';
|
|
warehouse = res.output.ref_warehouse;
|
|
data = res.output.ref;
|
|
|
|
/**
|
|
* To warehouse
|
|
*/
|
|
$(`select[name='warehouse'][role=${type}]`).val(warehouse).attr('disabled', true);
|
|
|
|
retrieve_zone(type, function() {
|
|
$(`select[name='zone'][role=${type}]`).val(data.zone).attr('disabled', true);
|
|
|
|
retrieve_aisle(type, function() {
|
|
$(`select[name='aisle'][role=${type}]`).val(data.aisle).attr('disabled',true);
|
|
|
|
retrieve_rack(type, function() {
|
|
$(`select[name='rack'][role=${type}]`).val(data.rack).attr('disabled',true);
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|
|
});
|
|
});
|
|
|
|
var data = res.output;
|
|
|
|
// retrieve for edit
|
|
$.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);
|
|
console.log(data);
|
|
$('#product_name').val(data.product_name);
|
|
$('#product_sku').attr('secondary', data.product_sku);
|
|
|
|
$(`button[type=submit]`).text('Update');
|
|
$(`button[type=reset]`).hide();
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(async function() {
|
|
try {
|
|
await retrieve_warehouse('from');
|
|
await retrieve_warehouse('to');
|
|
await retrieve_for_edit();
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
});
|
|
|
|
$(`#product_sku`).on('blur', function() {
|
|
$(async function() {
|
|
try {
|
|
await retrieve_warehouse('from');
|
|
await retrieve_warehouse('to');
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
})
|
|
});
|
|
|
|
<?php if(empty($_GET["id"])){ ?>
|
|
$("select[name='warehouse']").change(function() {
|
|
retrieve_zone($(this).attr('role'));
|
|
});
|
|
|
|
$("select[name='zone']").change(function() {
|
|
retrieve_aisle($(this).attr('role'));
|
|
});
|
|
|
|
$("select[name='aisle']").change(function() {
|
|
retrieve_rack($(this).attr('role'));
|
|
});
|
|
|
|
<?php } ?>
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|