Lot, Serial, ExpiryDate

This commit is contained in:
Thanakorn S
2026-04-25 14:37:00 +07:00
parent 92d116fd21
commit 3cc5baba3f
35 changed files with 3518 additions and 1890 deletions
+171 -142
View File
@@ -2,7 +2,6 @@
session_start();
require '../config.php';
require '../include_header.php';
?>
<body>
@@ -13,30 +12,33 @@
<!-- MAIN CONTENT -->
<main id="content" class="content py-15">
<div class="container-fluid">
<div class="row ">
<!-- Page header -->
<div class="row">
<div class="col-12">
<div class="mb-6 d-flex align-items-center justify-content-between">
<div>
<h1 class="fs-3 mb-1">Warehouse / Location Management
</h1>
<h1 class="fs-3 mb-1">Warehouse / Location Management</h1>
<p class="mb-0">Manage your warehouses, storage locations, and capacity.</p>
</div>
</div>
</div>
</div>
<!-- Summary stats -->
<div class="row mb-5 g-5">
<div class="col-12">
<div class="card ">
<div class="card">
<div class="card-body p-0">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap ">
<div class=" p-6 flex-grow-1 d-flex justify-content-between" id="total_warehouse">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap">
<div class="p-6 flex-grow-1 d-flex justify-content-between" id="total_warehouse">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">5</span>
<span class="fs-2 fw-bold mb-3 d-block">—</span>
<span class="fs-5">Total Warehouses</span>
<small class="text-info">
Across 5 locations</small>
<small class="text-info">Across — locations</small>
</div>
<div class="">
<div>
<span class="text-info">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
@@ -48,17 +50,15 @@
</svg>
</span>
</div>
</div>
<div class=" p-6 flex-grow-1 d-flex justify-content-between" id="total_capacity">
<div class="p-6 flex-grow-1 d-flex justify-content-between" id="total_capacity">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">41,000</span>
<!-- Total Capacity card -->
<span class="fs-2 fw-bold mb-3 d-block">—</span>
<span class="fs-5">Total Capacity</span>
<small class="text-warning">Rack positions available</small>
<!-- was "Storage units available" -->
<small class="text-warning">Rack positions available</small>
</div>
<div class="">
<div>
<span class="text-warning">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
@@ -77,17 +77,15 @@
</svg>
</span>
</div>
</div>
<div class=" p-6 flex-grow-1 d-flex justify-content-between" id="total_space_used">
<div class="p-6 flex-grow-1 d-flex justify-content-between" id="total_space_used">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">25,500</span>
<!-- Space Used card -->
<span class="fs-2 fw-bold mb-3 d-block">—</span>
<span class="fs-5">Space Used</span>
<small class="text-success">Racks occupied</small>
<!-- was "Storage units available" (which was wrong!) -->
<small class="text-success">Racks occupied</small>
</div>
<div class="">
<div>
<span class="text-success">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
@@ -101,16 +99,15 @@
</svg>
</span>
</div>
</div>
<div class="-0 p-6 flex-grow-1 d-flex justify-content-between" id="total_product">
<div class="p-6 flex-grow-1 d-flex justify-content-between" id="total_product">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">730</span>
<span class="fs-2 fw-bold mb-3 d-block">—</span>
<span class="fs-5">Total Products</span>
<small class="text-primary">
Products stored</small>
<small class="text-primary">Products stored</small>
</div>
<div class="">
<div>
<span class="text-primary">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
@@ -121,19 +118,15 @@
</svg>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Tabs -->
<ul class="nav nav-pills mb-3 bg-light p-2 rounded-2 d-inline-flex" id="pills-tab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="pills-warehouse-tab" data-bs-toggle="pill"
@@ -146,32 +139,37 @@
</li>
</ul>
<!-- Warehouses tab -->
<div class="row g-5 mb-5 tab-pane fade show active" id="pills-warehouse" role="tabpanel"
aria-labelledby="pills-warehouse-tab">
<div class="col-12">
<div class="card ">
<div class="card">
<div class="card-body p-5 justify-content-between">
<div class="mb-6 d-flex align-items-center justify-content-between">
<div>
<h2 class="fs-4 mb-2">Warehouses</h2>
<p>All warehouse facilities and their current status</p>
</div>
<div>
<a href="<?php echo $server_url?>inventory/manage_warehouse.php" class="btn btn-primary">Add
Warehouse</a>
<a href="<?php echo $server_url?>inventory/manage_warehouse.php" class="btn btn-primary">
Add Warehouse
</a>
</div>
</div>
<!-- Search bar -->
<div class="col-lg-12 mb-5">
<div class="position-relative">
<input type="search" class="form-control ps-9" placeholder="Search by product name or SKU">
<input type="search" id="search_warehouse" class="form-control ps-9"
placeholder="Search by warehouse name, location, or manager…">
<span class="position-absolute top-25 ms-4">
<i class="ti ti-search text-muted"></i>
</span>
</div>
</div>
<!-- Table -->
<div class="table-responsive">
<table class="table mb-0 text-nowrap table-hover table-centered" id="warehouse">
<thead class="table-primary border-primary">
@@ -182,46 +180,49 @@
<th class="py-3">Capacity</th>
<th class="py-3">Products</th>
<th class="py-3">Status</th>
<th class="py-3">Action</th>
</tr>
</thead>
<tbody></tbody>
<tfoot class="">
</tfoot>
<tfoot></tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Storage tab -->
<div class="row g-5 mb-5 tab-pane fade" id="pills-storage" role="tabpanel" aria-labelledby="pills-storage-tab">
<div class="col-12">
<div class="card ">
<div class="card">
<div class="card-body p-5">
<div class="mb-6 d-flex align-items-center justify-content-between">
<div>
<h2 class="fs-4 mb-2">Storage Locations</h2>
<p>Zones, aisles, and rack assignments</p>
</div>
<div>
<a href="<?php echo $server_url?>inventory/manage_storage.php" class="btn btn-secondary">Add
Storage</a>
<a href="<?php echo $server_url?>inventory/manage_storage.php" class="btn btn-secondary">
Add Storage
</a>
</div>
</div>
<!-- Search bar -->
<div class="col-lg-12 mb-5">
<div class="position-relative">
<input type="search" class="form-control ps-9" placeholder="Search by product name or SKU">
<input type="search" id="search_storage" class="form-control ps-9"
placeholder="Search by warehouse or zone…">
<span class="position-absolute top-25 ms-4">
<i class="ti ti-search text-muted"></i>
</span>
</div>
</div>
<!-- Table -->
<div class="table-responsive">
<table class="table mb-0 text-nowrap table-hover table-centered" id="storage">
<thead class="table-secondary">
@@ -231,17 +232,14 @@
<th class="py-3">Aisle Range</th>
<th class="py-3">Rack Range</th>
<th class="py-3">Items Stored</th>
<th>Action</th>
</tr>
</thead>
<tbody></tbody>
<tfoot class="">
</tfoot>
<tfoot></tfoot>
</table>
</div>
</div>
</div>
</div>
@@ -253,7 +251,14 @@
<?php require "../include_ending.php";?>
<script>
// ── Current search terms (read by change_page_* when paginating) ─────
var search_term_warehouse = '';
var search_term_storage = '';
// ── Stats card ───────────────────────────────────────────────────────
function retrieve_stats() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/warehouse_stats.php",
autoPrepare: true,
@@ -264,16 +269,13 @@
$("#total_warehouse span.fs-2").text(res.total_warehouse);
$("#total_warehouse small.text-info").text(`Across ${res.total_location} locations`);
// Capacity = rack count (integer, no decimals)
$("#total_capacity span.fs-2").text(format_number(res.total_capacity, 0));
// NEW: Space Used wiring
$("#total_space_used span.fs-2").text(format_number(res.space_used, 0));
// Optional: show % utilization in the small text
var pct = res.total_capacity > 0
? Math.round(res.space_used / res.total_capacity * 100)
: 0;
var pct = res.total_capacity > 0 ?
Math.round(res.space_used / res.total_capacity * 100) :
0;
$("#total_space_used small").text(`${pct}% utilized`);
$("#total_product span.fs-2").text(res.total_product);
@@ -282,8 +284,7 @@
}
// ── Warehouse: fetch + render ────────────────────────────────────────
function retrieve_warehouse() {
return ajax_request({
@@ -293,58 +294,65 @@
action: 'read',
onSuccess: function(res) {
// Register the array as a table name
alasql('CREATE TABLE IF NOT EXISTS output');
alasql.tables.output.data = res.output || [];
var total_records = alasql.tables.output.data.length;
var table_id = 'warehouse';
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.`);
}
change_page_warehouse(1);
}
});
}
function change_page_warehouse(page_num) {
var offset = (page_num - 1) * prop_limit;
var kw = search_term_warehouse.toLowerCase();
var page_data = alasql(`SELECT * FROM output LIMIT ${prop_limit} OFFSET ${offset}`);
// Filter in-memory, then paginate
var filtered = kw ?
alasql(`SELECT * FROM output
WHERE LOWER(warehouse_name) LIKE '%${kw}%'
OR LOWER(location) LIKE '%${kw}%'
OR LOWER(manager_name) LIKE '%${kw}%'
OR LOWER(manager_surname) LIKE '%${kw}%'`) :
alasql(`SELECT * FROM output`);
var body = ``;
// Pagination reflects the filtered total
var page = generate_pagination('warehouse', filtered.length);
$(`table#warehouse tfoot`).html(page);
var page_data = filtered.slice(offset, offset + prop_limit);
if (filtered.length === 0) {
$("table#warehouse > tbody").html(
'<tr><td colspan="7" class="text-center py-5 text-muted">No warehouses match your search.</td></tr>'
);
return;
}
var body = '';
$.each(page_data, function(key, item) {
body += `<tr>
<td class="py-3">${item['warehouse_name']}</td>
<td class="py-3">${item['location']}</td>
<td class="py-3">${item['manager_name']} ${item['manager_surname']}</td>
<td class="py-3" style='text-align: right;'>${format_number(item['capacity'],2)}</td>
<td class="py-3">${item['unique_product']}</td>
<td class="py-3">
${(item['status']==1)?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
</td>
<td class="py-3">
<a href="<?php echo $server_url?>inventory/manage_warehouse.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="javascript:;" class="link-danger" onclick="remove_warehouse(${item['id']},$(this))"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
<td class="py-3">${item['warehouse_name']}</td>
<td class="py-3">${item['location']}</td>
<td class="py-3">${item['manager_name']} ${item['manager_surname']}</td>
<td class="py-3" style='text-align: right;'>${format_number(item['capacity'], 2)}</td>
<td class="py-3">${item['unique_product']}</td>
<td class="py-3">
${(item['status']==1)?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
</td>
<td class="py-3">
<a href="<?php echo $server_url?>inventory/manage_warehouse.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="javascript:;" class="link-danger" onclick="remove_warehouse(${item['id']},$(this))"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
});
$("table#warehouse > tbody").html(body);
}
// ── Storage: fetch + render ──────────────────────────────────────────
function retrieve_storage() {
return ajax_request({
@@ -354,56 +362,59 @@
action: 'read',
onSuccess: function(res) {
// Register the array as a table name
alasql('CREATE TABLE IF NOT EXISTS storage');
alasql.tables.storage.data = res.output || [];
var total_records = alasql.tables.storage.data.length;
var table_id = 'storage';
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.`);
}
change_page_storage(1);
}
});
}
function change_page_storage(page_num) {
var offset = (page_num - 1) * prop_limit;
var kw = search_term_storage.toLowerCase();
var page_data = alasql(`SELECT * FROM storage LIMIT ${prop_limit} OFFSET ${offset}`);
var filtered = kw ?
alasql(`SELECT * FROM storage
WHERE LOWER(warehouse_name) LIKE '%${kw}%'
OR LOWER(zone) LIKE '%${kw}%'`) :
alasql(`SELECT * FROM storage`);
var body = ``;
var page = generate_pagination('storage', filtered.length);
$(`table#storage tfoot`).html(page);
var page_data = filtered.slice(offset, offset + prop_limit);
if (filtered.length === 0) {
$("table#storage > tbody").html(
'<tr><td colspan="6" class="text-center py-5 text-muted">No storage locations match your search.</td></tr>'
);
return;
}
var body = '';
$.each(page_data, function(key, item) {
body += `<tr>
<td class="py-3">${item['warehouse_name']}</td>
<td class="py-3">${item['zone']}</td>
<td class="py-3">${item['aisle_from']} - ${item["aisle_to"]}</td>
<td class="py-3">${item['rack_from']} - ${item["rack_to"]}</td>
<td class="py-3"></td>
<td class="py-3">
<a href="<?php echo $server_url?>inventory/manage_storage.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="javascript:;" class="link-danger" onclick="remove_storage(${item['id']},$(this))"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
<td class="py-3">${item['warehouse_name']}</td>
<td class="py-3">${item['zone']}</td>
<td class="py-3">${item['aisle_from']} - ${item["aisle_to"]}</td>
<td class="py-3">${item['rack_from']} - ${item["rack_to"]}</td>
<td class="py-3"></td>
<td class="py-3">
<a href="<?php echo $server_url?>inventory/manage_storage.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="javascript:;" class="link-danger" onclick="remove_storage(${item['id']},$(this))"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
});
$("table#storage > tbody").html(body);
}
function remove_warehouse(id,element) {
// ── Remove handlers ──────────────────────────────────────────────────
function remove_warehouse(id, element) {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/remove_warehouse.php",
@@ -415,16 +426,13 @@
},
action: 'delete',
onSuccess: function(res) {
element.parent().parent().remove();
}
});
}
function remove_storage(id,element) {
function remove_storage(id, element) {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/remove_storage.php",
@@ -436,15 +444,37 @@
},
action: 'delete',
onSuccess: function(res) {
element.parent().parent().remove();
}
});
}
// ── Search: debounce + re-render ─────────────────────────────────────
function debounce(fn, ms) {
var t;
return function() {
var args = arguments,
ctx = this;
clearTimeout(t);
t = setTimeout(function() {
fn.apply(ctx, args);
}, ms);
};
}
$('#search_warehouse').on('input', debounce(function() {
search_term_warehouse = $(this).val().trim();
change_page_warehouse(1); // always reset to page 1 on new search
}, 200));
$('#search_storage').on('input', debounce(function() {
search_term_storage = $(this).val().trim();
change_page_storage(1);
}, 200));
// ── Boot ─────────────────────────────────────────────────────────────
$(async function() {
try {
await retrieve_stats();
@@ -455,20 +485,19 @@
}
});
// Remember last active tab across page reloads
$(document).ready(function() {
// switching to nav-link from last leave
$('button.nav-link').on('click', function() {
nav_id = $(this).attr('id');
var nav_id = $(this).attr('id');
sessionStorage.setItem("warehouse_nav_id", nav_id);
})
let nav_id = sessionStorage.getItem("warehouse_nav_id");
if(nav_id){
});
var nav_id = sessionStorage.getItem("warehouse_nav_id");
if (nav_id) {
$(`button#${nav_id}`).trigger('click');
}
})
});
</script>
</body>
</html>