unit uEditorInformeFacturasProveedorReportGrafComp;

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, uIEditorInformeFacturasProveedorReportGrafComp,
  uViewIntervaloComparativo, uViewFiltroProveedores;

type
  TfEditorInformeFacturasProveedorReportGrafComp = class(TfEditorInformeBase, IEditorInformeFacturasProveedorReportGrafComp)
    TBXItem58: TTBXItem;
    frViewIntervaloComparativo1: TfrViewIntervaloComparativo;
    frViewFiltroProveedores1: TfrViewFiltroProveedores;
    procedure actRefrescarExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);

  private
    FListaIDProveedores: TIntegerArray;
    function GetIntervalo: Variant;
    function GetAno1: Variant;
    function GetAno2: Variant;
    function GetListaIDProveedores: 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 ListaIDProveedores: TIntegerArray read GetListaIDProveedores;
    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 TfEditorInformeFacturasProveedorReportGrafComp.actRefrescarExecute(Sender: TObject);
begin
  inherited;
  RefrescarInforme;
end;

constructor TfEditorInformeFacturasProveedorReportGrafComp.Create(AOwner: TComponent);
begin
  inherited;
  FListaIDProveedores := TIntegerArray.Create;
end;

destructor TfEditorInformeFacturasProveedorReportGrafComp.Destroy;
begin
  FListaIDProveedores.Free;
  inherited;
end;

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

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

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

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

function TfEditorInformeFacturasProveedorReportGrafComp.GetListaIDProveedores: TIntegerArray;
begin
  FListaIDProveedores.Clear;
  if Assigned(frViewFiltroProveedores1.Proveedor) then
     FListaIDProveedores.Add(frViewFiltroProveedores1.Proveedor.ID);

  Result := FListaIDProveedores;
end;

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

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

    AStream := (Controller as IGestorInformesController).DataModule.GenerarInformeFacturasProvGrafComp(
      AppFactuGES.EmpresaActiva.ID,
      Intervalo,
      Ano1,
      Ano2,
      ListaIDProveedores,
      NTop);

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

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

begin
  inherited;

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

  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.
