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.module.ld.document.web.struts;
017
018 import java.util.List;
019 import java.util.Map;
020
021 import javax.servlet.http.HttpServletRequest;
022
023 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025 import org.kuali.kfs.module.ld.LaborConstants;
026 import org.kuali.kfs.module.ld.businessobject.ExpenseTransferAccountingLine;
027 import org.kuali.kfs.module.ld.businessobject.LedgerBalance;
028 import org.kuali.kfs.module.ld.document.SalaryExpenseTransferDocument;
029 import org.kuali.kfs.sys.KFSConstants;
030 import org.kuali.kfs.sys.KFSPropertyConstants;
031 import org.kuali.kfs.sys.context.SpringContext;
032 import org.kuali.rice.kim.bo.Person;
033 import org.kuali.rice.kim.service.KIMServiceLocator;
034 import org.kuali.rice.kim.service.PersonService;
035 import org.kuali.rice.kns.service.ParameterService;
036 import org.kuali.rice.kns.util.GlobalVariables;
037 import org.kuali.rice.kns.web.format.CurrencyFormatter;
038
039 /**
040 * Struts Action Form for the Salary Expense Transfer document. This method extends the parent ExpenseTransferDocumentFormBase class
041 * which contains all of the common form methods and form attributes needed by the Salary Expense Transfer document. It adds a new
042 * method which is a convenience method for getting at the Salary Expense Transfer document easier.
043 */
044 public class SalaryExpenseTransferForm extends ExpenseTransferDocumentFormBase {
045 protected static Log LOG = LogFactory.getLog(SalaryExpenseTransferForm.class);
046
047 protected String balanceTypeCode;
048
049 /**
050 * Constructs a SalaryExpenseTransferForm instance and sets up the appropriately casted document.
051 */
052 public SalaryExpenseTransferForm() {
053 super();
054
055 setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
056 setLookupResultsBOClassName(LedgerBalance.class.getName());
057 setFormatterType(KFSPropertyConstants.DOCUMENT + "." + KFSPropertyConstants.APPROVAL_OBJECT_CODE_BALANCES, CurrencyFormatter.class);
058 }
059
060 @Override
061 protected String getDefaultDocumentTypeName() {
062 return "ST";
063 }
064
065 /**
066 * Gets the balanceTypeCode attribute.
067 *
068 * @return Returns the balanceTypeCode.
069 */
070 public String getFinancialBalanceTypeCode() {
071 return balanceTypeCode;
072 }
073
074 /**
075 * Sets the balanceTypeCode attribute value.
076 *
077 * @param balanceTypeCode The balanceTypeCode to set.
078 */
079 public void setFinancialBalanceTypeCode(String balanceTypeCode) {
080 this.balanceTypeCode = balanceTypeCode;
081 }
082
083 /**
084 * @see org.kuali.rice.kns.web.struts.pojo.PojoForm#populate(javax.servlet.http.HttpServletRequest)
085 */
086 @Override
087 public void populate(HttpServletRequest request) {
088 super.populate(request);
089 }
090
091 /**
092 * This method returns a reference to the Salary Expense Transfer Document
093 *
094 * @return Returns the SalaryExpenseTransferDocument.
095 */
096 public SalaryExpenseTransferDocument getSalaryExpenseTransferDocument() {
097 return (SalaryExpenseTransferDocument) getDocument();
098 }
099
100 /**
101 * Removes fields from map if users is allowed to edit.
102 *
103 * @see org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentFormBase#getForcedReadOnlyTargetFields()
104 */
105 @Override
106 public Map getForcedReadOnlyTargetFields() {
107 Map map = this.getForcedReadOnlySourceFields();
108 map.remove(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
109 map.remove(KFSPropertyConstants.ACCOUNT_NUMBER);
110 map.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
111 map.remove(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
112 map.remove(KFSPropertyConstants.PROJECT_CODE);
113 map.remove(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID);
114 map.remove(KFSPropertyConstants.AMOUNT);
115
116 return map;
117 }
118
119 /**
120 * Populate serach fields (i.e. universal fiscal year and employee ID)
121 *
122 * @see org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentFormBase#populateSearchFields()
123 */
124 @Override
125 public void populateSearchFields() {
126 List<ExpenseTransferAccountingLine> sourceAccoutingLines = this.getSalaryExpenseTransferDocument().getSourceAccountingLines();
127 if (sourceAccoutingLines != null && !sourceAccoutingLines.isEmpty()) {
128 ExpenseTransferAccountingLine sourceAccountingLine = sourceAccoutingLines.get(0);
129 this.setUniversityFiscalYear(sourceAccountingLine.getPostingYear());
130 }
131 }
132 }
133