View Javadoc

1   /*
2    * Copyright 2005-2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document;
17  
18  import static org.kuali.ole.sys.OLEConstants.BALANCE_TYPE_ACTUAL;
19  
20  import org.kuali.ole.sys.OLEConstants;
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
23  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
24  import org.kuali.ole.sys.businessobject.SystemOptions;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.sys.document.AccountingDocumentBase;
27  import org.kuali.ole.sys.document.AmountTotaling;
28  import org.kuali.ole.sys.document.Correctable;
29  import org.kuali.ole.sys.document.service.AccountingDocumentRuleHelperService;
30  import org.kuali.ole.sys.document.service.DebitDeterminerService;
31  import org.kuali.ole.sys.service.OptionsService;
32  import org.kuali.rice.krad.document.Copyable;
33  
34  /**
35   * The Transfer of Funds (TF) document is used to transfer funds (cash) between accounts. There are two kinds of transfer
36   * transactions, mandatory and non-mandatory. Mandatory transfers are required to meet contractual agreements. Specific object codes
37   * are used to identify these transactions. Examples of these are: moving dedicated student fees to the retirement of indebtedness
38   * fund group for principal and interest payments on bonds. Non-mandatory transfers are allocations of unrestricted cash between
39   * fund groups which are not required either by the terms of a loan or by other external agreements. These transfers are the most
40   * commonly used throughout the university.
41   */
42  public class TransferOfFundsDocument extends AccountingDocumentBase implements Copyable, Correctable, AmountTotaling {
43      protected static final long serialVersionUID = -3871133713027969492L;
44  
45      /**
46       * Initializes the array lists and some basic info.
47       */
48      public TransferOfFundsDocument() {
49          super();
50      }
51  
52      /**
53       * Overrides the base implementation to return "From".
54       * 
55       * @see org.kuali.ole.sys.document.AccountingDocument#getSourceAccountingLinesSectionTitle()
56       */
57      public String getSourceAccountingLinesSectionTitle() {
58          return OLEConstants.FROM;
59      }
60  
61      /**
62       * Overrides the base implementation to return "To".
63       * 
64       * @see org.kuali.ole.sys.document.AccountingDocument#getTargetAccountingLinesSectionTitle()
65       */
66      public String getTargetAccountingLinesSectionTitle() {
67          return OLEConstants.TO;
68      }
69      
70      /**
71       * Set attributes of an offset pending entry according to rules specific to TransferOfFundsDocument.  The current rules
72       * require setting the balance type code to 'actual'.
73       * 
74       * @param financialDocument The accounting document containing the general ledger pending entries being customized.
75       * @param accountingLine The accounting line the explicit general ledger pending entry was generated from.
76       * @param explicitEntry The explicit general ledger pending entry the offset entry is generated for.
77       * @param offsetEntry The offset general ledger pending entry being customized.
78       * @return This method always returns true.
79       * 
80       * @see org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBase#customizeOffsetGeneralLedgerPendingEntry(org.kuali.rice.krad.document.FinancialDocument,
81       *      org.kuali.rice.krad.bo.AccountingLine, org.kuali.module.gl.bo.GeneralLedgerPendingEntry,
82       *      org.kuali.module.gl.bo.GeneralLedgerPendingEntry)
83       */
84      @Override
85      public boolean customizeOffsetGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail accountingLine, GeneralLedgerPendingEntry explicitEntry, GeneralLedgerPendingEntry offsetEntry) {
86          offsetEntry.setFinancialBalanceTypeCode(BALANCE_TYPE_ACTUAL);
87          return true;
88      }
89  
90      /**
91       * Set attributes of an explicit pending entry according to rules specific to TransferOfFundsDocument.
92       * 
93       * @param financialDocument The accounting document containing the general ledger pending entries being customized.
94       * @param accountingLine The accounting line the explicit general ledger pending entry was generated from.
95       * @param explicitEntry The explicit general ledger pending entry to be customized.
96       * 
97       * @see org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBase#customizeExplicitGeneralLedgerPendingEntry(org.kuali.rice.krad.document.FinancialDocument,
98       *      org.kuali.rice.krad.bo.AccountingLine, org.kuali.module.gl.bo.GeneralLedgerPendingEntry)
99       */
100     @Override
101     public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail generalLedgerPendingEntrySourceDetail, GeneralLedgerPendingEntry explicitEntry) {
102         AccountingLine accountingLine = (AccountingLine)generalLedgerPendingEntrySourceDetail;
103         SystemOptions options = SpringContext.getBean(OptionsService.class).getCurrentYearOptions();
104 
105         explicitEntry.setFinancialBalanceTypeCode(BALANCE_TYPE_ACTUAL);
106         DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
107         if (isDebitUtils.isExpense(accountingLine)) {
108             explicitEntry.setFinancialObjectTypeCode(options.getFinancialObjectTypeTransferExpenseCd());
109         }
110         else {
111             if (isDebitUtils.isIncome(accountingLine)) {
112                 explicitEntry.setFinancialObjectTypeCode(options.getFinancialObjectTypeTransferIncomeCd());
113             }
114             else {
115                 AccountingDocumentRuleHelperService accountingDocumentRuleUtil = SpringContext.getBean(AccountingDocumentRuleHelperService.class);
116                 explicitEntry.setFinancialObjectTypeCode(accountingDocumentRuleUtil.getObjectCodeTypeCodeWithoutSideEffects(accountingLine));
117             }
118         }
119     }
120 
121     /**
122      * Adds the following restrictions in addition to those provided by <code>IsDebitUtils.isDebitConsideringNothingPositiveOnly</code>
123      * <ol>
124      * <li> Only allow income or expense object type codes
125      * <li> Target lines have the opposite debit/credit codes as the source lines
126      * </ol>
127      * 
128      * @param financialDocument The document used to determine if the accounting line is a debit line.
129      * @param accountingLine The accounting line to be analyzed.
130      * @return True if the accounting line provided is a debit line, false otherwise.
131      * 
132      * @see IsDebitUtils#isDebitConsideringNothingPositiveOnly(FinancialDocumentRuleBase, FinancialDocument, AccountingLine)
133      * @see org.kuali.rice.krad.rule.AccountingLineRule#isDebit(org.kuali.rice.krad.document.FinancialDocument,
134      *      org.kuali.rice.krad.bo.AccountingLine)
135      */
136     public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) {
137         AccountingLine accountingLine = (AccountingLine)postable;
138         // only allow income or expense
139         DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
140         if (!isDebitUtils.isIncome(accountingLine) && !isDebitUtils.isExpense(accountingLine)) {
141             throw new IllegalStateException(isDebitUtils.getDebitCalculationIllegalStateExceptionMessage());
142         }
143         boolean isDebit = false;
144         if (accountingLine.isSourceAccountingLine()) {
145             isDebit = isDebitUtils.isDebitConsideringNothingPositiveOnly(this, accountingLine);
146         }
147         else if (accountingLine.isTargetAccountingLine()) {
148             isDebit = !isDebitUtils.isDebitConsideringNothingPositiveOnly(this, accountingLine);
149         }
150         else {
151             throw new IllegalStateException(isDebitUtils.getInvalidLineTypeIllegalArgumentExceptionMessage());
152         }
153 
154         return isDebit;
155     }
156 }