001/**
002 * Copyright 2004-2015 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 */
016package org.kuali.kpme.tklm.leave.payout.web;
017
018import java.math.BigDecimal;
019import java.util.Date;
020
021import javax.servlet.http.HttpServletRequest;
022
023import org.apache.commons.lang.StringUtils;
024import org.joda.time.LocalDate;
025import org.kuali.kpme.core.api.accrualcategory.AccrualCategory;
026import org.kuali.kpme.core.api.earncode.EarnCode;
027import org.kuali.kpme.core.earncode.EarnCodeBo;
028import org.kuali.kpme.core.service.HrServiceLocator;
029import org.kuali.kpme.core.util.HrConstants;
030import org.kuali.kpme.tklm.leave.payout.LeavePayout;
031import org.kuali.rice.kns.util.ActionFormUtilMap;
032import org.kuali.rice.kns.util.WebUtils;
033import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
034
035public class LeavePayoutForm extends KualiTransactionalDocumentFormBase {
036
037        /**
038         * 
039         */
040        private static final long serialVersionUID = 1L;
041        private LeavePayout leavePayout;
042        private String leavePayoutId;
043        private String accrualCategoryRule;
044        private String principalId;
045        private String earnCode;
046        private String fromAccrualCategory;
047        private BigDecimal payoutAmount;
048        private BigDecimal forfeitedAmount;
049        private Date effectiveDate;
050        private String leaveCalendarDocumentId;
051        private String type;
052        private boolean onLeaveApproval;
053        private boolean timesheet;
054        
055        public Date getEffectiveDate() {
056                return effectiveDate;
057        }
058
059        public void setEffectiveDate(Date effectiveDate) {
060                this.effectiveDate = effectiveDate;
061        }
062        
063        public String getPrincipalId() {
064                return principalId;
065        }
066
067        public void setPrincipalId(String principalId) {
068                this.principalId = principalId;
069        }
070
071        public String getEarnCode() {
072                return earnCode;
073        }
074
075        public void setEarnCode(String earnCode) {
076                this.earnCode = earnCode;
077        }
078
079        public String getFromAccrualCategory() {
080                return fromAccrualCategory;
081        }
082
083        public void setFromAccrualCategory(String fromAccrualCategory) {
084                this.fromAccrualCategory = fromAccrualCategory;
085        }
086
087        public BigDecimal getPayoutAmount() {
088                return payoutAmount;
089        }
090
091        public void setPayoutAmount(BigDecimal payoutAmount) {
092                this.payoutAmount = payoutAmount;
093        }
094
095        public BigDecimal getForfeitedAmount() {
096                return forfeitedAmount;
097        }
098
099        public void setForfeitedAmount(BigDecimal forfeitedAmount) {
100                this.forfeitedAmount = forfeitedAmount;
101        }
102        
103        public String getLeavePayoutId() {
104                return leavePayoutId;
105        }
106
107        public void setLeavePayoutId(String leavePayoutId) {
108                this.leavePayoutId = leavePayoutId;
109        }
110        
111        public String getAccrualCategoryRule() {
112                return accrualCategoryRule;
113        }
114
115        public void setAccrualCategoryRule(String accrualCategoryRule) {
116                this.accrualCategoryRule = accrualCategoryRule;
117        }
118
119        public EarnCode getPayoutEarnCodeObj() {
120                return HrServiceLocator.getEarnCodeService().getEarnCode(earnCode, LocalDate.fromDateFields(effectiveDate));
121        }
122
123        public AccrualCategory getDebitedAccrualCategory() {
124                return HrServiceLocator.getAccrualCategoryService().getAccrualCategory(fromAccrualCategory, LocalDate.fromDateFields(effectiveDate));
125        }
126        
127    @Override
128    public String getBackLocation() {
129        return "LeaveCalendarSubmit.do?methodToCall=approveLeaveCalendar";
130    }
131
132    @Override
133    public void populate(HttpServletRequest request) {
134        super.populate(request);
135        ((ActionFormUtilMap) getActionFormUtilMap()).setCacheValueFinderResults(false);
136
137        if (this.getMethodToCall() == null || StringUtils.isEmpty(this.getMethodToCall())) {
138            setMethodToCall(WebUtils.parseMethodToCall(this, request));
139        }
140    }   
141        
142        @Override
143        public void addRequiredNonEditableProperties() {
144                super.addRequiredNonEditableProperties();
145        }
146
147        public LeavePayout getLeavePayout() {
148                return leavePayout;
149        }
150
151        public void setLeavePayout(LeavePayout leavePayout) {
152                this.leavePayout = leavePayout;
153        }
154
155        public String getLeaveCalendarDocumentId() {
156                return leaveCalendarDocumentId;
157        }
158
159        public void setLeaveCalendarDocumentId(String leaveCalendarDocId) {
160                this.leaveCalendarDocumentId = leaveCalendarDocId;
161        }
162
163        public String getType() {
164                return type;
165        }
166
167        public void setType(String type) {
168                this.type = type;
169        }
170
171        public boolean isOnLeaveApproval() {
172                if(StringUtils.equals(type, HrConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE))
173                        return true;
174                else
175                        return false;
176                //Will return false if MAX_BAL_ACTION_FREQ is YEAR_END, but for purposes of the leave calendar, YEAR_END is not
177                //transferable.
178        }
179
180        public void setOnLeaveApproval(boolean onLeaveApproval) {
181                this.onLeaveApproval = onLeaveApproval;
182        }
183
184        public void isTimesheet(boolean b) {
185                timesheet = true;
186        }
187
188
189}