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:} DARemoteService_Impl,
  {Used RODLs:} DataAbstract_Intf,
  {Generated:} FactuGES_Intf, uDAScriptingProvider, uDABusinessProcessor,
  uDAClasses, uDADataTable, uDABINAdapter,

  uDACDSDataTable, uDAInterfaces, DB,
  frxClass, frxDBSet,  frxDCtrl, frxDMPExport, frxGradient,
  frxChBox, frxCross, frxRich, frxChart, frxOLE, frxBarcode;

type
  { TsrvRecibosProveedor }
  TsrvRecibosCliente = class(TDARemoteService, IsrvRecibosCliente)
    DABINAdapter: TDABINAdapter;
    bpRecibosCliente: TDABusinessProcessor;
    bpPagosCliente: TDABusinessProcessor;
    bpRecibosCompensados: TDABusinessProcessor;
    schRecibosCliente: TDASchema;
    DADataDictionary: TDADataDictionary;
    procedure DARemoteServiceBeforeAcquireConnection(Sender: TDARemoteService;
      var ConnectionName: string);
    procedure DARemoteServiceBeforeGetDatasetData(const Dataset: IDADataset;
      const IncludeSchema: Boolean; const MaxRecords: Integer);
    procedure DARemoteServiceCreate(Sender: TObject);
  private
  protected
    { IsrvRecibosProveedor methods }
    function GetNextAutoInc(const GeneratorName: String): Integer;
    function GenerateReport(const ID: String): Binary;
  end;

implementation

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

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

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

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;
end;

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

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

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

finalization

end.
