01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.purap.web.struts.form;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: import org.kuali.core.util.ObjectUtils;
22: import org.kuali.core.util.TypedArrayList;
23: import org.kuali.kfs.bo.AccountingLine;
24: import org.kuali.kfs.context.SpringContext;
25: import org.kuali.kfs.web.struts.form.KualiAccountingDocumentFormBase;
26: import org.kuali.module.purap.bo.PurApAccountingLine;
27: import org.kuali.module.purap.bo.PurApItem;
28: import org.kuali.module.purap.document.PurchasingAccountsPayableDocument;
29: import org.kuali.module.purap.service.PurapAccountingService;
30: import org.kuali.module.purap.util.SummaryAccount;
31:
32: /**
33: * Struts Action Form for Purchasing and Accounts Payable documents.
34: */
35: public class PurchasingAccountsPayableFormBase extends
36: KualiAccountingDocumentFormBase {
37:
38: private List<SummaryAccount> summaryAccounts;
39:
40: /**
41: * Constructs a PurchasingAccountsPayableFormBase instance and initializes summary accounts.
42: */
43: public PurchasingAccountsPayableFormBase() {
44: super ();
45: clearSummaryAccounts();
46: }
47:
48: /**
49: * Updates the summaryAccounts that are contained in the form. Currently we are only calling this on load and when
50: * refreshAccountSummary is called.
51: */
52: public void refreshAccountSummmary() {
53: clearSummaryAccounts();
54: PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) getDocument();
55: summaryAccounts.addAll(SpringContext.getBean(
56: PurapAccountingService.class).generateSummaryAccounts(
57: purapDocument));
58: }
59:
60: /**
61: * Initializes summary accounts.
62: */
63: public void clearSummaryAccounts() {
64: summaryAccounts = new TypedArrayList(SummaryAccount.class);
65: }
66:
67: /**
68: * @see org.kuali.kfs.web.struts.form.KualiAccountingDocumentFormBase#getBaselineSourceAccountingLines()
69: */
70: @Override
71: public List getBaselineSourceAccountingLines() {
72: List<AccountingLine> accounts = super
73: .getBaselineSourceAccountingLines();
74: if (ObjectUtils.isNull(accounts) || accounts.isEmpty()) {
75: accounts = new ArrayList<AccountingLine>();
76: for (PurApItem item : ((PurchasingAccountsPayableDocument) getDocument())
77: .getItems()) {
78: List<PurApAccountingLine> lines = item
79: .getBaselineSourceAccountingLines();
80: for (PurApAccountingLine line : lines) {
81: accounts.add(line);
82: }
83:
84: }
85: }
86: return accounts;
87: }
88:
89: public List<SummaryAccount> getSummaryAccounts() {
90: return summaryAccounts;
91: }
92:
93: public void setSummaryAccounts(List<SummaryAccount> summaryAccounts) {
94: this.summaryAccounts = summaryAccounts;
95: }
96: }
|