001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.gl.web.lookupable;
017:
018: import java.util.Iterator;
019: import java.util.List;
020: import java.util.Map;
021:
022: import org.kuali.core.bo.BusinessObject;
023: import org.kuali.core.lookup.AbstractLookupableHelperServiceImpl;
024: import org.kuali.core.lookup.CollectionIncomplete;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.kfs.KFSPropertyConstants;
027: import org.kuali.module.gl.GLConstants;
028: import org.kuali.module.gl.bo.AccountBalance;
029: import org.kuali.module.gl.bo.TransientBalanceInquiryAttributes;
030: import org.kuali.module.gl.service.AccountBalanceService;
031: import org.kuali.module.gl.util.BusinessObjectFieldConverter;
032: import org.kuali.module.gl.web.Constant;
033: import org.kuali.module.gl.web.inquirable.AccountBalanceByConsolidationInquirableImpl;
034:
035: /**
036: * An extension of KualiLookupableImpl to support the account balance by consolidation inquiry screen
037: */
038: public class AccountBalanceByConsolidationLookupableHelperServiceImpl
039: extends AbstractLookupableHelperServiceImpl {
040:
041: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
042: .getLogger(AccountBalanceByConsolidationLookupableHelperServiceImpl.class);
043:
044: private AccountBalanceService accountBalanceService;
045:
046: public void setAccountBalanceService(AccountBalanceService abs) {
047: accountBalanceService = abs;
048: }
049:
050: /**
051: * Returns the inquiry url for a result field.
052: *
053: * @param bo the business object instance to build the urls for
054: * @param propertyName the property which links to an inquirable
055: * @return String url to inquiry
056: */
057: @Override
058: public String getInquiryUrl(BusinessObject bo, String propertyName) {
059: return (new AccountBalanceByConsolidationInquirableImpl())
060: .getInquiryUrl(bo, propertyName);
061: }
062:
063: /**
064: * Get the search results that meet the input search criteria.
065: *
066: * @param fieldValues - Map containing prop name keys and search values
067: * @return a List of found business objects
068: */
069: @Override
070: public List getSearchResults(Map fieldValues) {
071: LOG.debug("getSearchResults() started");
072:
073: setBackLocation((String) fieldValues
074: .get(KFSConstants.BACK_LOCATION));
075: setDocFormKey((String) fieldValues
076: .get(KFSConstants.DOC_FORM_KEY));
077:
078: BusinessObjectFieldConverter.escapeSingleQuote(fieldValues);
079:
080: String costShareOption = (String) fieldValues
081: .get(GLConstants.DummyBusinessObject.COST_SHARE_OPTION);
082: String pendingEntryOption = (String) fieldValues
083: .get(GLConstants.DummyBusinessObject.PENDING_ENTRY_OPTION);
084: String consolidationOption = (String) fieldValues
085: .get(GLConstants.DummyBusinessObject.CONSOLIDATION_OPTION);
086: boolean isCostShareExcluded = Constant.COST_SHARE_EXCLUDE
087: .equals(costShareOption);
088:
089: int pendingEntryCode = AccountBalanceService.PENDING_NONE;
090: if (GLConstants.PendingEntryOptions.APPROVED
091: .equals(pendingEntryOption)) {
092: pendingEntryCode = AccountBalanceService.PENDING_APPROVED;
093: } else if (GLConstants.PendingEntryOptions.ALL
094: .equals(pendingEntryOption)) {
095: pendingEntryCode = AccountBalanceService.PENDING_ALL;
096: }
097:
098: boolean isConsolidated = Constant.CONSOLIDATION
099: .equals(consolidationOption);
100:
101: String chartOfAccountsCode = (String) fieldValues
102: .get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
103: String accountNumber = (String) fieldValues
104: .get(KFSPropertyConstants.ACCOUNT_NUMBER);
105: String subAccountNumber = (String) fieldValues
106: .get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
107: String ufy = (String) fieldValues
108: .get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
109:
110: // Dashes means no sub account number
111: if (KFSConstants.getDashSubAccountNumber().equals(
112: subAccountNumber)) {
113: subAccountNumber = "";
114: }
115:
116: // TODO Deal with invalid numbers
117: Integer universityFiscalYear = new Integer(Integer
118: .parseInt(ufy));
119:
120: List results = accountBalanceService
121: .findAccountBalanceByConsolidation(
122: universityFiscalYear, chartOfAccountsCode,
123: accountNumber, subAccountNumber,
124: isCostShareExcluded, isConsolidated,
125: pendingEntryCode);
126:
127: // Put the search related stuff in the objects
128: int count = 0;
129: for (Iterator iter = results.iterator(); iter.hasNext();) {
130: AccountBalance ab = (AccountBalance) iter.next();
131: count++;
132: TransientBalanceInquiryAttributes dbo = ab
133: .getDummyBusinessObject();
134: dbo.setConsolidationOption(consolidationOption);
135: dbo.setCostShareOption(costShareOption);
136: dbo.setPendingEntryOption(pendingEntryOption);
137: dbo.setLinkButtonOption(Constant.LOOKUP_BUTTON_VALUE);
138:
139: // Set the variance on the detail lines
140: if (count > 7) {
141: dbo.setGenericAmount(ab.getVariance());
142: }
143: }
144: return new CollectionIncomplete(results, new Long(results
145: .size()));
146: }
147: }
|