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.sql.Timestamp;
019: import java.util.Iterator;
020:
021: import org.kuali.core.service.KualiRuleService;
022: import org.kuali.core.util.KualiDecimal;
023: import org.kuali.kfs.KFSConstants;
024: import org.kuali.kfs.bo.AccountingLineBase;
025: import org.kuali.kfs.bo.AccountingLineParser;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.kfs.document.AccountingDocumentBase;
028: import org.kuali.kfs.rule.AccountingLineRule;
029: import org.kuali.module.financial.bo.BasicFormatWithLineDescriptionAccountingLineParser;
030: import org.kuali.module.financial.rules.CashReceiptFamilyRule;
031:
032: /**
033: * Abstract class which defines behavior common to CashReceipt-like documents.
034: */
035: abstract public class CashReceiptFamilyBase extends
036: AccountingDocumentBase {
037: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
038: .getLogger(CashReceiptFamilyBase.class);
039: private String campusLocationCode; // TODO Needs to be an actual object - also need to clarify this
040: private Timestamp depositDate;
041:
042: /**
043: * Constructs a CashReceiptFamilyBase
044: */
045: public CashReceiptFamilyBase() {
046: setCampusLocationCode(KFSConstants.CashReceiptConstants.DEFAULT_CASH_RECEIPT_CAMPUS_LOCATION_CODE);
047: }
048:
049: /**
050: * Documents in the CashReceiptFamily do not perform Sufficient Funds checking
051: *
052: * @see org.kuali.kfs.document.AccountingDocumentBase#documentPerformsSufficientFundsCheck()
053: */
054: @Override
055: public boolean documentPerformsSufficientFundsCheck() {
056: return false;
057: }
058:
059: /**
060: * Gets the campusLocationCode attribute.
061: *
062: * @return Returns the campusLocationCode.
063: */
064: public String getCampusLocationCode() {
065: return campusLocationCode;
066: }
067:
068: /**
069: * Sets the campusLocationCode attribute value.
070: *
071: * @param campusLocationCode The campusLocationCode to set.
072: */
073: public void setCampusLocationCode(String campusLocationCode) {
074: this .campusLocationCode = campusLocationCode;
075: }
076:
077: /**
078: * Gets the depositDate attribute.
079: *
080: * @return Returns the depositDate.
081: */
082: public Timestamp getDepositDate() {
083: return depositDate;
084: }
085:
086: /**
087: * Sets the depositDate attribute value.
088: *
089: * @param depositDate The depositDate to set.
090: */
091: public void setDepositDate(Timestamp depositDate) {
092: this .depositDate = depositDate;
093: }
094:
095: /**
096: * Total for a Cash Receipt according to the spec should be the sum of the amounts on accounting lines belonging to object codes
097: * having the 'income' object type, less the sum of the amounts on accounting lines belonging to object codes having the
098: * 'expense' object type.
099: *
100: * @see org.kuali.kfs.document.AccountingDocument#getSourceTotal()
101: */
102: @Override
103: public KualiDecimal getSourceTotal() {
104: CashReceiptFamilyRule crFamilyRule = (CashReceiptFamilyRule) SpringContext
105: .getBean(KualiRuleService.class)
106: .getBusinessRulesInstance(this ,
107: AccountingLineRule.class);
108: KualiDecimal total = KualiDecimal.ZERO;
109: AccountingLineBase al = null;
110: Iterator iter = sourceAccountingLines.iterator();
111: while (iter.hasNext()) {
112: al = (AccountingLineBase) iter.next();
113: try {
114: KualiDecimal amount = al.getAmount().abs();
115: if (amount != null && amount.isNonZero()) {
116: if (crFamilyRule.isDebit(this , al)) {
117: total = total.subtract(amount);
118: } else if (crFamilyRule.isCredit(al, this )) {
119: total = total.add(amount);
120: } else {
121: LOG
122: .error("could not determine credit/debit for accounting line");
123: return KualiDecimal.ZERO;
124: }
125: }
126: } catch (Exception e) {
127: // Possibly caused by accounting lines w/ bad data
128: LOG
129: .error(
130: "Error occured trying to compute Cash receipt total, returning 0",
131: e);
132: return KualiDecimal.ZERO;
133: }
134: }
135: return total;
136: }
137:
138: /**
139: * Cash Receipts only have source lines, so this should always return 0.
140: *
141: * @see org.kuali.kfs.document.AccountingDocument#getTargetTotal()
142: */
143: @Override
144: public KualiDecimal getTargetTotal() {
145: return KualiDecimal.ZERO;
146: }
147:
148: /**
149: * Overrides the base implementation to return an empty string.
150: *
151: * @see org.kuali.kfs.document.AccountingDocument#getSourceAccountingLinesSectionTitle()
152: */
153: @Override
154: public String getSourceAccountingLinesSectionTitle() {
155: return KFSConstants.EMPTY_STRING;
156: }
157:
158: /**
159: * Overrides the base implementation to return an empty string.
160: *
161: * @see org.kuali.kfs.document.AccountingDocument#getTargetAccountingLinesSectionTitle()
162: */
163: @Override
164: public String getTargetAccountingLinesSectionTitle() {
165: return KFSConstants.EMPTY_STRING;
166: }
167:
168: /**
169: * @see org.kuali.kfs.document.AccountingDocumentBase#getAccountingLineParser()
170: */
171: @Override
172: public AccountingLineParser getAccountingLineParser() {
173: return new BasicFormatWithLineDescriptionAccountingLineParser();
174: }
175: }
|