001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.lm.leavepayout;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.hr.lm.accrual.AccrualCategory;
020 import org.kuali.hr.lm.accrual.AccrualCategoryRule;
021 import org.kuali.hr.lm.leaveblock.LeaveBlock;
022 import org.kuali.hr.time.HrBusinessObject;
023 import org.kuali.hr.time.earncode.EarnCode;
024 import org.kuali.hr.time.principal.PrincipalHRAttributes;
025 import org.kuali.hr.time.service.base.TkServiceLocator;
026 import org.kuali.rice.kim.api.identity.Person;
027 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
028 import org.kuali.rice.krad.util.ObjectUtils;
029
030 import java.math.BigDecimal;
031 import java.util.ArrayList;
032 import java.util.List;
033
034 public class LeavePayout extends HrBusinessObject {
035
036 private static final long serialVersionUID = 1L;
037
038 private String lmLeavePayoutId;
039 private String principalId;
040 private String documentHeaderId;
041 private String fromAccrualCategory;
042 private String earnCode;
043 private String description;
044 private BigDecimal payoutAmount = new BigDecimal("0.0");
045 private BigDecimal forfeitedAmount = new BigDecimal("0.0");
046 private Person principal;
047 private AccrualCategory fromAccrualCategoryObj;
048 private EarnCode earnCodeObj;
049 private PrincipalHRAttributes principalHRAttrObj;
050 private String leaveCalendarDocumentId;
051 private String accrualCategoryRule;
052 private String forfeitedLeaveBlockId;
053 private String payoutFromLeaveBlockId;
054 private String payoutLeaveBlockId;
055
056 private String status;
057
058 public String getEarnCode() {
059 return earnCode;
060 }
061 public void setEarnCode(String earnCode) {
062 this.earnCode = earnCode;
063 }
064 public EarnCode getEarnCodeObj() {
065 return TkServiceLocator.getEarnCodeService().getEarnCode(earnCode, getEffectiveDate());
066 }
067 public void setEarnCodeObj(EarnCode earnCodeObj) {
068 this.earnCodeObj = earnCodeObj;
069 }
070 public String getPrincipalId() {
071 return principalId;
072 }
073 public void setPrincipalId(String principalId) {
074 this.principalId = principalId;
075 }
076 public Person getPrincipal() {
077 return principal;
078 }
079 public void setPrincipal(Person principal) {
080 this.principal = principal;
081 }
082 public String getName() {
083 if (principal == null) {
084 principal = KimApiServiceLocator.getPersonService().getPerson(this.principalId);
085 }
086 return (principal != null) ? principal.getName() : "";
087 }
088
089 public String getLeavePlan() {
090 if (!StringUtils.isEmpty(this.principalId)) {
091 principalHRAttrObj = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, this.getEffectiveDate());
092 }
093 return (principalHRAttrObj != null) ? principalHRAttrObj.getLeavePlan() : "";
094 }
095
096 public void setLeavePlan(String leavePlan) {
097 }
098 public String getFromAccrualCategory() {
099 return fromAccrualCategory;
100 }
101 public void setFromAccrualCategory(String accrualCategory) {
102 this.fromAccrualCategory = accrualCategory;
103 }
104
105 public String getDescription() {
106 return description;
107 }
108 public void setDescription(String description) {
109 this.description = description;
110 }
111 public BigDecimal getPayoutAmount() {
112 return payoutAmount;
113 }
114 public void setPayoutAmount(BigDecimal amount) {
115 this.payoutAmount = amount;
116 }
117 public BigDecimal getForfeitedAmount() {
118 return forfeitedAmount;
119 }
120 public void setForfeitedAmount(BigDecimal amount) {
121 this.forfeitedAmount = amount;
122 }
123 public AccrualCategory getFromAccrualCategoryObj() {
124 return TkServiceLocator.getAccrualCategoryService().getAccrualCategory(fromAccrualCategory, getEffectiveDate());
125 }
126 public void setFromAccrualCategoryObj(AccrualCategory accrualCategoryObj) {
127 this.fromAccrualCategoryObj = accrualCategoryObj;
128 }
129 public static long getSerialversionuid() {
130 return serialVersionUID;
131 }
132 public String getLmLeavePayoutId() {
133 return lmLeavePayoutId;
134 }
135 public void setLmLeavePayoutId(String id) {
136 this.lmLeavePayoutId = id;
137 }
138
139 @Override
140 protected String getUniqueKey() {
141 return getLmLeavePayoutId();
142 }
143
144 @Override
145 public String getId() {
146 return getLmLeavePayoutId();
147 }
148
149 @Override
150 public void setId(String id) {
151 setLmLeavePayoutId(id);
152 }
153
154 public PrincipalHRAttributes getPrincipalHRAttrObj() {
155 return principalHRAttrObj;
156 }
157 public void setPrincipalHRAttrObj(PrincipalHRAttributes hrObj) {
158 this.principalHRAttrObj = hrObj;
159 }
160 public String getAccrualCategoryRule() {
161 return accrualCategoryRule;
162 }
163 public void setAccrualCategoryRule(String accrualCategoryRule) {
164 this.accrualCategoryRule = accrualCategoryRule;
165 }
166 public String getForfeitedLeaveBlockId() {
167 return forfeitedLeaveBlockId;
168 }
169 public void setForfeitedLeaveBlockId(String forfeitedLeaveBlockId) {
170 this.forfeitedLeaveBlockId = forfeitedLeaveBlockId;
171 }
172 public String getPayoutLeaveBlockId() {
173 return payoutLeaveBlockId;
174 }
175 public void setPayoutLeaveBlockId(String payoutLeaveBlockId) {
176 this.payoutLeaveBlockId = payoutLeaveBlockId;
177 }
178 public String getPayoutFromLeaveBlockId() {
179 return payoutFromLeaveBlockId;
180 }
181 public void setPayoutFromLeaveBlockId(String payoutFromLeaveBlockId) {
182 this.payoutFromLeaveBlockId = payoutFromLeaveBlockId;
183 }
184
185 public void setLeaveCalendarDocumentId(String leaveCalendarDocumentId) {
186 this.leaveCalendarDocumentId = leaveCalendarDocumentId;
187 }
188
189 public List<LeaveBlock> getLeaveBlocks() {
190 List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>();
191
192 if (getForfeitedLeaveBlockId() != null) {
193 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(forfeitedLeaveBlockId));
194 }
195 if (getPayoutFromLeaveBlockId() != null) {
196 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(payoutFromLeaveBlockId));
197 }
198 if (getPayoutLeaveBlockId() != null) {
199 leaveBlocks.add(TkServiceLocator.getLeaveBlockService().getLeaveBlock(payoutLeaveBlockId));
200 }
201 return leaveBlocks;
202 }
203
204 public String getLeaveCalendarDocumentId() {
205 return leaveCalendarDocumentId;
206 }
207 public LeavePayout adjust(BigDecimal payoutAmount) {
208 BigDecimal difference = this.payoutAmount.subtract(payoutAmount);
209 //technically if there is forfeiture, then the transfer amount has already been maximized
210 //via BalanceTransferService::initializeTransfer(...)
211 //i.o.w. transfer amount cannot be increased.
212 //this method is written with the intention of eventually allowing end user to adjust the transfer
213 //amount as many times as they wish before submitting. Currently they cannot.
214 if(difference.signum() < 0) {
215 //transfer amount is being increased.
216 if(forfeitedAmount.compareTo(BigDecimal.ZERO) > 0) {
217 //transfer amount has already been maximized.
218 if(forfeitedAmount.compareTo(difference.abs()) >= 0)
219 // there is enough leave in the forfeited amount to take out the difference.
220 forfeitedAmount = forfeitedAmount.subtract(difference.abs());
221 else
222 // the difference zero's the forfeited amount.
223 forfeitedAmount = BigDecimal.ZERO;
224 }
225 // a forfeited amount equal to zero with an increase in the transfer amount
226 // does not produce forfeiture.
227 // forfeiture cannot be negative.
228 }
229 else if (difference.signum() > 0) {
230 //transfer amount is being decreased
231 forfeitedAmount = forfeitedAmount.add(difference);
232 }
233
234 this.payoutAmount = payoutAmount;
235
236 return this;
237 }
238
239 public String getStatus() {
240 return status;
241 }
242
243 public void setStatus(String code) {
244 status = code;
245 }
246 public String getDocumentHeaderId() {
247 return documentHeaderId;
248 }
249 public void setDocumentHeaderId(String documentHeaderId) {
250 this.documentHeaderId = documentHeaderId;
251 }
252 }