unit uEditorInformeBeneficiosReportGrafComp;

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, uControllerBase,
  dxLayoutControl, cxControls, uViewFiltroImportes,
  FactuGES_Intf, TBXDkPanels, uEditorInformeBase,
  uIEditorInformeBase, uViewParametrosInforme, uIEditorInformeBeneficiosReportGrafComp,
  uViewIntervaloComparativo, uViewFiltroClientes;

type
  TfEditorInformeBeneficiosReportGrafComp = class(TfEditorInformeBase, IEditorInformeBeneficiosReportGrafComp)
    TBXItem58: TTBXItem;
    frViewIntervaloComparativo1: TfrViewIntervaloComparativo;
    frViewFiltroClientes1: TfrViewFiltroClientes;
    procedure actRefrescarExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);

  private
    FListaIDClientes: TIntegerArray;
    function GetIntervalo: Variant;
    function GetAno1: Variant;
    function GetAno2: Variant;
    function GetSerie: variant;
    function GetListaIDClientes: TIntegerArray;
    function GetNTop: Variant;

    procedure RefrescarInforme;

  protected
    procedure SetController (const Value : IControllerBase); override;

  public
    property Intervalo: Variant read GetIntervalo;
    property Ano1: Variant read GetAno1;
    property Ano2: Variant read GetAno2;
    property Serie: Variant read GetSerie;
    property ListaIDClientes: TIntegerArray read GetListaIDClientes;
    property NTop: Variant read GetNTop;

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


implementation

{$R *.dfm}

uses uROTypes, DateUtils, uGestorInformesController, uFactuGES_App;

{ TfEditorGestorInformesReport }

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

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

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

procedure TfEditorInformeBeneficiosReportGrafComp.FormShow(Sender: TObject);
begin
  inherited;
  actTodaPagina.Execute;
end;

function TfEditorInformeBeneficiosReportGrafComp.GetIntervalo: Variant;
begin
  Result := frViewIntervaloComparativo1.cbIntervalo.EditValue;
end;

function TfEditorInformeBeneficiosReportGrafComp.GetAno1: Variant;
begin
  Result := frViewIntervaloComparativo1.cbAno1.EditValue;
end;

function TfEditorInformeBeneficiosReportGrafComp.GetAno2: Variant;
begin
  Result := frViewIntervaloComparativo1.cbAno2.EditValue;
end;

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

  Result := FListaIDClientes;
end;

function TfEditorInformeBeneficiosReportGrafComp.GetNTop: Variant;
begin
  Result := frViewIntervaloComparativo1.stopN.Value;
end;

function TfEditorInformeBeneficiosReportGrafComp.GetSerie: Variant;
begin
  Result := frViewIntervaloComparativo1.Serie;
end;

procedure TfEditorInformeBeneficiosReportGrafComp.RefrescarInforme;
var
  AStream: Binary;
begin
  ShowHourglassCursor;
  try

    AStream := (Controller as IGestorInformesController).DataModule.GenerarInformeBeneficiosGrafComp(
      AppFactuGES.EmpresaActiva.ID,
      Intervalo,
      Ano1,
      Ano2,
      Serie);

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

procedure TfEditorInformeBeneficiosReportGrafComp.SetController(
  const Value: IControllerBase);
var
  AListaAnos: TStringList;
  AListaIntervalos: TStringList;
  i: Integer;

begin
  inherited;

  AListaIntervalos := (Controller as IGestorInformesController).DarListaIntervalos;
  AListaAnos := (Controller as IGestorInformesController).DarListaAnosFacturasCli;

  if Assigned(AListaIntervalos) then
  begin
    frViewIntervaloComparativo1.cbIntervalo.Properties.Items.BeginUpdate;
    frViewIntervaloComparativo1.cbIntervalo.Properties.Items.Clear;
    for i := 0 to AListaIntervalos.Count - 1 do
        frViewIntervaloComparativo1.cbIntervalo.Properties.Items.Append(AListaIntervalos.Strings[i]);
    frViewIntervaloComparativo1.cbIntervalo.Properties.Items.EndUpdate;
  end;

  if Assigned(AListaAnos) then
  begin
    frViewIntervaloComparativo1.cbAno1.Properties.Items.BeginUpdate;
    frViewIntervaloComparativo1.cbAno2.Properties.Items.BeginUpdate;
    frViewIntervaloComparativo1.cbAno1.Properties.Items.Clear;
    frViewIntervaloComparativo1.cbAno2.Properties.Items.Clear;
    for i := 0 to AListaAnos.Count - 1 do
    begin
        frViewIntervaloComparativo1.cbAno1.Properties.Items.Append(AListaAnos.Strings[i]);
        frViewIntervaloComparativo1.cbAno2.Properties.Items.Append(AListaAnos.Strings[i]);
    end;
    frViewIntervaloComparativo1.cbAno1.Properties.Items.EndUpdate;
    frViewIntervaloComparativo1.cbAno2.Properties.Items.EndUpdate;
  end;

  frViewIntervaloComparativo1.cbIntervalo.ItemIndex := 0;
  frViewIntervaloComparativo1.cbAno1.ItemIndex := 0;
end;

end.
