[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
@@ -1,60 +1,13 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
require '../../../assets/utils/classes/ReportManager.php';
$product_sku = $data['product_sku'] ?? '';
$lot_number = $data['lot_number'] ?? '';
if (!$product_sku || !$lot_number) {
$answer['output'] = [];
$answer['success'] = 1;
exit(json_encode($answer));
}
// Discover all warehouses
$sth = $pdo2->prepare(
"SELECT id, warehouse_name FROM md_warehouse
WHERE company_id = :company_id AND status = 1"
$report = new ReportManager($pdo2, $company_id);
$answer['output'] = $report->getLotStockLog(
$data['product_sku'] ?? '',
$data['lot_number'] ?? ''
);
$sth->execute([':company_id' => $company_id]);
$warehouses = $sth->fetchAll(PDO::FETCH_ASSOC);
$rows = [];
foreach ($warehouses as $wh) {
$safe = preg_replace('/[^a-zA-Z0-9_]/', '', $wh['warehouse_name']);
$table = "td_stock_{$safe}";
$sth = $pdo2->prepare(
"SELECT
s.id,
s.date,
s.type,
s.zone,
s.aisle,
s.rack,
ROUND(COALESCE(s.`in`, 0), 2) AS stock_in,
ROUND(COALESCE(s.`out`, 0), 2) AS stock_out,
s.serial_number,
s.description,
'{$wh['warehouse_name']}' AS warehouse_name
FROM `{$table}` s
WHERE s.company_id = :company_id
AND s.product_sku = :product_sku
AND s.lot_number = :lot_number
ORDER BY s.date DESC"
);
$sth->execute([
':company_id' => $company_id,
':product_sku' => $product_sku,
':lot_number' => $lot_number,
]);
$rows = array_merge($rows, $sth->fetchAll(PDO::FETCH_ASSOC));
}
// Sort all rows by date DESC
usort($rows, fn($a, $b) => strcmp($b['date'], $a['date']));
$answer['output'] = $rows;
$answer['success'] = 1;
exit(json_encode($answer));
?>