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.io.FileNotFoundException;
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.kuali.ole.fp.businessobject.CapitalAccountingLines;
31 import org.kuali.ole.fp.businessobject.CapitalAssetAccountsGroupDetails;
32 import org.kuali.ole.fp.businessobject.CapitalAssetInformation;
33 import org.kuali.ole.fp.businessobject.CapitalAssetInformationDetail;
34 import org.kuali.ole.fp.businessobject.options.CapitalAccountingLinesComparator;
35 import org.kuali.ole.fp.document.CapitalAccountingLinesDocumentBase;
36 import org.kuali.ole.fp.document.validation.event.CapitalAccountingLinesSameObjectCodeSubTypeEvent;
37 import org.kuali.ole.integration.cab.CapitalAssetBuilderModuleService;
38 import org.kuali.ole.sys.OLEConstants;
39 import org.kuali.ole.sys.OLEKeyConstants;
40 import org.kuali.ole.sys.businessobject.AccountingLine;
41 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
42 import org.kuali.ole.sys.businessobject.TargetAccountingLine;
43 import org.kuali.ole.sys.context.SpringContext;
44 import org.kuali.ole.sys.document.AccountingDocument;
45 import org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase;
46 import org.kuali.rice.core.api.config.property.ConfigurationService;
47 import org.kuali.rice.core.api.util.RiceConstants;
48 import org.kuali.rice.kew.api.exception.WorkflowException;
49 import org.kuali.rice.kns.question.ConfirmationQuestion;
50 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
51 import org.kuali.rice.kns.web.struts.form.KualiForm;
52 import org.kuali.rice.krad.document.Document;
53 import org.kuali.rice.krad.service.KualiRuleService;
54 import org.kuali.rice.krad.util.GlobalVariables;
55 import org.kuali.rice.krad.util.ObjectUtils;
56
57
58
59
60 public abstract class CapitalAccountingLinesActionBase extends CapitalAssetInformationActionBase {
61 private CapitalAssetBuilderModuleService capitalAssetBuilderModuleService = SpringContext.getBean(CapitalAssetBuilderModuleService.class);
62
63
64
65
66
67
68 @Override
69 public ActionForward correct(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
70 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) form;
71 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
72 caldb.getCapitalAccountingLines().clear();
73
74 super.correct(mapping, capitalAccountingLinesFormBase, request, response);
75
76 KualiAccountingDocumentFormBase kadfb = (KualiAccountingDocumentFormBase) form;
77 List<CapitalAssetInformation> currentCapitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kadfb);
78 for (CapitalAssetInformation capitalAsset : currentCapitalAssetInformation) {
79 capitalAsset.setCapitalAssetProcessedIndicator(false);
80 capitalAsset.setCapitalAssetLineAmount(capitalAsset.getCapitalAssetLineAmount().negated());
81
82
83 List<CapitalAssetInformationDetail> tagLocationDetails = capitalAsset.getCapitalAssetInformationDetails();
84 for (CapitalAssetInformationDetail tagLocationDetail : tagLocationDetails) {
85 tagLocationDetail.setCapitalAssetTagNumber(null);
86 tagLocationDetail.setCapitalAssetSerialNumber(null);
87 }
88
89 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
90 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
91 groupAccountLine.setAmount(groupAccountLine.getAmount().negated());
92 }
93 }
94
95 String distributionAmountCode = capitalAccountingLinesFormBase.getCapitalAccountingLine().getDistributionCode();
96
97 AccountingDocument tdoc = (AccountingDocument) capitalAccountingLinesFormBase.getDocument();
98
99 List<CapitalAccountingLines> capitalAccountingLines = new ArrayList();
100
101
102
103 createCapitalAccountingLines(capitalAccountingLines, tdoc, distributionAmountCode);
104 sortCaptitalAccountingLines(capitalAccountingLines);
105
106 caldb.setCapitalAccountingLines(capitalAccountingLines);
107
108 checkSelectForCapitalAccountingLines(capitalAccountingLinesFormBase);
109
110 checkCapitalAccountingLinesSelected(capitalAccountingLinesFormBase);
111 calculatePercentsForSelectedCapitalAccountingLines(capitalAccountingLinesFormBase);
112
113
114 setupIntialNextCapitalAssetLineNumber(capitalAccountingLinesFormBase);
115
116 return mapping.findForward(RiceConstants.MAPPING_BASIC);
117 }
118
119
120
121
122
123
124 @Override
125 protected void loadDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
126 super.loadDocument(kualiDocumentFormBase);
127
128 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) kualiDocumentFormBase;
129 String distributionAmountCode = capitalAccountingLinesFormBase.getCapitalAccountingLine().getDistributionCode();
130
131 AccountingDocument tdoc = (AccountingDocument) kualiDocumentFormBase.getDocument();
132
133 List<CapitalAccountingLines> capitalAccountingLines = new ArrayList();
134
135
136
137 createCapitalAccountingLines(capitalAccountingLines, tdoc, distributionAmountCode);
138 sortCaptitalAccountingLines(capitalAccountingLines);
139
140 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) tdoc;
141 caldb.setCapitalAccountingLines(capitalAccountingLines);
142
143 checkSelectForCapitalAccountingLines(capitalAccountingLinesFormBase);
144
145 checkCapitalAccountingLinesSelected(capitalAccountingLinesFormBase);
146 calculatePercentsForSelectedCapitalAccountingLines(capitalAccountingLinesFormBase);
147
148
149 setupIntialNextCapitalAssetLineNumber(kualiDocumentFormBase);
150
151 KualiForm kualiForm = kualiDocumentFormBase;
152
153
154 setTabStatesForCapitalAssets(kualiForm);
155 }
156
157
158
159
160
161
162
163 @Override
164 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
165 super.refresh(mapping, form, request, response);
166
167 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) form;
168 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
169
170 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
171 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
172 AccountingDocument tdoc = (AccountingDocument) kualiDocumentFormBase.getDocument();
173
174 capitalAccountingLines = updateCapitalAccountingLines(capitalAccountingLines, tdoc);
175 sortCaptitalAccountingLines(capitalAccountingLines);
176 caldb.setCapitalAccountingLines(capitalAccountingLines);
177
178
179
180
181 KualiAccountingDocumentFormBase kadfb = (KualiAccountingDocumentFormBase) form;
182 List<CapitalAssetInformation> currentCapitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kadfb);
183
184 removeOrphanDisributedAccountingLines(capitalAccountingLines, currentCapitalAssetInformation);
185 checkCapitalAccountingLinesSelected(capitalAccountingLinesFormBase);
186 setTabStatesForCapitalAssets(form);
187
188 return mapping.findForward(OLEConstants.MAPPING_BASIC);
189 }
190
191
192
193
194
195
196 @Override
197 protected void insertAccountingLine(boolean isSource, KualiAccountingDocumentFormBase financialDocumentForm, AccountingLine line) {
198 super.insertAccountingLine(isSource, financialDocumentForm, line);
199
200 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) financialDocumentForm;
201 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
202 String distributionAmountCode = capitalAccountingLinesFormBase.getCapitalAccountingLine().getDistributionCode();
203
204 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
205
206
207
208 createCapitalAccountingLine(capitalAccountingLines, line, distributionAmountCode);
209 sortCaptitalAccountingLines(capitalAccountingLines);
210
211 KualiForm kualiForm = financialDocumentForm;
212
213 setTabStatesForCapitalAssets(kualiForm);
214 }
215
216
217
218
219
220
221
222
223 @Override
224 protected void deleteAccountingLine(boolean isSource, KualiAccountingDocumentFormBase financialDocumentForm, int deleteIndex) {
225
226 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) financialDocumentForm;
227 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
228
229 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
230
231 if (isSource) {
232
233 AccountingLine line = (AccountingLine) financialDocumentForm.getFinancialDocument().getSourceAccountingLines().get(deleteIndex);
234 deleteCapitalAccountingLine(capitalAccountingLines, line);
235 deleteCapitalAssetLines(financialDocumentForm, line);
236 }
237 else {
238
239 AccountingLine line = (AccountingLine) financialDocumentForm.getFinancialDocument().getTargetAccountingLines().get(deleteIndex);
240 deleteCapitalAccountingLine(capitalAccountingLines, line);
241 deleteCapitalAssetLines(financialDocumentForm, line);
242 }
243
244 super.deleteAccountingLine(isSource, financialDocumentForm, deleteIndex);
245 sortCaptitalAccountingLines(capitalAccountingLines);
246
247 KualiForm kualiForm = financialDocumentForm;
248
249
250 checkSelectForCapitalAccountingLines(capitalAccountingLinesFormBase);
251 checkCapitalAccountingLinesSelected(capitalAccountingLinesFormBase);
252 calculatePercentsForSelectedCapitalAccountingLines(capitalAccountingLinesFormBase);
253 setTabStatesForCapitalAssets(kualiForm);
254 }
255
256
257
258
259
260 @Override
261 protected void uploadAccountingLines(boolean isSource, ActionForm form) throws FileNotFoundException, IOException {
262 super.uploadAccountingLines(isSource, form);
263
264 KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
265 CapitalAccountingLinesFormBase capitalAccountingLinesFormBase = (CapitalAccountingLinesFormBase) form;
266 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) capitalAccountingLinesFormBase.getFinancialDocument();
267
268 String distributionAmountCode = capitalAccountingLinesFormBase.getCapitalAccountingLine().getDistributionCode();
269
270 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
271 AccountingDocument tdoc = (AccountingDocument) kualiAccountingDocumentFormBase.getDocument();
272
273 createCapitalAccountingLines(capitalAccountingLines, tdoc, distributionAmountCode);
274 sortCaptitalAccountingLines(capitalAccountingLines);
275
276 KualiForm kualiForm = (KualiForm) form;
277 setTabStatesForCapitalAssets(kualiForm);
278 }
279
280
281
282
283
284
285
286
287 protected void createCapitalAccountingLines(List<CapitalAccountingLines> capitalAccountingLines, AccountingDocument tdoc, String distributionAmountCode) {
288 List<SourceAccountingLine> sourceAccountLines = tdoc.getSourceAccountingLines();
289
290 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) tdoc;
291
292 for (SourceAccountingLine line : sourceAccountLines) {
293
294 createCapitalAccountingLine(capitalAccountingLines, line, distributionAmountCode);
295 }
296
297 List<TargetAccountingLine> targetAccountLines = tdoc.getTargetAccountingLines();
298
299 for (TargetAccountingLine line : targetAccountLines) {
300
301 createCapitalAccountingLine(capitalAccountingLines, line, distributionAmountCode);
302 }
303
304
305 sortCaptitalAccountingLines(capitalAccountingLines);
306 }
307
308
309
310
311
312
313
314 protected List<CapitalAccountingLines> updateCapitalAccountingLines(List<CapitalAccountingLines> capitalAccountingLines, AccountingDocument tdoc) {
315 List<SourceAccountingLine> sourceAccountLines = tdoc.getSourceAccountingLines();
316
317 for (SourceAccountingLine line : sourceAccountLines) {
318
319 updateCapitalAccountingLine(capitalAccountingLines, line);
320 }
321
322 List<TargetAccountingLine> targetAccountLines = tdoc.getTargetAccountingLines();
323
324 for (TargetAccountingLine line : targetAccountLines) {
325
326 updateCapitalAccountingLine(capitalAccountingLines, line);
327 }
328
329
330
331 return removeOrphanCapitalAccountingLines(capitalAccountingLines, tdoc);
332 }
333
334
335
336
337
338
339
340
341 protected List<CapitalAccountingLines> removeOrphanCapitalAccountingLines(List<CapitalAccountingLines> capitalAccountingLines, AccountingDocument tdoc) {
342 List<CapitalAccountingLines> newCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
343 if ( capitalAccountingLines != null ) {
344 List<AccountingLine> sourceAccountLines = tdoc.getSourceAccountingLines();
345 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
346 if (removeOrphanCapitalAccountingLine(sourceAccountLines, capitalAccountingLine)) {
347 newCapitalAccountingLines.add(capitalAccountingLine);
348 }
349 }
350
351 List<AccountingLine> targetAccountLines = tdoc.getTargetAccountingLines();
352 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
353 if (removeOrphanCapitalAccountingLine(targetAccountLines, capitalAccountingLine)) {
354 newCapitalAccountingLines.add(capitalAccountingLine);
355 }
356 }
357 }
358 return newCapitalAccountingLines;
359 }
360
361
362
363
364
365
366
367
368
369 protected boolean removeOrphanCapitalAccountingLine(List<AccountingLine> accountLines, CapitalAccountingLines capitalAccountingLine) {
370 boolean found = false;
371
372 for (AccountingLine accountingLine : accountLines) {
373 if (capitalAccountingLine.getChartOfAccountsCode().equals(accountingLine.getChartOfAccountsCode()) &&
374 capitalAccountingLine.getAccountNumber().equals(accountingLine.getAccountNumber()) &&
375 capitalAccountingLine.getFinancialObjectCode().equals(accountingLine.getFinancialObjectCode()) &&
376 capitalAccountingLine.getLineType().equalsIgnoreCase(accountingLine instanceof SourceAccountingLine ? OLEConstants.SOURCE : OLEConstants.TARGET)) {
377 found = true;
378 }
379 }
380
381 return found;
382 }
383
384
385
386
387
388
389
390
391 protected void removeOrphanDisributedAccountingLines(List<CapitalAccountingLines> capitalAccountingLines, List<CapitalAssetInformation> capitalAssets) {
392 List<CapitalAssetInformation> removalCaiList = new ArrayList<CapitalAssetInformation>();
393
394 for (CapitalAssetInformation capitalAsset : capitalAssets) {
395 removeOrphanDisributedAccountingLine(capitalAccountingLines, capitalAsset);
396 if (capitalAsset.getCapitalAssetAccountsGroupDetails().size() == 0) {
397 capitalAsset.getCapitalAssetInformationDetails().clear();
398 removalCaiList.add(capitalAsset);
399 }
400 }
401
402
403 if (ObjectUtils.isNotNull(removalCaiList)) {
404 capitalAssets.removeAll(removalCaiList);
405 }
406 }
407
408
409
410
411
412
413
414
415 protected void removeOrphanDisributedAccountingLine(List<CapitalAccountingLines> capitalAccountingLines, CapitalAssetInformation capitalAsset) {
416 List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
417 CapitalAssetAccountsGroupDetails accountLineToDelete = null;
418
419 for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
420 if (!checkDistributedAccountingLineExists(capitalAccountingLines, groupAccountLine)) {
421 accountLineToDelete = groupAccountLine;
422 break;
423 }
424 }
425
426 if (ObjectUtils.isNotNull(accountLineToDelete)) {
427
428 capitalAsset.getCapitalAssetAccountsGroupDetails().clear();
429 }
430 }
431
432
433
434
435
436
437
438
439
440 protected boolean checkDistributedAccountingLineExists(List<CapitalAccountingLines> capitalAccountingLines, CapitalAssetAccountsGroupDetails groupAccountLine) {
441 boolean exists = false;
442
443 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
444 if (groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 &&
445 groupAccountLine.getFinancialDocumentLineTypeCode().equals(OLEConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE : OLEConstants.TARGET_ACCT_LINE_TYPE_CODE) &&
446 groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) &&
447 groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) &&
448 groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
449 return true;
450 }
451 }
452
453 return false;
454 }
455
456
457
458
459
460
461
462
463
464
465 protected List<CapitalAccountingLines> createCapitalAccountingLine(List<CapitalAccountingLines> capitalAccountingLines, AccountingLine line, String distributionAmountCode) {
466 Integer sequenceNumber = capitalAccountingLines.size() + 1;
467
468 if (capitalAssetBuilderModuleService.hasCapitalAssetObjectSubType(line)) {
469
470 CapitalAccountingLines cal = addCapitalAccountingLine(capitalAccountingLines, line);
471 cal.setDistributionAmountCode(distributionAmountCode);
472 capitalAccountingLines.add(cal);
473 }
474
475 return capitalAccountingLines;
476 }
477
478
479
480
481
482
483
484
485
486
487 protected void updateCapitalAccountingLine(List<CapitalAccountingLines> capitalAccountingLines, AccountingLine line) {
488 boolean found = false;
489
490 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
491 if (capitalAccountingLine.getChartOfAccountsCode().equals(line.getChartOfAccountsCode()) &&
492 capitalAccountingLine.getAccountNumber().equals(line.getAccountNumber()) &&
493 capitalAccountingLine.getFinancialObjectCode().equals(line.getFinancialObjectCode()) &&
494 capitalAccountingLine.getLineType().equalsIgnoreCase(line instanceof SourceAccountingLine ? OLEConstants.SOURCE : OLEConstants.TARGET) &&
495 capitalAccountingLine.getSequenceNumber().compareTo(line.getSequenceNumber()) == 0) {
496 capitalAccountingLine.setFinancialSubObjectCode(line.getFinancialSubObjectCode());
497 capitalAccountingLine.setSubAccountNumber(line.getSubAccountNumber());
498 capitalAccountingLine.setProjectCode(line.getProjectCode());
499 capitalAccountingLine.setOrganizationReferenceId(line.getOrganizationReferenceId());
500 capitalAccountingLine.setAmount(line.getAmount());
501 capitalAccountingLine.setFinancialDocumentLineDescription(line.getFinancialDocumentLineDescription());
502 found = true;
503 break;
504 }
505 }
506
507 if (!found) {
508
509 if (capitalAssetBuilderModuleService.hasCapitalAssetObjectSubType(line)) {
510 CapitalAccountingLines cal = addCapitalAccountingLine(capitalAccountingLines, line);
511 capitalAccountingLines.add(cal);
512 }
513 }
514 }
515
516
517
518
519
520
521
522
523
524 protected CapitalAccountingLines addCapitalAccountingLine(List<CapitalAccountingLines> capitalAccountingLines, AccountingLine line) {
525 CapitalAccountingLines cal = new CapitalAccountingLines();
526
527 if (line instanceof SourceAccountingLine) {
528 cal.setLineType(OLEConstants.SOURCE);
529 }
530 else {
531 cal.setLineType(OLEConstants.TARGET);
532 }
533 cal.setSequenceNumber(line.getSequenceNumber());
534 cal.setChartOfAccountsCode(line.getChartOfAccountsCode());
535 cal.setAccountNumber(line.getAccountNumber());
536 cal.setSubAccountNumber(line.getSubAccountNumber());
537 cal.setFinancialObjectCode(line.getFinancialObjectCode());
538 cal.setFinancialSubObjectCode(line.getFinancialSubObjectCode());
539 cal.setProjectCode(line.getProjectCode());
540 cal.setOrganizationReferenceId(line.getOrganizationReferenceId());
541 cal.setFinancialDocumentLineDescription(line.getFinancialDocumentLineDescription());
542 cal.setAmount(line.getAmount());
543 cal.setAccountLinePercent(null);
544 cal.setSelectLine(false);
545
546 return cal;
547 }
548
549
550
551
552
553
554
555
556 protected List<CapitalAccountingLines> deleteCapitalAccountingLine(List<CapitalAccountingLines> capitalAccountingLines, AccountingLine line) {
557 CapitalAccountingLines cal = null;
558
559 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
560 if (capitalAccountingLine.getChartOfAccountsCode().equals(line.getChartOfAccountsCode()) &&
561 capitalAccountingLine.getAccountNumber().equals(line.getAccountNumber()) &&
562 capitalAccountingLine.getFinancialObjectCode().equals(line.getFinancialObjectCode()) &&
563 capitalAccountingLine.getLineType().equalsIgnoreCase(line instanceof SourceAccountingLine ? OLEConstants.SOURCE : OLEConstants.TARGET)) {
564 cal = capitalAccountingLine;
565 break;
566 }
567 }
568
569 if (ObjectUtils.isNotNull(cal)) {
570 capitalAccountingLines.remove(cal);
571 }
572
573 return capitalAccountingLines;
574 }
575
576
577
578
579
580 protected void sortCaptitalAccountingLines(List<CapitalAccountingLines> capitalAccountingLines) {
581 CapitalAccountingLinesComparator calComparator = new CapitalAccountingLinesComparator();
582
583
584 Collections.sort(capitalAccountingLines, calComparator);
585 }
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602 public ActionForward createAsset(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
603 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
604 String distributionAmountCode = calfb.getCapitalAccountingLine().getDistributionCode();
605 if (OLEConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equals(distributionAmountCode)) {
606 calfb.setDistributeEqualAmount(true);
607 }
608 else {
609 calfb.setDistributeEqualAmount(false);
610 }
611
612 boolean createAction = calfb.getCapitalAccountingLine().isCanCreateAsset();
613 calfb.setEditCreateOrModify(false);
614
615 GlobalVariables.getMessageMap().clearErrorMessages();
616 if (!capitalAccountingLinesSelected(calfb)) {
617 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_ACCOUNTING_LINES_FOR_CAPITALIZATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_FOR_CAPITALIZATAION_REQUIRED_CREATE);
618 return mapping.findForward(OLEConstants.MAPPING_BASIC);
619 }
620 else {
621 calfb.setEditCreateOrModify(false);
622 }
623
624 Document document = calfb.getFinancialDocument();
625
626
627 if (checkObjecSubTypeCrossingCapitalAccountingLines(document)) {
628
629 ActionForward forward = performQuestionPrompt(mapping, form, request, response, OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR, distributionAmountCode);
630 if (forward != null) {
631 return forward;
632 }
633 }
634 else {
635 createCapitalAssetsForSelectedAccountingLines(form , calfb, OLEConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR, distributionAmountCode);
636 }
637
638
639 setTabStatesForCapitalAssets(form);
640
641 return mapping.findForward(OLEConstants.MAPPING_BASIC);
642 }
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659 public ActionForward modifyAsset(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
660 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
661 String distributionAmountCode = calfb.getCapitalAccountingLine().getDistributionCode();
662
663 if (OLEConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equals(distributionAmountCode)) {
664 calfb.setDistributeEqualAmount(true);
665 }
666 else {
667 calfb.setDistributeEqualAmount(false);
668 }
669
670 GlobalVariables.getMessageMap().clearErrorMessages();
671 if (!capitalAccountingLinesSelected(calfb)) {
672 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_ACCOUNTING_LINES_FOR_CAPITALIZATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_FOR_CAPITALIZATAION_REQUIRED_MODIFY);
673 return mapping.findForward(OLEConstants.MAPPING_BASIC);
674 }
675 else {
676 calfb.setEditCreateOrModify(false);
677 }
678
679 Document document = calfb.getFinancialDocument();
680
681
682 if (checkObjecSubTypeCrossingCapitalAccountingLines(document)) {
683
684 ActionForward forward = performQuestionPrompt(mapping, form, request, response, OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR, distributionAmountCode);
685 if (forward != null) {
686 return forward;
687 }
688 }
689 else {
690 createCapitalAssetsForSelectedAccountingLines(form , calfb, OLEConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR, distributionAmountCode);
691 }
692
693
694 setTabStatesForCapitalAssets(form);
695
696 return mapping.findForward(OLEConstants.MAPPING_BASIC);
697 }
698
699
700
701
702
703
704
705
706
707
708
709 protected void createCapitalAssetsForSelectedAccountingLines(ActionForm form, CapitalAccountingLinesFormBase calfb, String actionTypeIndicator, String distributionAmountCode) {
710 calculatePercentsForSelectedCapitalAccountingLines(calfb);
711 createCapitalAssetForGroupAccountingLines(calfb, actionTypeIndicator, distributionAmountCode);
712 checkCapitalAccountingLinesSelected(calfb);
713
714 KualiForm kualiForm = (KualiForm) form;
715 setTabStatesForCapitalAssets(kualiForm);
716 }
717
718
719
720
721
722
723
724
725
726 protected boolean capitalAccountingLinesSelected(CapitalAccountingLinesFormBase calfb) {
727 boolean selected = false;
728
729 CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
730 List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
731
732 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
733 if (capitalAccountingLine.isSelectLine()) {
734 selected = true;
735 break;
736 }
737 }
738
739 return selected;
740 }
741
742
743
744
745
746
747
748
749 protected boolean checkObjecSubTypeCrossingCapitalAccountingLines(Document document) {
750 boolean differentObjecSubtypes = true;
751 differentObjecSubtypes &= getRuleService().applyRules(new CapitalAccountingLinesSameObjectCodeSubTypeEvent(document));
752
753 return differentObjecSubtypes;
754 }
755
756
757
758
759
760
761
762
763
764
765
766 protected ActionForward performQuestionPrompt(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String actionTypeCode, String distributionAmountCode) throws Exception {
767 ActionForward forward = null;
768 Object question = request.getParameter(OLEConstants.QUESTION_INST_ATTRIBUTE_NAME);
769 CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
770
771 if (question == null) {
772 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.WARNING_NOT_SAME_OBJECT_SUB_TYPES);
773 return this.performQuestionWithoutInput(mapping, form, request, response, OLEConstants.OBJECT_SUB_TYPES_DIFFERENT_QUESTION, questionText, OLEConstants.CONFIRMATION_QUESTION, OLEConstants.ROUTE_METHOD, "");
774 }
775 else {
776 Object buttonClicked = request.getParameter(OLEConstants.QUESTION_CLICKED_BUTTON);
777
778 if (OLEConstants.OBJECT_SUB_TYPES_DIFFERENT_QUESTION.equals(question) && ConfirmationQuestion.YES.equals(buttonClicked)) {
779 createCapitalAssetsForSelectedAccountingLines(form , calfb, actionTypeCode, distributionAmountCode);
780
781 KualiForm kualiForm = (KualiForm) form;
782 setTabStatesForCapitalAssets(kualiForm);
783
784 return mapping.findForward(OLEConstants.MAPPING_BASIC);
785
786 }
787
788 else {
789 uncheckCapitalAccountingLinesSelected(calfb);
790 forward = mapping.findForward(OLEConstants.MAPPING_BASIC);
791 }
792 }
793
794 return forward;
795 }
796
797
798
799
800
801
802 protected KualiRuleService getRuleService() {
803 return SpringContext.getBean(KualiRuleService.class);
804 }
805 }