View Javadoc
1   /*
2    * Copyright 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.gl.businessobject.lookup;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.kuali.ole.gl.Constant;
23  import org.kuali.ole.gl.GeneralLedgerConstants;
24  import org.kuali.ole.gl.businessobject.AccountBalance;
25  import org.kuali.ole.gl.businessobject.TransientBalanceInquiryAttributes;
26  import org.kuali.ole.gl.businessobject.inquiry.AccountBalanceByLevelInquirableImpl;
27  import org.kuali.ole.gl.service.AccountBalanceService;
28  import org.kuali.ole.sys.OLEConstants;
29  import org.kuali.ole.sys.OLEPropertyConstants;
30  import org.kuali.rice.kns.lookup.HtmlData;
31  import org.kuali.rice.kns.lookup.KualiLookupableImpl;
32  import org.kuali.rice.krad.bo.PersistableBusinessObject;
33  import org.kuali.rice.krad.lookup.CollectionIncomplete;
34  
35  /**
36   * An extension of KualiLookupableImpl to support the account balance by level inquiry screen
37   */
38  public class AccountBalanceByLevelLookupableImpl extends KualiLookupableImpl {
39      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceByLevelLookupableImpl.class);
40  
41      private AccountBalanceService accountBalanceService;
42  
43      public void setAccountBalanceService(AccountBalanceService abs) {
44          accountBalanceService = abs;
45      }
46  
47      /**
48       * Returns the inquiry url for a field if one exist.
49       * 
50       * @param bo the business object instance to build the urls for
51       * @param propertyName the property which links to an inquirable
52       * @return String url to inquiry
53       */
54      public HtmlData getInquiryUrl(PersistableBusinessObject bo, String propertyName) {
55          return (new AccountBalanceByLevelInquirableImpl()).getInquiryUrl(bo, propertyName);
56      }
57  
58      /**
59       * Uses Lookup Service to provide a basic search.
60       * 
61       * @param fieldValues - Map containing prop name keys and search values
62       * @return List found business objects
63       */
64      public List getSearchResults(Map fieldValues) {
65          LOG.debug("getSearchResults() started");
66  
67          setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
68          setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
69  
70          BusinessObjectFieldConverter.escapeSingleQuote(fieldValues);
71  
72          String costShareOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.COST_SHARE_OPTION);
73          String pendingEntryOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.PENDING_ENTRY_OPTION);
74          String consolidationOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.CONSOLIDATION_OPTION);
75          boolean isCostShareExcluded = Constant.COST_SHARE_EXCLUDE.equals(costShareOption);
76          int pendingEntryCode = AccountBalanceService.PENDING_NONE;
77          if (GeneralLedgerConstants.PendingEntryOptions.APPROVED.equals(pendingEntryOption)) {
78              pendingEntryCode = AccountBalanceService.PENDING_APPROVED;
79          }
80          else if (GeneralLedgerConstants.PendingEntryOptions.ALL.equals(pendingEntryOption)) {
81              pendingEntryCode = AccountBalanceService.PENDING_ALL;
82          }
83          boolean isConsolidated = Constant.CONSOLIDATION.equals(consolidationOption);
84  
85          String chartOfAccountsCode = (String) fieldValues.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
86          String accountNumber = (String) fieldValues.get(OLEPropertyConstants.ACCOUNT_NUMBER);
87          String subAccountNumber = (String) fieldValues.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
88          String financialConsolidationObjectCode = (String) fieldValues.get(GeneralLedgerConstants.BalanceInquiryDrillDowns.CONSOLIDATION_OBJECT_CODE);
89  
90          // Dashes means no sub account number
91          if (OLEConstants.getDashSubAccountNumber().equals(subAccountNumber)) {
92              subAccountNumber = "";
93          }
94  
95          String ufy = (String) fieldValues.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR);
96  
97          // TODO Deal with invalid numbers
98          Integer universityFiscalYear = new Integer(Integer.parseInt(ufy));
99  
100         List results = accountBalanceService.findAccountBalanceByLevel(universityFiscalYear, chartOfAccountsCode, accountNumber, subAccountNumber, financialConsolidationObjectCode, isCostShareExcluded, isConsolidated, pendingEntryCode);
101 
102         // Put the search related stuff in the objects
103         for (Iterator iter = results.iterator(); iter.hasNext();) {
104             AccountBalance ab = (AccountBalance) iter.next();
105 
106             TransientBalanceInquiryAttributes dbo = ab.getDummyBusinessObject();
107             dbo.setConsolidationOption(consolidationOption);
108             dbo.setCostShareOption(costShareOption);
109             dbo.setPendingEntryOption(pendingEntryOption);
110             dbo.setLinkButtonOption(Constant.LOOKUP_BUTTON_VALUE);
111         }
112         return new CollectionIncomplete(results, new Long(results.size()));
113     }
114 }