FinchContext
Run with

Build Accounting Data into the SAF-T D406 Declaration XML

Skill: Convert ledger and invoice data into the Romanian SAF-T D406 XML

Region: Romania (România) Category: Tax reporting — SAF-T D406 (Declarația informativă D406, ANAF) Does: Takes accounting/ledger/master and invoice data and produces the OECD SAF-T–based D406 XML (AuditFile) — Header, MasterFiles, GeneralLedgerEntries, and SourceDocuments — submitted electronically to ANAF. Schema version: ANAF SAF-T Romania_SAFT_Financiar (OECD SAF-T 2.0 derived) — D406 PDF wrapper validated by ANAF DUKIntegrator

This XML is the D406 informative declaration that taxpayers submit to ANAF; large taxpayers file monthly (or quarterly if on quarterly VAT), medium taxpayers from Jan 2023, small taxpayers from Jan 2025. The full AuditFile (D406) is filed monthly/quarterly; D406T (stocks) and D406A (assets) are on request/year-end. Validate with the ANAF DUKIntegrator (J/A soft) before submission. The AI produces the XML; the user validates and files.


When this applies


Conversion procedure

  1. Read the source. Accept trial balance + journal CSV/JSON, an accounting-system SAF-T export, or pasted ledger and invoice data. Parse company identity, chart of accounts, customers, suppliers, tax codes, journal lines, and sales/purchase invoices.
  2. Extract fields. Identify: company CUI (TaxRegistrationNumber), name, address; period (start/end, fiscal year); GL accounts (number, description, opening/closing); customers and suppliers (id, CUI, balances); tax table (rates, codes); products; every GL journal transaction and line; sales and purchase invoices with line-level VAT. If a mandatory nomenclature code or CUI is missing, stop and ask.
  3. Normalize. Dates → YYYY-MM-DD. CUI → digits only (no RO prefix in TaxRegistrationNumber; RO allowed in VAT fields). Amounts → dot decimal, 2 decimals. Map account types and tax codes to ANAF nomenclatures.
  4. Compute. Recompute per-account debit/credit totals, NumberOfEntries, TotalDebit/TotalCredit control totals in GeneralLedgerEntries, and invoice VAT per line and document. Closing balance = opening + debits − credits.
  5. Emit the AuditFile. Build per the Document structure section using the worked example as the template; set Header/AuditFileVersion and TaxAccountingBasis.
  6. Validate. Run the Validation checklist; pass the file through the ANAF DUKIntegrator validator.

Source → SAF-T field map

From the source → Target element / field
File version (fixed) Header/AuditFileVersion
Country Header/AuditFileCountry (RO)
Fiscal year Header/FiscalYear
Period start / end Header/StartDate, Header/EndDate
Currency Header/CurrencyCode (RON)
Accounting basis Header/TaxAccountingBasis (A/P/BANK…)
Company name Header/Company/Name
Company CUI Header/Company/Registration/TaxRegistrationNumber
Company address Header/Company/Address/...
GL account number MasterFiles/GeneralLedgerAccounts/Account/AccountID
GL account description Account/AccountDescription
Account opening/closing Account/OpeningDebitBalance / ClosingDebitBalance
Customer id + name MasterFiles/Customers/Customer/CustomerID, CompanyName
Customer CUI Customer/CustomerTaxID
Supplier id + name MasterFiles/Suppliers/Supplier/SupplierID, CompanyName
Tax rate + code MasterFiles/TaxTable/TaxTableEntry/TaxCodeDetails/TaxCode, TaxPercentage
Product code + description MasterFiles/Products/Product/ProductCode, Description
Journal id / batch GeneralLedgerEntries/Journal/JournalID
Transaction id + date Journal/Transaction/TransactionID, TransactionDate
GL posting line Transaction/Lines/DebitLine / CreditLine (AccountID, Amount)
Control totals GeneralLedgerEntries/NumberOfEntries, TotalDebit, TotalCredit
Sales invoice no + date SourceDocuments/SalesInvoices/Invoice/InvoiceNo, InvoiceDate
Sales invoice customer Invoice/CustomerInfo/CustomerID
Sales line + VAT Invoice/Line/..., Line/Tax/TaxPercentage, TaxAmount
Purchase invoice SourceDocuments/PurchaseInvoices/Invoice/...
Payments SourceDocuments/Payments/Payment/...

