001/**
002 * Copyright 2004-2014 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 */
016package org.kuali.kpme.tklm.leave.timeoff;
017
018import java.math.BigDecimal;
019import java.util.Date;
020
021import org.apache.commons.lang.StringUtils;
022import org.joda.time.LocalDate;
023import org.kuali.kpme.core.accrualcategory.AccrualCategoryBo;
024import org.kuali.kpme.core.bo.HrBusinessObject;
025import org.kuali.kpme.core.earncode.EarnCodeBo;
026import org.kuali.kpme.core.leaveplan.LeavePlanBo;
027import org.kuali.kpme.core.location.LocationBo;
028import org.kuali.kpme.core.service.HrServiceLocator;
029import org.kuali.kpme.core.util.HrConstants;
030import org.kuali.kpme.tklm.api.leave.timeoff.SystemScheduledTimeOffContract;
031import org.kuali.kpme.tklm.api.common.TkConstants;
032
033import com.google.common.collect.ImmutableList;
034import com.google.common.collect.ImmutableMap;
035
036public class SystemScheduledTimeOff extends HrBusinessObject implements SystemScheduledTimeOffContract {
037
038        private static final String ACCRUED_DATE = "accruedDate";
039        private static final String ACCRUAL_CATEGORY = "accrualCategory";
040        private static final String LOCATION = "location";
041        private static final String LEAVE_PLAN = "leavePlan";
042        private static final String EARN_CODE = "earnCode";
043
044        private static final long serialVersionUID = 6660625335629574993L;
045
046        public static final String CACHE_NAME = TkConstants.Namespace.NAMESPACE_PREFIX + "SystemScheduledTimeOff";
047        //KPME-2273/1965 Primary Business Keys List.
048        public static final ImmutableList<String> fields = new ImmutableList.Builder<String>()
049             .add(EARN_CODE)             
050             .add(LEAVE_PLAN)
051             .add(LOCATION)
052             .add(ACCRUAL_CATEGORY)
053             .add(ACCRUED_DATE)
054             .build();
055        
056        
057        private String lmSystemScheduledTimeOffId;
058        private String leavePlan;
059        private String accrualCategory;
060        private String earnCode;
061        private Date accruedDate;
062        private Date scheduledTimeOffDate;
063        private String location;
064        private String descr;
065        private BigDecimal amountofTime;
066        private String unusedTime;
067        private BigDecimal transferConversionFactor;
068        private String transfertoEarnCode;
069        private String premiumEarnCode;
070        private String premiumHoliday;
071
072        private LeavePlanBo leavePlanObj;
073        private AccrualCategoryBo accrualCategoryObj;
074        private EarnCodeBo earnCodeObj;
075        private EarnCodeBo transferToEarnCodeObj;
076        private EarnCodeBo premiumEarnCodeObj;
077        private LocationBo locationObj;
078        
079        
080        @Override
081        public ImmutableMap<String, Object> getBusinessKeyValuesMap() {
082        return  new ImmutableMap.Builder<String, Object>()
083                        .put(EARN_CODE, this.getEarnCode())
084                        .put(LEAVE_PLAN, this.getLeavePlan())
085                        .put(LOCATION, this.getLocation())
086                        .put(ACCRUAL_CATEGORY, this.getAccrualCategory())
087                        .put(ACCRUED_DATE, this.getAccruedDate())
088                        .build();
089        }
090        
091        public String getLmSystemScheduledTimeOffId() {
092                return lmSystemScheduledTimeOffId;
093        }
094
095        public void setLmSystemScheduledTimeOffId(String lmSystemScheduledTimeOffId) {
096                this.lmSystemScheduledTimeOffId = lmSystemScheduledTimeOffId;
097        }
098
099        public String getLeavePlan() {
100                if(StringUtils.isNotEmpty(leavePlan)) {
101                        return leavePlan;
102                }
103                if (this.earnCodeObj == null && 
104                                (!StringUtils.isEmpty(this.earnCode) && getEffectiveDate() != null)) {          
105                        earnCodeObj =  EarnCodeBo.from(HrServiceLocator.getEarnCodeService().getEarnCode(earnCode, getEffectiveLocalDate()));
106                }
107                leavePlan = (earnCodeObj != null) ? earnCodeObj.getLeavePlan() : "";
108                return leavePlan;
109        }
110
111        public void setLeavePlan(String leavePlan) {
112                this.leavePlan = leavePlan;
113        }
114
115        public String getAccrualCategory() {
116        if(StringUtils.isNotEmpty(accrualCategory)) {
117            return accrualCategory;
118        }
119                if (this.earnCodeObj == null &&
120                                (!StringUtils.isEmpty(this.earnCode) && getEffectiveDate() != null)) {
121                        earnCodeObj =  EarnCodeBo.from(HrServiceLocator.getEarnCodeService().getEarnCode(earnCode, getEffectiveLocalDate()));
122                }
123                accrualCategory = (earnCodeObj != null) ? earnCodeObj.getAccrualCategory() : "";
124                return accrualCategory;
125        }
126
127        public void setAccrualCategory(String accrualCategory) {
128                this.accrualCategory = accrualCategory;
129        }
130
131        public Date getAccruedDate() {
132                return accruedDate;
133        }
134
135        public void setAccruedDate(Date accruedDate) {
136                this.accruedDate = accruedDate;
137        }
138        
139        public LocalDate getAccruedLocalDate() {
140                return accruedDate != null ? LocalDate.fromDateFields(accruedDate) : null;
141        }
142        
143        public void setAccruedLocalDate(LocalDate accruedLocalDate) {
144                this.accruedDate = accruedLocalDate != null? accruedLocalDate.toDate() : null;
145        }
146
147        public Date getScheduledTimeOffDate() {
148                return scheduledTimeOffDate;
149        }
150
151        public void setScheduledTimeOffDate(Date scheduledTimeOffDate) {
152                this.scheduledTimeOffDate = scheduledTimeOffDate;
153        }
154        
155        public LocalDate getScheduledTimeOffLocalDate() {
156                return scheduledTimeOffDate != null ? LocalDate.fromDateFields(scheduledTimeOffDate) : null;
157        }
158        
159        public void setScheduledTimeOffLocalDate(LocalDate scheduledTimeOffLocalDate) {
160                this.scheduledTimeOffDate = scheduledTimeOffLocalDate != null? scheduledTimeOffLocalDate.toDate() : null;
161        }
162
163        public String getLocation() {
164                return location;
165        }
166
167        public void setLocation(String location) {
168                this.location = location;
169        }
170
171        public String getDescr() {
172                return descr;
173        }
174
175        public void setDescr(String descr) {
176                this.descr = descr;
177        }
178
179        public BigDecimal getAmountofTime() {
180                return amountofTime; // != null ? amountofTime.setScale(scale) : null;
181        }
182
183        public void setAmountofTime(BigDecimal amountofTime) {
184                this.amountofTime = amountofTime;
185        }
186
187        public String getUnusedTime() {
188                return unusedTime;
189        }
190
191        public void setUnusedTime(String unusedTime) {
192                this.unusedTime = unusedTime;
193        }
194
195        public BigDecimal getTransferConversionFactor() {
196                return transferConversionFactor != null ? transferConversionFactor.setScale(HrConstants.BIG_DECIMAL_SCALE) : null;
197        }
198
199        public void setTransferConversionFactor(BigDecimal transferConversionFactor) {
200                this.transferConversionFactor = transferConversionFactor;
201        }
202
203        public String getPremiumHoliday() {
204                return premiumHoliday;
205        }
206
207        public void setPremiumHoliday(String premiumHoliday) {
208                this.premiumHoliday = premiumHoliday;
209        }
210
211        public LeavePlanBo getLeavePlanObj() {
212                return leavePlanObj;
213        }
214
215        public void setLeavePlanObj(LeavePlanBo leavePlanObj) {
216                this.leavePlanObj = leavePlanObj;
217        }
218
219        public AccrualCategoryBo getAccrualCategoryObj() {
220                return accrualCategoryObj;
221        }
222
223        public void setAccrualCategoryObj(AccrualCategoryBo accrualCategoryObj) {
224                this.accrualCategoryObj = accrualCategoryObj;
225        }
226
227        public String getEarnCode() {
228                return earnCode;
229        }
230
231        public void setEarnCode(String earnCode) {
232                this.earnCode = earnCode;
233        }
234
235        public String getTransfertoEarnCode() {
236                return transfertoEarnCode;
237        }
238
239        public void setTransfertoEarnCode(String transfertoEarnCode) {
240                this.transfertoEarnCode = transfertoEarnCode;
241        }
242
243        public EarnCodeBo getEarnCodeObj() {
244                return earnCodeObj;
245        }
246
247        public void setEarnCodeObj(EarnCodeBo earnCodeObj) {
248                this.earnCodeObj = earnCodeObj;
249        }
250
251        public LocationBo getLocationObj() {
252                return locationObj;
253        }
254
255        public void setLocationObj(LocationBo locationObj) {
256                this.locationObj = locationObj;
257        }
258
259        @Override
260        protected String getUniqueKey() {
261                String lmSystemScheduledTimeOffKey = getEarnCode() +"_"+ getLeavePlan() +"_"+ getAccrualCategory();
262                return lmSystemScheduledTimeOffKey;
263        }
264
265        @Override
266        public String getId() {
267                return getLmSystemScheduledTimeOffId();
268        }
269
270        @Override
271        public void setId(String id) {
272                setLmSystemScheduledTimeOffId(id);
273        }
274
275        public EarnCodeBo getTransferToEarnCodeObj() {
276                return transferToEarnCodeObj;
277        }
278
279        public void setTransferToEarnCodeObj(EarnCodeBo transferToEarnCodeObj) {
280                this.transferToEarnCodeObj = transferToEarnCodeObj;
281        }
282
283    @Override
284        public String getPremiumEarnCode() {
285                return premiumEarnCode;
286        }
287
288        public void setPremiumEarnCode(String premiumEarnCode) {
289                this.premiumEarnCode = premiumEarnCode;
290        }
291
292        public EarnCodeBo getPremiumEarnCodeObj() {
293                return premiumEarnCodeObj;
294        }
295
296        public void setPremiumEarnCodeObj(EarnCodeBo premiumEarnCodeObj) {
297                this.premiumEarnCodeObj = premiumEarnCodeObj;
298        }
299        
300}