001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.gl.businessobject.lookup;
017
018 import java.util.Iterator;
019 import java.util.List;
020 import java.util.Map;
021
022 import org.kuali.kfs.gl.Constant;
023 import org.kuali.kfs.gl.GeneralLedgerConstants;
024 import org.kuali.kfs.gl.businessobject.AccountBalance;
025 import org.kuali.kfs.gl.businessobject.TransientBalanceInquiryAttributes;
026 import org.kuali.kfs.gl.businessobject.inquiry.AccountBalanceByLevelInquirableImpl;
027 import org.kuali.kfs.gl.service.AccountBalanceService;
028 import org.kuali.kfs.sys.KFSConstants;
029 import org.kuali.kfs.sys.KFSPropertyConstants;
030 import org.kuali.rice.kns.bo.BusinessObject;
031 import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
032 import org.kuali.rice.kns.lookup.CollectionIncomplete;
033 import org.kuali.rice.kns.lookup.HtmlData;
034
035 /**
036 * An extension of KualiLookupableImpl to support the account balance by level inquiry screen
037 */
038 public class AccountBalanceByLevelLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
039 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceByLevelLookupableHelperServiceImpl.class);
040
041 private AccountBalanceService accountBalanceService;
042
043 public void setAccountBalanceService(AccountBalanceService abs) {
044 accountBalanceService = abs;
045 }
046
047 /**
048 * Returns the inquiry url for a field if one exist.
049 *
050 * @param bo the business object instance to build the urls for
051 * @param propertyName the property which links to an inquirable
052 * @return String url to inquiry
053 */
054 @Override
055 public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
056 return (new AccountBalanceByLevelInquirableImpl()).getInquiryUrl(bo, propertyName);
057 }
058
059 /**
060 * Uses Lookup Service to provide a basic search.
061 *
062 * @param fieldValues - Map containing prop name keys and search values
063 * @return List found business objects
064 */
065 public List getSearchResults(Map fieldValues) {
066 LOG.debug("getSearchResults() started");
067
068 setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION));
069 setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY));
070
071 BusinessObjectFieldConverter.escapeSingleQuote(fieldValues);
072
073 String costShareOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.COST_SHARE_OPTION);
074 String pendingEntryOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.PENDING_ENTRY_OPTION);
075 String consolidationOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.CONSOLIDATION_OPTION);
076 boolean isCostShareExcluded = Constant.COST_SHARE_EXCLUDE.equals(costShareOption);
077 int pendingEntryCode = AccountBalanceService.PENDING_NONE;
078 if (GeneralLedgerConstants.PendingEntryOptions.APPROVED.equals(pendingEntryOption)) {
079 pendingEntryCode = AccountBalanceService.PENDING_APPROVED;
080 }
081 else if (GeneralLedgerConstants.PendingEntryOptions.ALL.equals(pendingEntryOption)) {
082 pendingEntryCode = AccountBalanceService.PENDING_ALL;
083 }
084 boolean isConsolidated = Constant.CONSOLIDATION.equals(consolidationOption);
085
086 String chartOfAccountsCode = (String) fieldValues.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
087 String accountNumber = (String) fieldValues.get(KFSPropertyConstants.ACCOUNT_NUMBER);
088 String subAccountNumber = (String) fieldValues.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
089 String financialConsolidationObjectCode = (String) fieldValues.get(GeneralLedgerConstants.BalanceInquiryDrillDowns.CONSOLIDATION_OBJECT_CODE);
090
091 // Dashes means no sub account number
092 if (KFSConstants.getDashSubAccountNumber().equals(subAccountNumber)) {
093 subAccountNumber = "";
094 }
095
096 String ufy = (String) fieldValues.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
097
098 // TODO Deal with invalid numbers
099 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 }