001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.financial.service.impl;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Map;
024:
025: import org.kuali.core.service.BusinessObjectService;
026: import org.kuali.core.util.KualiDecimal;
027: import org.kuali.core.util.KualiInteger;
028: import org.kuali.core.util.ObjectUtils;
029: import org.kuali.kfs.KFSPropertyConstants;
030: import org.kuali.kfs.bo.SourceAccountingLine;
031: import org.kuali.kfs.bo.TargetAccountingLine;
032: import org.kuali.module.financial.bo.BudgetAdjustmentAccountingLine;
033: import org.kuali.module.financial.bo.BudgetAdjustmentSourceAccountingLine;
034: import org.kuali.module.financial.document.BudgetAdjustmentDocument;
035: import org.kuali.module.financial.service.BudgetAdjustmentLaborBenefitsService;
036: import org.kuali.module.labor.bo.BenefitsCalculation;
037: import org.kuali.module.labor.bo.PositionObjectBenefit;
038:
039: /**
040: *
041: * This is the default implementation of the methods defined by the BudgetAdjustmentLaborBenefitsService.
042: *
043: * These service performs methods related to the generation of labor benefit accounting lines for the budget
044: * adjustment document.
045: *
046: */
047: public class BudgetAdjustmentLaborBenefitsServiceImpl implements
048: BudgetAdjustmentLaborBenefitsService {
049: private BusinessObjectService businessObjectService;
050:
051: /**
052: * This method generated labor benefit accounting lines to be added to the BudgetDocument provided.
053: *
054: * @param budgetDocument The BudgetDocument to have the new labor benefit accounting lines added to.
055: *
056: * @see org.kuali.module.financial.service.BudgetAdjustmentLaborBenefitsService#generateLaborBenefitsAccountingLines(org.kuali.module.financial.document.BudgetAdjustmentDocument)
057: */
058: public void generateLaborBenefitsAccountingLines(
059: BudgetAdjustmentDocument budgetDocument) {
060: Integer fiscalYear = budgetDocument.getPostingYear();
061:
062: List accountingLines = new ArrayList();
063: accountingLines.addAll(budgetDocument
064: .getSourceAccountingLines());
065: accountingLines.addAll(budgetDocument
066: .getTargetAccountingLines());
067:
068: /*
069: * find lines that have labor object codes, then retrieve the benefit calculation records for the object code. Finally, for
070: * each benefit record, create an accounting line with properties set from the original line, but substituted with the
071: * benefit object code and calculated current and base amount.
072: */
073: for (Iterator iter = accountingLines.iterator(); iter.hasNext();) {
074: BudgetAdjustmentAccountingLine line = (BudgetAdjustmentAccountingLine) iter
075: .next();
076:
077: // check if the line was previousely generated benefit line, if so delete and skip
078: if (line.isFringeBenefitIndicator()) {
079: if (line instanceof BudgetAdjustmentSourceAccountingLine) {
080: budgetDocument.getSourceAccountingLines().remove(
081: line);
082: } else {
083: budgetDocument.getTargetAccountingLines().remove(
084: line);
085: }
086: continue;
087: }
088:
089: Collection objectBenefits = retrieveLaborObjectBenefits(
090: fiscalYear, line);
091: if (objectBenefits != null) {
092: for (Iterator iterator = objectBenefits.iterator(); iterator
093: .hasNext();) {
094: PositionObjectBenefit objectBenefit = (PositionObjectBenefit) iterator
095: .next();
096: BenefitsCalculation benefitsCalculation = objectBenefit
097: .getBenefitsCalculation();
098:
099: // now create and set properties for the benefit line
100: BudgetAdjustmentAccountingLine benefitLine = (BudgetAdjustmentAccountingLine) ObjectUtils
101: .deepCopy(line);
102: benefitLine
103: .setFinancialObjectCode(benefitsCalculation
104: .getPositionFringeBenefitObjectCode());
105: benefitLine.refresh();
106:
107: KualiDecimal benefitCurrentAmount = line
108: .getCurrentBudgetAdjustmentAmount()
109: .multiply(
110: benefitsCalculation
111: .getPositionFringeBenefitPercent()
112: .toKualiDecimal());
113: benefitLine
114: .setCurrentBudgetAdjustmentAmount(benefitCurrentAmount);
115:
116: KualiInteger benefitBaseAmount = line
117: .getBaseBudgetAdjustmentAmount()
118: .multiply(
119: benefitsCalculation
120: .getPositionFringeBenefitPercent()
121: .toKualiDecimal());
122: benefitLine
123: .setBaseBudgetAdjustmentAmount(benefitBaseAmount);
124:
125: // clear monthly lines per KULEDOCS-1606
126: benefitLine
127: .clearFinancialDocumentMonthLineAmounts();
128:
129: // set flag on line so we know it was a generated benefit line and can clear it out later if needed
130: benefitLine.setFringeBenefitIndicator(true);
131:
132: if (benefitLine instanceof BudgetAdjustmentSourceAccountingLine) {
133: budgetDocument
134: .addSourceAccountingLine((SourceAccountingLine) benefitLine);
135: } else {
136: budgetDocument
137: .addTargetAccountingLine((TargetAccountingLine) benefitLine);
138: }
139: }
140: }
141: }
142: }
143:
144: /**
145: * @param budgetDocument
146: * @return
147: *
148: * @see org.kuali.module.financial.service.BudgetAdjustmentLaborBenefitsService#hasLaborObjectCodes(org.kuali.module.financial.document.BudgetAdjustmentDocument)
149: */
150: public boolean hasLaborObjectCodes(
151: BudgetAdjustmentDocument budgetDocument) {
152: boolean hasLaborObjectCodes = false;
153:
154: List accountingLines = new ArrayList();
155: accountingLines.addAll(budgetDocument
156: .getSourceAccountingLines());
157: accountingLines.addAll(budgetDocument
158: .getTargetAccountingLines());
159:
160: Integer fiscalYear = budgetDocument.getPostingYear();
161: for (Iterator iter = accountingLines.iterator(); iter.hasNext();) {
162: BudgetAdjustmentAccountingLine line = (BudgetAdjustmentAccountingLine) iter
163: .next();
164: Collection objectBenefits = retrieveLaborObjectBenefits(
165: fiscalYear, line);
166: if (objectBenefits != null && !objectBenefits.isEmpty()) {
167: hasLaborObjectCodes = true;
168: break;
169: }
170: }
171:
172: return hasLaborObjectCodes;
173: }
174:
175: /**
176: * Calls business object service to retrieve LaborObjectBenefit objects for the given fiscal year, and chart,
177: * object code from accounting line.
178: *
179: * @param fiscalYear The fiscal year to be used as search criteria for looking up the labor object benefits.
180: * @param line The account line the benefits are being retrieved for.
181: * @return List of LaborObjectBenefit objects or null if one does not exist for parameters
182: */
183: private Collection retrieveLaborObjectBenefits(Integer fiscalYear,
184: BudgetAdjustmentAccountingLine line) {
185: Map searchCriteria = new HashMap();
186:
187: searchCriteria.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
188: fiscalYear);
189: searchCriteria.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
190: line.getChartOfAccountsCode());
191: searchCriteria.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
192: line.getFinancialObjectCode());
193:
194: return getBusinessObjectService().findMatching(
195: PositionObjectBenefit.class, searchCriteria);
196: }
197:
198: /**
199: * Gets the businessObjectService attribute.
200: *
201: * @return Returns the businessObjectService.
202: */
203: public BusinessObjectService getBusinessObjectService() {
204: return businessObjectService;
205: }
206:
207: /**
208: * Sets the businessObjectService attribute value.
209: *
210: * @param businessObjectService The businessObjectService to set.
211: */
212: public void setBusinessObjectService(
213: BusinessObjectService businessObjectService) {
214: this.businessObjectService = businessObjectService;
215: }
216:
217: }
|