View Javadoc
1   /*
2    * Kuali Coeus, a comprehensive research administration system for higher education.
3    * 
4    * Copyright 2005-2015 Kuali, Inc.
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.coeus.s2sgen.impl.budget;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.kuali.coeus.common.api.person.KcPersonRepositoryService;
23  import org.kuali.coeus.common.api.rolodex.RolodexService;
24  import org.kuali.coeus.common.budget.api.core.BudgetContract;
25  import org.kuali.coeus.common.budget.api.nonpersonnel.BudgetLineItemCalculatedAmountContract;
26  import org.kuali.coeus.common.budget.api.nonpersonnel.BudgetLineItemContract;
27  import org.kuali.coeus.common.budget.api.nonpersonnel.BudgetRateAndBaseContract;
28  import org.kuali.coeus.common.budget.api.period.BudgetPeriodContract;
29  import org.kuali.coeus.common.budget.api.personnel.*;
30  import org.kuali.coeus.common.budget.api.rate.RateClassContract;
31  import org.kuali.coeus.common.api.org.OrganizationRepositoryService;
32  import org.kuali.coeus.common.api.person.KcPersonContract;
33  import org.kuali.coeus.common.budget.api.rate.RateClassType;
34  import org.kuali.coeus.common.budget.api.personnel.BudgetPersonContract;
35  import org.kuali.coeus.common.api.rolodex.RolodexContract;
36  import org.kuali.coeus.propdev.api.budget.ProposalDevelopmentBudgetExtContract;
37  import org.kuali.coeus.propdev.api.budget.modular.BudgetModularIdcContract;
38  import org.kuali.coeus.propdev.api.core.DevelopmentProposalContract;
39  import org.kuali.coeus.propdev.api.location.ProposalSiteContract;
40  import org.kuali.coeus.propdev.api.person.ProposalPersonContract;
41  import org.kuali.coeus.propdev.api.s2s.S2SConfigurationService;
42  import org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeService;
43  import org.kuali.coeus.s2sgen.impl.person.S2SProposalPersonService;
44  import org.kuali.coeus.s2sgen.impl.util.FieldValueConstants;
45  import org.kuali.coeus.s2sgen.impl.validate.S2SErrorHandlerService;
46  import org.kuali.coeus.propdev.api.core.ProposalDevelopmentDocumentContract;
47  import org.kuali.coeus.sys.api.model.ScaleTwoDecimal;
48  import org.kuali.coeus.s2sgen.api.core.ConfigurationConstants;
49  import org.kuali.coeus.s2sgen.api.core.S2SException;
50  import org.kuali.coeus.common.budget.api.core.category.BudgetCategoryMapContract;
51  import org.kuali.coeus.common.budget.api.core.category.BudgetCategoryMapService;
52  import org.kuali.coeus.common.budget.api.core.category.BudgetCategoryMappingContract;
53  import org.kuali.coeus.common.budget.api.personnel.BudgetPersonSalaryService;
54  import org.kuali.coeus.common.api.sponsor.hierarchy.SponsorHierarchyService;
55  
56  import org.springframework.beans.factory.annotation.Autowired;
57  import org.springframework.beans.factory.annotation.Qualifier;
58  import org.springframework.stereotype.Component;
59  
60  import java.math.BigDecimal;
61  import java.math.RoundingMode;
62  import java.util.*;
63  
64  /**
65   * This class contains the implementation for common budget calculations required for S2S Form generators
66   * 
67   * @author Kuali Research Administration Team (kualidev@oncourse.iu.edu)
68   */
69  @Component("s2SBudgetCalculatorService")
70  public class S2SBudgetCalculatorServiceImpl implements
71                  S2SBudgetCalculatorService {
72      public static final String VALUE_UNKNOWN = "Unknown";
73      private static final int MAX_KEY_PERSON_COUNT = 8;
74      private static final String CATEGORY_TYPE_OTHER_DIRECT_COST = "O";
75      private static final String LASALARIES = "LASALARIES";
76      private static final String PERSONNEL_TYPE_GRAD = "Grad";
77      private static final String PERSONNEL_TYPE_POSTDOC = "PostDoc";
78      private static final String PERSONNEL_TYPE_UNDERGRAD = "UnderGrad";
79      private static final String PERSONNEL_TYPE_SEC = "Sec";
80      private static final String PERSONNEL_TYPE_OTHER = "Other";
81      private static final String PERSONNEL_TYPE_OTHER_PROFESSIONALS = "Other Professionals";
82      private static final String PERSONNEL_TYPE_ALLOCATED_ADMIN_SUPPORT = "Allocated Admin Support";
83      private static final String ROLE_GRADUATE_STUDENTS = "Graduate Students";
84      private static final String ROLE_POST_DOCTORAL_ASSOCIATES = "Post Doctoral Associates";
85      private static final String ROLE_GRADUATE_UNDERGRADUATE_STUDENTS = "Undergraduate Students";
86      private static final String ROLE_GRADUATE_SECRETARIAL_OR_CLERICAL = "Secretarial / Clerical";
87      private static final String ROLE_GRADUATE_OTHER = "Other";
88      private static final String ROLE_GRADUATE_OTHER_PROFESSIONALS = "Other Professionals";
89      private static final String ROLE_GRADUATE_ALLOCATED_ADMIN_SUPPORT = "Allocated Admin Support";
90      private static final String TARGET_CATEGORY_CODE_01 = "01";
91      private static final String OTHER_DIRECT_COSTS = "Other Direct Costs";
92      private static final String ALL_OTHER_COSTS = "All Other Costs";
93      private static final String DESCRIPTION = "Description";
94      private static final String DESCRIPTION_LA = "LA ";
95      private static final String KEYPERSON_CO_PD_PI = "CO-PD/PI";
96      private static final String NID_PD_PI = "PD/PI";
97      private static final String NID_CO_PD_PI = "CO-INVESTIGATOR"; 
98      private static final String KEYPERSON_OTHER = "Other (Specify)";
99      public static final String SPONSOR = "S2S";
100     private static final String PRINCIPAL_INVESTIGATOR_ROLE = "PD/PI";
101     private static final BigDecimal POINT_ZERO_ONE = new ScaleTwoDecimal(0.01).bigDecimalValue();
102 
103     @Autowired
104     @Qualifier("budgetCategoryMapService")
105     private BudgetCategoryMapService budgetCategoryMapService;
106 
107     @Autowired
108     @Qualifier("s2SConfigurationService")
109     private S2SConfigurationService s2SConfigurationService;
110 
111     @Autowired
112     @Qualifier("budgetPersonSalaryService")
113     private BudgetPersonSalaryService budgetPersonSalaryService;
114 
115     @Autowired
116     @Qualifier("organizationRepositoryService")
117     private OrganizationRepositoryService organizationRepositoryService;
118 
119     @Autowired
120     @Qualifier("sponsorHierarchyService")
121     private SponsorHierarchyService sponsorHierarchyService;
122 
123     @Autowired
124     @Qualifier("kcPersonRepositoryService")
125     private KcPersonRepositoryService kcPersonRepositoryService;
126 
127     @Autowired
128     @Qualifier("tbnPersonService")
129     private TbnPersonService tbnPersonService;
130 
131     @Autowired
132     @Qualifier("rolodexService")
133     private RolodexService rolodexService;
134 
135     @Autowired
136     @Qualifier("s2SDateTimeService")
137     private S2SDateTimeService s2SDateTimeService;
138 
139     @Autowired
140     @Qualifier("s2SProposalPersonService")
141     private S2SProposalPersonService s2SProposalPersonService;
142 
143     @Autowired
144     @Qualifier("s2SErrorHandlerService")
145     private S2SErrorHandlerService s2SErrorHandlerService;
146 
147     @Autowired
148     @Qualifier("s2SCommonBudgetService")
149     private S2SCommonBudgetService s2SCommonBudgetService;
150 
151     @Override
152     public String getParticipantSupportCategoryCode() {
153         return s2SConfigurationService.getValueAsString(ConfigurationConstants.BUDGET_CATEGORY_TYPE_PARTICIPANT_SUPPORT);
154     }
155 
156     @Override
157     public List<? extends BudgetLineItemContract> getMatchingLineItems(List<? extends BudgetLineItemContract> lineItems, List<String> budgetCategoryType) {
158         List<BudgetLineItemContract> result = new ArrayList<BudgetLineItemContract>();
159         for (BudgetLineItemContract lineItem : lineItems) {
160             if (budgetCategoryType.contains(lineItem.getBudgetCategory().getBudgetCategoryType().getCode())) {
161                 result.add(lineItem);
162             }
163         }
164         return result;
165     }
166 
167     /**
168      * 
169      * This method does the budget related calculations for a given ProposalDevelopmentDocumentContract and returns them in
170      * BudgetSummaryInfo
171      * 
172      * @param pdDoc ProposalDevelopmentDocumentContract.
173      * @return BudgetSummaryInfo corresponding to the ProposalDevelopmentDocumentContract object.
174      * @throws S2SException
175      */
176     @Override
177     public BudgetSummaryDto getBudgetInfo(ProposalDevelopmentDocumentContract pdDoc, List<BudgetPeriodDto> budgetPeriodInfos)
178             throws S2SException {
179         ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService.getBudget(pdDoc.getDevelopmentProposal());
180         BudgetSummaryDto budgetSummaryInfo = new BudgetSummaryDto();
181         if (budget == null) {
182             return budgetSummaryInfo;
183         }
184 
185         budgetSummaryInfo.setBudgetPeriods(budgetPeriodInfos);
186         budgetSummaryInfo.setCumTotalCosts(budget.getTotalCost());
187         budgetSummaryInfo.setCumTotalIndirectCosts(budget.getTotalIndirectCost());
188         budgetSummaryInfo.setCumTotalDirectCosts(budget.getTotalDirectCost());
189         if (budget.getSubmitCostSharingFlag()) {
190             budgetSummaryInfo.setCumTotalCostSharing(budget.getCostSharingAmount());
191         }
192 
193         ScaleTwoDecimal totalDirectCostSharing = ScaleTwoDecimal.ZERO;
194         ScaleTwoDecimal totalIndirectCostSharing = ScaleTwoDecimal.ZERO;
195         ScaleTwoDecimal lineItemCost = ScaleTwoDecimal.ZERO;
196         ScaleTwoDecimal lineItemCostSharingAmount = ScaleTwoDecimal.ZERO;
197         ScaleTwoDecimal fringeCost = ScaleTwoDecimal.ZERO;
198         ScaleTwoDecimal fringeCostSharingAmount = ScaleTwoDecimal.ZERO;
199         ScaleTwoDecimal budgetDetailsCost = ScaleTwoDecimal.ZERO;
200         ScaleTwoDecimal budgetDetailsCostSharingAmount = ScaleTwoDecimal.ZERO;
201         ScaleTwoDecimal budgetDetailsFringeCost = ScaleTwoDecimal.ZERO;
202         ScaleTwoDecimal budgetDetailsFringeCostSharingAmount = ScaleTwoDecimal.ZERO;
203         ScaleTwoDecimal totPersFunds = ScaleTwoDecimal.ZERO;
204         ScaleTwoDecimal totPersNonFunds = ScaleTwoDecimal.ZERO;
205         String budgetCategoryTypePersonnel = s2SConfigurationService.getValueAsString(
206                 ConfigurationConstants.S2SBUDGET_BUDGET_CATEGORY_TYPE_PERSONNEL);
207         String rateTypeSupportStaffSalaries = s2SConfigurationService.getValueAsString(
208                 ConfigurationConstants.S2SBUDGET_RATE_TYPE_SUPPORT_STAFF_SALARIES);
209         String rateTypeAdministrativeSalaries = s2SConfigurationService.getValueAsString(
210                 ConfigurationConstants.S2SBUDGET_RATE_TYPE_ADMINISTRATIVE_SALARIES);
211                 
212         for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) {
213             for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
214                 totalDirectCostSharing = totalDirectCostSharing.add(lineItem.getCostSharingAmount());
215                 if (lineItem
216                         .getBudgetCategory()
217                         .getBudgetCategoryType()
218                         .getCode()
219                         .equals(budgetCategoryTypePersonnel)) {
220                     lineItemCost = lineItemCost.add(lineItem.getLineItemCost());
221                     if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
222                         lineItemCostSharingAmount = lineItemCostSharingAmount.add(lineItem.getCostSharingAmount());
223                     }
224                 }
225 
226                 for (BudgetLineItemCalculatedAmountContract lineItemCalAmt : lineItem.getBudgetLineItemCalculatedAmounts()) {
227                     if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
228                         if (lineItemCalAmt.getRateClass().getRateClassType().getCode().equals(RateClassType.OVERHEAD.getRateClassType())) {
229                             totalIndirectCostSharing = totalIndirectCostSharing.add(lineItemCalAmt.getCalculatedCostSharing());
230                         }
231                         else {
232                             totalDirectCostSharing = totalDirectCostSharing.add(lineItemCalAmt.getCalculatedCostSharing());
233                         }
234                     }
235                     if ((lineItemCalAmt.getRateClass().getCode().equals(
236                             s2SConfigurationService.getValueAsString(
237                                     ConfigurationConstants.S2SBUDGET_RATE_CLASS_CODE_EMPLOYEE_BENEFITS)) && !lineItemCalAmt.getRateTypeCode()
238                             .equals(rateTypeSupportStaffSalaries))
239                             || (lineItemCalAmt.getRateClass().getCode().equals(
240                                     s2SConfigurationService.getValueAsString(
241                                             ConfigurationConstants.S2SBUDGET_RATE_CLASS_CODE_VACATION)) && !lineItemCalAmt.getRateTypeCode()
242                                     .equals(rateTypeAdministrativeSalaries))) {
243                         if (lineItem
244                                 .getBudgetCategory()
245                                 .getBudgetCategoryType()
246                                 .getCode()
247                                 .equals(budgetCategoryTypePersonnel)) {
248                             fringeCost = fringeCost.add(lineItemCalAmt.getCalculatedCost());
249                             if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
250                                 fringeCostSharingAmount = fringeCostSharingAmount.add(lineItemCalAmt.getCalculatedCostSharing());
251                             }
252                         }
253                     }
254                     if (lineItemCalAmt
255                             .getRateClass()
256                             .getRateClassType().getCode()
257                             .equals(s2SConfigurationService.getValueAsString(
258                                     ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_LAB_ALLOCATION_SALARIES))) {
259                         budgetDetailsCost = budgetDetailsCost.add(lineItemCalAmt.getCalculatedCost());
260                         if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
261                             budgetDetailsCostSharingAmount = budgetDetailsCostSharingAmount.add(lineItemCalAmt
262                                     .getCalculatedCostSharing());
263                         }
264                     }
265                     if ((lineItemCalAmt
266                             .getRateClass()
267                             .getRateClassType().getCode()
268                             .equals(s2SConfigurationService.getValueAsString(
269                                     ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_EMPLOYEE_BENEFITS)) && lineItemCalAmt.getRateTypeCode()
270                             .equals(rateTypeSupportStaffSalaries))
271                             || (lineItemCalAmt
272                                     .getRateClass()
273                                     .getRateClassType().getCode()
274                                     .equals(s2SConfigurationService.getValueAsString(
275                                             ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_VACATION)) && lineItemCalAmt.getRateTypeCode()
276                                     .equals(rateTypeAdministrativeSalaries))) {
277                         budgetDetailsFringeCost = budgetDetailsFringeCost.add(lineItemCalAmt.getCalculatedCost());
278                         if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
279                             budgetDetailsFringeCostSharingAmount = budgetDetailsFringeCostSharingAmount.add(lineItemCalAmt
280                                     .getCalculatedCostSharing());
281                         }
282                     }
283 
284                 }
285             }
286         }
287         if (budget.getSubmitCostSharingFlag()) {
288             budgetSummaryInfo.setCumTotalDirectCostSharing(totalDirectCostSharing);
289             budgetSummaryInfo.setCumTotalIndirectCostSharing(totalIndirectCostSharing);
290         }
291         totPersFunds = totPersFunds.add(lineItemCost).add(fringeCost).add(budgetDetailsCost).add(budgetDetailsFringeCost);
292         totPersNonFunds = totPersNonFunds.add(lineItemCostSharingAmount).add(fringeCostSharingAmount)
293                 .add(budgetDetailsCostSharingAmount).add(budgetDetailsFringeCostSharingAmount);
294 
295         budgetSummaryInfo.setCumTotalNonFundsForPersonnel(totPersNonFunds);
296         budgetSummaryInfo.setCumTotalFundsForPersonnel(totPersFunds);
297 
298         OtherDirectCostInfoDto otherDirectCostInfo = new OtherDirectCostInfoDto();
299         List<OtherDirectCostInfoDto> cvOtherDirectCost = new ArrayList<OtherDirectCostInfoDto>();
300         List<Map<String, String>> cvOtherCosts = new ArrayList<Map<String, String>>();
301 
302         ScaleTwoDecimal cumAlterations = ScaleTwoDecimal.ZERO;
303         ScaleTwoDecimal cumConsultants = ScaleTwoDecimal.ZERO;
304         ScaleTwoDecimal cumMaterials = ScaleTwoDecimal.ZERO;
305         ScaleTwoDecimal cumPubs = ScaleTwoDecimal.ZERO;
306         ScaleTwoDecimal cumSubAward = ScaleTwoDecimal.ZERO;
307         ScaleTwoDecimal cumComputer = ScaleTwoDecimal.ZERO;
308         ScaleTwoDecimal cumEquipRental = ScaleTwoDecimal.ZERO;
309         ScaleTwoDecimal cumAll = ScaleTwoDecimal.ZERO;
310         ScaleTwoDecimal cumOtherType1 = ScaleTwoDecimal.ZERO;
311         ScaleTwoDecimal cumPartStipends = ScaleTwoDecimal.ZERO;
312         ScaleTwoDecimal cumPartSubsistence = ScaleTwoDecimal.ZERO;
313         ScaleTwoDecimal cumPartTuition = ScaleTwoDecimal.ZERO;
314         ScaleTwoDecimal cumPartOther = ScaleTwoDecimal.ZERO;
315         ScaleTwoDecimal cumPartTravel = ScaleTwoDecimal.ZERO;
316         int cumParticipantCount = 0;
317         ScaleTwoDecimal cumAlterationsCostSharing = ScaleTwoDecimal.ZERO;
318         ScaleTwoDecimal cumConsultantsCostSharing = ScaleTwoDecimal.ZERO;
319         ScaleTwoDecimal cumMaterialsCostSharing = ScaleTwoDecimal.ZERO;
320         ScaleTwoDecimal cumPubsCostSharing = ScaleTwoDecimal.ZERO;
321         ScaleTwoDecimal cumSubAwardCostSharing = ScaleTwoDecimal.ZERO;
322         ScaleTwoDecimal cumComputerCostSharing = ScaleTwoDecimal.ZERO;
323         ScaleTwoDecimal cumEquipRentalCostSharing = ScaleTwoDecimal.ZERO;
324         ScaleTwoDecimal cumAllCostSharing = ScaleTwoDecimal.ZERO;
325         ScaleTwoDecimal cumOtherType1CostSharing = ScaleTwoDecimal.ZERO;
326         ScaleTwoDecimal cumPartStipendsCostSharing = ScaleTwoDecimal.ZERO;
327         ScaleTwoDecimal cumPartSubsistenceCostSharing = ScaleTwoDecimal.ZERO;
328         ScaleTwoDecimal cumPartTuitionCostSharing = ScaleTwoDecimal.ZERO;
329         ScaleTwoDecimal cumPartOtherCostSharing = ScaleTwoDecimal.ZERO;
330         ScaleTwoDecimal cumPartTravelCostSharing = ScaleTwoDecimal.ZERO;
331         ScaleTwoDecimal participantTotalCostSharing = ScaleTwoDecimal.ZERO;
332 
333         ScaleTwoDecimal totalDomesticTravel = ScaleTwoDecimal.ZERO;
334         ScaleTwoDecimal totalForeignTravel = ScaleTwoDecimal.ZERO;
335         ScaleTwoDecimal totalDomesticTravelNonFund = ScaleTwoDecimal.ZERO;
336         ScaleTwoDecimal totalForeignTravelNonFund = ScaleTwoDecimal.ZERO;
337         ScaleTwoDecimal cumTotalEquipFund = ScaleTwoDecimal.ZERO;
338         ScaleTwoDecimal cumTotalEquipNonFund = ScaleTwoDecimal.ZERO;
339         ScaleTwoDecimal totCountOtherPersonnel = ScaleTwoDecimal.ZERO;
340 
341         if (budgetPeriodInfos != null) {
342             for (BudgetPeriodDto budgetPeriodInfo : budgetPeriodInfos) {
343                 cvOtherDirectCost = budgetPeriodInfo.getOtherDirectCosts();
344                 otherDirectCostInfo = cvOtherDirectCost.get(0);
345                 cumAlterations = cumAlterations.add(otherDirectCostInfo.getAlterations());
346                 cumConsultants = cumConsultants.add(otherDirectCostInfo.getConsultants());
347                 cumMaterials = cumMaterials.add(otherDirectCostInfo.getmaterials());
348                 cumPubs = cumPubs.add(otherDirectCostInfo.getpublications());
349                 cumSubAward = cumSubAward.add(otherDirectCostInfo.getsubAwards());
350                 cumComputer = cumComputer.add(otherDirectCostInfo.getcomputer());
351                 cumEquipRental = cumEquipRental.add(otherDirectCostInfo.getEquipRental());
352                 cumAll = cumAll.add(otherDirectCostInfo.gettotalOtherDirect());
353 
354                 cumPartStipends = cumPartStipends.add(otherDirectCostInfo.getPartStipends() == null ? ScaleTwoDecimal.ZERO
355                         : otherDirectCostInfo.getPartStipends());
356                 cumPartTravel = cumPartTravel.add(otherDirectCostInfo.getPartTravel() == null ? ScaleTwoDecimal.ZERO
357                         : otherDirectCostInfo.getPartTravel());
358                 cumPartSubsistence = cumPartSubsistence.add(otherDirectCostInfo.getPartSubsistence() == null ? ScaleTwoDecimal.ZERO
359                         : otherDirectCostInfo.getPartSubsistence());
360                 cumPartTuition = cumPartTuition.add(otherDirectCostInfo.getPartTuition() == null ? ScaleTwoDecimal.ZERO
361                         : otherDirectCostInfo.getPartTuition());
362                 cumPartOther = cumPartOther.add(otherDirectCostInfo.getPartOther() == null ? ScaleTwoDecimal.ZERO
363                         : otherDirectCostInfo.getPartOther());
364                 cumParticipantCount = cumParticipantCount
365                         + (otherDirectCostInfo.getParticpantTotalCount() == 0 ? 0 : otherDirectCostInfo.getParticpantTotalCount());
366                 if (budget.getSubmitCostSharingFlag()) {
367                     cumAlterationsCostSharing = cumAlterationsCostSharing.add(otherDirectCostInfo.getAlterationsCostSharing());
368                     cumConsultantsCostSharing = cumConsultantsCostSharing.add(otherDirectCostInfo.getConsultantsCostSharing());
369                     cumMaterialsCostSharing = cumMaterialsCostSharing.add(otherDirectCostInfo.getMaterialsCostSharing());
370                     cumPubsCostSharing = cumPubsCostSharing.add(otherDirectCostInfo.getPublicationsCostSharing());
371                     cumSubAwardCostSharing = cumSubAwardCostSharing.add(otherDirectCostInfo.getSubAwardsCostSharing());
372                     cumComputerCostSharing = cumComputerCostSharing.add(otherDirectCostInfo.getComputerCostSharing());
373                     cumEquipRentalCostSharing = cumEquipRentalCostSharing.add(otherDirectCostInfo.getEquipRentalCostSharing());
374                     cumAllCostSharing = cumAllCostSharing.add(otherDirectCostInfo.getTotalOtherDirectCostSharing());
375 
376                     cumPartStipendsCostSharing = cumPartStipendsCostSharing
377                             .add(otherDirectCostInfo.getPartStipendsCostSharing() == null ? ScaleTwoDecimal.ZERO
378                                     : otherDirectCostInfo.getPartStipendsCostSharing());
379                     cumPartTravelCostSharing = cumPartTravelCostSharing
380                             .add(otherDirectCostInfo.getPartTravelCostSharing() == null ? ScaleTwoDecimal.ZERO : otherDirectCostInfo
381                                     .getPartTravelCostSharing());
382                     cumPartSubsistenceCostSharing = cumPartSubsistenceCostSharing.add(otherDirectCostInfo
383                             .getPartSubsistenceCostSharing() == null ? ScaleTwoDecimal.ZERO : otherDirectCostInfo
384                             .getPartSubsistenceCostSharing());
385                     cumPartTuitionCostSharing = cumPartTuitionCostSharing
386                             .add(otherDirectCostInfo.getPartTuitionCostSharing() == null ? ScaleTwoDecimal.ZERO : otherDirectCostInfo
387                                     .getPartTuitionCostSharing());
388 
389                     cumPartOtherCostSharing = cumPartOtherCostSharing
390                             .add(otherDirectCostInfo.getPartOtherCostSharing() == null ? ScaleTwoDecimal.ZERO : otherDirectCostInfo
391                                     .getPartOtherCostSharing());
392                 }
393                 else {
394                     cumAlterationsCostSharing = cumAlterationsCostSharing.add(ScaleTwoDecimal.ZERO);
395                     cumConsultantsCostSharing = cumConsultantsCostSharing.add(ScaleTwoDecimal.ZERO);
396                     cumMaterialsCostSharing = cumMaterialsCostSharing.add(ScaleTwoDecimal.ZERO);
397                     cumPubsCostSharing = cumPubsCostSharing.add(ScaleTwoDecimal.ZERO);
398                     cumSubAwardCostSharing = cumSubAwardCostSharing.add(ScaleTwoDecimal.ZERO);
399                     cumComputerCostSharing = cumComputerCostSharing.add(ScaleTwoDecimal.ZERO);
400                     cumEquipRentalCostSharing = cumEquipRentalCostSharing.add(ScaleTwoDecimal.ZERO);
401                     cumAllCostSharing = cumAllCostSharing.add(ScaleTwoDecimal.ZERO);
402                     cumPartStipendsCostSharing = cumPartStipendsCostSharing.add(ScaleTwoDecimal.ZERO);
403                     cumPartTravelCostSharing = cumPartTravelCostSharing.add(ScaleTwoDecimal.ZERO);
404                     cumPartSubsistenceCostSharing = cumPartSubsistenceCostSharing.add(ScaleTwoDecimal.ZERO);
405                     cumPartTuitionCostSharing = cumPartTuitionCostSharing.add(ScaleTwoDecimal.ZERO);
406                     cumPartOtherCostSharing = cumPartOtherCostSharing.add(ScaleTwoDecimal.ZERO);
407                 }
408                 totalDomesticTravel = totalDomesticTravel.add(budgetPeriodInfo.getDomesticTravelCost());
409                 totalForeignTravel = totalForeignTravel.add(budgetPeriodInfo.getForeignTravelCost());
410                 totalDomesticTravelNonFund = totalDomesticTravelNonFund.add(budgetPeriodInfo.getDomesticTravelCostSharing());
411                 totalForeignTravelNonFund = totalForeignTravelNonFund.add(budgetPeriodInfo.getForeignTravelCostSharing());
412                 totCountOtherPersonnel = totCountOtherPersonnel.add(budgetPeriodInfo.getOtherPersonnelTotalNumber());
413 
414                 for (EquipmentDto equipmentInfo : budgetPeriodInfo.getEquipment()) {
415                     cumTotalEquipFund = cumTotalEquipFund.add(equipmentInfo.getTotalFund());
416                     cumTotalEquipNonFund = cumTotalEquipNonFund.add(equipmentInfo.getTotalNonFund());
417                 }
418 
419                 Map<String, String> hmOthers = new HashMap<String, String>();
420                 cvOtherCosts = otherDirectCostInfo.getOtherCosts();
421                 for (int l = 0; l < cvOtherCosts.size(); l++) {
422                     hmOthers = cvOtherCosts.get(l);
423                     cumOtherType1 = cumOtherType1.add(new ScaleTwoDecimal(hmOthers.get(CostConstants.KEY_COST)));
424                     cumOtherType1CostSharing = cumOtherType1CostSharing.add(new ScaleTwoDecimal(hmOthers
425                             .get(CostConstants.KEY_COSTSHARING)));
426                 }
427             }
428         }
429 
430         budgetSummaryInfo.setCumDomesticTravelNonFund(totalDomesticTravelNonFund);
431         budgetSummaryInfo.setCumForeignTravelNonFund(totalForeignTravelNonFund);
432         budgetSummaryInfo.setCumTravelNonFund(totalDomesticTravelNonFund.add(totalForeignTravelNonFund));
433         budgetSummaryInfo.setCumDomesticTravel(totalDomesticTravel);
434         budgetSummaryInfo.setCumForeignTravel(totalForeignTravel);
435         budgetSummaryInfo.setCumTravel(totalDomesticTravel.add(totalForeignTravel));
436         budgetSummaryInfo.setpartOtherCost(cumPartOther);
437         budgetSummaryInfo.setpartStipendCost(cumPartStipends);
438         budgetSummaryInfo.setpartTravelCost(cumPartTravel);
439         budgetSummaryInfo.setPartSubsistence(cumPartSubsistence);
440         budgetSummaryInfo.setPartTuition(cumPartTuition);
441         budgetSummaryInfo.setparticipantCount(cumParticipantCount);
442 
443         if (budget.getSubmitCostSharingFlag()) {
444             // add costSaring for fedNonFedBudget report
445             budgetSummaryInfo.setPartOtherCostSharing(cumPartOtherCostSharing);
446             budgetSummaryInfo.setPartStipendCostSharing(cumPartStipendsCostSharing);
447             budgetSummaryInfo.setPartTravelCostSharing(cumPartTravelCostSharing);
448             budgetSummaryInfo.setPartSubsistenceCostSharing(cumPartSubsistenceCostSharing);
449             budgetSummaryInfo.setPartTuitionCostSharing(cumPartTuitionCostSharing);
450         }
451 
452         OtherDirectCostInfoDto summaryOtherDirectCostInfo = new OtherDirectCostInfoDto();
453         summaryOtherDirectCostInfo.setAlterations(cumAlterations);
454         summaryOtherDirectCostInfo.setcomputer(cumComputer);
455         summaryOtherDirectCostInfo.setConsultants(cumConsultants);
456         summaryOtherDirectCostInfo.setmaterials(cumMaterials);
457         summaryOtherDirectCostInfo.setpublications(cumPubs);
458         summaryOtherDirectCostInfo.setsubAwards(cumSubAward);
459         summaryOtherDirectCostInfo.setEquipRental(cumEquipRental);
460         summaryOtherDirectCostInfo.settotalOtherDirect(cumAll);
461 
462         summaryOtherDirectCostInfo.setPartStipends(cumPartStipends);
463         summaryOtherDirectCostInfo.setPartTravel(cumPartTravel);
464         summaryOtherDirectCostInfo.setPartSubsistence(cumPartSubsistence);
465         summaryOtherDirectCostInfo.setPartTuition(cumPartTuition);
466         summaryOtherDirectCostInfo.setPartOther(cumPartOther);
467         summaryOtherDirectCostInfo.setParticipantTotal(cumPartStipends.add(cumPartTravel.add(cumPartOther.add(cumPartSubsistence
468                 .add(cumPartTravel)))));
469         summaryOtherDirectCostInfo.setParticipantTotalCount(cumParticipantCount);
470         // start add costSaring for fedNonFedBudget report
471         summaryOtherDirectCostInfo.setAlterationsCostSharing(cumAlterationsCostSharing);
472         summaryOtherDirectCostInfo.setComputerCostSharing(cumComputerCostSharing);
473         summaryOtherDirectCostInfo.setConsultantsCostSharing(cumConsultantsCostSharing);
474         summaryOtherDirectCostInfo.setMaterialsCostSharing(cumMaterialsCostSharing);
475         summaryOtherDirectCostInfo.setPublicationsCostSharing(cumPubsCostSharing);
476         summaryOtherDirectCostInfo.setSubAwardsCostSharing(cumSubAwardCostSharing);
477         summaryOtherDirectCostInfo.setEquipRentalCostSharing(cumEquipRentalCostSharing);
478         summaryOtherDirectCostInfo.setTotalOtherDirectCostSharing(cumAllCostSharing);
479 
480         summaryOtherDirectCostInfo.setPartStipendsCostSharing(cumPartStipendsCostSharing);
481         summaryOtherDirectCostInfo.setPartTravelCostSharing(cumPartTravelCostSharing);
482         summaryOtherDirectCostInfo.setPartTuitionCostSharing(cumPartTuitionCostSharing);
483         summaryOtherDirectCostInfo.setPartSubsistenceCostSharing(cumPartSubsistenceCostSharing);
484         summaryOtherDirectCostInfo.setPartOtherCostSharing(cumPartOtherCostSharing);
485 
486         participantTotalCostSharing = participantTotalCostSharing.add(cumPartStipendsCostSharing);
487         participantTotalCostSharing = participantTotalCostSharing.add(cumPartTravelCostSharing);
488         participantTotalCostSharing = participantTotalCostSharing.add(cumPartOtherCostSharing);
489         participantTotalCostSharing = participantTotalCostSharing.add(cumPartTuitionCostSharing);
490         participantTotalCostSharing = participantTotalCostSharing.add(cumPartSubsistenceCostSharing);
491         summaryOtherDirectCostInfo.setParticipantTotalCostSharing(participantTotalCostSharing);
492 
493         List<Map<String, String>> cvAllOthers = new ArrayList<Map<String, String>>();
494         HashMap<String, String> hmAllOthers = new HashMap<String, String>();
495         hmAllOthers.put(CostConstants.KEY_COST, cumOtherType1.toString());
496         hmAllOthers.put(CostConstants.KEY_COSTSHARING, cumOtherType1CostSharing.toString());
497         cvAllOthers.add(hmAllOthers);
498         summaryOtherDirectCostInfo.setOtherCosts(cvAllOthers);
499 
500         List<OtherDirectCostInfoDto> cvCumOtherDirectCost = new ArrayList<OtherDirectCostInfoDto>(); // all
501         // periods
502         cvCumOtherDirectCost.add(summaryOtherDirectCostInfo);
503         budgetSummaryInfo.setOtherDirectCosts(cvCumOtherDirectCost);
504 
505         budgetSummaryInfo.setCumEquipmentFunds(cumTotalEquipFund);
506         budgetSummaryInfo.setCumEquipmentNonFunds(cumTotalEquipNonFund);
507 
508         // hardcoded
509         budgetSummaryInfo.setCumFee(ScaleTwoDecimal.ZERO);
510 
511         ScaleTwoDecimal totSrFunds = ScaleTwoDecimal.ZERO;
512         ScaleTwoDecimal totSrNonFunds = ScaleTwoDecimal.ZERO;
513 
514         if (budgetPeriodInfos != null) {
515             for (BudgetPeriodDto budgetPeriodInfo : budgetPeriodInfos) {
516                 totSrFunds = totSrFunds.add(budgetPeriodInfo.getTotalFundsKeyPersons());
517                 totSrNonFunds = totSrNonFunds.add(budgetPeriodInfo.getTotalNonFundsKeyPersons());
518             }
519         }
520         budgetSummaryInfo.setCumTotalFundsForSrPersonnel(totSrFunds);
521         budgetSummaryInfo.setCumTotalNonFundsForSrPersonnel(totSrNonFunds);
522 
523         // other personnel - funds for other personnel will be difference
524         // between total person funds and senior person funds
525         budgetSummaryInfo.setCumTotalFundsForOtherPersonnel(totPersFunds.subtract(totSrFunds));
526         budgetSummaryInfo.setCumTotalNonFundsForOtherPersonnel(totPersNonFunds.subtract(totSrNonFunds));
527         budgetSummaryInfo.setCumNumOtherPersonnel(totCountOtherPersonnel);
528         return budgetSummaryInfo;
529     }
530 
531     /**
532      * This method gets the list of BudgetPeriodInfo for the latest BudgetDocument of the given ProposalDevelopmentDocumentContract
533      * 
534      * @param pdDoc ProposalDevelopmentDocumentContract
535      * @return a List of BudgetPeriodInfo corresponding to the ProposalDevelopmentDocumentContract object.
536      * @throws S2SException
537      */
538     @Override
539     public List<BudgetPeriodDto> getBudgetPeriods(ProposalDevelopmentDocumentContract pdDoc) throws S2SException {
540         List<BudgetPeriodDto> budgetPeriods = new ArrayList<BudgetPeriodDto>();
541         ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService.getBudget(pdDoc.getDevelopmentProposal());
542         if (budget == null) {
543             return budgetPeriods;
544         }
545 
546         for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) {
547             BudgetPeriodDto bpData = new BudgetPeriodDto();
548             ScaleTwoDecimal totalCostSharing = ScaleTwoDecimal.ZERO;
549             ScaleTwoDecimal totalDirectCostSharing = ScaleTwoDecimal.ZERO;
550             ScaleTwoDecimal totalIndirectCostSharing = ScaleTwoDecimal.ZERO;
551             bpData.setLineItemCount(budgetPeriod.getBudgetLineItems().size());
552             if (budget.getSubmitCostSharingFlag()) {
553                 for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
554                     if (lineItem.getSubmitCostSharingFlag()) {
555                         totalCostSharing = totalCostSharing.add(lineItem.getCostSharingAmount());
556                     }
557                     for (BudgetLineItemCalculatedAmountContract lineItemCalculatedAmt : lineItem.getBudgetLineItemCalculatedAmounts()) {
558                         if (lineItem.getSubmitCostSharingFlag()) {
559                             if (lineItemCalculatedAmt.getRateClass().getRateClassType().getCode()
560                                     .equals(RateClassType.OVERHEAD.getRateClassType())) {
561                                 totalIndirectCostSharing = totalIndirectCostSharing.add(lineItemCalculatedAmt
562                                         .getCalculatedCostSharing());
563                             }
564                             else {
565                                 totalDirectCostSharing = totalDirectCostSharing.add(lineItemCalculatedAmt
566                                         .getCalculatedCostSharing());
567                             }
568                         }
569                     }
570                 }
571                 totalDirectCostSharing = totalDirectCostSharing.add(totalCostSharing);
572             }
573 
574             // populate the budgetPeriod data from the BudgetPeriod
575             //if there is a final budget, then thats the budget we have now.
576             bpData.setFinalVersionFlag(pdDoc.getDevelopmentProposal().getFinalBudget() != null ? "Y" : "N");
577             bpData.setProposalNumber(pdDoc.getDevelopmentProposal().getProposalNumber());
578             bpData.setBudgetPeriod(budgetPeriod.getBudgetPeriod());
579             bpData.setVersion(budget.getBudgetVersionNumber());
580             bpData.setStartDate(new java.sql.Date(budgetPeriod.getStartDate().getTime()));
581             bpData.setEndDate(new java.sql.Date(budgetPeriod.getEndDate().getTime()));
582             bpData.setTotalCosts(budgetPeriod.getTotalCost());
583             bpData.setDirectCostsTotal(budgetPeriod.getTotalDirectCost());
584             bpData.setTotalIndirectCost(budgetPeriod.getTotalIndirectCost());
585             bpData.setCostSharingAmount(budgetPeriod.getCostSharingAmount());
586             if (budget.getSubmitCostSharingFlag()) {
587                 bpData.setTotalDirectCostSharing(totalDirectCostSharing);
588                 bpData.setTotalIndirectCostSharing(totalIndirectCostSharing);
589             }
590             bpData.setCognizantFedAgency(getCognizantFedAgency(pdDoc.getDevelopmentProposal()));
591 
592             bpData.setIndirectCosts(getIndirectCosts(budget, budgetPeriod));
593             bpData.setEquipment(getEquipment(budgetPeriod, budget));
594             bpData.setOtherDirectCosts(getOtherDirectCosts(budgetPeriod, budget));
595             if (bpData.getOtherDirectCosts().size() > 0) {
596                 OtherDirectCostInfoDto otherCostInfo = bpData.getOtherDirectCosts().get(0);
597                 bpData.setDomesticTravelCost(otherCostInfo.getDomTravel());
598 
599                 bpData.setForeignTravelCost(otherCostInfo.getForeignTravel());
600                 bpData.setTotalTravelCost(otherCostInfo.getTotTravel());
601                 if (budget.getSubmitCostSharingFlag()) {
602                     // add costSaring for fedNonFedBudget report
603                     bpData.setDomesticTravelCostSharing(otherCostInfo.getDomTravelCostSharing());
604                     bpData.setForeignTravelCostSharing(otherCostInfo.getForeignTravelCostSharing());
605                     bpData.setTotalTravelCostSharing(otherCostInfo.getTotTravelCostSharing());
606                 }
607                 // participants
608                 bpData.setpartOtherCost(otherCostInfo.getPartOther());
609                 bpData.setpartStipendCost(otherCostInfo.getPartStipends());
610                 bpData.setpartTravelCost(otherCostInfo.getPartTravel());
611                 bpData.setPartSubsistence(otherCostInfo.getPartSubsistence());
612                 bpData.setPartTuition(otherCostInfo.getPartTuition());
613                 bpData.setparticipantCount(otherCostInfo.getParticpantTotalCount());
614                 if (budget.getSubmitCostSharingFlag()) {
615                     bpData.setPartOtherCostSharing(otherCostInfo.getPartOtherCostSharing());
616                     bpData.setPartStipendCostSharing(otherCostInfo.getPartStipendsCostSharing());
617                     bpData.setPartTravelCostSharing(otherCostInfo.getPartTravelCostSharing());
618                     bpData.setPartTuitionCostSharing(otherCostInfo.getPartTuitionCostSharing());
619                     bpData.setPartSubsistenceCostSharing(otherCostInfo.getPartSubsistenceCostSharing());
620                 }
621             }
622             List<List<KeyPersonDto>> keyPersonList = getKeyPersons(
623                     budgetPeriod,pdDoc,MAX_KEY_PERSON_COUNT, budget);
624             List<KeyPersonDto> keyPersons = new ArrayList<KeyPersonDto>();
625             List<KeyPersonDto> extraPersons = new ArrayList<KeyPersonDto>();
626             if (keyPersonList.size() > 0) {
627                 keyPersons = keyPersonList.get(0);
628             }
629             if (keyPersonList.size() > 1) {
630                 extraPersons = keyPersonList.get(1);
631             }
632 
633             bpData.setKeyPersons(keyPersons);
634             bpData.setExtraKeyPersons(extraPersons);
635 
636             ScaleTwoDecimal totalKeyPersonSum = ScaleTwoDecimal.ZERO;
637             ScaleTwoDecimal totalKeyPersonSumCostSharing = ScaleTwoDecimal.ZERO;
638             ScaleTwoDecimal totalAttKeyPersonSum = ScaleTwoDecimal.ZERO;
639             ScaleTwoDecimal totalAttKeyPersonSumCostSharing = ScaleTwoDecimal.ZERO;
640             if (keyPersons != null) {
641                 for (KeyPersonDto keyPerson : keyPersons) {
642                     totalKeyPersonSum = totalKeyPersonSum.add(keyPerson.getFundsRequested());
643                     if (budget.getSubmitCostSharingFlag()) {
644                         totalKeyPersonSumCostSharing = totalKeyPersonSumCostSharing.add(keyPerson.getNonFundsRequested());
645                     }
646                 }
647             }
648 
649             if (extraPersons != null) {
650                 for (KeyPersonDto keyPerson : extraPersons) {
651                     totalAttKeyPersonSum = totalAttKeyPersonSum.add(keyPerson.getFundsRequested());
652                     if (budget.getSubmitCostSharingFlag()) {
653                         // start add costSaring for fedNonFedBudget report
654                         totalAttKeyPersonSumCostSharing = totalAttKeyPersonSumCostSharing.add(keyPerson.getNonFundsRequested());
655                     }
656                 }
657             }
658             bpData.setTotalFundsKeyPersons(totalKeyPersonSum.add(totalAttKeyPersonSum));
659             bpData.setTotalFundsAttachedKeyPersons(totalAttKeyPersonSum);
660             bpData.setTotalNonFundsKeyPersons(totalKeyPersonSumCostSharing.add(totalAttKeyPersonSumCostSharing));
661             bpData.setTotalNonFundsAttachedKeyPersons(totalAttKeyPersonSumCostSharing);
662 
663             List<OtherPersonnelDto> otherPersonnel = getOtherPersonnel(budgetPeriod, pdDoc);
664             bpData.setOtherPersonnel(otherPersonnel);
665             ScaleTwoDecimal otherPersonnelCount = ScaleTwoDecimal.ZERO;
666             ScaleTwoDecimal otherPersonnelTotalFunds = ScaleTwoDecimal.ZERO;
667             ScaleTwoDecimal otherPersonnelTotalNonFunds = ScaleTwoDecimal.ZERO;
668 
669             for (OtherPersonnelDto otherPersonnelInfo : otherPersonnel) {
670                 otherPersonnelCount = otherPersonnelCount.add(new ScaleTwoDecimal(otherPersonnelInfo.getNumberPersonnel()));
671                 otherPersonnelTotalFunds = otherPersonnelTotalFunds.add(otherPersonnelInfo.getCompensation().getFundsRequested());
672                 otherPersonnelTotalNonFunds = otherPersonnelTotalNonFunds.add(otherPersonnelInfo.getCompensation()
673                         .getNonFundsRequested());
674             }
675             bpData.setTotalOtherPersonnelFunds(otherPersonnelTotalFunds);
676             bpData.setOtherPersonnelTotalNumber(otherPersonnelCount);
677             bpData.setTotalCompensation(otherPersonnelTotalFunds.add(totalKeyPersonSum).add(totalAttKeyPersonSum));
678             bpData.setTotalOtherPersonnelNonFunds(otherPersonnelTotalNonFunds);
679             bpData.setTotalCompensationCostSharing(otherPersonnelTotalNonFunds.add(totalKeyPersonSumCostSharing).add(
680                     totalAttKeyPersonSumCostSharing));
681 
682             budgetPeriods.add(bpData);
683         }
684         return budgetPeriods;
685     }
686 
687     protected String getCognizantFedAgency(DevelopmentProposalContract developmentProposal) {
688         StringBuilder fedAgency = new StringBuilder();
689         ProposalSiteContract applicantOrganization = developmentProposal.getApplicantOrganization();
690         if (applicantOrganization != null && applicantOrganization.getOrganization() != null
691                 && applicantOrganization.getOrganization().getCognizantAuditor() != null) {
692             fedAgency.append(organizationRepositoryService.getCognizantFedAgency(applicantOrganization.getOrganization()));
693         }
694         if (fedAgency.toString().length() == 0) {
695             fedAgency.append(VALUE_UNKNOWN);
696         }
697         return fedAgency.toString();
698     }
699 
700     /**
701      * 
702      * This method populates the {@link OtherPersonnelDto} business objects for the given {@link org.kuali.coeus.common.budget.api.period.BudgetPeriodContract} and
703      * {@link ProposalDevelopmentDocumentContract}
704      * 
705      * @param budgetPeriod given budget period.
706      * @param pdDoc Proposal Development Document.
707      * @return {@link List} of {@link OtherPersonnelDto}
708      */
709     protected List<OtherPersonnelDto> getOtherPersonnel(BudgetPeriodContract budgetPeriod, ProposalDevelopmentDocumentContract pdDoc) {
710         List<OtherPersonnelDto> cvOtherPersonnel = new ArrayList<OtherPersonnelDto>();
711         cvOtherPersonnel.add(getOtherPersonnelDetails(
712                 budgetPeriod,pdDoc,
713                 s2SConfigurationService.getValueAsString(
714                         ConfigurationConstants.S2SBUDGET_CATEGORY_01_GRADUATES),PERSONNEL_TYPE_GRAD,
715                 ROLE_GRADUATE_STUDENTS));
716         cvOtherPersonnel.add(getOtherPersonnelDetails(
717                 budgetPeriod,pdDoc,
718                 s2SConfigurationService.getValueAsString(
719                         ConfigurationConstants.S2SBUDGET_CATEGORY_01_POSTDOCS),PERSONNEL_TYPE_POSTDOC,
720                 ROLE_POST_DOCTORAL_ASSOCIATES));
721         cvOtherPersonnel.add(getOtherPersonnelDetails(
722                 budgetPeriod,pdDoc,
723                 s2SConfigurationService.getValueAsString(
724                         ConfigurationConstants.S2SBUDGET_CATEGORY_01_UNDERGRADS),PERSONNEL_TYPE_UNDERGRAD,
725                 ROLE_GRADUATE_UNDERGRADUATE_STUDENTS));
726         cvOtherPersonnel.add(getOtherPersonnelDetails(
727                 budgetPeriod,pdDoc,
728                 s2SConfigurationService.getValueAsString(
729                         ConfigurationConstants.S2SBUDGET_CATEGORY_01_SECRETARIAL),PERSONNEL_TYPE_SEC,
730                 ROLE_GRADUATE_SECRETARIAL_OR_CLERICAL));
731         cvOtherPersonnel.add(getOtherPersonnelDetails(
732                 budgetPeriod,pdDoc,
733                 s2SConfigurationService.getValueAsString(
734                         ConfigurationConstants.S2SBUDGET_CATEGORY_01_OTHER),PERSONNEL_TYPE_OTHER,
735                 ROLE_GRADUATE_OTHER));
736         cvOtherPersonnel.add(getOtherPersonnelDetails(
737                 budgetPeriod,pdDoc,
738                 s2SConfigurationService.getValueAsString(
739                         ConfigurationConstants.S2SBUDGET_CATEGORY_01_OTHER_PROFS),PERSONNEL_TYPE_OTHER_PROFESSIONALS,
740                 ROLE_GRADUATE_OTHER_PROFESSIONALS));
741         cvOtherPersonnel.add(getOtherPersonnelDetails(
742                 budgetPeriod,pdDoc,
743                 LASALARIES,PERSONNEL_TYPE_ALLOCATED_ADMIN_SUPPORT,
744                 ROLE_GRADUATE_ALLOCATED_ADMIN_SUPPORT));
745         return cvOtherPersonnel;
746     }
747 
748     /**
749      * 
750      * This method populates the details for {@link OtherPersonnelDto} business object for the given
751      * {@link ProposalDevelopmentDocumentContract}
752      * 
753      * @param budgetPeriod given budget period.
754      * @param pdDoc Proposal Development Document.
755      * @param category budget category
756      * @param personnelType proposal personnel type.
757      * @param role role of the proposal person.
758      * @return OtherPersonnelInfo information about the other personnel.
759      */
760     protected OtherPersonnelDto getOtherPersonnelDetails(BudgetPeriodContract budgetPeriod, ProposalDevelopmentDocumentContract pdDoc,
761             String category, String personnelType, String role) {
762         OtherPersonnelDto otherPersonnelInfo = new OtherPersonnelDto();
763 
764         int count = 0;
765         ScaleTwoDecimal salaryRequested = ScaleTwoDecimal.ZERO;
766         ScaleTwoDecimal salaryCostSharing = ScaleTwoDecimal.ZERO;
767         ScaleTwoDecimal lineItemCost = ScaleTwoDecimal.ZERO;
768         ScaleTwoDecimal lineItemCostSharingAmount = ScaleTwoDecimal.ZERO;
769         ScaleTwoDecimal mrLaCost = ScaleTwoDecimal.ZERO;
770         ScaleTwoDecimal mrLaCostSharingAmount = ScaleTwoDecimal.ZERO;
771 
772         ScaleTwoDecimal fringeCost = ScaleTwoDecimal.ZERO;
773         ScaleTwoDecimal fringeCostSharingAmount = ScaleTwoDecimal.ZERO;
774         ScaleTwoDecimal mrLaFringeCost = ScaleTwoDecimal.ZERO;
775         ScaleTwoDecimal mrLaFringeCostSharingAmount = ScaleTwoDecimal.ZERO;
776         ScaleTwoDecimal budgetLineItemFringeCost = ScaleTwoDecimal.ZERO;
777         ScaleTwoDecimal budgetLineItemFringeCostSharingAmount = ScaleTwoDecimal.ZERO;
778 
779         ScaleTwoDecimal bdSalary = ScaleTwoDecimal.ZERO;
780         ScaleTwoDecimal bdFringe = ScaleTwoDecimal.ZERO;
781         ScaleTwoDecimal bdFunds = ScaleTwoDecimal.ZERO;
782         ScaleTwoDecimal bdSalaryCostSharing = ScaleTwoDecimal.ZERO;
783         ScaleTwoDecimal bdFringeCostSharing = ScaleTwoDecimal.ZERO;
784         ScaleTwoDecimal bdNonFunds = ScaleTwoDecimal.ZERO;
785 
786         BigDecimal academicMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
787         BigDecimal summerMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
788         BigDecimal calendarMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
789         BigDecimal cycleMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
790 
791         BigDecimal numberOfMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
792         String rateTypeSupportStaffSalaries = s2SConfigurationService.getValueAsString(
793                 ConfigurationConstants.S2SBUDGET_RATE_TYPE_SUPPORT_STAFF_SALARIES);
794         String rateClassCodeEmployeeBenefits = s2SConfigurationService.getValueAsString(
795                 ConfigurationConstants.S2SBUDGET_RATE_CLASS_CODE_EMPLOYEE_BENEFITS);
796         String rateClassCodeVacation = s2SConfigurationService.getValueAsString(
797                 ConfigurationConstants.S2SBUDGET_RATE_CLASS_CODE_VACATION);
798         String rateTypeAdministrativeSalaries = s2SConfigurationService.getValueAsString(
799                 ConfigurationConstants.S2SBUDGET_RATE_TYPE_ADMINISTRATIVE_SALARIES);
800         Map<String, String> personJobCodes = new HashMap<String, String>();
801         boolean personExistsAsProposalPerson = false;
802         
803         // Calculate the salary and fringe for category
804         // LASALARIES
805         if (category.equalsIgnoreCase(LASALARIES)) {
806             for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
807                 // Caluclate LA for rate class type Y
808                 for (BudgetLineItemCalculatedAmountContract lineItemCalculatedAmount : lineItem
809                         .getBudgetLineItemCalculatedAmounts()) {
810                     if (lineItemCalculatedAmount
811                             .getRateClass()
812                             .getRateClassType().getCode()
813                             .equals(s2SConfigurationService.getValueAsString(
814                                     ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_LAB_ALLOCATION_SALARIES))) {
815                         mrLaCost = mrLaCost.add(lineItemCalculatedAmount.getCalculatedCost());
816                         if(lineItem.getSubmitCostSharingFlag()){
817                             mrLaCostSharingAmount = mrLaCostSharingAmount.add(lineItemCalculatedAmount
818                                     .getCalculatedCostSharing());
819                         }
820                     }
821 
822                     // Calculate the fringe
823                     if ((lineItemCalculatedAmount
824                             .getRateClass()
825                             .getRateClassType().getCode()
826                             .equals(s2SConfigurationService.getValueAsString(
827                                     ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_EMPLOYEE_BENEFITS)) && lineItemCalculatedAmount
828                                     .getRateTypeCode().equals(
829                                             rateTypeSupportStaffSalaries))
830                                             || (lineItemCalculatedAmount
831                                                     .getRateClass()
832                                                     .getRateClassType().getCode()
833                                                     .equals(s2SConfigurationService.getValueAsString(
834                                                             ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_VACATION)) && lineItemCalculatedAmount
835                                                             .getRateTypeCode().equals(
836                                                                     rateTypeAdministrativeSalaries))) {
837                         mrLaFringeCost = mrLaFringeCost.add(lineItemCalculatedAmount.getCalculatedCost());
838                         if(lineItem.getSubmitCostSharingFlag()){
839                             mrLaFringeCostSharingAmount = mrLaFringeCostSharingAmount.add(lineItemCalculatedAmount
840                                     .getCalculatedCostSharing());
841                         }
842                     }
843                 }
844             }
845         }
846         else{
847             for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
848                 List<? extends BudgetCategoryMappingContract> budgetCategoryList = budgetCategoryMapService.findCatMappingByTargetAndMappingName(category, SPONSOR);
849 
850                 for (BudgetCategoryMappingContract categoryMapping : budgetCategoryList) {
851                     if (categoryMapping.getBudgetCategoryCode().equals(lineItem.getBudgetCategory().getCode())) {
852                         List<? extends BudgetPersonnelDetailsContract> lineItemPersonDetails = lineItem.getBudgetPersonnelDetailsList();
853                         boolean personExist = !lineItemPersonDetails.isEmpty();
854                         if (personExist) {
855                             for (BudgetPersonnelDetailsContract personDetails : lineItemPersonDetails) {
856                                 if (categoryMapping.getBudgetCategoryCode().equals(lineItem.getBudgetCategory().getCode())) {
857                                     String budgetPersonId = personDetails.getPersonId();
858                                     personExistsAsProposalPerson = false;
859                                     // get sum of salary of other personnel, but
860                                     // exclude the key persons and investigators
861                                     for (ProposalPersonContract proposalPerson : pdDoc.getDevelopmentProposal().getProposalPersons()) {
862                                         if (budgetPersonId.equals(proposalPerson.getPersonId())
863                                                 || (proposalPerson.getRolodexId() != null && budgetPersonId.equals(proposalPerson
864                                                         .getRolodexId().toString()))) {
865                                             personExistsAsProposalPerson = true;
866                                             break;
867                                         }
868                                     }
869                                     if (!personExistsAsProposalPerson) {
870                                         salaryRequested = salaryRequested.add(personDetails.getSalaryRequested());
871                                         if(lineItem.getSubmitCostSharingFlag()){
872                                             salaryCostSharing = salaryCostSharing.add(personDetails.getCostSharingAmount());
873                                         }
874                                         numberOfMonths = s2SDateTimeService.getNumberOfMonths(personDetails.getStartDate(),
875                                                 personDetails.getEndDate()).bigDecimalValue();
876                                         if (personDetails.getPeriodTypeCode().equals(
877                                                 s2SConfigurationService.getValueAsString(
878                                                         ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_ACADEMIC_MONTHS))) {
879                                             if (lineItem.getSubmitCostSharingFlag()) {
880                                                 academicMonths = academicMonths.add(personDetails.getPercentEffort().bigDecimalValue()
881                                                         .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
882                                             } else {
883                                                 academicMonths = academicMonths.add(personDetails.getPercentCharged().bigDecimalValue()
884                                                         .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
885                                             }                                            
886                                         }
887                                         else if (personDetails.getPeriodTypeCode().equals(
888                                                 s2SConfigurationService.getValueAsString(
889                                                         ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_SUMMER_MONTHS))) {
890                                             if (lineItem.getSubmitCostSharingFlag()) {
891                                                 summerMonths = summerMonths.add(personDetails.getPercentEffort().bigDecimalValue().multiply(numberOfMonths)
892                                                         .multiply(POINT_ZERO_ONE));
893                                             } else {
894                                                 summerMonths = summerMonths.add(personDetails.getPercentCharged().bigDecimalValue().multiply(numberOfMonths)
895                                                         .multiply(POINT_ZERO_ONE));
896                                             }
897                                             
898                                         }
899                                         else if (personDetails.getPeriodTypeCode().equals(
900                                                 s2SConfigurationService.getValueAsString(
901                                                         ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_CALENDAR_MONTHS))) {
902                                             if (lineItem.getSubmitCostSharingFlag()) {
903                                                 calendarMonths = calendarMonths.add(personDetails.getPercentEffort().bigDecimalValue().multiply(numberOfMonths)
904                                                         .multiply(POINT_ZERO_ONE));
905                                             } else {
906                                                 calendarMonths = calendarMonths.add(personDetails.getPercentCharged().bigDecimalValue().multiply(numberOfMonths)
907                                                         .multiply(POINT_ZERO_ONE));
908                                             }
909                                         }
910                                         else if (personDetails.getPeriodTypeCode().equals(
911                                                 s2SConfigurationService.getValueAsString(
912                                                         ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_CYCLE_MONTHS))) {
913                                             cycleMonths = cycleMonths.add(personDetails.getPercentEffort().bigDecimalValue().multiply(numberOfMonths)
914                                                     .multiply(POINT_ZERO_ONE));
915                                         }
916                                         // Get total count of unique
917                                         // personId+jobCode combination for those
918                                         // persons who are part of
919                                         // BudgetPersonnelDetails but are not
920                                         // proposal persons
921                                         personJobCodes.put(personDetails.getPersonId() + personDetails.getJobCode(), "");
922                                         // Calcculate the fringe cost
923                                         for (BudgetPersonnelCalculatedAmountContract personCalculatedAmount :  personDetails
924                                                 .getBudgetPersonnelCalculatedAmounts()) {
925                                             if ((personCalculatedAmount.getRateClass().getCode().equals(
926                                                     rateClassCodeEmployeeBenefits) && !personCalculatedAmount
927                                                     .getRateTypeCode().equals(
928                                                             rateTypeSupportStaffSalaries))
929                                                             || (personCalculatedAmount.getRateClass().getCode().equals(
930                                                                     rateClassCodeVacation) && !personCalculatedAmount
931                                                                     .getRateTypeCode().equals(
932                                                                             rateTypeAdministrativeSalaries))) {
933                                                 fringeCost = fringeCost.add(personCalculatedAmount.getCalculatedCost());
934                                                 if(lineItem.getSubmitCostSharingFlag()){
935                                                     fringeCostSharingAmount = fringeCostSharingAmount.add(personCalculatedAmount
936                                                             .getCalculatedCostSharing());
937                                                 }
938                                             }
939                                         }
940                                     }
941                                 }
942                             }
943                         }
944                         else {
945                             // personExist is false. No person found for the line
946                             // item.
947                             // get costs for this budget category that do not have
948                             // persons attached to the cost element
949                             lineItemCost = lineItemCost.add(lineItem.getLineItemCost());
950                             if(lineItem.getSubmitCostSharingFlag()){
951                                 lineItemCostSharingAmount = lineItemCostSharingAmount.add(lineItem.getCostSharingAmount());
952                             }
953                             count = lineItem.getQuantity();
954                             for (BudgetLineItemCalculatedAmountContract lineItemCalculatedAmount : lineItem
955                                     .getBudgetLineItemCalculatedAmounts()) {
956 
957                                 // Calculate fringe cost
958                                 if (lineItemCalculatedAmount.getRateClass().getRateClassType().getCode().equalsIgnoreCase("E")) {
959                                     fringeCost = fringeCost.add(lineItemCalculatedAmount.getCalculatedCost());
960                                 }
961                                 if ((lineItemCalculatedAmount.getRateClass().getCode().equals(
962                                         rateClassCodeEmployeeBenefits) && !lineItemCalculatedAmount
963                                         .getRateTypeCode().equals(
964                                                 rateTypeSupportStaffSalaries))
965                                                 || (lineItemCalculatedAmount.getRateClass().getCode().equals(
966                                                         rateClassCodeVacation) && !lineItemCalculatedAmount
967                                                         .getRateTypeCode().equals(
968                                                                 rateTypeAdministrativeSalaries))) {
969                                     if(lineItem.getSubmitCostSharingFlag()){
970                                         fringeCostSharingAmount = fringeCostSharingAmount.add(lineItemCalculatedAmount
971                                                 .getCalculatedCostSharing());
972                                     }
973                                 }
974                             }
975                         }
976                     }
977                 }
978             }
979         }
980         // Set the salary amounts
981         bdSalary = bdSalary.add(salaryRequested).add(lineItemCost).add(mrLaCost);
982         bdSalaryCostSharing = bdSalaryCostSharing.add(salaryCostSharing).add(lineItemCostSharingAmount).add(mrLaCostSharingAmount);
983 
984         // Set the fringe costs
985         bdFringe = bdFringe.add(fringeCost).add(budgetLineItemFringeCost).add(mrLaFringeCost);
986         bdFringeCostSharing = bdFringeCostSharing.add(fringeCostSharingAmount).add(budgetLineItemFringeCostSharingAmount)
987                 .add(mrLaFringeCostSharingAmount);
988 
989         bdNonFunds = bdSalaryCostSharing.add(bdFringeCostSharing);
990         bdFunds = bdSalary.add(bdFringe);
991 
992         count = personJobCodes.isEmpty() ? count : personJobCodes.size();
993         otherPersonnelInfo.setNumberPersonnel(count);
994         otherPersonnelInfo.setPersonnelType(personnelType);
995         otherPersonnelInfo.setRole(role);
996 
997         CompensationDto compensationInfo = new CompensationDto();
998         // not sure that we need base salary
999         compensationInfo.setBaseSalary(ScaleTwoDecimal.ZERO);
1000         compensationInfo.setFringe(bdFringe);
1001         compensationInfo.setFundsRequested(bdFunds);
1002         compensationInfo.setRequestedSalary(bdSalary);
1003         compensationInfo.setSummerMonths(new ScaleTwoDecimal(summerMonths));
1004         compensationInfo.setAcademicMonths(new ScaleTwoDecimal(academicMonths));
1005         compensationInfo.setCalendarMonths(new ScaleTwoDecimal(calendarMonths));
1006 
1007         // start add costSaring for fedNonFedBudget report
1008         compensationInfo.setFringeCostSharing(bdFringeCostSharing);
1009         compensationInfo.setNonFundsRequested(bdNonFunds);
1010         compensationInfo.setCostSharingAmount(bdSalaryCostSharing);
1011         // end add costSaring for fedNonFedBudget report
1012 
1013         otherPersonnelInfo.setCompensation(compensationInfo);
1014         return otherPersonnelInfo;
1015     }
1016 
1017     /**
1018      * 
1019      * This method computes the indirect costs for a given {@link org.kuali.coeus.common.budget.api.period.BudgetPeriodContract}
1020      * 
1021      * @param budgetPeriod given BudgetPeriod.
1022      * @return IndirectCostInfo for the corresponding BudgetPeriod object.
1023      */
1024     @Override
1025     public IndirectCostDto getIndirectCosts(BudgetContract budget, BudgetPeriodContract budgetPeriod) {
1026         List<IndirectCostDetailsDto> indirectCostDetailList = new ArrayList<IndirectCostDetailsDto>();
1027         IndirectCostDetailsDto indirectCostDetails;
1028         ScaleTwoDecimal baseCost = ScaleTwoDecimal.ZERO;
1029         ScaleTwoDecimal baseCostSharing = ScaleTwoDecimal.ZERO;
1030         ScaleTwoDecimal calculatedCost = ScaleTwoDecimal.ZERO;
1031         ScaleTwoDecimal calculatedCostSharing = ScaleTwoDecimal.ZERO;
1032         ScaleTwoDecimal appliedRate = ScaleTwoDecimal.ZERO;
1033         ScaleTwoDecimal totalIndirectCosts = ScaleTwoDecimal.ZERO;
1034         ScaleTwoDecimal totalIndirectCostSharing = ScaleTwoDecimal.ZERO;
1035 
1036         String description = "";
1037         boolean firstLoop = true;
1038 
1039         if (budget.getModularBudgetFlag()) {
1040             for (BudgetModularIdcContract budgetModularIdc : budgetPeriod.getBudgetModular().getBudgetModularIdcs()) {
1041                 if (firstLoop) {
1042                     appliedRate = appliedRate.add(budgetModularIdc.getIdcRate());
1043                     description = budgetModularIdc.getDescription();
1044                     firstLoop = false;
1045                 }
1046                 baseCost = baseCost.add(budgetModularIdc.getIdcBase());
1047                 calculatedCost = calculatedCost.add(budgetModularIdc.getFundsRequested());
1048             }
1049             indirectCostDetails = new IndirectCostDetailsDto();
1050             indirectCostDetails.setBase(baseCost);
1051             indirectCostDetails.setBaseCostSharing(baseCostSharing);
1052             indirectCostDetails.setCostSharing(calculatedCostSharing);
1053             indirectCostDetails.setCostType(description);
1054             indirectCostDetails.setFunds(calculatedCost);
1055             indirectCostDetails.setRate(appliedRate);
1056             indirectCostDetailList.add(indirectCostDetails);
1057             totalIndirectCosts = totalIndirectCosts.add(calculatedCost);
1058             totalIndirectCostSharing = totalIndirectCostSharing.add(calculatedCostSharing);
1059         }
1060         else {
1061             Map<String, IndirectCostDetailsDto> costDetailsMap = new HashMap<String, IndirectCostDetailsDto>();
1062             for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
1063                 for (BudgetRateAndBaseContract rateBase : lineItem.getBudgetRateAndBaseList()) {
1064                     RateClassContract rateClass = rateBase.getRateClass();
1065                     if (rateClass.getRateClassType().getCode().equals(RateClassType.OVERHEAD.getRateClassType())) {
1066                         String rateClassCode = rateClass.getCode();
1067                         String rateTypeCode = rateBase.getRateTypeCode();
1068                         appliedRate = rateBase.getAppliedRate();
1069                         StringBuilder keyBuilder = new StringBuilder();
1070                         keyBuilder.append(rateClassCode);
1071                         keyBuilder.append("-");
1072                         keyBuilder.append(rateTypeCode);
1073                         keyBuilder.append("-");
1074                         keyBuilder.append(appliedRate);
1075                         String key = keyBuilder.toString();
1076                         if (costDetailsMap.get(key) == null) {
1077                             indirectCostDetails = new IndirectCostDetailsDto();
1078                             indirectCostDetails.setBase(rateBase.getBaseCost() == null ? ScaleTwoDecimal.ZERO : rateBase
1079                                     .getBaseCost());
1080                             indirectCostDetails.setBaseCostSharing(rateBase.getBaseCostSharing() == null ? ScaleTwoDecimal.ZERO
1081                                     : rateBase.getBaseCostSharing());
1082                             if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1083                                 indirectCostDetails.setCostSharing(rateBase.getCalculatedCostSharing() == null ? ScaleTwoDecimal.ZERO
1084                                         : rateBase.getCalculatedCostSharing());
1085                             }
1086                             indirectCostDetails.setCostType(rateClass.getDescription());
1087                             indirectCostDetails.setFunds(rateBase.getCalculatedCost() == null ? ScaleTwoDecimal.ZERO : rateBase
1088                                     .getCalculatedCost());
1089                             indirectCostDetails.setRate(appliedRate);
1090                         }
1091                         else {
1092                             indirectCostDetails = costDetailsMap.get(key);
1093                             baseCost = indirectCostDetails.getBase().add(
1094                                     rateBase.getBaseCost() == null ? ScaleTwoDecimal.ZERO : rateBase.getBaseCost());
1095                             baseCostSharing = indirectCostDetails.getBaseCostSharing().add(
1096                                     rateBase.getBaseCostSharing() == null ? ScaleTwoDecimal.ZERO : rateBase.getBaseCostSharing());
1097                             calculatedCost = indirectCostDetails.getFunds().add(
1098                                     rateBase.getCalculatedCost() == null ? ScaleTwoDecimal.ZERO : rateBase.getCalculatedCost());
1099                             if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1100                                 calculatedCostSharing = indirectCostDetails.getCostSharing().add(
1101                                         rateBase.getCalculatedCostSharing() == null ? ScaleTwoDecimal.ZERO : rateBase
1102                                                 .getCalculatedCostSharing());
1103                             } else if (!lineItem.getSubmitCostSharingFlag()&& budget.getSubmitCostSharingFlag()) {
1104                                 calculatedCostSharing = indirectCostDetails.getCostSharing();
1105                             }
1106                             indirectCostDetails.setBase(baseCost);
1107                             indirectCostDetails.setBaseCostSharing(baseCostSharing);
1108                             indirectCostDetails.setCostSharing(calculatedCostSharing);
1109                             indirectCostDetails.setFunds(calculatedCost);
1110                         }
1111                         costDetailsMap.put(key, indirectCostDetails);
1112 
1113                         indirectCostDetailList = new ArrayList<IndirectCostDetailsDto>(costDetailsMap.values());
1114                         totalIndirectCosts = totalIndirectCosts.add(rateBase.getCalculatedCost() == null ? ScaleTwoDecimal.ZERO
1115                                 : rateBase.getCalculatedCost());
1116                         if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1117                             totalIndirectCostSharing = totalIndirectCostSharing
1118                                     .add(rateBase.getCalculatedCostSharing() == null ? ScaleTwoDecimal.ZERO : rateBase
1119                                             .getCalculatedCostSharing());
1120                         }
1121                     }
1122                 }
1123             }
1124         }
1125         IndirectCostDto indirectCostInfo = new IndirectCostDto();
1126         indirectCostInfo.setIndirectCostDetails(indirectCostDetailList);
1127         indirectCostInfo.setTotalIndirectCosts(totalIndirectCosts);
1128         indirectCostInfo.setTotalIndirectCostSharing(totalIndirectCostSharing);
1129         return indirectCostInfo;
1130     }
1131 
1132     /**
1133      * 
1134      * This method computes Other Dirtect Costs for the given {@link org.kuali.coeus.common.budget.api.period.BudgetPeriodContract} and Sponsor
1135      * 
1136      * @param budgetPeriod given BudgetPeriod.
1137      * @return List<OtherDirectCostInfo> list of OtherDirectCostInfo corresponding to the BudgetPeriod object.
1138      */
1139     protected List<OtherDirectCostInfoDto> getOtherDirectCosts(BudgetPeriodContract budgetPeriod, BudgetContract budget) {
1140         OtherDirectCostInfoDto otherDirectCostInfo = new OtherDirectCostInfoDto();
1141 
1142         List<CostDto> costInfoList = new ArrayList<CostDto>();
1143         List<String> filterTargetCategoryCodes = new ArrayList<String>();
1144         filterTargetCategoryCodes.add(s2SConfigurationService.getValueAsString(
1145                 ConfigurationConstants.S2SBUDGET_TARGET_CATEGORY_CODE_EQUIPMENT_COST));
1146         List<String> filterCategoryTypes = new ArrayList<String>();
1147         filterCategoryTypes.add(s2SConfigurationService.getValueAsString(
1148                 ConfigurationConstants.S2SBUDGET_FILTER_CATEGORY_TYPE_PERSONNEL));
1149         List<? extends BudgetCategoryMapContract> budgetCategoryMapList = getBudgetCategoryMapList(filterTargetCategoryCodes, filterCategoryTypes);
1150 
1151         boolean recordAdded;
1152         for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
1153             for (BudgetCategoryMapContract budgetCategoryMap : budgetCategoryMapList) {
1154                 recordAdded = false;
1155                 for (BudgetCategoryMappingContract budgetCategoryMapping : budgetCategoryMap.getBudgetCategoryMappings()) {
1156                     if (lineItem.getBudgetCategory().getCode().equals(budgetCategoryMapping.getBudgetCategoryCode())) {
1157                         CostDto costInfo = new CostDto();
1158                         costInfo.setBudgetPeriod(budgetPeriod.getBudgetPeriod().intValue());
1159                         costInfo.setCost(lineItem.getLineItemCost());
1160                         if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1161                             costInfo.setCostSharing(lineItem.getCostSharingAmount());
1162                         }
1163                         costInfo.setCategory(budgetCategoryMap.getDescription());
1164                         costInfo.setCategoryType(budgetCategoryMap.getCategoryType());
1165                         if (lineItem.getQuantity() != null) {
1166                             costInfo.setQuantity(lineItem.getQuantity());
1167                         }
1168                         costInfoList.add(costInfo);
1169                         recordAdded = true;
1170                         break;
1171                     }
1172                 }
1173                 if (recordAdded) {
1174                     break;
1175                 }
1176             }
1177 
1178             CostDto lineItemcostInfo = new CostDto();
1179             lineItemcostInfo.setBudgetPeriod(budgetPeriod.getBudgetPeriod().intValue());
1180             lineItemcostInfo.setCategory(OTHER_DIRECT_COSTS);
1181             lineItemcostInfo.setCategoryType(CATEGORY_TYPE_OTHER_DIRECT_COST);
1182             lineItemcostInfo.setQuantity(1);
1183 
1184             ScaleTwoDecimal totalCost = ScaleTwoDecimal.ZERO;
1185             ScaleTwoDecimal totalCostSharing = ScaleTwoDecimal.ZERO;
1186             for (BudgetLineItemCalculatedAmountContract lineItemCalculatedAmt : lineItem.getBudgetLineItemCalculatedAmounts()) {
1187                 if (lineItemCalculatedAmt
1188                         .getRateClass()
1189                         .getRateClassType().getCode()
1190                         .equals(s2SConfigurationService.getValueAsString(
1191                                 ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_SALARIES_MS))) {
1192                     totalCost = totalCost.add(lineItemCalculatedAmt.getCalculatedCost());
1193                     if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1194                         totalCostSharing = totalCostSharing.add(lineItemCalculatedAmt.getCalculatedCostSharing());
1195                     }
1196                 }
1197             }
1198             lineItemcostInfo.setCost(totalCost);
1199             if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1200                 lineItemcostInfo.setCostSharing(totalCostSharing);
1201             }
1202             StringBuilder description = new StringBuilder();
1203             description.append(DESCRIPTION_LA);
1204             description.append(totalCost);
1205             description.append(";");
1206             lineItemcostInfo.setDescription(description.toString());
1207             costInfoList.add(lineItemcostInfo);
1208         }
1209 
1210         ScaleTwoDecimal totalOtherDirect = ScaleTwoDecimal.ZERO;
1211         ScaleTwoDecimal totalTravelCost = ScaleTwoDecimal.ZERO;
1212         ScaleTwoDecimal totalParticipantCost = ScaleTwoDecimal.ZERO;
1213         ScaleTwoDecimal totalOtherDirectCostSharing = ScaleTwoDecimal.ZERO;
1214 
1215         ScaleTwoDecimal totalTravelCostSharing = ScaleTwoDecimal.ZERO;
1216         ScaleTwoDecimal totalParticipantCostSharing = ScaleTwoDecimal.ZERO;
1217 
1218         ScaleTwoDecimal materialCost = ScaleTwoDecimal.ZERO;
1219         ScaleTwoDecimal materialCostSharing = ScaleTwoDecimal.ZERO;
1220         ScaleTwoDecimal consultantCost = ScaleTwoDecimal.ZERO;
1221         ScaleTwoDecimal consultantCostSharing = ScaleTwoDecimal.ZERO;
1222         ScaleTwoDecimal publicationCost = ScaleTwoDecimal.ZERO;
1223         ScaleTwoDecimal publicationCostSharing = ScaleTwoDecimal.ZERO;
1224         ScaleTwoDecimal computerCost = ScaleTwoDecimal.ZERO;
1225         ScaleTwoDecimal computerCostSharing = ScaleTwoDecimal.ZERO;
1226         ScaleTwoDecimal alterationsCost = ScaleTwoDecimal.ZERO;
1227         ScaleTwoDecimal alterationsCostSharing = ScaleTwoDecimal.ZERO;
1228         ScaleTwoDecimal subContractCost = ScaleTwoDecimal.ZERO;
1229         ScaleTwoDecimal subContractCostSharing = ScaleTwoDecimal.ZERO;
1230         ScaleTwoDecimal equipmentRentalCost = ScaleTwoDecimal.ZERO;
1231         ScaleTwoDecimal equipmentRentalCostSharing = ScaleTwoDecimal.ZERO;
1232         ScaleTwoDecimal domesticTravelCost = ScaleTwoDecimal.ZERO;
1233         ScaleTwoDecimal domesticTravelCostSharing = ScaleTwoDecimal.ZERO;
1234         ScaleTwoDecimal foreignTravelCost = ScaleTwoDecimal.ZERO;
1235         ScaleTwoDecimal foreignTravelCostSharing = ScaleTwoDecimal.ZERO;
1236         ScaleTwoDecimal partStipendsCost = ScaleTwoDecimal.ZERO;
1237         ScaleTwoDecimal partStipendsCostSharing = ScaleTwoDecimal.ZERO;
1238         ScaleTwoDecimal partTravelCost = ScaleTwoDecimal.ZERO;
1239         ScaleTwoDecimal partTravelCostSharing = ScaleTwoDecimal.ZERO;
1240         ScaleTwoDecimal partTuitionCost = ScaleTwoDecimal.ZERO;
1241         ScaleTwoDecimal partTuitionCostSharing = ScaleTwoDecimal.ZERO;
1242         ScaleTwoDecimal partSubsistenceCost = ScaleTwoDecimal.ZERO;
1243         ScaleTwoDecimal partSubsistenceCostSharing = ScaleTwoDecimal.ZERO;
1244         ScaleTwoDecimal partOtherCost = ScaleTwoDecimal.ZERO;
1245         ScaleTwoDecimal partOtherCostSharing = ScaleTwoDecimal.ZERO;
1246         ScaleTwoDecimal otherDirectCost = ScaleTwoDecimal.ZERO;
1247         ScaleTwoDecimal otherDirectCostSharing = ScaleTwoDecimal.ZERO;
1248         ScaleTwoDecimal otherCost = ScaleTwoDecimal.ZERO;
1249         ScaleTwoDecimal otherCostSharing = ScaleTwoDecimal.ZERO;
1250 
1251         for (CostDto costInfo : costInfoList) {
1252             if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1253                     ConfigurationConstants.S2SBUDGET_MATERIALS_AND_SUPPLIES_CATEGORY))) {
1254                 materialCost = materialCost.add(costInfo.getCost());
1255                 if (budget.getSubmitCostSharingFlag()) {
1256                     materialCostSharing = materialCostSharing.add(costInfo.getCostSharing());
1257                 }
1258             }
1259             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1260                     ConfigurationConstants.S2SBUDGET_CONSULTANT_COSTS_CATEGORY))) {
1261                 consultantCost = consultantCost.add(costInfo.getCost());
1262                 if (budget.getSubmitCostSharingFlag()) {
1263                     consultantCostSharing = consultantCostSharing.add(costInfo.getCostSharing());
1264                 }
1265             }
1266             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1267                     ConfigurationConstants.S2SBUDGET_PUBLICATION_COSTS_CATEGORY))) {
1268                 publicationCost = publicationCost.add(costInfo.getCost());
1269                 if (budget.getSubmitCostSharingFlag()) {
1270                     publicationCostSharing = publicationCostSharing.add(costInfo.getCostSharing());
1271                 }
1272             }
1273             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1274                     ConfigurationConstants.S2SBUDGET_COMPUTER_SERVICES_CATEGORY))) {
1275                 computerCost = computerCost.add(costInfo.getCost());
1276                 if (budget.getSubmitCostSharingFlag()) {
1277                     computerCostSharing = computerCostSharing.add(costInfo.getCostSharing());
1278                 }
1279             }
1280             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1281                     ConfigurationConstants.S2SBUDGET_ALTERATIONS_CATEGORY))) {
1282                 alterationsCost = alterationsCost.add(costInfo.getCost());
1283                 if (budget.getSubmitCostSharingFlag()) {
1284                     alterationsCostSharing = alterationsCostSharing.add(costInfo.getCostSharing());
1285                 }
1286             }
1287             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1288                     ConfigurationConstants.S2SBUDGET_SUBCONTRACT_CATEGORY))) {
1289                 subContractCost = subContractCost.add(costInfo.getCost());
1290                 if (budget.getSubmitCostSharingFlag()) {
1291                     subContractCostSharing = subContractCostSharing.add(costInfo.getCostSharing());
1292                 }
1293             }
1294             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1295                     ConfigurationConstants.S2SBUDGET_EQUIPMENT_RENTAL_CATEGORY))) {
1296                 equipmentRentalCost = equipmentRentalCost.add(costInfo.getCost());
1297                 if (budget.getSubmitCostSharingFlag()) {
1298                     equipmentRentalCostSharing = equipmentRentalCostSharing.add(costInfo.getCostSharing());
1299                 }
1300             }
1301             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1302                     ConfigurationConstants.S2SBUDGET_DOMESTIC_TRAVEL_CATEGORY))) {
1303                 domesticTravelCost = domesticTravelCost.add(costInfo.getCost());
1304                 if (budget.getSubmitCostSharingFlag()) {
1305                     domesticTravelCostSharing = domesticTravelCostSharing.add(costInfo.getCostSharing());
1306                 }
1307             }
1308             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1309                     ConfigurationConstants.S2SBUDGET_FOREIGN_TRAVEL_CATEGORY))) {
1310                 foreignTravelCost = foreignTravelCost.add(costInfo.getCost());
1311                 if (budget.getSubmitCostSharingFlag()) {
1312                     foreignTravelCostSharing = foreignTravelCostSharing.add(costInfo.getCostSharing());
1313                 }
1314             }
1315             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1316                     ConfigurationConstants.S2SBUDGET_PARTICIPANT_STIPENDS_CATEGORY))) {
1317                 partStipendsCost = partStipendsCost.add(costInfo.getCost());
1318                 if (budget.getSubmitCostSharingFlag()) {
1319                     partStipendsCostSharing = partStipendsCostSharing.add(costInfo.getCostSharing());
1320                     totalParticipantCostSharing = totalParticipantCostSharing.add(costInfo.getCostSharing());
1321                 }
1322                 totalParticipantCost = totalParticipantCost.add(costInfo.getCost());
1323             }
1324             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1325                     ConfigurationConstants.S2SBUDGET_PARTICIPANT_TRAVEL_CATEGORY))) {
1326                 partTravelCost = partTravelCost.add(costInfo.getCost());
1327                 if (budget.getSubmitCostSharingFlag()) {
1328                     partTravelCostSharing = partTravelCostSharing.add(costInfo.getCostSharing());
1329                     totalParticipantCostSharing = totalParticipantCostSharing.add(costInfo.getCostSharing());
1330                 }
1331                 totalParticipantCost = totalParticipantCost.add(costInfo.getCost());
1332             }
1333             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1334                     ConfigurationConstants.S2SBUDGET_PARTICIPANT_TUITION_CATEGORY))) {
1335                 partTuitionCost = partTuitionCost.add(costInfo.getCost());
1336                 if (budget.getSubmitCostSharingFlag()) {
1337                     partTuitionCostSharing = partTuitionCostSharing.add(costInfo.getCostSharing());
1338                     totalParticipantCostSharing = totalParticipantCostSharing.add(costInfo.getCostSharing());
1339                 }
1340                 totalParticipantCost = totalParticipantCost.add(costInfo.getCost());
1341             }
1342             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1343                     ConfigurationConstants.S2SBUDGET_PARTICIPANT_SUBSISTENCE_CATEGORY))) {
1344                 partSubsistenceCost = partSubsistenceCost.add(costInfo.getCost());
1345                 if (budget.getSubmitCostSharingFlag()) {
1346                     partSubsistenceCostSharing = partSubsistenceCostSharing.add(costInfo.getCostSharing());
1347                     totalParticipantCostSharing = totalParticipantCostSharing.add(costInfo.getCostSharing());
1348                 }
1349                 totalParticipantCost = totalParticipantCost.add(costInfo.getCost());
1350             }
1351             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1352                     ConfigurationConstants.S2SBUDGET_PARTICIPANT_OTHER_CATEGORY))) {
1353                 partOtherCost = partOtherCost.add(costInfo.getCost());
1354                 if (budget.getSubmitCostSharingFlag()) {
1355                     partOtherCostSharing = partOtherCostSharing.add(costInfo.getCostSharing());
1356                     totalParticipantCostSharing = totalParticipantCostSharing.add(costInfo.getCostSharing());
1357                 }
1358                 totalParticipantCost = totalParticipantCost.add(costInfo.getCost());
1359             }
1360             else if (costInfo.getCategory().equals(s2SConfigurationService.getValueAsString(
1361                     ConfigurationConstants.S2SBUDGET_OTHER_DIRECT_COSTS_CATEGORY))) {
1362                 otherDirectCost = otherDirectCost.add(costInfo.getCost());
1363                 if (budget.getSubmitCostSharingFlag()) {
1364                     otherDirectCostSharing = otherDirectCostSharing.add(costInfo.getCostSharing());
1365                 }
1366             }
1367             else {
1368                 otherCost = otherCost.add(costInfo.getCost());
1369                 if (budget.getSubmitCostSharingFlag()) {
1370                     otherCostSharing = otherCostSharing.add(costInfo.getCostSharing());
1371                 }
1372             }
1373         }
1374 
1375         otherDirectCostInfo.setmaterials(materialCost);
1376         otherDirectCostInfo.setMaterialsCostSharing(materialCostSharing);
1377         otherDirectCostInfo.setConsultants(consultantCost);
1378         otherDirectCostInfo.setConsultantsCostSharing(consultantCostSharing);
1379         otherDirectCostInfo.setpublications(publicationCost);
1380         otherDirectCostInfo.setPublicationsCostSharing(publicationCostSharing);
1381         otherDirectCostInfo.setcomputer(computerCost);
1382         otherDirectCostInfo.setComputerCostSharing(computerCostSharing);
1383         otherDirectCostInfo.setAlterations(alterationsCost);
1384         otherDirectCostInfo.setAlterationsCostSharing(alterationsCostSharing);
1385         otherDirectCostInfo.setsubAwards(subContractCost);
1386         otherDirectCostInfo.setSubAwardsCostSharing(subContractCostSharing);
1387         otherDirectCostInfo.setEquipRental(equipmentRentalCost);
1388         otherDirectCostInfo.setEquipRentalCostSharing(equipmentRentalCostSharing);
1389         otherDirectCostInfo.setDomTravel(domesticTravelCost);
1390         otherDirectCostInfo.setDomTravelCostSharing(domesticTravelCostSharing);
1391         otherDirectCostInfo.setForeignTravel(foreignTravelCost);
1392         otherDirectCostInfo.setForeignTravelCostSharing(foreignTravelCostSharing);
1393         otherDirectCostInfo.setPartStipends(partStipendsCost);
1394         otherDirectCostInfo.setPartStipendsCostSharing(partStipendsCostSharing);
1395         otherDirectCostInfo.setPartTravel(partTravelCost);
1396         otherDirectCostInfo.setPartTravelCostSharing(partTravelCostSharing);
1397         otherDirectCostInfo.setPartTuition(partTuitionCost);
1398         otherDirectCostInfo.setPartTuitionCostSharing(partTuitionCostSharing);
1399         otherDirectCostInfo.setPartSubsistence(partSubsistenceCost);
1400         otherDirectCostInfo.setPartSubsistenceCostSharing(partSubsistenceCostSharing);
1401         otherDirectCostInfo.setPartOther(partOtherCost);
1402         otherDirectCostInfo.setPartOtherCostSharing(partOtherCostSharing);
1403         otherDirectCostInfo.setParticipantTotal(totalParticipantCost);
1404         otherDirectCostInfo.setParticipantTotalCostSharing(totalParticipantCostSharing);
1405         otherDirectCostInfo.setParticipantTotalCount(budgetPeriod.getNumberOfParticipants() == null ? 0 : budgetPeriod.getNumberOfParticipants());
1406 
1407         totalOtherDirect = totalOtherDirect.add(materialCost);
1408         totalOtherDirect = totalOtherDirect.add(consultantCost);
1409         totalOtherDirect = totalOtherDirect.add(publicationCost);
1410         totalOtherDirect = totalOtherDirect.add(computerCost);
1411         totalOtherDirect = totalOtherDirect.add(alterationsCost);
1412         totalOtherDirect = totalOtherDirect.add(subContractCost);
1413         totalOtherDirect = totalOtherDirect.add(equipmentRentalCost);
1414         totalOtherDirect = totalOtherDirect.add(otherDirectCost);
1415         totalOtherDirect = totalOtherDirect.add(otherCost);
1416 
1417         totalTravelCost = totalTravelCost.add(domesticTravelCost);
1418         totalTravelCost = totalTravelCost.add(foreignTravelCost);
1419         if (budget.getSubmitCostSharingFlag()) {
1420             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(materialCostSharing);
1421             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(consultantCostSharing);
1422             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(publicationCostSharing);
1423             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(computerCostSharing);
1424             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(alterationsCostSharing);
1425             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(subContractCostSharing);
1426             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(equipmentRentalCostSharing);
1427             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(otherDirectCostSharing);
1428             totalOtherDirectCostSharing = totalOtherDirectCostSharing.add(otherCostSharing);
1429 
1430             totalTravelCostSharing = totalTravelCostSharing.add(domesticTravelCostSharing);
1431             totalTravelCostSharing = totalTravelCostSharing.add(foreignTravelCostSharing);
1432         }
1433         otherDirectCostInfo.settotalOtherDirect(totalOtherDirect);
1434         otherDirectCostInfo.setTotalOtherDirectCostSharing(totalOtherDirectCostSharing);
1435         otherDirectCostInfo.setTotTravel(totalTravelCost);
1436         otherDirectCostInfo.setTotTravelCostSharing(totalTravelCostSharing);
1437 
1438         List<Map<String, String>> otherCostDetails = new ArrayList<Map<String, String>>();
1439         Map<String, String> hmOtherDirectCostDetails = new HashMap<String, String>();
1440         hmOtherDirectCostDetails.put(CostConstants.KEY_COST, otherDirectCost.toString());
1441         hmOtherDirectCostDetails
1442                 .put(DESCRIPTION,OTHER_DIRECT_COSTS);
1443         hmOtherDirectCostDetails.put(CostConstants.KEY_COSTSHARING, otherDirectCostSharing.toString());
1444         otherCostDetails.add(hmOtherDirectCostDetails);
1445 
1446         Map<String, String> hmOtherCostDetails = new HashMap<String, String>();
1447         hmOtherCostDetails.put(CostConstants.KEY_COST, otherCost.toString());
1448         hmOtherCostDetails
1449                 .put(DESCRIPTION,ALL_OTHER_COSTS);
1450         hmOtherCostDetails.put(CostConstants.KEY_COSTSHARING, otherCostSharing.toString());
1451         otherCostDetails.add(hmOtherCostDetails);
1452 
1453         otherDirectCostInfo.setOtherCosts(otherCostDetails);
1454         List<OtherDirectCostInfoDto> otherDirectCosts = new ArrayList<OtherDirectCostInfoDto>();
1455         otherDirectCosts.add(otherDirectCostInfo);
1456         return otherDirectCosts;
1457     }
1458 
1459     private boolean canBudgetLineItemCostSharingInclude(BudgetContract budget, BudgetLineItemContract lineItem) {
1460         return budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag();
1461     }
1462 
1463     /**
1464      * This method returns a list of BudgetCategoryMap based on the input. The list returned will not contain the categories that
1465      * the codes passed as a list of String and also will not contain those that match the types passed as list of String. In case 2
1466      * empty lists are passed as parameters, the method will return entire list without applying any filters.
1467      * 
1468      * @param filterTargetCategoryCodes Category Codes that must be filtered
1469      * @param filterCategoryTypes Category types that must be filtered
1470      * @return a List of BudgetCategoryMap.
1471      * @see org.kuali.coeus.s2sgen.impl.budget.S2SBudgetCalculatorService#getBudgetCategoryMapList(java.util.List, java.util.List)
1472      */
1473     @Override
1474     public List<? extends BudgetCategoryMapContract> getBudgetCategoryMapList(List<String> filterTargetCategoryCodes, List<String> filterCategoryTypes) {
1475         List<? extends BudgetCategoryMappingContract> budgetCategoryMappingList;
1476         List<BudgetCategoryMapContract> budgetCategoryMapList = new ArrayList<BudgetCategoryMapContract>();
1477         budgetCategoryMappingList = budgetCategoryMapService.findCatMappingByMappingName(SPONSOR);
1478 
1479         boolean targetMatched;
1480         boolean duplicateExists;
1481         for (BudgetCategoryMappingContract categoryMapping : budgetCategoryMappingList) {
1482             targetMatched = true;
1483             // Apply mapping list filtering only if targetCategoryCodes size>0
1484             if (filterTargetCategoryCodes.size() > 0) {
1485                 for (String targetCategoryCode : filterTargetCategoryCodes) {
1486                     if (categoryMapping.getTargetCategoryCode().equals(targetCategoryCode)) {
1487                         targetMatched = false;
1488                         break;
1489                     }
1490                 }
1491             }
1492 
1493             if (targetMatched) {
1494                 Iterator<? extends BudgetCategoryMapContract> filterList = budgetCategoryMapService.findCatMapByTargetAndMappingName(
1495                         categoryMapping.getTargetCategoryCode(), categoryMapping.getMappingName()).iterator();
1496 
1497                 while (filterList.hasNext()) {
1498                     BudgetCategoryMapContract filterMap = filterList.next();
1499                     targetMatched = true;
1500                     if (filterCategoryTypes.size() > 0) {
1501                         for (String categoryType : filterCategoryTypes) {
1502                             if (filterMap.getCategoryType().trim().equals(categoryType.trim())) {
1503                                 targetMatched = false;
1504                                 break;
1505                             }
1506                         }
1507                     }
1508 
1509                     if (targetMatched) {
1510                         // Avoid adding duplicates to list
1511                         duplicateExists = false;
1512                         for (BudgetCategoryMapContract map : budgetCategoryMapList) {
1513                             if (filterMap.getTargetCategoryCode().equals(map.getTargetCategoryCode())) {
1514                                 duplicateExists = true;
1515                                 break;
1516                             }
1517                         }
1518                         if (!duplicateExists) {
1519                             budgetCategoryMapList.add(filterMap);
1520                         }
1521                     }
1522                 }
1523             }
1524         }
1525         return budgetCategoryMapList;
1526     }
1527 
1528     /**
1529      * 
1530      * This method computes the Equipment Costs for a given {@link org.kuali.coeus.common.budget.api.period.BudgetPeriodContract}
1531      * 
1532      * @param budgetPeriod given BudgetPeriod.
1533      * @return List<EquipmentInfo> list of equipment cost corresponding to the BudgetPeriod object.
1534      */
1535     protected List<EquipmentDto> getEquipment(BudgetPeriodContract budgetPeriod, BudgetContract budget) {
1536         List<CostDto> cvExtraEquipment = new ArrayList<CostDto>();
1537         CostDto equipCostInfo;
1538         List<? extends BudgetCategoryMapContract> budgetCategoryMapList = getBudgetCategoryMapList(new ArrayList<String>(), new ArrayList<String>());
1539 
1540         ScaleTwoDecimal totalEquipFund = ScaleTwoDecimal.ZERO;
1541         ScaleTwoDecimal totalExtraEquipFund = ScaleTwoDecimal.ZERO;
1542         ScaleTwoDecimal totalEquipNonFund = ScaleTwoDecimal.ZERO;
1543         ScaleTwoDecimal totalExtraEquipNonFund = ScaleTwoDecimal.ZERO;
1544         Map<String, CostDto> costInfoMap = new HashMap<String, CostDto>();
1545         List<CostDto> costInfos = new ArrayList<CostDto>();
1546         for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
1547             for (BudgetCategoryMapContract budgetCategoryMap : budgetCategoryMapList) {
1548                 equipCostInfo = new CostDto();
1549                 for (BudgetCategoryMappingContract budgetCategoryMapping : budgetCategoryMap.getBudgetCategoryMappings()) {
1550                     if (lineItem.getBudgetCategory().getCode().equals(budgetCategoryMapping.getBudgetCategoryCode())
1551                             && (budgetCategoryMapping.getTargetCategoryCode().equals( s2SConfigurationService.getValueAsString(
1552                             ConfigurationConstants.S2SBUDGET_TARGET_CATEGORY_CODE_EQUIPMENT_COST)))
1553                             && (budgetCategoryMapping.getMappingName().equals(SPONSOR))) {
1554                         equipCostInfo.setBudgetPeriod(budgetPeriod.getBudgetPeriod().intValue());
1555                         equipCostInfo.setCategory(budgetCategoryMap.getDescription());
1556                         equipCostInfo.setCategoryType(budgetCategoryMap.getCategoryType());
1557                         if (lineItem.getLineItemDescription() != null)
1558                             equipCostInfo.setDescription(lineItem.getLineItemDescription());
1559                         else
1560                             equipCostInfo.setDescription(lineItem.getCostElementBO().getDescription());
1561                         totalEquipFund = totalEquipFund.add(lineItem.getLineItemCost());
1562                         if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1563                             totalEquipNonFund = totalEquipNonFund.add(lineItem.getCostSharingAmount());
1564                         }
1565 
1566                         StringBuilder keyBuilder = new StringBuilder();
1567                         keyBuilder.append(budgetCategoryMap.getCategoryType());
1568                         keyBuilder.append("-");
1569                         keyBuilder.append(lineItem.getLineItemDescription());
1570                         String key = keyBuilder.toString();
1571                         if (costInfoMap.get(key) == null) {
1572                             equipCostInfo = new CostDto();
1573                             equipCostInfo.setBudgetPeriod(budgetPeriod.getBudgetPeriod().intValue());
1574                             equipCostInfo.setCategory(budgetCategoryMap.getDescription());
1575                             equipCostInfo.setCategoryType(budgetCategoryMap.getCategoryType());
1576                             if (lineItem.getLineItemDescription() != null)
1577                                 equipCostInfo.setDescription(lineItem.getLineItemDescription());
1578                             else
1579                                 equipCostInfo.setDescription(lineItem.getCostElementBO().getDescription());
1580                             equipCostInfo.setCost(lineItem.getLineItemCost());
1581                             if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1582                                 equipCostInfo.setCostSharing(lineItem.getCostSharingAmount());
1583                             }
1584                         }
1585                         else {
1586                             equipCostInfo = costInfoMap.get(key);
1587                             equipCostInfo.setCost(equipCostInfo.getCost().add(lineItem.getLineItemCost()));
1588                             if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1589                                 equipCostInfo.setCostSharing(equipCostInfo.getCostSharing().add(lineItem.getCostSharingAmount()));
1590                             }
1591                         }
1592                         if (StringUtils.isNotEmpty(lineItem.getLineItemDescription())) {
1593                             costInfoMap.put(key, equipCostInfo);
1594                         }
1595                         costInfos.add(equipCostInfo);
1596                     }
1597                 }
1598             }
1599         }
1600         EquipmentDto equipmentInfo = new EquipmentDto();
1601 
1602         if (costInfos.size() > 10) {
1603             for (int j = costInfos.size() - 1; j > 9; j--) {
1604                 cvExtraEquipment.add(costInfos.get(j));
1605                 CostDto extraCostInfo = (CostDto) costInfos.get(j);
1606                 totalExtraEquipFund = totalExtraEquipFund.add(extraCostInfo.getCost());
1607                 totalExtraEquipNonFund = totalExtraEquipNonFund.add(extraCostInfo.getCostSharing());
1608                 costInfos.remove(j);
1609             }
1610             Collections.reverse(cvExtraEquipment);
1611             equipmentInfo.setExtraEquipmentList(cvExtraEquipment);
1612             equipmentInfo.setTotalExtraNonFund(totalExtraEquipNonFund);
1613         }
1614         equipmentInfo.setTotalExtraFund(totalExtraEquipFund);
1615 
1616         equipmentInfo.setEquipmentList(costInfos);
1617         equipmentInfo.setTotalFund(totalEquipFund);
1618         equipmentInfo.setTotalNonFund(totalEquipNonFund);
1619 
1620         List<EquipmentDto> equipmentInfos = new ArrayList<EquipmentDto>();
1621         equipmentInfos.add(equipmentInfo);
1622         return equipmentInfos;
1623     }
1624 
1625     /**
1626      * This method gets the {@link List} of Key Persons for a given {@link ProposalDevelopmentDocumentContract}
1627      * 
1628      * @param budgetPeriod given BudgetPeriod.
1629      * @param pdDoc Proposal Development Document.
1630      * @param numKeyPersons number of key persons.
1631      * @return List<List<KeyPersonInfo>> list of KeyPersonInfo list.
1632      */
1633     protected List<List<KeyPersonDto>> getKeyPersons(BudgetPeriodContract budgetPeriod, ProposalDevelopmentDocumentContract pdDoc,
1634             int numKeyPersons, BudgetContract budget) {
1635         List<KeyPersonDto> keyPersons = new ArrayList<KeyPersonDto>();
1636         List<KeyPersonDto> seniorPersons = new ArrayList<KeyPersonDto>();
1637         KeyPersonDto keyPerson = new KeyPersonDto();
1638         ProposalPersonContract principalInvestigator = s2SProposalPersonService.getPrincipalInvestigator(pdDoc);
1639 
1640         // Create master list of contacts
1641         List<ProposalPersonContract> propPersons = new ArrayList<ProposalPersonContract>();
1642         if (principalInvestigator != null) {
1643             propPersons.add(principalInvestigator);
1644             keyPerson.setPersonId(principalInvestigator.getPersonId());
1645             keyPerson.setRolodexId(principalInvestigator.getRolodexId());
1646             keyPerson.setFirstName(principalInvestigator.getFirstName() == null ? FieldValueConstants.VALUE_UNKNOWN
1647                     : principalInvestigator.getFirstName());
1648             keyPerson.setLastName(principalInvestigator.getLastName() == null ? FieldValueConstants.VALUE_UNKNOWN : principalInvestigator
1649                     .getLastName());
1650             keyPerson.setMiddleName(principalInvestigator.getMiddleName());
1651             keyPerson.setRole(PRINCIPAL_INVESTIGATOR_ROLE);
1652             keyPerson.setNonMITPersonFlag(isPersonNonMITPerson(principalInvestigator));
1653             keyPersons.add(keyPerson);
1654         }
1655 
1656         for (ProposalPersonContract coInvestigator : s2SProposalPersonService.getCoInvestigators(pdDoc)) {
1657             propPersons.add(coInvestigator);
1658             keyPerson = new KeyPersonDto();
1659             keyPerson.setPersonId(coInvestigator.getPersonId());
1660             keyPerson.setRolodexId(coInvestigator.getRolodexId());
1661             keyPerson.setFirstName(coInvestigator.getFirstName() == null ? FieldValueConstants.VALUE_UNKNOWN : coInvestigator
1662                     .getFirstName());
1663             keyPerson.setLastName(coInvestigator.getLastName() == null ? FieldValueConstants.VALUE_UNKNOWN : coInvestigator.getLastName());
1664             keyPerson.setMiddleName(coInvestigator.getMiddleName());
1665             keyPerson.setNonMITPersonFlag(isPersonNonMITPerson(coInvestigator));
1666 
1667             if (sponsorHierarchyService.isSponsorNihMultiplePi(pdDoc.getDevelopmentProposal().getSponsor().getSponsorCode())) {
1668                 if (coInvestigator.isMultiplePi()){
1669                     keyPerson.setRole(NID_PD_PI);
1670                 }else{
1671                     keyPerson.setRole(NID_CO_PD_PI);
1672                 }
1673             }else{
1674                 keyPerson.setRole(KEYPERSON_CO_PD_PI);
1675             }
1676             keyPersons.add(keyPerson);
1677         }
1678 
1679         for (ProposalPersonContract propPerson : s2SProposalPersonService.getKeyPersons(pdDoc)) {
1680             propPersons.add(propPerson);
1681             keyPerson = new KeyPersonDto();
1682             keyPerson.setPersonId(propPerson.getPersonId());
1683             keyPerson.setRolodexId(propPerson.getRolodexId());
1684             keyPerson.setFirstName(propPerson.getFirstName() == null ? FieldValueConstants.VALUE_UNKNOWN : propPerson.getFirstName());
1685             keyPerson.setLastName(propPerson.getLastName() == null ? FieldValueConstants.VALUE_UNKNOWN : propPerson.getLastName());
1686             keyPerson.setMiddleName(propPerson.getMiddleName());
1687             keyPerson.setNonMITPersonFlag(isPersonNonMITPerson(propPerson));
1688 
1689             keyPerson.setRole(getBudgetPersonRoleOther());
1690             keyPerson.setKeyPersonRole(propPerson.getProjectRole());
1691             keyPersons.add(keyPerson);
1692         }
1693 
1694         boolean personAlreadyAdded = false;
1695         List<? extends BudgetCategoryMappingContract> budgetCategoryList = budgetCategoryMapService.findCatMappingByTargetAndMappingName(TARGET_CATEGORY_CODE_01, SPONSOR);
1696         for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
1697             for (BudgetPersonnelDetailsContract budgetPersonnelDetails : lineItem.getBudgetPersonnelDetailsList()) {
1698                 personAlreadyAdded = false;
1699                 for (ProposalPersonContract proposalPerson : pdDoc.getDevelopmentProposal().getProposalPersons()) {
1700                     if (proposalPersonEqualsBudgetPerson(proposalPerson, budgetPersonnelDetails)) {
1701                         personAlreadyAdded = true;
1702                         break;
1703                     }
1704                 }
1705                 if (!personAlreadyAdded) {
1706                     if (budgetPersonnelDetails.getBudgetPerson().getNonEmployeeFlag()) {
1707                         if (budgetPersonnelDetails.getBudgetPerson().getRolodexId() != null) {
1708                             RolodexContract rolodexPerson = rolodexService.getRolodex(budgetPersonnelDetails.getBudgetPerson().getRolodexId());
1709                             keyPerson = new KeyPersonDto();
1710                             keyPerson.setRolodexId(rolodexPerson.getRolodexId());
1711                             keyPerson.setFirstName(rolodexPerson.getFirstName() == null ? FieldValueConstants.VALUE_UNKNOWN
1712                                     : rolodexPerson.getFirstName());
1713                             keyPerson.setLastName(rolodexPerson.getLastName() == null ? FieldValueConstants.VALUE_UNKNOWN : rolodexPerson
1714                                     .getLastName());
1715                             keyPerson.setMiddleName(rolodexPerson.getMiddleName());
1716                             keyPerson.setRole(StringUtils.isNotBlank(rolodexPerson.getTitle()) ? rolodexPerson.getTitle()
1717                                     : getBudgetPersonRoleOther());
1718                             keyPerson.setNonMITPersonFlag(true);
1719 
1720                             if (isSeniorLineItem(budgetCategoryList, lineItem.getBudgetCategory().getCode())) {
1721                                 keyPersons.add(keyPerson);
1722                             }
1723                         }else if (StringUtils.isNotBlank(budgetPersonnelDetails.getBudgetPerson().getTbnId())) {
1724                             TbnPersonContract tbnPerson = tbnPersonService.getTbnPerson(budgetPersonnelDetails.getBudgetPerson().getTbnId());
1725                             if (tbnPerson != null) {
1726                                 keyPerson = new KeyPersonDto();
1727                                 String[] tbnNames = tbnPerson.getPersonName().split(" ");
1728                                 int nameIndex = 0;
1729                                 keyPerson.setPersonId(tbnPerson.getId());
1730                                 keyPerson.setFirstName(tbnNames.length >= 1 ? tbnNames[nameIndex++] : FieldValueConstants.VALUE_UNKNOWN);
1731                                 keyPerson.setMiddleName(tbnNames.length >= 3 ? tbnNames[nameIndex++] : " ");
1732                                 keyPerson.setLastName(tbnNames.length >= 2 ? tbnNames[nameIndex++] : FieldValueConstants.VALUE_UNKNOWN);
1733                                 keyPerson.setRole(tbnPerson.getPersonName());
1734                                 keyPerson.setNonMITPersonFlag(false);
1735 
1736                                 if (isSeniorLineItem( budgetCategoryList, lineItem.getBudgetCategory().getCode())) {
1737                                     keyPersons.add(keyPerson);
1738                                 }
1739 
1740                             }
1741                         }
1742                     }else {
1743 
1744                         KcPersonContract kcPerson = kcPersonRepositoryService.findKcPersonByPersonId(budgetPersonnelDetails.getBudgetPerson().getPersonId());
1745                         if (kcPerson != null) {
1746                             keyPerson = new KeyPersonDto();
1747                             keyPerson.setPersonId(kcPerson.getPersonId());
1748                             keyPerson.setFirstName(kcPerson.getFirstName() == null ? FieldValueConstants.VALUE_UNKNOWN : kcPerson
1749                                     .getFirstName());
1750                             keyPerson.setLastName(kcPerson.getLastName() == null ? FieldValueConstants.VALUE_UNKNOWN : kcPerson
1751                                     .getLastName());
1752                             keyPerson.setMiddleName(kcPerson.getMiddleName());
1753                             keyPerson.setNonMITPersonFlag(false);
1754                             keyPerson.setRole(getBudgetPersonRoleOther());
1755                             if (isSeniorLineItem( budgetCategoryList, lineItem.getBudgetCategory().getCode())) {
1756                                 keyPersons.add(keyPerson);
1757                             }
1758                         }
1759                     }
1760                 }
1761             }
1762         }
1763         for(KeyPersonDto seniorPerson : keyPersons){
1764             if(seniorPerson.getRole().equals(NID_PD_PI)||hasPersonnelBudget(budgetPeriod,seniorPerson)){
1765                 seniorPersons.add(seniorPerson);
1766             }            
1767         }
1768 
1769         List<KeyPersonDto> nKeyPersons = getNKeyPersons(seniorPersons, true, numKeyPersons);
1770         List<KeyPersonDto> extraPersons = getNKeyPersons(seniorPersons, false, numKeyPersons);
1771         CompensationDto compensationInfo;
1772         for (KeyPersonDto keyPersonInfo : nKeyPersons) {
1773             keyPerson = keyPersonInfo;
1774             compensationInfo = getCompensation(keyPerson, budgetPeriod, pdDoc.getDevelopmentProposal().getProposalNumber(), budget);
1775             keyPerson.setAcademicMonths(compensationInfo.getAcademicMonths());
1776             keyPerson.setCalendarMonths(compensationInfo.getCalendarMonths());
1777             keyPerson.setSummerMonths(compensationInfo.getSummerMonths());
1778             keyPerson.setBaseSalary(compensationInfo.getBaseSalary());
1779             keyPerson.setRequestedSalary(compensationInfo.getRequestedSalary());
1780             keyPerson.setFundsRequested(compensationInfo.getFundsRequested());
1781             keyPerson.setFringe(compensationInfo.getFringe());
1782             // start add costSaring for fedNonFedBudget report
1783             keyPerson.setCostSharingAmount(compensationInfo.getCostSharingAmount());
1784             keyPerson.setNonFundsRequested(compensationInfo.getNonFundsRequested());
1785             keyPerson.setFringeCostSharing(compensationInfo.getFringeCostSharing());
1786             // end add costSaring for fedNonFedBudget report
1787         }
1788 
1789         if (extraPersons != null) {
1790             for (KeyPersonDto keyPersonInfo : extraPersons) {
1791                 keyPerson = keyPersonInfo;
1792                 compensationInfo = getCompensation(keyPerson, budgetPeriod, pdDoc.getDevelopmentProposal().getProposalNumber(), budget);
1793 
1794                 keyPerson.setAcademicMonths(compensationInfo.getAcademicMonths());
1795                 keyPerson.setCalendarMonths(compensationInfo.getCalendarMonths());
1796                 keyPerson.setSummerMonths(compensationInfo.getSummerMonths());
1797                 keyPerson.setBaseSalary(compensationInfo.getBaseSalary());
1798                 keyPerson.setRequestedSalary(compensationInfo.getRequestedSalary());
1799                 keyPerson.setFundsRequested(compensationInfo.getFundsRequested());
1800                 keyPerson.setFringe(compensationInfo.getFringe());
1801                 // start add costSaring for fedNonFedBudget report
1802                 keyPerson.setCostSharingAmount(compensationInfo.getCostSharingAmount());
1803                 keyPerson.setNonFundsRequested(compensationInfo.getNonFundsRequested());
1804                 keyPerson.setFringeCostSharing(compensationInfo.getFringeCostSharing());
1805                 // end add costSaring for fedNonFedBudget report
1806             }
1807         }
1808 
1809         List<List<KeyPersonDto>> listKeyPersons = new ArrayList<List<KeyPersonDto>>();
1810         listKeyPersons.add(nKeyPersons);
1811         listKeyPersons.add(extraPersons);
1812         return listKeyPersons;
1813     }
1814 
1815     private Boolean hasPersonnelBudget(BudgetPeriodContract budgetPeriod,KeyPersonDto keyPerson){
1816 
1817         for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
1818             for (BudgetPersonnelDetailsContract budgetPersonnelDetails : lineItem.getBudgetPersonnelDetailsList()) {
1819                 if( budgetPersonnelDetails.getPersonId().equals(keyPerson.getPersonId())){
1820                     return true;
1821                 } 
1822             }
1823         }
1824         return false;
1825     }
1826 
1827     private String getBudgetPersonRoleOther() {
1828         return KEYPERSON_OTHER;
1829     }
1830 
1831     private boolean isSeniorLineItem(List<? extends BudgetCategoryMappingContract> budgetCategoryList, String budgetCategoryCode) {
1832         boolean isSeniorLineItem = false;
1833         for (BudgetCategoryMappingContract categoryMapping : budgetCategoryList) {
1834             if (categoryMapping.getBudgetCategoryCode().equals(budgetCategoryCode)) {
1835                 isSeniorLineItem = true;
1836             }
1837         }
1838         return isSeniorLineItem;
1839     }
1840 
1841     protected boolean proposalPersonEqualsBudgetPerson(ProposalPersonContract proposalPerson, BudgetPersonnelDetailsContract budgetPersonnelDetails) {
1842         boolean equal = false;
1843         if (proposalPerson != null && budgetPersonnelDetails != null) {
1844             String budgetPersonId = budgetPersonnelDetails.getPersonId();
1845             if ((proposalPerson.getPersonId() != null && proposalPerson.getPersonId().equals(budgetPersonId))
1846                     || (proposalPerson.getRolodexId() != null && proposalPerson.getRolodexId().toString().equals(budgetPersonId))) {
1847                 equal = true;
1848             }
1849         }
1850         return equal;
1851     }
1852 
1853     /**
1854      * This method determines whether a {@link org.kuali.coeus.propdev.api.person.ProposalPersonContract} is a Non MIT person
1855      * 
1856      * @param proposalPerson ProposalPerson.
1857      * @return boolean true if Non MIT Person false otherwise.
1858      * @see org.kuali.coeus.s2sgen.impl.budget.S2SBudgetCalculatorService#isPersonNonMITPerson(ProposalPersonContract)
1859      */
1860     @Override
1861     public boolean isPersonNonMITPerson(ProposalPersonContract proposalPerson) {
1862         return proposalPerson.getPersonId() == null;
1863     }
1864 
1865     /**
1866      * 
1867      * This method computes the CompensationInfo for given person, {@link org.kuali.coeus.common.budget.api.period.BudgetPeriodContract} and Proposal Numnber
1868      * 
1869      * @param keyPerson id of the proposal person.
1870      * @param budgetPeriod given BudgetPeriod.
1871      * @param proposalNumber propsal number.
1872      * 
1873      * @return {@link CompensationDto} corresponding to the personId,budgetPeriod and proposalNumber.
1874      */
1875     protected CompensationDto getCompensation(KeyPersonDto keyPerson, BudgetPeriodContract budgetPeriod, String proposalNumber, BudgetContract budget) {
1876         CompensationDto compensationInfo = new CompensationDto();
1877         BigDecimal summerMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
1878         BigDecimal academicMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
1879         BigDecimal calendarMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
1880         ScaleTwoDecimal totalSal = ScaleTwoDecimal.ZERO;
1881         ScaleTwoDecimal fringe = ScaleTwoDecimal.ZERO;
1882         ScaleTwoDecimal baseAmount = ScaleTwoDecimal.ZERO;
1883         ScaleTwoDecimal totalSalCostSharing = ScaleTwoDecimal.ZERO;
1884         ScaleTwoDecimal fringeCostSharing = ScaleTwoDecimal.ZERO;
1885         BigDecimal numberOfMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
1886         String budgetCatagoryCodePersonnel = s2SConfigurationService.getValueAsString(
1887                 ConfigurationConstants.S2SBUDGET_BUDGET_CATEGORY_CODE_PERSONNEL);
1888         
1889         for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
1890             
1891             for (BudgetPersonnelDetailsContract personDetails : lineItem.getBudgetPersonnelDetailsList()) {
1892                 if (keyPersonEqualsBudgetPerson(keyPerson, personDetails)) {
1893                     numberOfMonths = s2SDateTimeService.getNumberOfMonths(personDetails.getStartDate(), personDetails.getEndDate()).bigDecimalValue();
1894                     if (personDetails.getPeriodTypeCode().equals(
1895                             s2SConfigurationService.getValueAsString(
1896                                     ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_ACADEMIC_MONTHS))) {
1897                         if (lineItem.getSubmitCostSharingFlag()) {
1898                             academicMonths = academicMonths.add(personDetails.getPercentEffort().bigDecimalValue()
1899                                     .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
1900                         } else {
1901                             academicMonths = academicMonths.add(personDetails.getPercentCharged().bigDecimalValue()
1902                                     .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
1903                         }
1904                     }
1905                     else if (personDetails.getPeriodTypeCode().equals(
1906                             s2SConfigurationService.getValueAsString(
1907                                     ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_SUMMER_MONTHS))) {
1908                         if (lineItem.getSubmitCostSharingFlag()) {
1909                             summerMonths = summerMonths.add(personDetails.getPercentEffort().bigDecimalValue().multiply(numberOfMonths)
1910                                     .multiply(POINT_ZERO_ONE));
1911                         } else {
1912                             summerMonths = summerMonths.add(personDetails.getPercentCharged().bigDecimalValue().multiply(numberOfMonths)
1913                                     .multiply(POINT_ZERO_ONE));
1914                         }
1915                     }
1916                     else {
1917                         if (StringUtils.isNotBlank(personDetails.getBudgetPerson().getTbnId())) {
1918                             if (lineItem.getBudgetCategory()
1919                                     .getCode().equals(budgetCatagoryCodePersonnel)) {
1920                                 if (lineItem.getSubmitCostSharingFlag()) {
1921                                     calendarMonths = calendarMonths.add(personDetails.getPercentEffort().bigDecimalValue().multiply(numberOfMonths)
1922                                             .multiply(POINT_ZERO_ONE));
1923                                 } else {
1924                                     calendarMonths = calendarMonths.add(personDetails.getPercentCharged().bigDecimalValue().multiply(numberOfMonths)
1925                                             .multiply(POINT_ZERO_ONE));
1926                                 }
1927                             } 
1928                         }else {
1929                             if (lineItem.getSubmitCostSharingFlag()) {
1930                                 calendarMonths = calendarMonths.add(personDetails.getPercentEffort().bigDecimalValue().multiply(numberOfMonths)
1931                                         .multiply(POINT_ZERO_ONE));
1932                             }
1933                             else {
1934                                 calendarMonths = calendarMonths.add(personDetails.getPercentCharged().bigDecimalValue().multiply(numberOfMonths)
1935                                         .multiply(POINT_ZERO_ONE));
1936                             }
1937                         }
1938                     }
1939                     if (StringUtils.isNotBlank(personDetails.getBudgetPerson().getTbnId() ) ){
1940                         if(lineItem.getBudgetCategory()
1941                                 .getCode().equals(budgetCatagoryCodePersonnel)){
1942                                     totalSal = totalSal.add(personDetails.getSalaryRequested());
1943                                 }
1944                     }else{
1945                         totalSal = totalSal.add(personDetails.getSalaryRequested());
1946                     }
1947                     if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1948                         if (StringUtils.isNotBlank(personDetails.getBudgetPerson().getTbnId() ) ){
1949                             if(lineItem.getBudgetCategory()
1950                                     .getCode().equals(budgetCatagoryCodePersonnel)){
1951                         totalSalCostSharing = totalSalCostSharing.add(personDetails.getCostSharingAmount());
1952                             }
1953                         }else{
1954                             totalSalCostSharing = totalSalCostSharing.add(personDetails.getCostSharingAmount());
1955                         }
1956                     }
1957                     for (BudgetPersonnelCalculatedAmountContract personCalculatedAmt : personDetails.getBudgetPersonnelCalculatedAmounts()) {
1958                         if ((personCalculatedAmt
1959                                 .getRateClass()
1960                                 .getRateClassType().getCode()
1961                                 .equals(s2SConfigurationService.getValueAsString(
1962                                         ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_EMPLOYEE_BENEFITS)) && !personCalculatedAmt
1963                                 .getRateTypeCode().equals(
1964                                         s2SConfigurationService.getValueAsString(
1965                                                 ConfigurationConstants.S2SBUDGET_RATE_TYPE_SUPPORT_STAFF_SALARIES)))
1966                                 || (personCalculatedAmt
1967                                         .getRateClass()
1968                                         .getRateClassType().getCode()
1969                                         .equals(s2SConfigurationService.getValueAsString(
1970                                                 ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_VACATION)) && !personCalculatedAmt
1971                                         .getRateTypeCode().equals(
1972                                                 s2SConfigurationService.getValueAsString(
1973                                                         ConfigurationConstants.S2SBUDGET_RATE_TYPE_ADMINISTRATIVE_SALARIES)))) {
1974                             if (StringUtils.isNotBlank(personDetails.getBudgetPerson().getTbnId() ) ){
1975                                 if(lineItem.getBudgetCategory()
1976                                         .getCode().equals(budgetCatagoryCodePersonnel)){
1977                                     fringe = fringe.add(personCalculatedAmt.getCalculatedCost());
1978                                 }
1979                             }
1980                             else{
1981                                 fringe = fringe.add(personCalculatedAmt.getCalculatedCost());
1982                             }
1983                             if (canBudgetLineItemCostSharingInclude(budget, lineItem)) {
1984                                 if (StringUtils.isNotBlank(personDetails.getBudgetPerson().getTbnId() ) ){
1985                                     if(lineItem.getBudgetCategory()
1986                                             .getCode().equals(budgetCatagoryCodePersonnel)){
1987                                         fringeCostSharing = fringeCostSharing.add(personCalculatedAmt.getCalculatedCostSharing());
1988                                     }
1989                                 }
1990                                 else{ 
1991                                     fringeCostSharing = fringeCostSharing.add(personCalculatedAmt.getCalculatedCostSharing());
1992                                 }
1993                             }
1994                         }
1995                     }
1996                     BudgetPersonContract budgetPerson = personDetails.getBudgetPerson();
1997                     if (budgetPerson != null) {
1998                         baseAmount = budgetPerson.getCalculationBase();
1999                         // baseAmount must be set to the first record value in
2000                         // case
2001                         // the execution doesnt enter the if condition below
2002                         String apptTypeCode = budgetPerson.getAppointmentType().getCode();
2003                         if (!apptTypeCode.equals(s2SConfigurationService.getValueAsString(
2004                                 ConfigurationConstants.S2SBUDGET_APPOINTMENT_TYPE_SUM_EMPLOYEE))
2005                                 && !apptTypeCode.equals(s2SConfigurationService.getValueAsString(
2006                                 ConfigurationConstants.S2SBUDGET_APPOINTMENT_TYPE_TMP_EMPLOYEE))) {
2007                             baseAmount = budgetPerson.getCalculationBase();
2008                         }
2009                     }
2010                 }
2011 
2012             }
2013         }
2014         compensationInfo.setAcademicMonths(new ScaleTwoDecimal(academicMonths));
2015         compensationInfo.setCalendarMonths(new ScaleTwoDecimal(calendarMonths));
2016         compensationInfo.setSummerMonths(new ScaleTwoDecimal(summerMonths));
2017         compensationInfo.setRequestedSalary(totalSal);
2018         compensationInfo.setBaseSalary(baseAmount);
2019         compensationInfo.setCostSharingAmount(totalSalCostSharing);
2020         compensationInfo.setFringe(fringe);
2021         compensationInfo.setFundsRequested(totalSal.add(fringe));
2022         compensationInfo.setFringeCostSharing(fringeCostSharing);
2023         compensationInfo.setNonFundsRequested(totalSalCostSharing.add(fringeCostSharing));
2024         return compensationInfo;
2025     }
2026 
2027 
2028     /**
2029      * 
2030      * This method limits the number of key persons to n, returns list of key persons, first n in case firstN is true, or all other
2031      * than first n, in case of firstN being false
2032      * 
2033      * @param keyPersons list of {@link KeyPersonDto}
2034      * @param firstN value that determines whether the returned list should contain first n persons or the rest of persons
2035      * @param n number of key persons that are considered as not extra persons
2036      * @return list of {@link KeyPersonDto}
2037      */
2038     protected List<KeyPersonDto> getNKeyPersons(List<KeyPersonDto> keyPersons, boolean firstN, int n) {
2039         KeyPersonDto keyPersonInfo, previousKeyPersonInfo;
2040         int size = keyPersons.size();
2041 
2042         for (int i = size - 1; i > 0; i--) {
2043             keyPersonInfo = (KeyPersonDto) (keyPersons.get(i));
2044             previousKeyPersonInfo = (KeyPersonDto) (keyPersons.get(i - 1));
2045             if (keyPersonInfo.getPersonId() != null && previousKeyPersonInfo.getPersonId() != null
2046                     && keyPersonInfo.getPersonId().equals(previousKeyPersonInfo.getPersonId())) {
2047                 keyPersons.remove(i);
2048             }
2049             else if (keyPersonInfo.getRolodexId() != null && previousKeyPersonInfo.getRolodexId() != null
2050                     && keyPersonInfo.getRolodexId().equals(previousKeyPersonInfo.getRolodexId())) {
2051                 keyPersons.remove(i);
2052             }
2053         }
2054 
2055         size = keyPersons.size();
2056         if (firstN) {
2057             List<KeyPersonDto> firstNPersons = new ArrayList<KeyPersonDto>();
2058 
2059             // Make sure we don't exceed the size of the list.
2060             if (size > n) {
2061                 size = n;
2062             }
2063             // remove extras
2064             for (int i = 0; i < size; i++) {
2065                 firstNPersons.add(keyPersons.get(i));
2066             }
2067             return firstNPersons;
2068         }
2069         else {
2070             // return extra people
2071             List<KeyPersonDto> extraPersons = new ArrayList<KeyPersonDto>();
2072             for (int i = n; i < size; i++) {
2073                 extraPersons.add(keyPersons.get(i));
2074             }
2075             return extraPersons;
2076         }
2077     }
2078 
2079     @Override
2080     public ScaleTwoDecimal getBaseSalaryByPeriod(Long budgetId, int budgetPeriod, KeyPersonDto person ) {
2081         return budgetPersonSalaryService.findBaseSalaryForFirstPeriod(budgetId, person.getPersonId() != null ? person.getPersonId() : person.getRolodexId().toString(), budgetPeriod);
2082     }
2083 
2084     /**
2085      * This method compares a key person with budget person. It checks whether the key person is from PERSON or ROLODEX and matches
2086      * the respective person ID with the person in {@link org.kuali.coeus.common.budget.api.personnel.BudgetPersonnelDetailsContract}
2087      *
2088      * @param keyPersonInfo - key person to compare
2089      * @param budgetPersonnelDetails person from BudgetPersonnelDetails
2090      * @return true if persons match, false otherwise
2091      */
2092     @Override
2093     public boolean keyPersonEqualsBudgetPerson(KeyPersonDto keyPersonInfo, BudgetPersonnelDetailsContract budgetPersonnelDetails) {
2094         boolean equal = false;
2095         if (keyPersonInfo != null && budgetPersonnelDetails != null) {
2096             String budgetPersonId = budgetPersonnelDetails.getPersonId();
2097             if ((keyPersonInfo.getPersonId() != null && keyPersonInfo.getPersonId().equals(budgetPersonId))
2098                     || (keyPersonInfo.getRolodexId() != null && keyPersonInfo.getRolodexId().toString().equals(budgetPersonId))) {
2099                 equal = true;
2100             }
2101         }
2102         return equal;
2103     }
2104 
2105     public void setBudgetCategoryMapService(BudgetCategoryMapService budgetCategoryMapService) {
2106         this.budgetCategoryMapService = budgetCategoryMapService;
2107     }
2108 
2109     public BudgetCategoryMapService getBudgetCategoryMapService() {
2110         return budgetCategoryMapService;
2111     }
2112 
2113     public S2SConfigurationService getS2SConfigurationService() {
2114         return s2SConfigurationService;
2115     }
2116 
2117     public void setS2SConfigurationService(S2SConfigurationService s2SConfigurationService) {
2118         this.s2SConfigurationService = s2SConfigurationService;
2119     }
2120 
2121     public BudgetPersonSalaryService getBudgetPersonSalaryService() {
2122         return budgetPersonSalaryService;
2123     }
2124 
2125     public void setBudgetPersonSalaryService(BudgetPersonSalaryService budgetPersonSalaryService) {
2126         this.budgetPersonSalaryService = budgetPersonSalaryService;
2127     }
2128 
2129     public OrganizationRepositoryService getOrganizationRepositoryService() {
2130         return organizationRepositoryService;
2131     }
2132 
2133     public void setOrganizationRepositoryService(OrganizationRepositoryService organizationRepositoryService) {
2134         this.organizationRepositoryService = organizationRepositoryService;
2135     }
2136 
2137     public SponsorHierarchyService getSponsorHierarchyService() {
2138         return sponsorHierarchyService;
2139     }
2140 
2141     public void setSponsorHierarchyService(SponsorHierarchyService sponsorHierarchyService) {
2142         this.sponsorHierarchyService = sponsorHierarchyService;
2143     }
2144 
2145     public KcPersonRepositoryService getKcPersonRepositoryService() {
2146         return kcPersonRepositoryService;
2147     }
2148 
2149     public void setKcPersonRepositoryService(KcPersonRepositoryService kcPersonRepositoryService) {
2150         this.kcPersonRepositoryService = kcPersonRepositoryService;
2151     }
2152 
2153     public TbnPersonService getTbnPersonService() {
2154         return tbnPersonService;
2155     }
2156 
2157     public void setTbnPersonService(TbnPersonService tbnPersonService) {
2158         this.tbnPersonService = tbnPersonService;
2159     }
2160 
2161     public RolodexService getRolodexService() {
2162         return rolodexService;
2163     }
2164 
2165     public void setRolodexService(RolodexService rolodexService) {
2166         this.rolodexService = rolodexService;
2167     }
2168 
2169     public S2SDateTimeService getS2SDateTimeService() {
2170         return s2SDateTimeService;
2171     }
2172 
2173     public void setS2SDateTimeService(S2SDateTimeService s2SDateTimeService) {
2174         this.s2SDateTimeService = s2SDateTimeService;
2175     }
2176 
2177     public S2SProposalPersonService getS2SProposalPersonService() {
2178         return s2SProposalPersonService;
2179     }
2180 
2181     public void setS2SProposalPersonService(S2SProposalPersonService s2SProposalPersonService) {
2182         this.s2SProposalPersonService = s2SProposalPersonService;
2183     }
2184 
2185     public S2SErrorHandlerService getS2SErrorHandlerService() {
2186         return s2SErrorHandlerService;
2187     }
2188 
2189     public void setS2SErrorHandlerService(S2SErrorHandlerService s2SErrorHandlerService) {
2190         this.s2SErrorHandlerService = s2SErrorHandlerService;
2191     }
2192 
2193     public S2SCommonBudgetService getS2SCommonBudgetService() {
2194         return s2SCommonBudgetService;
2195     }
2196 
2197     public void setS2SCommonBudgetService(S2SCommonBudgetService s2SCommonBudgetService) {
2198         this.s2SCommonBudgetService = s2SCommonBudgetService;
2199     }
2200 }