<?php
// cron_check_due.php
// Crontab: 30 0 * * * /usr/bin/php /path/to/cron_check_due.php

require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../includes/functions.php';

if (php_sapi_name() !== 'cli') die('Access denied.');

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

$stmt = $db->prepare("UPDATE bills SET status = 'overdue' WHERE status = 'unpaid' AND due_date < ?");
$stmt->execute([$today]);
echo "Updated " . $stmt->rowCount() . " bills to overdue.\n";