Example #1
0
  // 'Luis Gachuz, 29/Mar/2003
  // 'Modificaciòn para recibir el nuevo paràmetro ic_Trad
  public final RespuestaFondosVO calculaMontoFondos(
      final ParFondosVO fondosVO, final SantanderSecurityContext sc) throws Exception {
    /*
     * '15032002 GSP.
     * Calcula el monto de la operación si se proporcionan los títulos
     * 'Se regresa una cadena con el monto calculado
     */

    String rateCode = "";
    String strCountry = "";
    String strFundPrice = "";
    String icCon = "";
    String branch = "";
    String ctaContrato = "";
    String user = "";
    String vatrate = "";
    double dblComision = 0.0;
    double dblIva = 0.0;
    double dblMontoBruto = 0.0;
    double dblMontoNeto = 0.0;
    double dblCalcQty = 0.0;
    ValidaContratoVO contratoVO = new ValidaContratoVO();
    RespuestaFondosVO clientInformationVO = new RespuestaFondosVO();
    RespuestaFondosVO issuingVO = new RespuestaFondosVO();
    RespuestaFondosVO commRateVO = new RespuestaFondosVO();
    RespuestaFondosVO respFondosVO = new RespuestaFondosVO();

    /*
     * Se llama al método de validaContrato para obtener
     * valores que se necesitan
     * pasar como parametros para otros metodos.
     */
    branch = fondosVO.getBranch();
    ctaContrato = fondosVO.getContrato();
    user = sc.getPrivilegiosUsuario().getTrad();

    contratoVO = commonDAO.validaContrato(branch, ctaContrato, user);

    icCon = contratoVO.getCno();

    /*===================================================================*/
    /*             Obtenemos la información del cliente.                 */
    /*===================================================================*/
    clientInformationVO = capturaFondosDAO.readClientInformation(icCon.trim());
    if (clientInformationVO != null) {
      if (clientInformationVO.getStatus() != 0) {
        respFondosVO.setError(String.valueOf(clientInformationVO.getStatus()));
        if (!fondosVO.isBlError()) {
          return respFondosVO;
        }
      }
    } else {
      respFondosVO.setError(
          "Error al ejecutar el Store Procedure:" + "\n" + "SPS_READ_CLIENT_INFORMATION. ");
      if (!fondosVO.isBlError()) {
        return respFondosVO;
      }
    }

    log.debug("clientInformationVO[0]" + clientInformationVO.getStrClientInfo()[0]);
    log.debug("clientInformationVO[1]" + clientInformationVO.getStrClientInfo()[1]);

    /*===================================================================*/
    /*         Obtenemos la ciudad a la que corresponde el branch.       */
    /*===================================================================*/
    strCountry = capturaFondosDAO.readBranchCountry(branch);
    if (strCountry.trim().equals("Error")) {
      respFondosVO.setError("Error al obtener la ciudad del branch.");
      if (!fondosVO.isBlError()) {
        return respFondosVO;
      }
    } else if (strCountry == null) {
      strCountry = "";
    } else {
      strCountry = strCountry.trim();
    }
    log.debug("strCountry " + strCountry);
    /*===================================================================*/
    /*                  Valida la moneda de la emisora.                  */
    /*===================================================================*/
    issuingVO = validateIssuing(fondosVO.getEmisora(), fondosVO.getMoneda());
    DatosTabulares dt = null;

    if (issuingVO.getError() == null || issuingVO.getError().trim().length() == 0) {
      dt = issuingVO.getResp();
    } else {
      respFondosVO.setError(issuingVO.getError());
      if (!fondosVO.isBlError()) {
        return respFondosVO;
      }
    }

    /*===================================================================*/
    /*             Se obtiene el precio del fondo de inversión.          */
    /*===================================================================*/
    strFundPrice = capturaFondosDAO.readFundPrice(fondosVO.getBranch(), fondosVO.getEmisora());

    if (strFundPrice.trim().equals("Error")) {
      log.debug("No se encontro el precio del Fondo de Inversión.");
      respFondosVO.setError(ErrorKeys.ERR_NO_ENCONTRO_PRECIO_FONDO);
      if (!fondosVO.isBlError()) {
        return respFondosVO;
      }
    } else if (strFundPrice == null) {
      strFundPrice = "";
    }

    log.debug("strFundPrice " + strFundPrice);

    String ccode = "";

    if (clientInformationVO.getStrClientInfo()[1] != null) {
      ccode = clientInformationVO.getStrClientInfo()[1].trim();
    }

    /*===================================================================*/
    /*                          Obtenemos el IVA                         */
    /*===================================================================*/
    vatrate =
        capturaFondosDAO.getClientesVatRate(
            fondosVO.getBranch(), fondosVO.getContrato(), contratoVO.getCno(), ccode, strCountry);

    log.debug("==== vatrate " + vatrate);

    if (vatrate == null) {
      vatrate = "";
      // vatrate = "10";
    } else if (vatrate.trim().equals("Error")) {
      respFondosVO.setError("Error al ejecutar el Store Procedure SPS_OBTIENE_IVA.");
      if (!fondosVO.isBlError()) {
        return respFondosVO;
      }
    }
    // 'Luis Gachuz, 29/Mar/2003
    // 'Se le envìan nuevos paràmetros ic_Secid, ic_Trad
    /*===================================================================*/
    /*                      Obtenemos la comision.                       */
    /*===================================================================*/

    String product;
    String prodType;

    if (dt == null) {
      product = "";
      prodType = "";
    } else {
      product = dt.get(0, colProduct).toString().trim();
      prodType = dt.get(0, colProdType).toString().trim();
    }

    log.debug("product " + product);
    log.debug("prodType " + prodType);
    log.debug("Vatrate " + vatrate);

    commRateVO =
        capturaFondosDAO.getClientCommission(
            sc,
            fondosVO.getBranch(),
            fondosVO.getContrato(),
            product,
            prodType,
            rateCode,
            fondosVO.getTitulos(),
            fondosVO.getMonto(),
            vatrate,
            fondosVO.getCompraVenta(),
            fondosVO.getEmisora(),
            fondosVO.getPromotor());
    if (commRateVO != null) {
      if (commRateVO.getStatus() != 0 || commRateVO.getError() != null) {
        respFondosVO.setError(commRateVO.getError());
        if (!fondosVO.isBlError()) {
          return respFondosVO;
        }
      }
    } else {
      commRateVO.setOnCommrate(null);
    }

    log.debug("IVA " + commRateVO.getOnCommrate());
    /*===================================================================*/
    /*                         Se calcula el monto                       */
    /*===================================================================*/
    double fundPrice = 0;
    double dblCommrate = 0;
    double dblVatrate = 0;

    if (!strFundPrice.equals("") && !strFundPrice.equals("Error")) {
      fundPrice = Double.parseDouble(strFundPrice);
    }
    if (commRateVO.getOnCommrate() != null) {
      dblCommrate = Double.parseDouble(commRateVO.getOnCommrate());
    }
    if (!vatrate.equals("") && !vatrate.equals("Error")) {
      dblVatrate = Double.parseDouble(vatrate);
    }

    if (fondosVO.getTitulos() != 0) {
      dblComision = Math.abs((fondosVO.getTitulos() * fundPrice * dblCommrate) / 100);
      dblComision = Formateador.formatoDouble(dblComision, fondosVO.getDecimalsMoneda()) * (-1);
      dblIva = ((dblComision * dblVatrate) / 100);
      dblIva = Formateador.formatoDouble(dblIva, fondosVO.getDecimalsMoneda());
      dblMontoBruto =
          Formateador.formatoDouble(
              (fondosVO.getTitulos() * fundPrice), fondosVO.getDecimalsMoneda());
      dblMontoNeto = dblMontoBruto + dblComision + dblIva;
      dblCalcQty = fondosVO.getTitulos();

      log.debug("dblComision " + dblComision);
      log.debug("dblIva " + dblIva);
      log.debug("dblMontoBruto " + dblMontoBruto);
      log.debug("dblCalcQty " + dblCalcQty);

    } else if (fondosVO.getMonto() != 0) {
      if (fondosVO.getCompraVenta().equals("P")) {
        dblCalcQty =
            (fondosVO.getMonto()
                    / (fundPrice * (1 + dblCommrate / 100 + dblCommrate / 100 * dblVatrate / 100)))
                * (-1);
      } else {
        dblCalcQty =
            (fondosVO.getMonto()
                / (fundPrice * (1 - dblCommrate / 100 - dblCommrate / 100 * dblVatrate / 100))
                * (-1));
      }
      dblComision = Math.abs((dblCalcQty * fundPrice * dblCommrate) / 100);
      dblComision = Formateador.formatoDouble(dblComision, fondosVO.getDecimalsMoneda()) * (-1);
      dblIva = (dblComision * dblVatrate) / 100;
      dblIva = Formateador.formatoDouble(dblIva, fondosVO.getDecimalsMoneda());
      dblMontoBruto = (dblCalcQty * fundPrice) * (-1);
      dblMontoBruto = Formateador.formatoDouble(dblMontoBruto, fondosVO.getDecimalsMoneda());
      dblMontoNeto = dblMontoBruto + dblComision + dblIva;
    }

    dblComision = Math.abs(dblComision);

    /* Se debe formatear dblMontoNeto al
     * número de decimales de la moneda. */
    respFondosVO.setDblMontoNeto(
        Formateador.formatoDouble(dblMontoNeto, fondosVO.getDecimalsMoneda()));

    log.debug("dblMontoNeto VO " + respFondosVO.getDblMontoNeto());

    return respFondosVO;
  }