unit uDataModuleEmpleados;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uDataModuleContactos, DB, uDADataTable, uDAScriptingProvider,
  uDACDSDataTable, uDABINAdapter, uRORemoteService,
  uROClient, uROBinMessage, uROWinInetHttpChannel, uBizGruposEmpleado, uROTypes,
  uIDataModuleEmpleados, uBizContactos, uDADesigntimeCall, uIDataModuleFichasEmpleadoReport,
  uDAInterfaces, uDAMemDataTable, uDADataStreamer, uDABin2DataStreamer,
  uDARemoteDataAdapter, uIntegerListUtils;

type
  TDataModuleEmpleados = class(TDataModuleContactos, IDataModuleEmpleados, IDataModuleFichasEmpleadoReport)
    tbl_Empleados: TDAMemDataTable;
    ds_Empleados: TDADataSource;
    tbl_GruposEmpleado: TDAMemDataTable;
    ds_GruposEmpleado: TDADataSource;
  protected
  public
    function GetItem(const ID : Integer) : IBizEmpleado;
    function NewItem : IBizEmpleado;
    function GetItems : IBizEmpleado;
    function GetGruposEmpleado : IBizGrupoEmpleado;

    function DarListaContratosEmpleado : TStringList;

    // Report
    function GetReport(const ListaID: TIntegerList): Binary;
  end;


implementation

{$R *.dfm}

uses
  FactuGES_Intf, cxControls, schContactosClient_Intf, uDataTableUtils,
  uStringsUtils;

{ TDataModuleVendedores }

function TDataModuleEmpleados.DarListaContratosEmpleado: TStringList;
begin
  Result := TStringList.Create;
  StringToStrings((RORemoteService as IsrvContactos).DarListaContratosEmpleados, '|', Result);
end;

function TDataModuleEmpleados.GetGruposEmpleado: IBizGrupoEmpleado;
var
  AGrupoEmpleado : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    AGrupoEmpleado := CloneDataTable(tbl_GruposEmpleado);
    AGrupoEmpleado.BusinessRulesID := BIZ_CLIENT_GRUPOSEMPLEADO;
    Result := (AGrupoEmpleado as IBizGrupoEmpleado);
  finally
    HideHourglassCursor;
  end;
end;

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

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

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

  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleEmpleados.GetItems: IBizEmpleado;
var
  AContacto : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    AContacto := CloneDataTable(tbl_Empleados);
    AContacto.BusinessRulesID := BIZ_CLIENT_EMPLEADO;

    with TBizEmpleado(AContacto.BusinessEventsObj) do
    begin
      DatosBancarios := _GetDatosBancarios;
    end;

    Result := (AContacto as IBizEmpleado);
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleEmpleados.GetReport(const ListaID: TIntegerList): Binary;
var
  AParam : TIntegerArray;
begin
  AParam := ListaID.ToIntegerArray;
  try
    Result := (RORemoteService as IsrvContactos).GenerarInformeFichaEmpleado(AParam)
  finally
    FreeANDNil(AParam);
  end;
end;

function TDataModuleEmpleados.NewItem: IBizEmpleado;
begin
  Result := GetItem(ID_NULO)
end;

end.
