unit srvInfMargenArticulo_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, uDAClasses,
  uDataModuleServer, uDAInterfaces, uDADataTable, uDABINAdapter;

type
  { TsrvInfMargenArticulo }
  TsrvInfMargenArticulo = class(TDARemoteService, IsrvInfMargenArticulo)
    DABINAdapter: TDABINAdapter;
    schInfMargenArticulo: TDASchema;
    DataDictionary: TDADataDictionary;
  private
  protected
    { IsrvInfMargenArticulo methods }
    function GetData(const DatasetName: String; const MaxRecords: Integer; const Columns: String; const Params: TDADatasetParamArray): Binary;
    function GetSchema(const DatasetName: String; const Columns: String): Binary;
  end;

implementation

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

const
  CAMPOS_AVG1 = '#IMP_NETO_ULT_VENT#IMP_NETO_PRO_VENT#IMP_PORTE_PRO_VENT#IMP_NETO_COMPRA#IMP_NETO_ULT_COMP#IMP_NETO_PRO_COMP#IMP_UNIDAD_PRO_COMP#IMP_PORTE_PRO_COMP#IMP_MARGEN_ULT_VENT_COMPRA#POR_MARGEN_ULT_VENT_COMPRA#IMP_MARGEN_ULT_VENT_ULT_COMP#';
  CAMPOS_AVG2 = '#POR_MARGEN_ULT_VENT_ULT_COMP#IMP_MARGEN_ULT_VENT_PRO_COMP#POR_MARGEN_ULT_VENT_PRO_COMP#IMP_MARGEN_PRO_VENT_COMPRA#POR_MARGEN_PRO_VENT_COMPRA#IMP_MARGEN_PRO_VENT_ULT_COMP#POR_MARGEN_PRO_VENT_ULT_COMP#IMP_MARGEN_PRO_VENT_PRO_COMP#';
  CAMPOS_AVG3 = '#POR_MARGEN_PRO_VENT_PRO_COMP#IMP_UNIDAD_PRO_VENT#';

  CAMPOS_SUMA = '';


procedure Create_srv_InfMargenArticulo(out anInstance : IUnknown);
begin
  anInstance := TsrvInfMargenArticulo.Create(NIL);
end;

{ srvInfMargenArticulo }

function TsrvInfMargenArticulo.GetData(const DatasetName: String;
  const MaxRecords: Integer; const Columns: String;
  const Params: TDADatasetParamArray): TROBinaryMemoryStream;
var
  ds : IDADataset;
  i : integer;
begin
  result := Binary.Create;
  try
    { Prepares the parameter arrays}

    with TReplicarDataSet.Create do
    begin
      SourceDataSetName := DatasetName;
      Service := Self;
      Columnas := Columns;
      ColumnasQueSuman := CAMPOS_SUMA;
      ColumnasQueAVG := CAMPOS_AVG1 + CAMPOS_AVG2 + CAMPOS_AVG3;
      try
        ds := GetNewDataSet;
      finally
        Free;
      end;
    end;

    for i := 0 to (Params.Count-1) do
      ds.ParamByName(Params[i].Name).Value := Params[i].Value;

    ds.Open;
    ServiceAdapter.WriteDataset(Result, ds, [woRows], MaxRecords);
  except
    FreeAndNIl(result);
    raise;
  end;
end;

function TsrvInfMargenArticulo.GetSchema(const DatasetName: String; const Columns: String): TROBinaryMemoryStream;
var
  ds : IDADataset;
begin
  result := Binary.Create;
  try
    with TReplicarDataSet.Create do
    begin
      SourceDataSetName := DatasetName;
      Service := Self;
      Columnas := Columns;
      ColumnasQueSuman := CAMPOS_SUMA;
      try
        ds := GetNewDataSet;
      finally
        Free;
      end;
    end;
    ServiceAdapter.WriteDataset(result, ds, [woSchema]);
  except
    FreeAndNIl(result);
    raise;
  end;
end;


initialization
  TROClassFactory.Create('srvInfMargenArticulo', Create_srv_InfMargenArticulo, TsrvInfMargenArticulo_Invoker);

finalization

end.
