1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.coa.document;
17  
18  import java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.apache.log4j.Logger;
22  import org.kuali.ole.coa.businessobject.Account;
23  import org.kuali.ole.coa.businessobject.IndirectCostRecoveryRateDetail;
24  import org.kuali.ole.coa.service.AccountService;
25  import org.kuali.ole.gl.GeneralLedgerConstants;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.OLEPropertyConstants;
28  import org.kuali.ole.sys.context.SpringContext;
29  import org.kuali.ole.sys.document.FinancialSystemMaintainable;
30  import org.kuali.rice.krad.bo.PersistableBusinessObject;
31  import org.kuali.rice.krad.util.ObjectUtils;
32  
33  public class IndirectCostRecoveryRateMaintainableImpl extends FinancialSystemMaintainable {
34      private static final Logger LOG = Logger.getLogger(IndirectCostRecoveryRateMaintainableImpl.class);  
35  
36      private Integer indirectCostRecoveryRateNextEntryNumber;
37  
38      
39  
40  
41  
42      @Override
43      public void addNewLineToCollection(String collectionName) {
44  
45          
46          IndirectCostRecoveryRateDetail addLine = (IndirectCostRecoveryRateDetail) newCollectionLines.get(collectionName);
47          List<IndirectCostRecoveryRateDetail> maintCollection = (List<IndirectCostRecoveryRateDetail>) ObjectUtils.getPropertyValue(getBusinessObject(), collectionName);
48  
49          if(StringUtils.isBlank(addLine.getSubAccountNumber()) || StringUtils.containsOnly(addLine.getSubAccountNumber(), "-")) {
50              addLine.setSubAccountNumber(OLEConstants.getDashSubAccountNumber());
51          }
52          if(StringUtils.isBlank(addLine.getFinancialSubObjectCode()) || StringUtils.containsOnly(addLine.getFinancialSubObjectCode(), "-")) {
53              addLine.setFinancialSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
54          }
55  
56          Integer icrEntryNumberMax = 0;
57          for(IndirectCostRecoveryRateDetail item : maintCollection) {
58              if(icrEntryNumberMax < item.getAwardIndrCostRcvyEntryNbr()) {
59                  icrEntryNumberMax = item.getAwardIndrCostRcvyEntryNbr();
60              }
61          }
62  
63          
64          addLine.setNewCollectionRecord(true);
65          addLine.setAwardIndrCostRcvyEntryNbr(icrEntryNumberMax + 1);
66          maintCollection.add(addLine);
67          initNewCollectionLine(collectionName);
68      }
69  
70      
71  
72  
73  
74  
75  
76      @Override
77      protected void populateChartOfAccountsCodeFields() {
78          
79          super.populateChartOfAccountsCodeFields();
80          
81          PersistableBusinessObject bo = getBusinessObject();        
82          AccountService acctService = SpringContext.getBean(AccountService.class);    
83          PersistableBusinessObject newAccount = getNewCollectionLine(OLEPropertyConstants.INDIRECT_COST_RECOVERY_RATE_DETAILS);
84          String accountNumber = (String)ObjectUtils.getPropertyValue(newAccount, OLEPropertyConstants.ACCOUNT_NUMBER);
85          String coaCode = null;
86          
87          
88          if (GeneralLedgerConstants.PosterService.SYMBOL_USE_EXPENDITURE_ENTRY.equals(accountNumber) || 
89              GeneralLedgerConstants.PosterService.SYMBOL_USE_ICR_FROM_ACCOUNT.equals(accountNumber)) {
90              coaCode = accountNumber;
91          }
92          
93          else {
94              Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);            
95              if (ObjectUtils.isNotNull(account)) {
96                  coaCode = account.getChartOfAccountsCode();
97              }
98          }
99           
100         
101         try {
102             ObjectUtils.setObjectProperty(newAccount, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, coaCode); 
103         }
104         catch (Exception e) {
105             LOG.error("Error in setting property value for " + OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
106         } 
107     }    
108     
109 }