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
25 public class GracePeriodServiceImpl implements GracePeriodService {
26 private GracePeriodDao gracePeriodDao;
27
28 public GracePeriodDao getGracePeriodDao() {
29 return gracePeriodDao;
30 }
31
32 public void setGracePeriodDao(GracePeriodDao gracePeriodDao) {
33 this.gracePeriodDao = gracePeriodDao;
34 }
35
36 @Override
37 public GracePeriodRule getGracePeriodRule(Date asOfDate){
38 return gracePeriodDao.getGracePeriodRule(asOfDate);
39 }
40
41
42 @SuppressWarnings("deprecation")
43 public Timestamp processGracePeriodRule(Timestamp actualTime, Date asOfDate){
44 GracePeriodRule gracePeriodRule = getGracePeriodRule(asOfDate);
45 if(gracePeriodRule!=null){
46
47 actualTime.setSeconds(0);
48
49 BigDecimal minuteIncrement = gracePeriodRule.getHourFactor();
50 BigDecimal minutes = new BigDecimal(actualTime.getMinutes());
51 int bottomIntervalFactor = minutes.divide(minuteIncrement, 0, BigDecimal.ROUND_FLOOR).intValue();
52 BigDecimal bottomInterval = new BigDecimal(bottomIntervalFactor).multiply(minuteIncrement);
53 BigDecimal topInterval = new BigDecimal(bottomIntervalFactor + 1).multiply(minuteIncrement);
54 if(bottomInterval.subtract(minutes).abs().intValue() < topInterval.subtract(minutes).abs().intValue()){
55 actualTime.setMinutes(bottomInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
56 } else {
57 if(topInterval.equals(new BigDecimal(60))){
58 actualTime.setHours(actualTime.getHours()+1);
59 actualTime.setMinutes(0);
60 } else {
61 actualTime.setMinutes(topInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
62 }
63 }
64 }
65 return actualTime;
66 }
67
68 @Override
69 public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) {
70 return gracePeriodDao.getGracePeriodRule(tkGracePeriodId);
71 }
72 }