This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES2/Source/Modulos/Facturas de proveedor/Controller/uFacturasProveedorReportController.pas

143 lines
3.8 KiB
ObjectPascal

unit uFacturasProveedorReportController;
interface
uses
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleFacturasProveedorReport,
uClientesController, uDetallesFacturaProveedorController, uBizFacturasProveedor,
uIntegerListUtils;
type
IFacturasProveedorReportController = interface(IControllerBase)
['{551F82DC-B8DC-482E-A20D-15003E845078}']
procedure Preview(const AListaID : TIntegerList);
function Print(const AListaID : TIntegerList): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
TFacturasProveedorReportController = class(TControllerBase, IFacturasProveedorReportController)
private
FDataModule : IDataModuleFacturasProveedorReport;
function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
public
constructor Create; override;
destructor Destroy; override;
procedure Preview(const AListaID : TIntegerList);
function Print(const AListaID : TIntegerList): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
implementation
uses
uROTypes, uEditorRegistryUtils, uIEditorFacturasProveedorPreview,
uEditorPreview, uDataModuleFacturasProveedor, uEditorBase, cxControls,
uStringsUtils, schFacturasProveedorClient_Intf;
{ TFacturasProveedorReportController }
constructor TFacturasProveedorReportController.Create;
begin
inherited;
FDataModule := TDataModuleFacturasProveedor.Create(Nil);
end;
function TFacturasProveedorReportController.CreateEditor(const AName: String;
const IID: TGUID; out Intf): Boolean;
begin
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
end;
destructor TFacturasProveedorReportController.Destroy;
begin
FDataModule := NIL;
inherited;
end;
function TFacturasProveedorReportController.ExportToPDF(const AID: Integer;
const AFileName: String): Boolean;
var
AStream: Binary;
begin
Result := False;
if EsCadenaVacia(AFileName) then
Exit;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptPDFFactura(AID);
try
AStream.SaveToFile(AFileName);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
procedure TFacturasProveedorReportController.Preview(const AListaID : TIntegerList);
var
AStream: Binary;
AEditor : IEditorFacturasProveedorPreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptFacturas(AListaID);
try
CreateEditor('EditorFacturasProveedorPreview', IEditorFacturasProveedorPreview, AEditor);
if Assigned(AEditor) then
try
AEditor.LoadFromStream(AStream);
AEditor.Preview;
finally
AEditor.Release;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
function TFacturasProveedorReportController.Print(const AListaID : TIntegerList): Boolean;
var
AStream: Binary;
AEditor : IEditorFacturasProveedorPreview;
begin
Result := False;
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptFacturas(AListaID);
try
CreateEditor('EditorFacturasProveedorPreview', IEditorFacturasProveedorPreview, AEditor);
if Assigned(AEditor) then
try
AEditor.LoadFromStream(AStream);
AEditor.TablaImpresion := nme_FacturasProveedor;
AEditor.IdTablaImpresion := AListaID.ToString;
Result := AEditor.Print;
finally
AEditor.Release;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
end.