Ir para conteúdo
  • Cadastre-se

dev botao

Notas Destinadas duvidas


  • Este tópico foi criado há 2408 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Recommended Posts

Boa tarde 

Estou com uma duvida no código abaixa não consegui identificar o qual valor desse componente [edtConsultas.ValueInt]  para poder adaptar o meu código alguem pode mim ajudar?

desde já agradeço.

 

procedure TfrmMovManifestacao.btnLocalizarClick(Sender: TObject);
var
 CNPJ, Impresso, sChave, sEmissao, sCNPJ, sNome, sNumero, sSerie,
 sIEst, sNSU, sTipoNFe: String;
 Valor: Double;
 i, j, k: integer;
begin
 // ======== Dados do Emitente =============================================
 DM_CTA.Empresa.Close;
 DM_CTA.Empresa.SQL.Clear;
 DM_CTA.Empresa.SQL.Add('Select * From Sis_Empresa');
 DM_CTA.Empresa.SQL.Add('Where Codigo = :xCodigo');
 DM_CTA.Empresa.Params[0].AsString:=DM_CTA.ParamDFeEmitente.AsString;
 DM_CTA.Empresa.Active:=True;
 DM_CTA.Empresa.Open;

 if copy(DM_CTA.EmpresaCNPJ.AsString,10,4) <> '0000'
  then CNPJ := Copy(DM_CTA.EmpresaCNPJ.AsString, 2, 14)
  else CNPJ := Copy(DM_CTA.EmpresaCNPJ.AsString, 1, 9) +
               Copy(DM_CTA.EmpresaCNPJ.AsString, 14, 2);

 MemoStatus.Lines.Add('------------------------------------------------------');
 MemoStatus.Lines.Add(' =>  Consultando NFe Destinadas');
 MemoStatus.Lines.Add('------------------------------------------------------');

 Memo1.Text := '';
 k := 0;
 repeat
   inc(k);
   DMDFe.NFe.DistribuicaoDFePorUltNSU( DM_CTA.EmpresaCodigoEstado.AsInteger,
                                       CNPJ,
                                       edtUltNSU.Text );

   sStat   := IntToStr(DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.cStat);
   sMotivo := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.xMotivo;

   if DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.cStat = 137
   then sTemMais := 'N'
   else sTemMais := 'S';

   sUltimoNSU := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.ultNSU;

   GravaUltimaConsulta;

   if DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.cStat = 138
    then begin
     MemoStatus.Lines.Add(' Documento Localizado para o Destinatário');
     MemoStatus.Lines.Add(' Utilizar o número que esta no campo: Último NSU');
     MemoStatus.Lines.Add(' Para uma nova pesquisa.');
     MemoStatus.Lines.Add(' ');

     j := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Count - 1;
     lstChave1.Clear;
     chkListaNotas.Clear;

     for i := 0 to j do
      begin
       sSerie   := '';
       sNumero  := '';
       sCNPJ    := '';
       sNome    := '';
       sIEst    := '';
       sNSU     := '';
       sEmissao := '';
       sTipoNFe := '';
       Valor    := 0.0;
       Impresso := ' ';

       if DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.chNFe <> ''
        then begin
         // Conjunto de informações resumo da NF-e localizadas.
         // Este conjunto de informação será gerado quando a NF-e for autorizada ou denegada.

         sChave := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.chNFe;

         sSerie  := Copy(sChave, 23, 3);
         sNumero := Copy(sChave, 26, 9);
         sCNPJ := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.CNPJCPF;
         sNome := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.xNome;
         sIEst := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.IE;
         case DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.tpNF of
          tnEntrada: sTipoNFe := 'E';
          tnSaida:   sTipoNFe := 'S';
         end;
         sNSU  := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.NSU;
         sEmissao := DateToStr(DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.dhEmi);
         Valor := DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.vNF;

         case DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.docZip.Items.resNFe.cSitNFe of
          snAutorizado: Impresso := 'A';
          snDenegado:   Impresso := 'D';
          snCancelada:  Impresso := 'C';
         end;
        end;

       // Registra no Banco de Dados as Notas Retornadas pela Consulta
       DM_VEN.Manifestacao.Close;
       DM_VEN.Manifestacao.SQL.Clear;
       DM_VEN.Manifestacao.SQL.Add('Select * From Eve_Manifestacao');
       DM_VEN.Manifestacao.SQL.Add('Where Empresa = :xEmpresa');
       DM_VEN.Manifestacao.SQL.Add('and Chave = :xChave');
       DM_VEN.Manifestacao.Params[0].AsString:=DM_CTA.xCodEmpresa;
       DM_VEN.Manifestacao.Params[1].AsString:=sChave;
       DM_VEN.Manifestacao.Active:=True;
       DM_VEN.Manifestacao.Open;

       if not ((DM_VEN.ManifestacaoEmpresa.AsString = DM_CTA.xCodEmpresa) and
               (DM_VEN.ManifestacaoChave.AsString = sChave))
        then begin
         DM_VEN.IncAltDel.SQL.Clear;
         DM_VEN.IncAltDel.SQL.Add('Insert into Eve_Manifestacao');
         DM_VEN.IncAltDel.SQL.Add('(Empresa, Chave, CNPJ, Nome, IE, Emissao, Tipo, Valor,');
         DM_VEN.IncAltDel.SQL.Add('Situacao, Confirmacao, NSU, DataEvento, Protocolo)');
         DM_VEN.IncAltDel.SQL.Add('Values (:xEmpresa, :xChave, :xCNPJ, :xNome, :xIE, :xEmissao, :xTipo,');
         DM_VEN.IncAltDel.SQL.Add(':xValor, :xSituacao, :xConfirmacao, :xNSU, :xDataEve, :xProtocolo)');
         DM_VEN.IncAltDel.Params[0].AsString:=DM_CTA.xCodEmpresa;
         DM_VEN.IncAltDel.Params[1].AsString:=sChave;
         DM_VEN.IncAltDel.Params[2].AsString:=sCNPJ;
         DM_VEN.IncAltDel.Params[3].AsString:=sNome;
         DM_VEN.IncAltDel.Params[4].AsString:=sIEst;
         DM_VEN.IncAltDel.Params[5].AsDateTime:=StrToDate(sEmissao);
         DM_VEN.IncAltDel.Params[6].AsString:=sTipoNFe;
         DM_VEN.IncAltDel.Params[7].AsFloat:=Valor;
         DM_VEN.IncAltDel.Params[8].AsString:=Impresso;
         DM_VEN.IncAltDel.Params[9].AsInteger:=-1;
         DM_VEN.IncAltDel.Params[10].AsString:=sNSU;
         DM_VEN.IncAltDel.Params[11].AsDateTime:=0;
         DM_VEN.IncAltDel.Params[12].AsString:='';
         DM_VEN.IncAltDel.ExecSQL;
        end;

      end; // Fim do For
    end
    else begin
     // Nenhum Documento Localizado para o Destinatário
     if DMDFe.NFe.WebServices.DistribuicaoDFe.retDistDFeInt.cStat = 137
      then begin
       MemoStatus.Lines.Add(' Nenhum Documento Localizado para o Destinatário');
       MemoStatus.Lines.Add(' Utilizar o número que esta no campo: Último NSU');
       MemoStatus.Lines.Add(' Para uma nova pesquisa ('+edtUltNSU.Text+').');
       MemoStatus.Lines.Add(' ');
      end
      else begin
       MemoStatus.Lines.Add(' Falha ao realizar a consulta.');
       MemoStatus.Lines.Add('  ' + sStat + ' - ' + sMotivo);
       MemoStatus.Lines.Add(' ');
      end;
    end;

   MontaChkLista;
 until (k = edtConsultas.ValueInt) or (sTemMais = 'S');

 if sTemMais = 'S'
  then Memo1.Text := IntToStr(k) + ' Consultas Realizadas e tem mais Documentos.'
  else Memo1.Text := IntToStr(k) + ' Consultas Realizadas e não tem mais Documentos.';

 AtivaBotao;
