unit uDataModuleTraspasos;

interface

uses {vcl:} SysUtils, Classes, DB, DBClient,
     {RemObjects:} uDAClientDataModule, uDADataTable, uDAScriptingProvider,
  uDACDSDataTable, uDABINAdapter, uDataModuleBase, uROClient,
  uROServiceComponent, uRORemoteService, uBizTraspasos;

type
  TdmTraspasos = class(TDAClientDataModule)
    RORemoteService: TRORemoteService;
    tbl_Traspasos: TDACDSDataTable;
    ds_Traspasos: TDADataSource;
    tbl_TraspasosAprobados: TDACDSDataTable;
    ds_TraspasosAprobados: TDADataSource;
    tbl_TraspasosPendientes: TDACDSDataTable;
    ds_TraspasosPendientes: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);
  public
    function GetItems : IBizTraspasos; overload;
    function GetItems(const AEstado : TInvTraspasoEstado) : IBizTraspasos; overload;
  end;

var
  dmTraspasos: TdmTraspasos;

implementation

{$R *.DFM}

uses
  Forms, Windows, Controls, VARELA_Intf, uEditorPreview,
  uDataTableUtils, uROTypes, cxControls, uDAInterfaces;

procedure TdmTraspasos.DAClientDataModuleCreate(Sender: TObject);
begin
  RORemoteService.Channel := dmBase.Channel;
  RORemoteService.Message := dmBase.Message;
end;

function TdmTraspasos.GetItems: IBizTraspasos;
var
  dtLista: TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    dtLista := TDACDSDataTable.Create(NIL);
    CloneDataTable(tbl_Traspasos, dtLista);
    dtLista.BusinessRulesID := BIZ_TRASPASOS;
    Result := (dtLista as IBizTraspasos);
  finally
    HideHourglassCursor;
  end;
end;

function TdmTraspasos.GetItems(
  const AEstado: TInvTraspasoEstado): IBizTraspasos;
var
  dtLista: TDACDSDataTable;
  AStr : String;
begin
  ShowHourglassCursor;
  try
    dtLista := TDACDSDataTable.Create(NIL);

    case AEstado of
      titPendiente : CloneDataTable(tbl_TraspasosPendientes, dtLista);
      titAprobado  : CloneDataTable(tbl_TraspasosAprobados, dtLista);
    end;

    dtLista.BusinessRulesID := BIZ_TRASPASOS;
    Result := (dtLista as IBizTraspasos);
  finally
    HideHourglassCursor;
  end;
end;

initialization
  dmTraspasos := TdmTraspasos.Create(nil);

finalization
  FreeAndNil(dmTraspasos);

end.
