Advertisement
filhotecmail

MovFinalizadorasAgroupModel

Feb 27th, 2020
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.24 KB | None | 0 0
  1. unit LeopardGerenciador.Core.Financeiro.RelatoriosPDV.MovFinalizadoras.Model.MovFinalizadorasAgroupModel;
  2.  
  3. interface
  4. uses
  5.     System.Classes,
  6.     System.SysUtils,
  7.     System.VarUtils,
  8.     System.Variants,
  9.     // Vcl
  10.     vcl.Dialogs,
  11.     Vcl.Graphics,
  12.     Vcl.ExtCtrls,
  13.     Vcl.Forms,
  14.     Vcl.StdCtrls,
  15.     Vcl.Consts,
  16.     Vcl.Controls,
  17.     Data.DB,
  18.     // Leopard
  19.     LeopardDriverDataset,
  20.     StringsH.Helpers.Model,
  21.     FireDAC.Phys.Intf,FireDAC.Stan.Option, FireDAC.Stan.Intf, FireDAC.Comp.Client,
  22.     Dialog.Rai.Model,
  23.     LeopardGerenciador.BaseClass.InterfaceModelGenericClass.InterfaceModelGenericBaseClass,
  24.     LeopardGerenciador.BaseClass.InjectableBaseclass.InjectableBaseClassModel,
  25.     LeopardGerenciador.Core.Financeiro.RelatoriosPDV.MovFinalizadoras.Dependency.MovFinalizadorasDependency;
  26.  
  27.    type IMovFinalizadorasAgroupModel = Interface( IModelBaseInterface )
  28.      ['{35E1D273-5331-4A21-8668-5DCE802742D6}']
  29.      function Inject( InjectDeps: TProc<TObject> ):TInterfacedObject;
  30.      function SetEvents( InjectDeps: TProc<TObject> ):TInterfacedObject;
  31.      function Response( Done: TProc<TObject>; Fail: TProc<Exception> ):TInterfacedObject;
  32.  
  33.      function PrintData:TInterfacedObject;
  34.      function ExportToXml:TInterfacedObject;
  35.      function ExportToCsv:TInterfacedObject;
  36.      function ExportToJson:TInterfacedObject;
  37.  
  38.    End;
  39.  
  40.    type TMovFinalizadorasAgroupModel = class(TInterfacedObject,IMovFinalizadorasAgroupModel)
  41.  
  42.      strict private
  43.       FBaseModel: IModelBaseInterface;
  44.       FDeps: TMovFinalizadoraDeps;
  45.       FData: TLeopardDriverDataset;
  46.       procedure SetDeps(const Value: TInjectableBaseClassModel); virtual; abstract;
  47.       function getFDeps: TInjectableBaseClassModel; virtual; abstract;
  48.       function MakeDataset(  Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload; virtual; abstract;
  49.       function MakeDataset( const GeneratorName,Field: String ;Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload; virtual; abstract;
  50.       procedure AlertEvent;
  51.   public
  52.  
  53.      function Inject( InjectDeps: TProc<TObject> ):TInterfacedObject;
  54.      function SetEvents( InjectDeps: TProc<TObject> ):TInterfacedObject;
  55.      function Response( Done: TProc<TObject>; Fail: TProc<Exception> ):TInterfacedObject;
  56.  
  57.      function PrintData:TInterfacedObject;
  58.      function ExportToXml:TInterfacedObject;
  59.      function ExportToCsv:TInterfacedObject;
  60.      function ExportToJson:TInterfacedObject;
  61.  
  62.     procedure AfterConstruction; override;
  63.     procedure BeforeDestruction; override;
  64.     class function New: IMovFinalizadorasAgroupModel;
  65.  
  66.    end;
  67.  
  68. implementation
  69.  
  70. { TMovFinalizadorasAgroupModel }
  71.  
  72. procedure TMovFinalizadorasAgroupModel.AfterConstruction;
  73. begin
  74.   inherited AfterConstruction;
  75.   FBaseModel:= TModelBaseObjConcret.New;
  76.  
  77.   FDeps := TMovFinalizadoraDeps.Create;
  78.   FDeps.Response := FBaseModel.Deps.Response;
  79.   FDeps.Parametros := FBaseModel.Deps.Parametros;
  80.   FDeps.Eventos    := FBaseModel.Deps.Eventos;
  81.  
  82.   FBaseModel.MakeDataset(
  83.   procedure
  84.   ( ResData: TObject; Model: IModelBaseInterface )
  85.   begin
  86.    FData:= TMovFinalizadoraDeps(ResData).Response.DataL[0];
  87.    FDeps.PostEventFB.AlertEvent := AlertEvent;
  88.    FDeps.NameEvent := 'MovFinalizadorasEvent';
  89.    FDeps.Connection := FData.DataFire.Connection;
  90.    FDeps.UsePostEvent := Not FDeps.UsePostEvent;
  91.   end);
  92.  
  93. end;
  94.  
  95. procedure TMovFinalizadorasAgroupModel.AlertEvent;
  96.  const cFIN_VALORREC: string = 'FIN_VALORREC';
  97. var
  98.   vFinRec: Extended;
  99.   RecCount: integer;
  100. begin
  101.   FData.Refresh;
  102.   vFinRec := 0.00;
  103.   RecCount:= 0;
  104.   if not FData.IsEmpty then
  105.   begin
  106.     FData.ReturnAgregate(cFIN_VALORREC,vFinRec,aSomar);
  107.     RecCount:= FData.RecCount;
  108.   end;
  109.  if Assigned(FDeps.OnSumValuesEvent) then
  110.     FDeps.OnSumValuesEvent([vFinRec,RecCount]);
  111. end;
  112.  
  113. procedure TMovFinalizadorasAgroupModel.BeforeDestruction;
  114. begin
  115.   inherited BeforeDestruction;
  116.  
  117. end;
  118.  
  119. function TMovFinalizadorasAgroupModel.ExportToCsv: TInterfacedObject;
  120. begin
  121.  FData.SaveToCstFile('',False);
  122.  result:= Self;
  123. end;
  124.  
  125. function TMovFinalizadorasAgroupModel.ExportToJson: TInterfacedObject;
  126. begin
  127.  FData.SaveToJsonFile('',False);
  128.  result:= Self;
  129. end;
  130.  
  131. function TMovFinalizadorasAgroupModel.ExportToXml: TInterfacedObject;
  132. begin
  133.  FData.SaveToXmlFile('',False);
  134.  result:= Self;
  135. end;
  136.  
  137. function TMovFinalizadorasAgroupModel.Inject(InjectDeps: TProc<TObject>): TInterfacedObject;
  138. begin
  139.  
  140.  if Assigned(InjectDeps) then
  141.     InjectDeps(FDeps);
  142.  
  143.  Result:= Self;
  144. end;
  145.  
  146. class function TMovFinalizadorasAgroupModel.New: IMovFinalizadorasAgroupModel;
  147. begin
  148.  Result:= TMovFinalizadorasAgroupModel.Create;
  149. end;
  150.  
  151. function TMovFinalizadorasAgroupModel.PrintData: TInterfacedObject;
  152. begin
  153.  
  154. end;
  155.  
  156. function TMovFinalizadorasAgroupModel.Response(Done: TProc<TObject>; Fail: TProc<Exception>): TInterfacedObject;
  157. begin
  158.   try
  159.    try
  160.     FData.Open(
  161.      ' SELECT '
  162.     +' F.FIN_DESCRICAO, '
  163.     +' SUM(F.FIN_VALORREC)FIN_VALORREC '
  164.     +' FROM MOV_PDVFINALIZADORAS F '
  165.     +'  '
  166.     +' WHERE F.VENDA_DATA BETWEEN :DATAINICIAL AND :DATAFINAL '
  167.     +' AND ( '
  168.     +' ( F.FIN_DESCRICAO CONTAINING :PFINDESC ) '
  169.     +' ) '
  170.     +' AND ( '
  171.     +' F.PDV_NUMPDV CONTAINING :NUMPDV '
  172.     +' ) '
  173.     +'  '
  174.     +' AND ( '
  175.     +' ( F.VENDA_SITUACAO CONTAINING :PVENDASITUACAO ) '
  176.     +'  '
  177.     +' ) '
  178.     +'  '
  179.     +' GROUP BY 1 '
  180.     ,
  181.                [ FDeps.Parametros.DataInicial,
  182.                  FDeps.Parametros.DataFinal,
  183.                  Tcaption(FDeps.ParametrosFinalizadora.DescricaoFinalizadora).CheckNullisTodos,
  184.                  Tcaption(FDeps.Parametros.NumeroPDV).CheckNullisTodos,
  185.                  Tcaption(FDeps.ParametrosFinalizadora.SituacaoDaVenda).CheckNullisTodos ],
  186.                      [FtDate,
  187.                       FtDate,
  188.                       FtString,
  189.                       FtString,
  190.                       FtString]).AMaskMoneytoAllField('###,##0.00');
  191.  
  192.    finally
  193.     if FData.Active then
  194.     begin
  195.        if Assigned(Done) then
  196.           Done(FDeps);
  197.        AlertEvent;
  198.     end;
  199.  
  200.    end;
  201.   Except
  202.    on E: Exception do
  203.       if Assigned(Fail) then
  204.          Fail(E);
  205.   end;
  206.  Result:= Self;
  207. end;
  208.  
  209. function TMovFinalizadorasAgroupModel.SetEvents(InjectDeps: TProc<TObject>): TInterfacedObject;
  210. begin
  211.  
  212. end;
  213. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement