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:} DataAbstractService_Impl,
  {Used RODLs:} DataAbstract4_Intf,
  {Generated:}   uDABusinessProcessor, uDABin2DataStreamer, uDADataStreamer,
  uDAScriptingProvider, uDAClasses,
  FactuGES_Intf, uDAInterfaces;

type
  { TsrvPedidosCliente }
  TsrvPedidosCliente = class(TDataAbstractService, IsrvPedidosCliente)
    bpPedidosCliente: TDABusinessProcessor;
    bpPedidosCliente_Detalles: TDABusinessProcessor;
    Bin2DataStreamer: TDABin2DataStreamer;
    schPedidosCliente: TDASchema;
    DADataDictionary: TDADataDictionary;
    procedure DARemoteServiceBeforeGetDatasetData(const Dataset: IDADataset;
      const IncludeSchema: Boolean; const MaxRecords: Integer);
    procedure DARemoteServiceCreate(Sender: TObject);
    procedure DataAbstractServiceBeforeAcquireConnection(aSender: TObject;
      var aConnectionName: string);
  protected
    { IsrvPedidosCliente methods }
    function GenerarInforme(const ListaID: TIntegerArray;
      const ImprimirPrecio: Boolean; const ImprimirRefProveedor: Boolean): Binary;
    function GenerarInformeEnPDF(const ListaID: TIntegerArray;
      const ImprimirPrecio: Boolean; const ImprimirRefProveedor: Boolean): Binary;
  end;

implementation

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

{  uRORemoteDataModule,
  fServerForm, Variants, IB,
}
procedure Create_srvPedidosCliente(out anInstance : IUnknown);
begin
  anInstance := TsrvPedidosCliente.Create(NIL);
end;

{ srvPedidosCliente }

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;

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

function TsrvPedidosCliente.GenerarInforme(const ListaID: TIntegerArray;
  const ImprimirPrecio: Boolean; const ImprimirRefProveedor: Boolean): Binary;
var
  AReportGenerator : TRptPedidosCliente;
begin
  AReportGenerator := TRptPedidosCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarPedido(ListaID,
      ImprimirPrecio, ImprimirRefProveedor);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

function TsrvPedidosCliente.GenerarInformeEnPDF(
  const ListaID: TIntegerArray;
  const ImprimirPrecio: Boolean; const ImprimirRefProveedor: Boolean): Binary;
var
  AReportGenerator : TRptPedidosCliente;
begin
  AReportGenerator := TRptPedidosCliente.Create(nil);
  try
    Result := AReportGenerator.GenerarPedidoEnPDF(ListaID,
      ImprimirPrecio, ImprimirRefProveedor);
  finally
    FreeAndNIL(AReportGenerator);
  end;
end;

initialization
  TROClassFactory.Create('srvPedidosCliente', Create_srvPedidosCliente, TsrvPedidosCliente_Invoker);

finalization

end.
