unit srvRemesasProveedor_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
  { TsrvRemesasProveedor }
  TsrvRemesasProveedor = class(TDARemoteService, IsrvRemesasProveedor)
    Diagrams: TDADiagrams;
    DABINAdapter: TDABINAdapter;
    bpRemesasProveedor: TDABusinessProcessor;
    schRemesasProveedor: 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
    { IsrvRemesasProveedor methods }
    function GetNextAutoInc(const GeneratorName: String): Integer;
    function GenerateReport(const ID: String): Binary;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, uDataModuleServer,
  uDatabaseUtils, schRemesasProveedorClient_Intf, uRestriccionesUsuarioUtils,
  uBizRemesasProveedorServer, uRptRemesasProveedor_Server, Dialogs;

procedure Create_srvRemesasProveedor(out anInstance : IUnknown);
begin
  anInstance := TsrvRemesasProveedor.Create(NIL);
end;

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

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

procedure TsrvRemesasProveedor.DARemoteServiceCreate(Sender: TObject);
begin
  SessionManager := dmServer.SessionManager;
  bpRemesasProveedor.BusinessRulesID := BIZ_SERVER_REMESAS_PROVEEDOR;  
end;

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

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

initialization
  TROClassFactory.Create('srvRemesasProveedor', Create_srvRemesasProveedor, TsrvRemesasProveedor_Invoker);

finalization

end.
