SefazDanfe.Contingency (sefaz_danfe v0.1.0)

Copy Markdown View Source

The contingency of a document, read from its ide: tpEmis (the emission type) and, when the XML has them, dhCont (when the contingency began) and xJust (why).

The data maps of the four documents carry "emission_type" (the tpEmis number) and "contingency": nil for a normal emission (tpEmis 1), otherwise

%{"mode" => "fs_da", "entered_at" => "13/10/2026 09:30:00", "reason" => "..."}

"mode" names the emission type ("fs_ia", "fs_da", "epec", "svc_an", "svc_rs", "svc_sp", "offline" or "contingency"), "entered_at" and "reason" are nil when the XML does not have them. Whether the printed document carries a notice is decided by the layout from "emission_type".

The NF-e and the CT-e FS-DA also carry "contingency_code", the digits of the second barcode (SefazDanfe.ContingencyCode), nil for any other emission.

What each document prints

The texts are the official ones; capital letters are the manuals' emphasis.

DANFE (NF-e)

tpEmisPrinted
2 (FS-IA), 5 (FS-DA)notice "DANFE EM CONTINGÊNCIA - IMPRESSO EM DECORRÊNCIA DE PROBLEMAS TÉCNICOS"; second barcode "DADOS DA NF-E" (campo 1, below the access key barcode, in place of the consulta URL) and its 36 digits in nine blocks of four (campo 2, the protocol box, labelled "DADOS DA NF-E")
4 (EPEC)notice "DANFE impresso em contingência - EPEC regularmente recebida pela Receita Federal do Brasil"; the protocol box is labelled "PROTOCOLO DE AUTORIZAÇÃO DO EPEC"; campo 1 keeps the consulta URL
6, 7 (SVC-AN, SVC-RS)no notice, printed as a normal emission

Source: MOC 7.0, Anexo II (DANFE), the contingency items, and item 2.9.2 for the second barcode; MOC on-line (SEFAZ-PR), "Contingência". In every contingency the line "Entrada em contingência" (dhCont) and "Justificativa" (xJust) prints in the additional data, which is mandatory.

DANFE NFC-e

tpEmisPrinted
9 (offline)"EMITIDA EM CONTINGÊNCIA" and "Pendente de autorização", in emphasis, on two lines, below the header (Divisão I) and below the identification of the NFC-e (Divisão VII). They always print, even if the XML carries a protocol; the "Protocolo de autorização" line is suppressed. dhCont and xJust are not printed.

Source: MOC 7.0, Anexo III (DANFE NFC-e), Divisões I and VII. The :copy option of SefazDanfe.render/2 prints "Via do Estabelecimento" next to the emission date and time.

DACTE (CT-e)

tpEmisPrinted
5 (FS-DA)notice "DACTE EM CONTINGÊNCIA - IMPRESSO EM DECORRÊNCIA DE PROBLEMAS TÉCNICOS"; second barcode "DADOS DO CT-E" below the access key (campo 1) and its numeric form in the protocol box (campo 2); value vTPrest, party the recipient (the sender when the CT-e has none); ICMSp is 1 with a vICMS (ICMS00, 20, 90), ICMSs is 1 with vICMSSTRet (ICMS60)
4 (EPEC), 2 (offline), 7, 8 (SVC)no notice: the manuals define no text. The dhCont / xJust line prints in the observations

Source: DACTE Anexo II, MOC 3.00a, items 2.4 and 2.18.2; NT 2026.004. By NT 2026.004 the CT-e FS-DA and EPEC contingencies are retired from 14/12/2026, except the FS-DA in MG; the CT-e offline contingency (tpEmis 2) stays and its QR code (sign) comes in the XML.

DAMDFE (MDF-e)

tpEmisPrinted
2"EMISSÃO EM CONTINGÊNCIA", mandatory and in emphasis, in the place of the authorization protocol; no banner

Source: DAMDFE Anexo II, MOC 3.00a, item 2.4.

Summary

Functions

The "contingency" map of an ide of a document of type, nil for a normal emission.

The "emission_type" (the tpEmis number) of an ide, nil when it has none.

Types

type()

@type type() :: :nfe | :nfce | :cte | :mdfe

Functions

build(type, ide)

@spec build(type(), map()) :: map() | nil

The "contingency" map of an ide of a document of type, nil for a normal emission.

emission_type(ide)

@spec emission_type(map()) :: integer() | nil

The "emission_type" (the tpEmis number) of an ide, nil when it has none.