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.AbstractLookupableHelperServiceImpl;
31  import org.kuali.rice.kns.lookup.HtmlData;
32  import org.kuali.rice.krad.bo.BusinessObject;
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 AccountBalanceByLevelLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
39      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceByLevelLookupableHelperServiceImpl.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      @Override
55      public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
56          return (new AccountBalanceByLevelInquirableImpl()).getInquiryUrl(bo, propertyName);
57      }
58  
59      /**
60       * Uses Lookup Service to provide a basic search.
61       * 
62       * @param fieldValues - Map containing prop name keys and search values
63       * @return List found business objects
64       */
65      public List getSearchResults(Map fieldValues) {
66          LOG.debug("getSearchResults() started");
67  
68          setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
69          setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
70  
71          BusinessObjectFieldConverter.escapeSingleQuote(fieldValues);
72  
73          String costShareOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.COST_SHARE_OPTION);
74          String pendingEntryOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.PENDING_ENTRY_OPTION);
75          String consolidationOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.CONSOLIDATION_OPTION);
76          boolean isCostShareExcluded = Constant.COST_SHARE_EXCLUDE.equals(costShareOption);
77          int pendingEntryCode = AccountBalanceService.PENDING_NONE;
78          if (GeneralLedgerConstants.PendingEntryOptions.APPROVED.equals(pendingEntryOption)) {
79              pendingEntryCode = AccountBalanceService.PENDING_APPROVED;
80          }
81          else if (GeneralLedgerConstants.PendingEntryOptions.ALL.equals(pendingEntryOption)) {
82              pendingEntryCode = AccountBalanceService.PENDING_ALL;
83          }
84          boolean isConsolidated = Constant.CONSOLIDATION.equals(consolidationOption);
85  
86          String chartOfAccountsCode = (String) fieldValues.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
87          String accountNumber = (String) fieldValues.get(OLEPropertyConstants.ACCOUNT_NUMBER);
88          String subAccountNumber = (String) fieldValues.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
89          String financialConsolidationObjectCode = (String) fieldValues.get(GeneralLedgerConstants.BalanceInquiryDrillDowns.CONSOLIDATION_OBJECT_CODE);
90  
91          // Dashes means no sub account number
92          if (OLEConstants.getDashSubAccountNumber().equals(subAccountNumber)) {
93              subAccountNumber = "";
94          }
95  
96          String ufy = (String) fieldValues.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR);
97  
98          // TODO Deal with invalid numbers
99          Integer universityFiscalYear = new Integer(Integer.parseInt(ufy));
100 
101         List results = accountBalanceService.findAccountBalanceByLevel(universityFiscalYear, chartOfAccountsCode, accountNumber, subAccountNumber, financialConsolidationObjectCode, isCostShareExcluded, isConsolidated, pendingEntryCode);
102 
103         // Put the search related stuff in the objects
104         for (Iterator iter = results.iterator(); iter.hasNext();) {
105             AccountBalance ab = (AccountBalance) iter.next();
106 
107             TransientBalanceInquiryAttributes dbo = ab.getDummyBusinessObject();
108             dbo.setConsolidationOption(consolidationOption);
109             dbo.setCostShareOption(costShareOption);
110             dbo.setPendingEntryOption(pendingEntryOption);
111             dbo.setLinkButtonOption(Constant.LOOKUP_BUTTON_VALUE);
112         }
113         return new CollectionIncomplete(results, new Long(results.size()));
114     }
115 }