Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit LeopardGerenciador.Core.Financeiro.RelatoriosPDV.MovFinalizadoras.Model.MovFinalizadorasModel;
- 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 IMovFinalizadorasModel = Interface( IModelBaseInterface )
- ['{680CA34F-3B71-4A60-A67E-7D92D8304697}']
- 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 TMovFinalizadorasModel = class(TInterfacedObject,IMovFinalizadorasModel)
- 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: IMovFinalizadorasModel;
- end;
- implementation
- { TMovFinalizadorasModel }
- procedure TMovFinalizadorasModel.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 TMovFinalizadorasModel.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.DataFire.ForEach(FData.DataFire,
- procedure
- begin
- vFinRec:= vFinRec + FData.Field('FIN_VALORREC').AsCurrency
- end);
- RecCount:= FData.RecCount;
- FData.First;
- end;
- if Assigned(FDeps.OnSumValuesEvent) then
- FDeps.OnSumValuesEvent([vFinRec,RecCount]);
- end;
- procedure TMovFinalizadorasModel.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- function TMovFinalizadorasModel.ExportToCsv: TInterfacedObject;
- begin
- FData.SaveToCstFile('',False);
- result:= Self;
- end;
- function TMovFinalizadorasModel.ExportToJson: TInterfacedObject;
- begin
- FData.SaveToJsonFile('',False);
- result:= Self;
- end;
- function TMovFinalizadorasModel.ExportToXml: TInterfacedObject;
- begin
- FData.SaveToXmlFile('',False);
- result:= Self;
- end;
- function TMovFinalizadorasModel.Inject(InjectDeps: TProc<TObject>): TInterfacedObject;
- begin
- if Assigned(InjectDeps) then
- InjectDeps(FDeps);
- Result:= Self;
- end;
- class function TMovFinalizadorasModel.New: IMovFinalizadorasModel;
- begin
- Result:= TMovFinalizadorasModel.Create;
- end;
- function TMovFinalizadorasModel.PrintData: TInterfacedObject;
- begin
- end;
- function TMovFinalizadorasModel.Response(Done: TProc<TObject>; Fail: TProc<Exception>): TInterfacedObject;
- begin
- try
- try
- FData.Open(FDeps.GetSqlData,
- [ FDeps.Parametros.DataInicial,
- FDeps.Parametros.DataFinal,
- Tcaption(FDeps.ParametrosFinalizadora.DescricaoFinalizadora).CheckNullisTodos,
- Tcaption(FDeps.Parametros.NumeroPDV).CheckNullisTodos,
- FDeps.ParametrosFinalizadora.NumerodaVenda,
- Tcaption(FDeps.ParametrosFinalizadora.SituacaoDaVenda).CheckNullisTodos ],
- [FtDate,
- FtDate,
- FtString,
- 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 TMovFinalizadorasModel.SetEvents(InjectDeps: TProc<TObject>): TInterfacedObject;
- begin
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement