unit srvPedidosCliente_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
  { TsrvPedidosProveedor }
  TsrvPedidosCliente = class(TDARemoteService, IsrvPedidosProveedor)
    DABINAdapter: TDABINAdapter;
    bpPedidosCliente: TDABusinessProcessor;
    bpPedidosCliente_Detalles: TDABusinessProcessor;
    schPedidosCliente: 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
    { IsrvPedidosProveedor methods }
    function GetNextAutoInc(const GeneratorName: String): Integer;
    function GenerateReport(const ID: String): Binary;
  end;

implementation

{$R *.dfm}
uses
  Dialogs,
  {Generated:} FactuGES_Invk, uDataModuleServer, uDatabaseUtils,
  schPedidosClienteClient_Intf, uRestriccionesUsuarioUtils,
  uRptPedidosCliente_Server, uBizPedidosClienteServer;

procedure Create_srvPedidosProveedor(out anInstance : IUnknown);
begin
  anInstance := TsrvPedidosCliente.Create(NIL);
end;

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

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

procedure TsrvPedidosCliente.DARemoteServiceCreate(Sender: TObject);
begin
  SessionManager := dmServer.SessionManager;
  bpPedidosCliente.BusinessRulesID := BIZ_SERVER_PEDIDOS_CLIENTE;
end;

function TsrvPedidosCliente.GenerateReport(const ID: String): Binary;
var
  AReportGenerator : TRptPedidosCliente;
begin
  AReportGenerator := TRptPedidosCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarPedido(ID);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

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

initialization
  TROClassFactory.Create('srvPedidosCliente', Create_srvPedidosProveedor, TsrvPedidosProveedor_Invoker);

finalization

end.
