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.math.BigDecimal;
019:
020: import org.kuali.core.util.KualiDecimal;
021: import org.kuali.core.util.KualiInteger;
022: import org.kuali.module.kra.budget.bo.BudgetNonpersonnel;
023:
024: /**
025: * This is a wrapper for BudgetNonpersonnel business object. It's useful on the copy over page because it assists in housing and
026: * computing the inflation rates.
027: */
028: public class BudgetNonpersonnelCopyOverBoHelper extends
029: BudgetNonpersonnel {
030: private static final long serialVersionUID = -4975734069081678964L;
031:
032: private KualiInteger budgetInflatedAgencyAmount;
033: private KualiInteger budgetInflatedInstitutionCostShareAmount;
034: private KualiInteger budgetInflatedThirdPartyCostShareAmount;
035:
036: /**
037: * Constructs a BudgetNonpersonnelCopyOverBoHelper. Default, no arg constructor
038: */
039: public BudgetNonpersonnelCopyOverBoHelper() {
040: // to ensure an empty item like this is not considered an origin item. See
041: // this.isOriginItem
042: this .setBudgetNonpersonnelSequenceNumber(new Integer(-1));
043: }
044:
045: /**
046: * <p>
047: * This does a 1:1 copy from BudgetNonpersonnel to BudgetNonpersonnelCopyOverBoHelper, with the exception of:
048: * </p>
049: * 1. If copyToFuturePeriods is set, it sets the three amount indicators.<br>
050: * 2. The three inflation amounts are set to the regular amounts (since origin inflated amount = origin amount).<br>
051: * <p>
052: * Useful for origin items.
053: * </p>
054: *
055: * @param budgetNonpersonnel object to copy
056: */
057: public BudgetNonpersonnelCopyOverBoHelper(
058: BudgetNonpersonnel budgetNonpersonnel) {
059: super (budgetNonpersonnel); // This does a 1:1 copy
060:
061: // 1. set the three amount indicators if copyToFuturePeriods is set. This is to accommodate
062: // functional requirements on the interface. Note that copyToFuturePeriods also needs
063: // to be copied so that "following copy over items" know that the origin has
064: // copyToFuturePeriods set.
065: if (budgetNonpersonnel.getCopyToFuturePeriods()) {
066: this .setAgencyCopyIndicator(true);
067: this .setBudgetInstitutionCostShareCopyIndicator(true);
068: this .setBudgetThirdPartyCostShareCopyIndicator(true);
069: }
070:
071: // 2.
072: this .setBudgetInflatedAgencyAmount(budgetNonpersonnel
073: .getAgencyRequestAmount());
074: this
075: .setBudgetInflatedInstitutionCostShareAmount(budgetNonpersonnel
076: .getBudgetInstitutionCostShareAmount());
077: this
078: .setBudgetInflatedThirdPartyCostShareAmount(budgetNonpersonnel
079: .getBudgetThirdPartyCostShareAmount());
080: }
081:
082: /**
083: * <p>
084: * This does a 1:1 copy from BudgetNonpersonnel to BudgetNonpersonnelCopyOverBoHelper and populates inflation values based on
085: * origin values, with the exception of:
086: * </p> - Blanks out the three types of amounts based on whether the appropriate indicator are set. This is a functional
087: * requirement<br>
088: * <p>
089: * Useful for items that are not origin items but already exist at the time of entering the copy over page (so either they were
090: * created in the past or they were entered on NPRS).
091: * </p>
092: *
093: * @param budgetNonpersonnel object to copy
094: * @param inflationLength
095: * @param budgetNonpersonnelInflationRate inflation rate to use
096: */
097: public BudgetNonpersonnelCopyOverBoHelper(
098: BudgetNonpersonnel budgetNonpersonnel, int inflationLength,
099: KualiDecimal budgetNonpersonnelInflationRate) {
100: super (budgetNonpersonnel); // This does a 1:1 copy
101:
102: // Set amounts to 0 if the indicator is set. Functionally this means if the indicator is checked and
103: // they uncheck it, they see 0 instead of the nonpersonnel screen value.
104: if (budgetNonpersonnel.getAgencyCopyIndicator()) {
105: this .setAgencyRequestAmount(new KualiInteger(0));
106: }
107: if (budgetNonpersonnel
108: .getBudgetInstitutionCostShareCopyIndicator()) {
109: this
110: .setBudgetThirdPartyCostShareAmount(new KualiInteger(
111: 0));
112: }
113: if (budgetNonpersonnel
114: .getBudgetThirdPartyCostShareCopyIndicator()) {
115: this
116: .setBudgetInstitutionCostShareAmount(new KualiInteger(
117: 0));
118: }
119:
120: // calculate inflation based on origin amounts per method specification.
121: // Can always be done because of t=0 then it's the original value.
122: // details here: http://en.wikipedia.org/wiki/Interest
123: BigDecimal inflationFactor = budgetNonpersonnelInflationRate
124: .bigDecimalValue().divide(BigDecimal.valueOf(100), 8,
125: KualiDecimal.ROUND_BEHAVIOR).add(
126: BigDecimal.valueOf(1));
127:
128: KualiInteger tmpBudgetAgencyAmount = this
129: .getBudgetOriginAgencyAmount().multiply(
130: new BigDecimal(Math.pow(inflationFactor
131: .doubleValue(), inflationLength)));
132: this .setBudgetInflatedAgencyAmount(tmpBudgetAgencyAmount);
133:
134: KualiInteger tmpBudgetInstitutionCostShareAmount = this
135: .getBudgetOriginInstitutionCostShareAmount().multiply(
136: new BigDecimal(Math.pow(inflationFactor
137: .doubleValue(), inflationLength)));
138: this
139: .setBudgetInflatedInstitutionCostShareAmount(tmpBudgetInstitutionCostShareAmount);
140:
141: KualiInteger tmpBudgetThirdPartyCostShareAmount = this
142: .getBudgetOriginThirdPartyCostShareAmount().multiply(
143: new BigDecimal(Math.pow(inflationFactor
144: .doubleValue(), inflationLength)));
145: this
146: .setBudgetInflatedThirdPartyCostShareAmount(tmpBudgetThirdPartyCostShareAmount);
147: }
148:
149: /**
150: * <p>
151: * This does a 1:1 copy from BudgetNonpersonnel to BudgetNonpersonnelCopyOverBoHelper, with the exception of:
152: * </p>
153: * 1. Updates the period number with budgetPeriodSequenceNumberOverride.<br>
154: * 2. Sets the amounts in this object to 0.<br>
155: * 3. Sets the budgetOriginSequenceNumber to budgetNonpersonnelSequenceNumber.<br>
156: * 4. Sets the origin amounts to the values of originBudgetNonpersonnel passed in.<br>
157: * 5. If copyToFuturePeriods is set, it sets the three amount indicators.<br>
158: * 6. Sets budgetNonpersonnelSequenceNumber to null because this item does not exist yet (don't use -1 because then it might be
159: * mistaken as a pre-origin item by iterface).<br>
160: * 7. Populates inflation values based on BudgetNonpersonnel amounts.<br>
161: * <p>
162: * Useful for non-origin items that have not been created yet.
163: * </p>
164: *
165: * @param originBudgetNonpersonnel object to copy (origin item)
166: * @param budgetPeriodSequenceNumberOverride values used for the new budgetPeriodSequenceNumber value
167: * @param inflationLength
168: * @param budgetNonpersonnelInflationRate inflation rate to use
169: */
170: public BudgetNonpersonnelCopyOverBoHelper(
171: BudgetNonpersonnel originBudgetNonpersonnel,
172: Integer budgetPeriodSequenceNumberOverride,
173: int inflationLength,
174: KualiDecimal budgetNonpersonnelInflationRate) {
175: super (originBudgetNonpersonnel); // This does a 1:1 copy
176:
177: // 1.
178: this
179: .setBudgetPeriodSequenceNumber(budgetPeriodSequenceNumberOverride);
180:
181: // 2.
182: this .setAgencyRequestAmount(new KualiInteger(0));
183: this .setBudgetThirdPartyCostShareAmount(new KualiInteger(0));
184: this .setBudgetInstitutionCostShareAmount(new KualiInteger(0));
185:
186: // 3.
187: this .setBudgetOriginSequenceNumber(originBudgetNonpersonnel
188: .getBudgetNonpersonnelSequenceNumber());
189:
190: // 4.
191: this .setBudgetOriginAgencyAmount(originBudgetNonpersonnel
192: .getAgencyRequestAmount());
193: this
194: .setBudgetOriginInstitutionCostShareAmount(originBudgetNonpersonnel
195: .getBudgetInstitutionCostShareAmount());
196: this
197: .setBudgetOriginThirdPartyCostShareAmount(originBudgetNonpersonnel
198: .getBudgetThirdPartyCostShareAmount());
199:
200: // 5. set the three amount indicators if copyToFuturePeriods is set. This is to accomondate
201: // functional requirements on the interface. Note that copyToFuturePeriods also needs
202: // to be copied so that "following copy over items" know that the origin has
203: // copyToFuturePeriods set.
204: if (originBudgetNonpersonnel.getCopyToFuturePeriods()) {
205: this .setAgencyCopyIndicator(true);
206: this .setBudgetInstitutionCostShareCopyIndicator(true);
207: this .setBudgetThirdPartyCostShareCopyIndicator(true);
208: }
209:
210: // 6. (needs to happen late because 3 above uses this)
211: this .setBudgetNonpersonnelSequenceNumber(null);
212:
213: // 7. Note: Does not use origin amounts like inflation calculation in other constructor.
214:
215: // calculate inflation based on amounts per method specification
216: BigDecimal inflationFactor = budgetNonpersonnelInflationRate
217: .bigDecimalValue().divide(BigDecimal.valueOf(100), 8,
218: KualiDecimal.ROUND_BEHAVIOR).add(
219: BigDecimal.valueOf(1));
220:
221: KualiInteger tmpBudgetAgencyAmount = this
222: .getBudgetOriginAgencyAmount().multiply(
223: new BigDecimal(Math.pow(inflationFactor
224: .doubleValue(), inflationLength)));
225: this .setBudgetInflatedAgencyAmount(tmpBudgetAgencyAmount);
226:
227: KualiInteger tmpBudgetInstitutionCostShareAmount = this
228: .getBudgetOriginInstitutionCostShareAmount().multiply(
229: new BigDecimal(Math.pow(inflationFactor
230: .doubleValue(), inflationLength)));
231: this
232: .setBudgetInflatedInstitutionCostShareAmount(tmpBudgetInstitutionCostShareAmount);
233:
234: KualiInteger tmpBudgetThirdPartyCostShareAmount = this
235: .getBudgetOriginThirdPartyCostShareAmount().multiply(
236: new BigDecimal(Math.pow(inflationFactor
237: .doubleValue(), inflationLength)));
238: this
239: .setBudgetInflatedThirdPartyCostShareAmount(tmpBudgetThirdPartyCostShareAmount);
240: }
241:
242: /**
243: * Gets the BudgetNonpersonnel representation of this object. Uses inflation values if appropriate indicators are set.
244: *
245: * @return the BudgetNonpersonnel representation of this object.
246: */
247: public BudgetNonpersonnel getBudgetNonpersonnel() {
248: // Check if inflations values have to be used.
249: if (this .getAgencyCopyIndicator()) {
250: this .setAgencyRequestAmount(budgetInflatedAgencyAmount);
251: }
252: if (this .getBudgetInstitutionCostShareCopyIndicator()) {
253: this
254: .setBudgetInstitutionCostShareAmount(budgetInflatedInstitutionCostShareAmount);
255: }
256: if (this .getBudgetThirdPartyCostShareCopyIndicator()) {
257: this
258: .setBudgetThirdPartyCostShareAmount(budgetInflatedThirdPartyCostShareAmount);
259: }
260:
261: this .setCopyToFuturePeriods(false); // nothing to do with copy over, just make sure the checkbox is unchecked if "save" is
262: // used to copy over items on NPRS page
263:
264: return (BudgetNonpersonnel) new BudgetNonpersonnel(this ); // Don't just return "this" because giving a
265: // BudgetNonpersonnelCopyOverBoHelper confuses OJB.
266: }
267:
268: /**
269: * Gets the agencyRequestAmount or budgetInflatedAgencyAmount attribute based on if agencyCopyIndicator is set or not.
270: *
271: * @return amount per logic.
272: */
273: public KualiDecimal getDisplayAgencyRequestAmount() {
274: return this .getAgencyCopyIndicator() ? new KualiDecimal(this
275: .getBudgetInflatedAgencyAmount().longValue())
276: : new KualiDecimal(this .getAgencyRequestAmount()
277: .longValue());
278: }
279:
280: /**
281: * Gets the budgetInstitutionCostShareAmount or budgetInstitutionCostShareAmount attribute based on if
282: * budgetInstitutionCostShareCopyIndicator is set or not.
283: *
284: * @return amount per logic.
285: */
286: public KualiDecimal getDisplayBudgetInstitutionCostShareAmount() {
287: return this .getBudgetInstitutionCostShareCopyIndicator() ? new KualiDecimal(
288: this .getBudgetInflatedInstitutionCostShareAmount()
289: .longValue())
290: : new KualiDecimal(this
291: .getBudgetInstitutionCostShareAmount()
292: .longValue());
293: }
294:
295: /**
296: * Gets the budgetThirdPartyCostShareCopyAmount or budgetInflatedThirdPartyCostShareCopyAmount attribute based on if
297: * budgetThirdPartyCostShareCopyIndicator is set or not.
298: *
299: * @return amount per logic.
300: */
301: public KualiDecimal getDisplayBudgetThirdPartyCostShareAmount() {
302: return this .getBudgetThirdPartyCostShareCopyIndicator() ? new KualiDecimal(
303: this .getBudgetInflatedThirdPartyCostShareAmount()
304: .longValue())
305: : new KualiDecimal(this
306: .getBudgetThirdPartyCostShareAmount()
307: .longValue());
308: }
309:
310: /**
311: * Gets the budgetInflatedAgencyAmount attribute.
312: *
313: * @return Returns the budgetInflatedAgencyAmount.
314: */
315: public KualiInteger getBudgetInflatedAgencyAmount() {
316: return budgetInflatedAgencyAmount;
317: }
318:
319: /**
320: * Sets the budgetInflatedAgencyAmount attribute value.
321: *
322: * @param budgetInflatedAgencyAmount The budgetInflatedAgencyAmount to set.
323: */
324: public void setBudgetInflatedAgencyAmount(KualiInteger o) {
325: budgetInflatedAgencyAmount = o;
326: }
327:
328: /**
329: * Sets the budgetInflatedInstitutionCostShareAmount attribute value.
330: *
331: * @param budgetInflatedInstitutionCostShareAmount The budgetInflatedInstitutionCostShareAmount to set.
332: */
333: public void setBudgetInflatedInstitutionCostShareAmount(
334: KualiInteger o) {
335: budgetInflatedInstitutionCostShareAmount = o;
336: }
337:
338: /**
339: * Gets the budgetInflatedInstitutionCostShareAmount attribute.
340: *
341: * @return Returns the budgetInflatedInstitutionCostShareAmount.
342: */
343: public KualiInteger getBudgetInflatedInstitutionCostShareAmount() {
344: return budgetInflatedInstitutionCostShareAmount;
345: }
346:
347: /**
348: * Sets the budgetInflatedThirdPartyCostShareAmount attribute value.
349: *
350: * @param budgetInflatedThirdPartyCostShareAmount The budgetInflatedThirdPartyCostShareAmount to set.
351: */
352: public void setBudgetInflatedThirdPartyCostShareAmount(
353: KualiInteger o) {
354: budgetInflatedThirdPartyCostShareAmount = o;
355: }
356:
357: /**
358: * Gets the budgetInflatedThirdPartyCostShareAmount attribute.
359: *
360: * @return Returns the budgetInflatedThirdPartyCostShareAmount.
361: */
362: public KualiInteger getBudgetInflatedThirdPartyCostShareAmount() {
363: return budgetInflatedThirdPartyCostShareAmount;
364: }
365: }
|