275 lines
8.1 KiB
PHP
275 lines
8.1 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 d-flex justify-content-between align-items-center">
|
|
<h1 class="fs-3 mb-0">Stock Transfer
|
|
</h1>
|
|
<a href="<?php echo $server_url?>ics/manage_stock_transfer.php" class="btn btn-primary">
|
|
<span><i class="ti ti-plus"></i></span>
|
|
<span>ADD Stock Transfer</span></a>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-5">
|
|
|
|
<div class="mb-3 col-lg-2">
|
|
<input class="form-control" value='Warehouse From' disabled>
|
|
</div>
|
|
<div class="mb-3 col-lg-4">
|
|
<select name="warehouse" id="warehouse" class="form-select" required></select>
|
|
</div>
|
|
<div class="mb-3 col-lg-4">
|
|
<button class='btn btn-secondary' onclick='retrieve_stock_transfer()'>Search</button>
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-body p-5">
|
|
<h2 class="mb-4 fs-5">Item List</h2>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover mb-0 table-centered" id="stock_transfer">
|
|
<thead class="table-primary border-light">
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Product</th>
|
|
<th>Quantity</th>
|
|
<th class="th_loc_zone">Zone</th>
|
|
<th class="th_loc_aisle">Aisle</th>
|
|
<th class="th_loc_rack">Rack</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
<tfoot class="">
|
|
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
|
|
<?php require "../include_ending.php";?>
|
|
|
|
<script>
|
|
var advanced = false;
|
|
var label_rack = 'Location';
|
|
var label_zone = 'Zone';
|
|
var label_aisle = 'Aisle';
|
|
|
|
function apply_location_labels() {
|
|
if (advanced) {
|
|
$('.th_loc_zone').text(label_zone).show();
|
|
$('.th_loc_aisle').text(label_aisle).show();
|
|
$('.th_loc_rack').text(label_rack);
|
|
} else {
|
|
$('.th_loc_zone, .th_loc_aisle').hide();
|
|
$('.th_loc_rack').text(label_rack);
|
|
}
|
|
}
|
|
|
|
function location_cells(item) {
|
|
if (advanced) {
|
|
return `<td class="py-3">${item['zone'] || ''}</td>
|
|
<td class="py-3">${item['aisle'] || ''}</td>
|
|
<td class="py-3">${item['rack'] || ''}</td>`;
|
|
}
|
|
return `<td class="py-3">${item['rack'] || ''}</td>`;
|
|
}
|
|
|
|
function retrieve_stock_transfer() {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/stock_transfer.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
debugMode: 0,
|
|
action: 'read',
|
|
onSuccess: function(res) {
|
|
|
|
// Register the array as a table name
|
|
alasql('CREATE TABLE IF NOT EXISTS stock_transfer');
|
|
alasql.tables.stock_transfer.data = res.output || [];
|
|
|
|
var total_records = alasql.tables.stock_transfer.data.length;
|
|
|
|
var table_id = 'stock_transfer';
|
|
|
|
var page = generate_pagination(table_id, total_records);
|
|
$(`table#${table_id} tfoot`).html(page);
|
|
|
|
// dynamic function name
|
|
if (typeof window[`change_page_${table_id}`] === "function") {
|
|
window[`change_page_${table_id}`](1);
|
|
} else {
|
|
console.error(`Function change_page_${table_id} does not exist.`);
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function change_page_stock_transfer(page_num) {
|
|
|
|
var offset = (page_num - 1) * prop_limit;
|
|
|
|
var page_data = alasql(`SELECT * FROM stock_transfer LIMIT ${prop_limit} OFFSET ${offset}`);
|
|
|
|
var body = ``;
|
|
|
|
var warehouse = $(`select#warehouse`).val();
|
|
|
|
$.each(page_data, function(key, item) {
|
|
body += `<tr>
|
|
<td class="py-3">${format_date(item["date"])}</td>
|
|
<td class="py-3">${item["product_sku"]}: ${item['product_name']}</td>
|
|
<td class="py-3">${item['quantity']}</td>
|
|
${location_cells(item)}
|
|
<td class="py-3">
|
|
${item['status'] == 1 ? '<span class="badge bg-success">Approved</span>' : '<span class="badge bg-warning text-dark">Draft</span>'}
|
|
</td>
|
|
<td class="py-3">
|
|
<a href="<?php echo $server_url?>ics/manage_stock_transfer.php?id=${item['id']}&wh=${warehouse}" class=""><i class="ti ti-eye fs-5"></i></a>
|
|
${item['status'] == 0
|
|
? (auto_approve
|
|
? '<button class="btn btn-sm btn-outline-secondary ms-2" disabled title="Auto-approved on save — no manual approval needed"><i class=\"ti ti-check\"></i></button>'
|
|
: '<button class="btn btn-sm btn-outline-success ms-2" onclick=\"approve_stock('+item['id']+', '+item['warehouse_id']+', \'transfer\')\" title="Approve"><i class=\"ti ti-check\"></i></button>'
|
|
)
|
|
: ''}
|
|
<a href="javascript:void(0);" class="link-danger"
|
|
onclick="delete_stock_transfer($(this),${item['id']})">
|
|
<i class="ti ti-trash ms-2 fs-5"></i>
|
|
</a>
|
|
</td>
|
|
</tr>`;
|
|
})
|
|
|
|
$("table#stock_transfer > tbody").html(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieve_warehouse() {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
action: 'read',
|
|
onSuccess: function(res) {
|
|
var option = ``;
|
|
$.each(res.output, function(key, item) {
|
|
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
|
|
})
|
|
$(`select#warehouse`).html(option);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_stock_transfer(element, id) {
|
|
|
|
return ajax_request({
|
|
url: "<?php echo $server_url?>ics/api/engine/delete_stock_transfer.php",
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
action: 'delete',
|
|
data : {
|
|
id: id,
|
|
wh: $(`select#warehouse`).val()
|
|
},
|
|
onSuccess: function(res) {
|
|
element.closest('tr').remove();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
$(async function() {
|
|
try {
|
|
await load_company_setting();
|
|
await retrieve_warehouse();
|
|
await retrieve_stock_transfer();
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
});
|
|
|
|
// ── Stock approval ────────────────────────────────────────────────────────
|
|
var auto_approve = false; // set from company_setting on load
|
|
|
|
function load_company_setting() {
|
|
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 || {};
|
|
auto_approve = s.default_stock_status == 1;
|
|
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';
|
|
apply_location_labels();
|
|
}
|
|
});
|
|
}
|
|
|
|
function approve_stock(id, warehouse_id, type) {
|
|
bootbox.confirm({
|
|
message: 'Approve this stock record?',
|
|
buttons: { confirm: { label: 'Approve', className: 'btn-success' }, cancel: { label: 'Cancel', className: 'btn-secondary' } },
|
|
callback: function(result) {
|
|
if (!result) return;
|
|
ajax_request({
|
|
url: server_url + 'ics/api/engine/approve_stock.php',
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
action: 'update',
|
|
id: id,
|
|
warehouse: warehouse_id,
|
|
type: type,
|
|
onSuccess: function(res) {
|
|
retrieve_stock_list();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|