unit InformeFacturaCliente;

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, RdxEmpresaActiva;

type
  TdmInformeFacturaCliente = class(TdmInformeBase)
    TablaCab: TfrDBDataSet;
    TablaDet: TfrDBDataSet;
    TablaFacturasCliente: TIBQuery;
    TablaDetallesFacturas: TIBQuery;
  private
    FCodigoFactura : Variant;
  protected
    procedure RellenarCabecera(Band: TfrBand); override;
    procedure PrepararConsultas; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property CodigoFactura : variant read FCodigoFactura write FCodigoFactura;
  end;

var
  dmInformeFacturaCliente: TdmInformeFacturaCliente;

implementation

{$R *.dfm}

uses
  TablaFacturasCliente, StrFunc, Constantes, BaseDatos, TablaEmpresas;

{ TdmInformeFacturaCliente }

constructor TdmInformeFacturaCliente.Create(AOwner: TComponent);
begin
  inherited;
  FNombreInforme := 'FacturaCliente.frf';
end;

procedure TdmInformeFacturaCliente.PrepararConsultas;
begin
  inherited;

  with TablaFacturasCliente do
  begin
    Database := FBaseDatos;
    Transaction := FTransaccion;
    SQL.Clear;
    SQL.Add('select * from FACTURASCLIENTE ');
    SQL.Add('where CODIGOEMPRESA = :CODIGOEMPRESA');
    SQL.Add(' and CODIGO = :CODIGO');
    ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
    ParamByName('CODIGO').AsString := FCodigoFactura;
    Prepare;
  end;

  with TablaDetallesFacturas do
  begin
    Database := FBaseDatos;
    Transaction := FTransaccion;
    SQL.Clear;
    SQL.Add('select * from DETALLESFACTURASCLIARTICULOS ');
    SQL.Add('where CODIGOEMPRESA = :CODIGOEMPRESA ');
    SQL.Add('and CODIGOFACTURA = :CODIGOFACTURA ');
    SQL.Add('order by NUMCONCEPTO ');
    ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;    
    ParamByName('CODIGOFACTURA').AsString := FCodigoFactura;
    Prepare;
  end;

  TablaCab.Open;
  TablaDet.Open;
end;

procedure TdmInformeFacturaCliente.RellenarCabecera(Band: TfrBand);
var
  iCont : Integer;
  Objeto : TfrView;
begin
  inherited;
{  if TablaFacturasCliente.FieldByName('CLASEFACTURA').AsString = CTE_CF_ABONO then
    with Band do
    begin
       for iCont := 0 to Objects.Count - 1 do
        begin
          Objeto := Objects[iCont];
          if ((Objeto is TfrMemoView) and (Objeto.Name = 'LiteralAbono')) then
           (Objeto as TfrMemoView).Visible := True;
        end;
    end;}
end;

end.
