unit InformeBeneficiosAnualesContratos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, InformeBase, FR_IBXDB, FR_Shape, FR_DSet, FR_DBSet, FR_Class,
  DB, IBCustomDataSet, IBQuery, FR_Cross, IBDatabase, RdxEmpresaActiva;

type
  TdmInformeBeneficiosAnualesContratos = class(TdmInformeBase)
    TablaCon: TfrDBDataSet;
    TablaContratos: TIBQuery;
    frCrossObject1: TfrCrossObject;
    procedure FReportBeforePrint(Memo: TStringList; View: TfrView);
  private
    FFechaInicio : Variant;
    FFechaFin : Variant;
  protected
    procedure RellenarCabecera(Band: TfrBand); override;
    procedure PrepararConsultas; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property FechaInicio : Variant read FFechaInicio write FFechaInicio;
    property FechaFin : Variant read FFechaFin write FFechaFin;
  end;

var
  dmInformeBeneficiosAnualesContratos: TdmInformeBeneficiosAnualesContratos;

implementation

{$R *.dfm}

uses
  StrFunc, DateFunc;

{ TdmInformeBase1 }

constructor TdmInformeBeneficiosAnualesContratos.Create(AOwner: TComponent);
begin
  inherited;
  FNombreInforme := 'InformeBeneficiosAnualesContratos.frf';
  FReport.OnBeforePrint := FReportBeforePrint;
end;

procedure TdmInformeBeneficiosAnualesContratos.PrepararConsultas;
begin
  inherited;

  with TablaContratos do
  begin
    Database := FBaseDatos;
    Transaction := FTransaccion;
    SQL.Clear;
    SQL.Add('select extract(month from c.FECHACONTRATO), d.descripcion, c.IMPORTETOTAL ');
    SQL.Add('from CONTRATOSCLIENTE c, DOCUMENTOS d');
    SQL.Add('where c.CODIGODOCUMENTO = d.CODIGO');
    SQL.Add('and c.FECHACONTRATO between :FECHAINI and :FECHAFIN');
    ParamByName('FECHAINI').AsString := FFechaInicio;
    ParamByName('FECHAFIN').AsString := FFechaFin;
    Prepare;
  end;

end;

procedure TdmInformeBeneficiosAnualesContratos.RellenarCabecera(Band: TfrBand);
var
  iCont : Integer;
  Objeto : TfrView;
begin
  inherited;
  with Band do
  begin
     for iCont := 0 to Objects.Count - 1 do
      begin
        Objeto := Objects[iCont];
        if ((Objeto is TfrMemoView) and (Objeto.Name = 'CabParametros')) then
        begin
          with (Objeto as TfrMemoView) do
          begin
            Memo.Clear;
            Memo.Add('Empresa: ' + EmpresaActiva.NombreComercial);
            Memo.Add('Rango de fechas: ' + FechaInicio + ' - ' + FechaFin);
          end;
        end;
      end;
  end;
end;

procedure TdmInformeBeneficiosAnualesContratos.FReportBeforePrint(Memo: TStringList; View: TfrView);
begin
  inherited;

  if  (View.FormatStr = '#0')
  and (StrToIntDef(View.Memo.CommaText, -1) <> -1) then
    View.Memo.Text := DarMes(StrToIntDef(View.Memo.CommaText, -1));
end;

end.
