Advertisement
filhotecmail

NfeProcessor

Apr 28th, 2018
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.08 KB | None | 0 0
  1. unit ProcessadorNfe;
  2.  
  3.  
  4. interface
  5.  
  6.   uses AcbrNfe,Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.SvcMgr, Vcl.Dialogs,
  7.   ServicesCore, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
  8.   FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait, FireDAC.Stan.Param,
  9.   FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, Datasnap.DBClient;
  10.  
  11.  
  12.   type TGrupoNfeIDArray = array of string;
  13.   type TGrupoEmitArray       = Array of String;
  14.   Type TgrupoDestArray       = Array Of String;
  15.   type TGrupoNfeId = TGrupoNfeIDArray;
  16.   type TGrupoEmit  = TGrupoEmitArray;
  17.   type TGrupoDest  = TgrupoDestArray;
  18.  
  19.   type TReadStringObjofArquive = packed class
  20.  
  21.       public
  22.        FTGrupoNfeId: TGrupoNfeId;
  23.        FTGrupoEmit: TGrupoEmit;
  24.        FTGrupoDest: TGrupoDest;
  25.   end;
  26.  
  27.   type TProcessadorNfe = class( TReadStringObjofArquive )
  28.  
  29.     private
  30.     {Private declaration}
  31.     FAcbrNfe: TACBrNFe;
  32.     FDatasetNfe: TDataset;
  33.     FArquivo: Ansistring;
  34.     FPatchSalvar: string;
  35.     FDatasetItensNfe: TDataset;
  36.     function SaveXmltoFolder(const Patch: string): Boolean;
  37.      procedure StringOftoGrupoNfeId;
  38.     procedure StringOftoGrupoEmit;
  39.     procedure CreateDatasettoNfe( const aNfe: TAcbrNfe );
  40.     protected
  41.     {Protected declaration}
  42.     public
  43.     {Public declaration declaration}
  44.     procedure AfterConstruction; override;
  45.     procedure BeforeDestruction; override;
  46.  
  47.  
  48.     procedure MontaDadosNfetoGrupoNfeId( acbrNfe: TAcbrNfe );
  49.  
  50.     function Salvar: Boolean;
  51.       constructor Create( AcbrNfe: TAcbrNfe; const Arquivo: AnsiString ); (*Metodos do Constructor*)
  52.       destructor Destroy; override;
  53.  
  54.     published
  55.     {Protected declaration}
  56.     property PatchSalvar : string read FPatchSalvar write FPatchSalvar;
  57.     property DatasetNfe: TDataset read FDatasetNfe;
  58.     property DatasetItensNfe: TDataset read FDatasetItensNfe;
  59.  
  60.     end;
  61.  
  62.  
  63. implementation
  64.  
  65. { TProcessadorNfe }
  66.  
  67. procedure TProcessadorNfe.AfterConstruction;
  68. begin
  69.   inherited AfterConstruction;
  70.  
  71. end;
  72.  
  73. procedure TProcessadorNfe.BeforeDestruction;
  74. begin
  75.   inherited BeforeDestruction;
  76.  
  77. end;
  78.  
  79. constructor TProcessadorNfe.Create( AcbrNfe: TAcbrNfe; const Arquivo: AnsiString );
  80. begin
  81.   FAcbrNfe := AcbrNfe;
  82.   FArquivo := Arquivo;
  83. end;
  84.  
  85. procedure TProcessadorNfe.CreateDatasettoNfe( const aNfe: TAcbrNfe );
  86.  var T: TclientDataset;
  87. begin
  88.    T:= TClientDataSet.Create(nil);
  89.    T.Close;
  90.    T.FieldDefs.Clear;
  91.    T.FieldDefs.add('CODIGO',ftInteger);
  92.    T.FieldDefs.add('NOME',ftString,50);
  93.    T.CreateDataSet;
  94.  
  95.    FDatasetNfe.Assign(T);
  96.  
  97. end;
  98.  
  99. destructor TProcessadorNfe.Destroy;
  100. begin
  101.  
  102.   inherited Destroy;
  103. end;
  104.  
  105. procedure TProcessadorNfe.MontaDadosNfetoGrupoNfeId(acbrNfe: TAcbrNfe);
  106. begin
  107.    StringOftoGrupoNfeId;
  108.    StringOftoGrupoEmit;
  109.  
  110.   with acbrNfe.NotasFiscais.Add do
  111.   begin
  112.  
  113.     NFe.infNFe.ID         := FTGrupoNfeId[0];
  114.     NFe.Ide.nNF           := FTGrupoNfeId[1].ToInteger;
  115.     NFe.infNFe.Versao     := FTGrupoNfeId[2].ToInteger;
  116.  
  117.     NFE.Emit.xNome   := FTGrupoEmit[0];
  118.     NFE.Emit.xFant   := FTGrupoEmit[1];
  119.     NFE.Emit.IE      := FTGrupoEmit[2];
  120.     NFE.Emit.CNPJCPF := FTGrupoEmit[3];
  121.  
  122.   end;
  123. end;
  124.  
  125. function TProcessadorNfe.Salvar: Boolean;
  126. begin
  127.  
  128.   result := ( (not trim(FPatchSalvar).IsEmpty) and ( SaveXmltoFolder(FPatchSalvar)));
  129. end;
  130.  
  131. function TProcessadorNfe.SaveXmltoFolder(const Patch: string): Boolean;
  132. begin
  133.   FAcbrNfe.NotasFiscais.GravarXML(Patch);
  134. end;
  135.  
  136. procedure TProcessadorNfe.StringOftoGrupoEmit;
  137. begin
  138.  // aqui está a toda a logica, onde você vai começar a desmembrar sua string e colocar em cada grupo
  139.  // pertencente
  140.  FTGrupoEmit := ['EMPRESA EMISSORA LTDA ME','FANTASIA DA EMPRESA','NPJ','IE'  ];
  141. end;
  142.  
  143. procedure TProcessadorNfe.StringOftoGrupoNfeId;
  144. begin
  145.  // aqui está a toda a logica, onde você vai começar a desmembrar sua string e colocar em cada grupo
  146.  // pertencente
  147.  
  148.  FTGrupoNfeId := [ '00000000000000000000000000000000000000000000'  ];
  149. end;
  150.  
  151. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement