unit uBizAgentesComisiones;

interface

uses
  uDAInterfaces, uDADataTable,
  schContactosClient_Intf;

const
  BIZ_CLIENT_AGENTE_COMISIONES = 'Client.AgenteComisiones';

type
  IBizAgentesComisiones = interface (IAgentes_Comisiones)
  ['{B41B58A9-2CE3-45A2-9EA9-E8C2B72356BB}']
  end;

  TBizAgenteComisiones = class(TAgentes_ComisionesDataTableRules, IBizAgentesComisiones)
  private
    ContIdAux: Integer;
  protected
    procedure OnNewRecord(Sender: TDADataTable); override;
    procedure BeforeInsert(Sender: TDADataTable); override;    
  public
    constructor Create(aDataTable: TDADataTable); override;
  end;

implementation

{ TBizAgenteComisiones }

uses
  DB;

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

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

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

initialization
  RegisterDataTableRules(BIZ_CLIENT_AGENTE_COMISIONES, TBizAgenteComisiones);

end.

