unit srvRecibosCliente_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, uDADataTable,
  uDACDSDataTable, DB, frxClass, frxDBSet, uDAClasses, uDABINAdapter, uDAInterfaces;

type
  { TsrvRecibosCliente }
  TsrvRecibosCliente = class(TDARemoteService, IsrvRecibosCliente)
    DABINAdapter: TDABINAdapter;
    frxDBCabecera: TfrxDBDataset;
    DADataCabecera: TDADataSource;
    tbl_RecibosCliente: TDACDSDataTable;
    schRecibosCliente: TDASchema;
    frxReport1: TfrxReport;
  private
  protected
    { IsrvRecibosCliente methods }
    function GetNextAutoInc: Integer;
    function GenerateReport(const Codigo: Integer): Binary;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, uDataModuleServer;

procedure Create_srvRecibosCliente(out anInstance : IUnknown);
begin
  anInstance := TsrvRecibosCliente.Create(NIL);
end;

{ srvRecibosCliente }
function TsrvRecibosCliente.GetNextAutoInc: Integer;
begin
  Result := uDataModuleServer.GetNextAutoinc(Connection, 'GEN_RECIBOSCLIENTE');
end;

function TsrvRecibosCliente.GenerateReport(const Codigo: Integer): Binary;
var
  dsMaster: IDADataset;
  AStream: TMemoryStream;
begin
  AStream := TMemoryStream.Create;
  Result := Binary.Create;
  try
    dsMaster := schRecibosCliente.NewDataset(Connection, 'InformeReciboCliente', ['CODIGO'], [Codigo]);

    AStream.Clear;
    ServiceAdapter.WriteDataset(AStream, dsMaster, [woRows, woSchema], -1);
    ServiceAdapter.ReadDataset(AStream, tbl_RecibosCliente, TRUE, '', TRUE, TRUE);

    frxReport1.LoadFromFile(DarRutaInformes + 'InfReciboCliente.fr3', True);
    frxReport1.PrepareReport;
    frxReport1.PreviewPages.SaveToStream(Result);
  finally
    AStream.Free;
  end;
end;

initialization
  TROClassFactory.Create('srvRecibosCliente', Create_srvRecibosCliente, TsrvRecibosCliente_Invoker);

finalization

end.
