Ricardo!
Estou usando o ACBrNFe1 pra emitir e cancelar.
Exemplo do código de cancelamento:
ACBrNFe1.EventoNFe.Evento.Clear;
ACBrNFe1.EventoNFe.idLote := 1;
with ACBrNFe1.EventoNFe.Evento.Add do
begin
infEvento.dhEvento := now;
infEvento.tpEvento := teCancelamento;
infEvento.detEvento.xJust := vAux;
end;
if ACBrNFe1.EnviarEvento(1) then
begin
with ACBrNFe1.WebServices.EnvEvento do
begin
if EventoRetorno.retEvento.Items[0].RetInfEvento.cStat <> 135 then
begin
raise Exception.CreateFmt(
'Ocorreu o seguinte erro ao cancelar a nota fiscal eletrônica:' + sLineBreak +
'Código:%d' + sLineBreak +
'Motivo: %s', [
EventoRetorno.retEvento.Items[0].RetInfEvento.cStat,
EventoRetorno.retEvento.Items[0].RetInfEvento.xMotivo
]);
end;
// retornos
DataHoraEvento := DateToStr(EventoRetorno.retEvento.Items[0].RetInfEvento.dhRegEvento);
NumeroProtocolo := EventoRetorno.retEvento.Items[0].RetInfEvento.nProt;
XMLCancelamento := EventoRetorno.retEvento.Items[0].RetInfEvento.XML;
CodigoStatus := IntToStr(EventoRetorno.retEvento.Items[0].RetInfEvento.cStat);
MotivoStatus := EventoRetorno.retEvento.Items[0].RetInfEvento.xMotivo;
end;
end
else
begin
with ACBrNFe1.WebServices.EnvEvento do
begin
raise Exception.Create(
'Ocorreram erros ao tentar efetuar o cancelamento:' + sLineBreak +
'Lote: ' + IntToStr(EventoRetorno.idLote) + sLineBreak +
'Ambiente: ' + TpAmbToStr(EventoRetorno.tpAmb) + sLineBreak +
'Orgao: ' + IntToStr(EventoRetorno.cOrgao) + sLineBreak +
sLineBreak +
'Status: ' + IntToStr(EventoRetorno.cStat) + sLineBreak +
'Motivo: ' + EventoRetorno.xMotivo
);
end;
end;