001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.financial.document;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.core.document.AmountTotaling;
022: import org.kuali.core.document.Copyable;
023: import org.kuali.core.service.DocumentTypeService;
024: import org.kuali.core.util.KualiDecimal;
025: import org.kuali.core.web.format.CurrencyFormatter;
026: import org.kuali.kfs.KFSConstants;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.financial.bo.AdvanceDepositDetail;
029:
030: /**
031: * This is the business object that represents the AdvanceDeposit document in Kuali. This is a transactional document that will
032: * eventually post transactions to the G/L. It integrates with workflow. Since an Advance Deposit document is a one sided
033: * transactional document, only accepting funds into the university, the accounting line data will be held in the source accounting
034: * line data structure only.
035: */
036: public class AdvanceDepositDocument extends CashReceiptFamilyBase
037: implements Copyable, AmountTotaling {
038: // holds details about each advance deposit
039: private List<AdvanceDepositDetail> advanceDeposits = new ArrayList<AdvanceDepositDetail>();
040:
041: // incrementers for detail lines
042: private Integer nextAdvanceDepositLineNumber = 1;
043:
044: // monetary attributes
045: private KualiDecimal totalAdvanceDepositAmount = KualiDecimal.ZERO;
046:
047: /**
048: * Default constructor that calls super.
049: */
050: public AdvanceDepositDocument() {
051: super ();
052: }
053:
054: /**
055: * Gets the total advance deposit amount.
056: *
057: * @return KualiDecimal
058: */
059: public KualiDecimal getTotalAdvanceDepositAmount() {
060: return totalAdvanceDepositAmount;
061: }
062:
063: /**
064: * This method returns the advance deposit total amount as a currency formatted string.
065: *
066: * @return String
067: */
068: public String getCurrencyFormattedTotalAdvanceDepositAmount() {
069: return (String) new CurrencyFormatter()
070: .format(totalAdvanceDepositAmount);
071: }
072:
073: /**
074: * Sets the total advance deposit amount which is the sum of all advance deposits on this document.
075: *
076: * @param advanceDepositAmount
077: */
078: public void setTotalAdvanceDepositAmount(
079: KualiDecimal advanceDepositAmount) {
080: this .totalAdvanceDepositAmount = advanceDepositAmount;
081: }
082:
083: /**
084: * Gets the list of advance deposits which is a list of AdvanceDepositDetail business objects.
085: *
086: * @return List
087: */
088: public List<AdvanceDepositDetail> getAdvanceDeposits() {
089: return advanceDeposits;
090: }
091:
092: /**
093: * Sets the advance deposits list.
094: *
095: * @param advanceDeposits
096: */
097: public void setAdvanceDeposits(
098: List<AdvanceDepositDetail> advanceDeposits) {
099: this .advanceDeposits = advanceDeposits;
100: }
101:
102: /**
103: * Adds a new advance deposit to the list.
104: *
105: * @param advanceDepositDetail
106: */
107: public void addAdvanceDeposit(
108: AdvanceDepositDetail advanceDepositDetail) {
109: // these three make up the primary key for an advance deposit detail record
110: prepareNewAdvanceDeposit(advanceDepositDetail);
111:
112: // add the new detail record to the list
113: this .advanceDeposits.add(advanceDepositDetail);
114:
115: // increment line number
116: this .nextAdvanceDepositLineNumber++;
117:
118: // update the overall amount
119: this .totalAdvanceDepositAmount = this .totalAdvanceDepositAmount
120: .add(advanceDepositDetail
121: .getFinancialDocumentAdvanceDepositAmount());
122: }
123:
124: /**
125: * This is a helper method that automatically populates document specfic information into the advance deposit
126: * (AdvanceDepositDetail) instance.
127: *
128: * @param advanceDepositDetail
129: */
130: public final void prepareNewAdvanceDeposit(
131: AdvanceDepositDetail advanceDepositDetail) {
132: advanceDepositDetail
133: .setFinancialDocumentLineNumber(this .nextAdvanceDepositLineNumber);
134: advanceDepositDetail
135: .setFinancialDocumentColumnTypeCode(KFSConstants.AdvanceDepositConstants.CASH_RECEIPT_ADVANCE_DEPOSIT_COLUMN_TYPE_CODE);
136: advanceDepositDetail
137: .setDocumentNumber(this .getDocumentNumber());
138: advanceDepositDetail.setFinancialDocumentTypeCode(SpringContext
139: .getBean(DocumentTypeService.class)
140: .getDocumentTypeCodeByClass(this .getClass()));
141: }
142:
143: /**
144: * Retrieve a particular advance deposit at a given index in the list of advance deposits.
145: *
146: * @param index
147: * @return AdvanceDepositDetail
148: */
149: public AdvanceDepositDetail getAdvanceDepositDetail(int index) {
150: while (this .advanceDeposits.size() <= index) {
151: advanceDeposits.add(new AdvanceDepositDetail());
152: }
153: return advanceDeposits.get(index);
154: }
155:
156: /**
157: * This method removes an advance deposit from the list and updates the total appropriately.
158: *
159: * @param index
160: */
161: public void removeAdvanceDeposit(int index) {
162: AdvanceDepositDetail advanceDepositDetail = advanceDeposits
163: .remove(index);
164: this .totalAdvanceDepositAmount = this .totalAdvanceDepositAmount
165: .subtract(advanceDepositDetail
166: .getFinancialDocumentAdvanceDepositAmount());
167: }
168:
169: /**
170: * @return Integer
171: */
172: public Integer getNextAdvanceDepositLineNumber() {
173: return nextAdvanceDepositLineNumber;
174: }
175:
176: /**
177: * @param nextAdvanceDepositLineNumber
178: */
179: public void setNextAdvanceDepositLineNumber(
180: Integer nextAdvanceDepositLineNumber) {
181: this .nextAdvanceDepositLineNumber = nextAdvanceDepositLineNumber;
182: }
183:
184: /**
185: * This method returns the overall total of the document - the advance deposit total.
186: *
187: * @see org.kuali.kfs.document.AccountingDocumentBase#getTotalDollarAmount()
188: * @return KualiDecimal
189: */
190: @Override
191: public KualiDecimal getTotalDollarAmount() {
192: return this .totalAdvanceDepositAmount;
193: }
194:
195: /**
196: * Overrides super to call super and then also add in the new list of advance deposits that have to be managed.
197: *
198: * @see org.kuali.core.document.TransactionalDocumentBase#buildListOfDeletionAwareLists()
199: */
200: @Override
201: public List buildListOfDeletionAwareLists() {
202: List managedLists = super.buildListOfDeletionAwareLists();
203: managedLists.add(getAdvanceDeposits());
204:
205: return managedLists;
206: }
207: }
|