/**
   * RC add warranty claim fee
   *
   * @param request HttpServletRequest
   * @param form ActionForm
   * @return String Return results page
   */
  public String addBalanceFee(HttpServletRequest request, ActionForm form) {
    String forward = "resultMessage";
    ArrayList al = new ArrayList();
    int ftag = -1;
    int ptag = -1;
    try {

      /**
       * ******************************************************************** /*@Added/Modified by :
       * Veena /*@Date : 4/09/2012 /*@Reason : INC000000441294, CR 19 - Tax calculation by system
       * /*********************************************************************
       */
      String stateCode = null;
      String cityCode = null;
      String unitCode = null;
      Long organizationCode = null;
      String customerGroupId = null;
      ArrayList<String> feeTypeList = new ArrayList<String>();
      TreeMap<String, ServiceTaxListBean> serviceTaxMap = null;
      /** **********************Ends here********************************************* */
      Set balanceIdSet = new HashSet();
      HttpSession session = request.getSession();
      Long chargeStaffId = (Long) session.getAttribute("userId");
      String chks = (String) request.getParameter("chksBalanceId");
      BalanceFeeForm2 bf = (BalanceFeeForm2) form;
      String status = "";
      if ("bcApprove".equals(bf.getSheetType())) {
        status = "1";
      } else {
        status = "27";
      }
      //			System.out.println("sheetType---------------"+bf.getSheetType());
      //			System.out.println("status---------------"+status);
      //			BCBalanceApproveBo rbo=new BCBalanceApproveBo();
      List tempList = bcBalanceApproveBo.listVersion(chks);
      for (int i = 0; i < tempList.size(); i++) {
        BalanceFeeForm2 balanceFeeForm = (BalanceFeeForm2) tempList.get(i);
        balanceIdSet.add(balanceFeeForm.getBalanceId()); // 取不重复的balanceId
      }
      Iterator it = balanceIdSet.iterator();
      while (it.hasNext()) {
        BalanceFeeForm2 addFeeForm = new BalanceFeeForm2();
        Long tempBalanceId = (Long) it.next();
        addFeeForm.setBalanceId(tempBalanceId);
        addFeeForm.setBalanceFeeType(bf.getBalanceFeeType());
        addFeeForm.setBalanceSponsor(new Long(request.getParameter("hiddenFactoryInfo")));
        addFeeForm.setBalanceFee(bf.getBalanceFee());
        /**
         * ******************************************************************** /*@Added/Modified by
         * : Veena /*@Date : 4/09/2012 /*@Reason : INC000000441294, CR 19 - Tax calculation by
         * system /*********************************************************************
         */
        feeTypeList.add(bf.getBalanceFeeType());

        Long repairNo =
            Long.valueOf(bcBalanceApproveBo.findRepairNoByBalanceId(tempBalanceId.toString()));
        RepairServiceForm rsf = getRepairInfo(repairNo);
        organizationCode = rsf.getOrganizationCode();
        cityCode = cs.getCityCode(organizationCode);
        stateCode = cs.getStateCode(organizationCode);
        unitCode = cs.findUnitCodeByOrgCode(organizationCode);
        /* *******************************************************************/
        /*@Added/Modified by        : Manohar
        /*@Date                     : 17/04/2013
        /*@Reason                   : INC000000518392 - NeWSIS :: System issue :: Fee modification for jobs
        /**********************************************************************/

        if (null != rsf.getCustomerId() && rsf.getCustomerId().equals("")) {
          customerGroupId = cs.getCustomGrpId(rsf.getCustomerId().toString()).toString();
        }
        /* ************************ENDS HERE****************************************  */
        SearchOptionListSetting taxOptionList = new SearchOptionListSetting();

        taxOptionList.createServiceTaxDefaultInstance(
            stateCode, cityCode, unitCode, feeTypeList, customerGroupId);

        MultiEntity multiEntity = (MultiEntity) SpringContextUtil.getBean("multiEntity");
        String countryCode = multiEntity.getCountryCode();
        CommonSearchService commonSearchService =
            (CommonSearchService) SpringContextUtil.getBean("commonSearchService" + countryCode);

        serviceTaxMap = commonSearchService.getTaxList(taxOptionList);

        ServiceTaxListBean taxList =
            (serviceTaxMap == null) ? null : serviceTaxMap.get(bf.getBalanceFeeType());

        if (taxList != null) {
          taxList.calculate(bf.getBalanceFee());

          /* *******************************************************************/
          /*@Added/Modified by        : Sanjay
          /*@Date                     : 25/09/2012
          /*@Reason                   : INC000000456989 - IW Module Add fee Issue - Operation failed
          /**********************************************************************/

          if (null != taxList.getTotalTaxAmt().toString()) {
            addFeeForm.setTaxTotal(taxList.getTotalTaxAmt().toString());
          }
          /* ************************ENDS HERE********************************** */
        }

        addFeeForm.setBalanceFeeStatus(
            status); // 设置状��此页�结算�状�为BC暂�
        addFeeForm.setCreateBy(chargeStaffId);
        addFeeForm.setCreateDate(Operate.toUtilDate());
        addFeeForm.setIsSysGen("N"); // 代表是 BC手工添加的这笔费用
        addFeeForm.setRepairCode(
            bcBalanceApproveBo.findRepairCodeByBalanceId(tempBalanceId.toString())); // 方法代码
        if (bf.getBcRemark() != null && !"".equals(bf.getBcRemark())) {
          addFeeForm.setBcRemark("BC Manul Create:" + bf.getBcRemark());
        }
        ftag = bcBalanceApproveBo.add(addFeeForm);
        if (ftag == 1) {

          // 插入结算费用变化过程表
          SettlementFeeChangeProcdureForm sfcpf = new SettlementFeeChangeProcdureForm();
          sfcpf.setBalanceId(tempBalanceId);
          sfcpf.setBalanceFeeId(addFeeForm.getBalanceFeeId());
          sfcpf.setBalanceFee(bf.getBalanceFee());
          // wubin at 20100527 增加taxTotal
          Double tempTaxTotal =
              bf.getTaxTotal() == null || "".equals(bf.getTaxTotal().trim())
                  ? 0
                  : Double.parseDouble(bf.getTaxTotal());
          sfcpf.setTaxTotal(tempTaxTotal);
          sfcpf.setBalanceStatus(status);
          sfcpf.setChangeBy(chargeStaffId);
          sfcpf.setRemark(bf.getBcRemark());
          sfcpf.setCreateBy(chargeStaffId);
          sfcpf.setCreateDate(Operate.toUtilDate());
          ptag = bcBalanceApproveBo.add(sfcpf);
          if (ptag == -1) {
            bcBalanceApproveBo.delete(addFeeForm);
          }
        }
      }

      request.setAttribute("tag", ptag + "");
      if ("bcApprove".equals(bf.getSheetType())) {
        request.setAttribute("businessFlag", "RcApprove");
      } else {
        request.setAttribute("businessFlag", "BCWait");
      }
    } catch (VersionException ve) {
      forward = "versionErr";
    } catch (Exception e) {
      e.printStackTrace();
    }
    return forward;
  }