1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.web.struts;
17
18 import java.math.BigDecimal;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.apache.commons.lang.StringUtils;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.kuali.ole.fp.businessobject.CapitalAccountingLines;
35 import org.kuali.ole.fp.businessobject.CapitalAssetAccountsGroupDetails;
36 import org.kuali.ole.fp.businessobject.CapitalAssetInformation;
37 import org.kuali.ole.fp.businessobject.CapitalAssetInformationDetail;
38 import org.kuali.ole.fp.document.CapitalAccountingLinesDocumentBase;
39 import org.kuali.ole.fp.document.CapitalAssetEditable;
40 import org.kuali.ole.fp.document.CapitalAssetInformationDocumentBase;
41 import org.kuali.ole.integration.cam.businessobject.Asset;
42 import org.kuali.ole.sys.OLEConstants;
43 import org.kuali.ole.sys.OLEKeyConstants;
44 import org.kuali.ole.sys.OLEPropertyConstants;
45 import org.kuali.ole.sys.businessobject.AccountingLine;
46 import org.kuali.ole.sys.context.SpringContext;
47 import org.kuali.ole.sys.document.AccountingDocument;
48 import org.kuali.ole.sys.service.SegmentedLookupResultsService;
49 import org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase;
50 import org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase;
51 import org.kuali.rice.core.api.util.type.KualiDecimal;
52 import org.kuali.rice.kns.util.WebUtils;
53 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
54 import org.kuali.rice.kns.web.struts.form.KualiForm;
55 import org.kuali.rice.krad.bo.PersistableBusinessObject;
56 import org.kuali.rice.krad.util.GlobalVariables;
57 import org.kuali.rice.krad.util.ObjectUtils;
58
59
60
61
62 public abstract class CapitalAssetInformationActionBase extends KualiAccountingDocumentActionBase {
63 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CapitalAssetInformationActionBase.class);
64
65
66
67
68
69
70
71
72
73
74
75 @Override
76 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
77 super.refresh(mapping, form, request, response);
78
79
80 CapitalAssetInformationFormBase capitalAssetInformationFormBase = (CapitalAssetInformationFormBase) form;
81
82 Collection<PersistableBusinessObject> rawValues = null;
83 Map<String, Set<String>> segmentedSelection = new HashMap<String, Set<String>>();
84
85
86 if (StringUtils.equals(OLEConstants.MULTIPLE_VALUE, capitalAssetInformationFormBase.getRefreshCaller())) {
87 String lookupResultsSequenceNumber = capitalAssetInformationFormBase.getLookupResultsSequenceNumber();
88
89 if (StringUtils.isNotBlank(lookupResultsSequenceNumber)) {
90
91 Set<String> selectedIds = SpringContext.getBean(SegmentedLookupResultsService.class).retrieveSetOfSelectedObjectIds(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId());
92 for (String selectedId : selectedIds) {
93 String selectedObjId = StringUtils.substringBefore(selectedId, ".");
94 if (!segmentedSelection.containsKey(selectedObjId)) {
95 segmentedSelection.put(selectedObjId, new HashSet<String>());
96 }
97 }
98
99 if (LOG.isDebugEnabled()) {
100 LOG.debug("Asking segmentation service for object ids " + segmentedSelection.keySet());
101 }
102 rawValues = SpringContext.getBean(SegmentedLookupResultsService.class).retrieveSelectedResultBOs(lookupResultsSequenceNumber, segmentedSelection.keySet(), Asset.class, GlobalVariables.getUserSession().getPerson().getPrincipalId());
103 }
104
105 if (rawValues == null || rawValues.size() == 0) {
106
107 DistributeCapitalAssetAmountToGroupAccountingLines((KualiAccountingDocumentFormBase) form);
108
109 return mapping.findForward(OLEConstants.MAPPING_BASIC);
110 }
111
112 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
113 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
114 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
115 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
116 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
117
118 List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
119
120 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
121 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
122 selectedCapitalAccountingLines.add(capitalAccountingLine);
123 }
124 }
125
126
127
128 if (rawValues != null) {
129 for (PersistableBusinessObject bo : rawValues) {
130 Asset asset = (Asset) bo;
131
132
133 boolean addIt = modifyAssetAlreadyExists(capitalAssetInformation, asset.getCapitalAssetNumber());
134
135
136 if (addIt) {
137 createNewModifyCapitalAsset(selectedCapitalAccountingLines, capitalAssetInformation, calfb.getDocument().getDocumentNumber(), OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR, getNextCapitalAssetLineNumber(kualiAccountingDocumentFormBase), asset.getCapitalAssetNumber());
138 }
139 }
140
141 checkCapitalAccountingLinesSelected(calfb);
142
143
144 removeEmptyCapitalAssetModify(capitalAssetInformation);
145
146
147 redistributeModifyCapitalAssetAmount(mapping, form, request, response);
148 }
149 }
150
151
152 DistributeCapitalAssetAmountToGroupAccountingLines((KualiAccountingDocumentFormBase) form);
153
154 return mapping.findForward(OLEConstants.MAPPING_BASIC);
155
156 }
157
158
159
160
161
162 protected void removeEmptyCapitalAssetModify(List<CapitalAssetInformation> capitalAssetInformation) {
163 List<CapitalAssetInformation> removeCapitalAssetModify = new ArrayList<CapitalAssetInformation>();
164
165 for (CapitalAssetInformation capitalAssetRecord : capitalAssetInformation) {
166 if (ObjectUtils.isNull(capitalAssetRecord.getCapitalAssetNumber()) && OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equalsIgnoreCase(capitalAssetRecord.getCapitalAssetActionIndicator())) {
167 removeCapitalAssetModify.add(capitalAssetRecord);
168 }
169 }
170
171 if (!removeCapitalAssetModify.isEmpty()) {
172 capitalAssetInformation.removeAll(removeCapitalAssetModify);
173 }
174 }
175
176
177
178
179
180
181
182
183 protected KualiDecimal getCapitalAssetsAmountAllocated(List<CapitalAssetInformation> currentCapitalAssetInformation, CapitalAccountingLines capitalAccountingLine) {
184
185 KualiDecimal capitalAssetsAmount = KualiDecimal.ZERO;
186
187
188 for (CapitalAssetInformation capitalAsset : currentCapitalAssetInformation) {
189 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
190 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
191 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
192 groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
193 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
194 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
195 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
196 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
197 capitalAssetsAmount = capitalAssetsAmount.add(groupAccountLine.getAmount());
198 }
199 }
200 }
201
202 return capitalAssetsAmount;
203 }
204
205
206
207
208
209
210
211
212
213 protected boolean modifyAssetAlreadyExists(List<CapitalAssetInformation> capitalAssetInformation, Long capitalAssetNumber) {
214 boolean addIt = true;
215 KualiDecimal capitalAssetCreatedAmount = KualiDecimal.ZERO;
216
217 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
218 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator()) &&
219 ObjectUtils.isNotNull(capitalAsset.getCapitalAssetNumber()) &&
220 capitalAsset.getCapitalAssetNumber().compareTo(capitalAssetNumber) == 0) {
221 addIt = false;
222 break;
223 }
224 }
225
226 return addIt;
227 }
228
229
230
231
232
233
234
235
236
237 protected boolean capitalAssetExists(List<CapitalAccountingLines> capitalAccountingLines, CapitalAssetInformation capitalAsset, String actionTypeCode) {
238 boolean exists = true;
239
240 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
241
242 for(CapitalAccountingLines capitalAccountLine : capitalAccountingLines) {
243 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
244 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
245 groupAccountLine.getSequenceNumber().compareTo(capitalAccountLine.getSequenceNumber()) == 0 &&
246 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
247 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountLine.getChartOfAccountsCode()) &&
248 groupAccountLine.getAccountNumber().equals(capitalAccountLine.getAccountNumber()) &&
249 groupAccountLine.getFinancialObjectCode().equals(capitalAccountLine.getFinancialObjectCode())) {
250 return exists;
251 }
252 }
253 }
254
255 return false;
256 }
257
258
259
260
261
262 protected void redistributeCostEquallyForModifiedAssets(ActionForm form) {
263 KualiDecimal remainingAmountToDistribute = KualiDecimal.ZERO;
264
265 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
266 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
267
268 String distributionCode = calfb.getCapitalAccountingLine().getDistributionCode();
269 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
270
271 List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
272
273 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
274 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
275 selectedCapitalAccountingLines.add(capitalAccountingLine);
276 remainingAmountToDistribute = remainingAmountToDistribute.add(capitalAccountingLine.getAmount());
277 }
278 }
279
280 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
281 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
282 redistributeAmountsForAccountingsLineForModifyAssets(selectedCapitalAccountingLines, capitalAssetInformation, remainingAmountToDistribute);
283
284
285 redistributeAmountsForAccountingsLineForModifyAssetsByAmounts(selectedCapitalAccountingLines, capitalAssetInformation, remainingAmountToDistribute);
286 }
287
288
289
290
291
292
293
294 protected void redistributeAmountsForAccountingsLineForModifyAssets(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation, KualiDecimal remainingAmountToDistribute) {
295
296 int totalQuantity = getNumberOfModifiedAssetsExist(selectedCapitalAccountingLines, capitalAssetInformation);
297 if (totalQuantity > 0) {
298 KualiDecimal equalModifyAssetAmount = remainingAmountToDistribute.divide(new KualiDecimal(totalQuantity), true);
299
300 int lastAssetIndex = 0;
301 CapitalAssetInformation lastCapitalAsset = new CapitalAssetInformation();
302
303 if (equalModifyAssetAmount.compareTo(KualiDecimal.ZERO) != 0) {
304 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
305 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator()) &&
306 (ObjectUtils.isNotNull(capitalAsset.getCapitalAssetNumber())) &&
307 (OLEConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode()))) {
308 if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR)) {
309 capitalAsset.setCapitalAssetQuantity(1);
310 redistributeEqualAmounts(selectedCapitalAccountingLines, capitalAsset, equalModifyAssetAmount, totalQuantity);
311 lastAssetIndex++;
312
313 lastCapitalAsset = capitalAsset;
314 }
315 }
316 }
317 }
318
319
320 KualiDecimal varianceForAssets = remainingAmountToDistribute.subtract(equalModifyAssetAmount.multiply(new KualiDecimal(lastAssetIndex)));
321 if (varianceForAssets.isNonZero()) {
322 lastCapitalAsset.setCapitalAssetLineAmount(lastCapitalAsset.getCapitalAssetLineAmount().add(varianceForAssets));
323 redistributeEqualAmountsOnLastCapitalAsset(selectedCapitalAccountingLines, lastCapitalAsset, capitalAssetInformation, OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR);
324 }
325 }
326 }
327
328
329
330
331
332
333 protected void redistributeAmountsForAccountingsLineForModifyAssetsByAmounts(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation, KualiDecimal remainingAmountToDistribute) {
334 KualiDecimal appliedAccountingLinesTotal = KualiDecimal.ZERO;
335 CapitalAssetAccountsGroupDetails lastAccountingLine = new CapitalAssetAccountsGroupDetails();
336
337 for (CapitalAccountingLines capitalAccountLine : selectedCapitalAccountingLines) {
338 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
339 if (OLEConstants.CapitalAssets.DISTRIBUTE_COST_BY_INDIVIDUAL_ASSET_AMOUNT_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode())) {
340 if (capitalAsset.getCapitalAssetLineAmount().compareTo(getAccountingLinesTotalAmount(capitalAsset)) != 0) {
341 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
342 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
343 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
344 groupAccountLine.getSequenceNumber().compareTo(capitalAccountLine.getSequenceNumber()) == 0 &&
345 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
346 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountLine.getChartOfAccountsCode()) &&
347 groupAccountLine.getAccountNumber().equals(capitalAccountLine.getAccountNumber()) &&
348 groupAccountLine.getFinancialObjectCode().equals(capitalAccountLine.getFinancialObjectCode())) {
349
350 groupAccountLine.setAmount((capitalAsset.getCapitalAssetLineAmount().multiply(capitalAccountLine.getAccountLinePercent())).divide(new KualiDecimal(100)));
351 }
352 }
353 }
354 }
355 }
356 }
357 }
358
359
360
361
362
363
364
365
366
367
368 protected void redistributeEqualAmounts(List<CapitalAccountingLines> selectedCapitalAccountingLines, CapitalAssetInformation capitalAsset, KualiDecimal amount, int totalQuantity) {
369 int assetQuantity = 0;
370 KualiDecimal totalCapitalAssetQuantity = new KualiDecimal(totalQuantity);
371
372 if (ObjectUtils.isNotNull(capitalAsset.getCapitalAssetQuantity())) {
373 assetQuantity = capitalAsset.getCapitalAssetQuantity();
374 }
375
376 capitalAsset.setCapitalAssetLineAmount(capitalAsset.getCapitalAssetLineAmount().add(amount.multiply(new KualiDecimal(assetQuantity))));
377 int lastAccountIndex = 0;
378 KualiDecimal appliedAccountingLinesTotal = KualiDecimal.ZERO;
379
380 CapitalAssetAccountsGroupDetails lastLine = new CapitalAssetAccountsGroupDetails();
381
382 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
383
384 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
385 KualiDecimal capitalAccountingLineAmount = getCapitalAssetAccountLineAmount(selectedCapitalAccountingLines, groupAccountLine, capitalAsset);
386 KualiDecimal calculatedLineAmount = capitalAccountingLineAmount.divide(totalCapitalAssetQuantity, true);
387 groupAccountLine.setAmount(calculatedLineAmount.multiply(new KualiDecimal(assetQuantity)));
388 appliedAccountingLinesTotal = appliedAccountingLinesTotal.add(groupAccountLine.getAmount());
389
390 lastAccountIndex++;
391 lastLine = groupAccountLine;
392 }
393
394
395 KualiDecimal varianceForLines = capitalAsset.getCapitalAssetLineAmount().subtract(appliedAccountingLinesTotal);
396 if (varianceForLines.isNonZero()) {
397 lastLine.setAmount(lastLine.getAmount().add(varianceForLines));
398 }
399 }
400
401
402
403
404
405
406
407
408
409
410 protected void redistributeEqualAmountsOnLastCapitalAsset(List<CapitalAccountingLines> selectedCapitalAccountingLines, CapitalAssetInformation lastCapitalAsset, List<CapitalAssetInformation> capitalAssetInformation, String actionTypeCode) {
411 for (CapitalAccountingLines capitalAccountingLine : selectedCapitalAccountingLines ) {
412 KualiDecimal lineAmount = capitalAccountingLine.getAmount();
413 KualiDecimal distributedAmount = getAccountingLinesDistributedAmount(capitalAccountingLine, capitalAssetInformation, actionTypeCode);
414 KualiDecimal difference = lineAmount.subtract(distributedAmount);
415 if (!difference.isZero()) {
416 adjustAccountingLineAmountOnLastCapitalAsset(capitalAccountingLine, lastCapitalAsset, difference);
417 }
418 }
419 }
420
421
422
423
424
425
426
427
428
429 protected KualiDecimal getCapitalAssetAccountLineAmount(List<CapitalAccountingLines> selectedCapitalAccountingLines, CapitalAssetAccountsGroupDetails groupAccountLine, CapitalAssetInformation capitalAsset) {
430 KualiDecimal lineAmount = KualiDecimal.ZERO;
431
432 for (CapitalAccountingLines capitalAccountingLine : selectedCapitalAccountingLines) {
433 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
434 groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
435 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
436 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
437 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
438 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
439 return capitalAccountingLine.getAmount();
440 }
441 }
442
443 return lineAmount;
444 }
445
446
447
448
449
450
451 protected void redistributeIndividualAmountsForAccountingLinesForModifyAssets(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation) {
452 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
453 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator())) {
454 if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR)) {
455 redistributeIndividualAmounts(selectedCapitalAccountingLines, capitalAsset);
456 }
457 }
458 }
459 }
460
461
462
463
464
465
466
467
468 protected void adjustCapitalAssetsAccountingLinesAmounts(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation) {
469 for (CapitalAccountingLines capitalAcctLine : selectedCapitalAccountingLines) {
470 adjustAccountingLinesAmounts(capitalAcctLine, capitalAssetInformation);
471 }
472 }
473
474
475
476
477
478
479
480
481 protected void adjustAccountingLinesAmounts(CapitalAccountingLines capitalAcctLine, List<CapitalAssetInformation> capitalAssetInformation) {
482
483 CapitalAssetAccountsGroupDetails lastAcctLine = null;
484
485 KualiDecimal totalAccountsAmount = KualiDecimal.ZERO;
486
487 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
488 if (capitalAsset.getCapitalAssetLineAmount().compareTo(getAccountingLinesTotalAmount(capitalAsset)) != 0) {
489 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
490 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
491 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
492 groupAccountLine.getSequenceNumber().compareTo(capitalAcctLine.getSequenceNumber()) == 0 &&
493 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAcctLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
494 groupAccountLine.getChartOfAccountsCode().equals(capitalAcctLine.getChartOfAccountsCode()) &&
495 groupAccountLine.getAccountNumber().equals(capitalAcctLine.getAccountNumber()) &&
496 groupAccountLine.getFinancialObjectCode().equals(capitalAcctLine.getFinancialObjectCode())) {
497 totalAccountsAmount = totalAccountsAmount.add(groupAccountLine.getAmount());
498 lastAcctLine = groupAccountLine;
499 }
500 }
501 }
502 }
503
504 KualiDecimal variance = capitalAcctLine.getAmount().subtract(totalAccountsAmount);
505 if (variance.isNonZero() && ObjectUtils.isNotNull(lastAcctLine)) {
506 lastAcctLine.setAmount(lastAcctLine.getAmount().add(variance));
507 }
508 }
509
510
511
512
513
514
515
516
517
518
519 protected void adjustVarianceOnCapitalAssets(List<CapitalAssetInformation> capitalAssetInformation) {
520 KualiDecimal adjustedCapitalAssetBalance = KualiDecimal.ZERO;
521 CapitalAssetInformation lastCapitalAsset = null;
522
523 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
524
525 if (OLEConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode())) {
526 if (capitalAsset.getCapitalAssetLineAmount().mod(new KualiDecimal(2)) != KualiDecimal.ZERO) {
527 capitalAsset.setCapitalAssetLineAmount(capitalAsset.getCapitalAssetLineAmount().subtract(new KualiDecimal(0.01)));
528 adjustedCapitalAssetBalance = adjustedCapitalAssetBalance.add(new KualiDecimal(0.01));
529 lastCapitalAsset = capitalAsset;
530 }
531 }
532 }
533
534 if (ObjectUtils.isNotNull(lastCapitalAsset) && adjustedCapitalAssetBalance.isNonZero()) {
535 lastCapitalAsset.setCapitalAssetLineAmount(lastCapitalAsset.getCapitalAssetLineAmount().add(adjustedCapitalAssetBalance));
536 }
537 }
538
539
540
541
542
543
544 protected void redistributeIndividualAmountsForAccountingLinesForCreateAssets(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation) {
545 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
546 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator())) {
547 if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR)) {
548 redistributeIndividualAmounts(selectedCapitalAccountingLines, capitalAsset);
549 }
550 }
551 }
552 }
553
554
555
556
557
558
559 protected void redistributeIndividualAmounts(List<CapitalAccountingLines> selectedCapitalAccountingLines, CapitalAssetInformation capitalAsset) {
560 KualiDecimal capitalAssetAmount = capitalAsset.getCapitalAssetLineAmount();
561
562 KualiDecimal totalCapitalAccountsAmount = getTotalCapitalAccountsAmounts(selectedCapitalAccountingLines);
563
564 CapitalAssetAccountsGroupDetails lastAccountLine = new CapitalAssetAccountsGroupDetails();
565 int lastAccountLineIndex = 0;
566 KualiDecimal distributedAmount = KualiDecimal.ZERO;
567
568 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
569 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
570 BigDecimal linePercent = getCapitalAccountingLinePercent(selectedCapitalAccountingLines, groupAccountLine, totalCapitalAccountsAmount);
571 groupAccountLine.setAmount(new KualiDecimal(capitalAssetAmount.bigDecimalValue().multiply(linePercent)));
572 lastAccountLine = groupAccountLine;
573 distributedAmount = distributedAmount.add(groupAccountLine.getAmount());
574
575 lastAccountLineIndex++;
576 }
577
578 lastAccountLine.setAmount(lastAccountLine.getAmount().add(capitalAssetAmount.subtract(distributedAmount)));
579 }
580
581
582
583
584
585
586
587
588 protected BigDecimal getCapitalAccountingLinePercent(List<CapitalAccountingLines> selectedCapitalAccountingLines, CapitalAssetAccountsGroupDetails groupAccountLine, KualiDecimal totalCapitalAccountsAmount) {
589 for (CapitalAccountingLines capitalAccountingLine : selectedCapitalAccountingLines) {
590 if (groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
591 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
592 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
593 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
594 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
595 return (capitalAccountingLine.getAmount().bigDecimalValue().divide(totalCapitalAccountsAmount.bigDecimalValue(), OLEConstants.CapitalAssets.CAPITAL_ACCOUNT_LINE_PERCENT_SCALE, OLEConstants.CapitalAssets.PERCENT_SCALE));
596 }
597 }
598
599 return BigDecimal.ZERO;
600 }
601
602
603
604
605
606
607
608 protected void redistributeEqualAmountsForAccountingLineForCreateAssets(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation, KualiDecimal remainingAmountToDistribute) {
609
610 int totalQuantity = getTotalQuantityOfCreateAssets(selectedCapitalAccountingLines, capitalAssetInformation);
611 if (totalQuantity > 0) {
612 KualiDecimal equalCreateAssetAmount = remainingAmountToDistribute.divide(new KualiDecimal(totalQuantity), true);
613
614 int lastAssetIndex = 0;
615 CapitalAssetInformation lastCapitalAsset = new CapitalAssetInformation();
616
617 if (equalCreateAssetAmount.compareTo(KualiDecimal.ZERO) != 0) {
618 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
619 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator()) &&
620 (OLEConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode()))) {
621 if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR)) {
622 redistributeEqualAmounts(selectedCapitalAccountingLines, capitalAsset, equalCreateAssetAmount, totalQuantity);
623 if (ObjectUtils.isNotNull(capitalAsset.getCapitalAssetQuantity())) {
624 lastAssetIndex = lastAssetIndex + capitalAsset.getCapitalAssetQuantity();
625 }
626
627 lastCapitalAsset = capitalAsset;
628 }
629 }
630 }
631 }
632
633
634 KualiDecimal varianceForAssets = remainingAmountToDistribute.subtract(equalCreateAssetAmount.multiply(new KualiDecimal(lastAssetIndex)));
635 if (varianceForAssets.isNonZero()) {
636 lastCapitalAsset.setCapitalAssetLineAmount(lastCapitalAsset.getCapitalAssetLineAmount().add(varianceForAssets));
637 redistributeEqualAmountsOnLastCapitalAsset(selectedCapitalAccountingLines, lastCapitalAsset, capitalAssetInformation, OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR);
638 }
639 }
640 }
641
642
643
644
645
646
647
648 protected int getTotalQuantityOfCreateAssets(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation) {
649 int totalQuantity = 0;
650
651 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
652 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator())) {
653 if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR)) {
654 if (ObjectUtils.isNotNull(capitalAsset.getCapitalAssetQuantity())) {
655 totalQuantity += capitalAsset.getCapitalAssetQuantity();
656 }
657 }
658 }
659 }
660
661 return totalQuantity;
662 }
663
664
665
666
667
668
669
670 protected int numberOfCreateAssetsExist(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation) {
671 int createAssetsCount = 0;
672
673 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
674 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator())) {
675 if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR)) {
676 createAssetsCount++;
677 }
678 }
679 }
680
681 if (createAssetsCount == 0) {
682 return 1;
683 }
684
685 return createAssetsCount;
686 }
687
688
689
690
691
692
693
694 protected int getNumberOfModifiedAssetsExist(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation) {
695 int modifiedAssetsCount = 0;
696
697 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
698 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator()) &&
699 ObjectUtils.isNotNull(capitalAsset.getCapitalAssetNumber())) {
700 if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR)) {
701 modifiedAssetsCount++;
702 }
703 }
704 }
705
706 if (modifiedAssetsCount == 0) {
707 return 1;
708 }
709
710 return modifiedAssetsCount;
711 }
712
713
714
715
716
717
718
719
720
721
722
723 public ActionForward clearCapitalAssetInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
724 LOG.debug("clearCapitalAssetInfo() - start");
725
726 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
727 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
728
729 if (capitalAssetInformation == null) {
730 return mapping.findForward(OLEConstants.MAPPING_BASIC);
731 }
732
733 int clearIndex = getSelectedLine(request);
734 this.resetCapitalAssetInfo(capitalAssetInformation.get(clearIndex));
735
736
737 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
738
739 return mapping.findForward(OLEConstants.MAPPING_BASIC);
740 }
741
742
743
744
745
746
747
748
749
750
751
752
753
754 public ActionForward clearCapitalAssetModify(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
755 LOG.debug("clearCapitalAssetModify() - start");
756
757 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
758 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
759
760 if (capitalAssetInformation == null) {
761 return mapping.findForward(OLEConstants.MAPPING_BASIC);
762 }
763
764 int clearIndex = getSelectedLine(request);
765 capitalAssetInformation.get(clearIndex).setCapitalAssetLineAmount(KualiDecimal.ZERO);
766
767
768 for (CapitalAssetAccountsGroupDetails groupAccountLine : capitalAssetInformation.get(clearIndex).getCapitalAssetAccountsGroupDetails()) {
769 groupAccountLine.setAmount(KualiDecimal.ZERO);
770 }
771
772
773 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
774
775 return mapping.findForward(OLEConstants.MAPPING_BASIC);
776 }
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792 public ActionForward insertCapitalAssetInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
793 LOG.debug("insertCapitalAssetInfo() - start");
794
795 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
796 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
797
798 if (capitalAssetInformation == null) {
799 return mapping.findForward(OLEConstants.MAPPING_BASIC);
800 }
801
802 int addIndex = getSelectedLine(request);
803 if (capitalAssetInformation.get(addIndex).getCapitalAssetQuantity() == null || capitalAssetInformation.get(addIndex).getCapitalAssetQuantity() <= 0) {
804 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_CAPITAL_ASSET_INFORMATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_CAPITAL_ASSET_QUANTITY_REQUIRED);
805 }
806 else {
807 this.addCapitalAssetInfoDetailLines(capitalAssetInformation.get(addIndex));
808 }
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
840
841 return mapping.findForward(OLEConstants.MAPPING_BASIC);
842 }
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858 public ActionForward addCapitalAssetTagLocationInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
859 LOG.debug("addCapitalAssetTagLocationInfo() - start");
860
861 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
862 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
863
864 if (capitalAssetInformation == null) {
865 return mapping.findForward(OLEConstants.MAPPING_BASIC);
866 }
867
868 int addIndex = getSelectedLine(request);
869 if (capitalAssetInformation.get(addIndex).getCapitalAssetQuantity() == null || capitalAssetInformation.get(addIndex).getCapitalAssetQuantity() <= 0) {
870 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_CAPITAL_ASSET_INFORMATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_CAPITAL_ASSET_QUANTITY_REQUIRED);
871 }
872 else {
873 this.addCapitalAssetInfoDetailLines(capitalAssetInformation.get(addIndex));
874 }
875
876
877 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
878
879 return mapping.findForward(OLEConstants.MAPPING_BASIC);
880 }
881
882
883
884
885
886
887
888
889
890
891
892
893
894 public ActionForward refreshCapitalAssetModify(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
895 LOG.debug("refreshCapitalAssetModify() - start");
896
897 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
898 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
899
900 if (capitalAssetInformation == null) {
901 return mapping.findForward(OLEConstants.MAPPING_BASIC);
902 }
903
904 int refreshIndex = getSelectedLine(request);
905
906 if (capitalAssetInformation.get(refreshIndex).getCapitalAssetNumber() == null) {
907 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_CAPITAL_ASSET_MODIFY_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_CAPITAL_ASSET_NUMBER_REQUIRED);
908 }
909
910
911 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
912
913 return mapping.findForward(OLEConstants.MAPPING_BASIC);
914 }
915
916
917
918
919 public ActionForward deleteCapitalAssetInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
920 LOG.debug("deleteCapitalAssetInfoDetail() - start");
921
922 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
923 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
924
925 if (capitalAssetInformation == null) {
926 return mapping.findForward(OLEConstants.MAPPING_BASIC);
927 }
928
929 int lineIndexForCapitalAssetInfo = this.getLineToDelete(request);
930
931 if (capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetInformationDetails() != null &&
932 capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetInformationDetails().size() > 0) {
933 capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetInformationDetails().clear();
934
935 }
936
937 if (capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetAccountsGroupDetails() != null &&
938 capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetAccountsGroupDetails().size() > 0) {
939 capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetAccountsGroupDetails().clear();
940 }
941
942 capitalAssetInformation.remove(lineIndexForCapitalAssetInfo);
943
944
945 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
946
947 return mapping.findForward(OLEConstants.MAPPING_BASIC);
948 }
949
950
951
952
953 public ActionForward deleteCapitalAssetModify(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
954 LOG.debug("deleteCapitalAssetModify() - start");
955
956 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
957 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
958
959 if (capitalAssetInformation == null) {
960 return mapping.findForward(OLEConstants.MAPPING_BASIC);
961 }
962
963 int lineIndexForCapitalAssetInfo = this.getLineToDelete(request);
964
965 capitalAssetInformation.remove(lineIndexForCapitalAssetInfo);
966
967
968 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
969
970 return mapping.findForward(OLEConstants.MAPPING_BASIC);
971 }
972
973
974
975
976
977
978
979
980 protected void processRemainingCapitalAssetInfo(ActionForm form, List<CapitalAssetInformation> capitalAssetInformation) {
981 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
982
983
984 calculateRemainingDistributedAmount(calfb, capitalAssetInformation);
985
986
987
988 checkCapitalAccountingLinesSelected(calfb);
989
990
991 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
992 DistributeCapitalAssetAmountToGroupAccountingLines(kualiAccountingDocumentFormBase);
993
994 setTabStatesForCapitalAssets(form);
995 }
996
997
998
999
1000 public ActionForward deleteCapitalAssetInfoDetailLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1001 LOG.debug("deleteCapitalAssetInfoDetailLine() - start");
1002
1003 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
1004 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
1005
1006 if (capitalAssetInformation == null) {
1007 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1008 }
1009
1010 int lineIndexForCapitalAssetInfo = this.getLineToDelete(request);
1011 capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetInformationDetails().remove(0);
1012
1013 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1014 }
1015
1016
1017
1018
1019 protected List<CapitalAssetInformation> getCurrentCapitalAssetInformationObject(KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase) {
1020 LOG.debug("getCurrentCapitalAssetInformationObject() - start");
1021
1022 CapitalAssetInformationDocumentBase capitalAssetInformationDocumentBase = (CapitalAssetInformationDocumentBase) kualiAccountingDocumentFormBase.getFinancialDocument();
1023
1024 if (!(capitalAssetInformationDocumentBase instanceof CapitalAssetEditable)) {
1025 return null;
1026 }
1027
1028 List<CapitalAssetInformation> capitalAssetInformation = capitalAssetInformationDocumentBase.getCapitalAssetInformation();
1029 return capitalAssetInformation;
1030 }
1031
1032
1033
1034
1035
1036
1037 protected void resetCapitalAssetInfo(CapitalAssetInformation capitalAssetInformation) {
1038 if (capitalAssetInformation != null) {
1039 capitalAssetInformation.setCapitalAssetDescription(null);
1040 capitalAssetInformation.setCapitalAssetManufacturerModelNumber(null);
1041 capitalAssetInformation.setCapitalAssetManufacturerName(null);
1042
1043 capitalAssetInformation.setCapitalAssetNumber(null);
1044 capitalAssetInformation.setCapitalAssetTypeCode(null);
1045 capitalAssetInformation.setCapitalAssetQuantity(null);
1046
1047 capitalAssetInformation.setVendorDetailAssignedIdentifier(null);
1048 capitalAssetInformation.setVendorHeaderGeneratedIdentifier(null);
1049
1050
1051 capitalAssetInformation.setVendorDetail(null);
1052 capitalAssetInformation.setVendorName(null);
1053 capitalAssetInformation.setCapitalAssetLineAmount(KualiDecimal.ZERO);
1054 capitalAssetInformation.getCapitalAssetInformationDetails().clear();
1055
1056
1057 for (CapitalAssetAccountsGroupDetails groupAccountLine : capitalAssetInformation.getCapitalAssetAccountsGroupDetails()) {
1058 groupAccountLine.setAmount(KualiDecimal.ZERO);
1059 }
1060 }
1061 }
1062
1063
1064
1065
1066
1067 @Override
1068 public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1069 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) form;;
1070 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
1071
1072 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
1073 List<CapitalAccountingLines> copiedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
1074 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1075 copiedCapitalAccountingLines.add(capitalAccountingLine);
1076 }
1077 capitalAccountingLines.clear();
1078
1079 ActionForward forward = super.copy(mapping, form, request, response);
1080
1081 caldb.setCapitalAccountingLines(copiedCapitalAccountingLines);
1082
1083
1084 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
1085 AccountingDocument document = kualiAccountingDocumentFormBase.getFinancialDocument();
1086 if (document instanceof CapitalAssetEditable) {
1087 CapitalAssetEditable capitalAssetEditable = (CapitalAssetEditable) document;
1088
1089 List<CapitalAssetInformation> capitalAssets = capitalAssetEditable.getCapitalAssetInformation();
1090 for (CapitalAssetInformation capitalAsset : capitalAssets) {
1091 Long capitalAssetNumber = capitalAsset.getCapitalAssetNumber();
1092 resetCapitalAssetInfo(capitalAsset);
1093
1094
1095
1096 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equalsIgnoreCase(capitalAsset.getCapitalAssetActionIndicator())) {
1097 capitalAsset.setCapitalAssetNumber(capitalAssetNumber);
1098 }
1099 capitalAsset.setCapitalAssetProcessedIndicator(false);
1100 }
1101 }
1102
1103
1104 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1105 setupIntialNextCapitalAssetLineNumber(kualiDocumentFormBase);
1106
1107 checkCapitalAccountingLinesSelected(capitalAccountingLinesFormBase);
1108
1109 return forward;
1110 }
1111
1112
1113
1114
1115
1116
1117 protected void setupIntialNextCapitalAssetLineNumber(KualiDocumentFormBase kualiDocumentFormBase) {
1118 KualiAccountingDocumentFormBase kadfb = (KualiAccountingDocumentFormBase) kualiDocumentFormBase;
1119 CapitalAssetInformationDocumentBase caidb = (CapitalAssetInformationDocumentBase) kadfb.getFinancialDocument();
1120
1121 List<CapitalAssetInformation> currentCapitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kadfb);
1122 for (CapitalAssetInformation capitalAsset : currentCapitalAssetInformation) {
1123 if (capitalAsset.getCapitalAssetLineNumber() > caidb.getNextCapitalAssetLineNumber()) {
1124 caidb.setNextCapitalAssetLineNumber(capitalAsset.getCapitalAssetLineNumber());
1125 }
1126 }
1127
1128 caidb.setNextCapitalAssetLineNumber(caidb.getNextCapitalAssetLineNumber()+1);
1129 }
1130
1131
1132
1133
1134
1135
1136 protected void calculatePercentsForSelectedCapitalAccountingLines(CapitalAccountingLinesFormBase calfb) {
1137 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
1138 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
1139
1140 KualiDecimal totalCapitalLinesSelectedAmount = (calculateTotalCapitalLinesSelectedAmount(capitalAccountingLines)).abs();
1141 if (totalCapitalLinesSelectedAmount.isNonZero()) {
1142 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1143 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
1144 capitalAccountingLine.setAccountLinePercent(capitalAccountingLine.getAmount().divide(totalCapitalLinesSelectedAmount).multiply(new KualiDecimal(100), true));
1145 }
1146 }
1147 }
1148 }
1149
1150
1151
1152
1153
1154
1155 protected KualiDecimal calculateTotalCapitalLinesSelectedAmount(List<CapitalAccountingLines> capitalAccountingLines) {
1156 KualiDecimal totalLineAmount = KualiDecimal.ZERO;
1157
1158 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1159 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
1160 totalLineAmount = totalLineAmount.add(capitalAccountingLine.getAmount());
1161 }
1162 }
1163
1164 return totalLineAmount;
1165 }
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177 protected void createCapitalAssetForGroupAccountingLines(CapitalAccountingLinesFormBase calfb, String actionType, String distributionAmountCode) {
1178 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
1179
1180 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
1181 List<CapitalAssetInformation> capitalAssetInformation = new ArrayList<CapitalAssetInformation>();
1182
1183 KualiAccountingDocumentFormBase kadfb = calfb;
1184
1185 List<CapitalAssetInformation> currentCapitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kadfb);
1186
1187 String documentNumber = calfb.getDocument().getDocumentNumber();
1188 calfb.setSystemControlAmount(KualiDecimal.ZERO);
1189
1190 List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
1191
1192 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1193 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
1194 capitalAccountingLine.setDistributionAmountCode(distributionAmountCode);
1195 selectedCapitalAccountingLines.add(capitalAccountingLine);
1196 }
1197 }
1198
1199 CapitalAssetInformation existingCapitalAsset = capitalAssetCreated(selectedCapitalAccountingLines, currentCapitalAssetInformation);
1200 if (ObjectUtils.isNotNull(existingCapitalAsset)) {
1201 if (!accountingLinesAmountDistributed(selectedCapitalAccountingLines, existingCapitalAsset)) {
1202
1203
1204 createNewCapitalAsset(selectedCapitalAccountingLines, currentCapitalAssetInformation, documentNumber, actionType, getNextCapitalAssetLineNumber(kadfb));
1205 }
1206 }
1207 else {
1208
1209 createNewCapitalAsset(selectedCapitalAccountingLines, currentCapitalAssetInformation, documentNumber, actionType, getNextCapitalAssetLineNumber(kadfb));
1210 }
1211 }
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222 protected void createNewCapitalAsset(List<CapitalAccountingLines> capitalAccountingLines, List<CapitalAssetInformation> currentCapitalAssetInformation, String documentNumber, String actionType, Integer nextCapitalAssetLineNumber) {
1223 CapitalAssetInformation capitalAsset = new CapitalAssetInformation();
1224 capitalAsset.setCapitalAssetLineAmount(KualiDecimal.ZERO);
1225 capitalAsset.setDocumentNumber(documentNumber);
1226 capitalAsset.setCapitalAssetLineNumber(nextCapitalAssetLineNumber);
1227 capitalAsset.setCapitalAssetActionIndicator(actionType);
1228 capitalAsset.setCapitalAssetProcessedIndicator(false);
1229
1230
1231 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1232 capitalAsset.setDistributionAmountCode(capitalAccountingLine.getDistributionAmountCode());
1233 createCapitalAssetAccountingLinesDetails(capitalAccountingLine, capitalAsset);
1234 }
1235
1236 currentCapitalAssetInformation.add(capitalAsset);
1237 }
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249 protected void createNewModifyCapitalAsset(List<CapitalAccountingLines> capitalAccountingLines, List<CapitalAssetInformation> currentCapitalAssetInformation, String documentNumber, String actionType, Integer nextCapitalAssetLineNumber, long capitalAssetNumber) {
1250 CapitalAssetInformation capitalAsset = new CapitalAssetInformation();
1251 capitalAsset.setCapitalAssetNumber(capitalAssetNumber);
1252 capitalAsset.setCapitalAssetLineAmount(KualiDecimal.ZERO);
1253 capitalAsset.setDocumentNumber(documentNumber);
1254 capitalAsset.setCapitalAssetLineNumber(nextCapitalAssetLineNumber);
1255 capitalAsset.setCapitalAssetActionIndicator(actionType);
1256 capitalAsset.setCapitalAssetProcessedIndicator(false);
1257
1258
1259 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1260 capitalAsset.setDistributionAmountCode(capitalAccountingLine.getDistributionAmountCode());
1261 createCapitalAssetAccountingLinesDetails(capitalAccountingLine, capitalAsset);
1262 }
1263
1264 currentCapitalAssetInformation.add(capitalAsset);
1265 }
1266
1267
1268
1269
1270
1271
1272
1273 protected void createCapitalAssetAccountingLinesDetails(CapitalAccountingLines capitalAccountingLine, CapitalAssetInformation capitalAsset) {
1274
1275 CapitalAssetAccountsGroupDetails capitalAssetAccountLine = new CapitalAssetAccountsGroupDetails();
1276 capitalAssetAccountLine.setDocumentNumber(capitalAsset.getDocumentNumber());
1277 capitalAssetAccountLine.setChartOfAccountsCode(capitalAccountingLine.getChartOfAccountsCode());
1278 capitalAssetAccountLine.setAccountNumber(capitalAccountingLine.getAccountNumber());
1279 capitalAssetAccountLine.setSubAccountNumber(capitalAccountingLine.getSubAccountNumber());
1280 capitalAssetAccountLine.setFinancialDocumentLineTypeCode(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE);
1281 capitalAssetAccountLine.setCapitalAssetAccountLineNumber(getNextAccountingLineNumber(capitalAccountingLine, capitalAsset));
1282 capitalAssetAccountLine.setCapitalAssetLineNumber(capitalAsset.getCapitalAssetLineNumber());
1283 capitalAssetAccountLine.setFinancialObjectCode(capitalAccountingLine.getFinancialObjectCode());
1284 capitalAssetAccountLine.setFinancialSubObjectCode(capitalAccountingLine.getFinancialSubObjectCode());
1285 capitalAssetAccountLine.setProjectCode(capitalAccountingLine.getProjectCode());
1286 capitalAssetAccountLine.setOrganizationReferenceId(capitalAccountingLine.getOrganizationReferenceId());
1287 capitalAssetAccountLine.setSequenceNumber(capitalAccountingLine.getSequenceNumber());
1288 capitalAssetAccountLine.setAmount(KualiDecimal.ZERO);
1289 capitalAsset.getCapitalAssetAccountsGroupDetails().add(capitalAssetAccountLine);
1290 }
1291
1292
1293
1294
1295
1296
1297
1298
1299 protected Integer getNextAccountingLineNumber(CapitalAccountingLines capitalAccountingLine, CapitalAssetInformation capitalAsset) {
1300 Integer nextAccountingLineNumber = 0;
1301 List<CapitalAssetAccountsGroupDetails> capitalAssetAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
1302 for (CapitalAssetAccountsGroupDetails capitalAssetAccountLine : capitalAssetAccountLines) {
1303 nextAccountingLineNumber = capitalAssetAccountLine.getCapitalAssetAccountLineNumber();
1304 }
1305
1306 return ++nextAccountingLineNumber;
1307 }
1308
1309
1310
1311
1312
1313
1314 protected CapitalAssetInformation getCapitalAssetCreated(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetInformation> capitalAssetInformation) {
1315 CapitalAssetInformation existingCapitalAsset = null;
1316 if (ObjectUtils.isNull(capitalAssetInformation) ||capitalAssetInformation.size() <= 0) {
1317 return existingCapitalAsset;
1318 }
1319
1320 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
1321 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
1322 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
1323 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
1324 groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
1325 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
1326 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
1327 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
1328 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
1329 return capitalAsset;
1330 }
1331 }
1332 }
1333
1334 return existingCapitalAsset;
1335 }
1336
1337
1338
1339
1340
1341
1342
1343 protected CapitalAssetInformation capitalAssetCreated(List<CapitalAccountingLines> capitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation) {
1344 CapitalAssetInformation existingCapitalAsset = null;
1345
1346 if (ObjectUtils.isNull(capitalAssetInformation) && capitalAssetInformation.size() <= 0) {
1347 return existingCapitalAsset;
1348 }
1349
1350 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1351 existingCapitalAsset = getCapitalAssetCreated(capitalAccountingLine, capitalAssetInformation);
1352 if (ObjectUtils.isNotNull(existingCapitalAsset)) {
1353 return existingCapitalAsset;
1354 }
1355 }
1356
1357 return existingCapitalAsset;
1358 }
1359
1360
1361
1362
1363
1364
1365
1366 protected CapitalAssetInformation modifyCapitalAssetCreated(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetInformation> capitalAssetInformation) {
1367 CapitalAssetInformation existingCapitalAsset = null;
1368
1369 if (ObjectUtils.isNull(capitalAssetInformation) && capitalAssetInformation.size() <= 0) {
1370 return existingCapitalAsset;
1371 }
1372
1373 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
1374 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator()) &&
1375 ObjectUtils.isNull(capitalAsset.getCapitalAssetNumber())) {
1376 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
1377 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
1378 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
1379 groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
1380 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
1381 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
1382 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
1383 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
1384 return capitalAsset;
1385 }
1386 }
1387 }
1388 }
1389
1390 return existingCapitalAsset;
1391 }
1392
1393
1394
1395
1396
1397
1398
1399
1400 protected Integer getNextCapitalAssetLineNumber(KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase) {
1401 int nextCapitalAssetLineNumber = 1;
1402 CapitalAssetInformationDocumentBase caidb = (CapitalAssetInformationDocumentBase) kualiAccountingDocumentFormBase.getFinancialDocument();
1403 nextCapitalAssetLineNumber = caidb.getNextCapitalAssetLineNumber();
1404 caidb.setNextCapitalAssetLineNumber(nextCapitalAssetLineNumber+1);
1405
1406 return nextCapitalAssetLineNumber;
1407 }
1408
1409
1410
1411
1412
1413
1414
1415 protected boolean accountingLinesAmountDistributed(List<CapitalAccountingLines> capitalAccountingLines, CapitalAssetInformation existingCapitalAsset) {
1416
1417 KualiDecimal accountingLineAmount = KualiDecimal.ZERO;
1418 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1419 accountingLineAmount = accountingLineAmount.add(capitalAccountingLine.getAmount().abs());
1420 }
1421
1422 KualiDecimal capitalAssetsAmount = existingCapitalAsset.getCapitalAssetLineAmount();
1423
1424 return accountingLineAmount.equals(capitalAssetsAmount);
1425 }
1426
1427
1428
1429
1430
1431
1432
1433 protected boolean capitalAccountingLineAmountDistributed(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetInformation> capitalAssetsInformation) {
1434 KualiDecimal amountDistributed = KualiDecimal.ZERO;
1435 for (CapitalAssetInformation capitalAsset : capitalAssetsInformation) {
1436 amountDistributed = amountDistributed.add(getAccountingLineAmount(capitalAsset, capitalAccountingLine));
1437 }
1438
1439 KualiDecimal capitalAccountingLineAmount = capitalAccountingLine.getAmount();
1440
1441 return amountDistributed.equals(capitalAccountingLineAmount);
1442 }
1443
1444
1445
1446
1447
1448
1449
1450
1451 protected KualiDecimal getAccountingLineAmount(CapitalAssetInformation capitalAsset, CapitalAccountingLines capitalAccountingLine) {
1452 KualiDecimal accountLineAmount = KualiDecimal.ZERO;
1453
1454 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
1455
1456 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
1457 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 &&
1458 groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
1459 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
1460 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
1461 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
1462 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
1463 return groupAccountLine.getAmount();
1464 }
1465 }
1466
1467 return accountLineAmount;
1468 }
1469
1470
1471
1472
1473
1474
1475
1476
1477 protected void addMissingAccountingLinesToCapitalAsset(List<CapitalAccountingLines> capitalAccountingLines, CapitalAssetInformation existingCapitalAsset) {
1478 List<CapitalAssetAccountsGroupDetails> groupAccountLines = existingCapitalAsset.getCapitalAssetAccountsGroupDetails();
1479
1480 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1481 if (capitalAccountingLineMissing(capitalAccountingLine, groupAccountLines, existingCapitalAsset.getCapitalAssetLineNumber())) {
1482 createCapitalAssetAccountingLinesDetails(capitalAccountingLine, existingCapitalAsset);
1483 }
1484 }
1485 }
1486
1487
1488
1489
1490
1491 protected void createCapitalAssetInformationDetail(CapitalAssetInformation capitalAsset) {
1492 CapitalAssetInformationDetail assetDetail = new CapitalAssetInformationDetail();
1493 assetDetail.setDocumentNumber(capitalAsset.getDocumentNumber());
1494 assetDetail.setCapitalAssetLineNumber(capitalAsset.getCapitalAssetLineNumber());
1495 assetDetail.setItemLineNumber(getNextLineItemNumber(capitalAsset));
1496 capitalAsset.getCapitalAssetInformationDetails().add(0,assetDetail);
1497 }
1498
1499
1500
1501
1502
1503
1504
1505
1506 protected Integer getNextLineItemNumber(CapitalAssetInformation capitalAsset) {
1507 Integer nextLineNumber = 0;
1508 List<CapitalAssetInformationDetail> capitalAssetDetails = capitalAsset.getCapitalAssetInformationDetails();
1509 for (CapitalAssetInformationDetail capitalAssetDetail : capitalAssetDetails) {
1510 nextLineNumber = capitalAssetDetail.getItemLineNumber();
1511 }
1512
1513 return ++nextLineNumber;
1514 }
1515
1516 protected void calculateRemainingDistributedAmount(CapitalAccountingLinesFormBase calfb, List<CapitalAssetInformation> capitalAssetInformation) {
1517 calfb.setCreatedAssetsControlAmount(calfb.getSystemControlAmount());
1518
1519
1520 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
1521 calfb.setCreatedAssetsControlAmount(calfb.getCreatedAssetsControlAmount().subtract(capitalAsset.getCapitalAssetLineAmount()));
1522 }
1523 }
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534 protected boolean capitalAccountingLineMissing(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetAccountsGroupDetails> groupAccountLines, Integer capitalAssetLineNumber) {
1535 boolean missing = true;
1536
1537 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
1538 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAssetLineNumber) == 0 &&
1539 groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
1540 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
1541 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
1542 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
1543 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
1544 return false;
1545 }
1546 }
1547
1548 return missing;
1549 }
1550
1551
1552
1553
1554
1555
1556
1557
1558 protected void checkCapitalAccountingLinesSelected(CapitalAccountingLinesFormBase calfb) {
1559 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
1560
1561 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
1562
1563 KualiAccountingDocumentFormBase kadfb = calfb;
1564
1565 List<CapitalAssetInformation> currentCapitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kadfb);
1566
1567 calfb.setCreatedAssetsControlAmount(KualiDecimal.ZERO);
1568 calfb.setSystemControlAmount(KualiDecimal.ZERO);
1569
1570 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1571 if (capitalAccountingLine.isSelectLine()) {
1572 calfb.setSystemControlAmount(calfb.getSystemControlAmount().add(capitalAccountingLine.getAmount()));
1573 }
1574
1575 if (currentCapitalAssetInformation.size() <= 0) {
1576 capitalAccountingLine.setAccountLinePercent(null);
1577 capitalAccountingLine.setAmountDistributed(false);
1578 capitalAccountingLine.setSelectLine(false);
1579 } else {
1580 CapitalAssetInformation existingCapitalAsset = getCapitalAssetCreated(capitalAccountingLine, currentCapitalAssetInformation);
1581 if (ObjectUtils.isNotNull(existingCapitalAsset)) {
1582 capitalAccountingLine.setSelectLine(true);
1583 } else {
1584 capitalAccountingLine.setAccountLinePercent(null);
1585 capitalAccountingLine.setSelectLine(false);
1586 }
1587 }
1588
1589 if (capitalAccountingLineAmountDistributed(capitalAccountingLine, currentCapitalAssetInformation)) {
1590 capitalAccountingLine.setAmountDistributed(true);
1591 } else {
1592 capitalAccountingLine.setAmountDistributed(false);
1593 }
1594 }
1595
1596 KualiDecimal capitalAssetsTotal = KualiDecimal.ZERO;
1597
1598
1599 for (CapitalAssetInformation capitalAsset : currentCapitalAssetInformation) {
1600 capitalAssetsTotal= capitalAssetsTotal.add(capitalAsset.getCapitalAssetLineAmount());
1601 }
1602
1603 calfb.setCreatedAssetsControlAmount(calfb.getSystemControlAmount().subtract(capitalAssetsTotal));
1604 }
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617 protected void setTabStatesForCapitalAssets(ActionForm form) {
1618 KualiForm kualiForm = (KualiForm) form;
1619
1620 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) form;
1621
1622
1623 Map<String, String> tabStates = kualiForm.getTabStates();
1624 Map<String, String> newTabStates = new HashMap<String, String>();
1625
1626 CapitalAssetInformationFormBase capitalAssetInformationFormBase = (CapitalAssetInformationFormBase) form;
1627 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAssetInformationFormBase.getFinancialDocument();
1628
1629
1630 String tabIdForAccountingLinesForCapitalization = WebUtils.generateTabKey(OLEConstants.CapitalAssets.ACCOUNTING_LINES_FOR_CAPITALIZATION_TAB_TITLE);
1631 String tabIdForCreateCapitalAsset = WebUtils.generateTabKey(OLEConstants.CapitalAssets.CREATE_CAPITAL_ASSETS_TAB_TITLE);
1632 String tabIdForModifyCapitalAsset = WebUtils.generateTabKey(OLEConstants.CapitalAssets.MODIFY_CAPITAL_ASSETS_TAB_TITLE);
1633
1634 tabStates.remove(tabIdForAccountingLinesForCapitalization);
1635 tabStates.remove(tabIdForCreateCapitalAsset);
1636 tabStates.remove(tabIdForModifyCapitalAsset);
1637
1638
1639 if (caldb.getCapitalAccountingLines().size() > 0) {
1640 tabStates.put(tabIdForAccountingLinesForCapitalization, OLEConstants.CapitalAssets.CAPITAL_ASSET_TAB_STATE_OPEN);
1641 }
1642 else {
1643 tabStates.put(tabIdForAccountingLinesForCapitalization, OLEConstants.CapitalAssets.CAPITAL_ASSET_TAB_STATE_CLOSE);
1644 }
1645
1646 if (checkCreateAssetsExist(capitalAccountingLinesFormBase)) {
1647 tabStates.put(tabIdForCreateCapitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_TAB_STATE_OPEN);
1648 }
1649 else {
1650 tabStates.put(tabIdForCreateCapitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_TAB_STATE_CLOSE);
1651 }
1652
1653 if (checkModifyAssetsExist(capitalAccountingLinesFormBase)) {
1654 tabStates.put(tabIdForModifyCapitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_TAB_STATE_OPEN);
1655 }
1656 else {
1657 tabStates.put(tabIdForModifyCapitalAsset, OLEConstants.CapitalAssets.CAPITAL_ASSET_TAB_STATE_CLOSE);
1658 }
1659
1660 kualiForm.setTabStates(tabStates);
1661 }
1662
1663
1664
1665
1666
1667
1668 protected boolean checkCreateAssetsExist(CapitalAccountingLinesFormBase capitalAccountingLinesFormBase) {
1669 boolean exists = false;
1670
1671 CapitalAssetInformationDocumentBase capitalAssetInformationDocumentBase = (CapitalAssetInformationDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
1672
1673 List<CapitalAssetInformation> capitalAssets = capitalAssetInformationDocumentBase.getCapitalAssetInformation();
1674 for (CapitalAssetInformation capitalAsset : capitalAssets) {
1675 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator())) {
1676 return true;
1677 }
1678 }
1679
1680 return exists;
1681 }
1682
1683
1684
1685
1686
1687
1688 protected boolean checkModifyAssetsExist(CapitalAccountingLinesFormBase capitalAccountingLinesFormBase) {
1689 boolean exists = false;
1690
1691 CapitalAssetInformationDocumentBase capitalAssetInformationDocumentBase = (CapitalAssetInformationDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
1692
1693 List<CapitalAssetInformation> capitalAssets = capitalAssetInformationDocumentBase.getCapitalAssetInformation();
1694 for (CapitalAssetInformation capitalAsset : capitalAssets) {
1695 if (OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator())) {
1696 return true;
1697 }
1698 }
1699
1700 return exists;
1701 }
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712 public ActionForward redistributeCreateCapitalAssetAmount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1713 LOG.debug("redistributeCreateCapitalAssetAmount() - start");
1714
1715 KualiDecimal remainingAmountToDistribute = KualiDecimal.ZERO;
1716
1717 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
1718 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
1719 List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
1720 String distributionCode = calfb.getCapitalAccountingLine().getDistributionCode();
1721
1722 remainingAmountToDistribute = getRemainingAmounToDistribute(selectedCapitalAccountingLines, form);
1723
1724 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
1725 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
1726
1727
1728 redistributeEqualAmountsForAccountingLineForCreateAssets(selectedCapitalAccountingLines, capitalAssetInformation, remainingAmountToDistribute);
1729
1730 redistributeIndividualAmountsForAccountingLinesForCreateAssets(selectedCapitalAccountingLines, capitalAssetInformation);
1731
1732
1733 adjustCapitalAssetsAccountingLinesAmounts(selectedCapitalAccountingLines, capitalAssetInformation);
1734
1735
1736
1737
1738 checkCapitalAccountingLinesSelected(calfb);
1739
1740 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1741 }
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752 public ActionForward redistributeModifyCapitalAssetAmount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1753 LOG.debug("redistributeModifyCapitalAssetAmount() - start");
1754
1755 KualiDecimal remainingAmountToDistribute = KualiDecimal.ZERO;
1756 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
1757 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
1758 List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
1759 String distributionCode = calfb.getCapitalAccountingLine().getDistributionCode();
1760
1761 remainingAmountToDistribute = getRemainingAmounToDistribute(selectedCapitalAccountingLines, form);
1762
1763 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
1764 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
1765
1766
1767 redistributeAmountsForAccountingsLineForModifyAssets(selectedCapitalAccountingLines, capitalAssetInformation, remainingAmountToDistribute);
1768
1769 redistributeIndividualAmountsForAccountingLinesForModifyAssets(selectedCapitalAccountingLines, capitalAssetInformation);
1770
1771
1772 redistributeAmountsForAccountingsLineForModifyAssetsByAmounts(selectedCapitalAccountingLines, capitalAssetInformation, remainingAmountToDistribute);
1773
1774
1775 adjustCapitalAssetsAccountingLinesAmounts(selectedCapitalAccountingLines, capitalAssetInformation);
1776
1777 processRemainingCapitalAssetInfo(form, capitalAssetInformation);
1778
1779
1780 DistributeCapitalAssetAmountToGroupAccountingLines((KualiAccountingDocumentFormBase) form);
1781
1782 checkCapitalAccountingLinesSelected(calfb);
1783
1784 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1785 }
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795 protected KualiDecimal getRemainingAmounToDistribute(List<CapitalAccountingLines> selectedCapitalAccountingLines, ActionForm form) {
1796 KualiDecimal remainingAmountToDistribute = KualiDecimal.ZERO;
1797 KualiDecimal capitalAccountsAmountToDistribute = KualiDecimal.ZERO;
1798 KualiDecimal capitalAssetsAllocatedAmount = KualiDecimal.ZERO;
1799
1800 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
1801
1802 CapitalAssetInformationDocumentBase capitalAssetInformationDocumentBase = (CapitalAssetInformationDocumentBase) calfb.getFinancialDocument();
1803 List<CapitalAssetInformation> capitalAssets = capitalAssetInformationDocumentBase.getCapitalAssetInformation();
1804
1805 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
1806 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
1807
1808 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1809 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
1810 selectedCapitalAccountingLines.add(capitalAccountingLine);
1811 capitalAccountsAmountToDistribute = capitalAccountsAmountToDistribute.add(capitalAccountingLine.getAmount());
1812 capitalAssetsAllocatedAmount = capitalAssetsAllocatedAmount.add(getCapitalAssetsAmountAllocated(capitalAssets, capitalAccountingLine));
1813 }
1814 }
1815
1816 remainingAmountToDistribute = capitalAccountsAmountToDistribute.subtract(capitalAssetsAllocatedAmount);
1817
1818 return remainingAmountToDistribute;
1819 }
1820
1821
1822
1823
1824
1825
1826
1827 protected void deleteCapitalAssetLines(KualiAccountingDocumentFormBase financialDocumentForm, AccountingLine accountingLine) {
1828 CapitalAssetInformationDocumentBase capitalAssetInformationDocumentBase = (CapitalAssetInformationDocumentBase) financialDocumentForm.getFinancialDocument();
1829
1830 List<CapitalAssetInformation> removalCaiList = new ArrayList<CapitalAssetInformation>();
1831
1832 List<CapitalAssetInformation> capitalAssets = capitalAssetInformationDocumentBase.getCapitalAssetInformation();
1833 for (CapitalAssetInformation capitalAsset : capitalAssets) {
1834 removeDistributedAccountingLine(capitalAsset, accountingLine);
1835 if (capitalAsset.getCapitalAssetAccountsGroupDetails().size() == 0) {
1836 capitalAsset.getCapitalAssetInformationDetails().clear();
1837 removalCaiList.add(capitalAsset);
1838 }
1839 }
1840
1841
1842
1843 if (ObjectUtils.isNotNull(removalCaiList)) {
1844 capitalAssets.removeAll(removalCaiList);
1845 }
1846 }
1847
1848
1849
1850
1851
1852
1853
1854 protected void removeDistributedAccountingLine(CapitalAssetInformation capitalAsset, AccountingLine accountingLine) {
1855 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
1856 CapitalAssetAccountsGroupDetails accountLineToDelete = null;
1857
1858 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
1859 if (groupAccountLine.getSequenceNumber().compareTo(accountingLine.getSequenceNumber()) == 0 &&
1860 groupAccountLine.getFinancialDocumentLineTypeCode().equals(groupAccountLine.getFinancialDocumentLineTypeCode()) &&
1861 groupAccountLine.getChartOfAccountsCode().equals(accountingLine.getChartOfAccountsCode()) &&
1862 groupAccountLine.getAccountNumber().equals(accountingLine.getAccountNumber()) &&
1863 groupAccountLine.getFinancialObjectCode().equals(accountingLine.getFinancialObjectCode())) {
1864 accountLineToDelete = groupAccountLine;
1865 break;
1866 }
1867 }
1868
1869 if (ObjectUtils.isNotNull(accountLineToDelete)) {
1870 capitalAsset.setCapitalAssetLineAmount(capitalAsset.getCapitalAssetLineAmount().subtract(accountLineToDelete.getAmount()));
1871 groupAccountLines.remove(accountLineToDelete);
1872 }
1873 }
1874
1875
1876
1877
1878
1879
1880 protected void addCapitalAssetInfoDetailLines(CapitalAssetInformation capitalAssetInformation) {
1881 LOG.debug("addCapitalAssetInfoDetailLines() - start");
1882
1883 if (ObjectUtils.isNull(capitalAssetInformation)) {
1884 return;
1885 }
1886
1887 Integer quantity = capitalAssetInformation.getCapitalAssetQuantity();
1888 if (quantity == null || quantity <= 0) {
1889 String errorPath = OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.CAPITAL_ASSET_INFORMATION;
1890 GlobalVariables.getMessageMap().putError(errorPath, OLEKeyConstants.ERROR_INVALID_CAPITAL_ASSET_QUANTITY);
1891 return;
1892 }
1893
1894 List<CapitalAssetInformationDetail> detailLines = capitalAssetInformation.getCapitalAssetInformationDetails();
1895 Integer nextItemLineNumber = 0;
1896
1897 if (ObjectUtils.isNotNull(detailLines) || detailLines.size() > 0) {
1898 for (CapitalAssetInformationDetail detailLine : detailLines) {
1899 nextItemLineNumber = detailLine.getItemLineNumber().intValue();
1900 }
1901 }
1902
1903
1904 for (int index = 1; detailLines.size() < quantity; index++) {
1905 CapitalAssetInformationDetail detailLine = new CapitalAssetInformationDetail();
1906 detailLine.setDocumentNumber(capitalAssetInformation.getDocumentNumber());
1907 detailLine.setCapitalAssetLineNumber(capitalAssetInformation.getCapitalAssetLineNumber());
1908 detailLine.setItemLineNumber(++nextItemLineNumber);
1909 detailLines.add(detailLine);
1910 }
1911 }
1912
1913
1914
1915
1916
1917
1918 protected void uncheckCapitalAccountingLinesSelected(CapitalAccountingLinesFormBase calfb) {
1919 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getDocument();
1920
1921 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
1922 KualiAccountingDocumentFormBase kadfb = calfb;
1923
1924 List<CapitalAssetInformation> currentCapitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kadfb);
1925
1926
1927 List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
1928
1929 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1930 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
1931 calfb.setSystemControlAmount(calfb.getSystemControlAmount().add(capitalAccountingLine.getAmount()));
1932 selectedCapitalAccountingLines.add(capitalAccountingLine);
1933 }
1934 }
1935
1936 CapitalAssetInformation existingCapitalAsset = capitalAssetCreated(selectedCapitalAccountingLines, currentCapitalAssetInformation);
1937
1938 for (CapitalAccountingLines capitalAccountingLine : selectedCapitalAccountingLines) {
1939 if (ObjectUtils.isNull(existingCapitalAsset)) {
1940 capitalAccountingLine.setSelectLine(false);
1941 }
1942 }
1943 }
1944
1945
1946
1947
1948
1949
1950
1951 protected void checkSelectForCapitalAccountingLines(CapitalAccountingLinesFormBase calfb) {
1952 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
1953 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
1954 KualiAccountingDocumentFormBase kadfb = calfb;
1955 List<CapitalAssetInformation> currentCapitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kadfb);
1956
1957 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
1958 if (currentCapitalAssetInformation.size() <= 0) {
1959 capitalAccountingLine.setSelectLine(false);
1960 } else {
1961 CapitalAssetInformation existingCapitalAsset = getCapitalAssetCreated(capitalAccountingLine, currentCapitalAssetInformation);
1962 if (ObjectUtils.isNotNull(existingCapitalAsset)) {
1963 capitalAccountingLine.setSelectLine(true);
1964 } else {
1965 capitalAccountingLine.setSelectLine(false);
1966 }
1967 }
1968 }
1969 }
1970
1971
1972
1973
1974
1975
1976
1977 protected KualiDecimal getAccountingLinesTotalAmount(CapitalAssetInformation capitalAssetInformation) {
1978 KualiDecimal accountingLinesTotalAmount = KualiDecimal.ZERO;
1979
1980 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAssetInformation.getCapitalAssetAccountsGroupDetails();
1981
1982 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
1983 accountingLinesTotalAmount = accountingLinesTotalAmount.add(groupAccountLine.getAmount());
1984 }
1985
1986 return accountingLinesTotalAmount;
1987 }
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997 protected KualiDecimal getAccountingLinesDistributedAmount(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetInformation> capitalAssetInformation, String actionTypeCode) {
1998 KualiDecimal accountingLinesTotalAmount = KualiDecimal.ZERO;
1999
2000 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
2001 if (capitalAsset.getCapitalAssetActionIndicator().equalsIgnoreCase(actionTypeCode)) {
2002 accountingLinesTotalAmount = accountingLinesTotalAmount.add(getAccountingLineAmount(capitalAsset, capitalAccountingLine));
2003 }
2004 }
2005
2006 return accountingLinesTotalAmount;
2007 }
2008
2009
2010
2011
2012
2013
2014
2015 protected void adjustAccountingLineAmountOnLastCapitalAsset(CapitalAccountingLines capitalAccountingLine, CapitalAssetInformation lastCapitalAsset, KualiDecimal difference) {
2016 List<CapitalAssetAccountsGroupDetails> groupAccountLines = lastCapitalAsset.getCapitalAssetAccountsGroupDetails();
2017
2018 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
2019 if (groupAccountLine.getCapitalAssetLineNumber().compareTo(lastCapitalAsset.getCapitalAssetLineNumber()) == 0 &&
2020 groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
2021 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
2022 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
2023 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
2024 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
2025 groupAccountLine.setAmount(groupAccountLine.getAmount().add(difference));
2026 }
2027 }
2028 }
2029
2030
2031
2032
2033
2034
2035
2036 protected void redistributeToGroupAccountingLinesFromAssetsByAmounts(List<CapitalAccountingLines> selectedCapitalAccountingLines, CapitalAssetInformation capitalAsset) {
2037 KualiDecimal amountToDistribute = capitalAsset.getCapitalAssetLineAmount();
2038 KualiDecimal amountDistributed = KualiDecimal.ZERO;
2039
2040 KualiDecimal totalCapitalAccountsAmount = getTotalCapitalAccountsAmounts(selectedCapitalAccountingLines);
2041
2042
2043 CapitalAssetAccountsGroupDetails lastGroupAccountLine = new CapitalAssetAccountsGroupDetails();
2044
2045 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
2046 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
2047 BigDecimal linePercent = getCapitalAccountingLinePercent(selectedCapitalAccountingLines, groupAccountLine, totalCapitalAccountsAmount);
2048
2049 lastGroupAccountLine = groupAccountLine;
2050
2051 KualiDecimal groupAccountLineAmount = capitalAsset.getCapitalAssetLineAmount().multiply(new KualiDecimal(linePercent));
2052 groupAccountLine.setAmount(groupAccountLineAmount);
2053
2054
2055 amountDistributed = amountDistributed.add(groupAccountLineAmount);
2056 }
2057
2058
2059 lastGroupAccountLine.setAmount(lastGroupAccountLine.getAmount().add(amountToDistribute.subtract(amountDistributed)));
2060 }
2061
2062
2063
2064
2065
2066
2067
2068 protected KualiDecimal getTotalCapitalAccountsAmounts(List<CapitalAccountingLines> capitalAccountingLines) {
2069 KualiDecimal totalCapitalAccountsAmount = KualiDecimal.ZERO;
2070 for (CapitalAccountingLines capitalLine : capitalAccountingLines) {
2071 totalCapitalAccountsAmount = totalCapitalAccountsAmount.add(capitalLine.getAmount());
2072 }
2073
2074 return totalCapitalAccountsAmount;
2075 }
2076
2077
2078
2079
2080
2081
2082
2083
2084 protected void DistributeCapitalAssetAmountToGroupAccountingLines(KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase) {
2085 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) kualiAccountingDocumentFormBase;
2086 checkSelectForCapitalAccountingLines(capitalAccountingLinesFormBase);
2087
2088 checkCapitalAccountingLinesSelected(capitalAccountingLinesFormBase);
2089 calculatePercentsForSelectedCapitalAccountingLines(capitalAccountingLinesFormBase);
2090
2091 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
2092 String distributionAmountCode = capitalAccountingLinesFormBase.getCapitalAccountingLine().getDistributionCode();
2093
2094 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
2095
2096 List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
2097
2098 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
2099 if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
2100 capitalAccountingLine.setDistributionAmountCode(OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR);
2101 selectedCapitalAccountingLines.add(capitalAccountingLine);
2102 }
2103 }
2104
2105 List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
2106
2107 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
2108
2109
2110 if (!capitalAssetAmountAlreadyDistributedToGroupAccountingLines(capitalAsset)) {
2111 redistributeToGroupAccountingLinesFromAssetsByAmounts(selectedCapitalAccountingLines, capitalAsset);
2112 }
2113 }
2114 }
2115
2116
2117
2118
2119
2120
2121
2122 protected boolean capitalAssetAmountAlreadyDistributedToGroupAccountingLines(CapitalAssetInformation capitalAsset) {
2123 boolean amountDistributed = true;
2124
2125 KualiDecimal capitalAssetAmount = capitalAsset.getCapitalAssetLineAmount();
2126 KualiDecimal totalAmountDistributed = KualiDecimal.ZERO;
2127
2128 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
2129 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
2130
2131 totalAmountDistributed = totalAmountDistributed.add(groupAccountLine.getAmount());
2132 }
2133
2134 return (capitalAssetAmount.compareTo(totalAmountDistributed) == 0);
2135 }
2136 }