View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.lm.balancetransfer.web;
17  
18  import java.math.BigDecimal;
19  import java.sql.Date;
20  
21  import javax.servlet.http.HttpServletRequest;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.hr.lm.LMConstants;
25  import org.kuali.hr.lm.accrual.AccrualCategory;
26  import org.kuali.hr.lm.balancetransfer.BalanceTransfer;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.rice.kns.util.ActionFormUtilMap;
29  import org.kuali.rice.kns.util.WebUtils;
30  import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
31  import org.kuali.rice.krad.util.ObjectUtils;
32  
33  public class BalanceTransferForm extends KualiTransactionalDocumentFormBase {
34  
35  	/**
36  	 * 
37  	 */
38  	private static final long serialVersionUID = 1L;
39  	private BalanceTransfer balanceTransfer;
40  	private String balanceTransferId;
41  	private String accrualCategoryRule;
42  	private String principalId;
43  	private String toAccrualCategory;
44  	private String fromAccrualCategory;
45  	private BigDecimal transferAmount;
46  	private BigDecimal forfeitedAmount;
47  	private Date effectiveDate;
48  	private String leaveCalendarDocumentId;
49  	private String type;
50  	private boolean onLeaveApproval;
51  	private boolean timesheet;
52  	
53  	public Date getEffectiveDate() {
54  		return effectiveDate;
55  	}
56  
57  	public void setEffectiveDate(Date effectiveDate) {
58  		this.effectiveDate = effectiveDate;
59  	}
60  	
61  	public String getPrincipalId() {
62  		return principalId;
63  	}
64  
65  	public void setPrincipalId(String principalId) {
66  		this.principalId = principalId;
67  	}
68  
69  	public String getToAccrualCategory() {
70  		return toAccrualCategory;
71  	}
72  
73  	public void setToAccrualCategory(String toAccrualCategory) {
74  		this.toAccrualCategory = toAccrualCategory;
75  	}
76  
77  	public String getFromAccrualCategory() {
78  		return fromAccrualCategory;
79  	}
80  
81  	public void setFromAccrualCategory(String fromAccrualCategory) {
82  		this.fromAccrualCategory = fromAccrualCategory;
83  	}
84  
85  	public BigDecimal getTransferAmount() {
86  		return transferAmount;
87  	}
88  
89  	public void setTransferAmount(BigDecimal transferAmount) {
90  		this.transferAmount = transferAmount;
91  	}
92  
93  	public BigDecimal getForfeitedAmount() {
94  		return forfeitedAmount;
95  	}
96  
97  	public void setForfeitedAmount(BigDecimal forfeitedAmount) {
98  		this.forfeitedAmount = forfeitedAmount;
99  	}
100 	
101 	public String getBalanceTransferId() {
102 		return balanceTransferId;
103 	}
104 
105 	public void setBalanceTransferId(String balanceTransferId) {
106 		this.balanceTransferId = balanceTransferId;
107 	}
108 	
109 	public String getAccrualCategoryRule() {
110 		return accrualCategoryRule;
111 	}
112 
113 	public void setAccrualCategoryRule(String accrualCategoryRule) {
114 		this.accrualCategoryRule = accrualCategoryRule;
115 	}
116 
117 	public AccrualCategory getCreditedAccrualCategory() {
118 		return TkServiceLocator.getAccrualCategoryService().getAccrualCategory(toAccrualCategory, effectiveDate);
119 	}
120 
121 	public AccrualCategory getDebitedAccrualCategory() {
122 		return TkServiceLocator.getAccrualCategoryService().getAccrualCategory(fromAccrualCategory, effectiveDate);
123 	}
124 	
125     @Override
126     public String getBackLocation() {
127         return "LeaveCalendarSubmit.do?methodToCall=approveLeaveCalendar";
128     }
129 
130     @Override
131     public void populate(HttpServletRequest request) {
132         super.populate(request);
133         ((ActionFormUtilMap) getActionFormUtilMap()).setCacheValueFinderResults(false);
134 
135         if (this.getMethodToCall() == null || StringUtils.isEmpty(this.getMethodToCall())) {
136             setMethodToCall(WebUtils.parseMethodToCall(this, request));
137         }
138     }	
139 	
140 	@Override
141 	public void addRequiredNonEditableProperties() {
142 		super.addRequiredNonEditableProperties();
143 	}
144 
145 	public BalanceTransfer getBalanceTransfer() {
146 		return balanceTransfer;
147 	}
148 
149 	public void setBalanceTransfer(BalanceTransfer balanceTransfer) {
150 		this.balanceTransfer = balanceTransfer;
151 	}
152 
153 	public String getLeaveCalendarDocumentId() {
154 		return leaveCalendarDocumentId;
155 	}
156 
157 	public void setLeaveCalendarDocumentId(String leaveCalendarDocId) {
158 		this.leaveCalendarDocumentId = leaveCalendarDocId;
159 	}
160 
161 	public String getType() {
162 		return type;
163 	}
164 
165 	public void setType(String type) {
166 		this.type = type;
167 	}
168 
169 	public boolean isOnLeaveApproval() {
170 		if(StringUtils.equals(type, LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE))
171 			return true;
172 		else
173 			return false;
174 		//Will return false if MAX_BAL_ACTION_FREQ is YEAR_END, but for purposes of the leave calendar, YEAR_END is not
175 		//transferable.
176 	}
177 
178 	public void setOnLeaveApproval(boolean onLeaveApproval) {
179 		this.onLeaveApproval = onLeaveApproval;
180 	}
181 
182 	public void isTimesheet(boolean b) {
183 		timesheet = true;
184 	}
185 
186 	public boolean isSstoTransfer() {
187 		if(this.getBalanceTransfer() != null) {
188 			if(StringUtils.isNotEmpty(this.getBalanceTransfer().getSstoId()))
189 				return true;
190 			else
191 				return false;
192 		}
193 		else
194 			return false;
195 	}
196 
197 }