2007-11-05 18:00:22 +00:00
|
|
|
unit uFacturasClienteReportController;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleFacturasClienteReport,
|
|
|
|
|
uClientesController, uDetallesFacturaClienteController,
|
2008-08-22 14:52:35 +00:00
|
|
|
uBizFacturasCliente, uIntegerListUtils;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
|
|
|
type
|
2008-02-21 10:10:05 +00:00
|
|
|
IFacturasClienteReportController = interface(IControllerBase)
|
2007-11-05 18:00:22 +00:00
|
|
|
['{A0F41767-4FF6-4BAE-9FC9-894DD721D756}']
|
2008-08-22 14:52:35 +00:00
|
|
|
procedure Preview(const AListaID : TIntegerList);
|
|
|
|
|
procedure Print(const AListaID : TIntegerList);
|
2008-02-21 10:10:05 +00:00
|
|
|
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
|
2008-08-25 11:08:44 +00:00
|
|
|
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
|
2007-11-05 18:00:22 +00:00
|
|
|
end;
|
|
|
|
|
|
2008-02-21 10:10:05 +00:00
|
|
|
TFacturasClienteReportController = class(TControllerBase, IFacturasClienteReportController)
|
2007-11-05 18:00:22 +00:00
|
|
|
private
|
|
|
|
|
FDataModule : IDataModuleFacturasClienteReport;
|
|
|
|
|
function CreateEditor(const AName: String; const IID: TGUID;
|
|
|
|
|
out Intf): Boolean;
|
|
|
|
|
public
|
2008-05-20 18:50:02 +00:00
|
|
|
constructor Create; override;
|
2007-11-05 18:00:22 +00:00
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
2008-08-22 14:52:35 +00:00
|
|
|
procedure Preview(const AListaID : TIntegerList);
|
|
|
|
|
procedure Print(const AListaID : TIntegerList);
|
2008-02-21 10:10:05 +00:00
|
|
|
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
|
2008-08-25 11:08:44 +00:00
|
|
|
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
|
2007-11-05 18:00:22 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
uROTypes, uEditorRegistryUtils, uIEditorFacturasClientePreview,
|
2008-02-21 10:10:05 +00:00
|
|
|
uEditorPreview, uDataModuleFacturasCliente, uEditorBase, cxControls,
|
|
|
|
|
uStringsUtils, uSistemaFunc;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
|
|
|
{ TFacturasClienteReportController }
|
|
|
|
|
|
|
|
|
|
constructor TFacturasClienteReportController.Create;
|
|
|
|
|
begin
|
2008-11-10 19:38:27 +00:00
|
|
|
inherited;
|
2007-11-05 18:00:22 +00:00
|
|
|
FDataModule := TDataModuleFacturasCliente.Create(Nil);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TFacturasClienteReportController.CreateEditor(const AName: String;
|
|
|
|
|
const IID: TGUID; out Intf): Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
destructor TFacturasClienteReportController.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
FDataModule := NIL;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2008-08-25 11:08:44 +00:00
|
|
|
function TFacturasClienteReportController.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;
|
|
|
|
|
|
2008-02-21 10:10:05 +00:00
|
|
|
function TFacturasClienteReportController.ExportToWord(const AID: Integer;
|
|
|
|
|
const AFileName: String): Boolean;
|
|
|
|
|
var
|
|
|
|
|
AStream: Binary;
|
|
|
|
|
AFile : String;
|
|
|
|
|
begin
|
2008-05-20 18:50:02 +00:00
|
|
|
Result := False;
|
2008-02-21 10:10:05 +00:00
|
|
|
AFile := AFileName;
|
2008-05-20 18:50:02 +00:00
|
|
|
|
2008-08-20 14:23:47 +00:00
|
|
|
if EsCadenaVacia(AFile) and (not PreguntarFicheroWordExportar(AFile)) then
|
2008-02-21 10:10:05 +00:00
|
|
|
Exit;
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
try
|
|
|
|
|
AStream := FDataModule.GetRptWordFactura(AID);
|
|
|
|
|
try
|
|
|
|
|
AStream.SaveToFile(AFile);
|
|
|
|
|
Result := True;
|
|
|
|
|
finally
|
|
|
|
|
FreeAndNil(AStream);
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2008-08-22 14:52:35 +00:00
|
|
|
procedure TFacturasClienteReportController.Preview(const AListaID : TIntegerList);
|
2007-11-05 18:00:22 +00:00
|
|
|
var
|
|
|
|
|
AStream: Binary;
|
|
|
|
|
AEditor : IEditorFacturasClientePreview;
|
|
|
|
|
begin
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
try
|
2008-02-21 10:10:05 +00:00
|
|
|
AStream := FDataModule.GetRptFacturas(AListaID);
|
2007-11-05 18:00:22 +00:00
|
|
|
try
|
|
|
|
|
CreateEditor('EditorFacturasClientePreview', IEditorFacturasClientePreview, AEditor);
|
2007-11-13 19:36:56 +00:00
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
with AEditor do
|
|
|
|
|
begin
|
2008-02-21 10:10:05 +00:00
|
|
|
AEditor.Controller := Self;
|
2008-09-08 15:46:28 +00:00
|
|
|
ListaID := AListaID;
|
2007-11-18 20:08:55 +00:00
|
|
|
LoadFromStream(AStream);
|
|
|
|
|
Preview;
|
|
|
|
|
Release;
|
2007-11-13 19:36:56 +00:00
|
|
|
end;
|
2007-11-05 18:00:22 +00:00
|
|
|
finally
|
2007-11-13 19:36:56 +00:00
|
|
|
FreeAndNil(AStream);
|
|
|
|
|
AEditor := Nil;
|
2007-11-05 18:00:22 +00:00
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2008-08-22 14:52:35 +00:00
|
|
|
procedure TFacturasClienteReportController.Print(const AListaID : TIntegerList);
|
2007-11-05 18:00:22 +00:00
|
|
|
var
|
|
|
|
|
AStream: Binary;
|
|
|
|
|
AEditor : IEditorFacturasClientePreview;
|
|
|
|
|
begin
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
try
|
2008-02-21 10:10:05 +00:00
|
|
|
AStream := FDataModule.GetRptFacturas(AListaID);
|
2007-11-05 18:00:22 +00:00
|
|
|
try
|
|
|
|
|
CreateEditor('EditorFacturasClientePreview', IEditorFacturasClientePreview, AEditor);
|
2007-11-13 19:36:56 +00:00
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
with AEditor do
|
|
|
|
|
begin
|
2008-02-21 10:10:05 +00:00
|
|
|
AEditor.Controller := Self;
|
2007-11-18 20:08:55 +00:00
|
|
|
LoadFromStream(AStream);
|
|
|
|
|
Print;
|
|
|
|
|
Release;
|
2007-11-13 19:36:56 +00:00
|
|
|
end;
|
2007-11-05 18:00:22 +00:00
|
|
|
finally
|
2007-11-13 19:36:56 +00:00
|
|
|
FreeAndNil(AStream);
|
|
|
|
|
AEditor := Nil;
|
2007-11-05 18:00:22 +00:00
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|