1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  
40  
41      public IndirectCostAdjustmentDocument() {
42          super();
43      }
44  
45      
46  
47  
48      @Override
49      public String getSourceAccountingLinesSectionTitle() {
50          return OLEConstants.GRANT;
51      }
52  
53      
54  
55  
56      @Override
57      public String getTargetAccountingLinesSectionTitle() {
58          return OLEConstants.ICR;
59      }
60  
61      
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74      @Override
75      public void addSourceAccountingLine(SourceAccountingLine line) {
76          
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              
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              
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              
100     
101             targetAccountingLine.refresh();
102             
103             addTargetAccountingLine(targetAccountingLine);
104         }
105     }
106     
107     
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
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 }