<?php
require_once __DIR__ . '/bootstrap.php';

function generate_invoice_number(): string
{
    global $pdo;

    $year = date('Y');

    $stmt = $pdo->prepare(
        'SELECT COUNT(*) FROM invoices WHERE invoice_number LIKE :prefix'
    );
    $stmt->execute(['prefix' => "INV-$year-%"]);

    $count = (int)$stmt->fetchColumn() + 1;

    return sprintf('INV-%s-%06d', $year, $count);
}