Repeat Account, Customer, Supplier, Transaction, and Invoice as many times as the data requires.


Document structure

AuditFile  (xmlns urn:StandardAuditFile-Taxation-Financial:RO)
├── Header
│   ├── AuditFileVersion / AuditFileCountry (RO)
│   ├── FiscalYear / StartDate / EndDate
│   ├── CurrencyCode (RON) / DateCreated
│   ├── TaxAccountingBasis (A / P / BANK / INSURANCE …)
│   └── Company  (Name, Registration/TaxRegistrationNumber, Address, Contact)
├── MasterFiles
│   ├── GeneralLedgerAccounts
│   │   └── Account (AccountID, AccountDescription, GrouppingCategory, Opening/Closing balances)
│   ├── Customers
│   │   └── Customer (CustomerID, CompanyName, CustomerTaxID, Address, balances)
│   ├── Suppliers
│   │   └── Supplier (SupplierID, CompanyName, SupplierTaxID, …)
│   ├── TaxTable
│   │   └── TaxTableEntry (TaxType, Description, TaxCodeDetails: TaxCode, TaxPercentage, Country)
│   ├── UOMTable / AnalysisTypeTable / MovementTypeTable / Products / Owners   (as applicable)
├── GeneralLedgerEntries
│   ├── NumberOfEntries / TotalDebit / TotalCredit          (control totals)
│   └── Journal  (1..n)
│       └── Transaction (TransactionID, Period, TransactionDate, ...)
│           └── Lines
│               ├── DebitLine  (RecordID, AccountID, DebitAmount/Amount)
│               └── CreditLine (RecordID, AccountID, CreditAmount/Amount)
└── SourceDocuments
    ├── SalesInvoices   (NumberOfEntries, TotalDebit/Credit, Invoice 1..n)
    ├── PurchaseInvoices
    ├── Payments
    ├── MovementOfGoods        (D406T / on request)
    └── AssetTransactions      (D406A / on request)

Header and MasterFiles are mandatory. For the monthly/quarterly D406, GeneralLedgerEntries, SalesInvoices, PurchaseInvoices, and Payments are required; MovementOfGoods and AssetTransactions appear only in the stocks/assets variants.


Code tables

Header/TaxAccountingBasis

Code Meaning
A Accounting (contabilitate financiară — standard)
P Invoicing
BANK Banking institution
INSURANCE Insurance undertaking

Account/GrouppingCategory (Romanian chart of accounts class, by leading digit)

Class Romanian account class
1 Conturi de capitaluri (equity)
2 Conturi de imobilizări (fixed assets)
3 Conturi de stocuri (inventory)
4 Conturi de terți (third parties — receivables/payables)
5 Conturi de trezorerie (treasury/cash)
6 Conturi de cheltuieli (expenses)
7 Conturi de venituri (income)

TVA tax codes TaxTable/.../TaxCode (ANAF nomenclature, selected)

TaxCode TaxPercentage Meaning
1 19 Cota standard (standard 19%)
2 9 Cota redusă 9% (food, medicine)
3 5 Cota redusă 5% (books, housing)
4 0 Scutit cu drept de deducere (zero-rated/exempt with credit)
5 0 Scutit fără drept de deducere (exempt without credit)
6 0 Taxare inversă (reverse charge)
7 0 Neimpozabil / în afara sferei TVA

MovementType (MovementOfGoods, D406T — selected)

Code Meaning
RECEIPT Goods received (intrare)
ISSUE Goods issued (ieșire)
TRANSFER Internal transfer

Calculation rules


Worked example (end-to-end)

Input — pasted month-end data

