unit srvContratosCliente_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:}   uDABusinessProcessor, uDABin2DataStreamer, uDADataStreamer,
  uDAScriptingProvider, uDAClasses,
  FactuGES_Intf, uDAInterfaces;

type
  { TsrvContratosCliente }
  TsrvContratosCliente = class(TDataAbstractService, IsrvContratosCliente)
    Bin2DataStreamer: TDABin2DataStreamer;
    bpContratosCliente: TDABusinessProcessor;
    bpContratosClienteDetalles: TDABusinessProcessor;
    schContratosCliente: TDASchema;
    DADataDictionary: TDADataDictionary;
    procedure DataAbstractServiceBeforeAcquireConnection(aSender: TObject;
      var aConnectionName: string);
    procedure DARemoteServiceBeforeGetDatasetData(const Dataset: IDADataset;
      const IncludeSchema: Boolean; const MaxRecords: Integer);
    procedure DARemoteServiceCreate(Sender: TObject);
  protected
    { IsrvContratosCliente methods }
    function GenerarInforme(const ListaID: TIntegerArray; const VerCondiciones: Boolean; const TamLetra: Integer): Binary;
    function GenerarInformeEnPDF(const ListaID: TIntegerArray; const VerCondiciones: Boolean; const Usuario: AnsiString; const Firmado: Boolean): Binary;
  end;

implementation

{$R *.dfm}
uses
  Dialogs, uSistemaFunc, uROClasses,
  {Generated:} FactuGES_Invk, uDataModuleServer, uDatabaseUtils,
  schContratosClienteClient_Intf, uRestriccionesUsuarioUtils,
  uRptContratosCliente_Server, uBizContratosClienteServer;

procedure Create_srvContratosCliente(out anInstance : IUnknown);
begin
  anInstance := TsrvContratosCliente.Create(NIL);
end;

{ srvContratosCliente }

procedure TsrvContratosCliente.DARemoteServiceBeforeGetDatasetData(
  const Dataset: IDADataset; const IncludeSchema: Boolean;
  const MaxRecords: Integer);
begin
  if DataSet.Name = nme_ContratosCliente 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, schContratosCliente, DataSet, fld_ContratosClienteID_EMPRESA);
  end;
end;

procedure TsrvContratosCliente.DARemoteServiceCreate(Sender: TObject);
begin
  //SessionManager := dmServer.SessionManager;
  bpContratosCliente.BusinessRulesID := BIZ_SERVER_CONTRATOS_CLIENTE;
end;

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

function TsrvContratosCliente.GenerarInforme(const ListaID: TIntegerArray; const VerCondiciones: Boolean; const TamLetra: Integer): Binary;
var
  AReportGenerator : TRptContratosCliente;
begin
  AReportGenerator := TRptContratosCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarContrato(ListaID, VerCondiciones, TamLetra);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

function TsrvContratosCliente.GenerarInformeEnPDF(const ListaID: TIntegerArray; const VerCondiciones: Boolean; const Usuario: AnsiString; const Firmado: Boolean): Binary;
var
  AReportGenerator : TRptContratosCliente;
begin
  AReportGenerator := TRptContratosCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarContratoEnPDF(ListaID, VerCondiciones, Usuario, Firmado);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

initialization
  TROClassFactory.Create('srvContratosCliente', Create_srvContratosCliente, TsrvContratosCliente_Invoker);

finalization

end.
