View Javadoc
1   /*
2    * Copyright 2005 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 java.math.BigDecimal;
19  
20  import org.kuali.ole.coa.businessobject.IndirectCostRecoveryAccount;
21  import org.kuali.ole.fp.document.validation.impl.IndirectCostAdjustmentDocumentRuleConstants;
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.businessobject.AccountingLine;
24  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
25  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
26  import org.kuali.ole.sys.businessobject.TargetAccountingLine;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.ole.sys.document.AccountingDocumentBase;
29  import org.kuali.ole.sys.document.AmountTotaling;
30  import org.kuali.ole.sys.document.Correctable;
31  import org.kuali.ole.sys.document.service.DebitDeterminerService;
32  import org.kuali.rice.core.api.util.type.KualiDecimal;
33  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
34  import org.kuali.rice.krad.document.Copyable;
35  
36  public class IndirectCostAdjustmentDocument extends AccountingDocumentBase implements Copyable, Correctable, AmountTotaling {
37  
38      /**
39       * Constructs a IndirectCostAdjustmentDocument.java.
40       */
41      public IndirectCostAdjustmentDocument() {
42          super();
43      }
44  
45      /**
46       * @see org.kuali.ole.sys.document.AccountingDocument#getSourceAccountingLinesSectionTitle()
47       */
48      @Override
49      public String getSourceAccountingLinesSectionTitle() {
50          return OLEConstants.GRANT;
51      }
52  
53      /**
54       * @see org.kuali.ole.sys.document.AccountingDocument#getTargetAccountingLinesSectionTitle()
55       */
56      @Override
57      public String getTargetAccountingLinesSectionTitle() {
58          return OLEConstants.ICR;
59      }
60  
61      /**
62       * per ICA specs, adds a target(receipt) line when an source(grant) line is added using the following logic to populate the
63       * target line.
64       * <ol>
65       * <li>receipt line's chart = chart from grant line
66       * <li>receipt line's account = ICR account for the account entered on the grant line
67       * <li>receipt line's object code = Financial System Parameter APC for the document global receipt line object code (see APC
68       * setion below)
69       * <li>receipt line's amount = amount from grant line
70       * </ol>
71       * 
72       * @see org.kuali.ole.sys.document.AccountingDocumentBase#addSourceAccountingLine(SourceAccountingLine)
73       */
74      @Override
75      public void addSourceAccountingLine(SourceAccountingLine line) {
76          // add source
77          super.addSourceAccountingLine(line);
78          
79          for (IndirectCostRecoveryAccount icrAccount : line.getAccount().getActiveIndirectCostRecoveryAccounts()){
80              
81              KualiDecimal percentDecimal = new KualiDecimal(icrAccount.getAccountLinePercent().divide(new BigDecimal(100)));
82              
83              // create and populate target line
84              TargetAccountingLine targetAccountingLine = null;
85              try {
86                  targetAccountingLine = (TargetAccountingLine) getTargetAccountingLineClass().newInstance();
87              }
88              catch (Exception e) {
89                  throw new IllegalArgumentException("unable to create a target accounting line", e);
90              }
91              // get apc object code value
92              String objectCode = SpringContext.getBean(ParameterService.class).getParameterValueAsString(IndirectCostAdjustmentDocument.class, IndirectCostAdjustmentDocumentRuleConstants.RECEIPT_OBJECT_CODE);
93              targetAccountingLine.setFinancialObjectCode(objectCode);
94              targetAccountingLine.setAccountNumber(icrAccount.getIndirectCostRecoveryAccountNumber());
95              targetAccountingLine.setChartOfAccountsCode(icrAccount.getIndirectCostRecoveryFinCoaCode());
96              targetAccountingLine.setDocumentNumber(line.getDocumentNumber());
97              targetAccountingLine.setPostingYear(line.getPostingYear());
98              targetAccountingLine.setAmount(line.getAmount().multiply(percentDecimal));
99              // refresh reference objects
100     
101             targetAccountingLine.refresh();
102             // add target line
103             addTargetAccountingLine(targetAccountingLine);
104         }
105     }
106     
107     /**
108      * Same logic as <code>IsDebitUtils#isDebitConsideringType(FinancialDocumentRuleBase, FinancialDocument, AccountingLine)</code>
109      * but has the following accounting line restrictions: 
110      * 
111      * for grant lines(source):
112      * <ol>
113      * <li>only allow expense object type codes
114      * </ol>
115      * for receipt lines(target):
116      * <ol>
117      * <li>only allow income object type codes
118      * </ol>
119      * 
120      * @param transactionDocument The document associated with the accounting line being reviewed to determine if it's a debit.
121      * @param accountingLine The accounting line being reviewed to determine if it's a debit line.
122      * @return True if the accounting line is a debit.  See IsDebitUtils.isDebitConsideringType().
123      * @throws IllegalStateException Thrown if the accounting line given is a source accounting line representing an expense
124      * or is a target accounting line representing an income.
125      * 
126      * @see IsDebitUtils#isDebitConsideringType(FinancialDocumentRuleBase, FinancialDocument, AccountingLine)
127      * @see org.kuali.rice.krad.rule.AccountingLineRule#isDebit(org.kuali.rice.krad.document.FinancialDocument,
128      *      org.kuali.rice.krad.bo.AccountingLine)
129      */
130     public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) throws IllegalStateException {
131         AccountingLine accountingLine = (AccountingLine)postable;
132         DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
133         if (!(accountingLine.isSourceAccountingLine() && isDebitUtils.isExpense(accountingLine)) && !(accountingLine.isTargetAccountingLine() && isDebitUtils.isIncome(accountingLine))) {
134             throw new IllegalStateException(isDebitUtils.getDebitCalculationIllegalStateExceptionMessage());
135         }
136 
137         return isDebitUtils.isDebitConsideringType(this, accountingLine);
138     }
139 }