private List<BudgetDetail> populateCurrentYearBe() {
   BudgetDetail detail = new BudgetDetail();
   detail.copyFrom(budgetDetail);
   detail.setBudget(null);
   return budgetDetailService.searchByCriteriaWithTypeAndFY(
       budgetDetail.getBudget().getFinancialYear().getId(), "BE", detail);
 }
 private List<BudgetDetail> populateNextYearBe(CFinancialYear finYear) {
   BudgetDetail detail = new BudgetDetail();
   detail.copyFrom(budgetDetail);
   detail.setBudget(null);
   Date nextYear = getNextYearFor(finYear.getStartingDate());
   return budgetDetailService.searchByCriteriaWithTypeAndFY(
       financialYearDAO.getFinYearByDate(nextYear).getId(), "BE", detail);
 }
 @ValidationErrorPage(value = "form")
 public String generateReport() {
   showResults = true;
   CFinancialYear finYear =
       budgetService
           .find("from Budget where id=?", budgetDetail.getBudget().getId())
           .getFinancialYear();
   List<BudgetDetail> currentYearBeList = new ArrayList<BudgetDetail>();
   List<BudgetDetail> nextYearBeList = new ArrayList<BudgetDetail>();
   List<BudgetDetail> lastYearBe = new ArrayList<BudgetDetail>();
   List<BudgetDetail> lastYearRe = new ArrayList<BudgetDetail>();
   Budget b = budgetService.findById(budgetDetail.getBudget().getId(), false);
   if ("BE".equalsIgnoreCase(b.getIsbere())) {
     CFinancialYear previousYear = budgetDetailHelper.getPreviousYearFor(finYear);
     if (previousYear != null) {
       lastYearBe =
           budgetDetailService.findAllBy(
               "from BudgetDetail where budget.financialYear.id=? and budget.isPrimaryBudget=1 and "
                   + "budget.isActiveBudget=1 and budget.isbere='BE'",
               previousYear.getId());
       lastYearRe =
           budgetDetailService.findAllBy(
               "from BudgetDetail where budget.financialYear.id=? and budget.isPrimaryBudget=1 and "
                   + "budget.isActiveBudget=1 and budget.isbere='RE'",
               previousYear.getId());
     }
   } else {
     nextYearBeList = populateNextYearBe(finYear);
   }
   List<BudgetDetail> results =
       budgetDetailService.findAllBudgetDetailsForParent(
           budgetDetail.getBudget(), budgetDetail, persistenceService);
   for (BudgetDetail detail : results) {
     BudgetReportView view = new BudgetReportView();
     view.setId(detail.getId());
     view.setDepartmentCode(detail.getExecutingDepartment().getCode());
     view.setFunctionCode(detail.getFunction().getCode());
     view.setBudgetGroupName(detail.getBudgetGroup().getName());
     if ("BE".equalsIgnoreCase(detail.getBudget().getIsbere())) {
       view.setBeNextYearApproved(detail.getApprovedAmount());
       view.setBeNextYearOriginal(detail.getOriginalAmount());
       for (BudgetDetail budgetDetail : lastYearBe) {
         if (compareDetails(budgetDetail, detail)) {
           view.setBeCurrentYearApproved(budgetDetail.getApprovedAmount());
         }
       }
       for (BudgetDetail budgetDetail : lastYearRe) {
         if (compareDetails(budgetDetail, detail)) {
           view.setReCurrentYearApproved(budgetDetail.getApprovedAmount());
           view.setReCurrentYearOriginal(budgetDetail.getOriginalAmount());
         }
       }
     } else {
       view.setReCurrentYearApproved(detail.getApprovedAmount());
       view.setReCurrentYearOriginal(detail.getOriginalAmount());
       currentYearBeList = populateCurrentYearBe();
       for (BudgetDetail budgetDetail : currentYearBeList) {
         if (compareDetails(budgetDetail, detail)) {
           view.setBeCurrentYearApproved(budgetDetail.getApprovedAmount());
         }
       }
     }
     for (BudgetDetail nextYear : nextYearBeList) {
       if (compareDetails(nextYear, detail)) {
         view.setBeNextYearApproved(nextYear.getApprovedAmount());
         view.setBeNextYearOriginal(nextYear.getOriginalAmount());
       }
     }
     budgetDetailsList.add(view);
   }
   populatePreviousYearActuals(results, budgetDetail.getBudget().getFinancialYear());
   ajaxLoadBudgets();
   populateYearRange();
   canViewREApprovedAmount = canViewApprovedAmount(budgetDetail.getBudget());
   canViewBEApprovedAmount =
       canViewApprovedAmount(budgetService.getReferenceBudgetFor(budgetDetail.getBudget()));
   return "form";
 }
 public boolean canViewApprovedAmount(Budget budget) {
   return budgetDetailService.canViewApprovedAmount(persistenceService, budget);
 }