Files
wms-app/app/dashboard/api/engine_report/low_stock.php
T

31 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/../../../session.php';
require_once '../../../assets/utils/db_auth.php';
require_once '../../../assets/utils/classes/ReportManager.php';
$report = new ReportManager($pdo2, $company_id);
$items = $report->getLowStockItems();
$critical = 0;
$warning = 0;
foreach ($items as $item) {
if ($item['status'] === 'critical') { $critical++; } else { $warning++; }
}
// Every active warehouse, so one with healthy stock still appears in the
// filter (and reads as "nothing low here") instead of looking left out.
$sth = $pdo2->prepare("SELECT id, warehouse_name FROM md_warehouse WHERE company_id = :cid AND status = 1 ORDER BY warehouse_name");
$sth->execute([':cid' => $company_id]);
$answer['output'] = [
'items' => $items,
'warehouses' => $sth->fetchAll(PDO::FETCH_ASSOC),
'total_low' => count($items),
'total_critical' => $critical,
'total_warning' => $warning,
];
$answer['success'] = 1;
exit(json_encode($answer));
?>