unit srvFacturasProveedor_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
  { TsrvFacturasProveedor }
  TsrvFacturasProveedor = class(TDataAbstractService, IsrvFacturasProveedor)
    Diagrams: TDADiagrams;
    bpFacturasProveedor: TDABusinessProcessor;
    bpFacturasProveedor_Detalles: TDABusinessProcessor;
    Bin2DataStreamer: TDABin2DataStreamer;
    bpFacturasProveedor_Contratos: TDABusinessProcessor;
    schFacturasProveedor: TDASchema;
    DataDictionary: TDADataDictionary;
    procedure DARemoteServiceBeforeGetDatasetData(const Dataset: IDADataset;
      const IncludeSchema: Boolean; const MaxRecords: Integer);
    procedure DARemoteServiceCreate(Sender: TObject);
    procedure DataAbstractServiceBeforeAcquireConnection(aSender: TObject;
      var aConnectionName: string);
  protected
    { IsrvFacturasProveedor methods }
    function GenerateReport(const FacturaID: String): Binary;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, Dialogs,
  uDataModuleServer, uDatabaseUtils, uUsersManager, schFacturasProveedorClient_Intf,
  uRestriccionesUsuarioUtils, uBizFacturasProveedorServer;
//  uRptFacturasProveedor_Server;

procedure Create_srvFacturasProveedor(out anInstance : IUnknown);
begin
  anInstance := TsrvFacturasProveedor.Create(NIL);
end;

{ srvFacturasProveedor }

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

procedure TsrvFacturasProveedor.DARemoteServiceCreate(Sender: TObject);
begin
  //SessionManager := dmServer.SessionManager;
  bpFacturasProveedor.BusinessRulesID := BIZ_SERVER_FACTURAS_PROVEEDOR;
end;

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

function TsrvFacturasProveedor.GenerateReport(const FacturaID: String): Binary;
//var
//  AReportGenerator : TRptFacturasProveedor;
begin
  Result := NIL;
{  AReportGenerator := TRptFacturasProveedor.Create(nil);
  try
    Result := AReportGenerator.GenerarFactura(FacturaID);
  finally
    FreeAndNIL(AReportGenerator);
  end;
}
end;


initialization
  TROClassFactory.Create('srvFacturasProveedor', Create_srvFacturasProveedor, TsrvFacturasProveedor_Invoker);

finalization

end.