Companie: Exemplu Distributie SRL, CUI 12345678
Perioada: 2026-05-01 .. 2026-05-31, an fiscal 2026, moneda RON
Plan de conturi:
  4111 Clienti, sold initial debitor 0,00
  707  Venituri din vanzarea marfurilor, sold initial 0,00
  4427 TVA colectata, sold initial 0,00
Client: C001 Client Beta SRL, CUI 87654321
Jurnal vanzari, tranzactia T-2026-05-001, data 2026-05-15:
  Factura FE-2026-0007 catre Client Beta SRL
  Linia: marfuri, net 1.000,00, TVA 19% = 190,00, total 1.190,00
  Inregistrare: 4111 D 1.190,00 ; 707 C 1.000,00 ; 4427 C 190,00

After extraction + normalization (intermediate)

{
  "company": { "name": "Exemplu Distributie SRL", "cui": "12345678" },
  "period": { "fiscalYear": "2026", "start": "2026-05-01", "end": "2026-05-31", "currency": "RON" },
  "accounts": [
    { "id": "4111", "desc": "Clienti", "class": "4", "opening": 0.00 },
    { "id": "707",  "desc": "Venituri din vanzarea marfurilor", "class": "7", "opening": 0.00 },
    { "id": "4427", "desc": "TVA colectata", "class": "4", "opening": 0.00 }
  ],
  "customers": [ { "id": "C001", "name": "Client Beta SRL", "cui": "87654321" } ],
  "transaction": { "id": "T-2026-05-001", "date": "2026-05-15",
    "lines": [ { "type": "D", "account": "4111", "amount": 1190.00 },
               { "type": "C", "account": "707",  "amount": 1000.00 },
               { "type": "C", "account": "4427", "amount": 190.00 } ] },
  "salesInvoice": { "no": "FE-2026-0007", "date": "2026-05-15", "customer": "C001",
    "net": 1000.00, "taxCode": "1", "taxPct": 19, "vat": 190.00, "gross": 1190.00 },
  "control": { "entries": 1, "totalDebit": 1190.00, "totalCredit": 1190.00 }
}

Output — SAF-T D406 AuditFile

