SefazDanfe.ContingencyCode (sefaz_danfe v0.1.0)

Copy Markdown View Source

The additional barcode of the documents printed in contingency on the security form (FS-DA, and FS-IA of the NF-e): "Dados da NF-e" (MOC 7.0, Anexo II, item 2.9.2) and "Dados do CT-e" (MOC 3.00a of the DACTE, item 2.18.2). It is a Code 128 subset C of 36 digits, and the same 36 digits in nine blocks of four go printed in the box next to it.

The layout, every field right aligned, zero padded and without formatting:

FieldSizeContent
cUF2IBGE code of the UF of the recipient (or sender); 99 for a foreign one
tpEmis1the emission type
CNPJ14CNPJ of the recipient (or sender), its CPF zero padded, zeros when foreign
vNF14the total value in cents (vNF of the NF-e, vTPrest of the CT-e)
ICMSp11 when the own ICMS is shown on the document, else 2
ICMSs11 when the ICMS of the tax substitution is shown, else 2
DD2the day of the emission
DV1the check digit, modulo 11 as the one of the access key

Pure: build/1 takes what the data modules read from the XML and answers the digits and their presentation.

Summary

Functions

The code of a document: %{"digits" => "...36 digits...", "formatted" => "9999 9999 ..."}.

The check digit of digits: modulo 11 with weights 2 to 9 from the right, as the access key's. It is 11 - rem(sum, 11), and 0 when the remainder is 0 or 1.

The digits in blocks of four, separated by a space.

Whether a decimal as the XML writes it (28.80) is greater than zero.

The IBGE code of a UF; 99 for EX, an unknown UF or none.

Types

input()

@type input() :: %{
  optional(:uf) => String.t() | nil,
  optional(:emission_type) => integer() | nil,
  optional(:tax_id) => String.t() | nil,
  optional(:amount) => String.t() | nil,
  optional(:own_icms?) => boolean(),
  optional(:st_icms?) => boolean(),
  optional(:issued_at) => String.t() | nil
}

Functions

build(input)

@spec build(input()) :: %{required(String.t()) => String.t()}

The code of a document: %{"digits" => "...36 digits...", "formatted" => "9999 9999 ..."}.

  • :uf - the UF of the recipient or sender ("EX" or none for a foreign one);
  • :emission_type - the tpEmis;
  • :tax_id - the CNPJ (14 digits) or CPF (11 digits, zero padded) of the same party, nil when foreign; punctuation is ignored;
  • :amount - the total value as the XML writes it ("252.00");
  • :own_icms? and :st_icms? - the ICMS flags;
  • :issued_at - the dhEmi (ISO 8601), of which the day is taken.

check_digit(digits)

@spec check_digit(String.t()) :: 0..9

The check digit of digits: modulo 11 with weights 2 to 9 from the right, as the access key's. It is 11 - rem(sum, 11), and 0 when the remainder is 0 or 1.

format(digits)

@spec format(String.t()) :: String.t()

The digits in blocks of four, separated by a space.

positive?(value)

@spec positive?(String.t() | nil) :: boolean()

Whether a decimal as the XML writes it (28.80) is greater than zero.

uf_code(uf)

@spec uf_code(String.t() | nil) :: String.t()

The IBGE code of a UF; 99 for EX, an unknown UF or none.