001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.financial.document;
017:
018: import java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import org.kuali.core.document.AmountTotaling;
023: import org.kuali.core.document.Copyable;
024: import org.kuali.core.document.Correctable;
025: import org.kuali.core.util.KualiDecimal;
026: import org.kuali.kfs.KFSConstants;
027: import org.kuali.kfs.bo.AccountingLineParser;
028: import org.kuali.kfs.bo.AccountingLineParserBase;
029: import org.kuali.kfs.document.AccountingDocumentBase;
030: import org.kuali.module.financial.bo.InternalBillingItem;
031:
032: /**
033: * This is the business object that represents the InternalBillingDocument in Kuali. This is a transactional document that will
034: * eventually post transactions to the G/L. It integrates with workflow and also contains two groupings of accounting lines: Expense
035: * and Income.
036: */
037: public class InternalBillingDocument extends AccountingDocumentBase
038: implements Copyable, Correctable, AmountTotaling {
039:
040: private List items;
041: private Integer nextItemLineNumber;
042:
043: /**
044: * Initializes the array lists and some basic info.
045: */
046: public InternalBillingDocument() {
047: super ();
048: setItems(new ArrayList());
049: this .nextItemLineNumber = new Integer(1);
050: }
051:
052: /**
053: * Adds a new item to the item list.
054: *
055: * @param item
056: */
057: public void addItem(InternalBillingItem item) {
058: item.setItemSequenceId(this .nextItemLineNumber);
059: this .items.add(item);
060: this .nextItemLineNumber = new Integer(this .nextItemLineNumber
061: .intValue() + 1);
062: }
063:
064: /**
065: * Retrieve a particular item at a given index in the list of items. For Struts, the requested item and any intervening ones are
066: * initialized if necessary.
067: *
068: * @param index
069: * @return the item
070: */
071: public InternalBillingItem getItem(int index) {
072: while (getItems().size() <= index) {
073: getItems().add(new InternalBillingItem());
074: }
075: return (InternalBillingItem) getItems().get(index);
076: }
077:
078: /**
079: * @return Returns the items.
080: */
081: public List getItems() {
082: return items;
083: }
084:
085: /**
086: * Allows items (in addition to accounting lines) to be deleted from the database after being saved there.
087: *
088: * @see org.kuali.core.document.TransactionalDocumentBase#buildListOfDeletionAwareLists()
089: */
090: @Override
091: public List buildListOfDeletionAwareLists() {
092: List managedLists = super .buildListOfDeletionAwareLists();
093: managedLists.add(getItems());
094: return managedLists;
095: }
096:
097: /**
098: * Iterates through the list of items and sums up their totals.
099: *
100: * @return the total
101: */
102: public KualiDecimal getItemTotal() {
103: KualiDecimal total = new KualiDecimal(0);
104: for (Iterator iterator = items.iterator(); iterator.hasNext();) {
105: total = total.add(((InternalBillingItem) iterator.next())
106: .getTotal());
107: }
108: return total;
109: }
110:
111: /**
112: * Retrieves the next item line number.
113: *
114: * @return The next available item line number
115: */
116: public Integer getNextItemLineNumber() {
117: return this .nextItemLineNumber;
118: }
119:
120: /**
121: * @param items
122: */
123: public void setItems(List items) {
124: this .items = items;
125: }
126:
127: /**
128: * Setter for OJB to get from database and JSP to maintain state in hidden fields. This property is also incremented by the
129: * <code>addItem</code> method.
130: *
131: * @param nextItemLineNumber
132: */
133: public void setNextItemLineNumber(Integer nextItemLineNumber) {
134: this .nextItemLineNumber = nextItemLineNumber;
135: }
136:
137: /**
138: * @return "Income"
139: */
140: @Override
141: public String getSourceAccountingLinesSectionTitle() {
142: return KFSConstants.INCOME;
143: }
144:
145: /**
146: * @return "Expense"
147: */
148: @Override
149: public String getTargetAccountingLinesSectionTitle() {
150: return KFSConstants.EXPENSE;
151: }
152:
153: /**
154: * @see org.kuali.kfs.document.AccountingDocumentBase#getAccountingLineParser()
155: */
156: @Override
157: public AccountingLineParser getAccountingLineParser() {
158: return new AccountingLineParserBase();
159: }
160: }
|