/**
   * builds report body
   *
   * @param BudgetConstructionLevelSummary bcas
   */
  public void buildReportsBody(
      BudgetConstructionOrgLevelSummaryReport orgLevelSummaryReportEntry,
      BudgetConstructionLevelSummary levelSummary) {

    if (levelSummary.getFinancialObjectLevel() == null) {
      orgLevelSummaryReportEntry.setFinancialObjectLevelName(
          kualiConfigurationService.getPropertyValueAsString(
              BCKeyConstants.ERROR_REPORT_GETTING_OBJECT_LEVEL_NAME));
    } else {
      orgLevelSummaryReportEntry.setFinancialObjectLevelName(
          levelSummary.getFinancialObjectLevel().getFinancialObjectLevelName());
    }

    orgLevelSummaryReportEntry.setPositionCsfLeaveFteQuantity(
        BudgetConstructionReportHelper.setDecimalDigit(
            levelSummary.getPositionCsfLeaveFteQuantity(), 2, true));
    orgLevelSummaryReportEntry.setCsfFullTimeEmploymentQuantity(
        BudgetConstructionReportHelper.setDecimalDigit(
            levelSummary.getCsfFullTimeEmploymentQuantity(), 2, true));
    orgLevelSummaryReportEntry.setAppointmentRequestedCsfFteQuantity(
        BudgetConstructionReportHelper.setDecimalDigit(
            levelSummary.getAppointmentRequestedCsfFteQuantity(), 2, true));
    orgLevelSummaryReportEntry.setAppointmentRequestedFteQuantity(
        BudgetConstructionReportHelper.setDecimalDigit(
            levelSummary.getAppointmentRequestedFteQuantity(), 2, true));

    if (levelSummary.getAccountLineAnnualBalanceAmount() != null) {
      orgLevelSummaryReportEntry.setAccountLineAnnualBalanceAmount(
          levelSummary.getAccountLineAnnualBalanceAmount());
    }

    if (levelSummary.getFinancialBeginningBalanceLineAmount() != null) {
      orgLevelSummaryReportEntry.setFinancialBeginningBalanceLineAmount(
          levelSummary.getFinancialBeginningBalanceLineAmount());
    }

    if (levelSummary.getAccountLineAnnualBalanceAmount() != null
        && levelSummary.getFinancialBeginningBalanceLineAmount() != null) {
      orgLevelSummaryReportEntry.setAmountChange(
          levelSummary
              .getAccountLineAnnualBalanceAmount()
              .subtract(levelSummary.getFinancialBeginningBalanceLineAmount()));
    }

    orgLevelSummaryReportEntry.setPercentChange(
        BudgetConstructionReportHelper.calculatePercent(
            orgLevelSummaryReportEntry.getAmountChange(),
            orgLevelSummaryReportEntry.getFinancialBeginningBalanceLineAmount()));
  }
  /**
   * @see
   *     org.kuali.kfs.module.bc.document.service.BudgetConstructionAccountSummaryReportService#buildReports(java.lang.Integer,
   *     java.util.Collection)
   */
  public Collection<BudgetConstructionOrgAccountSummaryReport> buildReports(
      Integer universityFiscalYear, String principalName, boolean consolidated) {
    Collection<BudgetConstructionOrgAccountSummaryReport> reportSet = new ArrayList();
    Collection<BudgetConstructionAccountSummary> accountSummaryList =
        budgetConstructionReportsServiceHelper.getDataForBuildingReports(
            BudgetConstructionAccountSummary.class, principalName, buildOrderByList());

    // Making a list with same organizationChartOfAccountsCode, organizationCode,
    // chartOfAccountsCode, subFundGroupCode
    List totalList =
        BudgetConstructionReportHelper.deleteDuplicated(
            (List) accountSummaryList, fieldsForTotal());

    // Calculate Total Section
    List<BudgetConstructionOrgAccountSummaryReportTotal> orgAccountSummaryReportTotalList =
        calculateTotal((List) accountSummaryList, totalList);

    // builds report
    for (BudgetConstructionAccountSummary accountSummaryEntry : accountSummaryList) {
      BudgetConstructionOrgAccountSummaryReport orgAccountSummaryReportEntry =
          new BudgetConstructionOrgAccountSummaryReport();
      buildReportsHeader(
          universityFiscalYear, orgAccountSummaryReportEntry, accountSummaryEntry, consolidated);
      buildReportsBody(orgAccountSummaryReportEntry, accountSummaryEntry);
      buildReportsTotal(
          orgAccountSummaryReportEntry, accountSummaryEntry, orgAccountSummaryReportTotalList);
      reportSet.add(orgAccountSummaryReportEntry);
    }

    return reportSet;
  }
  /**
   * @see
   *     org.kuali.kfs.module.bc.document.service.BudgetConstructionLevelSummaryReportService#buildReports(java.lang.Integer,
   *     java.util.Collection)
   */
  public Collection<BudgetConstructionOrgLevelSummaryReport> buildReports(
      Integer universityFiscalYear, String principalName) {
    Collection<BudgetConstructionOrgLevelSummaryReport> reportSet = new ArrayList();

    BudgetConstructionOrgLevelSummaryReport orgLevelSummaryReportEntry;
    Collection<BudgetConstructionLevelSummary> levelSummaryList =
        budgetConstructionReportsServiceHelper.getDataForBuildingReports(
            BudgetConstructionLevelSummary.class, principalName, buildOrderByList());

    // Making a list with same organizationChartOfAccountsCode, organizationCode,
    // chartOfAccountsCode, subFundGroupCode
    List listForCalculateCons =
        BudgetConstructionReportHelper.deleteDuplicated((List) levelSummaryList, fieldsForCons());
    List listForCalculateGexpAndType =
        BudgetConstructionReportHelper.deleteDuplicated(
            (List) levelSummaryList, fieldsForGexpAndType());
    List listForCalculateTotal =
        BudgetConstructionReportHelper.deleteDuplicated((List) levelSummaryList, fieldsForTotal());

    // Calculate Total Section
    List<BudgetConstructionOrgLevelSummaryReportTotal> levelSummaryTotalConsList =
        calculateConsTotal((List) levelSummaryList, listForCalculateCons);
    List<BudgetConstructionOrgLevelSummaryReportTotal> levelSummaryTotalGexpAndTypeList =
        calculateGexpAndTypeTotal((List) levelSummaryList, listForCalculateGexpAndType);
    List<BudgetConstructionOrgLevelSummaryReportTotal> levelSummaryTotalList =
        calculateTotal((List) levelSummaryList, listForCalculateTotal);

    for (BudgetConstructionLevelSummary levelSummaryEntry : levelSummaryList) {
      orgLevelSummaryReportEntry = new BudgetConstructionOrgLevelSummaryReport();
      buildReportsHeader(universityFiscalYear, orgLevelSummaryReportEntry, levelSummaryEntry);
      buildReportsBody(orgLevelSummaryReportEntry, levelSummaryEntry);
      buildReportsTotal(
          orgLevelSummaryReportEntry,
          levelSummaryEntry,
          levelSummaryTotalConsList,
          levelSummaryTotalGexpAndTypeList,
          levelSummaryTotalList);
      reportSet.add(orgLevelSummaryReportEntry);
    }

    return reportSet;
  }
  /**
   * Calculates total part of report
   *
   * @param List bcasList
   * @param List simpleList
   */
  protected List calculateTotal(List bcasList, List simpleList) {

    Integer totalRevenueBaseAmount = 0;
    Integer totalGrossBaseAmount = 0;
    Integer totalTransferInBaseAmount = 0;
    Integer totalNetTransferBaseAmount = 0;
    Integer totalRevenueReqAmount = 0;
    Integer totalGrossReqAmount = 0;
    Integer totalTransferInReqAmount = 0;
    Integer totalNetTransferReqAmount = 0;

    List returnList = new ArrayList();
    Iterator simpleListIterator = simpleList.iterator();
    boolean prev = false;
    while (simpleListIterator.hasNext()) {
      BudgetConstructionAccountSummary simpleBcasEntry =
          (BudgetConstructionAccountSummary) simpleListIterator.next();
      Iterator bcasListIterator = bcasList.iterator();
      while (bcasListIterator.hasNext()) {
        BudgetConstructionAccountSummary bcasListEntry =
            (BudgetConstructionAccountSummary) bcasListIterator.next();
        if (BudgetConstructionReportHelper.isSameEntry(
            simpleBcasEntry, bcasListEntry, fieldsForTotal())) {
          if (bcasListEntry.getIncomeExpenseCode().equals(BCConstants.Report.INCOME_EXP_TYPE_A)) {
            prev = false;
            totalRevenueBaseAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getFinancialBeginningBalanceLineAmount());
            totalRevenueReqAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getAccountLineAnnualBalanceAmount());
          } else if (bcasListEntry
              .getIncomeExpenseCode()
              .equals(BCConstants.Report.INCOME_EXP_TYPE_E)) {
            prev = false;
            totalGrossBaseAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getFinancialBeginningBalanceLineAmount());
            totalGrossReqAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getAccountLineAnnualBalanceAmount());

          } else if (bcasListEntry
              .getIncomeExpenseCode()
              .equals(BCConstants.Report.INCOME_EXP_TYPE_T)) {
            prev = true;
            totalTransferInBaseAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getFinancialBeginningBalanceLineAmount());
            totalTransferInReqAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getAccountLineAnnualBalanceAmount());
          } else if (bcasListEntry
              .getIncomeExpenseCode()
              .equals(BCConstants.Report.INCOME_EXP_TYPE_X)) {
            totalNetTransferBaseAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getFinancialBeginningBalanceLineAmount());
            totalNetTransferReqAmount +=
                BudgetConstructionReportHelper.convertKualiInteger(
                    bcasListEntry.getAccountLineAnnualBalanceAmount());
            if (!prev) {
              prev = false;
              totalGrossBaseAmount +=
                  BudgetConstructionReportHelper.convertKualiInteger(
                      bcasListEntry.getFinancialBeginningBalanceLineAmount());
              totalGrossReqAmount +=
                  BudgetConstructionReportHelper.convertKualiInteger(
                      bcasListEntry.getAccountLineAnnualBalanceAmount());
            }
          }
        }
      }
      BudgetConstructionOrgAccountSummaryReportTotal bcoasrTotal =
          new BudgetConstructionOrgAccountSummaryReportTotal();
      bcoasrTotal.setBcas(simpleBcasEntry);
      bcoasrTotal.setTotalGrossBaseAmount(totalGrossBaseAmount);
      bcoasrTotal.setTotalGrossReqAmount(totalGrossReqAmount);
      bcoasrTotal.setTotalNetTransferBaseAmount(totalNetTransferBaseAmount);
      bcoasrTotal.setTotalNetTransferReqAmount(totalNetTransferReqAmount);
      bcoasrTotal.setTotalRevenueBaseAmount(totalRevenueBaseAmount);
      bcoasrTotal.setTotalRevenueReqAmount(totalRevenueReqAmount);
      bcoasrTotal.setTotalTransferInBaseAmount(totalTransferInBaseAmount);
      bcoasrTotal.setTotalTransferInReqAmount(totalTransferInReqAmount);
      returnList.add(bcoasrTotal);
      totalGrossBaseAmount = 0;
      totalGrossReqAmount = 0;
      totalNetTransferBaseAmount = 0;
      totalNetTransferReqAmount = 0;
      totalRevenueBaseAmount = 0;
      totalRevenueReqAmount = 0;
      totalTransferInBaseAmount = 0;
      totalTransferInReqAmount = 0;
    }

    return returnList;
  }
  /**
   * builds report total
   *
   * @param BudgetConstructionAccountSummary bcas
   * @param List reportTotalList
   */
  protected void buildReportsTotal(
      BudgetConstructionOrgAccountSummaryReport orgAccountSummaryReportEntry,
      BudgetConstructionAccountSummary accountSummary,
      List reportTotalList) {
    Iterator totalListIter = reportTotalList.iterator();
    while (totalListIter.hasNext()) {
      BudgetConstructionOrgAccountSummaryReportTotal bcasTotalEntry =
          (BudgetConstructionOrgAccountSummaryReportTotal) totalListIter.next();
      if (BudgetConstructionReportHelper.isSameEntry(
          accountSummary, bcasTotalEntry.getBcas(), fieldsForTotal())) {
        BigDecimal percentChange = BigDecimal.ZERO;
        orgAccountSummaryReportEntry.setTotalRevenueBaseAmount(
            bcasTotalEntry.getTotalRevenueBaseAmount());
        orgAccountSummaryReportEntry.setTotalGrossBaseAmount(
            bcasTotalEntry.getTotalGrossBaseAmount());
        orgAccountSummaryReportEntry.setTotalTransferInBaseAmount(
            bcasTotalEntry.getTotalTransferInBaseAmount());
        orgAccountSummaryReportEntry.setTotalNetTransferBaseAmount(
            bcasTotalEntry.getTotalNetTransferBaseAmount());

        orgAccountSummaryReportEntry.setTotalRevenueReqAmount(
            bcasTotalEntry.getTotalRevenueReqAmount());
        orgAccountSummaryReportEntry.setTotalGrossReqAmount(
            bcasTotalEntry.getTotalGrossReqAmount());
        orgAccountSummaryReportEntry.setTotalTransferInReqAmount(
            bcasTotalEntry.getTotalTransferInReqAmount());
        orgAccountSummaryReportEntry.setTotalNetTransferReqAmount(
            bcasTotalEntry.getTotalNetTransferReqAmount());

        orgAccountSummaryReportEntry.setTotalRevenueAmountChange(
            orgAccountSummaryReportEntry.getTotalRevenueReqAmount()
                - orgAccountSummaryReportEntry.getTotalRevenueBaseAmount());
        percentChange =
            BudgetConstructionReportHelper.calculatePercent(
                orgAccountSummaryReportEntry.getTotalRevenueAmountChange(),
                orgAccountSummaryReportEntry.getTotalRevenueBaseAmount());
        orgAccountSummaryReportEntry.setTotalRevenuePercentChange(percentChange);

        orgAccountSummaryReportEntry.setTotalGrossAmountChange(
            orgAccountSummaryReportEntry.getTotalGrossReqAmount()
                - orgAccountSummaryReportEntry.getTotalGrossBaseAmount());
        percentChange =
            BudgetConstructionReportHelper.calculatePercent(
                orgAccountSummaryReportEntry.getTotalGrossAmountChange(),
                orgAccountSummaryReportEntry.getTotalGrossBaseAmount());
        orgAccountSummaryReportEntry.setTotalGrossPercentChange(percentChange);

        orgAccountSummaryReportEntry.setTotalTransferAmountChange(
            orgAccountSummaryReportEntry.getTotalTransferInReqAmount()
                - orgAccountSummaryReportEntry.getTotalTransferInBaseAmount());
        percentChange =
            BudgetConstructionReportHelper.calculatePercent(
                orgAccountSummaryReportEntry.getTotalTransferAmountChange(),
                orgAccountSummaryReportEntry.getTotalTransferInBaseAmount());
        orgAccountSummaryReportEntry.setTotalTransferInPercentChange(percentChange);

        orgAccountSummaryReportEntry.setTotalNetTransferAmountChange(
            orgAccountSummaryReportEntry.getTotalNetTransferReqAmount()
                - orgAccountSummaryReportEntry.getTotalNetTransferBaseAmount());
        percentChange =
            BudgetConstructionReportHelper.calculatePercent(
                orgAccountSummaryReportEntry.getTotalNetTransferAmountChange(),
                orgAccountSummaryReportEntry.getTotalNetTransferBaseAmount());
        orgAccountSummaryReportEntry.setTotalNetTransferPercentChange(percentChange);

        orgAccountSummaryReportEntry.setRevExpDifferenceBaseAmount(
            orgAccountSummaryReportEntry.getTotalRevenueBaseAmount()
                - orgAccountSummaryReportEntry.getTotalNetTransferBaseAmount());
        orgAccountSummaryReportEntry.setRevExpDifferenceReqAmount(
            orgAccountSummaryReportEntry.getTotalRevenueReqAmount()
                - orgAccountSummaryReportEntry.getTotalNetTransferReqAmount());
        orgAccountSummaryReportEntry.setRevExpDifferenceAmountChange(
            orgAccountSummaryReportEntry.getRevExpDifferenceReqAmount()
                - orgAccountSummaryReportEntry.getRevExpDifferenceBaseAmount());
        percentChange =
            BudgetConstructionReportHelper.calculatePercent(
                orgAccountSummaryReportEntry.getRevExpDifferenceAmountChange(),
                orgAccountSummaryReportEntry.getRevExpDifferenceBaseAmount());
        orgAccountSummaryReportEntry.setRevExpDifferencePercentChange(percentChange);
      }
    }
  }
  /**
   * builds report body
   *
   * @param BudgetConstructionAccountSummary bcas
   */
  protected void buildReportsBody(
      BudgetConstructionOrgAccountSummaryReport orgAccountSummaryReportEntry,
      BudgetConstructionAccountSummary accountSummary) {
    orgAccountSummaryReportEntry.setAccountNumber(accountSummary.getAccountNumber());
    orgAccountSummaryReportEntry.setSubAccountNumber(accountSummary.getSubAccountNumber());

    if (accountSummary.getSubAccountNumber().equals(BCConstants.Report.DASHES_SUB_ACCOUNT_CODE)) {
      if (accountSummary.getAccount().getAccountName() == null) {
        orgAccountSummaryReportEntry.setAccountNameAndSubAccountName(
            kualiConfigurationService.getPropertyString(
                BCKeyConstants.ERROR_REPORT_GETTING_ACCOUNT_DESCRIPTION));
      } else
        orgAccountSummaryReportEntry.setAccountNameAndSubAccountName(
            accountSummary.getAccount().getAccountName());
    } else {
      try {
        if (accountSummary.getSubAccount().getSubAccountName() == null) {
          orgAccountSummaryReportEntry.setAccountNameAndSubAccountName(
              kualiConfigurationService.getPropertyString(
                  BCKeyConstants.ERROR_REPORT_GETTING_SUB_ACCOUNT_DESCRIPTION));
        } else
          orgAccountSummaryReportEntry.setAccountNameAndSubAccountName(
              accountSummary.getSubAccount().getSubAccountName());
      } catch (PersistenceBrokerException e) {
        orgAccountSummaryReportEntry.setAccountNameAndSubAccountName(
            kualiConfigurationService.getPropertyString(
                BCKeyConstants.ERROR_REPORT_GETTING_SUB_ACCOUNT_DESCRIPTION));
      }
    }

    // build income expense description
    if (accountSummary.getIncomeExpenseCode().equals(BCConstants.Report.INCOME_EXP_TYPE_A)) {
      orgAccountSummaryReportEntry.setIncExpDesc(
          kualiConfigurationService.getPropertyString(
              BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_REVENUE));
    } else if (accountSummary.getIncomeExpenseCode().equals(BCConstants.Report.INCOME_EXP_TYPE_E)) {
      orgAccountSummaryReportEntry.setIncExpDesc(
          kualiConfigurationService.getPropertyString(
              BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_EXP_GROSS));
    } else if (accountSummary.getIncomeExpenseCode().equals(BCConstants.Report.INCOME_EXP_TYPE_T)) {
      trExist = true;
      orgAccountSummaryReportEntry.setIncExpDesc(
          kualiConfigurationService.getPropertyString(
              BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_TRNFR_IN));
    } else {
      if (trExist) {
        trExist = false;
        orgAccountSummaryReportEntry.setIncExpDesc(
            kualiConfigurationService.getPropertyString(
                BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_EXP_NET_TRNFR));
      } else {
        orgAccountSummaryReportEntry.setIncExpDesc(
            kualiConfigurationService.getPropertyString(
                BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_EXPENDITURE));
      }
    }

    Integer beginingBalanceLineAmt = 0;
    Integer accountLineAnnualBalAmt = 0;
    if (accountSummary.getFinancialBeginningBalanceLineAmount() != null) {
      beginingBalanceLineAmt =
          BudgetConstructionReportHelper.convertKualiInteger(
              accountSummary.getFinancialBeginningBalanceLineAmount());
    }

    if (accountSummary.getFinancialBeginningBalanceLineAmount() != null) {
      accountLineAnnualBalAmt =
          BudgetConstructionReportHelper.convertKualiInteger(
              accountSummary.getAccountLineAnnualBalanceAmount());
    }

    orgAccountSummaryReportEntry.setBaseAmount(beginingBalanceLineAmt);
    orgAccountSummaryReportEntry.setReqAmount(accountLineAnnualBalAmt);
    orgAccountSummaryReportEntry.setAmountChange(accountLineAnnualBalAmt - beginingBalanceLineAmt);

    orgAccountSummaryReportEntry.setPercentChange(
        BudgetConstructionReportHelper.calculatePercent(
            orgAccountSummaryReportEntry.getAmountChange(), beginingBalanceLineAmt));
  }
  public List calculateTotal(
      List<BudgetConstructionLevelSummary> bclsList,
      List<BudgetConstructionLevelSummary> simpleList) {

    KualiInteger revenueFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
    KualiInteger revenueAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

    KualiInteger expenditureFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
    KualiInteger expenditureAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

    KualiInteger differenceFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
    KualiInteger differenceAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

    List returnList = new ArrayList();
    for (BudgetConstructionLevelSummary simpleBclsEntry : simpleList) {
      BudgetConstructionOrgLevelSummaryReportTotal bcLevelTotal =
          new BudgetConstructionOrgLevelSummaryReportTotal();
      for (BudgetConstructionLevelSummary bclsListEntry : bclsList) {
        if (BudgetConstructionReportHelper.isSameEntry(
            simpleBclsEntry, bclsListEntry, fieldsForTotal())) {

          if (bclsListEntry.getIncomeExpenseCode().equals("A")) {
            revenueFinancialBeginningBalanceLineAmount =
                revenueFinancialBeginningBalanceLineAmount.add(
                    bclsListEntry.getFinancialBeginningBalanceLineAmount());
            revenueAccountLineAnnualBalanceAmount =
                revenueAccountLineAnnualBalanceAmount.add(
                    bclsListEntry.getAccountLineAnnualBalanceAmount());
          } else {
            expenditureFinancialBeginningBalanceLineAmount =
                expenditureFinancialBeginningBalanceLineAmount.add(
                    bclsListEntry.getFinancialBeginningBalanceLineAmount());
            expenditureAccountLineAnnualBalanceAmount =
                expenditureAccountLineAnnualBalanceAmount.add(
                    bclsListEntry.getAccountLineAnnualBalanceAmount());
          }
        }
      }

      bcLevelTotal.setBcls(simpleBclsEntry);

      bcLevelTotal.setRevenueFinancialBeginningBalanceLineAmount(
          revenueFinancialBeginningBalanceLineAmount);
      bcLevelTotal.setRevenueAccountLineAnnualBalanceAmount(revenueAccountLineAnnualBalanceAmount);

      bcLevelTotal.setExpenditureFinancialBeginningBalanceLineAmount(
          expenditureFinancialBeginningBalanceLineAmount);
      bcLevelTotal.setExpenditureAccountLineAnnualBalanceAmount(
          expenditureAccountLineAnnualBalanceAmount);

      differenceFinancialBeginningBalanceLineAmount =
          revenueFinancialBeginningBalanceLineAmount.subtract(
              expenditureFinancialBeginningBalanceLineAmount);
      differenceAccountLineAnnualBalanceAmount =
          revenueAccountLineAnnualBalanceAmount.subtract(expenditureAccountLineAnnualBalanceAmount);
      bcLevelTotal.setDifferenceFinancialBeginningBalanceLineAmount(
          differenceFinancialBeginningBalanceLineAmount);
      bcLevelTotal.setDifferenceAccountLineAnnualBalanceAmount(
          differenceAccountLineAnnualBalanceAmount);

      returnList.add(bcLevelTotal);

      revenueFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
      revenueAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

      expenditureFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
      expenditureAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

      differenceFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
      differenceAccountLineAnnualBalanceAmount = KualiInteger.ZERO;
    }
    return returnList;
  }
  public List calculateGexpAndTypeTotal(
      List<BudgetConstructionLevelSummary> bclsList,
      List<BudgetConstructionLevelSummary> simpleList) {

    KualiInteger grossFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
    KualiInteger grossAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

    BigDecimal typePositionCsfLeaveFteQuantity = BigDecimal.ZERO;
    BigDecimal typePositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
    KualiInteger typeFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
    BigDecimal typeAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
    BigDecimal typeAppointmentRequestedFteQuantity = BigDecimal.ZERO;
    KualiInteger typeAccountLineAnnualBalanceAmount = KualiInteger.ZERO;
    KualiInteger typeAmountChange = KualiInteger.ZERO;
    BigDecimal typePercentChange = BigDecimal.ZERO;

    List returnList = new ArrayList();
    for (BudgetConstructionLevelSummary simpleBclsEntry : simpleList) {
      BudgetConstructionOrgLevelSummaryReportTotal bcLevelTotal =
          new BudgetConstructionOrgLevelSummaryReportTotal();
      for (BudgetConstructionLevelSummary bclsListEntry : bclsList) {
        if (BudgetConstructionReportHelper.isSameEntry(
            simpleBclsEntry, bclsListEntry, fieldsForGexpAndType())) {

          typeFinancialBeginningBalanceLineAmount =
              typeFinancialBeginningBalanceLineAmount.add(
                  bclsListEntry.getFinancialBeginningBalanceLineAmount());
          typeAccountLineAnnualBalanceAmount =
              typeAccountLineAnnualBalanceAmount.add(
                  bclsListEntry.getAccountLineAnnualBalanceAmount());
          typePositionCsfLeaveFteQuantity =
              typePositionCsfLeaveFteQuantity.add(bclsListEntry.getPositionCsfLeaveFteQuantity());
          typePositionCsfFullTimeEmploymentQuantity =
              typePositionCsfFullTimeEmploymentQuantity.add(
                  bclsListEntry.getCsfFullTimeEmploymentQuantity());
          typeAppointmentRequestedCsfFteQuantity =
              typeAppointmentRequestedCsfFteQuantity.add(
                  bclsListEntry.getAppointmentRequestedCsfFteQuantity());
          typeAppointmentRequestedFteQuantity =
              typeAppointmentRequestedFteQuantity.add(
                  bclsListEntry.getAppointmentRequestedFteQuantity());

          if (bclsListEntry.getIncomeExpenseCode().equals("B")
              && !bclsListEntry.getFinancialObjectLevelCode().equals("CORI")
              && !bclsListEntry.getFinancialObjectLevelCode().equals("TRIN")) {
            grossFinancialBeginningBalanceLineAmount =
                grossFinancialBeginningBalanceLineAmount.add(
                    bclsListEntry.getFinancialBeginningBalanceLineAmount());
            grossAccountLineAnnualBalanceAmount =
                grossAccountLineAnnualBalanceAmount.add(
                    bclsListEntry.getAccountLineAnnualBalanceAmount());
          }
        }
      }
      bcLevelTotal.setBcls(simpleBclsEntry);

      bcLevelTotal.setGrossFinancialBeginningBalanceLineAmount(
          grossFinancialBeginningBalanceLineAmount);
      bcLevelTotal.setGrossAccountLineAnnualBalanceAmount(grossAccountLineAnnualBalanceAmount);

      bcLevelTotal.setTypePositionCsfLeaveFteQuantity(typePositionCsfLeaveFteQuantity);
      bcLevelTotal.setTypePositionCsfFullTimeEmploymentQuantity(
          typePositionCsfFullTimeEmploymentQuantity);
      bcLevelTotal.setTypeFinancialBeginningBalanceLineAmount(
          typeFinancialBeginningBalanceLineAmount);
      bcLevelTotal.setTypeAppointmentRequestedCsfFteQuantity(
          typeAppointmentRequestedCsfFteQuantity);
      bcLevelTotal.setTypeAppointmentRequestedFteQuantity(typeAppointmentRequestedFteQuantity);
      bcLevelTotal.setTypeAccountLineAnnualBalanceAmount(typeAccountLineAnnualBalanceAmount);

      returnList.add(bcLevelTotal);
      grossFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
      grossAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

      typePositionCsfLeaveFteQuantity = BigDecimal.ZERO;
      typePositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
      typeFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
      typeAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
      typeAppointmentRequestedFteQuantity = BigDecimal.ZERO;
      typeAccountLineAnnualBalanceAmount = KualiInteger.ZERO;
      typeAmountChange = KualiInteger.ZERO;
      typePercentChange = BigDecimal.ZERO;
    }
    return returnList;
  }
  public List calculateConsTotal(
      List<BudgetConstructionLevelSummary> bclsList,
      List<BudgetConstructionLevelSummary> simpleList) {

    BigDecimal totalConsolidationPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
    BigDecimal totalConsolidationPositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
    KualiInteger totalConsolidationFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
    BigDecimal totalConsolidationAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
    BigDecimal totalConsolidationAppointmentRequestedFteQuantity = BigDecimal.ZERO;
    KualiInteger totalConsolidationAccountLineAnnualBalanceAmount = KualiInteger.ZERO;

    List returnList = new ArrayList();
    for (BudgetConstructionLevelSummary simpleBclsEntry : simpleList) {
      BudgetConstructionOrgLevelSummaryReportTotal bcLevelTotal =
          new BudgetConstructionOrgLevelSummaryReportTotal();
      for (BudgetConstructionLevelSummary bclsListEntry : bclsList) {
        if (BudgetConstructionReportHelper.isSameEntry(
            simpleBclsEntry, bclsListEntry, fieldsForCons())) {
          totalConsolidationFinancialBeginningBalanceLineAmount =
              totalConsolidationFinancialBeginningBalanceLineAmount.add(
                  bclsListEntry.getFinancialBeginningBalanceLineAmount());
          totalConsolidationAccountLineAnnualBalanceAmount =
              totalConsolidationAccountLineAnnualBalanceAmount.add(
                  bclsListEntry.getAccountLineAnnualBalanceAmount());
          totalConsolidationPositionCsfLeaveFteQuantity =
              totalConsolidationPositionCsfLeaveFteQuantity.add(
                  bclsListEntry.getPositionCsfLeaveFteQuantity());
          totalConsolidationPositionCsfFullTimeEmploymentQuantity =
              totalConsolidationPositionCsfFullTimeEmploymentQuantity.add(
                  bclsListEntry.getCsfFullTimeEmploymentQuantity());
          totalConsolidationAppointmentRequestedCsfFteQuantity =
              totalConsolidationAppointmentRequestedCsfFteQuantity.add(
                  bclsListEntry.getAppointmentRequestedCsfFteQuantity());
          totalConsolidationAppointmentRequestedFteQuantity =
              totalConsolidationAppointmentRequestedFteQuantity.add(
                  bclsListEntry.getAppointmentRequestedFteQuantity());
        }
      }
      bcLevelTotal.setBcls(simpleBclsEntry);
      bcLevelTotal.setTotalConsolidationPositionCsfLeaveFteQuantity(
          totalConsolidationPositionCsfLeaveFteQuantity);
      bcLevelTotal.setTotalConsolidationPositionCsfFullTimeEmploymentQuantity(
          totalConsolidationPositionCsfFullTimeEmploymentQuantity);
      bcLevelTotal.setTotalConsolidationFinancialBeginningBalanceLineAmount(
          totalConsolidationFinancialBeginningBalanceLineAmount);
      bcLevelTotal.setTotalConsolidationAppointmentRequestedCsfFteQuantity(
          totalConsolidationAppointmentRequestedCsfFteQuantity);
      bcLevelTotal.setTotalConsolidationAppointmentRequestedFteQuantity(
          totalConsolidationAppointmentRequestedFteQuantity);
      bcLevelTotal.setTotalConsolidationAccountLineAnnualBalanceAmount(
          totalConsolidationAccountLineAnnualBalanceAmount);
      returnList.add(bcLevelTotal);

      totalConsolidationPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
      totalConsolidationPositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
      totalConsolidationFinancialBeginningBalanceLineAmount = KualiInteger.ZERO;
      totalConsolidationAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
      totalConsolidationAppointmentRequestedFteQuantity = BigDecimal.ZERO;
      totalConsolidationAccountLineAnnualBalanceAmount = KualiInteger.ZERO;
    }
    return returnList;
  }
  /**
   * builds report total
   *
   * @param BudgetConstructionLevelSummary bcas
   * @param List reportTotalList
   */
  public void buildReportsTotal(
      BudgetConstructionOrgLevelSummaryReport orgLevelSummaryReportEntry,
      BudgetConstructionLevelSummary levelSummary,
      List<BudgetConstructionOrgLevelSummaryReportTotal> levelSummaryTotalConsList,
      List<BudgetConstructionOrgLevelSummaryReportTotal> levelSummaryTotalGexpAndTypeList,
      List<BudgetConstructionOrgLevelSummaryReportTotal> levelSummaryTotalList) {

    for (BudgetConstructionOrgLevelSummaryReportTotal consTotal : levelSummaryTotalConsList) {
      if (BudgetConstructionReportHelper.isSameEntry(
          levelSummary, consTotal.getBcls(), fieldsForCons())) {
        orgLevelSummaryReportEntry.setTotalConsolidationDescription(
            levelSummary.getFinancialConsolidationObject().getFinConsolidationObjectName());

        // The total part shouldn't have null value, so just checking '0'
        orgLevelSummaryReportEntry.setTotalConsolidationPositionCsfLeaveFteQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                consTotal.getTotalConsolidationPositionCsfLeaveFteQuantity(), 2, true));
        orgLevelSummaryReportEntry.setTotalConsolidationPositionCsfFullTimeEmploymentQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                consTotal.getTotalConsolidationPositionCsfFullTimeEmploymentQuantity(), 2, true));
        orgLevelSummaryReportEntry.setTotalConsolidationFinancialBeginningBalanceLineAmount(
            consTotal.getTotalConsolidationFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setTotalConsolidationAppointmentRequestedCsfFteQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                consTotal.getTotalConsolidationAppointmentRequestedCsfFteQuantity(), 2, true));
        orgLevelSummaryReportEntry.setTotalConsolidationAppointmentRequestedFteQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                consTotal.getTotalConsolidationAppointmentRequestedFteQuantity(), 2, true));
        orgLevelSummaryReportEntry.setTotalConsolidationAccountLineAnnualBalanceAmount(
            consTotal.getTotalConsolidationAccountLineAnnualBalanceAmount());

        KualiInteger amountChange =
            consTotal
                .getTotalConsolidationAccountLineAnnualBalanceAmount()
                .subtract(consTotal.getTotalConsolidationFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setTotalConsolidationAmountChange(amountChange);
        orgLevelSummaryReportEntry.setTotalConsolidationPercentChange(
            BudgetConstructionReportHelper.calculatePercent(
                amountChange,
                consTotal.getTotalConsolidationFinancialBeginningBalanceLineAmount()));
      }
    }

    for (BudgetConstructionOrgLevelSummaryReportTotal gexpAndTypeTotal :
        levelSummaryTotalGexpAndTypeList) {
      if (BudgetConstructionReportHelper.isSameEntry(
          levelSummary, gexpAndTypeTotal.getBcls(), fieldsForGexpAndType())) {

        orgLevelSummaryReportEntry.setGrossFinancialBeginningBalanceLineAmount(
            gexpAndTypeTotal.getGrossFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setGrossAccountLineAnnualBalanceAmount(
            gexpAndTypeTotal.getGrossAccountLineAnnualBalanceAmount());
        KualiInteger gexpAndTypeAmountChange =
            gexpAndTypeTotal
                .getGrossAccountLineAnnualBalanceAmount()
                .subtract(gexpAndTypeTotal.getGrossFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setGrossAmountChange(gexpAndTypeAmountChange);
        orgLevelSummaryReportEntry.setGrossPercentChange(
            BudgetConstructionReportHelper.calculatePercent(
                gexpAndTypeAmountChange,
                gexpAndTypeTotal.getGrossFinancialBeginningBalanceLineAmount()));

        if (levelSummary.getIncomeExpenseCode().equals(BCConstants.Report.INCOME_EXP_TYPE_A)) {
          orgLevelSummaryReportEntry.setTypeDesc(
              kualiConfigurationService.getPropertyValueAsString(
                  BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_UPPERCASE_REVENUE));
        } else {
          orgLevelSummaryReportEntry.setTypeDesc(
              kualiConfigurationService.getPropertyValueAsString(
                  BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_EXPENDITURE_NET_TRNFR));
        }
        orgLevelSummaryReportEntry.setTypePositionCsfLeaveFteQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                gexpAndTypeTotal.getTypePositionCsfLeaveFteQuantity(), 2, true));
        orgLevelSummaryReportEntry.setTypePositionCsfFullTimeEmploymentQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                gexpAndTypeTotal.getTypePositionCsfFullTimeEmploymentQuantity(), 2, true));
        orgLevelSummaryReportEntry.setTypeFinancialBeginningBalanceLineAmount(
            gexpAndTypeTotal.getTypeFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setTypeAppointmentRequestedCsfFteQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                gexpAndTypeTotal.getTypeAppointmentRequestedCsfFteQuantity(), 2, true));
        orgLevelSummaryReportEntry.setTypeAppointmentRequestedFteQuantity(
            BudgetConstructionReportHelper.setDecimalDigit(
                gexpAndTypeTotal.getTypeAppointmentRequestedFteQuantity(), 2, true));

        orgLevelSummaryReportEntry.setTypeAccountLineAnnualBalanceAmount(
            gexpAndTypeTotal.getTypeAccountLineAnnualBalanceAmount());
        KualiInteger typeAmountChange =
            gexpAndTypeTotal
                .getTypeAccountLineAnnualBalanceAmount()
                .subtract(gexpAndTypeTotal.getTypeFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setTypeAmountChange(typeAmountChange);
        orgLevelSummaryReportEntry.setTypePercentChange(
            BudgetConstructionReportHelper.calculatePercent(
                typeAmountChange, gexpAndTypeTotal.getTypeFinancialBeginningBalanceLineAmount()));
      }
    }

    for (BudgetConstructionOrgLevelSummaryReportTotal total : levelSummaryTotalList) {
      if (BudgetConstructionReportHelper.isSameEntry(
          levelSummary, total.getBcls(), fieldsForTotal())) {

        orgLevelSummaryReportEntry.setTotalSubFundGroupDesc(
            levelSummary.getSubFundGroup().getSubFundGroupDescription());
        orgLevelSummaryReportEntry.setRevenueFinancialBeginningBalanceLineAmount(
            total.getRevenueFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setRevenueAccountLineAnnualBalanceAmount(
            total.getRevenueAccountLineAnnualBalanceAmount());
        orgLevelSummaryReportEntry.setExpenditureFinancialBeginningBalanceLineAmount(
            total.getExpenditureFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setExpenditureAccountLineAnnualBalanceAmount(
            total.getExpenditureAccountLineAnnualBalanceAmount());

        KualiInteger revenueAmountChange =
            total
                .getRevenueAccountLineAnnualBalanceAmount()
                .subtract(total.getRevenueFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setRevenueAmountChange(revenueAmountChange);
        orgLevelSummaryReportEntry.setRevenuePercentChange(
            BudgetConstructionReportHelper.calculatePercent(
                revenueAmountChange, total.getRevenueFinancialBeginningBalanceLineAmount()));

        KualiInteger expenditureAmountChange =
            total
                .getExpenditureAccountLineAnnualBalanceAmount()
                .subtract(total.getExpenditureFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setExpenditureAmountChange(expenditureAmountChange);
        orgLevelSummaryReportEntry.setExpenditurePercentChange(
            BudgetConstructionReportHelper.calculatePercent(
                expenditureAmountChange,
                total.getExpenditureFinancialBeginningBalanceLineAmount()));

        orgLevelSummaryReportEntry.setDifferenceFinancialBeginningBalanceLineAmount(
            total.getDifferenceFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setDifferenceAccountLineAnnualBalanceAmount(
            total.getDifferenceAccountLineAnnualBalanceAmount());

        KualiInteger differenceAmountChange =
            total
                .getDifferenceAccountLineAnnualBalanceAmount()
                .subtract(total.getDifferenceFinancialBeginningBalanceLineAmount());
        orgLevelSummaryReportEntry.setDifferenceAmountChange(differenceAmountChange);
        orgLevelSummaryReportEntry.setDifferencePercentChange(
            BudgetConstructionReportHelper.calculatePercent(
                differenceAmountChange, total.getDifferenceFinancialBeginningBalanceLineAmount()));
      }
    }
  }