View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  	 * A hook for adding leave blocks via leave calendar action
57  	 * 
58  	 * @param leaveBlock The leave block to be added to the bucket
59  	 * @throws KPMEBalanceException
60  	 */
61  	public abstract void add(LeaveBlock leaveBlock) throws KPMEBalanceException;
62  	
63  	/**
64  	 * A hook for removing leave blocks via leave calendar action
65  	 * 
66  	 * @param leaveBlock
67  	 * @throws KPMEBalanceException
68  	 */
69  	public abstract void remove(LeaveBlock leaveBlock) throws KPMEBalanceException;
70  	
71  	/**
72  	 * A hook for editing leave blocks via leave calendar action
73  	 * 
74  	 * @param leaveBlock
75  	 * @throws KPMEBalanceException
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 }