This commit is contained in:
Thanakorn S
2026-02-19 14:48:40 +07:00
commit 9a50080ae5
221 changed files with 30788 additions and 0 deletions
@@ -0,0 +1,69 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
// get existing log
$sql = "SELECT `log`
FROM md_product_category
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$row = $sth->fetch(PDO::FETCH_ASSOC);
$table_log = json_decode($row['log'] ?? '[]', true);
$table_log[] = $logging;
if ($id > 0) {
$sql = "UPDATE md_product_category SET
`category` = :category,
`slug` = :slug,
`description` = :description,
`status` = :status,
`log` = :log
WHERE id = :id AND company_id = :company_id";
$sth = $pdo2->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
":category" => $data["category"],
":slug" => $data["slug"],
":description" => $data["description"],
":status" => $data["status"],
":log" => json_encode($table_log),
]);
} else {
$sql = "INSERT INTO md_product_category
(company_id, category, slug, `description`, `status`, `log`)
VALUES
(:company_id, :category, :slug, :description, :status, :log)";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":category" => $data["category"],
":slug" => $data["slug"],
":description" => $data["description"],
":status" => $data["status"],
":log" => json_encode($table_log),
]);
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,79 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
// get existing log
$sql = "SELECT `log`
FROM md_product
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$row = $sth->fetch(PDO::FETCH_ASSOC);
$table_log = json_decode($row['log'] ?? '[]', true);
$table_log[] = $logging;
if ($id > 0) {
$sql = "UPDATE md_product SET
product_name = :product_name,
sku = :sku,
price = :price,
category = :category,
product_image = :product_image,
`description` = :description,
`status` = :status,
`log` = :log
WHERE id = :id AND company_id = :company_id";
$sth = $pdo2->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
":product_name" => $data["product_name"],
":sku" => $data["sku"],
":price" => $data["price"],
":category" => $data["category"],
":product_image"=> $data["product_image"],
":description" => $data["description"],
":status" => $data["status"],
":log" => json_encode($table_log),
]);
} else {
$sql = "INSERT INTO md_product
(company_id, product_name, sku, price, category, product_image, `description`, `status`, `log`)
VALUES
(:company_id, :product_name, :sku, :price, :category, :product_image, :description, :status, :log)";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":product_name" => $data["product_name"],
":sku" => $data["sku"],
":price" => $data["price"],
":category" => $data["category"],
":product_image"=> $data["product_image"],
":description" => $data["description"],
":status" => $data["status"],
":log" => json_encode($table_log),
]);
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,99 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)($data['id'] ?? 0);
// get existing log
$sql = "SELECT `log`
FROM md_storage
WHERE company_id = :company_id
AND id = :id";
$sth = $pdo2->prepare($sql);
$sth->execute([
':company_id' => $company_id,
':id' => $id,
]);
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$row = $sth->fetch(PDO::FETCH_ASSOC);
$table_log = json_decode($row['log'] ?? '[]', true);
if (!is_array($table_log)) $table_log = [];
// add new log entry (assumes $logging already prepared)
$table_log[] = $logging;
if ($id > 0) {
$sql = "UPDATE md_storage SET
warehouse = :warehouse,
zone = :zone,
aisle_from = :aisle_from,
aisle_to = :aisle_to,
rack_from = :rack_from,
rack_to = :rack_to,
description = :description,
status = :status,
`log` = :log
WHERE id = :id
AND company_id = :company_id";
$sth = $pdo2->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
":warehouse" => $data["warehouse"] ?? "",
":zone" => $data["zone"] ?? "",
":aisle_from" => $data["aisle_from"] ?? "",
":aisle_to" => $data["aisle_to"] ?? "",
":rack_from" => $data["rack_from"] ?? "",
":rack_to" => $data["rack_to"] ?? "",
":description" => $data["description"] ?? "",
":status" => (int)($data["status"] ?? 1),
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
]);
} else {
$sql = "INSERT INTO md_storage
(company_id, warehouse, zone, aisle_from, aisle_to, rack_from, rack_to, description, status, `log`)
VALUES
(:company_id, :warehouse, :zone, :aisle_from, :aisle_to, :rack_from, :rack_to, :description, :status, :log)";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $data["warehouse"] ?? "",
":zone" => $data["zone"] ?? "",
":aisle_from" => $data["aisle_from"] ?? "",
":aisle_to" => $data["aisle_to"] ?? "",
":rack_from" => $data["rack_from"] ?? "",
":rack_to" => $data["rack_to"] ?? "",
":description" => $data["description"] ?? "",
":status" => (int)($data["status"] ?? 1),
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
]);
}
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,86 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)($data['id'] ?? 0);
// get existing log
$sql = "SELECT `log`
FROM md_warehouse
WHERE company_id = :company_id
AND id = :id";
$sth = $pdo2->prepare($sql);
$sth->execute([
':company_id' => $company_id,
':id' => $id,
]);
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$row = $sth->fetch(PDO::FETCH_ASSOC);
$table_log = json_decode($row['log'] ?? '[]', true);
if (!is_array($table_log)) $table_log = [];
// add new log entry (assumes $logging already prepared)
$table_log[] = $logging;
if ($id > 0) {
$sql = "UPDATE md_warehouse SET
warehouse_name = :warehouse_name,
location = :location,
manager = :manager,
capacity = :capacity,
description = :description,
status = :status,
`log` = :log
WHERE id = :id
AND company_id = :company_id";
$sth = $pdo2->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
":warehouse_name" => $data["warehouse_name"] ?? "",
":location" => $data["location"] ?? "",
":manager" => (int)($data["manager"] ?? 0),
":capacity" => (int)($data["capacity"] ?? 0),
":description" => $data["description"] ?? "",
":status" => (int)($data["status"] ?? 1),
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
]);
} else {
$sql = "INSERT INTO md_warehouse
(company_id, warehouse_name, location, manager, capacity, description, status, `log`)
VALUES
(:company_id, :warehouse_name, :location, :manager, :capacity, :description, :status, :log)";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse_name" => $data["warehouse_name"] ?? "",
":location" => $data["location"] ?? "",
":manager" => (int)($data["manager"] ?? 0),
":capacity" => (int)($data["capacity"] ?? 0),
":description" => $data["description"] ?? "",
":status" => (int)($data["status"] ?? 1),
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
]);
}
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
+22
View File
@@ -0,0 +1,22 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$sql = "SELECT *
FROM user
WHERE
username not in ('support','extra')";
$sth = $pdo1->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
+22
View File
@@ -0,0 +1,22 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$sql = "SELECT *
FROM md_product
WHERE
company_id = {$company_id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,22 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$sql = "SELECT *
FROM md_product_category
WHERE
company_id = {$company_id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,54 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
// get data
$sql = "SELECT *
FROM md_product_category
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$json = $sth->fetch(PDO::FETCH_ASSOC);
$json = json_encode($json);
// delete data
$sql = "DELETE FROM md_product_category
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
// insert into archive
$sql = "INSERT INTO archive (`company_id`,`user_id`,`date`,`json`) VALUES ({$company_id},{$user_id},NOW(),'{$jsona}')";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,26 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$sql = "SELECT *
FROM md_product_category
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetch(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,26 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$sql = "SELECT *
FROM md_product
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetch(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,26 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$sql = "SELECT *
FROM md_storage
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetch(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,26 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$sql = "SELECT *
FROM md_warehouse
WHERE
company_id = {$company_id} and
id = {$id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetch(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
+31
View File
@@ -0,0 +1,31 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$sql = "SELECT a.*, b.warehouse_name
FROM md_storage a
LEFT JOIN md_warehouse b ON
a.company_id = b.company_id and
a.warehouse = b.id
WHERE
a.company_id = {$company_id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
// modify output
foreach($answer["output"] as $key => $item){
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
session_start();
require '../../../preset.php';
require '../../../assets/utils/db_auth.php';
$sql = "SELECT a.*
FROM md_warehouse a
WHERE
a.company_id = {$company_id}";
$sth = $pdo2->prepare($sql);
$sth->execute();
if ($sth->errorInfo()[0] != "00000" && !empty($sth->errorInfo()[0])) {
$answer["message"] = (empty($sth->errorInfo()[2])) ? $sth->errorInfo()[0] : $sth->errorInfo()[2];
exit(json_encode($answer));
}
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
// modify output
foreach($answer["output"] as $key => $item){
// status
if($item["status"]==1){
$answer["output"][$key]["status"] = 'Active';
$answer["output"][$key]["bg_class"] = 'success';
}else{
$answer["output"][$key]["status"] = 'Inactive';
$answer["output"][$key]["bg_class"] = 'secondary';
}
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
+130
View File
@@ -0,0 +1,130 @@
<?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="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-5 gap-3">
<div class="">
<h1 class="fs-3 mb-1">Manage Category</h1>
<p class="mb-0">Create/Update your product category</p>
</div>
</div>
</div>
</div>
<div class="row" id="categoryForm">
<div class="col-12">
<div class="card">
<div class="card-body p-6">
<div class="row">
<div class="col-md-6 mb-3">
<label for="category" class="form-label">Category Name</label>
<input type="text" class="form-control" id="category" placeholder="Enter category name" required>
</div>
<div class="col-md-6 mb-3">
<label for="slug" class="form-label">Slug</label>
<input type="text" class="form-control" id="slug" placeholder="Enter Slug" required>
</div>
</div>
<div class="mb-3">
<label for="status" class="form-label">status</label>
<select class="form-select" id="status" required>
<option value="1">Active</option>
<option value="0">inactive</option>
</select>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" rows="4"
placeholder="Enter product description"></textarea>
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary" onclick="manage_category();">Create</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function manage_category() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/manage_category.php",
autoPrepare: true,
checkRequired: 1,
debugMode: 0,
action: 'manage',
onSuccess: function(res) {
window.location.href = "<?php echo $server_url?>inventory/product.php";
}
});
}
function retreive_for_edit() {
<?php if(empty($_GET["id"])){ ?>
return false;
<?php } ?>
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/retrieve_category.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
$.each(res.output, function(key, item) {
$(`#${key}`).val(item);
});
$(`button[type=submit]`).text('Update');
$(`button[type=reset]`).hide();
}
});
}
$(async function() {
try {
await retreive_for_edit();
} catch (e) {
console.log(e);
}
});
</script>
</body>
</html>
+159
View File
@@ -0,0 +1,159 @@
<?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="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-5 gap-3">
<div class="">
<h1 class="fs-3 mb-1">Add Product</h1>
<p class="mb-0">Manage your Product items</p>
</div>
</div>
</div>
</div>
<div class="row" id="productForm">
<div class="col-12">
<div class="card">
<div class="card-body p-6">
<div class="row">
<div class="col-md-6 mb-3">
<label for="product_name" class="form-label">Product Name</label>
<input type="text" class="form-control" id="product_name" placeholder="Enter product name" required>
</div>
<div class="col-md-6 mb-3">
<label for="sku" class="form-label">SKU</label>
<input type="text" class="form-control" id="sku" placeholder="Enter SKU" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="price" class="form-label">Price</label>
<input type="number" class="form-control" id="price" placeholder="0.00" step="0.01" required>
</div>
</div>
<div class="mb-3">
<label for="category" class="form-label">Category</label>
<select class="form-select" id="category" required> </select>
</div>
<div class="mb-3">
<label for="product_image" class="form-label">Product Image</label>
<input type="file" class="form-control" id="product_image" accept="image/*">
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" rows="4"
placeholder="Enter product description"></textarea>
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary" onclick="add_product();">Create</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function add_product() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/manage_product.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'manage',
onSuccess: function(res) {
window.location.href = "<?php echo $server_url?>inventory/product.php";
}
});
}
function retrieve_category() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/product_category.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
var option = ``;
$.each(res.output, function(key, item) {
option += `<option value='${item.id}'>${item.category}</option>`;
})
$(`select#category`).html(option);
}
});
}
function retreive_for_edit() {
<?php if(empty($_GET["id"])){ ?>
return false;
<?php } ?>
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/retrieve_product.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
$.each(res.output, function(key, item) {
$(`#${key}`).val(item);
});
$(`button[type=submit]`).text('Update');
$(`button[type=reset]`).hide();
}
});
}
$(async function() {
try {
await retrieve_category();
await retreive_for_edit();
} catch (e) {
console.log(e);
}
});
</script>
</body>
</html>
+159
View File
@@ -0,0 +1,159 @@
<?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="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-5 gap-3">
<div class="">
<h1 class="fs-3 mb-1">Manage Storage</h1>
<p class="mb-0">Manage your Storage items</p>
</div>
</div>
</div>
</div>
<div class="row" id="storageForm">
<div class="col-12">
<div class="card">
<div class="card-body p-6">
<div class="row">
<div class="col-md-6 mb-3">
<label for="warehouse" class="form-label">Warehouse</label>
<select class="form-select" id="warehouse" required> </select>
</div>
<div class="col-md-6 mb-3">
<label for="zone" class="form-label">Zone</label>
<input type="text" class="form-control" id="zone" placeholder="Enter zone" required>
</div>
</div>
<div class="row">
<div class="col-md-3 mb-3">
<label for="aisle_from" class="form-label">Aisle From</label>
<input type="text" class="form-control" id="aisle_from" placeholder="Enter aisle form" required>
</div>
<div class="col-md-3 mb-3">
<label for="aisle_to" class="form-label">Aisle To</label>
<input type="text" class="form-control" id="aisle_to" placeholder="Enter aisle to" required>
</div>
<div class="col-md-3 mb-3">
<label for="rack_from" class="form-label">Rack From</label>
<input type="text" class="form-control" id="rack_from" placeholder="Enter rack form" required>
</div>
<div class="col-md-3 mb-3">
<label for="rack_to" class="form-label">Rack To</label>
<input type="text" class="form-control" id="rack_to" placeholder="Enter rack to" required>
</div>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" rows="4"
placeholder="Enter warehouse description"></textarea>
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary" onclick="manage_storage();">Add Storage</button>
<button type="reset" class="btn btn-secondary" onclick="reset_input('#storageForm')">Clear</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function manage_storage() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/manage_storage.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
onSuccess: function(res) {
window.location.href = "<?php echo $server_url?>inventory/warehouse.php";
}
});
}
function retrieve_warehouse() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
autoPrepare: true,
checkRequired: 0,
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 retreive_for_edit() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/retrieve_storage.php",
autoPrepare: true,
checkRequired: 0,
onSuccess: function(res) {
$.each(res.output, function(key, item) {
$(`#${key}`).val(item);
});
$(`button[type=submit]`).text('Update Storage');
$(`button[type=reset]`).hide();
}
});
}
$(async function() {
try {
await retrieve_warehouse();
<?php if(!empty($_GET["id"])){ ?>
await retreive_for_edit();
<?php } ?>
} catch (e) {
console.log(e);
}
});
</script>
</body>
</html>
+155
View File
@@ -0,0 +1,155 @@
<?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="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-5 gap-3">
<div class="">
<h1 class="fs-3 mb-1">Manage Warehouse</h1>
<p class="mb-0">Manage your Warehouse items</p>
</div>
</div>
</div>
</div>
<div class="row" id="warehouseForm">
<div class="col-12">
<div class="card">
<div class="card-body p-6">
<div class="row">
<div class="col-md-6 mb-3">
<label for="warehouse_name" class="form-label">Warehouse Name</label>
<input type="text" class="form-control" id="warehouse_name" placeholder="Enter warehouse name"
required>
</div>
<div class="col-md-6 mb-3">
<label for="location" class="form-label">Location</label>
<input type="text" class="form-control" id="location" placeholder="Enter Location" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="manager" class="form-label">Manager</label>
<select class="form-select" id="manager" required> </select>
</div>
<div class="col-md-6 mb-3">
<label for="capacity" class="form-label">Capacity</label>
<input type="number" class="form-control" id="capacity" placeholder="0.00" step="0.01" required>
</div>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" rows="4"
placeholder="Enter warehouse description"></textarea>
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary" onclick="manage_warehouse();">Add Warehouse</button>
<button type="reset" class="btn btn-secondary" onclick="reset_input('#warehouseForm')">Clear</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function manage_warehouse() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/manage_warehouse.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'manage',
onSuccess: function(res) {
window.location.href = "<?php echo $server_url?>inventory/warehouse.php";
}
});
}
function retrieve_manager() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/manager.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
var option = ``;
$.each(res.output, function(key, item) {
option += `<option value='${item.user_id}'>${item.name} ${item.surname}</option>`;
})
$(`select#manager`).html(option);
}
});
}
function retreive_for_edit() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/retrieve_warehouse.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
$.each(res.output, function(key, item) {
$(`#${key}`).val(item);
});
$(`button[type=submit]`).text('Update Category');
$(`button[type=reset]`).hide();
}
});
}
$(async function() {
try {
await retrieve_manager();
<?php if(!empty($_GET["id"])){ ?>
await retreive_for_edit();
<?php } ?>
} catch (e) {
console.log(e);
}
});
</script>
</body>
</html>
+387
View File
@@ -0,0 +1,387 @@
<?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="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-5 gap-3">
<div class="">
<h1 class="fs-3 mb-1">Products</h1>
<p class="mb-0">Manage your products</p>
</div>
</div>
</div>
</div>
<div class="row g-5 mb-5">
<div class="col-xl-3 col-md-6 col-12">
<div class="card">
<div class="card-body p-6">
<div class="d-flex align-items-start gap-3">
<div class="icon-shape icon-lg bg-primary bg-opacity-10 text-primary rounded-2">
<i class="ti ti-category fs-4 "></i>
</div>
<div class="">
<span>Total Categories</span>
<h2 class="fw-bold mb-0">6</h2>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6 col-12">
<div class="card">
<div class="card-body p-6">
<div class="d-flex align-items-start gap-3">
<div class="icon-shape icon-lg bg-info bg-opacity-10 text-info rounded-2">
<i class="ti ti-check fs-4 "></i>
</div>
<div class="">
<span>Active</span>
<h2 class="fw-bold mb-0">5</h2>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6 col-12">
<div class="card">
<div class="card-body p-6">
<div class="d-flex align-items-start gap-3">
<div class="icon-shape icon-lg bg-warning bg-opacity-10 text-warning rounded-2">
<i class="ti ti-x fs-4 "></i>
</div>
<div class="">
<span>Inactive</span>
<h2 class="fw-bold mb-0">1</h2>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6 col-12">
<div class="card">
<div class="card-body p-6">
<div class="d-flex align-items-start gap-3">
<div class="icon-shape icon-lg bg-warning bg-opacity-10 text-warning rounded-2">
<i class="ti ti-box-seam fs-4 "></i>
</div>
<div class="">
<span>Total Products</span>
<h2 class="fw-bold mb-0">356</h2>
</div>
</div>
</div>
</div>
</div>
</div>
<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-categories-tab" data-bs-toggle="pill"
data-bs-target="#pills-categories" type="button" role="tab" aria-controls="pills-categories"
aria-selected="true">Categories</button>
</li>
<li class="nav-item nav-item-secondary" role="presentation">
<button class="nav-link" id="pills-products-tab" data-bs-toggle="pill" data-bs-target="#pills-products"
type="button" role="tab" aria-controls="pills-products" aria-selected="false">Products</button>
</li>
</ul>
<div class="row g-5 mb-5 tab-pane fade show active" id="pills-categories" role="tabpanel"
aria-labelledby="pills-categories-tab">
<div class="col-12">
<div class="card overflow-hidden">
<div class="card-body p-6">
<div class="mb-6 d-flex align-items-center justify-content-between">
<div>
<h3 class="mb-1 fs-4">Product Categories</h3>
<p class="mb-0">List of all product categories</p>
</div>
<div>
<a href="<?php echo $server_url?>inventory/manage_category.php" class="btn btn-primary">
<span class="me-1"><i class="ti ti-plus"></i></span>
<span>Add Categories</span></a>
</div>
</div>
<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">
<span class="position-absolute top-25 ms-4">
<i class="ti ti-search text-muted"></i>
</span>
</div>
</div>
<div class="table-responsive">
<table class="table mb-0 text-nowrap table-hover table-centered" id="category">
<thead class="table-primary border-light">
<tr>
<th>Category</th>
<th>Slug</th>
<th>Description</th>
<th>Products</th>
<th>Status</th>
<th>Actions</th>
</tr>
<tbody>
</tbody>
<tfoot class="">
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row g-5 mb-5 tab-pane fade" id="pills-products" role="tabpanel" aria-labelledby="pills-products-tab">
<div class="col-12">
<div class="card">
<div class="card-body p-5">
<div class="mb-6 d-flex align-items-center justify-content-between">
<div>
<h3 class="mb-1 fs-4">Products</h3>
<p class="mb-0">List of all products</p>
</div>
<div>
<a href="<?php echo $server_url?>inventory/manage_product.php" class="btn btn-secondary">
<span class="me-1"><i class="ti ti-plus"></i></span>
<span>Add Product</span></a>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover mb-0 table-centered" id="product">
<thead class="table-secondary border-light">
<tr>
<th>Product</th>
<th>SKU</th>
<th>Current Stock</th>
<th>Min Stock</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody></tbody>
<tfoot class="">
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function retrieve_category() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/product_category.php",
autoPrepare: true,
checkRequired: 0,
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 = 'category';
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 remove_category(id,element) {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/remove_category.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
data: {
id: id
},
action: 'delete',
onSuccess: function(res) {
element.parent().parent().remove();
}
});
}
function change_page_category(page_num) {
var offset = (page_num - 1) * prop_limit;
var page_data = alasql(`SELECT * FROM output LIMIT ${prop_limit} OFFSET ${offset}`);
var body = ``;
$.each(page_data, function(key, item) {
body += `<tr>
<td class="py-3">${item['category']}</td>
<td class="py-3">${item['slug']}</td>
<td class="py-3">${item['description']}</td>
<td class="py-3">${item['status']}</td>
<td class="py-3">
${(item['status'])?'<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_category.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="javascript:;" class="link-danger" onclick="remove_category(${item['id']},$(this))"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
$("table#category > tbody").html(body);
}
function retrieve_product() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/product.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
// Register the array as a table name
alasql('CREATE TABLE IF NOT EXISTS product');
alasql.tables.product.data = res.output || [];
var total_records = alasql.tables.product.data.length;
var table_id = 'product';
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_product(page_num) {
var offset = (page_num - 1) * prop_limit;
var page_data = alasql(`SELECT * FROM product LIMIT ${prop_limit} OFFSET ${offset}`);
var body = ``;
$.each(page_data, function(key, item) {
body += `<tr>
<td class="py-3">${item['product_name']}</td>
<td class="py-3">${item['sku']}</td>
<td class="py-3">${item['description']}</td>
<td class="py-3">${item['status']}</td>
<td class="py-3">
${(item['status'])?'<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_product.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="#" class="link-danger"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
$("table#product > tbody").html(body);
}
$(async function() {
try {
await retrieve_category();
await retrieve_product();
} catch (e) {
console.log(e);
}
});
$(document).ready(function() {
// switching to nav-link from last leave
$('button.nav-link').on('click', function() {
nav_id = $(this).attr('id');
sessionStorage.setItem("product_nav_id", nav_id);
})
let nav_id = sessionStorage.getItem("product_nav_id");
if(nav_id){
$(`button#${nav_id}`).trigger('click');
}
})
</script>
</body>
</html>
+397
View File
@@ -0,0 +1,397 @@
<?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 align-items-center justify-content-between">
<div>
<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>
<div class="row mb-5 g-5">
<div class="col-12">
<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">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">5</span>
<span class="fs-5">Total Warehouses</span>
<small class="text-info">
Across 5 locations</small>
</div>
<div class="">
<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"
class="icon icon-tabler icons-tabler-outline icon-tabler-building-warehouse">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M3 21v-13l9 -4l9 4v13" />
<path d="M13 13h4v8h-10v-6h6" />
<path d="M13 21v-9a1 1 0 0 0 -1 -1h-2a1 1 0 0 0 -1 1v3" />
</svg>
</span>
</div>
</div>
<div class=" p-6 flex-grow-1 d-flex justify-content-between">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">41,000</span>
<span class="fs-5">Total Capacity</span>
<small class="text-warning">
Storage units available</small>
</div>
<div class="">
<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"
class="icon icon-tabler icons-tabler-outline icon-tabler-building-plus">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M3 21h9" />
<path d="M9 8h1" />
<path d="M9 12h1" />
<path d="M9 16h1" />
<path d="M14 8h1" />
<path d="M14 12h1" />
<path
d="M5 21v-16c0 -.53 .211 -1.039 .586 -1.414c.375 -.375 .884 -.586 1.414 -.586h10c.53 0 1.039 .211 1.414 .586c.375 .375 .586 .884 .586 1.414v7" />
<path d="M16 19h6" />
<path d="M19 16v6" />
</svg>
</span>
</div>
</div>
<div class=" p-6 flex-grow-1 d-flex justify-content-between">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">25,500</span>
<span class="fs-5">Space Used</span>
<small class="text-success">
Storage units available</small>
</div>
<div class="">
<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"
class="icon icon-tabler icons-tabler-outline icon-tabler-package">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 3l8 4.5l0 9l-8 4.5l-8 -4.5l0 -9l8 -4.5" />
<path d="M12 12l8 -4.5" />
<path d="M12 12l0 9" />
<path d="M12 12l-8 -4.5" />
<path d="M16 5.25l-8 4.5" />
</svg>
</span>
</div>
</div>
<div class="-0 p-6 flex-grow-1 d-flex justify-content-between">
<div class="d-flex flex-column">
<span class="fs-2 fw-bold mb-3 d-block">730</span>
<span class="fs-5">Total Products</span>
<small class="text-primary">
Products stored</small>
</div>
<div class="">
<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"
class="icon icon-tabler icons-tabler-outline icon-tabler-map-pin">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" />
<path d="M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0z" />
</svg>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<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"
data-bs-target="#pills-warehouse" type="button" role="tab" aria-controls="pills-warehouse"
aria-selected="true">warehouse</button>
</li>
<li class="nav-item nav-item-secondary" role="presentation">
<button class="nav-link" id="pills-storage-tab" data-bs-toggle="pill" data-bs-target="#pills-storage"
type="button" role="tab" aria-controls="pills-storage" aria-selected="false">storage</button>
</li>
</ul>
<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-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>
</div>
</div>
<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">
<span class="position-absolute top-25 ms-4">
<i class="ti ti-search text-muted"></i>
</span>
</div>
</div>
<div class="table-responsive">
<table class="table mb-0 text-nowrap table-hover table-centered" id="warehouse">
<thead class="table-primary border-primary">
<tr>
<th class="py-3">Warehouse Name</th>
<th class="py-3">Location</th>
<th class="py-3">Manager</th>
<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>
</table>
</div>
</div>
</div>
</div>
</div>
<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-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>
</div>
</div>
<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">
<span class="position-absolute top-25 ms-4">
<i class="ti ti-search text-muted"></i>
</span>
</div>
</div>
<div class="table-responsive">
<table class="table mb-0 text-nowrap table-hover table-centered" id="storage">
<thead class="table-secondary">
<tr>
<th class="py-3">Warehouse</th>
<th class="py-3">Zone</th>
<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>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
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) {
// 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.`);
}
}
});
}
function change_page_warehouse(page_num) {
var offset = (page_num - 1) * prop_limit;
var page_data = alasql(`SELECT * FROM output LIMIT ${prop_limit} OFFSET ${offset}`);
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']}</td>
<td class="py-3">${item['capacity']}</td>
<td class="py-3">${item['product']}</td>
<td class="py-3">
<span class="badge bg-${item['bg_class']}">${item.status}</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="#" class="link-danger"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
$("table#warehouse > tbody").html(body);
}
function retrieve_storage() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/storage.php",
autoPrepare: true,
checkRequired: 0,
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.`);
}
}
});
}
function change_page_storage(page_num) {
var offset = (page_num - 1) * prop_limit;
var page_data = alasql(`SELECT * FROM storage LIMIT ${prop_limit} OFFSET ${offset}`);
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="#" class="link-danger"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
$("table#storage > tbody").html(body);
}
$(async function() {
try {
await retrieve_warehouse();
await retrieve_storage();
} catch (e) {
console.log(e);
}
});
$(document).ready(function() {
// switching to nav-link from last leave
$('button.nav-link').on('click', function() {
nav_id = $(this).attr('id');
sessionStorage.setItem("warehouse_nav_id", nav_id);
})
let nav_id = sessionStorage.getItem("warehouse_nav_id");
if(nav_id){
$(`button#${nav_id}`).trigger('click');
}
})
</script>
</body>
</html>