Ir para conteúdo
  • Cadastre-se

Recommended Posts

  • Membros Pro
Postado

Faça a consulta das notas destinadas e retorna varias notas a manifestar...Faço o manifesto, mas a nota nunca volta completa para o download do xml. Ou seja, não retorna a nota com o shema schprocNFe

A impressão é que a nota não é manifestada.. porém recebo retorno

image.thumb.png.742da6f2a708fccdc4339b9b3d211756.png

//ROTNA PARA MANIFESTAR NOTA
procedure TfrmNotasDestinadas.BitBtn2Click(Sender: TObject);
var
 lMsg : string;
 sChaves : TStringList;
 i : integer;
begin
 if not CDSDestinadas.IsEmpty then
  begin
  CDSDestinadas.First;
  CDSDestinadas.DisableControls;
  sChaves := TStringList.Create;
    try
     while not CDSDestinadas.Eof do
       begin
         if (CDSDestinadasSELECAO.AsBoolean) and (CDSDestinadasTIPO.AsString = 'Autorizada') then
           begin
                ACBrNFe1.EventoNFe.Evento.Clear;

                with ACBrNFe1.EventoNFe.Evento.New do
                begin
                  InfEvento.cOrgao   := 91;
                  infEvento.chNFe    := CDSDestinadasCHAVE.AsString;
                  infEvento.CNPJ     := CDSDestinadasCNPJ.AsString; // CNPJ/CPF do Destinatário da Mercadoria
                  infEvento.dhEvento := now;

                  infEvento.tpEvento := teManifDestCiencia;
                end;

                ACBrNFe1.EnviarEvento(1);

                CDSDestinadas.Edit;
                CDSDestinadasTIPO.AsString := 'Manifestada';
                CDSDestinadasDATA_MANIFESTO.AsDateTime := now;
                CDSDestinadasCODUSUARIO.AsInteger := CodUsuario;
                CDSDestinadas.ApplyUpdates(-1);

                sChaves.Add(CDSDestinadasCHAVE.AsString);
           end;

          CDSDestinadas.Next;
       end;

   finally
     if sChaves.Count > 0 then
      begin
        MemoDados.Lines.Add('Nota(s) Manifestada(s)');

        for I := 0 to sChaves.Count -1 do
           MemoDados.Lines.Add(sChaves[i]);

        PageControl1.ActivePageIndex := 0;
      end;


      FreeAndNil(sChaves);
      CDSDestinadas.EnableControls;

      Atualizar;
   end;
  end;
end;

 

Postado

Uai mano, voce precisa acionar o download e gravar no seu banco de dados o xml

Ex:

class function TFuncoesNFe.DownloadNFe(AACBrNFe: TACBrNFe;
  ACNPJEmpresa       : string;
  ChaveNFe           : string;
  AMostrarAdvertencia: Boolean;

  var
   AAdvertencia: string): string;
var
  UFAutor: Integer;
  SitDfe : TSituacaoDFe;
  xMotivo: string;
begin
  AAdvertencia := '';

  UFAutor := StrToInt(Copy(ChaveNFe, 1, 2));

  Result := '';

  if AACBrNFe.DistribuicaoDFePorChaveNFe(UFAutor, ACNPJEmpresa, ChaveNFe) then
  begin
    {
      // snAutorizado, snDenegado, snCancelado, snEncerrado

      schema:
      schresNFe, schresEvento, schprocNFe, schprocEventoNFe,
      schresCTe, schprocCTe, schprocCTeOS, schprocEventoCTe,
      schresMDFe, schprocMDFe, schprocEventoMDFe,
      schresBPe, schprocBPe, schprocEventoBPe
    }

    if AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Count > 0 then
    begin
      if AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items[0].resDFe.cSitDFe = snAutorizado then
      begin
        if AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items[0].schema in [schprocNFe { , schresNFe } ] then
           Result := AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items[0].XML;

        // tem que testar maiusculo o utf em alguns casos vem maiusculo
        if (Result <> '') and (Pos('<?XML VERSION="1.0" ENCODING="UTF-8"?>', AnsiUpperCase(Result)) = 0) then
           Result := '<?xml version="1.0" encoding="utf-8"?>' + #13 + Result;
      end
      else
      begin
        SitDfe := AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items[0].resDFe.cSitDFe;
        case SitDfe of
          snAutorizado: xMotivo := 'Autorizado';
          snDenegado: xMotivo   := 'Denegado';
          snCancelado: xMotivo  := 'Cancelado';
          snEncerrado: xMotivo  := 'Encerrado';
        end;

        AAdvertencia := 'Não foi possível efetuar Download da NFe ' + ChaveNFe + #13 + xMotivo;
      end;
    end
    else
    begin
      AAdvertencia := 'Não foi possível efetuar Download da NFe ' + ChaveNFe + #13 +
       IntToStr(AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.cStat) + ' - ' +
       AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.xMotivo;
    end;
  end
  else
     AAdvertencia := 'Não foi possível efetuar Download da NFe ' + ChaveNFe + #13 +
     IntToStr(AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.cStat) + ' - ' +
     AACBrNFe.WebServices.DistribuicaoDFe.retDistDFeInt.xMotivo;

  if (AAdvertencia <> '') and AMostrarAdvertencia then
{$IF DEFINED(AMLSERVER) or DEFINED(AGENDADOR)}
    raise Exception.Create(AAdvertencia);
{$ELSE}
    TCaixasDeDialogo.Aviso(AAdvertencia);
{$ENDIF}
end;

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar Agora
×
×
  • Criar Novo...

Informação Importante

Colocamos cookies em seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies, caso contrário, assumiremos que você está bem para continuar.

The popup will be closed in 10 segundos...