unit uEditorInformeFacturasClienteReport;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorPreview, frxExportText, frxExportRTF, frxExportMail,
  frxExportXLS, frxExportImage, frxExportPDF, frxClass, frxDCtrl, frxGradient,
  frxChBox, frxCross, frxRich, frxOLE, frxBarcode, JvAppStorage,
  JvAppRegistryStorage, JvComponentBase, JvFormPlacement, ImgList, PngImageList,
  StdActns, ActnList, ComCtrls, JvExComCtrls, JvStatusBar, TB2ExtItems,
  TBXExtItems, TBX, TB2Item, TB2Dock, TB2Toolbar, pngimage, ExtCtrls,
  JvExControls, JvNavigationPane, uCustomView,
  uViewBase, uViewPeriodoFechas, 
  uViewFiltroClientes, dxLayoutControl, cxControls, uViewFiltroImportes,
  FactuGES_Intf, TBXDkPanels, uEditorInformeBase,
  uIEditorInformeBase, uViewParametrosInforme, uIEditorInformeFacturasClienteReport;

type
  TfEditorInformeFacturasClienteReport = class(TfEditorInformeBase, IEditorInformeFacturasClienteReport)
    TBXItem58: TTBXItem;
    frViewPeriodoFechas1: TfrViewPeriodoFechas;
    frViewFiltroImportes1: TfrViewFiltroImportes;
    frViewFiltroClientes1: TfrViewFiltroClientes;
    procedure actRefrescarExecute(Sender: TObject);
  private
    FListaIDClientes: TIntegerArray;
    function GetFechaFin: TDateTime;
    function GetFechaInicio: TDateTime;
    function GetListaIDClientes: TIntegerArray;
    function GetImporteMinimo: Currency;
    function GetDesglosadoCliente: Boolean;

    procedure RefrescarInforme;

  public
    property FechaInicio: TDateTime read GetFechaInicio;
    property FechaFin: TDateTime read GetFechaFin;
    property ListaIDClientes: TIntegerArray read GetListaIDClientes;
    property DesglosadoCliente: Boolean read GetDesglosadoCliente;
    property ImporteMinimo: Currency read GetImporteMinimo;

    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;


implementation

{$R *.dfm}

uses uROTypes, uGestorInformesController, uFactuGES_App;

{ TfEditorGestorInformesReport }

procedure TfEditorInformeFacturasClienteReport.actRefrescarExecute(Sender: TObject);
begin
  inherited;
  RefrescarInforme;
end;

constructor TfEditorInformeFacturasClienteReport.Create(AOwner: TComponent);
begin
  inherited;
  FListaIDClientes := TIntegerArray.Create;
end;

destructor TfEditorInformeFacturasClienteReport.Destroy;
begin
  FListaIDClientes.Free;
  inherited;
end;

function TfEditorInformeFacturasClienteReport.GetDesglosadoCliente: Boolean;
begin
  if frViewFiltroImportes1.cbxDesglosado.Enabled then
    Result := frViewFiltroClientes1.cbxDesglosado.Checked
  else
     Result := False;
end;

function TfEditorInformeFacturasClienteReport.GetFechaFin: TDateTime;
begin
  Result := frViewPeriodoFechas1.edtFechaFin.Date;
end;

function TfEditorInformeFacturasClienteReport.GetFechaInicio: TDateTime;
begin
  Result := frViewPeriodoFechas1.edtFechaIni.Date;
end;

function TfEditorInformeFacturasClienteReport.GetImporteMinimo: Currency;
begin
  if frViewFiltroImportes1.eImporte.Enabled then
     Result := frViewFiltroImportes1.eImporte.Value
  else
     Result := 0;
end;

function TfEditorInformeFacturasClienteReport.GetListaIDClientes: TIntegerArray;
begin
  FListaIDClientes.Clear;
  if Assigned(frViewFiltroClientes1.Cliente) then
     FListaIDClientes.Add(frViewFiltroClientes1.Cliente.ID);

  Result := FListaIDClientes;
end;

procedure TfEditorInformeFacturasClienteReport.RefrescarInforme;
var
  AStream: Binary;
begin
  ShowHourglassCursor;
  try
    AStream := (Controller as IGestorInformesController).DataModule.GenerarInformeListadoFacturasCli(
      AppFactuGES.EmpresaActiva.ID,
      FechaInicio,
      FechaFin,
      ListaIDClientes,
      DesglosadoCliente,
      ImporteMinimo);

    LoadFromStream(AStream);
    Report.ShowPreparedReport;
  finally
    FreeAndNil(AStream);
    HideHourglassCursor;
  end;
end;

end.
