SHARE
TWEET

Untitled

a guest Sep 13th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure TEnviarMovimentoForm.GerarXML;
  2. var
  3.   NFeStream: TStringStream;
  4.   NFeDM: TNFeDataModule;
  5.   NFCe: TNFCe;
  6.   sArq: string;
  7.   ZipFile: TZipFile;
  8. begin
  9.   inherited;
  10.  
  11.   sPath :=
  12.     ExpandFileName(ExtractFileDir(Application.ExeName) + '\..\') +
  13.     'Remessa\NFCe\' + FormatDateTime('yyyymmdd', Now);
  14.  
  15.   if not ForceDirectories(sPath) then
  16.     raise Exception.Create('Ocorreu um erro ao criar a pasta de remessa ' + sPath);
  17.  
  18.   NFeDM := TNFeDataModule.Create(nil);
  19.   NFCe := TNFCe.Create(nil);
  20.   ZipFile := TZipFile.Create;
  21.  
  22.   try
  23.     ZipFile.Open(sPath + '\NFCe.zip', zmWrite);
  24.  
  25.     NFCe.Close;
  26.     NFCe.Busca('DATA_EMISSAO', DataInicialDateEdit.Date, DataFinalDateEdit.Date, 'DATA_EMISSAO');
  27.     NFCe.First;
  28.     while (not NFCe.Eof) do
  29.     begin
  30.       if NFCe.Status.AsString = 'A' then
  31.       begin
  32.         NFeDM.ACBrNFe1.NotasFiscais.Clear;
  33.         NFeStream := TStringStream.Create(NFCe.XmlNFe.Value);
  34.         try
  35.           NFeDM.ACBrNFe1.NotasFiscais.LoadFromStream(NFeStream);
  36.           if NFeDM.ACBrNFe1.NotasFiscais.Items[0].NFe.procNFe.chNFe <> '' then
  37.           begin
  38.             sArq := sPath + '\' + NFeDM.ACBrNFe1.NotasFiscais.Items[0].NFe.procNFe.chNFe + '-nfe.xml';
  39.             NFeDM.ACBrNFe1.NotasFiscais.GravarXML(sArq);
  40.             ZipFile.Add(sArq);
  41.           end;
  42.         finally
  43.           FreeAndNil(NFeStream);
  44.         end;
  45.       end;
  46.       NFCe.Next;
  47.     end;
  48.  
  49.     ZipFile.Close;
  50.  
  51.   finally
  52.     ZipFile.Free;
  53.     FreeAndNil(NFCe);
  54.     FreeAndNil(NFeDM);
  55.   end;
  56.  
  57.   Application.MessageBox('XMLs das NFC-e gerados com sucesso', 'Atenção', MB_OK);
  58. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top