5.3.1.1.1. Invoice Number Generation

The invoice number is generated using the following components:
 
  • Taxpayer ID – Uniquely identifies the business. This value is obtained during terminal activation, typically from the activation response.
  • Terminal Position – identifies the terminal within the business site or branch.
  • Julian Date – represents the transaction date in a numeric format.
  • Transaction Count – a sequential number for uniqueness per day.
     
    Each of these values is then converted from Base10 to Base64 for compact representation, and finally combined in this format:
    Base64(TaxpayerID) - Base64(TerminalPosition) - Base64(JulianDate) - Base64(Count)
     
C# Example: implementation of the method that combines encoded values into the final invoice number:
 
internal string GenerateInvoiceNumber(InvoiceGenerationRequest invoiceGenerationRequest)
 
{
 
    var julianDate = ToJulianDate(Convert.ToDateTime(invoiceGenerationRequest.transactiondate));
 
    var combinedString = GenerateCombinedString(invoiceGenerationRequest.businessId,
 
                                                invoiceGenerationRequest.terminalPosition,
 
                                                julianDate, invoiceGenerationRequest.transactionCount);
 
    return combinedString;
 
}
 
private int ToJulianDate(DateTime date)
{
 
    date = date.Date;
 
    int year = date.Year;
    int month = date.Month;
    int day = date.Day;
 
    if (month <= 2)
    {
        year -= 1;
        month += 12;
    }
 
    int A = year / 100;
    int B = 2 - A + (A / 4);
 
    int JD = (int)(Math.Floor(365.25 * (year + 4716))
        + Math.Floor(30.6001 * (month + 1))
        + day + B - 1524);
 
    return JD;
}
 
private string GenerateCombinedString(long taxpayerId, int position, long julianDate, long transactionCount)
{
    var base64TaxpayerNumber = Base10ToBase64(taxpayerId);
    var base64Position = Base10ToBase64(position);
    var julianDateBase64 = Base10ToBase64(julianDate);
    var serialNumberBase64 = Base10ToBase64(transactionCount);
 
    return $"{base64TaxpayerNumber}-{base64Position}-{julianDateBase64}-{serialNumberBase64}";
}
 
C# Example: Converting a Base10 value to Base64
 
public static string Base10ToBase64(long number)
{
    if (number == 0)
    {
        return "A";  // 'A' represents 0 in standard Base64
    }
    const string base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    StringBuilder result = new StringBuilder();
 
    while (number > 0)
    {
        int remainder = (int)(number % 64);
        result.Insert(0, base64Chars[remainder]);
        number /= 64;
    }
 
    return result.ToString();
}