/**
   * Obtiene los numeros de telefono movil de otros bancos que se encuentren registrados en el
   * perfil del cliente y que tengan estatus activo, ademas de las cuentas propias y saldos para
   * iniciar el flujo de transferencias a otros bancos.
   *
   * @param req HttpServletRequest
   * @param resp HttpServletResponse
   * @return ModelAndView
   * @throws Exception la exception
   */
  public ModelAndView getMovilesOtrosBancos(HttpServletRequest req, HttpServletResponse resp)
      throws Exception {
    JSONResponseBean response = new JSONResponseBean();
    ClienteBean cliente = (ClienteBean) req.getSession().getAttribute(LITERAL_CLIENTE);

    if (cliente != null) {
      try {
        BitacoraBean bitacora = getBitacoraBean(req, cliente.getClaveCliente());
        JSONObject getAllJSON = getJSONRequestObject(req);
        boolean getAll = false;

        try {
          getAll = getAllJSON.getBoolean("getAll");
        } catch (JSONException e) {
          LOG.info(
              "El JSON no contienen el atributo getAll, se trata transferencia como Operacion Rapida: "
                  .concat(e.getMessage()));
        }

        JSONObject jsonResponse = new JSONObject();
        List<NumeroMovilRegistrado> asociaciones =
            movilTercerosService.getMovilesTercerosActivos(
                cliente,
                SantanderConstantesMovilService.TIPO_CUENTA_MOVIL_INTERBANCARIA,
                SantanderConstantesMovilService.TTMO);
        jsonResponse.put("movilesTerceros", asociaciones);

        if (getAll) {
          List<CuentaBean> cuentas = cuentaService.getCuentasPropiasCheques(cliente);
          JSONArray jSONCuentas = JSONArray.fromObject(cuentas);
          jsonResponse.put("cuentas", jSONCuentas.toString());

          SaldoContainerBean saldoCheques =
              saldoService.getSaldosCuentasChequeras(cliente, bitacora, false);
          JSONObject jSONSaldoCheques = JSONObject.fromObject(saldoCheques);
          jsonResponse.put("saldos", jSONSaldoCheques.toString());
        }

        response.setDto(jsonResponse.toString());
        response.setError(ErrorBean.SUCCESS);
        req.getSession().setAttribute(SALTOSUCCESS, LITERAL_0_01);
      } catch (BusinessException e) {
        response.setError(e.getError());
      }
    } else {
      response.setError(LITERAL_GBL_03);
    }

    return getResponseView(response);
  }
  /**
   * Metodo que obtiene los movimientos realizados por cada cuenta o chequera del cliente.
   *
   * @param cliente Bean del Cliente
   * @param datosMovimientos Bean de los datos con mivimeintos
   * @param bitacoraBean Bean de bitacora
   * @return MovimientosBean Bean con los movimientos
   * @author Igor Mejia
   * @throws ParseException Excepxion al parsear
   * @throws BusinessException Excepcion de negocio
   */
  public MovimientosBean getMovimientoCuentasChequeras(
      ClienteBean cliente, DatosConsultaMovimientosBean datosMovimientos, BitacoraBean bitacoraBean)
      throws BusinessException, ParseException {

    boolean autorizadoPesos = false;
    boolean autorizadoDolares = false;

    Validator.valida(cliente, CLAVE_MODULO_MOVIMIENTO_CUENTA);
    log.debug("*****************ENTRO A MOVIMIENTOS CUENTAS CHEQUERAS************");
    if (cliente == null) {
      throw new BusinessException("MOVIMIENTOS");
    }
    Iterator itera = (Iterator) cuentaService.getCuentasPropias(cliente).iterator();
    while (itera.hasNext()) {
      CuentaBean cuenta = (CuentaBean) itera.next();
      String cuentaVista =
          MovimientosServiceReusableFunctions.getCuentaVista(
              cliente.getClaveCliente(),
              cuenta.getNumeroCuenta(),
              cuenta.getSucursal(),
              NOMBRE_CALSE);
      if (cuenta.getNumeroCuenta().equalsIgnoreCase(datosMovimientos.getCuenta())
          || datosMovimientos.getCuenta().equalsIgnoreCase(cuentaVista)) {
        autorizadoPesos = true;
        break;
      }
    }
    if (cliente.isDolares()) {
      Iterator iter = (Iterator) cuentaService.getCuentasPropiasDolares(cliente).iterator();

      while (iter.hasNext()) {
        CuentaBean cuentaDolares = (CuentaBean) iter.next();
        String cuentaVistaDolares =
            MovimientosServiceReusableFunctions.getCuentaVista(
                cliente.getClaveCliente(),
                cuentaDolares.getNumeroCuenta(),
                cuentaDolares.getSucursal(),
                NOMBRE_CALSE);

        if (!cuentaDolares.getNumeroCuenta().equalsIgnoreCase(datosMovimientos.getCuenta())
            && datosMovimientos.getCuenta().equalsIgnoreCase(cuentaVistaDolares)) {
          autorizadoDolares = true;
          break;
        }
      }
    }

    if (!autorizadoPesos && !autorizadoDolares) {
      if (datosMovimientos.getTipoCuenta().equals(TIPO_CUENTA_VISTA)) {
        throw new BusinessException("MOVC-MCC-1");
      } else throw new BusinessException("MOVC-MCC-1");
    }

    SantanderReferenciaService referencia =
        commonService.getReferencia(bitacoraBean.getNombreClase());

    MovimientosBean movimientosBean =
        obtenerMovimientosCheques(
            datosMovimientos,
            cliente.getClaveCliente(),
            String.valueOf(referencia.getNumReferencia()),
            bitacoraBean.getNombreClase());

    if (movimientosBean.getListaMovimientos() == null
        && movimientosBean.getMensajeStatus() == null
        && movimientosBean.getImporte() == null) {

      throw new BusinessException("MOVIMIENTOS");
    }

    String mensaje =
        SantanderConstantesService.MOVC + movimientosBean.getMensajeStatus().substring(4);

    bitacoraBean.setNumeroReferencia(referencia.getNumReferencia());
    bitacoraBean.setNumeroCuenta(datosMovimientos.getCuenta());
    bitacoraBean.setImporte(movimientosBean.getImporte());
    bitacoraBean.setClaveUsuario(cliente.getClaveCliente());
    bitacoraBean.setMensaje(mensaje);
    bitacoraBean.setClaveConcepto(SantanderConstantesService.CMCHEQUES);
    commonService.registrarBitacora(bitacoraBean);

    return movimientosBean;
  }