[OOP] contact,inventory,ics,dashboard

This commit is contained in:
Thanakorn S
2026-04-28 15:44:57 +07:00
parent 3d3b497c08
commit 2061624641
49 changed files with 1946 additions and 2146 deletions
+9 -41
View File
@@ -1,46 +1,14 @@
<?php
<?php
session_start();
require '../../../assets/utils/db_auth.php';
require '../../../assets/utils/classes/WarehouseManager.php';
// Build filter + params based on operation type.
// Filter warehouses by occupancy:
// 'to' = destination → only warehouses with at least one empty rack
// 'from' = source → only warehouses that hold the specific product SKU
// other = all warehouses (for read-only listings, dashboards, etc.)
$product_sku_filter = "";
$params = [":company_id" => $company_id];
if ($data["type"] == "to") {
$product_sku_filter = "AND r.product_sku IS NULL";
} elseif ($data["type"] == "from") {
$product_sku_filter = "AND r.product_sku = :product_sku";
$params[":product_sku"] = $data["product_sku"];
}
if(!empty($data["id"])){
$product_sku_filter = "";
unset($params[":product_sku"]);
}
// Only list warehouses that have racks matching the occupancy filter.
// EXISTS is efficient here — it stops searching as soon as one match is found.
$sql = "SELECT w.id, w.warehouse_name
FROM md_warehouse w
WHERE w.company_id = :company_id
AND EXISTS (
SELECT 1 FROM md_rack r
WHERE r.company_id = w.company_id
AND r.warehouse = w.id
$product_sku_filter
)
ORDER BY w.warehouse_name";
$sth = $pdo2->prepare($sql);
$sth->execute($params);
db_check($sth, $answer);
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["success"] = 1;
$wh = new WarehouseManager($pdo2, $company_id);
$answer['output'] = $wh->getWarehouseList(
$data['type'] ?? '',
$data['product_sku'] ?? '',
(int)($data['id'] ?? 0)
);
$answer['success'] = 1;
exit(json_encode($answer));
?>