ICS modules

This commit is contained in:
Thanakorn S
2026-03-21 14:58:15 +07:00
parent 2e558a55bb
commit a4f474b5df
45 changed files with 3110 additions and 597 deletions
+57 -52
View File
@@ -1,69 +1,74 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
try {
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging) {
// get existing log
$sql = "SELECT `log`
FROM md_product_category
WHERE
company_id = :company_id and
id = :id";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
db_check($sth, $answer);
$row = $sth->fetch(PDO::FETCH_ASSOC);
$id = (int)$data['id'];
$table_log = json_decode($row['log'] ?? '[]', true);
$sql = "SELECT `log` FROM md_product_category
WHERE company_id = :company_id AND id = :id";
$sth = $pdo->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
$table_log[] = $logging;
$table_log = json_decode($sth->fetchColumn() ?: '[]', true);
$table_log[] = $logging;
if ($id > 0) {
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";
$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),
]);
$sth = $pdo->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 {
} else {
$sql = "INSERT INTO md_product_category
(company_id, category, slug, `description`, `status`, `log`)
VALUES
(:company_id, :category, :slug, :description, :status, :log)";
$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),
]);
$sth = $pdo->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;
} catch (PDOException $e) {
$answer["success"] = 0;
$answer["message"] = "Database error, please try again";
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
+71 -61
View File
@@ -3,77 +3,87 @@
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
try {
// get existing log
$sql = "SELECT `log`
FROM md_product
WHERE
company_id = :company_id and
id = :id ";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
db_check($sth, $answer);
$row = $sth->fetch(PDO::FETCH_ASSOC);
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging) {
$table_log = json_decode($row['log'] ?? '[]', true);
$id = (int)$data['id'];
$table_log[] = $logging;
// get existing log
$sql = "SELECT `log` FROM md_product
WHERE company_id = :company_id AND id = :id";
$sth = $pdo->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
if ($id > 0) {
$table_log = json_decode($sth->fetchColumn() ?: '[]', true);
$table_log[] = $logging;
$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";
if ($id > 0) {
$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),
]);
$sql = "UPDATE md_product SET
product_name = :product_name,
sku = :sku,
price = :price,
min_stock = :min_stock,
category = :category,
product_image = :product_image,
`description` = :description,
`status` = :status,
`log` = :log
WHERE id = :id AND company_id = :company_id";
} else {
$sth = $pdo->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
":product_name" => $data["product_name"],
":sku" => $data["sku"],
":price" => $data["price"],
":min_stock" => $data["min_stock"],
":category" => $data["category"],
":product_image"=> $data["product_image"],
":description" => $data["description"],
":status" => $data["status"],
":log" => json_encode($table_log),
]);
$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)";
} else {
$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),
]);
$sql = "INSERT INTO md_product
(company_id, product_name, sku, price, min_stock, category, product_image, `description`, `status`, `log`)
VALUES
(:company_id, :product_name, :sku, :price, :min_stock, :category, :product_image, :description, :status, :log)";
$sth = $pdo->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":product_name" => $data["product_name"],
":sku" => $data["sku"],
":price" => $data["price"],
":min_stock" => $data["min_stock"],
":category" => $data["category"],
":product_image"=> $data["product_image"],
":description" => $data["description"],
":status" => $data["status"],
":log" => json_encode($table_log),
]);
}
});
$answer["success"] = 1;
} catch (PDOException $e) {
$answer["success"] = 0;
$answer["message"] = "Database error, please try again";
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
}
$answer["success"] = 1;
exit(json_encode($answer));
?>
+59 -76
View File
@@ -1,93 +1,76 @@
<?php
session_start();
session_start();
require '../../../assets/utils/db_auth.php';
require '../../../assets/utils/db_auth.php';
try {
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging) {
$id = (int)($data['id'] ?? 0);
$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,
]);
$sql = "SELECT `log` FROM md_storage
WHERE company_id = :company_id AND id = :id";
$sth = $pdo->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
db_check($sth, $answer);
$table_log = json_decode($sth->fetchColumn() ?: '[]', true);
if (!is_array($table_log)) $table_log = [];
$table_log[] = $logging;
$row = $sth->fetch(PDO::FETCH_ASSOC);
$params = [
":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),
];
$table_log = json_decode($row['log'] ?? '[]', true);
if (!is_array($table_log)) $table_log = [];
if ($id > 0) {
// add new log entry (assumes $logging already prepared)
$table_log[] = $logging;
$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";
if ($id > 0) {
$params[":id"] = $id;
$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";
} else {
$sth = $pdo2->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
$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)";
}
":warehouse" => $data["warehouse"] ?? "",
":zone" => $data["zone"] ?? "",
$sth = $pdo->prepare($sql);
$sth->execute($params);
":aisle_from" => $data["aisle_from"] ?? "",
":aisle_to" => $data["aisle_to"] ?? "",
});
":rack_from" => $data["rack_from"] ?? "",
":rack_to" => $data["rack_to"] ?? "",
$answer["success"] = 1;
":description" => $data["description"] ?? "",
":status" => (int)($data["status"] ?? 1),
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
]);
} catch (PDOException $e) {
$answer["success"] = 0;
$answer["message"] = "Database error, please try again";
} else {
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
}
$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),
]);
}
db_check($sth, $answer);
$answer["success"] = 1;
exit(json_encode($answer));
?>
exit(json_encode($answer));
?>
+61 -80
View File
@@ -1,98 +1,79 @@
<?php
session_start();
session_start();
require '../../../assets/utils/db_auth.php';
require '../../../assets/utils/db_auth.php';
try {
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging) {
$id = (int)($data['id'] ?? 0);
$id = (int)($data['id'] ?? 0);
$pdo2->beginTransaction();
$sql = "SELECT `log` FROM md_warehouse
WHERE company_id = :company_id AND id = :id";
$sth = $pdo->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
// 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,
]);
$table_log = json_decode($sth->fetchColumn() ?: '[]', true);
if (!is_array($table_log)) $table_log = [];
$table_log[] = $logging;
db_check($sth, $answer);
$params = [
":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),
];
$row = $sth->fetch(PDO::FETCH_ASSOC);
if ($id > 0) {
$table_log = json_decode($row['log'] ?? '[]', true);
if (!is_array($table_log)) $table_log = [];
$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";
// add new log entry (assumes $logging already prepared)
$table_log[] = $logging;
$params[":id"] = $id;
if ($id > 0) {
} else {
$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";
$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([
":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),
]);
db_check($sth, $answer);
$sth = $pdo->prepare($sql);
$sth->execute($params);
} else {
// Create stock table for new warehouse
if ($id == 0 && !empty($data["warehouse_name"])) {
$safe_name = 'td_stock_' . preg_replace('/[^a-zA-Z0-9_]/', '', $data["warehouse_name"]);
$sql = "CREATE TABLE `$safe_name` LIKE `td_stock`";
$pdo->exec($sql);
}
$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),
]);
db_check($sth, $answer);
$answer["success"] = 1;
} catch (PDOException $e) {
$answer["success"] = 0;
$answer["message"] = "Database error, please try again";
if(!empty($data["warehouse_name"])){
/**
* Create warehouse table
*/
$safe_name = 'td_stock_' . preg_replace('/[^a-zA-Z0-9_]/', '', $data["warehouse_name"]);
$sql = "CREATE TABLE `$safe_name` LIKE `td_stock`";
$sth = $pdo2->prepare($sql);
$sth->execute();
db_check($sth, $answer);
}
}
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
}
$pdo2->commit();
$answer["success"] = 1;
exit(json_encode($answer));
?>
exit(json_encode($answer));
?>
+2 -2
View File
@@ -87,7 +87,7 @@
}
function retreive_for_edit() {
function retrieve_for_edit() {
<?php if(empty($_GET["id"])){ ?>
return false;
@@ -117,7 +117,7 @@
$(async function() {
try {
await retreive_for_edit();
await retrieve_for_edit();
} catch (e) {
console.log(e);
}
+6 -2
View File
@@ -43,6 +43,10 @@
<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 class="col-md-6 mb-3">
<label for="min_stock" class="form-label">min_stock</label>
<input type="number" class="form-control" id="min_stock" placeholder="0" required>
</div>
</div>
<div class="mb-3">
@@ -115,7 +119,7 @@
}
function retreive_for_edit() {
function retrieve_for_edit() {
<?php if(empty($_GET["id"])){ ?>
return false;
@@ -146,7 +150,7 @@
$(async function() {
try {
await retrieve_category();
await retreive_for_edit();
await retrieve_for_edit();
} catch (e) {
console.log(e);
}
+2 -2
View File
@@ -120,7 +120,7 @@
}
function retreive_for_edit() {
function retrieve_for_edit() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/retrieve_storage.php",
@@ -148,7 +148,7 @@
try {
await retrieve_warehouse();
<?php if(!empty($_GET["id"])){ ?>
await retreive_for_edit();
await retrieve_for_edit();
<?php } ?>
} catch (e) {
console.log(e);
+2 -2
View File
@@ -113,7 +113,7 @@
}
function retreive_for_edit() {
function retrieve_for_edit() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/retrieve_warehouse.php",
@@ -141,7 +141,7 @@
try {
await retrieve_manager();
<?php if(!empty($_GET["id"])){ ?>
await retreive_for_edit();
await retrieve_for_edit();
<?php } ?>
} catch (e) {
console.log(e);
+1 -1
View File
@@ -344,7 +344,7 @@
<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" style='text-align: right;'>${format_number(item['min_stock'],2)}</td>
<td class="py-3">
${(item['status'])?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
</td>
+1 -1
View File
@@ -295,7 +295,7 @@
<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" style='text-align: right;'>${format_number(item['capacity'],2)}</td>
<td class="py-3">${item['product']}</td>
<td class="py-3">
<span class="badge bg-${item['bg_class']}">${item.status}</span>