FinchContext
Run with

Build the DMR Monthly Remuneration Declaration (AT)

Skill: Convert monthly payroll into the Declaração Mensal de Remunerações (DMR) XML

Region: Portugal Category: Payroll tax — DMR (Declaração Mensal de Remunerações), Autoridade Tributária e Aduaneira (AT) Does: Takes a month's payroll figures and produces the AT DMR XML — the employer's monthly declaration of employment/pension income paid and IRS withholding (retenção na fonte) retained, with one record per employee carrying the income type code (A, H, …), the gross remuneration, the IRS withheld, and the geographic zone (Continente / Açores / Madeira), for upload on the Portal das Finanças.

Schema version: AT DMR (Declaração Mensal de Remunerações, Modelo aprovado pela Portaria n.º 6/2013 e alterações) — IRS/AT side only

The DMR submitted to the AT covers only the IRS dimension (income paid + IRS withholding + IRS surcharges). The parallel Segurança Social monthly declaration (DRI / "Declaração de Remunerações" via Segurança Social Direta) is a separate file with its own schema — this skill does not produce it. The DMR-AT is due by the 10th day of the month following the one in which the income was paid or made available. The AI builds the XML; validate it against the current AT DMR schema and the Portal das Finanças validator before submission.


When this applies


Conversion procedure

  1. Read the source. Accept a payroll export (CSV/JSON one row per employee), a payroll-software report, or pasted figures. For each beneficiary capture: NIF, income code, gross income for the period, IRS withheld, any surcharge, other withholdings, and the zone.
  2. Extract the entity header. The employer NIF (NIFEmpregador), the reference year and month (Periodo), and a declaration type (1 first / 2 substitution).
  3. Validate identifiers. Every NIF is 9 digits. If a beneficiary NIF, an income code, or the withheld amount is missing or ambiguous, stop and ask — do not default a NIF or assume the income code.
  4. Normalise. Period as YYYY-MM; amounts to dot-decimal 2 dp; income codes to the AT letter codes (A, H, A1, …); zone to C (Continente), RA-A (Açores), RA-M (Madeira) — match your schema's zone enumeration.
  5. Build one record per beneficiary. Each Remuneracao carries NIF, CodRendimento, Valor (income), RetencaoIRS, Sobretaxa (if any), ContribObrigatorias, RetencaoSobretaxa, QuotizacaoSindical, and LocalObtencaoRendimentos (the zone).
  6. Compute totals and reconcile. Sum income, IRS retained, and surcharge across all records into the declaration totals; the per-beneficiary IRS must reconcile with the payroll register. Flag any mismatch.
  7. Validate. Work through the checklist; validate against the AT DMR schema.

Source → DMR field map

From the source → Target element / field
Employer NIF DMRAT/Cabecalho/NIFEmpregador
Reference year Cabecalho/AnoDeclaracao
Reference month (0112) Cabecalho/MesDeclaracao
Declaration type (1 first / 2 subst.) Cabecalho/TipoDeclaracao
Reference / receipt of prior declaration Cabecalho/ReferenciaDeclaracao
Total income declared Cabecalho/TotalRendimentos
Total IRS withheld Cabecalho/TotalRetencoesIRS
Total surcharge withheld Cabecalho/TotalRetencoesSobretaxa
Beneficiary NIF Quadro/Remuneracao/NIF
Income type code (A, H, …) Remuneracao/CodRendimento
Gross income for the period Remuneracao/Valor
IRS withheld (retenção na fonte) Remuneracao/RetencaoIRS
IRS surcharge (sobretaxa) Remuneracao/Sobretaxa
Surcharge withheld Remuneracao/RetencaoSobretaxa
Mandatory social contributions Remuneracao/ContribObrigatorias
Trade-union dues Remuneracao/QuotizacaoSindical
Zone (Continente / Açores / Madeira) Remuneracao/LocalObtencaoRendimentos

Every required output element appears above. Repeat Remuneracao once per beneficiary-and-income-code combination.


Document structure

DMRAT  (DMR — AT / IRS declaration)
├── Cabecalho                                  (header — once)
│   ├── NIFEmpregador                          (9-digit employer NIF)
│   ├── AnoDeclaracao                          (yyyy)
│   ├── MesDeclaracao                          (01–12)
│   ├── TipoDeclaracao                         (1 primeira | 2 substituicao)
│   ├── ReferenciaDeclaracao                   (receipt of declaration being replaced; blank if first)
│   ├── TotalRendimentos                       (Σ income)
│   ├── TotalRetencoesIRS                      (Σ IRS withheld)
│   └── TotalRetencoesSobretaxa                (Σ surcharge withheld)
└── Quadro                                     (body — the remuneration table)
    └── Remuneracao *                          (one per beneficiary + income code)
        ├── NIF                                (beneficiary NIF)
        ├── CodRendimento                      (A, A1, H, H1, B, …)
        ├── LocalObtencaoRendimentos           (C | RA-A | RA-M)
        ├── Valor                              (gross income)
        ├── RetencaoIRS                        (IRS withheld)
        ├── Sobretaxa                          (surcharge base, where applicable)
        ├── RetencaoSobretaxa                  (surcharge withheld)
        ├── ContribObrigatorias                (mandatory SS/CGA contributions)
        └── QuotizacaoSindical                 (union dues)

