001/* 002 * The Kuali Financial System, a comprehensive financial management system for higher education. 003 * 004 * Copyright 2005-2014 The Kuali Foundation 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero General Public License as 008 * published by the Free Software Foundation, either version 3 of the 009 * License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.kuali.kfs.module.ld.document.web.struts; 020 021import java.util.ArrayList; 022import java.util.Collection; 023import java.util.Collections; 024import java.util.List; 025 026import javax.servlet.http.HttpServletRequest; 027import javax.servlet.http.HttpServletResponse; 028 029import org.apache.struts.action.ActionForm; 030import org.apache.struts.action.ActionForward; 031import org.apache.struts.action.ActionMapping; 032import org.kuali.kfs.module.ld.businessobject.BenefitInquiry; 033import org.kuali.kfs.module.ld.businessobject.PositionObjectBenefit; 034import org.kuali.kfs.module.ld.service.LaborBenefitsCalculationService; 035import org.kuali.kfs.module.ld.service.LaborPositionObjectBenefitService; 036import org.kuali.kfs.sys.KFSConstants; 037import org.kuali.kfs.sys.context.SpringContext; 038import org.kuali.rice.core.api.util.type.KualiDecimal; 039import org.kuali.rice.kns.web.struts.action.KualiAction; 040 041public class FringeBenefitInquiryAction extends KualiAction { 042 043 public ActionForward calculateFringeBenefit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 044 FringeBenefitInquiryForm accountingLineForm = (FringeBenefitInquiryForm) form; 045 046 Integer payrollFiscalyear = new Integer(accountingLineForm.getPayrollEndDateFiscalYear()); 047 String chartOfAccountsCode = accountingLineForm.getChartOfAccountsCode(); 048 String objectCode = accountingLineForm.getFinancialObjectCode(); 049 KualiDecimal amount = new KualiDecimal(accountingLineForm.getAmount()); 050 Collection<PositionObjectBenefit> positionObjectBenefits = SpringContext.getBean(LaborPositionObjectBenefitService.class).getActivePositionObjectBenefits(payrollFiscalyear, chartOfAccountsCode, objectCode); 051 052 List<BenefitInquiry> fringebenefitEntries = new ArrayList<BenefitInquiry>(); 053 for (PositionObjectBenefit positionObjectBenefit : positionObjectBenefits) { 054 if (positionObjectBenefit.getBenefitsCalculation().isActive()) { 055 BenefitInquiry benefitInquiry = new BenefitInquiry(); 056 String fringeBenefitObjectCode = positionObjectBenefit.getBenefitsCalculation().getPositionFringeBenefitObjectCode(); 057 benefitInquiry.setFringeBenefitObjectCode(fringeBenefitObjectCode); 058 KualiDecimal benefitAmount = SpringContext.getBean(LaborBenefitsCalculationService.class).calculateFringeBenefit(positionObjectBenefit, amount, accountingLineForm.getAccountNumber(), accountingLineForm.getSubAccountNumber()); 059 benefitInquiry.setBenefitAmount(benefitAmount); 060 fringebenefitEntries.add(benefitInquiry); 061 } 062 } 063 064 Collections.sort(fringebenefitEntries,Collections.reverseOrder()); 065 066 accountingLineForm.setBenefitInquiry(fringebenefitEntries); 067 068 return mapping.findForward(KFSConstants.MAPPING_BASIC); 069 } 070 071 072}