001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.sys.document.service;
017
018 import org.kuali.kfs.sys.businessobject.AccountingLine;
019 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
020 import org.kuali.kfs.sys.document.AccountingDocument;
021 import org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource;
022
023 /**
024 * A collection of methods that help accounting docs determine whether an accounting line represents a debit or not
025 */
026 public interface DebitDeterminerService {
027 /**
028 * @param debitCreditCode
029 * @return true if debitCreditCode equals the the debit constant
030 */
031 public abstract boolean isDebitCode(String debitCreditCode);
032
033 /**
034 * <ol>
035 * <li>object type is included in determining if a line is debit or credit.
036 * </ol>
037 * the following are credits (return false)
038 * <ol>
039 * <li> (isIncome || isLiability) && (lineAmount > 0)
040 * <li> (isExpense || isAsset) && (lineAmount < 0)
041 * </ol>
042 * the following are debits (return true)
043 * <ol>
044 * <li> (isIncome || isLiability) && (lineAmount < 0)
045 * <li> (isExpense || isAsset) && (lineAmount > 0)
046 * </ol>
047 * the following are invalid ( throws an <code>IllegalStateException</code>)
048 * <ol>
049 * <li> document isErrorCorrection
050 * <li> lineAmount == 0
051 * <li> ! (isIncome || isLiability || isExpense || isAsset)
052 * </ol>
053 *
054 * @param rule
055 * @param accountingDocument
056 * @param accountingLine
057 * @return boolean
058 */
059 public abstract boolean isDebitConsideringType(GeneralLedgerPendingEntrySource poster, GeneralLedgerPendingEntrySourceDetail postable);
060
061 /**
062 * <ol>
063 * <li>object type is not included in determining if a line is debit or credit.
064 * <li>accounting line section (source/target) is not included in determining if a line is debit or credit.
065 * </ol>
066 * the following are credits (return false)
067 * <ol>
068 * <li> none
069 * </ol>
070 * the following are debits (return true)
071 * <ol>
072 * <li> (isIncome || isLiability || isExpense || isAsset) && (lineAmount > 0)
073 * </ol>
074 * the following are invalid ( throws an <code>IllegalStateException</code>)
075 * <ol>
076 * <li> lineAmount <= 0
077 * <li> ! (isIncome || isLiability || isExpense || isAsset)
078 * </ol>
079 *
080 * @param rule
081 * @param accountingDocument
082 * @param accountingLine
083 * @return boolean
084 */
085 public abstract boolean isDebitConsideringNothingPositiveOnly(GeneralLedgerPendingEntrySource poster, GeneralLedgerPendingEntrySourceDetail postable);
086
087 /**
088 * <ol>
089 * <li>accounting line section (source/target) type is included in determining if a line is debit or credit.
090 * <li> zero line amounts are never allowed
091 * </ol>
092 * the following are credits (return false)
093 * <ol>
094 * <li> isSourceLine && (isIncome || isExpense || isAsset || isLiability) && (lineAmount > 0)
095 * <li> isTargetLine && (isIncome || isExpense || isAsset || isLiability) && (lineAmount < 0)
096 * </ol>
097 * the following are debits (return true)
098 * <ol>
099 * <li> isSourceLine && (isIncome || isExpense || isAsset || isLiability) && (lineAmount < 0)
100 * <li> isTargetLine && (isIncome || isExpense || isAsset || isLiability) && (lineAmount > 0)
101 * </ol>
102 * the following are invalid ( throws an <code>IllegalStateException</code>)
103 * <ol>
104 * <li> lineAmount == 0
105 * <li> ! (isIncome || isLiability || isExpense || isAsset)
106 * </ol>
107 *
108 * @param rule
109 * @param accountingDocument
110 * @param accountingLine
111 * @return boolean
112 */
113 public abstract boolean isDebitConsideringSection(AccountingDocument accountingDocument, AccountingLine accountingLine);
114
115 /**
116 * <ol>
117 * <li>accounting line section (source/target) and object type is included in determining if a line is debit or credit.
118 * <li> negative line amounts are <b>Only</b> allowed during error correction
119 * </ol>
120 * the following are credits (return false)
121 * <ol>
122 * <li> isSourceLine && (isExpense || isAsset) && (lineAmount > 0)
123 * <li> isTargetLine && (isIncome || isLiability) && (lineAmount > 0)
124 * <li> isErrorCorrection && isSourceLine && (isIncome || isLiability) && (lineAmount < 0)
125 * <li> isErrorCorrection && isTargetLine && (isExpense || isAsset) && (lineAmount < 0)
126 * </ol>
127 * the following are debits (return true)
128 * <ol>
129 * <li> isSourceLine && (isIncome || isLiability) && (lineAmount > 0)
130 * <li> isTargetLine && (isExpense || isAsset) && (lineAmount > 0)
131 * <li> isErrorCorrection && (isExpense || isAsset) && (lineAmount < 0)
132 * <li> isErrorCorrection && (isIncome || isLiability) && (lineAmount < 0)
133 * </ol>
134 * the following are invalid ( throws an <code>IllegalStateException</code>)
135 * <ol>
136 * <li> !isErrorCorrection && !(lineAmount > 0)
137 * </ol>
138 *
139 * @param rule
140 * @param accountingDocument
141 * @param accountingLine
142 * @return boolean
143 */
144 public abstract boolean isDebitConsideringSectionAndTypePositiveOnly(AccountingDocument accountingDocument, AccountingLine accountingLine);
145
146 /**
147 * throws an <code>IllegalStateException</code> if the document is an error correction. otherwise does nothing
148 *
149 * @param rule
150 * @param accountingDocument
151 */
152 public abstract void disallowErrorCorrectionDocumentCheck(GeneralLedgerPendingEntrySource poster);
153
154 /**
155 * Convience method for determine if a document is an error correction document.
156 *
157 * @param accountingDocument
158 * @return true if document is an error correct
159 */
160 public abstract boolean isErrorCorrection(GeneralLedgerPendingEntrySource poster);
161
162 /**
163 * Determines whether an accounting line is an asset line.
164 *
165 * @param accountingLine
166 * @return boolean True if a line is an asset line.
167 */
168 public abstract boolean isAsset(GeneralLedgerPendingEntrySourceDetail postable);
169
170 /**
171 * Determines whether an accounting line is a liability line.
172 *
173 * @param accountingLine
174 * @return boolean True if the line is a liability line.
175 */
176 public abstract boolean isLiability(GeneralLedgerPendingEntrySourceDetail postable);
177
178 /**
179 * Determines whether an accounting line is an income line or not. This goes agains the configurable object type code list in
180 * the ApplicationParameter mechanism. This list can be configured externally.
181 *
182 * @param accountingLine
183 * @return boolean True if the line is an income line.
184 */
185 public abstract boolean isIncome(GeneralLedgerPendingEntrySourceDetail postable);
186
187 /**
188 * Check object code type to determine whether the accounting line is expense.
189 *
190 * @param accountingLine
191 * @return boolean True if the line is an expense line.
192 */
193 public abstract boolean isExpense(GeneralLedgerPendingEntrySourceDetail postable);
194
195 /**
196 * Determines whether an accounting line is an expense or asset.
197 *
198 * @param line
199 * @return boolean True if it's an expense or asset.
200 */
201 public abstract boolean isExpenseOrAsset(GeneralLedgerPendingEntrySourceDetail postable);
202
203 /**
204 * Determines whether an accounting line is an income or liability line.
205 *
206 * @param line
207 * @return boolean True if the line is an income or liability line.
208 */
209 public abstract boolean isIncomeOrLiability(GeneralLedgerPendingEntrySourceDetail postable);
210
211 /**
212 * Check object code type to determine whether the accounting line is revenue.
213 *
214 * @param line
215 * @return boolean True if the line is a revenue line.
216 */
217 public abstract boolean isRevenue(GeneralLedgerPendingEntrySourceDetail postable);
218
219 /**
220 * Determines whether the <code>objectTypeCode</code> is an asset.
221 *
222 * @param objectTypeCode
223 * @return Is she asset or something completely different?
224 */
225 public abstract boolean isAssetTypeCode(String objectTypeCode);
226
227 /**
228 * Determines whether the <code>objectTypeCode</code> is a liability.
229 *
230 * @param objectTypeCode
231 * @return Is she liability or something completely different?
232 */
233 public abstract boolean isLiabilityTypeCode(String objectTypeCode);
234
235 /**
236 * Gets the isDebitCalculationIllegalStateExceptionMessage attribute.
237 * @return Returns the isDebitCalculationIllegalStateExceptionMessage.
238 */
239 public abstract String getDebitCalculationIllegalStateExceptionMessage();
240
241 /**
242 * Gets the isErrorCorrectionIllegalStateExceptionMessage attribute.
243 * @return Returns the isErrorCorrectionIllegalStateExceptionMessage.
244 */
245 public abstract String getErrorCorrectionIllegalStateExceptionMessage();
246
247 /**
248 * Gets the isInvalidLineTypeIllegalArgumentExceptionMessage attribute.
249 * @return Returns the isInvalidLineTypeIllegalArgumentExceptionMessage.
250 */
251 public abstract String getInvalidLineTypeIllegalArgumentExceptionMessage();
252 }