<?php
/**
 * Cron script to generate monthly invoices.
 * Run this via CLI: php cron_generate_invoices.php
 */

require_once __DIR__ . '/vendor/autoload.php';

// Simple autoloader for App namespace
spl_autoload_register(function ($class) {
    $prefix = 'App\\';
    $base_dir = __DIR__ . '/app/';
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) return;
    $relative_class = substr($class, $len);
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
    if (file_exists($file)) require $file;
});

use App\Core\InvoiceGenerator;

echo "Starting monthly invoice generation..." . PHP_EOL;
$count = InvoiceGenerator::generateMonthly();
echo "Successfully generated $count invoices for " . date('F Y') . "." . PHP_EOL;
