unit uBizVentas;

interface

uses
  Classes, DB, SysUtils, uROClasses, uDADataTable, uDAInterfaces,
  DataAbstract_Intf, uROTypes;

const
  BIZ_VENTAS = 'Client.Ventas';

  { ListaInformesPorCategoria fields }
  fld_VentasCLAVE1 = 'CLAVE1';
  fld_VentasCLAVE2 = 'CLAVE2';
  fld_VentasCLAVE3 = 'CLAVE3';
  fld_VentasNUMINF = 'NUMINF';

type
  { IRDX_ARTVEN }
  IBizVentas = interface(IDAStronglyTypedDataTable)
    ['{E82C7F84-0CD4-4A27-80FB-BD608FDCA091}']
    function GetVisibleColumns: String;
    procedure SetVisibleColumns(AValue : String);
    procedure Show;
    property VisibleColumns : String read GetVisibleColumns write SetVisibleColumns;
  end;

  { TRDX_ARTVENDataTableRules }
  TBIZ_VENTASDataTableRules = class(TDADataTableRules, IBizVentas)
  private
    FVisibleColumns : String;
    FDateParams : TDADatasetParamArray;
  protected
    function GetVisibleColumns: String;
    procedure SetVisibleColumns(AValue : String);
    procedure OnBeforeDataRequestCall(DataTable: TDADataTable;
      Request: TDARemoteRequest);
    procedure OnBeforeSchemaCall(DataTable: TDADataTable;
      Request: TDARemoteRequest);
  public
    constructor Create(aDataTable: TDADataTable); override;
    
    procedure Show;
    property VisibleColumns : String read GetVisibleColumns write SetVisibleColumns;
    destructor Destroy; override;
  end;


implementation

{ TBIZ_VENTASDataTableRules }

uses
  Dialogs, uEditorUtils, uDataModuleVentas;

constructor TBIZ_VENTASDataTableRules.Create(aDataTable: TDADataTable);
begin
  inherited;
  FDateParams := TDADatasetParamArray.Create;
  if Assigned(DataTable) then
  begin
    DataTable.OnBeforeDataRequestCall := OnBeforeDataRequestCall;
    DataTable.OnBeforeSchemaCall := OnBeforeSchemaCall;
  end;
end;

destructor TBIZ_VENTASDataTableRules.Destroy;
begin
  FreeAndNIL(FDateParams);
  inherited;
end;

function TBIZ_VENTASDataTableRules.GetVisibleColumns: String;
begin
  if Length(FVisibleColumns) = 0 then
    FVisibleColumns := dmVentas.GetNameColumns;
  Result := FVisibleColumns
end;

procedure TBIZ_VENTASDataTableRules.OnBeforeDataRequestCall(
  DataTable: TDADataTable; Request: TDARemoteRequest);
begin
  Request.ParamByName('Columns').AsString := VisibleColumns;
  FDateParams.Clear;
  NewDatasetParam(FDateParams, 'FECHAINI', DataTable.ParamByName('FECHAINI').AsDateTime);
  NewDatasetParam(FDateParams, 'FECHAFIN', DataTable.ParamByName('FECHAFIN').AsDateTime);
  Request.ParamByName('Params').AsComplexType := FDateParams;
end;

procedure TBIZ_VENTASDataTableRules.OnBeforeSchemaCall(
  DataTable: TDADataTable; Request: TDARemoteRequest);
begin
  Request.ParamByName('Columns').AsString := VisibleColumns;
end;

procedure TBIZ_VENTASDataTableRules.SetVisibleColumns(AValue: String);
begin
  if Length(AValue) > 0 then
    FVisibleColumns := Avalue
  else
    FVisibleColumns := dmVentas.GetNameColumns;
end;

procedure TBIZ_VENTASDataTableRules.Show;
begin
  ShowEditor(IBizVentas, Self, etItem);
end;

initialization
  RegisterDataTableRules(BIZ_VENTAS, TBIZ_VENTASDataTableRules);

finalization

end.

