Пример #1
0
  protected BudgetLineItem findOrCreateLineItem(
      List<BudgetLineItem> lineItems,
      BudgetSubAwardPeriodDetail subAwardDetail,
      BudgetSubAwards subAward,
      BudgetPeriod budgetPeriod,
      String costElement) {
    for (BudgetLineItem curLineItem : lineItems) {
      if (StringUtils.equals(curLineItem.getCostElement(), costElement)) {
        return curLineItem;
      }
    }

    // if we didn't find one already
    BudgetLineItem newLineItem = new BudgetLineItem();
    newLineItem.setCostElement(costElement);
    newLineItem.setSubAwardNumber(subAwardDetail.getSubAwardNumber());
    newLineItem.setLineItemDescription(subAward.getOrganizationName());
    getBudgetService().populateNewBudgetLineItem(newLineItem, budgetPeriod);
    lineItems.add(newLineItem);
    return newLineItem;
  }
Пример #2
0
 public void generateSubAwardLineItems(BudgetSubAwards subAward, Budget budget) {
   BudgetDecimal amountChargeFA = new BudgetDecimal(25000);
   String directLtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_DIRECT_LT_25K_PARAM);
   String directGtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_DIRECT_GT_25K_PARAM);
   String inDirectLtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_F_AND_A_LT_25K_PARAM);
   String inDirectGtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_F_AND_A_GT_25K_PARAM);
   for (BudgetSubAwardPeriodDetail detail : subAward.getBudgetSubAwardPeriodDetails()) {
     BudgetPeriod budgetPeriod = findBudgetPeriod(detail, budget);
     List<BudgetLineItem> currentLineItems =
         findSubAwardLineItems(budgetPeriod, subAward.getSubAwardNumber());
     // zero out existing line items before recalculating
     for (BudgetLineItem item : currentLineItems) {
       item.setDirectCost(BudgetDecimal.ZERO);
       item.setCostSharingAmount(BudgetDecimal.ZERO);
       item.setSubAwardNumber(subAward.getSubAwardNumber());
       item.setLineItemDescription(subAward.getOrganizationName());
     }
     if (BudgetDecimal.returnZeroIfNull(detail.getDirectCost()).isNonZero()
         || hasBeenChanged(detail, true)) {
       BudgetDecimal ltValue = lesserValue(detail.getDirectCost(), amountChargeFA);
       BudgetDecimal gtValue = detail.getDirectCost().subtract(ltValue);
       if (ltValue.isNonZero()) {
         BudgetLineItem lt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, directLtCostElement);
         lt.setLineItemCost(ltValue);
       }
       if (gtValue.isNonZero()) {
         BudgetLineItem gt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, directGtCostElement);
         gt.setLineItemCost(gtValue);
       }
       amountChargeFA = amountChargeFA.subtract(ltValue);
     }
     if (BudgetDecimal.returnZeroIfNull(detail.getIndirectCost()).isNonZero()
         || hasBeenChanged(detail, false)) {
       BudgetDecimal ltValue = lesserValue(detail.getIndirectCost(), amountChargeFA);
       BudgetDecimal gtValue = detail.getIndirectCost().subtract(ltValue);
       if (ltValue.isNonZero()) {
         BudgetLineItem lt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, inDirectLtCostElement);
         lt.setLineItemCost(ltValue);
       }
       if (gtValue.isNonZero()) {
         BudgetLineItem gt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, inDirectGtCostElement);
         gt.setLineItemCost(gtValue);
       }
       amountChargeFA = amountChargeFA.subtract(ltValue);
     }
     Collections.sort(
         currentLineItems,
         new Comparator<BudgetLineItem>() {
           public int compare(BudgetLineItem arg0, BudgetLineItem arg1) {
             return arg0.getLineItemNumber().compareTo(arg1.getLineItemNumber());
           }
         });
     Iterator<BudgetLineItem> iter = currentLineItems.iterator();
     while (iter.hasNext()) {
       BudgetLineItem lineItem = iter.next();
       if (BudgetDecimal.returnZeroIfNull(lineItem.getLineItemCost()).isZero()) {
         budgetPeriod.getBudgetLineItems().remove(lineItem);
         iter.remove();
       } else {
         if (!budgetPeriod.getBudgetLineItems().contains(lineItem)) {
           budgetPeriod.getBudgetLineItems().add(lineItem);
         }
       }
     }
     if (!currentLineItems.isEmpty()
         && BudgetDecimal.returnZeroIfNull(detail.getCostShare()).isNonZero()) {
       currentLineItems.get(0).setCostSharingAmount(detail.getCostShare());
     }
   }
 }