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.bo.AccountingLineParser;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.financial.bo.BasicFormatWithLineDescriptionAccountingLineParser;
030: import org.kuali.module.financial.bo.CreditCardDetail;
031:
032: /**
033: * This is the business object that represents the CreditCardReceipt document in Kuali. This is a transactional document that will
034: * eventually post transactions to the G/L. It integrates with workflow. Since a Credit Card Receipt is a one sided transactional
035: * document, only accepting funds into the university, the accounting line data will be held in the source accounting line data
036: * structure only.
037: */
038: public class CreditCardReceiptDocument extends CashReceiptFamilyBase
039: implements Copyable, AmountTotaling {
040: // holds details about each credit card receipt
041: private List<CreditCardDetail> creditCardReceipts = new ArrayList<CreditCardDetail>();
042:
043: // incrementers for detail lines
044: private Integer nextCcCrLineNumber = new Integer(1);
045:
046: // monetary attributes
047: private KualiDecimal totalCreditCardAmount = new KualiDecimal(0);
048:
049: /**
050: * Default constructor that calls super.
051: */
052: public CreditCardReceiptDocument() {
053: super ();
054: }
055:
056: @Override
057: public boolean documentPerformsSufficientFundsCheck() {
058: return false;
059: }
060:
061: /**
062: * Gets the total credit card amount.
063: *
064: * @return KualiDecimal
065: */
066: public KualiDecimal getTotalCreditCardAmount() {
067: return totalCreditCardAmount;
068: }
069:
070: /**
071: * This method returns the credit card total amount as a currency formatted string.
072: *
073: * @return String
074: */
075: public String getCurrencyFormattedTotalCreditCardAmount() {
076: return (String) new CurrencyFormatter()
077: .format(totalCreditCardAmount);
078: }
079:
080: /**
081: * Sets the total credit card amount which is the sum of all credit card receipts on this document.
082: *
083: * @param creditCardAmount
084: */
085: public void setTotalCreditCardAmount(KualiDecimal creditCardAmount) {
086: this .totalCreditCardAmount = creditCardAmount;
087: }
088:
089: /**
090: * Gets the list of credit card receipts which is a list of CreditCardDetail business objects.
091: *
092: * @return List
093: */
094: public List<CreditCardDetail> getCreditCardReceipts() {
095: return creditCardReceipts;
096: }
097:
098: /**
099: * Sets the credit card receipts list.
100: *
101: * @param creditCardReceipts
102: */
103: public void setCreditCardReceipts(
104: List<CreditCardDetail> creditCardReceipts) {
105: this .creditCardReceipts = creditCardReceipts;
106: }
107:
108: /**
109: * Adds a new credit card receipt to the list.
110: *
111: * @param creditCardReceiptDetail
112: */
113: public void addCreditCardReceipt(
114: CreditCardDetail creditCardReceiptDetail) {
115: // these three make up the primary key for a credit card detail record
116: prepareNewCreditCardReceipt(creditCardReceiptDetail);
117:
118: // add the new detail record to the list
119: this .creditCardReceipts.add(creditCardReceiptDetail);
120:
121: // increment line number
122: this .nextCcCrLineNumber = new Integer(this .nextCcCrLineNumber
123: .intValue() + 1);
124:
125: // update the overall amount
126: this .totalCreditCardAmount = this .totalCreditCardAmount
127: .add(creditCardReceiptDetail
128: .getCreditCardAdvanceDepositAmount());
129: }
130:
131: /**
132: * This is a helper method that automatically populates document specfic information into the credit card receipt
133: * (CreditCardDetail) instance.
134: *
135: * @param creditCardReceiptDetail
136: */
137: public final void prepareNewCreditCardReceipt(
138: CreditCardDetail creditCardReceiptDetail) {
139: creditCardReceiptDetail
140: .setFinancialDocumentLineNumber(this .nextCcCrLineNumber);
141: creditCardReceiptDetail
142: .setFinancialDocumentColumnTypeCode(KFSConstants.CreditCardReceiptConstants.CASH_RECEIPT_CREDIT_CARD_RECEIPT_COLUMN_TYPE_CODE);
143: creditCardReceiptDetail.setDocumentNumber(this
144: .getDocumentNumber());
145: creditCardReceiptDetail
146: .setFinancialDocumentTypeCode(SpringContext.getBean(
147: DocumentTypeService.class)
148: .getDocumentTypeCodeByClass(this .getClass()));
149: }
150:
151: /**
152: * Retrieve a particular credit card receipt at a given index in the list of credit card receipts.
153: *
154: * @param index
155: * @return CreditCardReceiptDetail
156: */
157: public CreditCardDetail getCreditCardReceipt(int index) {
158: while (this .creditCardReceipts.size() <= index) {
159: creditCardReceipts.add(new CreditCardDetail());
160: }
161: return creditCardReceipts.get(index);
162: }
163:
164: /**
165: * This method removes a credit card receipt from the list and updates the total appropriately.
166: *
167: * @param index
168: */
169: public void removeCreditCardReceipt(int index) {
170: CreditCardDetail creditCardReceiptDetail = creditCardReceipts
171: .remove(index);
172: this .totalCreditCardAmount = this .totalCreditCardAmount
173: .subtract(creditCardReceiptDetail
174: .getCreditCardAdvanceDepositAmount());
175: }
176:
177: /**
178: * @return Integer
179: */
180: public Integer getNextCcCrLineNumber() {
181: return nextCcCrLineNumber;
182: }
183:
184: /**
185: * @param nextCcCrLineNumber
186: */
187: public void setNextCcCrLineNumber(Integer nextCcCrLineNumber) {
188: this .nextCcCrLineNumber = nextCcCrLineNumber;
189: }
190:
191: /**
192: * This method returns the overall total of the document - the credit card total.
193: *
194: * @see org.kuali.kfs.document.AccountingDocumentBase#getTotalDollarAmount()
195: * @return KualiDecimal
196: */
197: @Override
198: public KualiDecimal getTotalDollarAmount() {
199: return this .totalCreditCardAmount;
200: }
201:
202: /**
203: * This method returns the sum of all of the credit card receipts for this document.
204: *
205: * @return KualiDecimal
206: */
207: public KualiDecimal calculateCreditCardReceiptTotal() {
208: KualiDecimal total = KualiDecimal.ZERO;
209: for (CreditCardDetail detail : getCreditCardReceipts()) {
210: if (null != detail.getCreditCardAdvanceDepositAmount()) {
211: total = total.add(detail
212: .getCreditCardAdvanceDepositAmount());
213: }
214: }
215: return total;
216: }
217:
218: /**
219: * Overrides super to call super and then also add in the new list of credit card receipts that have to be managed.
220: *
221: * @see org.kuali.core.document.TransactionalDocumentBase#buildListOfDeletionAwareLists()
222: */
223: @Override
224: public List buildListOfDeletionAwareLists() {
225: List managedLists = super .buildListOfDeletionAwareLists();
226: managedLists.add(getCreditCardReceipts());
227:
228: return managedLists;
229: }
230:
231: /**
232: * @see org.kuali.kfs.document.AccountingDocumentBase#getAccountingLineParser()
233: */
234: @Override
235: public AccountingLineParser getAccountingLineParser() {
236: return new BasicFormatWithLineDescriptionAccountingLineParser();
237: }
238: }
|