Notes: every Remuneracao is keyed by NIF + CodRendimento + LocalObtencaoRendimentos; the same employee can have multiple records if paid under several income codes or zones. Sobretaxa/RetencaoSobretaxa are zero in years where the IRS surcharge no longer applies but the elements remain in the schema.


Code tables

CodRendimento (income type — selected)

Code Meaning
A Rendimentos do trabalho dependente (employment income, Categoria A)
A1 Trabalho dependente — gratificações não atribuídas pela entidade patronal
H Pensões (Categoria H)
H1 Pensões — rendas temporárias e vitalícias
B Rendimentos empresariais e profissionais com retenção (Categoria B)
SR Rendimentos sujeitos a taxas liberatórias / sem retenção (where applicable)

LocalObtencaoRendimentos (zone — determines the withholding tables)

Code Meaning
C Continente (mainland)
RA-A Região Autónoma dos Açores
RA-M Região Autónoma da Madeira

TipoDeclaracao

Code Meaning
1 Primeira declaração (first declaration for the period)
2 Declaração de substituição (replaces a prior one — ReferenciaDeclaracao required)

Calculation rules


Worked example (end-to-end)

Exemplo Empregador, Lda. (NIF 501234567) files the DMR for June 2026, first declaration. One employee, NIF 198765432, was paid employment income (A) in the mainland (C) of 2000.00 gross, with 300.00 IRS withheld and 220.00 mandatory social-security contributions; no surcharge applies. Header totals: income 2000.00, IRS 300.00, surcharge 0.00.

Input — payroll export (pasted)

Empregador: Exemplo Empregador, Lda. | NIF 501 234 567 | Periodo 2026-06 | Tipo: primeira
Funcionario: NIF 198 765 432 | Cod A | Zona Continente
  Rendimento bruto 2.000,00 | Retencao IRS 300,00 | Contrib. obrigatorias 220,00 | Sindical 0,00

After extraction + normalisation (intermediate)

NIFEmpregador 501234567 ; Ano 2026 ; Mes 06 ; TipoDeclaracao 1
Remuneracao: NIF 198765432 ; CodRendimento A ; Local C ; Valor 2000.00 ; RetencaoIRS 300.00 ;
             Sobretaxa 0.00 ; RetencaoSobretaxa 0.00 ; ContribObrigatorias 220.00 ; QuotizacaoSindical 0.00
Totais: TotalRendimentos 2000.00 ; TotalRetencoesIRS 300.00 ; TotalRetencoesSobretaxa 0.00

Output — DMR (AT) XML

<?xml version="1.0" encoding="UTF-8"?>
<DMRAT xmlns="http://www.at.gov.pt/schemas/dmr">
  <Cabecalho>
    <NIFEmpregador>501234567</NIFEmpregador>
    <AnoDeclaracao>2026</AnoDeclaracao>
    <MesDeclaracao>06</MesDeclaracao>
    <TipoDeclaracao>1</TipoDeclaracao>
    <ReferenciaDeclaracao></ReferenciaDeclaracao>
    <TotalRendimentos>2000.00</TotalRendimentos>
    <TotalRetencoesIRS>300.00</TotalRetencoesIRS>
    <TotalRetencoesSobretaxa>0.00</TotalRetencoesSobretaxa>
  </Cabecalho>
  <Quadro>
    <Remuneracao>
      <NIF>198765432</NIF>
      <CodRendimento>A</CodRendimento>
      <LocalObtencaoRendimentos>C</LocalObtencaoRendimentos>
      <Valor>2000.00</Valor>
      <RetencaoIRS>300.00</RetencaoIRS>
      <Sobretaxa>0.00</Sobretaxa>
      <RetencaoSobretaxa>0.00</RetencaoSobretaxa>
      <ContribObrigatorias>220.00</ContribObrigatorias>
      <QuotizacaoSindical>0.00</QuotizacaoSindical>
    </Remuneracao>
  </Quadro>
</DMRAT>

Normalisations shown: employer NIF 501 234 567501234567; beneficiary NIF 198 765 432198765432 (9 digits, no spaces); period → AnoDeclaracao 2026 / MesDeclaracao 06; type "primeira" → TipoDeclaracao 1 (so ReferenciaDeclaracao empty); zone "Continente" → C; amounts 2.000,002000.00 (dot decimal, 2 dp); header totals recomputed from the single record (TotalRendimentos 2000.00, TotalRetencoesIRS 300.00, TotalRetencoesSobretaxa 0.00). The Segurança Social side (DRI) is filed separately and is not part of this XML.


Validation checklist


Last updated: 2026-06-13 — verify the active AT DMR schema, the CodRendimento/zone code lists, the applicability of the IRS sobretaxa, and the monthly submission deadline against the current AT specification before use.