001 /**
002 * Copyright 2004-2013 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.hr.time.earncode;
017
018 import java.math.BigDecimal;
019 import java.sql.Date;
020 import java.sql.Timestamp;
021 import java.util.*;
022
023 import org.kuali.hr.core.KPMEConstants;
024 import org.kuali.hr.time.accrual.AccrualCategory;
025 import org.kuali.hr.earncodesec.EarnCodeSecurity;
026 import org.kuali.hr.time.HrBusinessObject;
027 import org.kuali.hr.time.service.base.TkServiceLocator;
028 import org.kuali.rice.krad.service.KRADServiceLocator;
029
030 public class EarnCode extends HrBusinessObject {
031 public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "EarnCode";
032 private static final String[] PRIVATE_CACHES_FOR_FLUSH = {EarnCodeSecurity.CACHE_NAME, EarnCode.CACHE_NAME};
033 public static final List<String> CACHE_FLUSH = Collections.unmodifiableList(Arrays.asList(PRIVATE_CACHES_FOR_FLUSH));
034 /**
035 *
036 */
037 private static final long serialVersionUID = 1L;
038
039 private String hrEarnCodeId;
040 private String earnCode;
041 private String description;
042
043 private Boolean ovtEarnCode;
044 private String accrualCategory;
045 private BigDecimal inflateMinHours;
046 private BigDecimal inflateFactor;
047 private Long defaultAmountofTime;
048 private boolean history;
049
050 private AccrualCategory accrualCategoryObj;
051
052 private String recordMethod;
053
054 public String getRecordMethod() {
055 return recordMethod;
056 }
057
058 public void setRecordMethod(String recordMethod) {
059 this.recordMethod = recordMethod;
060 }
061
062 public Long getDefaultAmountofTime() {
063 return defaultAmountofTime;
064 }
065
066 public void setDefaultAmountofTime(Long defaultAmountofTime) {
067 this.defaultAmountofTime = defaultAmountofTime;
068 }
069
070 public String getEarnCode() {
071 return earnCode;
072 }
073
074 public void setEarnCode(String earnCode) {
075 this.earnCode = earnCode;
076 }
077
078 public String getDescription() {
079 return description;
080 }
081
082 public void setDescription(String description) {
083 this.description = description;
084 }
085
086 public Date getEffectiveDate() {
087 return effectiveDate;
088 }
089
090 public void setEffectiveDate(Date effectiveDate) {
091 this.effectiveDate = effectiveDate;
092 }
093
094 public boolean isHistory() {
095 return history;
096 }
097
098 public void setHistory(boolean history) {
099 this.history = history;
100 }
101
102 public boolean isActive() {
103 return active;
104 }
105
106 public void setActive(boolean active) {
107 this.active = active;
108 }
109
110 public String getHrEarnCodeId() {
111 return hrEarnCodeId;
112 }
113
114 public void setHrEarnCodeId(String hrEarnCodeId) {
115 this.hrEarnCodeId = hrEarnCodeId;
116 }
117
118 public Timestamp getTimestamp() {
119 return timestamp;
120 }
121
122 public void setTimestamp(Timestamp timestamp) {
123 this.timestamp = timestamp;
124 }
125
126 public String getAccrualCategory() {
127 return accrualCategory;
128 }
129
130 public void setAccrualCategory(String accrualCategory) {
131 this.accrualCategory = accrualCategory;
132 }
133
134 public AccrualCategory getAccrualCategoryObj() {
135 if(accrualCategoryObj == null && !this.getAccrualCategory().isEmpty()) {
136 this.assingAccrualCategoryObj();
137 }
138 return accrualCategoryObj;
139 }
140 public void assingAccrualCategoryObj() {
141 Map<String,Object> parameters = new HashMap<String,Object>();
142 parameters.put("accrualCategory", getAccrualCategory());
143 Collection c = KRADServiceLocator.getBusinessObjectService().findMatching(AccrualCategory.class, parameters);
144 if(!c.isEmpty()) {
145 this.setAccrualCategoryObj((AccrualCategory)c.toArray()[0]);
146 }
147 }
148
149 public void setAccrualCategoryObj(AccrualCategory accrualCategoryObj) {
150 this.accrualCategoryObj = accrualCategoryObj;
151 }
152
153 public BigDecimal getInflateMinHours() {
154 return inflateMinHours;
155 }
156
157 public void setInflateMinHours(BigDecimal inflateMinHours) {
158 this.inflateMinHours = inflateMinHours;
159 }
160
161 public BigDecimal getInflateFactor() {
162 return inflateFactor;
163 }
164
165 public void setInflateFactor(BigDecimal inflateFactor) {
166 this.inflateFactor = inflateFactor;
167 }
168
169 public Boolean getOvtEarnCode() {
170 return ovtEarnCode;
171 }
172
173 public void setOvtEarnCode(Boolean ovtEarnCode) {
174 this.ovtEarnCode = ovtEarnCode;
175 }
176
177 /**
178 * This is used by the timeblock json object.
179 * The purpose of this function is to create a string based on the record_* fields which can be used to render hour / begin(end) time input box
180 * @return String fieldType
181 */
182 public String getEarnCodeType() {
183 // if(getRecordHours()) {
184 // return TkConstants.EARN_CODE_HOUR;
185 // }
186 // else if(getRecordTime()) {
187 // return TkConstants.EARN_CODE_TIME;
188 // }
189 // else if(getRecordAmount()) {
190 // return TkConstants.EARN_CODE_AMOUNT;
191 // }
192 // else {
193 // return "";
194 // }
195 return this.recordMethod;
196 }
197
198 @Override
199 public String getUniqueKey() {
200 return earnCode;
201 }
202
203 @Override
204 public String getId() {
205 return getHrEarnCodeId();
206 }
207
208 @Override
209 public void setId(String id) {
210 setHrEarnCodeId(id);
211 }
212
213 public String getEarnCodeKeyForDisplay() {
214 // String unitTime = null;
215 // AccrualCategory acObj = null;
216 // if(this.accrualCategory != null) {
217 // acObj = TkServiceLocator.getAccrualCategoryService().getAccrualCategory(accrualCategory, this.effectiveDate);
218 // }
219 // unitTime = (acObj!= null ? acObj.getUnitOfTime() : this.recordMethod) ;
220 // return hrEarnCodeId + ":" + unitTime;
221 return hrEarnCodeId;
222 }
223
224 public String getEarnCodeValueForDisplay() {
225 return earnCode + " : " + description;
226 }
227 }