unit srvEmpresas_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:} DataAbstractService_Impl,
  {Used RODLs:} DataAbstract4_Intf,
  {Generated:} FactuGES_Intf, uDAScriptingProvider, uDABusinessProcessor,
  uDABin2DataStreamer, uDADataStreamer, uDAClasses, uDAInterfaces;

type
  { TsrvEmpresas }
  TsrvEmpresas = class(TDataAbstractService, IsrvEmpresas)
    Diagrams: TDADiagrams;
    DABin2DataStreamer: TDABin2DataStreamer;
    bpEmpresas: TDABusinessProcessor;
    schEmpresas: TDASchema;
    DataDictionary: TDADataDictionary;
    procedure DARemoteServiceCreate(Sender: TObject);
    procedure DataAbstractServiceBeforeAcquireConnection(aSender: TObject;
      var aConnectionName: string);
    procedure DataAbstractServiceBeforeGetDatasetData(aSender: TObject;
      const aDataset: IDADataset; const aIncludeSchema: Boolean;
      const aMaxRecords: Integer);
  private
  protected
    function DarTiendaUsuario(const ID_EMPRESA: Integer; const ID_USUARIO: Integer): Integer;
    function DarListaFormasPago: Binary;
    function DarListaTiposIVA: Binary;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, uDataModuleServer, uRORemoteDataModule,
  uDatabaseUtils, Dialogs, Variants, uROStreamSerializer, uROBinaryHelpers,
  uSesionesUtils, schEmpresasClient_Intf, uUsersManager,
  uRestriccionesUsuarioUtils, srvFormasPago_Impl, srvTiposIva_Impl;

procedure Create_srvEmpresas(out anInstance : IUnknown);
begin
  anInstance := TsrvEmpresas.Create(NIL);
end;

{ srvEmpresas }
procedure TsrvEmpresas.DARemoteServiceCreate(Sender: TObject);
begin
  //SessionManager := dmServer.SessionManager;
end;

function TsrvEmpresas.DarListaFormasPago: Binary;
var
  AFormasPagoServer : TsrvFormasPago;
begin
  AFormasPagoServer := TsrvFormasPago.Create(nil);
  try
    Result := AFormasPagoServer.DarListaFormasPago;
  finally
    FreeAndNIL(AFormasPagoServer);
  end;
end;

function TsrvEmpresas.DarListaTiposIVA: Binary;
var
  ATiposIVAServer : TsrvTiposIVA;
begin
  ATiposIVAServer := TsrvTiposIVA.Create(nil);
  try
    Result := ATiposIVAServer.DarListaTiposIVA;
  finally
    FreeAndNIL(ATiposIVAServer);
  end;
end;

function TsrvEmpresas.DarTiendaUsuario(const ID_EMPRESA, ID_USUARIO: Integer): Integer;
var
  AContactosService : IsrvContactos;
  Intf : IInterface;
begin
  GetClassFactory('srvContactos').CreateInstance(ClientID, Intf);
  AContactosService := Intf as IsrvContactos;
  Result := AContactosService.DarTiendaDeUsuario(ID_EMPRESA, ID_USUARIO)
end;

procedure TsrvEmpresas.DataAbstractServiceBeforeAcquireConnection(
  aSender: TObject; var aConnectionName: string);
begin
  ConnectionName := dmServer.ConnectionName;
end;

procedure TsrvEmpresas.DataAbstractServiceBeforeGetDatasetData(aSender: TObject;
  const aDataset: IDADataset; const aIncludeSchema: Boolean;
  const aMaxRecords: Integer);
begin
  Exit;
  if (aDataset.Name <> nme_EmpresasDatosBanco) then
  begin
    { Aquí se asegura que el usuario sólo accede a las empresas a
      las que tiene permiso para acceder filtrando DataSet por ID_EMPRESA. }
    FiltrarAccesoUsuario(Session, Connection, ServiceSchema, aDataset, fld_EmpresasID);
  end;
end;

initialization
  TROClassFactory.Create('srvEmpresas', Create_srvEmpresas, TsrvEmpresas_Invoker);

finalization

end.
