unit uBizContactos; interface uses uDAInterfaces, uDADataTable, schContactosClient_Intf, uBizContactosDatosBancarios, uBizCategoriasContacto, uDBSelectionListUtils, uBizDireccionesContacto, uBizAgentesComisiones, uBizClientesDescuentos; const BIZ_CLIENT_CONTACTO = 'Client.Contacto'; BIZ_CLIENT_CLIENTE = 'Client.Cliente'; BIZ_CLIENT_PROVEEDOR = 'Client.Proveedor'; BIZ_CLIENT_AGENTE = 'Client.Agente'; CATEGORIA_CLIENTE = 1; CATEGORIA_PROVEEDOR = 2; CATEGORIA_AGENTE = 3; PROVEEDOR_REGIMEN_IVA = 'General'; CLIENTE_REGIMEN_IVA = 'General'; CLIENTE_DIAS_VENCIMIENTO = 15; CLIENTE_RECARGO_EQUIVALENCIA = 0; type IBizContacto = interface (IContactos) ['{CD585680-26B6-47A4-B684-89C468670F4A}'] procedure SetDatosBancarios(AValue : IBizContactosDatosBancarios); function GetDatosBancarios : IBizContactosDatosBancarios; property DatosBancarios : IBizContactosDatosBancarios read GetDatosBancarios write SetDatosBancarios; function GetCategoria : String; property Categoria : String read GetCategoria; function _GetCategorias: IBizCategoriasContacto; procedure _SetCategorias(const Value: IBizCategoriasContacto); property _Categorias : IBizCategoriasContacto read _GetCategorias write _SetCategorias; function GetDirecciones: IBizDireccionesContacto; procedure SetDirecciones(const Value: IBizDireccionesContacto); property Direcciones : IBizDireccionesContacto read GetDirecciones write SetDirecciones; function EsNuevo : Boolean; end; IBizCliente = interface (IBizContacto) ['{EA48A6AA-AC96-4AD9-B383-F2FD4552EE76}'] function GetID_AGENTEValue: Integer; procedure SetID_AGENTEValue(const aValue: Integer); function GetGRUPO_CLIENTEValue: String; procedure SetGRUPO_CLIENTEValue(const aValue: String); function GetNOMBRE_COMERCIALValue: String; procedure SetNOMBRE_COMERCIALValue(const aValue: String); function GetVENCIMIENTO_FACTURASValue: Integer; procedure SetVENCIMIENTO_FACTURASValue(const aValue: Integer); function GetBLOQUEADOValue: Integer; procedure SetBLOQUEADOValue(const aValue: Integer); function GetMOTIVO_BLOQUEOValue: String; procedure SetMOTIVO_BLOQUEOValue(const aValue: String); function GetRECARGO_EQUIVALENCIAValue: Integer; procedure SetRECARGO_EQUIVALENCIAValue(const aValue: Integer); function GetREGIMEN_IVAValue: String; procedure SetREGIMEN_IVAValue(const aValue: String); function GetID_TIPO_IVAValue: Integer; procedure SetID_TIPO_IVAValue(const aValue: Integer); function GetID_FORMA_PAGOValue: Integer; procedure SetID_FORMA_PAGOValue(const aValue: Integer); function GetTIENDA_WEBValue: Integer; procedure SetTIENDA_WEBValue(const aValue: Integer); function GetDescuentos: IBizClienteDescuentos; procedure SetDescuentos(Value: IBizClienteDescuentos); property Descuentos: IBizClienteDescuentos read GetDescuentos write SetDescuentos; property ID_AGENTE: Integer read GetID_AGENTEValue write SetID_AGENTEValue; property GRUPO_CLIENTE: String read GetGRUPO_CLIENTEValue write SetGRUPO_CLIENTEValue; property NOMBRE_COMERCIAL: String read GetNOMBRE_COMERCIALValue write SetNOMBRE_COMERCIALValue; property VENCIMIENTO_FACTURAS: Integer read GetVENCIMIENTO_FACTURASValue write SetVENCIMIENTO_FACTURASValue; property BLOQUEADO: Integer read GetBLOQUEADOValue write SetBLOQUEADOValue; property MOTIVO_BLOQUEO: String read GetMOTIVO_BLOQUEOValue write SetMOTIVO_BLOQUEOValue; property RECARGO_EQUIVALENCIA: Integer read GetRECARGO_EQUIVALENCIAValue write SetRECARGO_EQUIVALENCIAValue; property REGIMEN_IVA: String read GetREGIMEN_IVAValue write SetREGIMEN_IVAValue; property ID_TIPO_IVA: Integer read GetID_TIPO_IVAValue write SetID_TIPO_IVAValue; property ID_FORMA_PAGO: Integer read GetID_FORMA_PAGOValue write SetID_FORMA_PAGOValue; property TIENDA_WEB: Integer read GetTIENDA_WEBValue write SetTIENDA_WEBValue; end; IBizProveedor = interface (IBizContacto) ['{0CC1FBB8-C2F1-4E10-87B9-D4EEB1221299}'] function GetREGIMEN_IVAValue: String; procedure SetREGIMEN_IVAValue(const aValue: String); function GetDESCUENTOValue: Float; procedure SetDESCUENTOValue(const aValue: Float); function GetID_TIPO_IVAValue: Integer; procedure SetID_TIPO_IVAValue(const aValue: Integer); function GetID_FORMA_PAGOValue: Integer; procedure SetID_FORMA_PAGOValue(const aValue: Integer); function GetTIENDA_WEBValue: Integer; procedure SetTIENDA_WEBValue(const aValue: Integer); property REGIMEN_IVA: String read GetREGIMEN_IVAValue write SetREGIMEN_IVAValue; property DESCUENTO: Float read GetDESCUENTOValue write SetDESCUENTOValue; property ID_TIPO_IVA: Integer read GetID_TIPO_IVAValue write SetID_TIPO_IVAValue; property ID_FORMA_PAGO: Integer read GetID_FORMA_PAGOValue write SetID_FORMA_PAGOValue; property TIENDA_WEB: Integer read GetTIENDA_WEBValue write SetTIENDA_WEBValue; end; IBizAgente = interface (IBizContacto) ['{C3288C4E-127F-4AC5-A668-4DA88B79683F}'] function GetComisiones: IBizAgenteComisiones; procedure SetComisiones(Value: IBizAgenteComisiones); property Comisiones: IBizAgenteComisiones read GetComisiones write SetComisiones; end; TBizContacto = class(TContactosDataTableRules, IBizContacto, ISeleccionable) protected FDatosBancarios : IBizContactosDatosBancarios; FDatosBancariosLink : TDADataSource; FCategorias : IBizCategoriasContacto; FCategoriasLink : TDADataSource; FDirecciones : IBizDireccionesContacto; FDireccionesLink : TDADataSource; FSeleccionableInterface : ISeleccionable; function _GetCategorias: IBizCategoriasContacto; procedure _SetCategorias(const Value: IBizCategoriasContacto); procedure SetDatosBancarios(AValue : IBizContactosDatosBancarios); function GetDatosBancarios : IBizContactosDatosBancarios; function GetDirecciones: IBizDireccionesContacto; procedure SetDirecciones(const Value: IBizDireccionesContacto); function GetCategoria : String; procedure OnNewRecord(Sender: TDADataTable); override; public function EsNuevo : Boolean; procedure IniciarValoresContactoNuevo; virtual; constructor Create(aDataTable: TDADataTable); override; destructor Destroy; override; property Categoria : String read GetCategoria; property _Categorias : IBizCategoriasContacto read _GetCategorias write _SetCategorias; property DatosBancarios : IBizContactosDatosBancarios read GetDatosBancarios write SetDatosBancarios; property Direcciones : IBizDireccionesContacto read GetDirecciones write SetDirecciones; property SeleccionableInterface : ISeleccionable read FSeleccionableInterface write FSeleccionableInterface implements ISeleccionable; end; TBizCliente = class(TBizContacto, IBizCliente) protected FDescuentos : IBizClienteDescuentos; FDescuentosLink : TDADataSource; function GetID_AGENTEValue: Integer; procedure SetID_AGENTEValue(const aValue: Integer); function GetGRUPO_CLIENTEValue: String; procedure SetGRUPO_CLIENTEValue(const aValue: String); function GetNOMBRE_COMERCIALValue: String; procedure SetNOMBRE_COMERCIALValue(const aValue: String); function GetVENCIMIENTO_FACTURASValue: Integer; procedure SetVENCIMIENTO_FACTURASValue(const aValue: Integer); function GetBLOQUEADOValue: Integer; procedure SetBLOQUEADOValue(const aValue: Integer); function GetMOTIVO_BLOQUEOValue: String; procedure SetMOTIVO_BLOQUEOValue(const aValue: String); function GetRECARGO_EQUIVALENCIAValue: Integer; procedure SetRECARGO_EQUIVALENCIAValue(const aValue: Integer); function GetREGIMEN_IVAValue: String; procedure SetREGIMEN_IVAValue(const aValue: String); function GetID_TIPO_IVAValue: Integer; procedure SetID_TIPO_IVAValue(const aValue: Integer); function GetID_FORMA_PAGOValue: Integer; procedure SetID_FORMA_PAGOValue(const aValue: Integer); function GetTIENDA_WEBValue: Integer; procedure SetTIENDA_WEBValue(const aValue: Integer); function GetDescuentos: IBizClienteDescuentos; procedure SetDescuentos(Value: IBizClienteDescuentos); public procedure IniciarValoresContactoNuevo; override; constructor Create(aDataTable: TDADataTable); override; destructor Destroy; override; property Descuentos: IBizClienteDescuentos read GetDescuentos write SetDescuentos; property ID_AGENTE: Integer read GetID_AGENTEValue write SetID_AGENTEValue; property GRUPO_CLIENTE: String read GetGRUPO_CLIENTEValue write SetGRUPO_CLIENTEValue; property NOMBRE_COMERCIAL: String read GetNOMBRE_COMERCIALValue write SetNOMBRE_COMERCIALValue; property VENCIMIENTO_FACTURAS: Integer read GetVENCIMIENTO_FACTURASValue write SetVENCIMIENTO_FACTURASValue; property BLOQUEADO: Integer read GetBLOQUEADOValue write SetBLOQUEADOValue; property MOTIVO_BLOQUEO: String read GetMOTIVO_BLOQUEOValue write SetMOTIVO_BLOQUEOValue; property RECARGO_EQUIVALENCIA: Integer read GetRECARGO_EQUIVALENCIAValue write SetRECARGO_EQUIVALENCIAValue; property REGIMEN_IVA: String read GetREGIMEN_IVAValue write SetREGIMEN_IVAValue; property ID_TIPO_IVA: Integer read GetID_TIPO_IVAValue write SetID_TIPO_IVAValue; property ID_FORMA_PAGO: Integer read GetID_FORMA_PAGOValue write SetID_FORMA_PAGOValue; property TIENDA_WEB: Integer read GetTIENDA_WEBValue write SetTIENDA_WEBValue; end; TBizProveedor = class(TBizContacto, IBizProveedor) protected function GetDESCUENTOValue: Float; procedure SetDESCUENTOValue(const aValue: Float); function GetREGIMEN_IVAValue: String; procedure SetREGIMEN_IVAValue(const aValue: String); function GetID_TIPO_IVAValue: Integer; procedure SetID_TIPO_IVAValue(const aValue: Integer); function GetTIENDA_WEBValue: Integer; procedure SetTIENDA_WEBValue(const aValue: Integer); function GetID_FORMA_PAGOValue: Integer; procedure SetID_FORMA_PAGOValue(const aValue: Integer); public procedure IniciarValoresContactoNuevo; override; property DESCUENTO: Float read GetDESCUENTOValue write SetDESCUENTOValue; property REGIMEN_IVA: String read GetREGIMEN_IVAValue write SetREGIMEN_IVAValue; property ID_TIPO_IVA: Integer read GetID_TIPO_IVAValue write SetID_TIPO_IVAValue; property ID_FORMA_PAGO: Integer read GetID_FORMA_PAGOValue write SetID_FORMA_PAGOValue; property TIENDA_WEB: Integer read GetTIENDA_WEBValue write SetTIENDA_WEBValue; end; TBizAgente = class(TBizContacto, IBizAgente) protected FComisiones : IBizAgenteComisiones; FComisionesLink : TDADataSource; function GetComisiones: IBizAgenteComisiones; procedure SetComisiones(Value: IBizAgenteComisiones); public procedure IniciarValoresContactoNuevo; override; constructor Create(aDataTable: TDADataTable); override; destructor Destroy; override; property Comisiones: IBizAgenteComisiones read GetComisiones write SetComisiones; end; implementation uses uDataTableUtils, Classes, DateUtils, SysUtils, uDataModuleUsuarios; { TBizContacto } constructor TBizContacto.Create(aDataTable: TDADataTable); begin inherited; FCategoriasLink := TDADataSource.Create(NIL); FCategoriasLink.DataTable := aDataTable; FDatosBancariosLink := TDADataSource.Create(NIL); FDatosBancariosLink.DataTable := aDataTable; FDireccionesLink := TDADataSource.Create(NIL); FDireccionesLink.DataTable := aDataTable; FSeleccionableInterface := TSeleccionable.Create(aDataTable); end; destructor TBizContacto.Destroy; begin FCategorias := NIL; FCategoriasLink.Free; FDatosBancarios := NIL; FDatosBancariosLink.Free; FDirecciones := NIL; FDireccionesLink.Free; FSeleccionableInterface := NIL; inherited; end; function TBizContacto.EsNuevo: Boolean; begin Result := (ID < 0); end; function TBizContacto.GetCategoria: String; begin case ID_CATEGORIA of 1 : Result := 'Cliente'; 2 : Result := 'Proveedor'; 3 : Result := 'Agente'; end; end; function TBizContacto.GetDatosBancarios: IBizContactosDatosBancarios; begin Result := FDatosBancarios; end; function TBizContacto.GetDirecciones: IBizDireccionesContacto; begin Result := FDirecciones; end; procedure TBizContacto.IniciarValoresContactoNuevo; begin // USUARIO := dmUsuarios.LoginInfo.Usuario; end; procedure TBizContacto.OnNewRecord(Sender: TDADataTable); begin inherited; ID := GetRecNo; // -1, -2, -3... IniciarValoresContactoNuevo; end; procedure TBizContacto.SetDatosBancarios(AValue: IBizContactosDatosBancarios); begin FDatosBancarios := AValue; EnlazarMaestroDetalle(FDatosBancariosLink, FDatosBancarios); end; procedure TBizContacto.SetDirecciones(const Value: IBizDireccionesContacto); begin FDirecciones := Value; EnlazarMaestroDetalle(FDireccionesLink, FDirecciones); end; function TBizContacto._GetCategorias: IBizCategoriasContacto; begin Result := FCategorias; end; procedure TBizContacto._SetCategorias(const Value: IBizCategoriasContacto); begin FCategorias := Value; EnlazarMaestroDetalle(FCategoriasLink, FCategorias); end; { TBizCliente } constructor TBizCliente.Create(aDataTable: TDADataTable); begin inherited; FDescuentos := NIL; FDescuentosLink := TDADataSource.Create(NIL); FDescuentosLink.DataTable := aDataTable; end; destructor TBizCliente.Destroy; begin FDescuentos := NIL; FreeAndNIL(FDescuentosLink); inherited; end; function TBizCliente.GetBLOQUEADOValue: Integer; begin result := DataTable.Fields[idx_ClientesBLOQUEADO].AsInteger; end; function TBizCliente.GetDescuentos: IBizClienteDescuentos; begin Result := FDescuentos; end; function TBizCliente.GetGRUPO_CLIENTEValue: String; begin result := DataTable.Fields[idx_ClientesGRUPO_CLIENTE].AsString; end; function TBizCliente.GetID_AGENTEValue: Integer; begin result := DataTable.Fields[idx_ClientesID_AGENTE].AsInteger; end; function TBizCliente.GetID_FORMA_PAGOValue: Integer; begin result := DataTable.Fields[idx_ClientesID_FORMA_PAGO].AsInteger; end; function TBizCliente.GetID_TIPO_IVAValue: Integer; begin result := DataTable.Fields[idx_ClientesID_TIPO_IVA].AsInteger; end; function TBizCliente.GetMOTIVO_BLOQUEOValue: String; begin result := DataTable.Fields[idx_ClientesMOTIVO_BLOQUEO].AsString; end; function TBizCliente.GetNOMBRE_COMERCIALValue: String; begin result := DataTable.Fields[idx_ClientesNOMBRE_COMERCIAL].AsString; end; procedure TBizCliente.SetBLOQUEADOValue(const aValue: Integer); begin DataTable.Fields[idx_ClientesBLOQUEADO].AsInteger := aValue; end; procedure TBizCliente.SetDescuentos(Value: IBizClienteDescuentos); begin FDescuentos := Value; EnlazarMaestroDetalle(FDescuentosLink, FDescuentos); end; procedure TBizCliente.SetGRUPO_CLIENTEValue(const aValue: String); begin DataTable.Fields[idx_ClientesGRUPO_CLIENTE].AsString := aValue; end; procedure TBizCliente.SetID_AGENTEValue(const aValue: Integer); begin DataTable.Fields[idx_ClientesID_AGENTE].AsInteger := aValue; end; procedure TBizCliente.SetID_FORMA_PAGOValue(const aValue: Integer); begin DataTable.Fields[idx_ClientesID_FORMA_PAGO].AsInteger := aValue; end; procedure TBizCliente.SetID_TIPO_IVAValue(const aValue: Integer); begin DataTable.Fields[idx_ClientesID_TIPO_IVA].AsInteger := aValue; end; procedure TBizCliente.SetMOTIVO_BLOQUEOValue(const aValue: String); begin DataTable.Fields[idx_ClientesMOTIVO_BLOQUEO].AsString := aValue; end; procedure TBizCliente.SetNOMBRE_COMERCIALValue(const aValue: String); begin DataTable.Fields[idx_ClientesNOMBRE_COMERCIAL].AsString := aValue; end; function TBizCliente.GetRECARGO_EQUIVALENCIAValue: Integer; begin Result := DataTable.Fields[idx_ClientesRECARGO_EQUIVALENCIA].AsInteger; end; function TBizCliente.GetREGIMEN_IVAValue: String; begin Result := DataTable.Fields[idx_ClientesREGIMEN_IVA].AsString; end; function TBizCliente.GetTIENDA_WEBValue: Integer; begin result := DataTable.Fields[idx_ClientesTIENDA_WEB].AsInteger; end; function TBizCliente.GetVENCIMIENTO_FACTURASValue: Integer; begin result := DataTable.Fields[idx_ClientesVENCIMIENTO_FACTURAS].AsInteger; end; procedure TBizCliente.SetRECARGO_EQUIVALENCIAValue(const aValue: Integer); begin DataTable.Fields[idx_ClientesRECARGO_EQUIVALENCIA].AsInteger := aValue; end; procedure TBizCliente.SetREGIMEN_IVAValue(const aValue: String); begin DataTable.Fields[idx_ClientesREGIMEN_IVA].AsString := aValue; end; procedure TBizCliente.SetTIENDA_WEBValue(const aValue: Integer); begin DataTable.Fields[idx_ClientesTIENDA_WEB].AsInteger := aValue; end; procedure TBizCliente.SetVENCIMIENTO_FACTURASValue(const aValue: Integer); begin DataTable.Fields[idx_ClientesVENCIMIENTO_FACTURAS].AsInteger := aValue; end; procedure TBizCliente.IniciarValoresContactoNuevo; begin inherited; ID_CATEGORIA := CATEGORIA_CLIENTE; VENCIMIENTO_FACTURAS := CLIENTE_DIAS_VENCIMIENTO; BLOQUEADO := 0; RECARGO_EQUIVALENCIA := CLIENTE_RECARGO_EQUIVALENCIA; REGIMEN_IVA := CLIENTE_REGIMEN_IVA; end; { TBizProveedor } function TBizProveedor.GetID_FORMA_PAGOValue: Integer; begin result := DataTable.Fields[idx_ProveedoresID_FORMA_PAGO].AsInteger; end; function TBizProveedor.GetID_TIPO_IVAValue: Integer; begin result := DataTable.Fields[idx_ProveedoresID_TIPO_IVA].AsInteger; end; function TBizProveedor.GetREGIMEN_IVAValue: String; begin result := DataTable.Fields[idx_ProveedoresREGIMEN_IVA].AsString; end; function TBizProveedor.GetTIENDA_WEBValue: Integer; begin result := DataTable.Fields[idx_ProveedoresTIENDA_WEB].AsInteger; end; procedure TBizProveedor.IniciarValoresContactoNuevo; begin inherited; ID_CATEGORIA := CATEGORIA_PROVEEDOR; REGIMEN_IVA := PROVEEDOR_REGIMEN_IVA; end; function TBizProveedor.GetDESCUENTOValue: Float; begin result := DataTable.Fields[idx_ProveedoresDESCUENTO].AsFloat; end; procedure TBizProveedor.SetDESCUENTOValue(const aValue: Float); begin DataTable.Fields[idx_ProveedoresDESCUENTO].AsFloat := aValue; end; procedure TBizProveedor.SetID_FORMA_PAGOValue(const aValue: Integer); begin DataTable.Fields[idx_ProveedoresID_FORMA_PAGO].AsInteger := aValue; end; procedure TBizProveedor.SetID_TIPO_IVAValue(const aValue: Integer); begin DataTable.Fields[idx_ProveedoresID_TIPO_IVA].AsInteger := aValue; end; procedure TBizProveedor.SetREGIMEN_IVAValue(const aValue: String); begin DataTable.Fields[idx_ProveedoresREGIMEN_IVA].AsString := aValue; end; procedure TBizProveedor.SetTIENDA_WEBValue(const aValue: Integer); begin DataTable.Fields[idx_ProveedoresTIENDA_WEB].AsInteger := aValue; end; { TBizAgente } constructor TBizAgente.Create(aDataTable: TDADataTable); begin inherited; FComisiones := NIL; FComisionesLink := TDADataSource.Create(NIL); FComisionesLink.DataTable := aDataTable; end; destructor TBizAgente.Destroy; begin FComisiones := NIL; FComisionesLink.Free; inherited; end; function TBizAgente.GetComisiones: IBizAgenteComisiones; begin Result := FComisiones; end; procedure TBizAgente.IniciarValoresContactoNuevo; begin inherited; ID_CATEGORIA := CATEGORIA_AGENTE; end; procedure TBizAgente.SetComisiones(Value: IBizAgenteComisiones); begin FComisiones := Value; EnlazarMaestroDetalle(FComisionesLink, FComisiones); end; initialization RegisterDataTableRules(BIZ_CLIENT_CONTACTO, TBizContacto); RegisterDataTableRules(BIZ_CLIENT_CLIENTE, TBizCliente); RegisterDataTableRules(BIZ_CLIENT_PROVEEDOR, TBizProveedor); RegisterDataTableRules(BIZ_CLIENT_AGENTE, TBizAgente); finalization end.