unit srvContactos_Impl;

{----------------------------------------------------------------------------}
{ This unit was automatically generated by the RemObjects SDK after reading  }
{ the RODL file associated with this project .                               }
{                                                                            }
{ This is where you are supposed to code the implementation of your objects. }
{----------------------------------------------------------------------------}

interface

uses
  {vcl:} Classes, SysUtils,
  {RemObjects:} uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions,
  {Ancestor Implementation:} DARemoteService_Impl,
  {Used RODLs:} DataAbstract_Intf,
  {Generated:} FactuGES_Intf, uDADataTable, uDABINAdapter, uDAClasses,
  uDAInterfaces, uDAScriptingProvider,
  uDABusinessProcessor;

type
  { TsrvContactos }
  TsrvContactos = class(TDARemoteService, IsrvContactos)
    BINAdapter: TDABINAdapter;
    Diagrams: TDADiagrams;
    bpContactos: TDABusinessProcessor;
    bpDatosBancarios: TDABusinessProcessor;
    bpCategoriasContactos: TDABusinessProcessor;
    bpVendedores: TDABusinessProcessor;
    bpClientes: TDABusinessProcessor;
    bpProveedores: TDABusinessProcessor;
    schContactos: TDASchema;
    DataDictionary: TDADataDictionary;
    procedure DARemoteServiceBeforeAcquireConnection(Sender: TDARemoteService;
      var ConnectionName: string);
    procedure DARemoteServiceBeforeGetDatasetData(const Dataset: IDADataset;
      const IncludeSchema: Boolean; const MaxRecords: Integer);
    procedure DARemoteServiceCreate(Sender: TObject);
  public
    function GetNextAutoInc(const GeneratorName: string): Integer;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, Dialogs, uBizContactosServer,
  uDataModuleServer, uDatabaseUtils, uUsersManager,
  schContactosClient_Intf, uRORemoteDataModule, uBizVendedoresServer,
  uBizClientesServer, uBizProveedoresServer, uRestriccionesUsuarioUtils;

procedure Create_srvContactos(out anInstance : IUnknown);
begin
  anInstance := TsrvContactos.Create(NIL);
end;

{ TsrvContactos }

procedure TsrvContactos.DARemoteServiceBeforeAcquireConnection(
  Sender: TDARemoteService; var ConnectionName: string);
begin
  ConnectionName := dmServer.ConnectionName;
end;

procedure TsrvContactos.DARemoteServiceBeforeGetDatasetData(
  const Dataset: IDADataset; const IncludeSchema: Boolean;
  const MaxRecords: Integer);
begin
  if (DataSet.Name <> nme_DatosBancarios) and
     (DataSet.Name <> nme_ContactosCategorias) then
  begin
    { Aquí se asegura que el usuario sólo accede a presupuestos
      de las empresas a las que tiene permiso para acceder
      filtrando DataSet por ID_EMPRESA. }
    FiltrarAccesoUsuario(Session, Connection, schContactos, DataSet, fld_ContactosID_EMPRESA);
  end;
end;

procedure TsrvContactos.DARemoteServiceCreate(Sender: TObject);
begin
  SessionManager := dmServer.SessionManager;

  bpContactos.BusinessRulesID := BIZ_SERVER_CONTACTO;
  bpVendedores.BusinessRulesID := BIZ_SERVER_VENDEDOR;
  bpClientes.BusinessRulesID := BIZ_SERVER_CLIENTE;
  bpProveedores.BusinessRulesID := BIZ_SERVER_PROVEEDOR;  
end;

function TsrvContactos.GetNextAutoInc(const GeneratorName: string): Integer;
begin
  Result := uDatabaseUtils.GetNextAutoInc(GeneratorName)
end;

initialization
  TROClassFactory.Create('srvContactos', Create_srvContactos, TsrvContactos_Invoker);

finalization

end.
