unit uDataModuleFormasPago;

interface

uses
  SysUtils, Classes, DB, uDAClientDataModule, uDADataTable, uDABINAdapter,
  uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
  uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
  uDADesigntimeCall,
  uIDataModuleFormasPago, uBizFormasPago, uBizFormasPagoPlazos;

type
  TDataModuleFormasPago = class(TDAClientDataModule, IDataModuleFormasPago)
    RORemoteService: TRORemoteService;
    DABinAdapter: TDABINAdapter;
    DADesigntimeCall1: TDADesigntimeCall;
    LoginRemoteService: TRORemoteService;
    ROWinInetHTTPChannel1: TROWinInetHTTPChannel;
    ROBinMessage1: TROBinMessage;
    tbl_FormasPago: TDACDSDataTable;
    ds_FormasPago: TDADataSource;
    tbl_FormasPagoPlazos: TDACDSDataTable;
    ds_FormasPagoPlazos: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);
  protected
    function DarNombreGenerador(DataSetName: String): String; virtual;
    function _CloneDataTable (const ADataTable : TDACDSDataTable): TDACDSDataTable; overload;
    function _GetPlazos: IBizFormaPagoPlazos;
  public
    function GetItems: IBizFormaPago;
    function GetNextID(const DataSetName : String) : Integer;
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls, uDAInterfaces,
  schFormasPagoClient_Intf;

{ TdmAlmacens }

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

function TDataModuleFormasPago.DarNombreGenerador(DataSetName: String): String;
begin
  Result := '';
  if DataSetName = nme_FormasPago then
    Result := 'GEN_FORMAS_PAGO_ID'
  else
    if DataSetName = nme_FormasPagoPlazos then
      Result := 'GEN_FORMAS_PAGO_PLAZOS_ID';
end;

function TDataModuleFormasPago.GetNextID(const DataSetName: String): Integer;
var
  aGeneratorName : String;
begin
  aGeneratorName := DarNombreGenerador(DataSetName);
  Result := (RORemoteService as IsrvFormasPago).GetNextAutoInc(aGeneratorName)
end;

function TDataModuleFormasPago._CloneDataTable(const ADataTable : TDACDSDataTable): TDACDSDataTable;
begin
  Result := NIL;

  if not Assigned(ADataTable) then
    raise Exception.Create ('No se ha asignado la tabla de origen (CloneDataTable)');

  Result := TDACDSDataTable.Create(NIL);
  CloneDataTable(ADataTable, Result);
end;

function TDataModuleFormasPago._GetPlazos: IBizFormaPagoPlazos;
var
  APlazos : TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    APlazos := _CloneDataTable(tbl_FormasPagoPlazos);
    with APlazos do
    begin
      BusinessRulesID := BIZ_CLIENT_FORMAPAGOPLAZOS;
      DetailOptions := DetailOptions -
        [dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates];
    end;
    Result := (APlazos as IBizFormaPagoPlazos);
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleFormasPago.GetItems: IBizFormaPago;
var
  AFormaPago : TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    AFormaPago := _CloneDataTable(tbl_FormasPago);
    AFormaPago.BusinessRulesID := BIZ_CLIENT_FORMAPAGO;
    with TBizFormaPago(AFormaPago.BusinessEventsObj) do
      Plazos := _GetPlazos;

    Result := (AFormaPago as IBizFormaPago);
  finally
    HideHourglassCursor;
  end;
end;


end.
