1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.graceperiod.service;
17
18 import org.kuali.hr.time.graceperiod.dao.GracePeriodDao;
19 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule;
20
21 import java.math.BigDecimal;
22 import java.sql.Date;
23 import java.sql.Timestamp;
24 import java.util.List;
25
26 public class GracePeriodServiceImpl implements GracePeriodService {
27 private GracePeriodDao gracePeriodDao;
28
29 public GracePeriodDao getGracePeriodDao() {
30 return gracePeriodDao;
31 }
32
33 public void setGracePeriodDao(GracePeriodDao gracePeriodDao) {
34 this.gracePeriodDao = gracePeriodDao;
35 }
36
37 @Override
38 public GracePeriodRule getGracePeriodRule(Date asOfDate){
39 return gracePeriodDao.getGracePeriodRule(asOfDate);
40 }
41
42
43 @SuppressWarnings("deprecation")
44 public Timestamp processGracePeriodRule(Timestamp actualTime, Date asOfDate){
45 GracePeriodRule gracePeriodRule = getGracePeriodRule(asOfDate);
46 if(gracePeriodRule!=null){
47
48 actualTime.setSeconds(0);
49
50 BigDecimal minuteIncrement = gracePeriodRule.getHourFactor();
51 BigDecimal minutes = new BigDecimal(actualTime.getMinutes());
52 int bottomIntervalFactor = minutes.divide(minuteIncrement, 0, BigDecimal.ROUND_FLOOR).intValue();
53 BigDecimal bottomInterval = new BigDecimal(bottomIntervalFactor).multiply(minuteIncrement);
54 BigDecimal topInterval = new BigDecimal(bottomIntervalFactor + 1).multiply(minuteIncrement);
55 if(bottomInterval.subtract(minutes).abs().intValue() < topInterval.subtract(minutes).abs().intValue()){
56 actualTime.setMinutes(bottomInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
57 } else {
58 if(topInterval.equals(new BigDecimal(60))){
59 actualTime.setHours(actualTime.getHours()+1);
60 actualTime.setMinutes(0);
61 } else {
62 actualTime.setMinutes(topInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
63 }
64 }
65 }
66 return actualTime;
67 }
68
69 @Override
70 public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) {
71 return gracePeriodDao.getGracePeriodRule(tkGracePeriodId);
72 }
73
74 @Override
75 public List<GracePeriodRule> getGracePeriodRules(String hourFactor, String active) {
76 return gracePeriodDao.getGracePeriodRules(hourFactor, active);
77 }
78 }