unit srvAlbaranesCliente_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
  { TsrvAlbaranesCliente }
  TsrvAlbaranesCliente = class(TDataAbstractService, IsrvAlbaranesCliente)
    bpAlbaranesCliente: TDABusinessProcessor;
    bpAlbaranesCliente_Detalles: TDABusinessProcessor;
    Bin2DataStreamer: TDABin2DataStreamer;
    schAlbaranesCliente: 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
    { IsrvAlbaranesCliente methods }
    function GenerarInforme(const ListaID: TIntegerArray; const VerPrecios: Boolean): Binary;
    function GenerarInformeEtiquetas(const ID: Integer; const withRefCliente: Boolean): Binary;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, uDataModuleServer, uDatabaseUtils,
  schAlbaranesClienteClient_Intf, uRestriccionesUsuarioUtils,
  uRptAlbaranesCliente_Server, uBizAlbaranClienteServer;

const
  REF_ALBARANES_CLIENTE = 'REF_ALBARANES_CLIENTE';
  REF_ALBARANES_DEV_CLIENTE = 'REF_ALBARANES_DEV_CLIENTE';



procedure Create_srvAlbaranesCliente(out anInstance : IUnknown);
begin
  anInstance := TsrvAlbaranesCliente.Create(NIL);
end;

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

procedure TsrvAlbaranesCliente.DARemoteServiceCreate(Sender: TObject);
begin
  //SessionManager := dmServer.SessionManager;
  bpAlbaranesCliente.BusinessRulesID := BIZ_SERVER_ALBARAN_CLIENTE;
end;

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

function TsrvAlbaranesCliente.GenerarInforme(const ListaID: TIntegerArray; const VerPrecios: Boolean): Binary;
var
  AReportGenerator : TRptAlbaranesCliente;
begin
  AReportGenerator := TRptAlbaranesCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarAlbaran(ListaID, VerPrecios);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

function TsrvAlbaranesCliente.GenerarInformeEtiquetas(const ID: Integer;
  const withRefCliente: Boolean): Binary;
var
  AReportGenerator : TRptAlbaranesCliente;
begin
  AReportGenerator := TRptAlbaranesCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarEtiquetas(ID, withRefCliente);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

initialization
  TROClassFactory.Create('srvAlbaranesCliente', Create_srvAlbaranesCliente, TsrvAlbaranesCliente_Invoker);

finalization

end.
