Boa tarde Pessoal,
estou tentando cancelar uma Nfe estã dando o seguinte erro
meu codigo de cancelamento e este
// numero do lote de envio (somente um exemplo, pode-se utilizar seu proprio controle)
NumeroLote := StrToInt(FormatDateTime('yymmddhhmm', NOW));
if not(InputQuery('WebServices Cancelamento', 'Justificativa', vAux)) then
exit;
// Criar o cancelamento
ACBrNFe1.EventoNFe.Evento.Clear;
if ckTeste.Checked then
ACBrNFe1.Configuracoes.WebServices.Ambiente := StrToTpAmb(Ok,IntToStr(2)) // 1 Producao 2 Homologacao // StrToTpAmb(Ok,IntToStr(rgTipoAmb.ItemIndex+1));
else
ACBrNFe1.Configuracoes.WebServices.Ambiente := StrToTpAmb(Ok,IntToStr(1));
ACBrNFe1.Configuracoes.Certificados.Senha := cdsLocEmpresaFILSENHANFE.AsString;
ACBrNFe1.Configuracoes.Certificados.NumeroSerie := ACBrNFe1.Configuracoes.Certificados.SelecionarCertificado;
ACBrNFe1.Configuracoes.Geral.Salvar := false;
ACBrNFe1.Configuracoes.Geral.PathSalvar := ExtractFilePath(Application.ExeName)+'\Logs\'+cdsLocEmpresaFILCODIGO.AsString+'\';
ACBrNFe1.EventoNFe.Evento.Clear;
ACBrNFe1.EventoNFe.idLote := NumeroLote;
ShowMessage(FilterNumber(cdsLocEmpresaFILCNPJ.AsString));
ShowMessage('Recibo '+cdsLocNFNFSNRORECIBO.AsString);
ShowMessage('Protocolo '+cdsLocNFNFSNFOPROTOCOLO.AsString);
with ACBrNFe1.EventoNFe.Evento.Add do
begin
infEvento.chNFe := cdsLocNFNFSNRORECIBO.AsString;
infEvento.CNPJ := FilterNumber(cdsLocEmpresaFILCNPJ.AsString);
infEvento.dhEvento := NOW;
infEvento.tpEvento := teCancelamento;
infEvento.detEvento.nProt := cdsLocNFNFSNFOPROTOCOLO.AsString;
infEvento.detEvento.xJust := vAux;
end;
// Enviar o evento de cancelamento
if ACBrNFe1.EnviarEventoNFe(NumeroLote) 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 := EventoRetorno.retEvento.Items[0].RetInfEvento.dhRegEvento;
NumeroProtocolo := EventoRetorno.retEvento.Items[0].RetInfEvento.nProt;
XMLCancelamento := EventoRetorno.retEvento.Items[0].RetInfEvento.XML;
CodigoStatus := 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;
Obrigado