unit uPedidosProveedorReportController; interface uses Classes, SysUtils, uDADataTable, uControllerBase, uIDataModulePedidosProveedorReport, uClientesController, uPedidosProveedorController, uDetallesPedidoProveedorController, uBizPedidosProveedor, uIntegerListUtils; type IPedidosProveedorReportController = interface(IControllerBase) ['{D0686358-251C-43C4-9927-6112F2F4D3B8}'] procedure Preview(const AListaID : TIntegerList; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True); procedure Print(const AListaID : TIntegerList; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True); function ExportToWord(const AID: Integer; const AFileName : String = ''; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True): Boolean; function ExportToPDF(const AID: Integer; const AFileName : String = ''; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True): Boolean; end; TPedidosProveedorReportController = class(TControllerBase, IPedidosProveedorReportController) private FDataModule : IDataModulePedidosProveedorReport; function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; public constructor Create; override; destructor Destroy; override; procedure Preview(const AListaID : TIntegerList; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True); procedure Print(const AListaID : TIntegerList; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True); function ExportToWord(const AID: Integer; const AFileName : String = ''; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True): Boolean; function ExportToPDF(const AID: Integer; const AFileName : String = ''; const VerPrecios: Boolean = True; const VerRefProveedor: Boolean = True): Boolean; end; implementation uses uROTypes, uEditorRegistryUtils, uIEditorPedidosProveedorPreview, uEditorPreview, uDataModulePedidosProveedor, uEditorBase, cxControls, uFactuGES_App, uStringsUtils, uSistemaFunc; { TPedidosProveedorReportController } constructor TPedidosProveedorReportController.Create; begin inherited; FDataModule := TDataModulePedidosProveedor.Create(Nil); end; function TPedidosProveedorReportController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; begin Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf); end; destructor TPedidosProveedorReportController.Destroy; begin FDataModule := NIL; inherited; end; function TPedidosProveedorReportController.ExportToPDF(const AID: Integer; const AFileName: String; const VerPrecios: Boolean; const VerRefProveedor: Boolean): Boolean; var AStream: Binary; begin Result := False; if EsCadenaVacia(AFileName) then Exit; ShowHourglassCursor; try AStream := FDataModule.GetRptPDFPedido(AID, VerPrecios, VerRefProveedor); try AStream.SaveToFile(AFileName); Result := True; finally FreeAndNil(AStream); end; finally HideHourglassCursor; end; end; function TPedidosProveedorReportController.ExportToWord(const AID: Integer; const AFileName: String; const VerPrecios: Boolean; const VerRefProveedor: Boolean): Boolean; var AStream: Binary; AFile : String; begin Result := False; AFile := AFileName; if EsCadenaVacia(AFile) and (not PreguntarFicheroWordExportar(AFile)) then Exit; ShowHourglassCursor; try AStream := FDataModule.GetRptWordPedido(AID, VerPrecios, VerRefProveedor); try AStream.SaveToFile(AFile); Result := True; finally FreeAndNil(AStream); end; finally HideHourglassCursor; end; end; procedure TPedidosProveedorReportController.Preview(const AListaID : TIntegerList; const VerPrecios: Boolean; const VerRefProveedor: Boolean); var AStream: Binary; AEditor : IEditorPedidosProveedorPreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetReport(AListaID, VerPrecios, VerRefProveedor); try CreateEditor('EditorPedidosProveedorPreview', IEditorPedidosProveedorPreview, AEditor); if Assigned(AEditor) then begin try AEditor.Controller := Self; AEditor.ListaID := AListaID; AEditor.VerPrecios := VerPrecios; AEditor.VerRefProveedor := VerRefProveedor; AEditor.Title := 'Pedido a proveedor - ' + AppFactuGES.EmpresaActiva.NOMBRE; AEditor.LoadFromStream(AStream); AEditor.Preview; finally AEditor.Release; AEditor := Nil; end; end; finally FreeANDNil(AStream) end; finally HideHourglassCursor; end; end; procedure TPedidosProveedorReportController.Print(const AListaID : TIntegerList; const VerPrecios: Boolean; const VerRefProveedor: Boolean); var AStream: Binary; AEditor : IEditorPedidosProveedorPreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetReport(AListaID, VerPrecios, VerRefProveedor); try CreateEditor('EditorPedidosProveedorPreview', IEditorPedidosProveedorPreview, AEditor); if Assigned(AEditor) then begin try AEditor.Controller := Self; AEditor.ListaID := AListaID; AEditor.Title := 'Pedido a proveedor - ' + AppFactuGES.EmpresaActiva.NOMBRE; AEditor.LoadFromStream(AStream); AEditor.Print; finally AEditor.Release; end; end; finally FreeAndNil(AStream); AEditor := Nil; end; finally HideHourglassCursor; end; end; end.