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)); ?>