<?php

function getNextInvoiceNumber() {
    $file_path = __DIR__ . '/../data/invoice_number.txt';
    
    // Create file if it doesn't exist
    if (!file_exists($file_path)) {
        file_put_contents($file_path, '00001');
    }
    
    // Read current number
    $current_number = (int)file_get_contents($file_path);
    
    // Generate next number
    $next_number = str_pad($current_number + 1, 5, '0', STR_PAD_LEFT);
    
    // Save next number
    file_put_contents($file_path, $next_number);
    
    // Return current number (the one we're using now)
    return str_pad($current_number, 5, '0', STR_PAD_LEFT);
}
