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
+25
View File
@@ -0,0 +1,25 @@
<?php
/**
* alert_overdue_invoices.php — Called by Node.js scheduler daily at 9am.
* Returns companies that have one or more issued sales invoices past their due date.
* status = 1 means issued but not fully settled. status = 2 means fully settled.
* Response: { success: 1, alerts: [{ company_id, count }] }
*/
require __DIR__ . '/../assets/utils/cron_auth.php';
$sth = $pdo1->query(
"SELECT company_id, COUNT(*) AS count
FROM td_invoice
WHERE company_id > 0
AND doc_type = 'invoice'
AND status = 1
AND due_date IS NOT NULL
AND due_date < CURDATE()
GROUP BY company_id
HAVING count > 0"
);
$answer['success'] = 1;
$answer['alerts'] = $sth->fetchAll(PDO::FETCH_ASSOC);
exit(json_encode($answer));