Boa tarde,
tenho essa função no meu sistema para processar o retorno de cancelamento de NF, porém quando o cancelamento dá duplicidade, não estou conseguindo pegar o protocolo do cancelamento
Tentei pegar por ai e não deu certo. ALguem já precisou dessa informação ?
prot := NotaAcbr.WebServices.Consulta.procEventoNFe[i].RetEventoNFe.InfEvento.detEvento.nProtEvento;
procedure TProcessoNotaFiscal.ProcessarRetornoCancelamento(just : string);
var
codStat, i : Integer;
xml, prot : string;
dt : TDateTime;
trans : TDBXTransaction;
begin
codStat := NotaAcbr.WebServices.EnvEvento.EventoRetorno.retEvento.Items[0].RetInfEvento.cStat;
case codStat of
//Evento registrado
135 : begin
xml := NotaACBR.WebServices.EnvEvento.EventoRetorno.retEvento.Items[0].RetInfEvento.XML;
prot := NotaAcbr.WebServices.EnvEvento.EventoRetorno.retEvento.Items[0].RetInfEvento.nProt;
dt := NotaAcbr.WebServices.EnvEvento.EventoRetorno.retEvento.Items[0].RetInfEvento.dhRegEvento;
end;
//Duplicidade
573 : begin
NotaAcbr.NotasFiscais.Clear;
NotaAcbr.WebServices.Consulta.NFeChave := CdsDfe.AsStr('DFECHAVE');
NotaAcbr.WebServices.Consulta.ExtrairEventos := true;
NotaAcbr.WebServices.Consulta.Executar;
if NotaAcbr.WebServices.Consulta.cStat in [100, 101] then begin
for i := 0 to NotaAcbr.WebServices.Consulta.procEventoNFe.Count - 1 do begin
if NotaAcbr.WebServices.Consulta.procEventoNFe[i].RetEventoNFe.InfEvento.tpEvento = TpcnTpEvento.teCancelamento then begin
xml := NotaAcbr.WebServices.Consulta.procEventoNFe[i].RetEventoNFe.XML;
prot := NotaAcbr.WebServices.Consulta.procEventoNFe[i].RetEventoNFe.InfEvento.detEvento.nProtEvento;
dt := NotaAcbr.WebServices.Consulta.procEventoNFe[i].RetEventoNFe.InfEvento.dhEvento;
just := NotaAcbr.WebServices.Consulta.procEventoNFe[i].RetEventoNFe.InfEvento.detEvento.xJust;
end;
end;
end else
AddMsg(NotaAcbr.WebServices.Consulta.xMotivo, true);
end;
else
AddMsg('Não foi possível cancelar a NF.' + sLineBreak +
notaAcbr.WebServices.EnvEvento.EventoRetorno.retEvento.Items[0].RetInfEvento.xMotivo, true);
end;
if Sucesso then begin
trans := IniciarTransacao;
CdsDfe.Editar;
CdsDfe.FieldByName('DFEXMLCANCELADO').AsString := xml;
CdsDfe.FieldByName('DFEPROTOCOLOCANC').AsString := prot;
CdsDfe.FieldByName('DFEDATACANC').AsDateTime := dt;
CdsDfe.FieldByName('DFEJUSTCANC').AsString := just;
CdsDfe.FieldByName('DFESIT').AsInteger := Ord(esdCANCELADO);
CdsDfe.Commit;
CommitTransacao(trans);
end;
end;