1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.accrual.bucket;
17
18 import java.math.BigDecimal;
19
20 import org.joda.time.LocalDate;
21 import org.kuali.kpme.core.accrualcategory.AccrualCategory;
22 import org.kuali.kpme.core.accrualcategory.rule.AccrualCategoryRule;
23 import org.kuali.kpme.core.principal.PrincipalHRAttributes;
24 import org.kuali.kpme.core.service.HrServiceLocator;
25 import org.kuali.kpme.tklm.api.leave.accrual.bucket.KPMEBalanceException;
26 import org.kuali.kpme.tklm.api.leave.accrual.bucket.LeaveBalanceContract;
27 import org.kuali.kpme.tklm.leave.block.LeaveBlock;
28 import org.kuali.kpme.tklm.leave.override.EmployeeOverride;
29 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
30
31 public abstract class LeaveBalance implements LeaveBalanceContract {
32
33 protected AccrualCategory accrualCategory;
34 protected PrincipalHRAttributes principalCalendar;
35 protected LocalDate asOfDate;
36 protected LocalDate calendarPeriodBeginDate;
37 protected LocalDate calendarPeriodEndDate;
38 protected BigDecimal balance;
39
40 protected LeaveBalance(AccrualCategory accrualCategory, PrincipalHRAttributes principalCalendar) {
41 this.accrualCategory = accrualCategory;
42 this.principalCalendar = principalCalendar;
43 asOfDate = LocalDate.now();
44 balance = new BigDecimal(0);
45 }
46
47 protected void add(BigDecimal amount) {
48 balance = balance.add(amount);
49 }
50
51 protected void remove(BigDecimal amount) {
52 balance = balance.subtract(amount);
53 }
54
55
56
57
58
59
60
61 public abstract void add(LeaveBlock leaveBlock) throws KPMEBalanceException;
62
63
64
65
66
67
68
69 public abstract void remove(LeaveBlock leaveBlock) throws KPMEBalanceException;
70
71
72
73
74
75
76
77 public abstract void adjust(LeaveBlock leaveBlock) throws KPMEBalanceException;
78
79 public void clear() {
80 balance = new BigDecimal(0);
81 }
82
83 public abstract String getBalanceType();
84
85 public BigDecimal getBalance() { return balance; }
86
87 protected AccrualCategoryRule getAccrualCategoryRuleForDate(LocalDate leaveLocalDate) {
88 return HrServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRuleForDate(accrualCategory, leaveLocalDate, principalCalendar.getServiceLocalDate());
89 }
90
91 protected EmployeeOverride getEmployeeOverride(LeaveBlock leaveBlock, String overrideType) {
92 EmployeeOverride eo = null;
93 eo = LmServiceLocator.getEmployeeOverrideService().getEmployeeOverride(principalCalendar.getPrincipalId(),
94 principalCalendar.getLeavePlan(), accrualCategory.getAccrualCategory(), overrideType, leaveBlock.getLeaveLocalDate());
95 return eo;
96 }
97
98 public AccrualCategory getAccrualCategory() {
99 return accrualCategory;
100 }
101
102 }