unit srvRecibosCliente_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
  { TsrvRecibosProveedor }
  TsrvRecibosCliente = class(TDataAbstractService, IsrvRecibosCliente)
    bpRecibosCliente: TDABusinessProcessor;
    bpPagosCliente: TDABusinessProcessor;
    bpRecibosCompensados: TDABusinessProcessor;
    Bin2DataStreamer: TDABin2DataStreamer;
    schRecibosCliente: 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);
  private
  protected
    { IsrvRecibosProveedor methods }
    function GenerateReport(const ListaID: TIntegerArray): Binary;
  end;

implementation

{$R *.dfm}
uses
  Dialogs,
  {Generated:} FactuGES_Invk, uDataModuleServer, uDatabaseUtils,
  schRecibosClienteClient_Intf, uRestriccionesUsuarioUtils, uBizRecibosClienteServer,
  uBizPagosClienteServer,
  uRptRecibosCliente_Server;


procedure Create_srvRecibosCliente(out anInstance : IUnknown);
begin
  anInstance := TsrvRecibosCliente.Create(NIL);
end;

{ srvRecibosProveedor }

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

procedure TsrvRecibosCliente.DARemoteServiceCreate(Sender: TObject);
begin
  SessionManager := dmServer.SessionManager;
  bpRecibosCliente.BusinessRulesID := BIZ_SERVER_RECIBOS_CLIENTE;
  bpPagosCliente.BusinessRulesID := BIZ_SERVER_PAGOS_CLIENTE;
end;

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

function TsrvRecibosCliente.GenerateReport(const ListaID: TIntegerArray): Binary;
var
  AReportGenerator : TRptRecibosCliente;
begin
  AReportGenerator := TRptRecibosCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarRecibo(ListaID);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

initialization
  TROClassFactory.Create('srvRecibosCliente', Create_srvRecibosCliente, TsrvRecibosCliente_Invoker);

finalization

end.
