26 lines
768 B
PHP
26 lines
768 B
PHP
<?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));
|