<?php
// notification.php
require_once "db.php";

$today = date('Y-m-d');

// Fetch due payment notifications
$query = "
SELECT s.invoice_no, c.customer_name, s.due, s.payment_due_date 
FROM sales s 
JOIN customers c ON s.customer_id = c.customer_id 
WHERE s.due > 0 AND s.payment_due_date = '$today'
ORDER BY s.sale_id DESC
";
$result = $conn->query($query);

$notifications = [];
while ($row = $result->fetch_assoc()) {
    $notifications[] = $row;
}

echo json_encode($notifications);
?>
