1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document.service.impl;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.ole.coa.businessobject.Account;
20 import org.kuali.ole.gl.businessobject.Balance;
21 import org.kuali.ole.module.purap.businessobject.RequisitionItem;
22 import org.kuali.ole.module.purap.document.RequisitionDocument;
23 import org.kuali.ole.select.OleSelectNotificationConstant;
24 import org.kuali.ole.select.businessobject.OleRequisitionAccount;
25 import org.kuali.ole.select.businessobject.OleSufficientFundCheck;
26 import org.kuali.ole.select.document.service.OleRequisitionDocumentService;
27 import org.kuali.ole.sys.OLEConstants;
28 import org.kuali.ole.sys.OLEPropertyConstants;
29 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
30 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
31 import org.kuali.ole.sys.context.SpringContext;
32 import org.kuali.ole.sys.service.UniversityDateService;
33 import org.kuali.rice.core.api.config.property.ConfigurationService;
34 import org.kuali.rice.core.api.util.type.KualiDecimal;
35 import org.kuali.rice.kew.api.WorkflowDocument;
36 import org.kuali.rice.kim.api.identity.PersonService;
37 import org.kuali.rice.krad.UserSession;
38 import org.kuali.rice.krad.service.BusinessObjectService;
39 import org.kuali.rice.krad.service.DocumentHeaderService;
40 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
41 import org.kuali.rice.krad.util.GlobalVariables;
42
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46
47 public class OleRequisitionDocumentServiceImpl implements OleRequisitionDocumentService {
48 protected static final Logger LOG = Logger.getLogger(OleInvoiceFundCheckServiceImpl.class);
49 protected ConfigurationService kualiConfigurationService;
50 @Override
51 public boolean hasSufficientFundsOnRequisition(SourceAccountingLine accLine) {
52 boolean hasSufficientFundRequired = false;
53 String chartCode = accLine.getChartOfAccountsCode();
54 String accNo = accLine.getAccountNumber();
55 String objectCd = accLine.getFinancialObjectCode();
56 String fundCodeType = getFundCode(chartCode, accNo);
57 KualiDecimal budgetAllocation = KualiDecimal.ZERO;
58 KualiDecimal encumbranceAmt = KualiDecimal.ZERO;
59 Map<String, Object> fundKey = new HashMap<String, Object>();
60 String notificationOption = null;
61 fundKey.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
62 fundKey.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
63 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
64 OleSufficientFundCheck.class, fundKey);
65 if (account != null) {
66 notificationOption = account.getNotificationOption();
67 }
68
69 if (fundCodeType != null && fundCodeType.equals(OLEConstants.ACCOUNT_FUND_CODE)) {
70
71 if (notificationOption.equals(OLEPropertyConstants.BLOCK_USE)
72 || notificationOption.equals(OLEPropertyConstants.WARNING_MSG)) {
73 budgetAllocation = getBudgetAllocationForAccount(chartCode, accNo, objectCd);
74 encumbranceAmt = getEncumbranceForAccount(chartCode, accNo, objectCd);
75 budgetAllocation = budgetAllocation.subtract(encumbranceAmt);
76 } else if (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW)
77 || notificationOption.equals(OLEPropertyConstants.NOTIFICATION)) {
78 budgetAllocation = getBudgetAllocationForAccount(chartCode, accNo, objectCd);
79 encumbranceAmt = getEncumbranceForAccount(chartCode, accNo, objectCd);
80 encumbranceAmt = encumbranceAmt.subtract(accLine.getAmount());
81 budgetAllocation = budgetAllocation.subtract(encumbranceAmt);
82 }
83
84 if (accLine.getAmount().isGreaterThan(budgetAllocation)) {
85 hasSufficientFundRequired = true;
86 } else {
87 hasSufficientFundRequired = false;
88 }
89
90 } else if (fundCodeType != null && fundCodeType.equals(OLEConstants.OBJECT_FUND_CODE)) {
91 if (notificationOption.equals(OLEPropertyConstants.BLOCK_USE)
92 || notificationOption.equals(OLEPropertyConstants.WARNING_MSG)) {
93 budgetAllocation = getBudgetAllocationForObject(chartCode, accNo, objectCd);
94 encumbranceAmt = getEncumbranceForObject(chartCode, accNo, objectCd);
95 budgetAllocation = budgetAllocation.subtract(encumbranceAmt);
96 } else if (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW)
97 || notificationOption.equals(OLEPropertyConstants.NOTIFICATION)) {
98 budgetAllocation = getBudgetAllocationForObject(chartCode, accNo, objectCd);
99 encumbranceAmt = getEncumbranceForObject(chartCode, accNo, objectCd);
100 encumbranceAmt = encumbranceAmt.subtract(accLine.getAmount());
101 budgetAllocation = budgetAllocation.subtract(encumbranceAmt);
102 }
103 if (accLine.getAmount().isGreaterThan(budgetAllocation)) {
104 hasSufficientFundRequired = true;
105 } else {
106 hasSufficientFundRequired = false;
107 }
108 }
109 return hasSufficientFundRequired;
110 }
111
112 private String getFundCode(String chartCode, String accountNumber) {
113 Map accountMap = new HashMap();
114 accountMap.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
115 accountMap.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
116 Account account = SpringContext.getBean(BusinessObjectService.class)
117 .findByPrimaryKey(Account.class, accountMap);
118 boolean fundCheckIndication = false;
119 if (account != null) {
120 fundCheckIndication = account.isPendingAcctSufficientFundsIndicator();
121 }
122
123 if (fundCheckIndication) {
124 String fundCode = account.getAccountSufficientFundsCode();
125 return fundCode;
126 }
127 return null;
128 }
129
130 private KualiDecimal getBudgetAllocationForObject(String chartCode, String accountNumber, String objectCode) {
131 Map budgetMap = new HashMap();
132 UniversityDateService universityDateService = SpringContext.getBean(UniversityDateService.class);
133 budgetMap.put(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR,
134 universityDateService.getCurrentUniversityDate().getUniversityFiscalYear());
135 budgetMap.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
136 budgetMap.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
137 budgetMap.put(OLEPropertyConstants.OBJECT_CODE, objectCode);
138 budgetMap.put(OLEPropertyConstants.BALANCE_TYPE_CODE, OLEPropertyConstants.BAL_TYP_CODE);
139 Balance balance = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Balance.class, budgetMap);
140 KualiDecimal initialBudgetAmount = KualiDecimal.ZERO;
141 if (balance != null) {
142 initialBudgetAmount = balance.getAccountLineAnnualBalanceAmount();
143 }
144 Map encMap = new HashMap();
145 encMap.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
146 encMap.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
147 OleSufficientFundCheck oleSufficientFundCheck = SpringContext.getBean(BusinessObjectService.class)
148 .findByPrimaryKey(OleSufficientFundCheck.class, encMap);
149 KualiDecimal amount = KualiDecimal.ZERO;
150 if (oleSufficientFundCheck != null) {
151 if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_TYP_PERCENTAGE.equals(oleSufficientFundCheck
152 .getEncumbExpenseConstraintType())) {
153 amount = new KualiDecimal(oleSufficientFundCheck.getEncumbranceAmount());
154 if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_OVER.equals(oleSufficientFundCheck
155 .getEncumbExpenseMethod())) {
156 initialBudgetAmount = initialBudgetAmount.add((initialBudgetAmount.multiply(amount))
157 .divide(new KualiDecimal(100)));
158 } else if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_UNDER.equals(oleSufficientFundCheck
159 .getEncumbExpenseMethod())) {
160 initialBudgetAmount = initialBudgetAmount.subtract((initialBudgetAmount.multiply(amount))
161 .divide(new KualiDecimal(100)));
162
163 }
164 } else if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_TYP_CASH.equals(oleSufficientFundCheck
165 .getEncumbExpenseConstraintType())) {
166 amount = new KualiDecimal(oleSufficientFundCheck.getEncumbranceAmount());
167 if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_OVER.equals(oleSufficientFundCheck
168 .getEncumbExpenseMethod())) {
169 initialBudgetAmount = initialBudgetAmount.add(amount);
170 } else if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_UNDER.equals(oleSufficientFundCheck
171 .getEncumbExpenseMethod())) {
172 initialBudgetAmount = initialBudgetAmount.subtract(amount);
173 }
174 }
175 }
176 KualiDecimal budgetIncrease = getBudgetAdjustmentIncreaseForObject(chartCode,accountNumber,objectCode);
177 KualiDecimal budgetDecrease = getBudgetAdjustmentDecreaseForObject(chartCode,accountNumber,objectCode);
178 return initialBudgetAmount.add(budgetIncrease).subtract(budgetDecrease);
179
180 }
181
182 private KualiDecimal getEncumbranceForAccount(String chartCode, String accountNumber, String objectCode) {
183 Map encMap = new HashMap();
184 Map itemMap = new HashMap();
185 Map reqsMap = new HashMap();
186 encMap.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
187 encMap.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
188 KualiDecimal encumAmount = KualiDecimal.ZERO;
189 List<OleRequisitionAccount> encumList = (List<OleRequisitionAccount>) SpringContext.getBean(
190 BusinessObjectService.class).findMatching(OleRequisitionAccount.class, encMap);
191 if (encumList.size() > 0) {
192 for (OleRequisitionAccount olePurchaseOrderAccount : encumList) {
193 itemMap.put(OLEConstants.PO_ITEM_ID, olePurchaseOrderAccount.getItemIdentifier());
194 List<RequisitionItem> encumReqsList = (List<RequisitionItem>) SpringContext.getBean(
195 BusinessObjectService.class).findMatching(RequisitionItem.class, itemMap);
196 for(RequisitionItem reqsItm: encumReqsList) {
197 try {
198 reqsMap.put(OLEConstants.PUR_DOC_IDENTIFIER,reqsItm.getPurapDocumentIdentifier());
199 RequisitionDocument encumReqsDoc = SpringContext.getBean(
200 BusinessObjectService.class).findBySinglePrimaryKey(RequisitionDocument.class, reqsItm.getPurapDocumentIdentifier());
201
202 if (encumReqsDoc.getDocumentHeader().getDocumentNumber() == null) {
203 encumReqsDoc.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(encumReqsDoc.getDocumentNumber()));
204 }
205 WorkflowDocument workflowDocument = null;
206
207
208 String user = null;
209 if (GlobalVariables.getUserSession() == null) {
210 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
211 user = kualiConfigurationService.getPropertyValueAsString(OleSelectNotificationConstant.ACCOUNT_DOCUMENT_INTIATOR);
212 GlobalVariables.setUserSession(new UserSession(user));
213 }
214
215
216 workflowDocument = KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(encumReqsDoc.getDocumentNumber(), SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId()));
217 if(!(workflowDocument.isCanceled() || workflowDocument.isDisapproved() || workflowDocument.isException())) {
218 encumAmount = encumAmount.add(olePurchaseOrderAccount.getAmount());
219 }
220 }
221 catch(Exception e) {
222 LOG.error("Exception while calculating the Sufficient Fund for Requisition Document"+e);
223 throw new RuntimeException(e);
224 }
225 }
226 itemMap.clear();
227 reqsMap.clear();
228
229 }
230 }
231 return encumAmount;
232 }
233
234 private KualiDecimal getBudgetAllocationForAccount(String chartCode, String accountNumber, String objectCode) {
235 Map budgetMap = new HashMap();
236 KualiDecimal initialBudgetAmount = KualiDecimal.ZERO;
237 UniversityDateService universityDateService = SpringContext.getBean(UniversityDateService.class);
238 budgetMap.put(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR,
239 universityDateService.getCurrentUniversityDate().getUniversityFiscalYear());
240 budgetMap.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
241 budgetMap.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
242 budgetMap.put(OLEPropertyConstants.BALANCE_TYPE_CODE, OLEPropertyConstants.BAL_TYP_CODE);
243 List<Balance> balance = (List<Balance>) SpringContext.getBean(BusinessObjectService.class).findMatching(
244 Balance.class, budgetMap);
245 if (balance.size() > 0) {
246 for (Balance budgetBalance : balance) {
247 initialBudgetAmount = initialBudgetAmount.add(budgetBalance.getAccountLineAnnualBalanceAmount());
248 }
249 }
250 Map encMap = new HashMap();
251 encMap.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
252 encMap.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
253 OleSufficientFundCheck oleSufficientFundCheck = SpringContext.getBean(BusinessObjectService.class)
254 .findByPrimaryKey(OleSufficientFundCheck.class, encMap);
255 KualiDecimal amount = KualiDecimal.ZERO;
256 if (oleSufficientFundCheck != null) {
257 if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_TYP_PERCENTAGE.equals(oleSufficientFundCheck
258 .getEncumbExpenseConstraintType())) {
259 amount = new KualiDecimal(oleSufficientFundCheck.getEncumbranceAmount());
260 if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_OVER.equals(oleSufficientFundCheck
261 .getEncumbExpenseMethod())) {
262 initialBudgetAmount = initialBudgetAmount.add((initialBudgetAmount.multiply(amount))
263 .divide(new KualiDecimal(100)));
264 } else if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_UNDER.equals(oleSufficientFundCheck
265 .getEncumbExpenseMethod())) {
266 initialBudgetAmount = initialBudgetAmount.subtract((initialBudgetAmount.multiply(amount))
267 .divide(new KualiDecimal(100)));
268
269 }
270 } else if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_TYP_CASH.equals(oleSufficientFundCheck
271 .getEncumbExpenseConstraintType())) {
272 amount = new KualiDecimal(oleSufficientFundCheck.getEncumbranceAmount());
273 if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_OVER.equals(oleSufficientFundCheck
274 .getEncumbExpenseMethod())) {
275 initialBudgetAmount = initialBudgetAmount.add(amount);
276 } else if (OLEPropertyConstants.SUFFICIENT_FUND_ENC_UNDER.equals(oleSufficientFundCheck
277 .getEncumbExpenseMethod())) {
278 initialBudgetAmount = initialBudgetAmount.subtract(amount);
279 }
280 }
281 }
282
283 KualiDecimal budgetIncrease = getBudgetAdjustmentIncreaseForAccount(chartCode,accountNumber,objectCode);
284 KualiDecimal budgetDecrease = getBudgetAdjustmentDecreaseForAccount(chartCode,accountNumber,objectCode);
285 return initialBudgetAmount.add(budgetIncrease).subtract(budgetDecrease);
286 }
287
288 private KualiDecimal getEncumbranceForObject(String chartCode, String accountNumber, String objectCode) {
289 Map encMap = new HashMap();
290 Map itemMap = new HashMap();
291 Map reqsMap = new HashMap();
292 encMap.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
293 encMap.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
294 encMap.put(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, objectCode);
295 KualiDecimal encumAmount = KualiDecimal.ZERO;
296 List<OleRequisitionAccount> encumList = (List<OleRequisitionAccount>) SpringContext.getBean(
297 BusinessObjectService.class).findMatching(OleRequisitionAccount.class, encMap);
298 if (encumList.size() > 0) {
299 for (OleRequisitionAccount olePurchaseOrderAccount : encumList) {
300 itemMap.put(OLEConstants.PO_ITEM_ID, olePurchaseOrderAccount.getItemIdentifier());
301 List<RequisitionItem> encumReqsList = (List<RequisitionItem>) SpringContext.getBean(
302 BusinessObjectService.class).findMatching(RequisitionItem.class, itemMap);
303 for(RequisitionItem reqsItm: encumReqsList) {
304 try {
305 reqsMap.put(OLEConstants.PUR_DOC_IDENTIFIER,reqsItm.getPurapDocumentIdentifier());
306 RequisitionDocument encumReqsDoc = SpringContext.getBean(
307 BusinessObjectService.class).findBySinglePrimaryKey(RequisitionDocument.class, reqsItm.getPurapDocumentIdentifier());
308
309 if (encumReqsDoc.getDocumentHeader().getDocumentNumber() == null) {
310 encumReqsDoc.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(encumReqsDoc.getDocumentNumber()));
311 }
312 WorkflowDocument workflowDocument = null;
313
314 String user = null;
315 if (GlobalVariables.getUserSession() == null) {
316 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
317 user = kualiConfigurationService.getPropertyValueAsString(OleSelectNotificationConstant.ACCOUNT_DOCUMENT_INTIATOR);
318 GlobalVariables.setUserSession(new UserSession(user));
319 }
320 workflowDocument = KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(encumReqsDoc.getDocumentNumber(), SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId()));
321 if(!(workflowDocument.isCanceled() || workflowDocument.isDisapproved() || workflowDocument.isException())) {
322 encumAmount = encumAmount.add(olePurchaseOrderAccount.getAmount());
323 }
324 }
325 catch(Exception e) {
326 LOG.error("Exception while calculating the Sufficient Fund for Requisition Document"+e);
327 throw new RuntimeException(e);
328 }
329 }
330 itemMap.clear();
331 reqsMap.clear();
332 }
333 }
334 return encumAmount;
335 }
336
337
338 public boolean hasSufficientFundsOnBlanketApproveRequisition(SourceAccountingLine accLine) {
339 boolean hasSufficientFundRequired = false;
340 String chartCode = accLine.getChartOfAccountsCode();
341 String accNo = accLine.getAccountNumber();
342 String objectCd = accLine.getFinancialObjectCode();
343 String fundCodeType = getFundCode(chartCode, accNo);
344 KualiDecimal budgetAllocation = KualiDecimal.ZERO;
345 KualiDecimal encumbranceAmt = KualiDecimal.ZERO;
346 Map<String, Object> fundKey = new HashMap<String, Object>();
347 String notificationOption = null;
348 fundKey.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
349 fundKey.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
350 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
351 OleSufficientFundCheck.class, fundKey);
352 if (account != null) {
353 notificationOption = account.getNotificationOption();
354 }
355
356 if (fundCodeType != null && fundCodeType.equals(OLEConstants.ACCOUNT_FUND_CODE)) {
357
358 if (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW)) {
359 budgetAllocation = getBudgetAllocationForAccount(chartCode, accNo, objectCd);
360 encumbranceAmt = getEncumbranceForAccount(chartCode, accNo, objectCd);
361 budgetAllocation = budgetAllocation.subtract(encumbranceAmt);
362 }
363
364 if (accLine.getAmount().isGreaterThan(budgetAllocation)) {
365 hasSufficientFundRequired = true;
366 } else {
367 hasSufficientFundRequired = false;
368 }
369
370 } else if (fundCodeType != null && fundCodeType.equals(OLEConstants.OBJECT_FUND_CODE)) {
371 if (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW)) {
372 budgetAllocation = getBudgetAllocationForObject(chartCode, accNo, objectCd);
373 encumbranceAmt = getEncumbranceForObject(chartCode, accNo, objectCd);
374 budgetAllocation = budgetAllocation.subtract(encumbranceAmt);
375 }
376 if (accLine.getAmount().isGreaterThan(budgetAllocation)) {
377 hasSufficientFundRequired = true;
378 } else {
379 hasSufficientFundRequired = false;
380 }
381 }
382 return hasSufficientFundRequired;
383 }
384
385
386 public KualiDecimal getBudgetAdjustmentIncreaseForObject(String chartCode, String accountNo,
387 String objectCode) {
388 Map searchMap = new HashMap();
389 searchMap.put("chartOfAccountsCode", chartCode);
390 searchMap.put("accountNumber", accountNo);
391 searchMap.put("financialObjectCode", objectCode);
392 searchMap.put("financialDocumentTypeCode", OLEConstants.DOC_TYP_CD);
393 searchMap.put("financialBalanceTypeCode", OLEConstants.BAL_TYP_CD);
394 searchMap.put("financialDocumentApprovedCode", OLEConstants.FDOC_APPR_CD);
395 List<GeneralLedgerPendingEntry> generalLedgerPendingEntryList = (List<GeneralLedgerPendingEntry>) SpringContext.getBean(
396 BusinessObjectService.class).findMatching(GeneralLedgerPendingEntry.class, searchMap);
397 KualiDecimal budgetIncrease = KualiDecimal.ZERO;
398 if (generalLedgerPendingEntryList.size() > 0) {
399 for (GeneralLedgerPendingEntry entry : generalLedgerPendingEntryList) {
400 if (entry.getTransactionLedgerEntryAmount().isGreaterThan(KualiDecimal.ZERO)) {
401 budgetIncrease = budgetIncrease.add(entry.getTransactionLedgerEntryAmount());
402 }
403 }
404 }
405
406 return budgetIncrease;
407 }
408
409 public KualiDecimal getBudgetAdjustmentDecreaseForObject(String chartCode, String accountNo,
410 String objectCode) {
411 Map searchMap = new HashMap();
412 searchMap.put("chartOfAccountsCode", chartCode);
413 searchMap.put("accountNumber", accountNo);
414 searchMap.put("financialObjectCode", objectCode);
415 searchMap.put("financialDocumentTypeCode", OLEConstants.DOC_TYP_CD);
416 searchMap.put("financialBalanceTypeCode", OLEConstants.BAL_TYP_CD);
417 searchMap.put("financialDocumentApprovedCode", OLEConstants.FDOC_APPR_CD);
418 List<GeneralLedgerPendingEntry> generalLedgerPendingEntryList = (List<GeneralLedgerPendingEntry>) SpringContext.getBean(
419 BusinessObjectService.class).findMatching(GeneralLedgerPendingEntry.class, searchMap);
420 KualiDecimal budgetDecrease = KualiDecimal.ZERO;
421 if (generalLedgerPendingEntryList.size() > 0) {
422 for (GeneralLedgerPendingEntry entry : generalLedgerPendingEntryList) {
423 if (entry.getTransactionLedgerEntryAmount().isLessThan(KualiDecimal.ZERO)) {
424 budgetDecrease = budgetDecrease.add(entry.getTransactionLedgerEntryAmount());
425 }
426 }
427 }
428
429 return budgetDecrease.negated();
430 }
431
432
433 public KualiDecimal getBudgetAdjustmentIncreaseForAccount(String chartCode, String accountNo,
434 String objectCode) {
435 Map searchMap = new HashMap();
436 searchMap.put("chartOfAccountsCode", chartCode);
437 searchMap.put("accountNumber", accountNo);
438 searchMap.put("financialDocumentTypeCode", OLEConstants.DOC_TYP_CD);
439 searchMap.put("financialBalanceTypeCode", OLEConstants.BAL_TYP_CD);
440 searchMap.put("financialDocumentApprovedCode", OLEConstants.FDOC_APPR_CD);
441 List<GeneralLedgerPendingEntry> generalLedgerPendingEntryList = (List<GeneralLedgerPendingEntry>) SpringContext.getBean(
442 BusinessObjectService.class).findMatching(GeneralLedgerPendingEntry.class, searchMap);
443 KualiDecimal budgetIncrease = KualiDecimal.ZERO;
444 if (generalLedgerPendingEntryList.size() > 0) {
445 for (GeneralLedgerPendingEntry entry : generalLedgerPendingEntryList) {
446 if (entry.getTransactionLedgerEntryAmount().isGreaterThan(KualiDecimal.ZERO)) {
447 budgetIncrease = budgetIncrease.add(entry.getTransactionLedgerEntryAmount());
448 }
449 }
450 }
451
452 return budgetIncrease;
453 }
454
455 public KualiDecimal getBudgetAdjustmentDecreaseForAccount(String chartCode, String accountNo,
456 String objectCode) {
457 Map searchMap = new HashMap();
458 searchMap.put("chartOfAccountsCode", chartCode);
459 searchMap.put("accountNumber", accountNo);
460 searchMap.put("financialDocumentTypeCode", OLEConstants.DOC_TYP_CD);
461 searchMap.put("financialBalanceTypeCode", OLEConstants.BAL_TYP_CD);
462 searchMap.put("financialDocumentApprovedCode", OLEConstants.FDOC_APPR_CD);
463 List<GeneralLedgerPendingEntry> generalLedgerPendingEntryList = (List<GeneralLedgerPendingEntry>) SpringContext.getBean(
464 BusinessObjectService.class).findMatching(GeneralLedgerPendingEntry.class, searchMap);
465 KualiDecimal budgetDecrease = KualiDecimal.ZERO;
466 if (generalLedgerPendingEntryList.size() > 0) {
467 for (GeneralLedgerPendingEntry entry : generalLedgerPendingEntryList) {
468 if (entry.getTransactionLedgerEntryAmount().isLessThan(KualiDecimal.ZERO)) {
469 budgetDecrease = budgetDecrease.add(entry.getTransactionLedgerEntryAmount());
470 }
471 }
472 }
473
474 return budgetDecrease.negated();
475 }
476 }