1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.balancetransfer;
17
18 import java.math.BigDecimal;
19 import java.sql.Date;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.kuali.hr.lm.accrual.AccrualCategory;
24 import org.kuali.hr.lm.accrual.AccrualCategoryRule;
25 import org.kuali.hr.lm.leaveblock.LeaveBlock;
26 import org.kuali.hr.time.HrBusinessObject;
27 import org.kuali.hr.time.service.base.TkServiceLocator;
28 import org.kuali.hr.time.util.TkConstants;
29 import org.kuali.rice.kim.api.identity.Person;
30 import org.kuali.rice.krad.util.ObjectUtils;
31
32 public class BalanceTransfer extends HrBusinessObject {
33
34 private static final long serialVersionUID = 6948695780968441016L;
35
36 private String balanceTransferId;
37 private String documentHeaderId;
38 private String accrualCategoryRule;
39 private String principalId;
40 private String toAccrualCategory;
41 private String fromAccrualCategory;
42 private BigDecimal transferAmount;
43 private BigDecimal amountTransferred;
44 private BigDecimal forfeitedAmount;
45 private String leaveCalendarDocumentId;
46
47 private String status;
48 private String forfeitedLeaveBlockId;
49 private String accruedLeaveBlockId;
50 private String debitedLeaveBlockId;
51 private String sstoId;
52
53 private Person principal;
54
55 public String getPrincipalId() {
56 return principalId;
57 }
58
59 public void setPrincipalId(String principalId) {
60 this.principalId = principalId;
61 }
62
63 public String getToAccrualCategory() {
64 return toAccrualCategory;
65 }
66
67 public void setToAccrualCategory(String toAccrualCategory) {
68 this.toAccrualCategory = toAccrualCategory;
69 }
70
71 public String getFromAccrualCategory() {
72 return fromAccrualCategory;
73 }
74
75 public void setFromAccrualCategory(String fromAccrualCategory) {
76 this.fromAccrualCategory = fromAccrualCategory;
77 }
78
79 public BigDecimal getTransferAmount() {
80 return transferAmount;
81 }
82
83 public void setTransferAmount(BigDecimal transferAmount) {
84 this.transferAmount = transferAmount;
85 }
86
87 public BigDecimal getForfeitedAmount() {
88 return forfeitedAmount;
89 }
90
91 public void setForfeitedAmount(BigDecimal forfeitedAmount) {
92 this.forfeitedAmount = forfeitedAmount;
93 }
94
95 public String getBalanceTransferId() {
96 return balanceTransferId;
97 }
98
99 public void setBalanceTransferId(String balanceTransferId) {
100 this.balanceTransferId = balanceTransferId;
101 }
102
103 public String getAccrualCategoryRule() {
104 return accrualCategoryRule;
105 }
106
107 public void setAccrualCategoryRule(String accrualCategoryRule) {
108 this.accrualCategoryRule = accrualCategoryRule;
109 }
110
111 @Override
112 protected String getUniqueKey() {
113 return balanceTransferId;
114 }
115
116 @Override
117 public String getId() {
118 return getBalanceTransferId();
119 }
120
121 @Override
122 public void setId(String id) {
123 setBalanceTransferId(id);
124 }
125
126 public Person getPrincipal() {
127 return principal;
128 }
129
130 public void setPrincipal(Person principal) {
131 this.principal = principal;
132 }
133
134 public AccrualCategory getCreditedAccrualCategory() {
135 return TkServiceLocator.getAccrualCategoryService().getAccrualCategory(toAccrualCategory, super.getEffectiveDate());
136 }
137
138 public AccrualCategory getDebitedAccrualCategory() {
139 return TkServiceLocator.getAccrualCategoryService().getAccrualCategory(fromAccrualCategory, super.getEffectiveDate());
140 }
141
142 public String getLeaveCalendarDocumentId() {
143 return leaveCalendarDocumentId;
144 }
145
146 public void setLeaveCalendarDocumentId(String leaveCalendarDocumentId) {
147 this.leaveCalendarDocumentId = leaveCalendarDocumentId;
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161 public BalanceTransfer adjust(BigDecimal transferAmount) {
162 BigDecimal difference = this.transferAmount.subtract(transferAmount);
163 AccrualCategoryRule aRule = TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(accrualCategoryRule);
164
165
166
167
168
169 if(difference.signum() < 0) {
170
171 if(forfeitedAmount.compareTo(BigDecimal.ZERO) > 0) {
172
173 if(forfeitedAmount.compareTo(difference.abs()) >= 0)
174
175 forfeitedAmount = forfeitedAmount.subtract(difference.abs());
176 else
177
178 forfeitedAmount = BigDecimal.ZERO;
179 }
180
181
182
183 }
184 else if (difference.signum() > 0) {
185
186 forfeitedAmount = forfeitedAmount.add(difference);
187 }
188
189 this.transferAmount = transferAmount;
190
191 if(ObjectUtils.isNotNull(aRule.getMaxBalanceTransferConversionFactor()))
192 this.amountTransferred = transferAmount.multiply(aRule.getMaxBalanceTransferConversionFactor()).setScale(2);
193 else
194 this.amountTransferred = transferAmount;
195
196 return this;
197 }
198
199 public List<LeaveBlock> getLeaveBlocks() {
200 List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>();
201 if (getForfeitedLeaveBlockId() != null) {
202 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(forfeitedLeaveBlockId));
203 }
204 if (getAccruedLeaveBlockId() != null) {
205 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(accruedLeaveBlockId));
206 }
207 if (getDebitedLeaveBlockId() != null) {
208 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(debitedLeaveBlockId));
209 }
210
211 return leaveBlocks;
212 }
213
214 public String getStatus() {
215 return status;
216 }
217
218 public void setStatus(String status) {
219 this.status = status;
220 }
221
222 public void disapprove() {
223 TkServiceLocator.getLeaveBlockService().updateLeaveBlock(null, principalId);
224 setStatus(TkConstants.ROUTE_STATUS.DISAPPROVED);
225 }
226
227 public void approve() {
228
229 setStatus(TkConstants.ROUTE_STATUS.FINAL);
230 }
231
232 public void cancel() {
233
234 setStatus(TkConstants.ROUTE_STATUS.CANCEL);
235 }
236
237 public String getAccruedLeaveBlockId() {
238 return accruedLeaveBlockId;
239 }
240
241 public void setAccruedLeaveBlockId(String accruedLeaveBlockId) {
242 this.accruedLeaveBlockId = accruedLeaveBlockId;
243 }
244
245 public String getForfeitedLeaveBlockId() {
246 return forfeitedLeaveBlockId;
247 }
248
249 public void setForfeitedLeaveBlockId(String forfeitedLeaveBlockId) {
250 this.forfeitedLeaveBlockId = forfeitedLeaveBlockId;
251 }
252
253 public String getDebitedLeaveBlockId() {
254 return debitedLeaveBlockId;
255 }
256
257 public void setDebitedLeaveBlockId(String debitedLeaveBlockId) {
258 this.debitedLeaveBlockId = debitedLeaveBlockId;
259 }
260
261 public BigDecimal getAmountTransferred() {
262 return amountTransferred;
263 }
264
265 public void setAmountTransferred(BigDecimal amountTransferrerd) {
266 this.amountTransferred = amountTransferrerd;
267 }
268
269 public String getSstoId() {
270 return sstoId;
271 }
272
273 public void setSstoId(String sstoId) {
274 this.sstoId = sstoId;
275 }
276
277 public String getDocumentHeaderId() {
278 return documentHeaderId;
279 }
280
281 public void setDocumentHeaderId(String documentHeaderId) {
282 this.documentHeaderId = documentHeaderId;
283 }
284
285
286
287
288 }