unit uBizClientesDescuentos;

interface

uses
  uDAInterfaces, uDADataTable,
  schContactosClient_Intf;

const
  BIZ_CLIENT_CLIENTE_DESCUENTOS = 'Client.ClienteDescuentos';

type
  IBizClienteDescuentos = interface (IClientesDescuentos)
    ['{41EF5532-D013-4976-BE23-6094E4C07CEF}']
  end;

  TBizClienteDescuentos = class(TClientesDescuentosDataTableRules, IBizClienteDescuentos)
  private
    ContIdAux: Integer;
  protected
    procedure OnNewRecord(Sender: TDADataTable); override;
    procedure BeforeInsert(Sender: TDADataTable); override;    
  public
    constructor Create(aDataTable: TDADataTable); override;
  end;

implementation

{ TBizClienteDescuentos }

uses
  DB;

procedure TBizClienteDescuentos.BeforeInsert(Sender: TDADataTable);
var
  AMasterTable : TDADataTable;
begin
  inherited;
  AMasterTable := DataTable.GetMasterDataTable;
  if Assigned(AMasterTable) and (AMasterTable.State in dsEditModes) then
    AMasterTable.Post;
end;

constructor TBizClienteDescuentos.Create(aDataTable: TDADataTable);
begin
  inherited;
  ContIdAux := -1;
end;

procedure TBizClienteDescuentos.OnNewRecord(Sender: TDADataTable);
begin
  inherited;
  ID := ContIdAux; // -1, -2, -3...
  Dec(ContIdAux);
end;

initialization
  RegisterDataTableRules(BIZ_CLIENT_CLIENTE_DESCUENTOS, TBizClienteDescuentos);

end.

