<?php
declare(strict_types=1);

function generateDeclarationNumber(PDO $pdo, string $custShort): string
{
    $year = date('Y');

    // Count existing submitted declarations this year
    $stmt = $pdo->prepare("
        SELECT COUNT(*) 
        FROM md_declarations
        WHERE YEAR(locked_at) = :year
    ");

    $stmt->execute([
        'year' => $year
    ]);

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

    return sprintf(
        "%s-%s-%05d",
        strtoupper($custShort),
        $year,
        $count
    );
}
