unit uBizArticulosProveedores; interface uses uDAInterfaces, uDADataTable, schArticulosClient_Intf; const BIZ_CLIENT_ARTICULOS_PROVEEDORES = 'Client.ArticulosProveedores'; type IBizArticulosProveedores = interface(IArticulos_Proveedores) ['{DBDDEFE0-EE66-4D22-93C0-75A8CEBB6CAC}'] function EsNuevo : Boolean; procedure RecalcularImportes; end; TBizArticulosProveedores = class(TArticulos_ProveedoresDataTableRules, IBizArticulosProveedores) private procedure RecalcularImporte; protected procedure BeforeInsert(Sender: TDADataTable); override; procedure OnNewRecord(Sender: TDADataTable); override; procedure PARAMETROSPRECIOOnChange(Sender: TDACustomField); public procedure RecalcularImportes; function EsNuevo : Boolean; constructor Create(aDataTable: TDADataTable); override; end; implementation uses Dialogs,uDataTableUtils, DB; { TBizArticulosProveedores } procedure TBizArticulosProveedores.BeforeInsert(Sender: TDADataTable); var AMasterTable : TDADataTable; begin inherited; AMasterTable := DataTable.GetMasterDataTable; if Assigned(AMasterTable) and (AMasterTable.State in dsEditModes) then AMasterTable.Post; end; constructor TBizArticulosProveedores.Create(aDataTable: TDADataTable); begin inherited; with aDataTable do begin FieldByName(fld_Articulos_ProveedoresPRECIO_COSTE).OnChange := PARAMETROSPRECIOOnChange; FieldByName(fld_Articulos_ProveedoresDESCUENTO).OnChange := PARAMETROSPRECIOOnChange; FieldByName(fld_Articulos_ProveedoresPRECIO_PORTE).OnChange := PARAMETROSPRECIOOnChange; end; end; function TBizArticulosProveedores.EsNuevo: Boolean; begin Result := (ID < 0); end; procedure TBizArticulosProveedores.OnNewRecord(Sender: TDADataTable); begin inherited; PRECIO_PORTE := 0; PRECIO_COSTE := 0; DESCUENTO := 0; PRECIO_NETO := 0; end; procedure TBizArticulosProveedores.PARAMETROSPRECIOOnChange(Sender: TDACustomField); begin RecalcularImporte; end; procedure TBizArticulosProveedores.RecalcularImporte; begin with Self.DataTable do begin if not Editing then Edit; //OJO SI ALGUNA VEZ ESTO CAMBIA TAMBIEN HAY QUE CAMBIAR EL PROCEDIMIENTO ALMACENADO PRO_ART_RECALCULAR_PVP Self.PRECIO_NETO := Self.PRECIO_COSTE - (Self.PRECIO_COSTE * (Self.DESCUENTO / 100)); // Self.PRECIO_PVP_VENTA := (Self.PRECIO_NETO + Self.PRECIO_PORTE) * ((MasterSource.DataTable.FieldByName('PARAM_MARGEN').AsFloat / 100) + 1); // Self.PRECIO_PVP_TOTAL := Self.PRECIO_PVP_VENTA + MasterSource.DataTable.FieldByName('MANO_OBRA').AsFloat; end; end; procedure TBizArticulosProveedores.RecalcularImportes; var AIdAux: Integer; begin AIdAux := Self.ID; with Self.DataTable do begin DisableControls; try First; while not EOF do begin RecalcularImporte; Post; Next; end; First; Locate(fld_Articulos_ProveedoresID, AIdAux, []); finally EnableControls; end; end; end; initialization RegisterDataTableRules(BIZ_CLIENT_ARTICULOS_PROVEEDORES, TBizArticulosProveedores); end.