end;
 

Link para o comentário
Compartilhar em outros sites

  • Consultores

Boa tarde Edvanio,

O componente  [edtConsultas.ValueInt]  foi desenvolvido por mim, trata-se de um TEdit que permite a entrada somente de valores numéricos.

Você pode usar um Tedit do Delphi e mudar a linha da seguinte forma:

 until (k = StrToIntDef(edtConsultas.Text, 1)) or (sTemMais = 'S');

Consultor SAC ACBr

Italo Giurizzato Junior
Ajude o Projeto ACBr crescer - Assine o SAC

Projeto ACBr

Analista de Sistemas / e-mail: [email protected] / Fone: (16) 9-9701-5030 / Araraquara-SP

Araraquara - A era dos Trólebus

Link para o comentário
Compartilhar em outros sites

  • Consultores

Edvanio,

Peço que leia com muita atenção a Nota Técnica 2014/002 versão 1.02b, pois estou notando que você esta perdido sobre esse assunto.

A variável ultimoNSU recebe o valor da tag <ultNSU> retornado após a execução do método DistribuicaoDFe e que devemos utilizar na próxima execução do mesmo.

Quando montei essa rotina o usuário pode informar a quantidade de vezes que o método será executado, mas você pode executar o método quantas vezes forem necessárias até que o retorno da tag <ultNSU> seja igual ao da tag <maxNSU>.

Consultor SAC ACBr

Italo Giurizzato Junior
Ajude o Projeto ACBr crescer - Assine o SAC

Projeto ACBr

Analista de Sistemas / e-mail: [email protected] / Fone: (16) 9-9701-5030 / Araraquara-SP

Araraquara - A era dos Trólebus

Link para o comentário
Compartilhar em outros sites

×
×
  • 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.