unit uBizCobrosCliente; interface uses uDAInterfaces, uDADataTable, schCobrosClienteClient_Intf, uBizContactos, Classes; const BIZ_CLIENT_COBRO_CLIENTE = 'Client.CobroCliente'; type IBizCobroCliente = interface(ICobrosCliente) ['{B03C0E35-AE13-415A-B21A-3135E8CC3FFC}'] procedure SetCliente(AValue : IBizCliente); function GetCliente : IBizCliente; property Cliente : IBizCliente read GetCliente write SetCliente; function EsNuevo : Boolean; end; TBizCobroCliente = class(TCobrosClienteDataTableRules, IBizCobroCliente) protected FCliente : IBizCliente; procedure SetCliente(AValue : IBizCliente); function GetCliente : IBizCliente; procedure OnNewRecord(Sender: TDADataTable); override; public function EsNuevo : Boolean; property Cliente : IBizCliente read GetCliente write SetCliente; constructor Create(aDataTable: TDADataTable); override; destructor Destroy; override; end; implementation uses SysUtils, uDataTableUtils, DB, uDateUtils, DateUtils, uDataModuleUsuarios, Variants, cxDateUtils; { TBizCobroCliente } function TBizCobroCliente.EsNuevo: Boolean; begin Result := (ID < 0); end; constructor TBizCobroCliente.Create(aDataTable: TDADataTable); begin inherited; FCliente := Nil; end; destructor TBizCobroCliente.Destroy; begin FCliente := NIL; inherited; end; function TBizCobroCliente.GetCliente: IBizCliente; begin Result := FCliente; end; procedure TBizCobroCliente.OnNewRecord(Sender: TDADataTable); begin inherited; ID := GetRecNo; // -1, -2, -3... ID_EMPRESA := dmUsuarios.IDEmpresaActual; USUARIO := dmUsuarios.LoginInfo.Usuario; FECHA_COBRO := DateOf(Now); ID_CLIENTE := ID_NULO; IMPORTE := 0; end; procedure TBizCobroCliente.SetCliente(AValue: IBizCliente); var bEnEdicion : Boolean; begin FCliente := AValue; bEnEdicion := (DataTable.State in dsEditModes); if not bEnEdicion then Edit; if Assigned(FCliente) then begin if not FCliente.DataTable.Active then FCliente.DataTable.Active := True; ID_CLIENTE := FCliente.ID; Post; if bEnEdicion then Edit; end end; initialization RegisterDataTableRules(BIZ_CLIENT_COBRO_CLIENTE, TBizCobroCliente); finalization end.