Source Code Cross Referenced for SufficientFundsServiceImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » gl » service » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.module.gl.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.gl.service.impl;
017:
018:        import java.util.ArrayList;
019:        import java.util.HashMap;
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import java.util.Map;
023:
024:        import org.apache.commons.lang.StringUtils;
025:        import org.kuali.core.service.KualiConfigurationService;
026:        import org.kuali.core.util.KualiDecimal;
027:        import org.kuali.core.util.ObjectUtils;
028:        import org.kuali.kfs.KFSConstants;
029:        import org.kuali.kfs.bo.Options;
030:        import org.kuali.kfs.context.SpringContext;
031:        import org.kuali.kfs.document.GeneralLedgerPostingDocument;
032:        import org.kuali.kfs.service.GeneralLedgerPendingEntryService;
033:        import org.kuali.kfs.service.OptionsService;
034:        import org.kuali.module.chart.bo.Account;
035:        import org.kuali.module.chart.bo.ObjectCode;
036:        import org.kuali.module.chart.service.AccountService;
037:        import org.kuali.module.chart.service.ObjectLevelService;
038:        import org.kuali.module.chart.service.ObjectTypeService;
039:        import org.kuali.module.financial.document.YearEndDocument;
040:        import org.kuali.module.gl.bo.SufficientFundBalances;
041:        import org.kuali.module.gl.bo.SufficientFundRebuild;
042:        import org.kuali.module.gl.bo.Transaction;
043:        import org.kuali.module.gl.dao.SufficientFundBalancesDao;
044:        import org.kuali.module.gl.dao.SufficientFundsDao;
045:        import org.kuali.module.gl.service.SufficientFundRebuildService;
046:        import org.kuali.module.gl.service.SufficientFundsService;
047:        import org.kuali.module.gl.service.SufficientFundsServiceConstants;
048:        import org.kuali.module.gl.util.SufficientFundsItem;
049:        import org.springframework.transaction.annotation.Transactional;
050:
051:        /**
052:         * The base implementation of SufficientFundsService
053:         */
054:        @Transactional
055:        public class SufficientFundsServiceImpl implements 
056:                SufficientFundsService, SufficientFundsServiceConstants {
057:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
058:                    .getLogger(SufficientFundsServiceImpl.class);
059:
060:            private AccountService accountService;
061:            private ObjectLevelService objectLevelService;
062:            private KualiConfigurationService kualiConfigurationService;
063:            private SufficientFundsDao sufficientFundsDao;
064:            private SufficientFundBalancesDao sufficientFundBalancesDao;
065:            private OptionsService optionsService;
066:            private GeneralLedgerPendingEntryService generalLedgerPendingEntryService;
067:            private SufficientFundRebuildService sufficientFundRebuildService;
068:
069:            /**
070:             * Default constructor
071:             */
072:            public SufficientFundsServiceImpl() {
073:                super ();
074:            }
075:
076:            /**
077:             * This operation derives the acct_sf_finobj_cd which is used to populate the General Ledger Pending entry table, so that later
078:             * we can do Suff Fund checking against that entry
079:             * 
080:             * @param financialObject the object code being checked against
081:             * @param accountSufficientFundsCode the kind of sufficient funds checking turned on in this system
082:             * @return the object code that should be used for the sufficient funds inquiry, or a blank String
083:             * @see org.kuali.module.gl.service.SufficientFundsService#getSufficientFundsObjectCode(org.kuali.module.chart.bo.ObjectCode,
084:             *      java.lang.String)
085:             */
086:            public String getSufficientFundsObjectCode(
087:                    ObjectCode financialObject,
088:                    String accountSufficientFundsCode) {
089:                LOG.debug("getSufficientFundsObjectCode() started");
090:
091:                financialObject.refreshNonUpdateableReferences();
092:
093:                if (KFSConstants.SF_TYPE_NO_CHECKING
094:                        .equals(accountSufficientFundsCode)) {
095:                    return KFSConstants.NOT_AVAILABLE_STRING;
096:                } else if (KFSConstants.SF_TYPE_ACCOUNT
097:                        .equals(accountSufficientFundsCode)) {
098:                    return "    ";
099:                } else if (KFSConstants.SF_TYPE_CASH_AT_ACCOUNT
100:                        .equals(accountSufficientFundsCode)) {
101:                    return "    ";
102:                } else if (KFSConstants.SF_TYPE_OBJECT
103:                        .equals(accountSufficientFundsCode)) {
104:                    return financialObject.getFinancialObjectCode();
105:                } else if (KFSConstants.SF_TYPE_LEVEL
106:                        .equals(accountSufficientFundsCode)) {
107:                    return financialObject.getFinancialObjectLevelCode();
108:                } else if (KFSConstants.SF_TYPE_CONSOLIDATION
109:                        .equals(accountSufficientFundsCode)) {
110:                    return financialObject.getFinancialObjectLevel()
111:                            .getFinancialConsolidationObjectCode();
112:                } else {
113:                    throw new IllegalArgumentException(
114:                            "Invalid Sufficient Funds Code: "
115:                                    + accountSufficientFundsCode);
116:                }
117:            }
118:
119:            /**
120:             * Checks for sufficient funds on a single document
121:             * 
122:             * @param document document to check
123:             * @return Empty List if has sufficient funds for all accounts, List of SufficientFundsItem if not
124:             * @see org.kuali.module.gl.service.SufficientFundsService#checkSufficientFunds(org.kuali.core.document.FinancialDocument)
125:             */
126:            public List<SufficientFundsItem> checkSufficientFunds(
127:                    GeneralLedgerPostingDocument document) {
128:                LOG.debug("checkSufficientFunds() started");
129:
130:                return checkSufficientFunds((List<? extends Transaction>) document
131:                        .getPendingLedgerEntriesForSufficientFundsChecking());
132:            }
133:
134:            /**
135:             * checks to see if a document is a <code>YearEndDocument</code>
136:             * 
137:             * @param documentClass the class of a Document to check
138:             * @return true if the class implements <code>YearEndDocument</code>
139:             */
140:            private boolean isYearEndDocument(Class documentClass) {
141:                return YearEndDocument.class.isAssignableFrom(documentClass);
142:            }
143:
144:            /**
145:             * Checks for sufficient funds on a list of transactions
146:             * 
147:             * @param transactions list of transactions
148:             * @return Empty List if has sufficient funds for all accounts, List of SufficientFundsItem if not
149:             * @see org.kuali.module.gl.service.SufficientFundsService#checkSufficientFunds(java.util.List)
150:             */
151:            public List<SufficientFundsItem> checkSufficientFunds(
152:                    List<? extends Transaction> transactions) {
153:                LOG.debug("checkSufficientFunds() started");
154:
155:                for (Transaction e : transactions) {
156:                    e.refreshNonUpdateableReferences();
157:                }
158:
159:                List<SufficientFundsItem> summaryItems = summarizeTransactions(transactions);
160:                for (Iterator iter = summaryItems.iterator(); iter.hasNext();) {
161:                    SufficientFundsItem item = (SufficientFundsItem) iter
162:                            .next();
163:                    LOG.error("checkSufficientFunds() " + item.toString());
164:                    if (hasSufficientFundsOnItem(item)) {
165:                        iter.remove();
166:                    }
167:                }
168:
169:                return summaryItems;
170:            }
171:
172:            /**
173:             * For each transaction, fetches the appropriate sufficient funds item to check against
174:             * 
175:             * @param transactions a list of Transactions
176:             * @return a List of corresponding SufficientFundsItem
177:             */
178:            private List<SufficientFundsItem> summarizeTransactions(
179:                    List<? extends Transaction> transactions) {
180:                Map<String, SufficientFundsItem> items = new HashMap<String, SufficientFundsItem>();
181:
182:                Options currentYear = optionsService.getCurrentYearOptions();
183:
184:                for (Iterator iter = transactions.iterator(); iter.hasNext();) {
185:                    Transaction tran = (Transaction) iter.next();
186:
187:                    Options year = tran.getOption();
188:                    if (year == null) {
189:                        year = currentYear;
190:                    }
191:                    if (ObjectUtils.isNull(tran.getAccount())) {
192:                        throw new IllegalArgumentException("Invalid account: "
193:                                + tran.getChartOfAccountsCode() + "-"
194:                                + tran.getAccountNumber());
195:                    }
196:                    SufficientFundsItem sfi = new SufficientFundsItem(year,
197:                            tran, getSufficientFundsObjectCode(tran
198:                                    .getFinancialObject(), tran.getAccount()
199:                                    .getAccountSufficientFundsCode()));
200:                    sfi
201:                            .setDocumentTypeCode(tran
202:                                    .getFinancialDocumentTypeCode());
203:
204:                    if (items.containsKey(sfi.getKey())) {
205:                        SufficientFundsItem item = (SufficientFundsItem) items
206:                                .get(sfi.getKey());
207:                        item.add(tran);
208:                    } else {
209:                        items.put(sfi.getKey(), sfi);
210:                    }
211:                }
212:
213:                return new ArrayList<SufficientFundsItem>(items.values());
214:            }
215:
216:            /**
217:             * Given a sufficient funds item record, determines if there are sufficient funds available for the transaction
218:             * 
219:             * @param item the item to check
220:             * @return true if there are sufficient funds available, false otherwise
221:             */
222:            private boolean hasSufficientFundsOnItem(SufficientFundsItem item) {
223:
224:                if (item.getAmount().equals(KualiDecimal.ZERO)) {
225:                    LOG
226:                            .debug("hasSufficientFundsOnItem() Transactions with zero amounts shold pass");
227:                    return true;
228:                }
229:
230:                if (!item.getYear().isBudgetCheckingOptionsCode()) {
231:                    LOG
232:                            .debug("hasSufficientFundsOnItem() No sufficient funds checking");
233:                    return true;
234:                }
235:
236:                if (!item.getAccount().isPendingAcctSufficientFundsIndicator()) {
237:                    LOG
238:                            .debug("hasSufficientFundsOnItem() No checking on eDocs for account "
239:                                    + item.getAccount()
240:                                            .getChartOfAccountsCode()
241:                                    + "-"
242:                                    + item.getAccount().getAccountNumber());
243:                    return true;
244:                }
245:
246:                // exit sufficient funds checking if not enabled for an account
247:                if (KFSConstants.SF_TYPE_NO_CHECKING.equals(item
248:                        .getAccountSufficientFundsCode())) {
249:                    LOG
250:                            .debug("hasSufficientFundsOnItem() sufficient funds not enabled for account "
251:                                    + item.getAccount()
252:                                            .getChartOfAccountsCode()
253:                                    + "-"
254:                                    + item.getAccount().getAccountNumber());
255:                    return true;
256:                }
257:
258:                ObjectTypeService objectTypeService = (ObjectTypeService) SpringContext
259:                        .getBean(ObjectTypeService.class);
260:                List<String> expenseObjectTypes = objectTypeService
261:                        .getCurrentYearExpenseObjectTypes();
262:
263:                if (KFSConstants.SF_TYPE_CASH_AT_ACCOUNT.equals(item
264:                        .getAccount().getAccountSufficientFundsCode())
265:                        && !item.getFinancialObject().getChartOfAccounts()
266:                                .getFinancialCashObjectCode().equals(
267:                                        item.getFinancialObject()
268:                                                .getFinancialObjectCode())) {
269:                    LOG
270:                            .debug("hasSufficientFundsOnItem() SF checking is cash and transaction is not cash");
271:                    return true;
272:                }
273:
274:                else if (!KFSConstants.SF_TYPE_CASH_AT_ACCOUNT.equals(item
275:                        .getAccount().getAccountSufficientFundsCode())
276:                        && !expenseObjectTypes.contains(item
277:                                .getFinancialObjectType().getCode())) {
278:                    LOG
279:                            .debug("hasSufficientFundsOnItem() SF checking is budget and transaction is not expense");
280:                    return true;
281:                }
282:
283:                SufficientFundBalances sfBalance = sufficientFundBalancesDao
284:                        .getByPrimaryId(item.getYear()
285:                                .getUniversityFiscalYear(), item.getAccount()
286:                                .getChartOfAccountsCode(), item.getAccount()
287:                                .getAccountNumber(), item
288:                                .getSufficientFundsObjectCode());
289:
290:                if (sfBalance == null) {
291:                    SufficientFundRebuild sufficientFundRebuild = sufficientFundRebuildService
292:                            .getByAccount(item.getAccount()
293:                                    .getChartOfAccountsCode(), item
294:                                    .getAccount().getAccountNumber());
295:                    if (sufficientFundRebuild != null) {
296:                        LOG
297:                                .debug("hasSufficientFundsOnItem() No balance record and waiting on rebuild, no sufficient funds");
298:                        return false;
299:                    } else {
300:                        sfBalance = new SufficientFundBalances();
301:                        sfBalance
302:                                .setAccountActualExpenditureAmt(KualiDecimal.ZERO);
303:                        sfBalance
304:                                .setAccountEncumbranceAmount(KualiDecimal.ZERO);
305:                        sfBalance
306:                                .setCurrentBudgetBalanceAmount(KualiDecimal.ZERO);
307:                    }
308:                }
309:
310:                KualiDecimal balanceAmount = item.getAmount();
311:                if (KFSConstants.SF_TYPE_CASH_AT_ACCOUNT.equals(item
312:                        .getAccount().getAccountSufficientFundsCode())
313:                        || item.getYear().getBudgetCheckingBalanceTypeCd()
314:                                .equals(item.getBalanceTyp().getCode())) {
315:                    // We need to change the sign on the amount because the amount in the item is an increase in cash. We only care
316:                    // about decreases in cash.
317:
318:                    // Also, negating if this is a balance type code of budget checking and the transaction is a budget transaction.
319:
320:                    balanceAmount = balanceAmount.negated();
321:                }
322:
323:                if (balanceAmount.isNegative()) {
324:                    LOG
325:                            .debug("hasSufficientFundsOnItem() balanceAmount is negative, allow transaction to proceed");
326:                    return true;
327:                }
328:
329:                PendingAmounts priorYearPending = new PendingAmounts();
330:                if ((KFSConstants.SF_TYPE_CASH_AT_ACCOUNT.equals(item
331:                        .getAccount().getAccountSufficientFundsCode()))
332:                        && (!item.getYear().isFinancialBeginBalanceLoadInd())) {
333:                    priorYearPending = getPendingPriorYearBalanceAmount(item);
334:                }
335:
336:                PendingAmounts pending = getPendingBalanceAmount(item);
337:
338:                KualiDecimal availableBalance = null;
339:                if (KFSConstants.SF_TYPE_CASH_AT_ACCOUNT.equals(item
340:                        .getAccount().getAccountSufficientFundsCode())) {
341:                    if (!item.getYear().isFinancialBeginBalanceLoadInd()) {
342:                        availableBalance = sfBalance
343:                                .getCurrentBudgetBalanceAmount()
344:                                .add(priorYearPending.budget)
345:                                .add(pending.actual)
346:                                .subtract(
347:                                        sfBalance.getAccountEncumbranceAmount())
348:                                .subtract(priorYearPending.encumbrance);
349:                    } else {
350:                        availableBalance = sfBalance
351:                                .getCurrentBudgetBalanceAmount()
352:                                .add(pending.actual)
353:                                .subtract(
354:                                        sfBalance.getAccountEncumbranceAmount());
355:                    }
356:                } else {
357:                    availableBalance = sfBalance
358:                            .getCurrentBudgetBalanceAmount()
359:                            .add(pending.budget).subtract(
360:                                    sfBalance.getAccountActualExpenditureAmt())
361:                            .subtract(pending.actual).subtract(
362:                                    sfBalance.getAccountEncumbranceAmount())
363:                            .subtract(pending.encumbrance);
364:                }
365:
366:                LOG.debug("hasSufficientFundsOnItem() balanceAmount: "
367:                        + balanceAmount + " availableBalance: "
368:                        + availableBalance);
369:                if (balanceAmount.compareTo(availableBalance) > 0) {
370:                    LOG.debug("hasSufficientFundsOnItem() no sufficient funds");
371:                    return false;
372:                }
373:
374:                LOG.debug("hasSufficientFundsOnItem() has sufficient funds");
375:                return true;
376:            }
377:
378:            /**
379:             * An inner class to hold summary totals of pending ledger entry amounts
380:             */
381:            private class PendingAmounts {
382:                public KualiDecimal budget;
383:                public KualiDecimal actual;
384:                public KualiDecimal encumbrance;
385:
386:                /**
387:                 * Constructs a SufficientFundsServiceImpl.PendingAmounts instance
388:                 */
389:                public PendingAmounts() {
390:                    budget = KualiDecimal.ZERO;
391:                    actual = KualiDecimal.ZERO;
392:                    encumbrance = KualiDecimal.ZERO;
393:                }
394:
395:            }
396:
397:            /**
398:             * Given a sufficient funds item to check, gets the prior year sufficient funds balance to check against
399:             * 
400:             * @param item the sufficient funds item to check against
401:             * @return a PendingAmounts record with the pending budget and encumbrance
402:             */
403:            private PendingAmounts getPendingPriorYearBalanceAmount(
404:                    SufficientFundsItem item) {
405:                LOG.debug("getPendingBalanceAmount() started");
406:
407:                PendingAmounts amounts = new PendingAmounts();
408:
409:                // This only gets called for sufficient funds type of Cash at Account (H). The object code in the table for this type is
410:                // always
411:                // 4 spaces.
412:                SufficientFundBalances bal = sufficientFundBalancesDao
413:                        .getByPrimaryId(Integer.valueOf(item.getYear()
414:                                .getUniversityFiscalYear().intValue() - 1),
415:                                item.getAccount().getChartOfAccountsCode(),
416:                                item.getAccount().getAccountNumber(), "    ");
417:
418:                if (bal != null) {
419:                    amounts.budget = bal.getCurrentBudgetBalanceAmount();
420:                    amounts.encumbrance = bal.getAccountEncumbranceAmount();
421:                }
422:
423:                LOG.debug("getPendingPriorYearBalanceAmount() budget      "
424:                        + amounts.budget);
425:                LOG.debug("getPendingPriorYearBalanceAmount() encumbrance "
426:                        + amounts.encumbrance);
427:                return amounts;
428:            }
429:
430:            /**
431:             * Totals the amounts of actual, encumbrance, and budget amounts from related pending entries
432:             * 
433:             * @param item a sufficient funds item to find pending amounts for
434:             * @return the totals encapsulated in a PendingAmounts object
435:             */
436:            private PendingAmounts getPendingBalanceAmount(
437:                    SufficientFundsItem item) {
438:                LOG.debug("getPendingBalanceAmount() started");
439:
440:                Integer fiscalYear = item.getYear().getUniversityFiscalYear();
441:                String chart = item.getAccount().getChartOfAccountsCode();
442:                String account = item.getAccount().getAccountNumber();
443:                String sfCode = item.getAccount()
444:                        .getAccountSufficientFundsCode();
445:
446:                PendingAmounts amounts = new PendingAmounts();
447:
448:                if (KFSConstants.SF_TYPE_CASH_AT_ACCOUNT.equals(sfCode)) {
449:                    // Cash checking
450:                    List years = new ArrayList();
451:                    years.add(item.getYear().getUniversityFiscalYear());
452:
453:                    // If the beginning balance isn't loaded, we need to include cash from
454:                    // the previous fiscal year
455:                    if (!item.getYear().isFinancialBeginBalanceLoadInd()) {
456:                        years.add(item.getYear().getUniversityFiscalYear() - 1);
457:                    }
458:
459:                    // Calculate the pending actual amount
460:                    // Get Cash (debit amount - credit amount)
461:                    amounts.actual = generalLedgerPendingEntryService
462:                            .getCashSummary(years, chart, account, true);
463:                    amounts.actual = amounts.actual
464:                            .subtract(generalLedgerPendingEntryService
465:                                    .getCashSummary(years, chart, account,
466:                                            false));
467:
468:                    // Get Payables (credit amount - debit amount)
469:                    amounts.actual = amounts.actual
470:                            .add(generalLedgerPendingEntryService
471:                                    .getActualSummary(years, chart, account,
472:                                            false));
473:                    amounts.actual = amounts.actual
474:                            .subtract(generalLedgerPendingEntryService
475:                                    .getActualSummary(years, chart, account,
476:                                            true));
477:                } else {
478:                    // Non-Cash checking
479:
480:                    // Get expenditure (debit - credit)
481:                    amounts.actual = generalLedgerPendingEntryService
482:                            .getExpenseSummary(fiscalYear, chart, account, item
483:                                    .getSufficientFundsObjectCode(), true, item
484:                                    .getDocumentTypeCode().startsWith("YE"));
485:                    amounts.actual = amounts.actual
486:                            .subtract(generalLedgerPendingEntryService
487:                                    .getExpenseSummary(
488:                                            fiscalYear,
489:                                            chart,
490:                                            account,
491:                                            item.getSufficientFundsObjectCode(),
492:                                            false, item.getDocumentTypeCode()
493:                                                    .startsWith("YE")));
494:
495:                    // Get budget
496:                    amounts.budget = generalLedgerPendingEntryService
497:                            .getBudgetSummary(fiscalYear, chart, account, item
498:                                    .getSufficientFundsObjectCode(), item
499:                                    .getDocumentTypeCode().startsWith("YE"));
500:
501:                    // Get encumbrance (debit - credit)
502:                    amounts.encumbrance = generalLedgerPendingEntryService
503:                            .getEncumbranceSummary(fiscalYear, chart, account,
504:                                    item.getSufficientFundsObjectCode(), true,
505:                                    item.getDocumentTypeCode().startsWith("YE"));
506:                    amounts.encumbrance = amounts.encumbrance
507:                            .subtract(generalLedgerPendingEntryService
508:                                    .getEncumbranceSummary(
509:                                            fiscalYear,
510:                                            chart,
511:                                            account,
512:                                            item.getSufficientFundsObjectCode(),
513:                                            false, item.getDocumentTypeCode()
514:                                                    .startsWith("YE")));
515:                }
516:
517:                LOG.debug("getPendingBalanceAmount() actual      "
518:                        + amounts.actual);
519:                LOG.debug("getPendingBalanceAmount() budget      "
520:                        + amounts.budget);
521:                LOG.debug("getPendingBalanceAmount() encumbrance "
522:                        + amounts.encumbrance);
523:                return amounts;
524:            }
525:
526:            /**
527:             * Determines the current sufficient funds
528:             * 
529:             * @param propertyNames not referenced in the method
530:             * @param universityFiscalYear the university fiscal year to check
531:             * @param chartOfAccountsCode the chart to check
532:             * @param accountNumber the account to check
533:             * @param sufficientFundsObjectCode the object code to check
534:             * @param amount the amount to check if sufficient funds exist for
535:             * @param documentClass the class of the document doing the check
536:             * @return true is sufficientFunds were found, false otherwise
537:             */
538:            private boolean checkSufficientFunds(List propertyNames,
539:                    Integer universityFiscalYear, String chartOfAccountsCode,
540:                    String accountNumber, String sufficientFundsObjectCode,
541:                    KualiDecimal amount, Class documentClass) {
542:                // fp_sasfc:operation chk_suff_funds
543:                // I'm not certain this method is actually used currently
544:                if (universityFiscalYear == null) {
545:                    throw new IllegalArgumentException(
546:                            "Invalid (null) universityFiscalYear");
547:                }
548:                Integer originalUniversityFiscalYear = universityFiscalYear;
549:
550:                Account account = accountService.getByPrimaryId(
551:                        chartOfAccountsCode, accountNumber);
552:                if (account == null) {
553:                    throw new IllegalArgumentException(
554:                            "Invalid (null) account for: chartOfAccountsCode="
555:                                    + chartOfAccountsCode + ";accountNumber="
556:                                    + accountNumber);
557:                }
558:                boolean isYearEndDocument = isYearEndDocument(documentClass);
559:                // universityFiscalYear is universityFiscalYear-1 if year end document & chash
560:                // level checking
561:                if (isYearEndDocument
562:                        && StringUtils.equals(
563:                                KFSConstants.SF_TYPE_CASH_AT_ACCOUNT, account
564:                                        .getAccountSufficientFundsCode())) {
565:                    universityFiscalYear = new Integer(
566:                            originalUniversityFiscalYear.intValue() - 1);
567:                }
568:
569:                // exit sufficient funds checking if not enabled for an account
570:                if (StringUtils.equals(KFSConstants.SF_TYPE_NO_CHECKING,
571:                        account.getAccountSufficientFundsCode())
572:                        || !account.isPendingAcctSufficientFundsIndicator()) {
573:                    LOG.debug("sufficient funds not enabled for account "
574:                            + account.getAccountNumber());
575:                    return true;
576:                }
577:
578:                // fp_sasfc:19
579:                // retrieve gl sufficient fund balances for account
580:                SufficientFundBalances sfBalances = new SufficientFundBalances();
581:                sfBalances.setUniversityFiscalYear(universityFiscalYear);
582:                sfBalances.setChartOfAccountsCode(chartOfAccountsCode);
583:                sfBalances.setAccountNumber(accountNumber);
584:                if (!StringUtils.equals(KFSConstants.NOT_AVAILABLE_STRING,
585:                        sufficientFundsObjectCode)) {
586:                    sfBalances
587:                            .setFinancialObjectCode(sufficientFundsObjectCode);
588:                } else if (StringUtils.equals(KFSConstants.SF_TYPE_ACCOUNT,
589:                        account.getAccountSufficientFundsCode())) {
590:                    // dont set anything for account level checking
591:                } else {
592:                    sfBalances
593:                            .setAccountSufficientFundsCode(KFSConstants.SF_TYPE_CASH_AT_ACCOUNT);
594:                }
595:
596:                sfBalances = sufficientFundBalancesDao.getByPrimaryId(
597:                        sfBalances.getUniversityFiscalYear(), sfBalances
598:                                .getChartOfAccountsCode(), sfBalances
599:                                .getAccountNumber(), sfBalances
600:                                .getFinancialObjectCode());
601:                // fp_sasfc:32-1
602:                if (sfBalances == null) {
603:                    sfBalances = new SufficientFundBalances();
604:                    sfBalances
605:                            .setCurrentBudgetBalanceAmount(new KualiDecimal(0));
606:                    sfBalances.setAccountActualExpenditureAmt(new KualiDecimal(
607:                            0));
608:                    sfBalances.setAccountEncumbranceAmount(new KualiDecimal(0));
609:                    sfBalances.setChartOfAccountsCode(chartOfAccountsCode);
610:                    sfBalances.setAccountNumber(accountNumber);
611:                    sfBalances.setAccountSufficientFundsCode(account
612:                            .getAccountSufficientFundsCode());
613:
614:                }
615:                // fp_sasfc;37
616:                // restore universityFiscalYear
617:
618:                sfBalances
619:                        .setUniversityFiscalYear(originalUniversityFiscalYear);
620:
621:                // return calculatePLEBuckets(propertyNames, isYearEndDocument, amount, sufficientFundsObjectCode, sfBalances);
622:                return false;
623:            }
624:
625:            /**
626:             * Purge the sufficient funds balance table by year/chart
627:             * 
628:             * @param chart the chart of sufficient fund balances to purge
629:             * @param year the fiscal year of sufficient fund balances to purge
630:             */
631:            public void purgeYearByChart(String chart, int year) {
632:                LOG.debug("setAccountService() started");
633:                sufficientFundsDao.purgeYearByChart(chart, year);
634:            }
635:
636:            public void setAccountService(AccountService accountService) {
637:                this .accountService = accountService;
638:            }
639:
640:            public void setGeneralLedgerPendingEntryService(
641:                    GeneralLedgerPendingEntryService generalLedgerPendingEntryService) {
642:                this .generalLedgerPendingEntryService = generalLedgerPendingEntryService;
643:            }
644:
645:            public void setKualiConfigurationService(
646:                    KualiConfigurationService kualiConfigurationService) {
647:                this .kualiConfigurationService = kualiConfigurationService;
648:            }
649:
650:            public void setObjectLevelService(
651:                    ObjectLevelService objectLevelService) {
652:                this .objectLevelService = objectLevelService;
653:            }
654:
655:            public void setOptionsService(OptionsService optionsService) {
656:                this .optionsService = optionsService;
657:            }
658:
659:            public void setSufficientFundBalancesDao(
660:                    SufficientFundBalancesDao sufficientFundBalancesDao) {
661:                this .sufficientFundBalancesDao = sufficientFundBalancesDao;
662:            }
663:
664:            public void setSufficientFundsDao(
665:                    SufficientFundsDao sufficientFundsDao) {
666:                this .sufficientFundsDao = sufficientFundsDao;
667:            }
668:
669:            public void setSufficientFundRebuildService(
670:                    SufficientFundRebuildService sufficientFundRebuildService) {
671:                this.sufficientFundRebuildService = sufficientFundRebuildService;
672:            }
673:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.