1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leavepayout;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.lm.accrual.AccrualCategory;
20 import org.kuali.hr.lm.accrual.AccrualCategoryRule;
21 import org.kuali.hr.lm.leaveblock.LeaveBlock;
22 import org.kuali.hr.time.HrBusinessObject;
23 import org.kuali.hr.time.earncode.EarnCode;
24 import org.kuali.hr.time.principal.PrincipalHRAttributes;
25 import org.kuali.hr.time.service.base.TkServiceLocator;
26 import org.kuali.rice.kim.api.identity.Person;
27 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28 import org.kuali.rice.krad.util.ObjectUtils;
29
30 import java.math.BigDecimal;
31 import java.util.ArrayList;
32 import java.util.List;
33
34 public class LeavePayout extends HrBusinessObject {
35
36 private static final long serialVersionUID = 1L;
37
38 private String lmLeavePayoutId;
39 private String principalId;
40 private String documentHeaderId;
41 private String fromAccrualCategory;
42 private String earnCode;
43 private String description;
44 private BigDecimal payoutAmount = new BigDecimal("0.0");
45 private BigDecimal forfeitedAmount = new BigDecimal("0.0");
46 private transient Person principal;
47 private transient AccrualCategory fromAccrualCategoryObj;
48 private transient EarnCode earnCodeObj;
49 private transient PrincipalHRAttributes principalHRAttrObj;
50 private String leaveCalendarDocumentId;
51 private String accrualCategoryRule;
52 private String forfeitedLeaveBlockId;
53 private String payoutFromLeaveBlockId;
54 private String payoutLeaveBlockId;
55
56 private String status;
57
58 public String getEarnCode() {
59 return earnCode;
60 }
61 public void setEarnCode(String earnCode) {
62 this.earnCode = earnCode;
63 }
64 public EarnCode getEarnCodeObj() {
65 if (earnCodeObj == null) {
66 earnCodeObj = TkServiceLocator.getEarnCodeService().getEarnCode(this.earnCode, getEffectiveDate());
67 }
68 return earnCodeObj;
69 }
70 public void setEarnCodeObj(EarnCode earnCodeObj) {
71 this.earnCodeObj = earnCodeObj;
72 }
73 public String getPrincipalId() {
74 return principalId;
75 }
76 public void setPrincipalId(String principalId) {
77 this.principalId = principalId;
78 }
79 public Person getPrincipal() {
80 return principal;
81 }
82 public void setPrincipal(Person principal) {
83 this.principal = principal;
84 }
85 public String getName() {
86 if (principal == null) {
87 principal = KimApiServiceLocator.getPersonService().getPerson(this.principalId);
88 }
89 return (principal != null) ? principal.getName() : "";
90 }
91
92 public String getLeavePlan() {
93 if (!StringUtils.isEmpty(this.principalId)) {
94 principalHRAttrObj = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, this.getEffectiveDate());
95 }
96 return (principalHRAttrObj != null) ? principalHRAttrObj.getLeavePlan() : "";
97 }
98
99 public void setLeavePlan(String leavePlan) {
100 }
101 public String getFromAccrualCategory() {
102 return fromAccrualCategory;
103 }
104 public void setFromAccrualCategory(String accrualCategory) {
105 this.fromAccrualCategory = accrualCategory;
106 }
107
108 public String getDescription() {
109 return description;
110 }
111 public void setDescription(String description) {
112 this.description = description;
113 }
114 public BigDecimal getPayoutAmount() {
115 return payoutAmount;
116 }
117 public void setPayoutAmount(BigDecimal amount) {
118 this.payoutAmount = amount;
119 }
120 public BigDecimal getForfeitedAmount() {
121 return forfeitedAmount;
122 }
123 public void setForfeitedAmount(BigDecimal amount) {
124 this.forfeitedAmount = amount;
125 }
126 public AccrualCategory getFromAccrualCategoryObj() {
127 if (fromAccrualCategoryObj == null) {
128 fromAccrualCategoryObj = TkServiceLocator.getAccrualCategoryService().getAccrualCategory(fromAccrualCategory, getEffectiveDate());
129 }
130 return fromAccrualCategoryObj;
131 }
132 public void setFromAccrualCategoryObj(AccrualCategory accrualCategoryObj) {
133 this.fromAccrualCategoryObj = accrualCategoryObj;
134 }
135 public static long getSerialversionuid() {
136 return serialVersionUID;
137 }
138 public String getLmLeavePayoutId() {
139 return lmLeavePayoutId;
140 }
141 public void setLmLeavePayoutId(String id) {
142 this.lmLeavePayoutId = id;
143 }
144
145 @Override
146 protected String getUniqueKey() {
147 return getLmLeavePayoutId();
148 }
149
150 @Override
151 public String getId() {
152 return getLmLeavePayoutId();
153 }
154
155 @Override
156 public void setId(String id) {
157 setLmLeavePayoutId(id);
158 }
159
160 public PrincipalHRAttributes getPrincipalHRAttrObj() {
161 return principalHRAttrObj;
162 }
163 public void setPrincipalHRAttrObj(PrincipalHRAttributes hrObj) {
164 this.principalHRAttrObj = hrObj;
165 }
166 public String getAccrualCategoryRule() {
167 return accrualCategoryRule;
168 }
169 public void setAccrualCategoryRule(String accrualCategoryRule) {
170 this.accrualCategoryRule = accrualCategoryRule;
171 }
172 public String getForfeitedLeaveBlockId() {
173 return forfeitedLeaveBlockId;
174 }
175 public void setForfeitedLeaveBlockId(String forfeitedLeaveBlockId) {
176 this.forfeitedLeaveBlockId = forfeitedLeaveBlockId;
177 }
178 public String getPayoutLeaveBlockId() {
179 return payoutLeaveBlockId;
180 }
181 public void setPayoutLeaveBlockId(String payoutLeaveBlockId) {
182 this.payoutLeaveBlockId = payoutLeaveBlockId;
183 }
184 public String getPayoutFromLeaveBlockId() {
185 return payoutFromLeaveBlockId;
186 }
187 public void setPayoutFromLeaveBlockId(String payoutFromLeaveBlockId) {
188 this.payoutFromLeaveBlockId = payoutFromLeaveBlockId;
189 }
190
191 public void setLeaveCalendarDocumentId(String leaveCalendarDocumentId) {
192 this.leaveCalendarDocumentId = leaveCalendarDocumentId;
193 }
194
195 public List<LeaveBlock> getLeaveBlocks() {
196 List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>();
197
198 if (getForfeitedLeaveBlockId() != null) {
199 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(forfeitedLeaveBlockId));
200 }
201 if (getPayoutFromLeaveBlockId() != null) {
202 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(payoutFromLeaveBlockId));
203 }
204 if (getPayoutLeaveBlockId() != null) {
205 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(payoutLeaveBlockId));
206 }
207 return leaveBlocks;
208 }
209
210 public String getLeaveCalendarDocumentId() {
211 return leaveCalendarDocumentId;
212 }
213 public LeavePayout adjust(BigDecimal payoutAmount) {
214 BigDecimal difference = this.payoutAmount.subtract(payoutAmount);
215
216
217
218
219
220 if(difference.signum() < 0) {
221
222 if(forfeitedAmount.compareTo(BigDecimal.ZERO) > 0) {
223
224 if(forfeitedAmount.compareTo(difference.abs()) >= 0)
225
226 forfeitedAmount = forfeitedAmount.subtract(difference.abs());
227 else
228
229 forfeitedAmount = BigDecimal.ZERO;
230 }
231
232
233
234 }
235 else if (difference.signum() > 0) {
236
237 forfeitedAmount = forfeitedAmount.add(difference);
238 }
239
240 this.payoutAmount = payoutAmount;
241
242 return this;
243 }
244
245 public String getStatus() {
246 return status;
247 }
248
249 public void setStatus(String code) {
250 status = code;
251 }
252 public String getDocumentHeaderId() {
253 return documentHeaderId;
254 }
255 public void setDocumentHeaderId(String documentHeaderId) {
256 this.documentHeaderId = documentHeaderId;
257 }
258 }