Builders for the CT-e (model 57 and 67) events, layout 4.00.
Like SefazNfe.Events, these carry no tax arithmetic: a key, a protocol and
a few facts. The shape differs from the NF-e's in four ways, all from
eventoCTe_v4.00.xsd (and confirmed against NFePHP sped-cte):
- the root is
eventoCTe(versao4.00) in the CT-e namespace, sent alone: there is noenvEventoand noidLote; - the key is
chCTe, anddetEventocarriesversaoEvento, notversao; detEventoholds one element per event (evCancCTe,evCCeCTe,evCECTe,evCancCECTe,evIECTe,evCancIECTe), where an NF-e event puts its fields indetEventodirectly;nSeqEventoand the last part ofIdhave three digits.
| Event | Code | Element |
|---|---|---|
| cancel | 110111 | evCancCTe |
| CC-e | 110110 | evCCeCTe |
| delivery proof | 110180 | evCECTe |
| cancel of the delivery proof | 110181 | evCancCECTe |
| delivery failure | 110190 | evIECTe |
| cancel of the delivery failure | 110191 | evCancIECTe |
The delivery hash
hashEntrega and hashTentativaEntrega are, per the MOC and the XSD,
"Hash (SHA1) no formato Base64 resultante da concatenacao: Chave de acesso
do CT-e + Base64 da imagem capturada". delivery_hash/2 is exactly that:
Base.encode64(sha1(ch_cte <> Base.encode64(image))), where the
concatenation is of the two ASCII texts, not of the key and the raw image
bytes. The result is 28 characters (the XSD's 20-byte base64Binary). The MOC
adds that SEFAZ has no control over the field: it is the author's own index to
the proof it keeps. NFePHP only forwards a hash the caller computed.
A caller that keeps the image elsewhere may compute the hash itself and pass it
as :hash instead of :image: the 28 characters of the Base64 of the 20-byte
SHA-1. valid_hash?/1 is the check the XSD makes (base64Binary of length 20).
Summary
Functions
Event 110111, cancelling an authorized CT-e.
Event 110191, cancelling the delivery failure whose protocol is :n_prot_ie.
Event 110181, cancelling the delivery proof whose protocol is :n_prot_ce.
Event 110110, the structured Carta de Correcao.
Event 110190, the insucesso na entrega.
The delivery hash: Base.encode64(sha1(ch_cte <> Base.encode64(image))). See
the moduledoc.
Event 110180, the comprovante de entrega.
Whether hash is what hashEntrega and hashTentativaEntrega accept: 28
characters of Base64 that decode to 20 bytes (a SHA-1).
Functions
Event 110111, cancelling an authorized CT-e.
Event 110191, cancelling the delivery failure whose protocol is :n_prot_ie.
Event 110181, cancelling the delivery proof whose protocol is :n_prot_ce.
Event 110110, the structured Carta de Correcao.
opts.corrections is a list of maps with :grupo_alterado, :campo_alterado
and :valor_alterado, and optionally :nro_item_alterado (the 1-based index
when the corrected field is in a list). xCondUso is the fixed legal text.
Event 110190, the insucesso na entrega.
opts: :n_prot, :dh_tentativa_entrega, :tp_motivo (1 recebedor nao
encontrado, 2 recusa do recebedor, 3 endereco inexistente, 4 outros) and
optionally :n_tentativa (three digits), :x_just_motivo (required with
motivo 4), :latitude, :longitude, :image (hashed here) or :hash (the
finished hash); with neither, the hash group is left out, as the XSD allows, :dh_hash and :ch_nfes.
The delivery hash: Base.encode64(sha1(ch_cte <> Base.encode64(image))). See
the moduledoc.
Event 110180, the comprovante de entrega.
opts: :n_prot (of the CT-e), :dh_entrega, :n_doc, :x_nome, :image
(the proof's bytes, hashed here, see the moduledoc; or :hash, the finished
hash, instead of it) and optionally
:latitude, :longitude, :ch_nfes (the NF-e keys delivered, for a normal
service) and :dh_hash (when the hash was generated; dhEntrega by default).
Whether hash is what hashEntrega and hashTentativaEntrega accept: 28
characters of Base64 that decode to 20 bytes (a SHA-1).