unit uDataModuleInventario;

interface

uses
  SysUtils, Classes, DB, uDADataTable, uDABINAdapter,
  uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
  uRORemoteService, uROClient, uROBinMessage,
  uDADesigntimeCall, uDataModuleBase,
  uIDataModuleInventario, uBizInventario, uDARemoteDataAdapter, uDADataStreamer,
  uDABin2DataStreamer, uDAInterfaces, uDAMemDataTable;

type
  TDataModuleInventario = class(TDataModuleBase, IDataModuleInventario)
    RORemoteService: TRORemoteService;
    Bin2DataStreamer: TDABin2DataStreamer;
    rda_Inventario: TDARemoteDataAdapter;
    tbl_DetalleReservas: TDAMemDataTable;
    ds_DetalleReservas: TDADataSource;
    tbl_Inventario: TDAMemDataTable;
    ds_Inventario: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);
  public
    function GetItems : IBizInventario; overload;
    function GetItems(const ID_ALMACEN : Integer) : IBizInventario; overload;
    function GetDetalleReservas: IBizDetalleReservas;
    function GetDetalleReservasVacio: IBizDetalleReservas;
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls,
  schInventarioClient_Intf;

{ TdmArticulos }

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

function TDataModuleInventario.GetDetalleReservas: IBizDetalleReservas;
var
  ADetalleReservas : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    ADetalleReservas := CloneDataTable(tbl_DetalleReservas);
    ADetalleReservas.BusinessRulesID := BIZ_CLIENT_DETALLE_RESERVAS_INV;
    Result := (ADetalleReservas as IBizDetalleReservas);
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleInventario.GetDetalleReservasVacio: IBizDetalleReservas;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetDetalleReservas;
    with Result.DataTable.Where do
    begin
      if NotEmpty then
        AddOperator(opAND);

      OpenBraket;
      AddText(fld_DetalleReservasID + ' = ' + IntToStr(ID_NULO));
      CloseBraket;
    end;
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleInventario.GetItems(const ID_ALMACEN: Integer): IBizInventario;
var
  Condicion: TDAWhereExpression;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;

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

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

  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleInventario.GetItems: IBizInventario;
var
  AInventario : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    AInventario := CloneDataTable(tbl_Inventario);
    AInventario.BusinessRulesID := BIZ_CLIENT_INVENTARIO;
    Result := (AInventario as IBizInventario);
  finally
    HideHourglassCursor;
  end;
end;


end.
