unit srvRemesasCliente_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,
  uDAScriptingProvider, uDABusinessProcessor, uDAInterfaces;

type
  { TsrvRemesasCliente }
  TsrvRemesasCliente = class(TDARemoteService, IsrvRemesasCliente)
    Diagrams: TDADiagrams;
    DABINAdapter: TDABINAdapter;
    bpRemesasCliente: TDABusinessProcessor;
    schRemesasCliente: TDASchema;
    DataDictionary: TDADataDictionary;
    procedure DARemoteServiceBeforeAcquireConnection(Sender: TDARemoteService;
      var ConnectionName: string);
    procedure DARemoteServiceCreate(Sender: TObject);
    procedure DARemoteServiceBeforeGetDatasetData(const Dataset: IDADataset;
      const IncludeSchema: Boolean; const MaxRecords: Integer);
  private
  protected
    { IsrvRemesasCliente methods }
    function GetNextAutoInc(const GeneratorName: String): Integer;
    function GenerateReport(const ID: String): Binary;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, uDataModuleServer,
  uDatabaseUtils, schRemesasClienteClient_Intf, uRestriccionesUsuarioUtils,
  uBizRemesasClienteServer, uRptRemesasCliente_Server, Dialogs;

procedure Create_srvRemesasCliente(out anInstance : IUnknown);
begin
  anInstance := TsrvRemesasCliente.Create(NIL);
end;

{ srvRemesasCliente }
procedure TsrvRemesasCliente.DARemoteServiceBeforeAcquireConnection(
  Sender: TDARemoteService; var ConnectionName: string);
begin
  ConnectionName := dmServer.ConnectionName;
end;

procedure TsrvRemesasCliente.DARemoteServiceBeforeGetDatasetData(
  const Dataset: IDADataset; const IncludeSchema: Boolean;
  const MaxRecords: Integer);
begin
  if DataSet.Name = nme_RemesasCliente then
  begin
    { Aquí se asegura que el usuario sólo accede a los RemesasCliente
      de las empresas a las que tiene permiso para acceder
      filtrando DataSet por ID_EMPRESA. }
    FiltrarAccesoUsuario(Session, Connection, schRemesasCliente, DataSet, fld_RemesasClienteID_EMPRESA);
  end;
end;

procedure TsrvRemesasCliente.DARemoteServiceCreate(Sender: TObject);
begin
  SessionManager := dmServer.SessionManager;
  bpRemesasCliente.BusinessRulesID := BIZ_SERVER_REMESAS_CLIENTE;  
end;

function TsrvRemesasCliente.GenerateReport(const ID: String): Binary;
var
  AReportGenerator : TRptRemesasCliente;
begin
  AReportGenerator := TRptRemesasCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarRemesa(ID);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

function TsrvRemesasCliente.GetNextAutoInc(const GeneratorName: String): Integer;
begin
  Result := uDatabaseUtils.GetNextAutoInc(GeneratorName)
end;

initialization
  TROClassFactory.Create('srvRemesasCliente', Create_srvRemesasCliente, TsrvRemesasCliente_Invoker);

finalization

end.
