Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit LeopardGerenciador.Core.Financeiro.RelatoriosPDV.MovFinalizadoras.Model.MovFinalizadorasAgroupModel;
- interface
- uses
- System.Classes,
- System.SysUtils,
- System.VarUtils,
- System.Variants,
- // Vcl
- vcl.Dialogs,
- Vcl.Graphics,
- Vcl.ExtCtrls,
- Vcl.Forms,
- Vcl.StdCtrls,
- Vcl.Consts,
- Vcl.Controls,
- Data.DB,
- // Leopard
- LeopardDriverDataset,
- StringsH.Helpers.Model,
- FireDAC.Phys.Intf,FireDAC.Stan.Option, FireDAC.Stan.Intf, FireDAC.Comp.Client,
- Dialog.Rai.Model,
- LeopardGerenciador.BaseClass.InterfaceModelGenericClass.InterfaceModelGenericBaseClass,
- LeopardGerenciador.BaseClass.InjectableBaseclass.InjectableBaseClassModel,
- LeopardGerenciador.Core.Financeiro.RelatoriosPDV.MovFinalizadoras.Dependency.MovFinalizadorasDependency;
- type IMovFinalizadorasAgroupModel = Interface( IModelBaseInterface )
- ['{35E1D273-5331-4A21-8668-5DCE802742D6}']
- function Inject( InjectDeps: TProc<TObject> ):TInterfacedObject;
- function SetEvents( InjectDeps: TProc<TObject> ):TInterfacedObject;
- function Response( Done: TProc<TObject>; Fail: TProc<Exception> ):TInterfacedObject;
- function PrintData:TInterfacedObject;
- function ExportToXml:TInterfacedObject;
- function ExportToCsv:TInterfacedObject;
- function ExportToJson:TInterfacedObject;
- End;
- type TMovFinalizadorasAgroupModel = class(TInterfacedObject,IMovFinalizadorasAgroupModel)
- strict private
- FBaseModel: IModelBaseInterface;
- FDeps: TMovFinalizadoraDeps;
- FData: TLeopardDriverDataset;
- procedure SetDeps(const Value: TInjectableBaseClassModel); virtual; abstract;
- function getFDeps: TInjectableBaseClassModel; virtual; abstract;
- function MakeDataset( Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload; virtual; abstract;
- function MakeDataset( const GeneratorName,Field: String ;Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload; virtual; abstract;
- procedure AlertEvent;
- public
- function Inject( InjectDeps: TProc<TObject> ):TInterfacedObject;
- function SetEvents( InjectDeps: TProc<TObject> ):TInterfacedObject;
- function Response( Done: TProc<TObject>; Fail: TProc<Exception> ):TInterfacedObject;
- function PrintData:TInterfacedObject;
- function ExportToXml:TInterfacedObject;
- function ExportToCsv:TInterfacedObject;
- function ExportToJson:TInterfacedObject;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- class function New: IMovFinalizadorasAgroupModel;
- end;
- implementation
- { TMovFinalizadorasAgroupModel }
- procedure TMovFinalizadorasAgroupModel.AfterConstruction;
- begin
- inherited AfterConstruction;
- FBaseModel:= TModelBaseObjConcret.New;
- FDeps := TMovFinalizadoraDeps.Create;
- FDeps.Response := FBaseModel.Deps.Response;
- FDeps.Parametros := FBaseModel.Deps.Parametros;
- FDeps.Eventos := FBaseModel.Deps.Eventos;
- FBaseModel.MakeDataset(
- procedure
- ( ResData: TObject; Model: IModelBaseInterface )
- begin
- FData:= TMovFinalizadoraDeps(ResData).Response.DataL[0];
- FDeps.PostEventFB.AlertEvent := AlertEvent;
- FDeps.NameEvent := 'MovFinalizadorasEvent';
- FDeps.Connection := FData.DataFire.Connection;
- FDeps.UsePostEvent := Not FDeps.UsePostEvent;
- end);
- end;
- procedure TMovFinalizadorasAgroupModel.AlertEvent;
- const cFIN_VALORREC: string = 'FIN_VALORREC';
- var
- vFinRec: Extended;
- RecCount: integer;
- begin
- FData.Refresh;
- vFinRec := 0.00;
- RecCount:= 0;
- if not FData.IsEmpty then
- begin
- FData.ReturnAgregate(cFIN_VALORREC,vFinRec,aSomar);
- RecCount:= FData.RecCount;
- end;
- if Assigned(FDeps.OnSumValuesEvent) then
- FDeps.OnSumValuesEvent([vFinRec,RecCount]);
- end;
- procedure TMovFinalizadorasAgroupModel.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- function TMovFinalizadorasAgroupModel.ExportToCsv: TInterfacedObject;
- begin
- FData.SaveToCstFile('',False);
- result:= Self;
- end;
- function TMovFinalizadorasAgroupModel.ExportToJson: TInterfacedObject;
- begin
- FData.SaveToJsonFile('',False);
- result:= Self;
- end;
- function TMovFinalizadorasAgroupModel.ExportToXml: TInterfacedObject;
- begin
- FData.SaveToXmlFile('',False);
- result:= Self;
- end;
- function TMovFinalizadorasAgroupModel.Inject(InjectDeps: TProc<TObject>): TInterfacedObject;
- begin
- if Assigned(InjectDeps) then
- InjectDeps(FDeps);
- Result:= Self;
- end;
- class function TMovFinalizadorasAgroupModel.New: IMovFinalizadorasAgroupModel;
- begin
- Result:= TMovFinalizadorasAgroupModel.Create;
- end;
- function TMovFinalizadorasAgroupModel.PrintData: TInterfacedObject;
- begin
- end;
- function TMovFinalizadorasAgroupModel.Response(Done: TProc<TObject>; Fail: TProc<Exception>): TInterfacedObject;
- begin
- try
- try
- FData.Open(
- ' SELECT '
- +' F.FIN_DESCRICAO, '
- +' SUM(F.FIN_VALORREC)FIN_VALORREC '
- +' FROM MOV_PDVFINALIZADORAS F '
- +' '
- +' WHERE F.VENDA_DATA BETWEEN :DATAINICIAL AND :DATAFINAL '
- +' AND ( '
- +' ( F.FIN_DESCRICAO CONTAINING :PFINDESC ) '
- +' ) '
- +' AND ( '
- +' F.PDV_NUMPDV CONTAINING :NUMPDV '
- +' ) '
- +' '
- +' AND ( '
- +' ( F.VENDA_SITUACAO CONTAINING :PVENDASITUACAO ) '
- +' '
- +' ) '
- +' '
- +' GROUP BY 1 '
- ,
- [ FDeps.Parametros.DataInicial,
- FDeps.Parametros.DataFinal,
- Tcaption(FDeps.ParametrosFinalizadora.DescricaoFinalizadora).CheckNullisTodos,
- Tcaption(FDeps.Parametros.NumeroPDV).CheckNullisTodos,
- Tcaption(FDeps.ParametrosFinalizadora.SituacaoDaVenda).CheckNullisTodos ],
- [FtDate,
- FtDate,
- FtString,
- FtString,
- FtString]).AMaskMoneytoAllField('###,##0.00');
- finally
- if FData.Active then
- begin
- if Assigned(Done) then
- Done(FDeps);
- AlertEvent;
- end;
- end;
- Except
- on E: Exception do
- if Assigned(Fail) then
- Fail(E);
- end;
- Result:= Self;
- end;
- function TMovFinalizadorasAgroupModel.SetEvents(InjectDeps: TProc<TObject>): TInterfacedObject;
- begin
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement