unit uDataModuleRemesasProveedor;

interface

uses
  SysUtils, Classes, DB, uDAClientDataModule, uDADataTable, uDABINAdapter,
  uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
  uRORemoteService, uROClient, uROBinMessage,
  uDADesigntimeCall, uDataModuleBase,
  uIDataModuleRemesasProveedor, uIDataModuleRemesasProveedorReport, uBizRemesasProveedor,
  uDARemoteDataAdapter, uDADataStreamer, uDABin2DataStreamer, uDAInterfaces,
  uDAMemDataTable;

type
  TDataModuleRemesasProveedor = class(TDataModuleBase, IDataModuleRemesasProveedor, IDataModuleRemesasProveedorReport)
    RORemoteService: TRORemoteService;
    Bin2DataStreamer: TDABin2DataStreamer;
    rda_RemesasProveedor: TDARemoteDataAdapter;
    tbl_RemesasProveedor: TDAMemDataTable;
    ds_RemesasProveedor: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);

  protected
    procedure AsignarClaseNegocio(var ARemesaProveedor: TDAMemDataTable); virtual;

  public
    function GetItems : IBizRemesaProveedor; overload;
    function GetItem(const ID : Integer) : IBizRemesaProveedor;
    function NewItem : IBizRemesaProveedor;

    // Report
    function GetReport(const ID: String): Binary;
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls, 
  schRemesasProveedorClient_Intf, Dialogs;

{ TdmRemesasProveedor }

procedure TDataModuleRemesasProveedor.AsignarClaseNegocio(var ARemesaProveedor: TDAMemDataTable);
begin
  ARemesaProveedor.BusinessRulesID := BIZ_CLIENT_REMESAPROVEEDOR;
end;

procedure TDataModuleRemesasProveedor.DAClientDataModuleCreate(Sender: TObject);
begin
  RORemoteService.Channel := dmConexion.Channel;
  RORemoteService.Message := dmConexion.Message;
end;


function TDataModuleRemesasProveedor.GetReport(const ID: String): Binary;
begin
//  Result := (RORemoteService as IsrvRemesasProveedor).GenerateReport(ID);
end;

function TDataModuleRemesasProveedor.NewItem: IBizRemesaProveedor;
begin
  Result := GetItem(ID_NULO)
end;

function TDataModuleRemesasProveedor.GetItem(const ID: Integer): IBizRemesaProveedor;
var
  Condicion: TDAWhereExpression;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;

    with Result.DataTable.DynamicWhere do
    begin
      // (ID = :ID)
      Condicion := NewBinaryExpression(NewField('', fld_RemesasProveedorID), NewConstant(ID, datInteger), dboEqual);

      if IsEmpty then
         Expression := Condicion
      else
         Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
    end;

  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleRemesasProveedor.GetItems: IBizRemesaProveedor;
var
  ARemesaProveedor : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    ARemesaProveedor := CloneDataTable(tbl_RemesasProveedor);
    AsignarClaseNegocio(ARemesaProveedor);
    
    // EL CAMPO REFERENCIA TIENE QUE SER AUTOREFRESH!!!!!
    ARemesaProveedor.FieldByName(fld_RemesasProveedorREFERENCIA).ServerAutoRefresh := TRUE;
    ARemesaProveedor.FieldByName(fld_RemesasProveedorIMPORTE_TOTAL).ServerAutoRefresh := TRUE;

    Result := (ARemesaProveedor as IBizRemesaProveedor);
  finally
    HideHourglassCursor;
  end;
end;


end.
