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_FactuGES/Source/Modulos/Facturas de proveedor/Controller/uFacturasProveedorReportController.pas

135 lines
3.5 KiB
ObjectPascal

unit uFacturasProveedorReportController;
interface
uses
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleFacturasProveedorReport,
uClientesController, uDetallesFacturaProveedorController, uBizFacturasProveedor;
type
IFacturasProveedorReportController = interface
['{551F82DC-B8DC-482E-A20D-15003E845078}']
procedure Preview(const AFacturaID : String);
function Print(const AFacturaID : String): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
TFacturasProveedorReportController = class(TInterfacedObject, IFacturasProveedorReportController)
private
FDataModule : IDataModuleFacturasProveedorReport;
function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
public
constructor Create;
destructor Destroy; override;
procedure Preview(const AFacturaID : String);
function Print(const AFacturaID : String): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
implementation
uses
uROTypes, uEditorRegistryUtils, uIEditorFacturasProveedorPreview,
uEditorPreview, uDataModuleFacturasProveedor, uEditorBase, cxControls,
schFacturasProveedorClient_Intf, uStringsUtils;
{ TFacturasProveedorReportController }
constructor TFacturasProveedorReportController.Create;
begin
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.GetRptPDFFacturas(AID, True);
try
AStream.SaveToFile(AFileName);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
procedure TFacturasProveedorReportController.Preview(const AFacturaID : String);
var
AStream: Binary;
AEditor : IEditorFacturasProveedorPreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetReport(AFacturaID);
try
CreateEditor('EditorFacturasProveedorPreview', IEditorFacturasProveedorPreview, AEditor);
AEditor.LoadFromStream(AStream);
finally
AStream.Free;
end;
finally
HideHourglassCursor;
end;
if Assigned(AEditor) then
AEditor.Preview;
end;
function TFacturasProveedorReportController.Print(const AFacturaID : String): Boolean;
var
AStream: Binary;
AEditor : IEditorFacturasProveedorPreview;
begin
Result := False;
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetReport(AFacturaID);
try
CreateEditor('EditorFacturasProveedorPreview', IEditorFacturasProveedorPreview, AEditor);
AEditor.LoadFromStream(AStream);
finally
AStream.Free;
end;
finally
HideHourglassCursor;
end;
if Assigned(AEditor) then
begin
AEditor.TablaImpresion := nme_FacturasProveedor;
AEditor.IdTablaImpresion := AFacturaID;
Result := AEditor.Print;
end;
end;
end.