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