cron low stock - overdue invoice

This commit is contained in:
Thanakorn S
2026-05-27 11:45:48 +07:00
parent 458a883810
commit a6651c41b9
3 changed files with 109 additions and 4 deletions
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* alert_low_stock.php — Called by Node.js scheduler daily at 8am.
* Returns companies that have one or more SKUs below their min_stock threshold.
* Response: { success: 1, alerts: [{ company_id, count }] }
*/
require __DIR__ . '/../assets/utils/cron_auth.php';
$sth = $pdo1->query(
"SELECT e.company_id, COUNT(*) AS count
FROM etl_stock_summary e
JOIN md_product p
ON p.product_sku = e.product_sku
AND p.company_id = e.company_id
AND p.status = 1
WHERE e.company_id > 0
AND p.min_stock > 0
AND (e.total_in - e.total_out) < p.min_stock
GROUP BY e.company_id
HAVING count > 0"
);
$answer['success'] = 1;
$answer['alerts'] = $sth->fetchAll(PDO::FETCH_ASSOC);
exit(json_encode($answer));