cron low stock - overdue invoice

This commit is contained in:
Thanakorn S
2026-05-27 11:45:48 +07:00
parent ebccca4989
commit 8916d9180d
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));
+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));