unit uEditorInformeIVAProveedoresReport;

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, 
  uViewFiltroProveedores, dxLayoutControl, cxControls, uViewFiltroImportes,
  FactuGES_Intf, TBXDkPanels, uEditorInformeBase,
  uIEditorInformeBase, uViewParametrosInforme, uIEditorInformeIVAProveedoresReport,
  dxLayoutLookAndFeels, frxExportCSV;

type
  TfEditorInformeIVAProveedoresReport = class(TfEditorInformeBase, IEditorInformeIVAProveedoresReport)
    TBXItem58: TTBXItem;
    frViewPeriodoFechas1: TfrViewPeriodoFechas;
    frViewFiltroImportes1: TfrViewFiltroImportes;
    frViewFiltroProveedores1: TfrViewFiltroProveedores;
    procedure actRefrescarExecute(Sender: TObject);
  private
    FListaIDProveedores: TIntegerArray;
    function GetFechaFin: Variant;
    function GetFechaInicio: Variant;
    function GetListaIDProveedores: TIntegerArray;
    function GetImporteMinimo: Currency;
    function GetDesglosadoProveedor: Boolean;

    procedure RefrescarInforme;

  public
    property FechaInicio: Variant read GetFechaInicio;
    property FechaFin: Variant read GetFechaFin;
    property ListaIDProveedores: TIntegerArray read GetListaIDProveedores;
    property DesglosadoProveedor: Boolean read GetDesglosadoProveedor;
    property ImporteMinimo: Currency read GetImporteMinimo;

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


implementation

{$R *.dfm}

uses uROTypes, DateUtils, uGestorInformesController, uFactuGES_App;

{ TfEditorGestorInformesReport }

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

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

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

function TfEditorInformeIVAProveedoresReport.GetDesglosadoProveedor: Boolean;
begin
  if frViewFiltroImportes1.cbxDesglosado.Enabled then
    Result := frViewFiltroProveedores1.cbxDesglosado.Checked
  else
     Result := False;
end;

function TfEditorInformeIVAProveedoresReport.GetFechaFin: Variant;
begin
  Result := frViewPeriodoFechas1.edtFechaFin.EditValue;

  //Esto es para quitar la hora del timestamp para que luego no me redondee al dia siguiente
  if not VarIsNull(Result) then
     Result := DateOf(frViewPeriodoFechas1.edtFechaFin.Date);
end;

function TfEditorInformeIVAProveedoresReport.GetFechaInicio: Variant;
begin
  Result := frViewPeriodoFechas1.edtFechaIni.EditValue;
end;

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

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

  Result := FListaIDProveedores;
end;

procedure TfEditorInformeIVAProveedoresReport.RefrescarInforme;
var
  AStream: Binary;
begin
  ShowHourglassCursor;
  try
    AStream := (Controller as IGestorInformesController).DataModule.GenerarInformeIVAProveedores(
      AppFactuGES.EmpresaActiva.ID,
      FechaInicio,
      FechaFin,
      ListaIDProveedores,
      DesglosadoProveedor,
      ImporteMinimo);

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

end.