<?xml version="1.0" encoding="UTF-8"?>
<AuditFile xmlns="urn:StandardAuditFile-Taxation-Financial:RO">
  <Header>
    <AuditFileVersion>2.0</AuditFileVersion>
    <AuditFileCountry>RO</AuditFileCountry>
    <FiscalYear>2026</FiscalYear>
    <StartDate>2026-05-01</StartDate>
    <EndDate>2026-05-31</EndDate>
    <CurrencyCode>RON</CurrencyCode>
    <DateCreated>2026-06-13</DateCreated>
    <TaxAccountingBasis>A</TaxAccountingBasis>
    <Company>
      <Name>Exemplu Distributie SRL</Name>
      <Registration>
        <TaxRegistrationNumber>12345678</TaxRegistrationNumber>
      </Registration>
      <Address>
        <City>Bucuresti</City>
        <Region>RO-B</Region>
        <Country>RO</Country>
      </Address>
    </Company>
  </Header>
  <MasterFiles>
    <GeneralLedgerAccounts>
      <Account>
        <AccountID>4111</AccountID>
        <AccountDescription>Clienti</AccountDescription>
        <GrouppingCategory>4</GrouppingCategory>
        <OpeningDebitBalance>0.00</OpeningDebitBalance>
        <ClosingDebitBalance>1190.00</ClosingDebitBalance>
      </Account>
      <Account>
        <AccountID>707</AccountID>
        <AccountDescription>Venituri din vanzarea marfurilor</AccountDescription>
        <GrouppingCategory>7</GrouppingCategory>
        <OpeningCreditBalance>0.00</OpeningCreditBalance>
        <ClosingCreditBalance>1000.00</ClosingCreditBalance>
      </Account>
      <Account>
        <AccountID>4427</AccountID>
        <AccountDescription>TVA colectata</AccountDescription>
        <GrouppingCategory>4</GrouppingCategory>
        <OpeningCreditBalance>0.00</OpeningCreditBalance>
        <ClosingCreditBalance>190.00</ClosingCreditBalance>
      </Account>
    </GeneralLedgerAccounts>
    <Customers>
      <Customer>
        <CustomerID>C001</CustomerID>
        <CompanyName>Client Beta SRL</CompanyName>
        <CustomerTaxID>87654321</CustomerTaxID>
      </Customer>
    </Customers>
    <TaxTable>
      <TaxTableEntry>
        <TaxType>TVA</TaxType>
        <Description>Taxa pe valoarea adaugata</Description>
        <TaxCodeDetails>
          <TaxCode>1</TaxCode>
          <Description>Cota standard</Description>
          <TaxPercentage>19.00</TaxPercentage>
          <Country>RO</Country>
        </TaxCodeDetails>
      </TaxTableEntry>
    </TaxTable>
  </MasterFiles>
  <GeneralLedgerEntries>
    <NumberOfEntries>1</NumberOfEntries>
    <TotalDebit>1190.00</TotalDebit>
    <TotalCredit>1190.00</TotalCredit>
    <Journal>
      <JournalID>VANZARI</JournalID>
      <Description>Jurnal vanzari</Description>
      <Type>SA</Type>
      <Transaction>
        <TransactionID>T-2026-05-001</TransactionID>
        <Period>5</Period>
        <TransactionDate>2026-05-15</TransactionDate>
        <Description>Factura FE-2026-0007</Description>
        <Lines>
          <DebitLine>
            <RecordID>1</RecordID>
            <AccountID>4111</AccountID>
            <DebitAmount>1190.00</DebitAmount>
          </DebitLine>
          <CreditLine>
            <RecordID>2</RecordID>
            <AccountID>707</AccountID>
            <CreditAmount>1000.00</CreditAmount>
          </CreditLine>
          <CreditLine>
            <RecordID>3</RecordID>
            <AccountID>4427</AccountID>
            <CreditAmount>190.00</CreditAmount>
          </CreditLine>
        </Lines>
      </Transaction>
    </Journal>
  </GeneralLedgerEntries>
  <SourceDocuments>
    <SalesInvoices>
      <NumberOfEntries>1</NumberOfEntries>
      <TotalDebit>0.00</TotalDebit>
      <TotalCredit>1190.00</TotalCredit>
      <Invoice>
        <InvoiceNo>FE-2026-0007</InvoiceNo>
        <CustomerInfo>
          <CustomerID>C001</CustomerID>
        </CustomerInfo>
        <InvoiceDate>2026-05-15</InvoiceDate>
        <InvoiceType>FT</InvoiceType>
        <Line>
          <LineNumber>1</LineNumber>
          <Description>Marfuri</Description>
          <Quantity>1</Quantity>
          <CreditAmount>1000.00</CreditAmount>
          <Tax>
            <TaxType>TVA</TaxType>
            <TaxCode>1</TaxCode>
            <TaxPercentage>19.00</TaxPercentage>
            <TaxAmount>190.00</TaxAmount>
          </Tax>
        </Line>
        <DocumentTotals>
          <TaxPayable>190.00</TaxPayable>
          <NetTotal>1000.00</NetTotal>
          <GrossTotal>1190.00</GrossTotal>
        </DocumentTotals>
      </Invoice>
    </SalesInvoices>
  </SourceDocuments>
</AuditFile>

Normalisations shown: CUI RO1234567812345678 in TaxRegistrationNumber; dates kept YYYY-MM-DD; amounts 1.000,001000.00; tax code mapped 19%TaxCode 1; closing balances recomputed (4111 debit 0 + 1190.00 = 1190.00); transaction balanced (debit 1190.00 = credit 1000.00 + 190.00); control totals NumberOfEntries 1, TotalDebit = TotalCredit = 1190.00. This AuditFile is loaded into ANAF DUKIntegrator, which wraps it as the D406 PDF for submission.


Validation checklist


Last updated: 2026-06-13 — verify the active ANAF SAF-T schema version, nomenclature code lists, taxpayer phase-in dates, and DUKIntegrator validator before use.