warehouse capacity and occupancy

This commit is contained in:
Thanakorn S
2026-04-23 08:24:30 +07:00
parent 35dd1a9fce
commit ed23c269ea
15 changed files with 429 additions and 85 deletions
+1 -1
View File
@@ -67,7 +67,7 @@
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
$answer["message"] = $e->getMessage();
}
exit(json_encode($answer));
+1 -1
View File
@@ -115,7 +115,7 @@
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
$answer["message"] = $e->getMessage();
$answer["error"] = $e->getMessage();
}
+26 -6
View File
@@ -1,6 +1,7 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
require '../../../assets/utils/classes/WarehouseManager.php';
try {
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging) {
@@ -48,17 +49,36 @@
$params[":id"] = $id;
$sth = $pdo->prepare($sql);
$sth->execute($params);
$storage_id = $id;
} else {
$sql = "INSERT INTO md_storage
(company_id, warehouse, zone, aisle_from, aisle_to, rack_from, rack_to, description, status, `log`)
(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)";
(:company_id, :warehouse, :zone, :aisle_from, :aisle_to,
:rack_from, :rack_to, :description, :status, :log)";
$sth = $pdo->prepare($sql);
$sth->execute($params);
$storage_id = (int) $pdo->lastInsertId();
}
$sth = $pdo->prepare($sql);
$sth->execute($params);
// Sync md_rack rows — same $pdo, inside the same transaction
$wm = new WarehouseManager($pdo, $company_id);
$wm->syncRacks($storage_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'],
]);
});
$answer["success"] = 1;
@@ -69,7 +89,7 @@
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
$answer["message"] = $e->getMessage();
}
exit(json_encode($answer));
@@ -24,7 +24,6 @@
":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),
@@ -36,7 +35,6 @@
`warehouse_name` = :warehouse_name,
`location` = :location,
`manager` = :manager,
`capacity` = :capacity,
`description` = :description,
`status` = :status,
`log` = :log
@@ -47,9 +45,9 @@
} else {
$sql = "INSERT INTO md_warehouse
(company_id, warehouse_name, location, manager, capacity, description, status, `log`)
(company_id, warehouse_name, location, manager, description, status, `log`)
VALUES
(:company_id, :warehouse_name, :location, :manager, :capacity, :description, :status, :log)";
(:company_id, :warehouse_name, :location, :manager, :description, :status, :log)";
}
$sth = $pdo->prepare($sql);
@@ -72,7 +70,7 @@
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
$answer["message"] = $e->getMessage();
}
exit(json_encode($answer));
+20 -11
View File
@@ -3,17 +3,26 @@
require '../../../assets/utils/db_auth.php';
$sql = "SELECT a.*, IFNULL(COUNT(DISTINCT b.product_sku), 0) AS unique_product,
c.name AS manager_name, c.surname AS manager_surname
FROM md_warehouse a
LEFT JOIN warehouse_balance b ON
a.company_id = b.company_id AND
a.id = b.warehouse_id
LEFT JOIN wms.user c ON
a.manager = c.user_id
WHERE
a.company_id = :company_id
GROUP BY a.id";
$sql = "SELECT
a.*,
COALESCE(r.total_racks, 0) AS capacity,
COALESCE(r.occupied_racks, 0) AS space_used,
COALESCE(r.unique_product, 0) AS unique_product,
c.name AS manager_name,
c.surname AS manager_surname
FROM md_warehouse a
LEFT JOIN (
SELECT
company_id, warehouse,
COUNT(*) AS total_racks,
COUNT(product_sku) AS occupied_racks,
COUNT(DISTINCT product_sku) AS unique_product
FROM md_rack
GROUP BY company_id, warehouse
) r ON a.company_id = r.company_id AND a.id = r.warehouse
LEFT JOIN wms.user c ON a.manager = c.user_id
WHERE a.company_id = :company_id";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id
@@ -9,6 +9,7 @@
$answer["total_warehouse"] = $report->getTotalWarehouse();
$answer["total_location"] = $report->getTotalLocation();
$answer["total_capacity"] = $report->getTotalCapacity();
$answer["space_used"] = $report->getSpaceUsed();
$answer["total_product"] = $report->getTotalProduct();
$answer["success"] = 1;