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.dao.ojb;
017:
018: import java.util.Iterator;
019: import java.util.List;
020:
021: import org.apache.ojb.broker.query.Criteria;
022: import org.apache.ojb.broker.query.QueryByCriteria;
023: import org.apache.ojb.broker.query.QueryFactory;
024: import org.apache.ojb.broker.query.ReportQueryByCriteria;
025: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
026: import org.kuali.core.util.KualiDecimal;
027: import org.kuali.core.util.TransactionalServiceUtils;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.KFSPropertyConstants;
030: import org.kuali.kfs.bo.GeneralLedgerPendingEntry;
031: import org.kuali.module.gl.bo.SufficientFundBalances;
032: import org.kuali.module.gl.dao.SufficientFundsDao;
033:
034: /**
035: * An OJB implementation of SufficientFundsDao
036: */
037: public class SufficientFundsDaoOjb extends PlatformAwareDaoBaseOjb
038: implements SufficientFundsDao {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(SufficientFundsDaoOjb.class);
041:
042: private static final String YEAR_END_DOC_PREFIX = "YE%";
043:
044: /**
045: * Constructs a SufficientFundsDaoOjb instance
046: */
047: public SufficientFundsDaoOjb() {
048: }
049:
050: /**
051: * Calculate the Prior Fiscal Year Budget total
052: *
053: * @param universityFiscalYear the university fiscal year of sufficient funds balances that will be summarized
054: * @param chartOfAccountCode the chart of accounts code of sufficient fund balance records that will be summarized
055: * @param accountNumber the account number of sufficient fund balances that will be summarized
056: * @return the sum of the prior fiscal year budget
057: * @see org.kuali.module.gl.dao.SufficientFundsDao#calculateM113PfyrBudget(java.lang.Integer, java.lang.String,
058: * java.lang.String)
059: */
060: public KualiDecimal calculateM113PfyrBudget(
061: Integer universityFiscalYear, String chartOfAccountsCode,
062: String accountNumber) {
063: Criteria criteria = new Criteria();
064: criteria.addEqualTo(
065: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
066: new Integer(universityFiscalYear.intValue() - 1));
067: criteria.addEqualTo(
068: KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME,
069: chartOfAccountsCode);
070: criteria.addEqualTo(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME,
071: accountNumber);
072: criteria
073: .addEqualTo(
074: KFSConstants.ACCOUNT_SUFFICIENT_FUNDS_CODE_PROPERTY_NAME,
075: KFSConstants.SF_TYPE_CASH_AT_ACCOUNT);
076:
077: ReportQueryByCriteria reportQuery = QueryFactory
078: .newReportQuery(SufficientFundBalances.class, criteria);
079: reportQuery
080: .setAttributes(new String[] { KFSConstants.CURRENT_BUDGET_BALANCE_AMOUNT_PROPERTY_NAME });
081:
082: return executeReportQuery(reportQuery);
083: }
084:
085: /**
086: * Calculate the prior fiscal year encumbrance total
087: *
088: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
089: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
090: * @param accountNumber the account number of sufficient fund balances to summarize
091: * @return the prior fiscal year encumbrnace total
092: * @see org.kuali.module.gl.dao.SufficientFundsDao#calculateM113PfyrEncum(java.lang.Integer, java.lang.String, java.lang.String)
093: */
094: public KualiDecimal calculateM113PfyrEncum(
095: Integer universityFiscalYear, String chartOfAccountsCode,
096: String accountNumber) {
097: Criteria criteria = new Criteria();
098: criteria.addEqualTo(
099: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
100: new Integer(universityFiscalYear.intValue() - 1));
101: criteria.addEqualTo(
102: KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME,
103: chartOfAccountsCode);
104: criteria.addEqualTo(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME,
105: accountNumber);
106: criteria
107: .addEqualTo(
108: KFSConstants.ACCOUNT_SUFFICIENT_FUNDS_CODE_PROPERTY_NAME,
109: KFSConstants.SF_TYPE_CASH_AT_ACCOUNT);
110:
111: ReportQueryByCriteria reportQuery = QueryFactory
112: .newReportQuery(SufficientFundBalances.class, criteria);
113: reportQuery
114: .setAttributes(new String[] { KFSConstants.ACCOUNT_ENCUMBRANCE_AMOUNT_PROPERTY_NAME });
115:
116: return executeReportQuery(reportQuery);
117: }
118:
119: /**
120: * Calculate the prior fiscal year pending actual amount
121: *
122: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
123: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
124: * @param accountNumber the account number of sufficient fund balances to summarize
125: * @param specialFinancialObjectCodes this actually doesn't seem to be used
126: * @param financialObjectCodeForCashInBank the object code for cash in the bank
127: * @return the prior fiscal year pending actual amount
128: * @see org.kuali.module.gl.dao.SufficientFundsDao#calculateM113PendActual(boolean, java.lang.Integer, java.lang.String,
129: * java.lang.String, List, String)
130: */
131: public KualiDecimal calculateM113PendActual(
132: boolean financialBeginBalanceLoadInd,
133: Integer universityFiscalYear, String chartOfAccountsCode,
134: String accountNumber, List specialFinancialObjectCodes,
135: String financialObjectCodeForCashInBank) {
136: // fp_sasfc:61-2...78-3 m113 calculate pendActual
137: KualiDecimal pendActual = calculateM113PendActual1(
138: financialBeginBalanceLoadInd, universityFiscalYear,
139: chartOfAccountsCode, accountNumber, true,
140: financialObjectCodeForCashInBank);
141: pendActual = pendActual.subtract(calculateM113PendActual1(
142: financialBeginBalanceLoadInd, universityFiscalYear,
143: chartOfAccountsCode, accountNumber, false,
144: financialObjectCodeForCashInBank));
145: pendActual = pendActual.add(calculateM113PendActual2(
146: financialBeginBalanceLoadInd, universityFiscalYear,
147: chartOfAccountsCode, accountNumber, false,
148: specialFinancialObjectCodes));
149: pendActual = pendActual.subtract(calculateM113PendActual2(
150: financialBeginBalanceLoadInd, universityFiscalYear,
151: chartOfAccountsCode, accountNumber, true,
152: specialFinancialObjectCodes));
153:
154: return pendActual;
155:
156: }
157:
158: /**
159: * Calculates the current pending actual
160: *
161: * @param isYearEndDocument should year end documents be included?
162: * @param actualFinancialBalanceTypeCd the actual balance type code
163: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
164: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
165: * @param accountNumber the account number of sufficient fund balances to summarize
166: * @param acctSufficientFundsFinObjCd the object code for sufficient funds
167: * @param expenditureCodes object codes that represent expenditures
168: * @return the current pending actual total
169: * @see org.kuali.module.gl.dao.SufficientFundsDao#calculatePendActual(boolean, java.lang.String, java.lang.Integer,
170: * java.lang.String, java.lang.String, java.lang.String, List)
171: */
172: public KualiDecimal calculatePendActual(boolean isYearEndDocument,
173: String actualFinancialBalanceTypeCd,
174: Integer universityFiscalYear, String chartOfAccountsCode,
175: String accountNumber, String acctSufficientFundsFinObjCd,
176: List expenditureCodes) {
177: KualiDecimal pendActual = calculatePendActual1(
178: isYearEndDocument, actualFinancialBalanceTypeCd,
179: universityFiscalYear, chartOfAccountsCode,
180: accountNumber, acctSufficientFundsFinObjCd, true,
181: expenditureCodes);
182: pendActual = pendActual.subtract(calculatePendActual1(
183: isYearEndDocument, actualFinancialBalanceTypeCd,
184: universityFiscalYear, chartOfAccountsCode,
185: accountNumber, acctSufficientFundsFinObjCd, false,
186: expenditureCodes));
187: return pendActual;
188: }
189:
190: /**
191: * calculates the current year pending budget total
192: *
193: * @param isYearEndDocument should year end documents be included?
194: * @param budgetCheckingBalanceTypeCd the budget balance type code
195: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
196: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
197: * @param accountNumber the account number of sufficient fund balances to summarize
198: * @param acctSufficientFundsFinObjCd the object code for sufficient funds
199: * @param expenditureCodes object codes that represent expenditures
200: * @return calculates the current year pending budget total
201: * @see org.kuali.module.gl.dao.SufficientFundsDao#calculatePendBudget(boolean, java.lang.String, java.lang.Integer,
202: * java.lang.String, java.lang.String, java.lang.String, List)
203: */
204: public KualiDecimal calculatePendBudget(boolean isYearEndDocument,
205: String budgetCheckingBalanceTypeCd,
206: Integer universityFiscalYear, String chartOfAccountsCode,
207: String accountNumber, String acctSufficientFundsFinObjCd,
208: List expenditureCodes) {
209: Criteria criteria = new Criteria();
210: criteria.addEqualTo(
211: KFSConstants.FINANCIAL_BALANCE_TYPE_CODE_PROPERTY_NAME,
212: budgetCheckingBalanceTypeCd);
213: criteria.addEqualTo(
214: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
215: universityFiscalYear);
216: criteria.addEqualTo(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME,
217: accountNumber);
218: criteria.addIn(KFSConstants.FINANCIAL_OBJECT_TYPE_CODE,
219: expenditureCodes);
220: criteria
221: .addEqualTo(
222: KFSConstants.ACCOUNT_SUFFICIENT_FUNDS_FINANCIAL_OBJECT_CODE_PROPERTY_NAME,
223: acctSufficientFundsFinObjCd);
224: criteria
225: .addNotEqualTo(
226: KFSConstants.DOCUMENT_HEADER_PROPERTY_NAME
227: + "."
228: + KFSConstants.DOCUMENT_HEADER_DOCUMENT_STATUS_CODE_PROPERTY_NAME,
229: KFSConstants.DocumentStatusCodes.CANCELLED);
230:
231: if (isYearEndDocument) {
232: criteria.addLike(KFSConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
233: YEAR_END_DOC_PREFIX);
234: } else {
235: criteria.addNotLike(
236: KFSConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
237: YEAR_END_DOC_PREFIX);
238: }
239:
240: ReportQueryByCriteria reportQuery = QueryFactory
241: .newReportQuery(GeneralLedgerPendingEntry.class,
242: criteria);
243: reportQuery.setAttributes(new String[] { "sum("
244: + KFSConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
245:
246: return executeReportQuery(reportQuery);
247:
248: }
249:
250: /**
251: * Calculates the current year pending encumbrance total
252: *
253: * @param isYearEndDocument should year end documents be included?
254: * @param extrnlEncumFinBalanceTypCd the external encumbrance balance type
255: * @param intrnlEncumFinBalanceTypCd the internal encumbrance balance type
256: * @param preencumbranceFinBalTypeCd the pre-encumbrance balance type
257: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
258: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
259: * @param accountNumber the account number of sufficient fund balances to summarize
260: * @param acctSufficientFundsFinObjCd the object code for sufficient funds
261: * @param expenditureCodes object codes that represent expenditures
262: * @return the current year pending encumbrance total
263: * @see org.kuali.module.gl.dao.SufficientFundsDao#calculatePendEncum(boolean, java.lang.String, java.lang.String,
264: * java.lang.String, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String, List)
265: */
266: public KualiDecimal calculatePendEncum(boolean isYearEndDocument,
267: String extrnlEncumFinBalanceTypCd,
268: String intrnlEncumFinBalanceTypCd,
269: String preencumbranceFinBalTypeCd,
270: Integer universityFiscalYear, String chartOfAccountsCode,
271: String accountNumber, String acctSufficientFundsFinObjCd,
272: List expenditureCodes) {
273: KualiDecimal pendEncum = calculatePendEncum1(isYearEndDocument,
274: extrnlEncumFinBalanceTypCd, intrnlEncumFinBalanceTypCd,
275: preencumbranceFinBalTypeCd, universityFiscalYear,
276: chartOfAccountsCode, accountNumber,
277: acctSufficientFundsFinObjCd, true, expenditureCodes);
278: pendEncum = pendEncum.subtract(calculatePendEncum1(
279: isYearEndDocument, extrnlEncumFinBalanceTypCd,
280: intrnlEncumFinBalanceTypCd, preencumbranceFinBalTypeCd,
281: universityFiscalYear, chartOfAccountsCode,
282: accountNumber, acctSufficientFundsFinObjCd, false,
283: expenditureCodes));
284: return pendEncum;
285: }
286:
287: /**
288: * Calcluate this part of the encumbrance total
289: *
290: * @param isYearEndDocument should year end documents be included?
291: * @param extrnlEncumFinBalanceTypCd the external encumbrance balance type
292: * @param intrnlEncumFinBalanceTypCd the internal encumbrance balance type
293: * @param preencumbranceFinBalTypeCd the pre-encumbrance balance type
294: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
295: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
296: * @param accountNumber the account number of sufficient fund balances to summarize
297: * @param acctSufficientFundsFinObjCd the object code for sufficient funds
298: * @param isEqualDebitCode should debits be included in the calculation or not
299: * @return this part of the encumbrance total
300: */
301: KualiDecimal calculatePendEncum1(boolean isYearEndDocument,
302: String extrnlEncumFinBalanceTypCd,
303: String intrnlEncumFinBalanceTypCd,
304: String preencumbranceFinBalTypeCd,
305: Integer universityFiscalYear, String chartOfAccountsCode,
306: String accountNumber, String acctSufficientFundsFinObjCd,
307: boolean isEqualDebitCode, List expenditureCodes) {
308: Criteria criteria = new Criteria();
309:
310: Criteria sub1 = new Criteria();
311: sub1.addEqualTo(
312: KFSConstants.FINANCIAL_BALANCE_TYPE_CODE_PROPERTY_NAME,
313: extrnlEncumFinBalanceTypCd);
314: Criteria sub1_1 = new Criteria();
315: sub1_1.addEqualTo(
316: KFSConstants.FINANCIAL_BALANCE_TYPE_CODE_PROPERTY_NAME,
317: intrnlEncumFinBalanceTypCd);
318: Criteria sub1_2 = new Criteria();
319: sub1_2.addEqualTo(
320: KFSConstants.FINANCIAL_BALANCE_TYPE_CODE_PROPERTY_NAME,
321: preencumbranceFinBalTypeCd);
322: sub1_1.addOrCriteria(sub1_2);
323: sub1.addOrCriteria(sub1_1);
324: criteria.addOrCriteria(sub1);
325:
326: criteria.addEqualTo(
327: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
328: universityFiscalYear);
329: criteria.addEqualTo(
330: KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME,
331: chartOfAccountsCode);
332: criteria.addEqualTo(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME,
333: accountNumber);
334: criteria
335: .addEqualTo(
336: KFSConstants.ACCOUNT_SUFFICIENT_FUNDS_FINANCIAL_OBJECT_CODE_PROPERTY_NAME,
337: acctSufficientFundsFinObjCd);
338: criteria.addIn(KFSConstants.FINANCIAL_OBJECT_TYPE_CODE,
339: expenditureCodes);
340:
341: if (isEqualDebitCode) {
342: criteria.addEqualTo(
343: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
344: KFSConstants.GL_DEBIT_CODE);
345: } else {
346: criteria.addNotEqualTo(
347: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
348: KFSConstants.GL_DEBIT_CODE);
349: }
350:
351: criteria
352: .addNotEqualTo(
353: KFSConstants.DOCUMENT_HEADER_PROPERTY_NAME
354: + "."
355: + KFSConstants.DOCUMENT_HEADER_DOCUMENT_STATUS_CODE_PROPERTY_NAME,
356: KFSConstants.DocumentStatusCodes.CANCELLED);
357:
358: if (isYearEndDocument) {
359: criteria.addLike(KFSConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
360: YEAR_END_DOC_PREFIX);
361: } else {
362: criteria.addNotLike(
363: KFSConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
364: YEAR_END_DOC_PREFIX);
365: }
366:
367: ReportQueryByCriteria reportQuery = QueryFactory
368: .newReportQuery(GeneralLedgerPendingEntry.class,
369: criteria);
370: reportQuery.setAttributes(new String[] { "sum("
371: + KFSConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
372:
373: return executeReportQuery(reportQuery);
374:
375: }
376:
377: /**
378: * Calculate this part of the actual total
379: *
380: * @param isYearEndDocument should year end documents be included?
381: * @param actualFinancialBalanceTypeCd the actual balance type code
382: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
383: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
384: * @param accountNumber the account number of sufficient fund balances to summarize
385: * @param acctSufficientFundsFinObjCd the object code for sufficient funds
386: * @return this part of the actual total
387: */
388: KualiDecimal calculatePendActual1(boolean isYearEndDocument,
389: String actualFinancialBalanceTypeCd,
390: Integer universityFiscalYear, String chartOfAccountsCode,
391: String accountNumber, String acctSufficientFundsFinObjCd,
392: boolean isEqualDebitCode, List expenditureCodes) {
393: Criteria criteria = new Criteria();
394: criteria.addEqualTo(
395: KFSConstants.FINANCIAL_BALANCE_TYPE_CODE_PROPERTY_NAME,
396: actualFinancialBalanceTypeCd);
397: criteria.addEqualTo(
398: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
399: universityFiscalYear);
400: criteria.addEqualTo(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME,
401: accountNumber);
402: criteria
403: .addEqualTo(
404: KFSConstants.ACCOUNT_SUFFICIENT_FUNDS_FINANCIAL_OBJECT_CODE_PROPERTY_NAME,
405: acctSufficientFundsFinObjCd);
406: criteria.addIn(KFSConstants.FINANCIAL_OBJECT_TYPE_CODE,
407: expenditureCodes);
408:
409: if (isEqualDebitCode) {
410: criteria.addEqualTo(
411: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
412: KFSConstants.GL_DEBIT_CODE);
413: } else {
414: criteria.addNotEqualTo(
415: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
416: KFSConstants.GL_DEBIT_CODE);
417: }
418:
419: criteria
420: .addNotEqualTo(
421: KFSConstants.DOCUMENT_HEADER_PROPERTY_NAME
422: + "."
423: + KFSConstants.DOCUMENT_HEADER_DOCUMENT_STATUS_CODE_PROPERTY_NAME,
424: KFSConstants.DocumentStatusCodes.CANCELLED);
425:
426: if (isYearEndDocument) {
427: criteria.addLike(KFSConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
428: YEAR_END_DOC_PREFIX);
429: } else {
430: criteria.addNotLike(
431: KFSConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
432: YEAR_END_DOC_PREFIX);
433: }
434:
435: ReportQueryByCriteria reportQuery = QueryFactory
436: .newReportQuery(GeneralLedgerPendingEntry.class,
437: criteria);
438: reportQuery.setAttributes(new String[] { "sum("
439: + KFSConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
440: return executeReportQuery(reportQuery);
441: }
442:
443: /**
444: * calculate part of the actual total
445: *
446: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
447: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
448: * @param accountNumber the account number of sufficient fund balances to summarize
449: * @return thsi part of the actual total
450: */
451: KualiDecimal calculateM113PendActual1(
452: boolean financialBeginBalanceLoadInd,
453: Integer universityFiscalYear, String chartOfAccountsCode,
454: String accountNumber, boolean isEqualDebitCode,
455: String financialObjectCodeForCashInBank) {
456: Criteria criteria = new Criteria();
457: criteria.addEqualTo(
458: KFSConstants.FINANCIAL_BALANCE_TYPE_CODE_PROPERTY_NAME,
459: KFSConstants.BALANCE_TYPE_ACTUAL);
460:
461: if (financialBeginBalanceLoadInd) {
462: criteria.addEqualTo(
463: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
464: universityFiscalYear);
465: } else {
466: Criteria sub1 = new Criteria();
467: sub1.addEqualTo(
468: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
469: universityFiscalYear);
470: Criteria sub1_1 = new Criteria();
471: sub1_1.addEqualTo(
472: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
473: new Integer(universityFiscalYear.intValue() - 1));
474: sub1.addOrCriteria(sub1_1);
475: criteria.addAndCriteria(sub1);
476: }
477:
478: criteria.addEqualTo(
479: KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME,
480: chartOfAccountsCode);
481: criteria.addEqualTo(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME,
482: accountNumber);
483: criteria.addEqualTo(
484: KFSConstants.FINANCIAL_OBJECT_CODE_PROPERTY_NAME,
485: financialObjectCodeForCashInBank);
486:
487: if (isEqualDebitCode) {
488: criteria.addEqualTo(
489: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
490: KFSConstants.GL_DEBIT_CODE);
491: } else {
492: criteria.addNotEqualTo(
493: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
494: KFSConstants.GL_DEBIT_CODE);
495: }
496:
497: criteria
498: .addNotEqualTo(
499: KFSConstants.DOCUMENT_HEADER_PROPERTY_NAME
500: + "."
501: + KFSConstants.DOCUMENT_HEADER_DOCUMENT_STATUS_CODE_PROPERTY_NAME,
502: KFSConstants.DocumentStatusCodes.CANCELLED);
503:
504: ReportQueryByCriteria reportQuery = QueryFactory
505: .newReportQuery(GeneralLedgerPendingEntry.class,
506: criteria);
507: reportQuery.setAttributes(new String[] { "sum("
508: + KFSConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
509:
510: return executeReportQuery(reportQuery);
511: }
512:
513: /**
514: * Calculate part of the actual total
515: *
516: * @param universityFiscalYear the university fiscal year of sufficient funds balances to summarize
517: * @param chartOfAccountsCode the chart of accounts code of sufficient funds balances to summarize
518: * @param accountNumber the account number of sufficient fund balances to summarize
519: * @param isEqualDebitCode should this query be returning debits or not?
520: * @param specialFinancialObjectCodes include only these financial object codes
521: * @return this part of the actual total
522: */
523: KualiDecimal calculateM113PendActual2(
524: boolean financialBeginBalanceLoadInd,
525: Integer universityFiscalYear, String chartOfAccountsCode,
526: String accountNumber, boolean isEqualDebitCode,
527: List specialFinancialObjectCodes) {
528: Criteria criteria = new Criteria();
529: criteria.addEqualTo(
530: KFSConstants.FINANCIAL_BALANCE_TYPE_CODE_PROPERTY_NAME,
531: KFSConstants.BALANCE_TYPE_ACTUAL);
532:
533: if (financialBeginBalanceLoadInd) {
534: criteria.addEqualTo(
535: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
536: universityFiscalYear);
537: } else {
538: Criteria sub1 = new Criteria();
539: sub1.addEqualTo(
540: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
541: universityFiscalYear);
542: Criteria sub1_1 = new Criteria();
543: sub1_1.addEqualTo(
544: KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME,
545: new Integer(universityFiscalYear.intValue() - 1));
546: sub1.addOrCriteria(sub1_1);
547: criteria.addAndCriteria(sub1);
548: }
549:
550: criteria.addEqualTo(
551: KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME,
552: chartOfAccountsCode);
553: criteria.addEqualTo(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME,
554: accountNumber);
555: criteria.addIn(
556: KFSConstants.FINANCIAL_OBJECT_CODE_PROPERTY_NAME,
557: specialFinancialObjectCodes);
558:
559: if (isEqualDebitCode) {
560: criteria.addEqualTo(
561: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
562: KFSConstants.GL_DEBIT_CODE);
563: } else {
564: criteria.addNotEqualTo(
565: KFSConstants.TRANSACTION_DEBIT_CREDIT_CODE,
566: KFSConstants.GL_DEBIT_CODE);
567: }
568:
569: criteria
570: .addNotEqualTo(
571: KFSConstants.DOCUMENT_HEADER_PROPERTY_NAME
572: + "."
573: + KFSConstants.DOCUMENT_HEADER_DOCUMENT_STATUS_CODE_PROPERTY_NAME,
574: KFSConstants.DocumentStatusCodes.CANCELLED);
575:
576: ReportQueryByCriteria reportQuery = QueryFactory
577: .newReportQuery(GeneralLedgerPendingEntry.class,
578: criteria);
579: reportQuery.setAttributes(new String[] { "sum("
580: + KFSConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
581:
582: return executeReportQuery(reportQuery);
583: }
584:
585: /**
586: * Purge table by year/chart
587: *
588: * @param chart the chart of sufficient fund balances to purge
589: * @param year the year of sufficient fund balances to purge
590: */
591: public void purgeYearByChart(String chartOfAccountsCode, int year) {
592: LOG.debug("purgeYearByChart() started");
593:
594: Criteria criteria = new Criteria();
595: criteria.addEqualTo(
596: KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
597: chartOfAccountsCode);
598: criteria.addLessThan(
599: KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
600: new Integer(year));
601:
602: getPersistenceBrokerTemplate().deleteByQuery(
603: new QueryByCriteria(SufficientFundBalances.class,
604: criteria));
605:
606: // This is required because if any deleted account balances are in the cache, deleteByQuery doesn't
607: // remove them from the cache so a future select will retrieve these deleted account balances from
608: // the cache and return them. Clearing the cache forces OJB to go to the database again.
609: getPersistenceBrokerTemplate().clearCache();
610: }
611:
612: /**
613: * This returns the very first value returned by a report query and then makes certain that OJB closes the
614: * connection that retrieved the query data
615: *
616: * @param reportQuery the ReportQuery to find the first value for
617: * @return the first value generated from the given query
618: */
619: private KualiDecimal executeReportQuery(
620: ReportQueryByCriteria reportQuery) {
621: Iterator iterator = getPersistenceBrokerTemplate()
622: .getReportQueryIteratorByQuery(reportQuery);
623: if (iterator.hasNext()) {
624: KualiDecimal returnResult = (KualiDecimal) ((Object[]) TransactionalServiceUtils
625: .retrieveFirstAndExhaustIterator(iterator))[0];
626: return returnResult;
627: } else {
628: return KualiDecimal.ZERO;
629: }
630: }
631: }
|