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.balancetransfer.web;
017    
018    import java.math.BigDecimal;
019    import java.sql.Date;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    import org.apache.commons.lang.StringUtils;
024    import org.kuali.hr.lm.LMConstants;
025    import org.kuali.hr.lm.accrual.AccrualCategory;
026    import org.kuali.hr.lm.balancetransfer.BalanceTransfer;
027    import org.kuali.hr.time.service.base.TkServiceLocator;
028    import org.kuali.rice.kns.util.ActionFormUtilMap;
029    import org.kuali.rice.kns.util.WebUtils;
030    import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
031    import org.kuali.rice.krad.util.ObjectUtils;
032    
033    public class BalanceTransferForm extends KualiTransactionalDocumentFormBase {
034    
035            /**
036             * 
037             */
038            private static final long serialVersionUID = 1L;
039            private BalanceTransfer balanceTransfer;
040            private String balanceTransferId;
041            private String accrualCategoryRule;
042            private String principalId;
043            private String toAccrualCategory;
044            private String fromAccrualCategory;
045            private BigDecimal transferAmount;
046            private BigDecimal forfeitedAmount;
047            private Date effectiveDate;
048            private String leaveCalendarDocumentId;
049            private String type;
050            private boolean onLeaveApproval;
051            private boolean timesheet;
052            
053            public Date getEffectiveDate() {
054                    return effectiveDate;
055            }
056    
057            public void setEffectiveDate(Date effectiveDate) {
058                    this.effectiveDate = effectiveDate;
059            }
060            
061            public String getPrincipalId() {
062                    return principalId;
063            }
064    
065            public void setPrincipalId(String principalId) {
066                    this.principalId = principalId;
067            }
068    
069            public String getToAccrualCategory() {
070                    return toAccrualCategory;
071            }
072    
073            public void setToAccrualCategory(String toAccrualCategory) {
074                    this.toAccrualCategory = toAccrualCategory;
075            }
076    
077            public String getFromAccrualCategory() {
078                    return fromAccrualCategory;
079            }
080    
081            public void setFromAccrualCategory(String fromAccrualCategory) {
082                    this.fromAccrualCategory = fromAccrualCategory;
083            }
084    
085            public BigDecimal getTransferAmount() {
086                    return transferAmount;
087            }
088    
089            public void setTransferAmount(BigDecimal transferAmount) {
090                    this.transferAmount = transferAmount;
091            }
092    
093            public BigDecimal getForfeitedAmount() {
094                    return forfeitedAmount;
095            }
096    
097            public void setForfeitedAmount(BigDecimal forfeitedAmount) {
098                    this.forfeitedAmount = forfeitedAmount;
099            }
100            
101            public String getBalanceTransferId() {
102                    return balanceTransferId;
103            }
104    
105            public void setBalanceTransferId(String balanceTransferId) {
106                    this.balanceTransferId = balanceTransferId;
107            }
108            
109            public String getAccrualCategoryRule() {
110                    return accrualCategoryRule;
111            }
112    
113            public void setAccrualCategoryRule(String accrualCategoryRule) {
114                    this.accrualCategoryRule = accrualCategoryRule;
115            }
116    
117            public AccrualCategory getCreditedAccrualCategory() {
118                    return TkServiceLocator.getAccrualCategoryService().getAccrualCategory(toAccrualCategory, effectiveDate);
119            }
120    
121            public AccrualCategory getDebitedAccrualCategory() {
122                    return TkServiceLocator.getAccrualCategoryService().getAccrualCategory(fromAccrualCategory, effectiveDate);
123            }
124            
125        @Override
126        public String getBackLocation() {
127            return "LeaveCalendarSubmit.do?methodToCall=approveLeaveCalendar";
128        }
129    
130        @Override
131        public void populate(HttpServletRequest request) {
132            super.populate(request);
133            ((ActionFormUtilMap) getActionFormUtilMap()).setCacheValueFinderResults(false);
134    
135            if (this.getMethodToCall() == null || StringUtils.isEmpty(this.getMethodToCall())) {
136                setMethodToCall(WebUtils.parseMethodToCall(this, request));
137            }
138        }   
139            
140            @Override
141            public void addRequiredNonEditableProperties() {
142                    // TODO Auto-generated method stub
143                    System.out.println("*******************************************");
144                    System.out.println("* Adding required non editable properties *");
145                    System.out.println("*******************************************");
146                    super.addRequiredNonEditableProperties();
147            }
148    
149            public BalanceTransfer getBalanceTransfer() {
150                    return balanceTransfer;
151            }
152    
153            public void setBalanceTransfer(BalanceTransfer balanceTransfer) {
154                    this.balanceTransfer = balanceTransfer;
155            }
156    
157            public String getLeaveCalendarDocumentId() {
158                    return leaveCalendarDocumentId;
159            }
160    
161            public void setLeaveCalendarDocumentId(String leaveCalendarDocId) {
162                    this.leaveCalendarDocumentId = leaveCalendarDocId;
163            }
164    
165            public String getType() {
166                    return type;
167            }
168    
169            public void setType(String type) {
170                    this.type = type;
171            }
172    
173            public boolean isOnLeaveApproval() {
174                    if(StringUtils.equals(type, LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE))
175                            return true;
176                    else
177                            return false;
178                    //Will return false if MAX_BAL_ACTION_FREQ is YEAR_END, but for purposes of the leave calendar, YEAR_END is not
179                    //transferable.
180            }
181    
182            public void setOnLeaveApproval(boolean onLeaveApproval) {
183                    this.onLeaveApproval = onLeaveApproval;
184            }
185    
186            public void isTimesheet(boolean b) {
187                    timesheet = true;
188            }
189    
190            public boolean isSstoTransfer() {
191                    if(this.getBalanceTransfer() != null) {
192                            if(StringUtils.isNotEmpty(this.getBalanceTransfer().getSstoId()))
193                                    return true;
194                            else
195                                    return false;
196                    }
197                    else
198                            return false;
199            }
200    
201    }