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