unit srvAlbaranesProveedor_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
  { TsrvAlbaranesProveedor }
  TsrvAlbaranesProveedor = class(TDARemoteService, IsrvAlbaranesProveedor)
    DABINAdapter: TDABINAdapter;
    bpAlbaranesProveedor: TDABusinessProcessor;
    bpAlbaranesProveedor_Detalles: TDABusinessProcessor;
    schAlbaranesProveedor: 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
    { IsrvAlbaranesProveedor methods }
    function GetNextAutoInc(const GeneratorName: String): Integer;
    function GenerateReport(const ID: String): Binary;
  end;

implementation

{$R *.dfm}
uses
  Dialogs,
  {Generated:} FactuGES_Invk, uDataModuleServer, uDatabaseUtils,
  schAlbaranesProveedorClient_Intf, uRestriccionesUsuarioUtils,
  uBizAlbaranProveedorServer, uRptAlbaranesProveedor_Server;

procedure Create_srvAlbaranesProveedor(out anInstance : IUnknown);
begin
  anInstance := TsrvAlbaranesProveedor.Create(NIL);
end;

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

procedure TsrvAlbaranesProveedor.DARemoteServiceBeforeGetDatasetData(
  const Dataset: IDADataset; const IncludeSchema: Boolean;
  const MaxRecords: Integer);
begin
  if DataSet.Name = nme_AlbaranesProveedor 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, schAlbaranesProveedor, DataSet, fld_AlbaranesProveedorID_EMPRESA);
  end;
end;

procedure TsrvAlbaranesProveedor.DARemoteServiceCreate(Sender: TObject);
begin
  SessionManager := dmServer.SessionManager;
  bpAlbaranesProveedor.BusinessRulesID := BIZ_SERVER_ALBARAN_PROVEEDOR;
end;

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

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

initialization
  TROClassFactory.Create('srvAlbaranesProveedor', Create_srvAlbaranesProveedor, TsrvAlbaranesProveedor_Invoker);

finalization

end.
