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:} 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
  { TsrvAlbaranesCliente }
  TsrvAlbaranesCliente = class(TDARemoteService, IsrvAlbaranesCliente)
    DABINAdapter: TDABINAdapter;
    bpAlbaranesCliente: TDABusinessProcessor;
    bpAlbaranesCliente_Detalles: TDABusinessProcessor;
    schAlbaranesCliente: 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
    { IsrvAlbaranesCliente methods }
    function GetNextAutoInc(const GeneratorName: String): Integer;
    function GenerateReport(const ID: String): Binary;
    function GenerateEtiquetas(const ID: Integer; const withRefCliente: Boolean): Binary;
  end;

implementation

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

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

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

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;

function TsrvAlbaranesCliente.GenerateEtiquetas(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;

function TsrvAlbaranesCliente.GenerateReport(const ID: String): Binary;
var
  AReportGenerator : TRptAlbaranesCliente;
begin
  AReportGenerator := TRptAlbaranesCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarAlbaran(ID);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

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

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

finalization

end.
