001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.kra.budget.web.struts.form;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.List;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.util.KualiInteger;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.kra.KraConstants;
028: import org.kuali.module.kra.budget.bo.BudgetAbstractCostShare;
029: import org.kuali.module.kra.budget.bo.BudgetAbstractPeriodCostShare;
030: import org.kuali.module.kra.budget.bo.BudgetInstitutionCostShare;
031: import org.kuali.module.kra.budget.bo.BudgetNonpersonnel;
032: import org.kuali.module.kra.budget.bo.BudgetPeriod;
033: import org.kuali.module.kra.budget.bo.BudgetTaskPeriodIndirectCost;
034: import org.kuali.module.kra.budget.bo.BudgetThirdPartyCostShare;
035: import org.kuali.module.kra.budget.bo.BudgetUser;
036: import org.kuali.module.kra.budget.bo.InstitutionCostSharePersonnel;
037: import org.kuali.module.kra.budget.bo.UserAppointmentTask;
038: import org.kuali.module.kra.budget.bo.UserAppointmentTaskPeriod;
039: import org.kuali.module.kra.budget.service.BudgetPeriodService;
040:
041: /**
042: * Used by UI to get totals, counts, aggregations, and other things to render the Cost Share page.
043: */
044: public class BudgetCostShareFormHelper {
045:
046: private BudgetPeriodService budgetPeriodService;
047:
048: private Direct institutionDirect;
049: private Direct thirdPartyDirect;
050:
051: private List<Subcontractor> subcontractors = new ArrayList();
052:
053: // Totals Section, arrays are the period totals while the total* values are the period array summations
054: private KualiInteger[] institutionIndirectCostShare;
055: private KualiInteger[] subcontractorCostShare;
056: private KualiInteger[] total;
057: private KualiInteger totalInstitutionIndirectCostShare = new KualiInteger(
058: 0);
059: private KualiInteger totalSubcontractorCostShare = new KualiInteger(
060: 0);
061: private KualiInteger totalTotal = new KualiInteger(0);
062:
063: public BudgetCostShareFormHelper() {
064: budgetPeriodService = SpringContext
065: .getBean(BudgetPeriodService.class);
066: }
067:
068: /**
069: * Constructor for the BudgetCostShareFormHelper object. Convenience argument of BudgetForm.
070: *
071: * @param budgetForm
072: */
073: public BudgetCostShareFormHelper(BudgetForm budgetForm) {
074: this (budgetForm.getBudgetDocument().getBudget().getPeriods(),
075: budgetForm.getBudgetDocument().getBudget()
076: .getPersonnel(), budgetForm.getBudgetDocument()
077: .getBudget().getNonpersonnelItems(), budgetForm
078: .getBudgetDocument().getBudget()
079: .getInstitutionCostSharePersonnelItems(),
080: budgetForm.getBudgetDocument().getBudget()
081: .getInstitutionCostShareItems(), budgetForm
082: .getBudgetDocument().getBudget()
083: .getThirdPartyCostShareItems(), budgetForm
084: .getBudgetIndirectCostFormHelper());
085: }
086:
087: /**
088: * Constructor for the BudgetCostShareFormHelper object. Initializes all sections in order for the Cost Share page to function.
089: *
090: * @param periods
091: * @param personnel
092: * @param budgetNonpersonnelItems
093: * @param institutionCostSharePersonnel
094: * @param budgetInstitutionCostShare
095: * @param budgetThirdPartyCostShare
096: * @param budgetIndirectCostFormHelper
097: */
098: public BudgetCostShareFormHelper(
099: List<BudgetPeriod> periods,
100: List<BudgetUser> personnel,
101: List<BudgetNonpersonnel> budgetNonpersonnelItems,
102: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel,
103: List<BudgetInstitutionCostShare> budgetInstitutionCostShare,
104: List<BudgetThirdPartyCostShare> budgetThirdPartyCostShare,
105: BudgetIndirectCostFormHelper budgetIndirectCostFormHelper) {
106: this ();
107:
108: // Subcontractors has to happen before 3rd Party Direct so that it can calculate correct totals.
109: setupSubcontractors(periods, budgetNonpersonnelItems);
110:
111: setupDirect(periods, personnel, budgetNonpersonnelItems,
112: institutionCostSharePersonnel,
113: budgetInstitutionCostShare, budgetThirdPartyCostShare);
114:
115: setupTotals(periods, budgetIndirectCostFormHelper);
116: }
117:
118: /**
119: * Constructor for the BudgetCostShareFormHelper object. Initializes direct (institution & third party) sections in order for
120: * audit mode to do its checks.
121: *
122: * @param periods
123: * @param personnel
124: * @param budgetNonpersonnelItems
125: * @param institutionCostSharePersonnel
126: * @param budgetInstitutionCostShare
127: * @param budgetThirdPartyCostShare
128: */
129: public BudgetCostShareFormHelper(
130: List<BudgetPeriod> periods,
131: List<BudgetUser> personnel,
132: List<BudgetNonpersonnel> budgetNonpersonnelItems,
133: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel,
134: List<BudgetInstitutionCostShare> budgetInstitutionCostShare,
135: List<BudgetThirdPartyCostShare> budgetThirdPartyCostShare) {
136: this ();
137:
138: setupDirect(periods, personnel, budgetNonpersonnelItems,
139: institutionCostSharePersonnel,
140: budgetInstitutionCostShare, budgetThirdPartyCostShare);
141: }
142:
143: /**
144: * Initializes the Institution & 3rd Party sections. Method should really be private but easier to access it from
145: * BudgetCostShareFormHelperTest this way.
146: *
147: * @param periods
148: * @param nonpersonnelItems
149: * @param budgetInstitutionCostShare
150: * @param budgetThirdPartyCostShare
151: */
152: private void setupDirect(
153: List<BudgetPeriod> periods,
154: List<BudgetUser> personnel,
155: List<BudgetNonpersonnel> budgetNonpersonnelItems,
156: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel,
157: List<BudgetInstitutionCostShare> budgetInstitutionCostShare,
158: List<BudgetThirdPartyCostShare> budgetThirdPartyCostShare) {
159: institutionDirect = new Direct(periods, personnel,
160: budgetNonpersonnelItems, institutionCostSharePersonnel,
161: budgetInstitutionCostShare);
162: thirdPartyDirect = new Direct(subcontractorCostShare, periods,
163: budgetNonpersonnelItems, budgetThirdPartyCostShare);
164: }
165:
166: /**
167: * Initializes the Subcontractor section. Method should really be private but easier to access it from
168: * BudgetCostShareFormHelperTest this way.
169: *
170: * @param periods
171: * @param nonpersonnelItems
172: */
173: private void setupSubcontractors(List<BudgetPeriod> periods,
174: List<BudgetNonpersonnel> nonpersonnelItems) {
175: HashMap<String, Subcontractor> addedSubcontractors = new HashMap();
176:
177: subcontractorCostShare = new KualiInteger[periods.size()];
178: Arrays.fill(subcontractorCostShare, new KualiInteger(0));
179:
180: // Loop and check below assumes origin items are always found before copy over items. Sort to make sure.
181: Collections.sort(nonpersonnelItems);
182:
183: // Go over each budgetNonpersonnel item, but only look at the subcontractor ones
184: for (BudgetNonpersonnel budgetNonpersonnel : nonpersonnelItems) {
185: // With the if statement below and the hashMap we aggregate nonpersonnel items that span several periods. This is
186: // similar to
187: // what can be found in BudgetNonpersonnelCopyOverHelper.NonpersonnelCopyOverCategoryHelper.addBudgetNonpersonnelItem.
188: if (KraConstants.SUBCONTRACTOR_CATEGORY_CODE
189: .equals(budgetNonpersonnel
190: .getBudgetNonpersonnelCategoryCode())) {
191: int periodIndex = budgetPeriodService.getPeriodIndex(
192: budgetNonpersonnel
193: .getBudgetPeriodSequenceNumber(),
194: periods);
195:
196: // Update total that displays at the bottom of the page
197: subcontractorCostShare[periodIndex] = subcontractorCostShare[periodIndex]
198: .add(budgetNonpersonnel
199: .getBudgetThirdPartyCostShareAmount());
200: totalSubcontractorCostShare = totalSubcontractorCostShare
201: .add(budgetNonpersonnel
202: .getBudgetThirdPartyCostShareAmount());
203:
204: if (addedSubcontractors.containsKey(budgetNonpersonnel
205: .getSubcontractorNumber())) {
206: Subcontractor subcontractor = addedSubcontractors
207: .get(budgetNonpersonnel
208: .getSubcontractorNumber());
209:
210: subcontractor.addPeriodAmount(budgetNonpersonnel
211: .getBudgetThirdPartyCostShareAmount(),
212: periodIndex);
213: } else {
214: Subcontractor subcontractor = new Subcontractor(
215: budgetNonpersonnel, periods.size(),
216: periodIndex);
217:
218: subcontractors.add(subcontractor);
219: addedSubcontractors.put(budgetNonpersonnel
220: .getSubcontractorNumber(), subcontractor);
221: }
222: }
223: }
224: }
225:
226: /**
227: * Initializes the Totals section. Method should really be private but easier to access it from BudgetCostShareFormHelperTest
228: * this way. It assumes that other setup methods already ran because the grand total calculation relies on certain numbers being
229: * present.
230: *
231: * @param budgetIndirectCostFormHelper
232: * @param periods
233: */
234: private void setupTotals(List<BudgetPeriod> periods,
235: BudgetIndirectCostFormHelper budgetIndirectCostFormHelper) {
236: // Deal with indirect cost totals first. They are all calculated in the helper.
237: institutionIndirectCostShare = new KualiInteger[periods.size()];
238: for (int i = 0; i < institutionIndirectCostShare.length; i++) {
239: BudgetTaskPeriodIndirectCost budgetTaskPeriodIndirectCost = (BudgetTaskPeriodIndirectCost) budgetIndirectCostFormHelper
240: .getPeriodTotals().get(i);
241:
242: institutionIndirectCostShare[i] = budgetTaskPeriodIndirectCost
243: .getCostShareCalculatedIndirectCost()
244: .add(
245: budgetTaskPeriodIndirectCost
246: .getCostShareUnrecoveredIndirectCost());
247: totalInstitutionIndirectCostShare = totalInstitutionIndirectCostShare
248: .add(institutionIndirectCostShare[i]);
249: }
250:
251: // Deal with the grand total. This assums other setup methods ran.
252: total = new KualiInteger[periods.size()];
253: for (int i = 0; i < total.length; i++) {
254: total[i] = institutionDirect.getAmountDistributed()[i]
255: .add(institutionIndirectCostShare[i]
256: .add(thirdPartyDirect
257: .getAmountDistributed()[i]
258: .add(subcontractorCostShare[i])));
259: totalTotal = totalTotal.add(total[i]);
260: }
261: }
262:
263: /**
264: * Gets the institutionDirect attribute.
265: *
266: * @return Returns the institutionDirect.
267: */
268: public Direct getInstitutionDirect() {
269: return institutionDirect;
270: }
271:
272: /**
273: * Gets the thirdPartyDirect attribute.
274: *
275: * @return Returns the thirdPartyDirect.
276: */
277: public Direct getThirdPartyDirect() {
278: return thirdPartyDirect;
279: }
280:
281: /**
282: * Gets the subcontractors attribute.
283: *
284: * @return Returns the subcontractors.
285: */
286: public List<Subcontractor> getSubcontractors() {
287: return subcontractors;
288: }
289:
290: /**
291: * Gets the institutionIndirectCostShare attribute.
292: *
293: * @return Returns the institutionIndirectCostShare.
294: */
295: public KualiInteger[] getInstitutionIndirectCostShare() {
296: return institutionIndirectCostShare;
297: }
298:
299: /**
300: * Gets the subcontractorCostShare attribute.
301: *
302: * @return Returns the subcontractorCostShare.
303: */
304: public KualiInteger[] getSubcontractorCostShare() {
305: return subcontractorCostShare;
306: }
307:
308: /**
309: * Gets the total attribute.
310: *
311: * @return Returns the total.
312: */
313: public KualiInteger[] getTotal() {
314: return total;
315: }
316:
317: /**
318: * Gets the totalInstitutionIndirectCostShare attribute.
319: *
320: * @return Returns the totalInstitutionIndirectCostShare.
321: */
322: public KualiInteger getTotalInstitutionIndirectCostShare() {
323: return totalInstitutionIndirectCostShare;
324: }
325:
326: /**
327: * Gets the totalSubcontractorCostShare attribute.
328: *
329: * @return Returns the totalSubcontractorCostShare.
330: */
331: public KualiInteger getTotalSubcontractorCostShare() {
332: return totalSubcontractorCostShare;
333: }
334:
335: /**
336: * Gets the totalTotal attribute.
337: *
338: * @return Returns the totalTotal.
339: */
340: public KualiInteger getTotalTotal() {
341: return totalTotal;
342: }
343:
344: /**
345: * Inner helper class that assists in the management of the data for the Institution & 3rd party direct section.
346: */
347: public class Direct {
348: private KualiInteger[] totalBudgeted;
349: private KualiInteger[] amountDistributed;
350: private KualiInteger[] balanceToBeDistributed;
351: private KualiInteger totalTotalBudgeted = new KualiInteger(0);
352: private KualiInteger totalAmountDistributed = new KualiInteger(
353: 0);
354: private KualiInteger totalBalanceToBeDistributed = new KualiInteger(
355: 0);
356:
357: private KualiInteger[] totalSource;
358:
359: // Following fields are only used for institution direct cost share. That is the only one that imports the personnel
360: // amounts.
361: private KualiInteger[][] institutionDirectPersonnel;
362: private KualiInteger[] totalInstitutionDirectPersonnel;
363:
364: /**
365: * Constructs a BudgetCostShareFormHelper, helper constructor with common variable initializations.
366: *
367: * @param periodsSize
368: * @param sourceSize
369: */
370: public Direct(int periodsSize, int sourceSize) {
371: // Initialize variables and fill the arrays with 0 values
372: totalBudgeted = new KualiInteger[periodsSize];
373: amountDistributed = new KualiInteger[periodsSize];
374: balanceToBeDistributed = new KualiInteger[periodsSize];
375: Arrays.fill(totalBudgeted, new KualiInteger(0));
376: Arrays.fill(amountDistributed, new KualiInteger(0));
377: Arrays.fill(balanceToBeDistributed, new KualiInteger(0));
378:
379: totalSource = new KualiInteger[sourceSize];
380: Arrays.fill(totalSource, new KualiInteger(0));
381: }
382:
383: /**
384: * Constructs a BudgetCostShareFormHelper with institution cost share values.
385: *
386: * @param periods
387: * @param personnel
388: * @param budgetNonpersonnelItems
389: * @param budgetThirdPartyCostShareItems
390: */
391: public Direct(
392: List<BudgetPeriod> periods,
393: List<BudgetUser> personnel,
394: List<BudgetNonpersonnel> budgetNonpersonnelItems,
395: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel,
396: List<BudgetInstitutionCostShare> budgetInstitutionCostShareItems) {
397: this (periods.size(), budgetInstitutionCostShareItems.size());
398:
399: // Setup arrays for institution direct personnel data (third party doesn't use those, so they arn't done in the commen
400: // constructor).
401: institutionDirectPersonnel = new KualiInteger[institutionCostSharePersonnel
402: .size()][periods.size()];
403: totalInstitutionDirectPersonnel = new KualiInteger[institutionCostSharePersonnel
404: .size()];
405: for (int i = 0; i < institutionDirectPersonnel.length; i++) {
406: Arrays.fill(institutionDirectPersonnel[i],
407: new KualiInteger(0));
408: }
409: Arrays.fill(totalInstitutionDirectPersonnel,
410: new KualiInteger(0));
411:
412: calculateInstitutionDirectPersonnel(periods, personnel,
413: institutionCostSharePersonnel);
414:
415: calculateNonpersonnelInstitutionTotalBudgeted(periods,
416: budgetNonpersonnelItems);
417:
418: calculateAmountDistributedAndTotalSource(budgetInstitutionCostShareItems);
419:
420: calculateSubcontractorAndBalanceToBeDistributed(null);
421: }
422:
423: /**
424: * Constructs a BudgetCostShareFormHelper with third party cost share values.
425: *
426: * @param subcontractorCostShare
427: * @param periods
428: * @param budgetNonpersonnelItems
429: * @param budgetThirdPartyCostShareItems
430: */
431: public Direct(
432: KualiInteger[] subcontractorCostShare,
433: List<BudgetPeriod> periods,
434: List<BudgetNonpersonnel> budgetNonpersonnelItems,
435: List<BudgetThirdPartyCostShare> budgetThirdPartyCostShareItems) {
436: this (periods.size(), budgetThirdPartyCostShareItems.size());
437:
438: calculateNonpersonnelThirdPartyTotalBudgeted(periods,
439: budgetNonpersonnelItems);
440:
441: calculateAmountDistributedAndTotalSource(budgetThirdPartyCostShareItems);
442:
443: calculateSubcontractorAndBalanceToBeDistributed(subcontractorCostShare);
444: }
445:
446: /**
447: * Calculates totalBudgeted for personnel institution cost share.
448: *
449: * @param periods
450: * @param personnel
451: * @param institutionCostSharePersonnel
452: */
453: private void calculateInstitutionDirectPersonnel(
454: List<BudgetPeriod> periods,
455: List<BudgetUser> personnel,
456: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel) {
457: // First we look at each chart/org.
458: for (int i = 0; i < institutionCostSharePersonnel.size(); i++) {
459: InstitutionCostSharePersonnel institutionCostSharePerson = institutionCostSharePersonnel
460: .get(i);
461:
462: // Second we check each person if it matches the chart/org we are currently evaluating.
463: for (BudgetUser person : personnel) {
464: if (institutionCostSharePerson
465: .getChartOfAccountsCode().equals(
466: StringUtils.defaultString(person
467: .getFiscalCampusCode()))
468: && institutionCostSharePerson
469: .getOrganizationCode()
470: .equals(
471: StringUtils
472: .defaultString(person
473: .getPrimaryDepartmentCode()))) {
474:
475: // Third we look at each Task.
476: for (UserAppointmentTask userAppointmentTask : person
477: .getUserAppointmentTasks()) {
478: // Fourth we look at each Period. Cost Share takes task summation / display of each period.
479: for (UserAppointmentTaskPeriod userAppointmentTaskPeriod : userAppointmentTask
480: .getUserAppointmentTaskPeriods()) {
481: int periodIndex = budgetPeriodService
482: .getPeriodIndex(
483: userAppointmentTaskPeriod
484: .getBudgetPeriodSequenceNumber(),
485: periods);
486: KualiInteger institutionDirectPersonnelAmount = userAppointmentTaskPeriod
487: .getInstitutionCostShareFringeBenefitTotalAmount()
488: .add(
489: userAppointmentTaskPeriod
490: .getInstitutionCostShareRequestTotalAmount());
491: institutionDirectPersonnelAmount = institutionDirectPersonnelAmount
492: .add(
493: userAppointmentTaskPeriod
494: .getInstitutionHealthInsuranceAmount())
495: .add(
496: userAppointmentTaskPeriod
497: .getInstitutionSalaryAmount())
498: .add(
499: userAppointmentTaskPeriod
500: .getInstitutionRequestedFeesAmount());
501:
502: // Take the value and put it into i (location of the chart / org) and j (period location).
503: institutionDirectPersonnel[i][periodIndex] = institutionDirectPersonnel[i][periodIndex]
504: .add(institutionDirectPersonnelAmount);
505: totalInstitutionDirectPersonnel[i] = totalInstitutionDirectPersonnel[i]
506: .add(institutionDirectPersonnelAmount);
507:
508: // Finally update the total budgeted and amount distributed with the same numbers.
509: totalBudgeted[periodIndex] = totalBudgeted[periodIndex]
510: .add(institutionDirectPersonnelAmount);
511: totalTotalBudgeted = totalTotalBudgeted
512: .add(institutionDirectPersonnelAmount);
513:
514: amountDistributed[periodIndex] = amountDistributed[periodIndex]
515: .add(institutionDirectPersonnelAmount);
516: totalAmountDistributed = totalAmountDistributed
517: .add(institutionDirectPersonnelAmount);
518: }
519: }
520: }
521: }
522: }
523: }
524:
525: /**
526: * Calculates Amount Distributed and Total Source. Both of them are done together so to eliminate unnecessary loops. This is
527: * just a helper method to consolidate code.
528: *
529: * @param budgetThirdPartyCostShareItems
530: */
531: private void calculateAmountDistributedAndTotalSource(
532: List budgetAbstractCostShareItems) {
533: for (int i = 0; i < budgetAbstractCostShareItems.size(); i++) {
534: BudgetAbstractCostShare budgetAbstractCostShare = (BudgetAbstractCostShare) budgetAbstractCostShareItems
535: .get(i);
536:
537: for (int j = 0; j < budgetAbstractCostShare
538: .getBudgetPeriodCostShare().size(); j++) {
539: BudgetAbstractPeriodCostShare budgetAbstractPeriodCostShare = (BudgetAbstractPeriodCostShare) budgetAbstractCostShare
540: .getBudgetPeriodCostShare().get(j);
541:
542: // check for null because it may be a newly added object
543: if (budgetAbstractPeriodCostShare
544: .getBudgetCostShareAmount() != null) {
545: totalSource[i] = totalSource[i]
546: .add(budgetAbstractPeriodCostShare
547: .getBudgetCostShareAmount());
548: amountDistributed[j] = amountDistributed[j]
549: .add(budgetAbstractPeriodCostShare
550: .getBudgetCostShareAmount());
551: totalAmountDistributed = totalAmountDistributed
552: .add(budgetAbstractPeriodCostShare
553: .getBudgetCostShareAmount());
554: }
555: }
556: }
557: }
558:
559: /**
560: * Calculates Institution Total Budget for Nonpersonnel items. This is just a helper method to consolidate code.
561: *
562: * @param periods
563: * @param budgetNonpersonnelItems
564: */
565: private void calculateNonpersonnelInstitutionTotalBudgeted(
566: List<BudgetPeriod> periods,
567: List<BudgetNonpersonnel> budgetNonpersonnelItems) {
568: for (BudgetNonpersonnel budgetNonpersonnel : budgetNonpersonnelItems) {
569: int periodIndex = budgetPeriodService.getPeriodIndex(
570: budgetNonpersonnel
571: .getBudgetPeriodSequenceNumber(),
572: periods);
573:
574: totalBudgeted[periodIndex] = totalBudgeted[periodIndex]
575: .add(budgetNonpersonnel
576: .getBudgetInstitutionCostShareAmount());
577: totalTotalBudgeted = totalTotalBudgeted
578: .add(budgetNonpersonnel
579: .getBudgetInstitutionCostShareAmount());
580: }
581: }
582:
583: /**
584: * Calculates Third Party Total Budget for Nonpersonnel items. This is just a helper method to consolidate code.
585: *
586: * @param periods
587: * @param budgetNonpersonnelItems
588: */
589: private void calculateNonpersonnelThirdPartyTotalBudgeted(
590: List<BudgetPeriod> periods,
591: List<BudgetNonpersonnel> budgetNonpersonnelItems) {
592: for (BudgetNonpersonnel budgetNonpersonnel : budgetNonpersonnelItems) {
593: int periodIndex = budgetPeriodService.getPeriodIndex(
594: budgetNonpersonnel
595: .getBudgetPeriodSequenceNumber(),
596: periods);
597:
598: totalBudgeted[periodIndex] = totalBudgeted[periodIndex]
599: .add(budgetNonpersonnel
600: .getBudgetThirdPartyCostShareAmount());
601: totalTotalBudgeted = totalTotalBudgeted
602: .add(budgetNonpersonnel
603: .getBudgetThirdPartyCostShareAmount());
604: }
605: }
606:
607: /**
608: * Calculates the balance to be distributed (and it's total) based on totalBudgeted - amountDistributed. This is just a
609: * helper method to consolidate code.
610: *
611: * @param subcontractorCostShare applicable for 3rd Party Direct cost share, otherwise null
612: */
613: private void calculateSubcontractorAndBalanceToBeDistributed(
614: KualiInteger[] subcontractorCostShare) {
615: // calculate totalBalanceToBeDistributed
616: for (int i = 0; i < balanceToBeDistributed.length; i++) {
617: if (subcontractorCostShare != null) {
618: // subcontractorCostShare needs to be added in
619: amountDistributed[i] = amountDistributed[i]
620: .add(subcontractorCostShare[i]);
621: totalAmountDistributed = totalAmountDistributed
622: .add(subcontractorCostShare[i]);
623: }
624:
625: balanceToBeDistributed[i] = totalBudgeted[i]
626: .subtract(amountDistributed[i]);
627: totalBalanceToBeDistributed = totalBalanceToBeDistributed
628: .add(balanceToBeDistributed[i]);
629: }
630: }
631:
632: /**
633: * Gets the amountDistributed attribute.
634: *
635: * @return Returns the amountDistributed.
636: */
637: public KualiInteger[] getAmountDistributed() {
638: return amountDistributed;
639: }
640:
641: /**
642: * Gets the balanceToBeDistributed attribute.
643: *
644: * @return Returns the balanceToBeDistributed.
645: */
646: public KualiInteger[] getBalanceToBeDistributed() {
647: return balanceToBeDistributed;
648: }
649:
650: /**
651: * Gets the totalAmountDistributed attribute.
652: *
653: * @return Returns the totalAmountDistributed.
654: */
655: public KualiInteger getTotalAmountDistributed() {
656: return totalAmountDistributed;
657: }
658:
659: /**
660: * Gets the totalBalanceToBeDistributed attribute.
661: *
662: * @return Returns the totalBalanceToBeDistributed.
663: */
664: public KualiInteger getTotalBalanceToBeDistributed() {
665: return totalBalanceToBeDistributed;
666: }
667:
668: /**
669: * Gets the totalBudgeted attribute.
670: *
671: * @return Returns the totalBudgeted.
672: */
673: public KualiInteger[] getTotalBudgeted() {
674: return totalBudgeted;
675: }
676:
677: /**
678: * Gets the totalTotalBudgeted attribute.
679: *
680: * @return Returns the totalTotalBudgeted.
681: */
682: public KualiInteger getTotalTotalBudgeted() {
683: return totalTotalBudgeted;
684: }
685:
686: /**
687: * Gets the totalSource attribute.
688: *
689: * @return Returns the totalSource.
690: */
691: public KualiInteger[] getTotalSource() {
692: return totalSource;
693: }
694:
695: /**
696: * Gets the institutionDirectPersonnel attribute.
697: *
698: * @return Returns the institutionDirectPersonnel.
699: */
700: public KualiInteger[][] getInstitutionDirectPersonnel() {
701: return institutionDirectPersonnel;
702: }
703:
704: /**
705: * Gets the totalInstitutionDirectPersonnel attribute.
706: *
707: * @return Returns the totalInstitutionDirectPersonnel.
708: */
709: public KualiInteger[] getTotalInstitutionDirectPersonnel() {
710: return totalInstitutionDirectPersonnel;
711: }
712: }
713:
714: /**
715: * Inner helper class that assists in the management of the data for the Subcontractor section.
716: */
717: public class Subcontractor {
718: private String budgetNonpersonnelDescription;
719:
720: private KualiInteger[] periodAmounts;
721: private KualiInteger totalPeriodAmount;
722:
723: /**
724: * Constructs a Subcontractor object. Initializes periodAmounts array to all 0s, sets initial amount, and adds that amount
725: * to totalPeriodAmount.
726: *
727: * @param budgetNonpersonnel
728: * @param periodsSize
729: * @param periodAmountsIndex
730: */
731: public Subcontractor(BudgetNonpersonnel budgetNonpersonnel,
732: int periodsSize, int periodAmountsIndex) {
733: budgetNonpersonnelDescription = budgetNonpersonnel
734: .getBudgetNonpersonnelDescription();
735:
736: periodAmounts = new KualiInteger[periodsSize];
737: Arrays.fill(periodAmounts, new KualiInteger(0));
738:
739: periodAmounts[periodAmountsIndex] = budgetNonpersonnel
740: .getBudgetThirdPartyCostShareAmount();
741: totalPeriodAmount = budgetNonpersonnel
742: .getBudgetThirdPartyCostShareAmount();
743: }
744:
745: /**
746: * Adds an amount to a certain period for a subcontractor.
747: *
748: * @param budgetThirdPartyCostShareAmount
749: * @param periodAmountsIndex
750: */
751: public void addPeriodAmount(
752: KualiInteger budgetThirdPartyCostShareAmount,
753: int periodAmountsIndex) {
754: periodAmounts[periodAmountsIndex] = periodAmounts[periodAmountsIndex]
755: .add(budgetThirdPartyCostShareAmount);
756: totalPeriodAmount = totalPeriodAmount
757: .add(budgetThirdPartyCostShareAmount);
758: }
759:
760: /**
761: * Gets the budgetNonpersonnelDescription attribute.
762: *
763: * @return Returns the budgetNonpersonnelDescription.
764: */
765: public String getBudgetNonpersonnelDescription() {
766: return budgetNonpersonnelDescription;
767: }
768:
769: /**
770: * Gets the periodAmounts attribute.
771: *
772: * @return Returns the periodAmounts.
773: */
774: public KualiInteger[] getPeriodAmounts() {
775: return periodAmounts;
776: }
777:
778: /**
779: * Gets the totalPeriodAmount attribute.
780: *
781: * @return Returns the totalPeriodAmount.
782: */
783: public KualiInteger getTotalPeriodAmount() {
784: return totalPeriodAmount;
785: }
786: }
787: }
|