001: /*
002: * Copyright 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.pdp.service.impl;
017:
018: import java.sql.Timestamp;
019: import java.util.ArrayList;
020: import java.util.Collections;
021: import java.util.Date;
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.apache.commons.lang.builder.EqualsBuilder;
028: import org.apache.commons.lang.builder.HashCodeBuilder;
029: import org.apache.commons.lang.builder.ToStringBuilder;
030: import org.kuali.core.bo.Parameter;
031: import org.kuali.core.service.BusinessObjectService;
032: import org.kuali.kfs.service.ParameterService;
033: import org.kuali.kfs.service.SchedulerService;
034: import org.kuali.kfs.service.impl.ParameterConstants;
035: import org.kuali.module.pdp.PdpConstants;
036: import org.kuali.module.pdp.bo.AchAccountNumber;
037: import org.kuali.module.pdp.bo.Bank;
038: import org.kuali.module.pdp.bo.CustomerBank;
039: import org.kuali.module.pdp.bo.CustomerProfile;
040: import org.kuali.module.pdp.bo.DisbursementNumberRange;
041: import org.kuali.module.pdp.bo.DisbursementType;
042: import org.kuali.module.pdp.bo.FormatProcess;
043: import org.kuali.module.pdp.bo.PaymentDetail;
044: import org.kuali.module.pdp.bo.PaymentGroup;
045: import org.kuali.module.pdp.bo.PaymentProcess;
046: import org.kuali.module.pdp.bo.PaymentStatus;
047: import org.kuali.module.pdp.bo.PdpUser;
048: import org.kuali.module.pdp.bo.ProcessSummary;
049: import org.kuali.module.pdp.dao.CustomerProfileDao;
050: import org.kuali.module.pdp.dao.DisbursementNumberRangeDao;
051: import org.kuali.module.pdp.dao.FormatPaymentDao;
052: import org.kuali.module.pdp.dao.FormatProcessDao;
053: import org.kuali.module.pdp.dao.PaymentDetailDao;
054: import org.kuali.module.pdp.dao.PaymentGroupDao;
055: import org.kuali.module.pdp.dao.ProcessDao;
056: import org.kuali.module.pdp.dao.ProcessSummaryDao;
057: import org.kuali.module.pdp.exception.ConfigurationError;
058: import org.kuali.module.pdp.service.AchInformation;
059: import org.kuali.module.pdp.service.AchService;
060: import org.kuali.module.pdp.service.DisbursementRangeExhaustedException;
061: import org.kuali.module.pdp.service.FormatResult;
062: import org.kuali.module.pdp.service.FormatSelection;
063: import org.kuali.module.pdp.service.FormatService;
064: import org.kuali.module.pdp.service.GlPendingTransactionService;
065: import org.kuali.module.pdp.service.MissingDisbursementRangeException;
066: import org.kuali.module.pdp.service.NoBankForCustomerException;
067: import org.kuali.module.pdp.service.ReferenceService;
068: import org.kuali.module.pdp.utilities.GeneralUtilities;
069: import org.springframework.transaction.annotation.Transactional;
070:
071: @Transactional
072: public class FormatServiceImpl implements FormatService {
073: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
074: .getLogger(FormatServiceImpl.class);
075:
076: private CustomerProfileDao customerProfileDao;
077: private DisbursementNumberRangeDao disbursementNumberRangeDao;
078: private FormatProcessDao formatProcessDao;
079: private PaymentDetailDao paymentDetailDao;
080: private PaymentGroupDao paymentGroupDao;
081: private ProcessSummaryDao processSummaryDao;
082: private ProcessDao processDao;
083: private AchService achService;
084: private ReferenceService referenceService;
085: private GlPendingTransactionService glPendingTransactionService;
086: private ParameterService parameterService;
087: private FormatPaymentDao formatPaymentDao;
088: private SchedulerService schedulerService;
089: private BusinessObjectService businessObjectService;
090:
091: public FormatServiceImpl() {
092: super ();
093: }
094:
095: /**
096: * @see org.kuali.module.pdp.service.FormatService#formatSelectionAction(org.kuali.module.pdp.bo.PdpUser, boolean)
097: */
098: public FormatSelection formatSelectionAction(PdpUser user,
099: boolean clearFormat) {
100: LOG.debug("formatSelectionAction() started");
101:
102: FormatSelection fs = new FormatSelection();
103:
104: fs.setCampus(user.getUniversalUser().getCampusCode());
105:
106: Date startDate = getFormatProcessStartDate(fs.getCampus());
107:
108: // If they want to clear the flag, do it
109: if ((startDate != null) && clearFormat) {
110: startDate = null;
111: endFormatProcess(fs.getCampus());
112: }
113: fs.setStartDate(startDate);
114:
115: if (startDate == null) {
116: fs.setCustomerList(getAllCustomerProfiles());
117: fs.setRangeList(getAllDisbursementNumberRanges());
118: }
119: return fs;
120: }
121:
122: public Date getFormatProcessStartDate(String campus) {
123: LOG.debug("getFormatProcessStartDate() started");
124:
125: FormatProcess fp = formatProcessDao.getByCampus(campus);
126: if (fp != null) {
127: LOG.debug("getFormatProcessStartDate() found");
128: return new Date(fp.getBeginFormat().getTime());
129: } else {
130: LOG.debug("getFormatProcessStartDate() not found");
131: return null;
132: }
133: }
134:
135: private int getMaxNoteLines() {
136: return GeneralUtilities.getParameterInteger(parameterService,
137: ParameterConstants.PRE_DISBURSEMENT_ALL.class,
138: PdpConstants.ApplicationParameterKeys.MAX_NOTE_LINES);
139: }
140:
141: private int getFormatSummaryListSize() {
142: return GeneralUtilities
143: .getParameterInteger(
144: parameterService,
145: ParameterConstants.PRE_DISBURSEMENT_LOOKUP.class,
146: PdpConstants.ApplicationParameterKeys.FORMAT_SUMMARY_ROWS,
147: 40);
148: }
149:
150: public List performFormat(Integer procId) {
151: LOG.debug("performFormat() started");
152:
153: PaymentProcess proc = processDao.get(procId);
154: if (proc == null) {
155: LOG.error("performFormat() Invalid proc ID " + procId);
156: throw new ConfigurationError("Invalid proc ID");
157: }
158: Map disbursementTypes = referenceService
159: .getallMap("DisbursementType");
160: Map paymentStatusCodes = referenceService
161: .getallMap("PaymentStatus");
162:
163: DisbursementType checkDisbursementType = (DisbursementType) disbursementTypes
164: .get("CHCK");
165: DisbursementType achDisbursementType = (DisbursementType) disbursementTypes
166: .get("ACH");
167:
168: int maxNoteLines = getMaxNoteLines();
169:
170: // Step one, get ACH or Check, Bank info, ACH info, sorting
171: Iterator groups = paymentGroupDao.getByProcess(proc);
172:
173: PostFormatProcessSummary fps = new PostFormatProcessSummary();
174: CustomerProfile customer = null;
175: Bank checkBank = null;
176: Bank achBank = null;
177:
178: while (groups.hasNext()) {
179: PaymentGroup pg = (PaymentGroup) groups.next();
180: LOG.debug("performFormat() Step 1 Payment Group ID "
181: + pg.getId());
182:
183: // Set the sort field to be saved in the database
184: pg.setSortValue(pg.getFormatSortField());
185:
186: if ((customer == null)
187: || (!customer.equals(pg.getBatch()
188: .getCustomerProfile()))) {
189: customer = pg.getBatch().getCustomerProfile();
190: CustomerBank cb = customer
191: .getCustomerBankByDisbursementType("CHCK");
192: if (cb != null) {
193: checkBank = cb.getBank();
194: }
195:
196: cb = customer.getCustomerBankByDisbursementType("ACH");
197: if (cb != null) {
198: achBank = cb.getBank();
199: }
200: }
201:
202: pg.setDisbursementDate(proc.getProcessTimestamp());
203: pg.setPhysCampusProcessCd(proc.getCampus());
204: pg.setProcess(proc);
205:
206: // Do we do ACH for this person?
207: AchInformation ai = null;
208: boolean check = true;
209: boolean noNegativeDetails = true;
210:
211: // If any one of the payment details in the group are negative, we always force a check
212: for (Iterator it = pg.getPaymentDetails().iterator(); it
213: .hasNext();) {
214: PaymentDetail pd = (PaymentDetail) it.next();
215: if (pd.getNetPaymentAmount().doubleValue() < 0) {
216: LOG.debug("performFormat() Payment Group " + pg
217: + " has payment detail net payment amount "
218: + pd.getNetPaymentAmount());
219: LOG
220: .debug("performFormat() Forcing a Check for Group");
221: noNegativeDetails = false;
222: break;
223: }
224: }
225:
226: // Attachments, Process Immediate & Special Handling are always checks
227: // If there isn't a PSD Transaction code for the customer, don't even look to see if any payment is ACH
228: // If the payment ID is X, it's always a check
229: // If any one of the payment details in the group are negative, we always force a check
230: if ((!"X".equals(pg.getPayeeIdTypeCd()))
231: && (!"".equals(pg.getPayeeIdTypeCd()))
232: && (pg.getPayeeIdTypeCd() != null)
233: && (!"".equals(pg.getPayeeId()))
234: && (pg.getPayeeId() != null)
235: && (!pg.getPymtAttachment().booleanValue())
236: && (!pg.getProcessImmediate().booleanValue())
237: && (!pg.getPymtSpecialHandling().booleanValue())
238: && (customer.getPsdTransactionCode() != null)
239: && (noNegativeDetails)) {
240: // Check ACH service
241: LOG.debug("performFormat() Checking ACH");
242: ai = achService.getAchInformation(
243: pg.getPayeeIdTypeCd(), pg.getPayeeId(),
244: customer.getPsdTransactionCode());
245: check = (ai == null);
246: }
247:
248: if (check) {
249: PaymentStatus ps = (PaymentStatus) paymentStatusCodes
250: .get("EXTR");
251: LOG.debug("performFormat() Check: " + ps);
252: pg.setDisbursementType(checkDisbursementType);
253: pg.setPaymentStatus(ps);
254: if (checkBank == null) {
255: LOG
256: .error("performFormat() A bank is needed for CHCK for customer: "
257: + customer);
258: throw new NoBankForCustomerException(
259: "A bank is needed for CHCK for customer: "
260: + customer, customer.getChartCode()
261: + "-" + customer.getOrgCode() + "-"
262: + customer.getSubUnitCode());
263: }
264: pg.setBank(checkBank);
265: } else {
266: PaymentStatus ps = (PaymentStatus) paymentStatusCodes
267: .get("PACH");
268: LOG.debug("performFormat() ACH: " + ps);
269: pg.setDisbursementType(achDisbursementType);
270: pg.setPaymentStatus(ps);
271: if (achBank == null) {
272: LOG
273: .error("performFormat() A bank is needed for ACH for customer: "
274: + customer);
275: throw new NoBankForCustomerException(
276: "A bank is needed for ACH for customer: "
277: + customer, customer.getChartCode()
278: + "-" + customer.getOrgCode() + "-"
279: + customer.getSubUnitCode());
280: }
281: pg.setBank(achBank);
282:
283: pg.setAchBankRoutingNbr(ai.getAchBankRoutingNbr());
284: pg.setAdviceEmailAddress(ai.getAdviceEmailAddress());
285: pg.setAchAccountType(ai.getAchAccountType());
286:
287: AchAccountNumber aan = new AchAccountNumber();
288: aan.setAchBankAccountNbr(ai.getAchBankAccountNbr());
289: aan.setId(pg.getId());
290: pg.setAchAccountNumber(aan);
291: }
292:
293: paymentGroupDao.save(pg);
294:
295: // Add to summary information
296: fps.add(pg);
297: }
298:
299: // step 2 figure out if we combine checks into one
300: LOG.debug("performFormat() Combining");
301:
302: PaymentInfo lastPaymentInfo = new PaymentInfo();
303: groups = paymentGroupDao.getByProcess(proc);
304:
305: while (groups.hasNext()) {
306: PaymentGroup pg = (PaymentGroup) groups.next();
307:
308: // Only look at checks
309: if (checkDisbursementType.equals(pg.getDisbursementType())) {
310: // Attachments, Special Handling and Immediates don't ever get combined
311: // Also, don't combine if the XML file says not to do so
312: if (pg.getPymtAttachment().booleanValue()
313: || pg.getProcessImmediate().booleanValue()
314: || pg.getPymtSpecialHandling().booleanValue()
315: || (!pg.getCombineGroups().booleanValue())) {
316: // This one doesn't combine with the next one
317: LOG
318: .debug("performFormat() This payment can't combine "
319: + pg.getPymtAttachment()
320: + " "
321: + pg.getProcessImmediate()
322: + " "
323: + pg.getPymtSpecialHandling()
324: + " "
325: + pg.getCombineGroups());
326: lastPaymentInfo = null;
327: } else {
328: PaymentInfo pi = new PaymentInfo();
329: pi.customer = pg.getBatch().getCustomerProfile();
330: pi.line1Address = pg.getLine1Address();
331: pi.payeeName = pg.getPayeeName();
332: pi.noteLines = pg.getNoteLines();
333: pi.payeeId = pg.getPayeeId();
334: pi.payeeIdType = pg.getPayeeIdTypeCd();
335: LOG
336: .debug("performFormat() This payment might combine "
337: + pi);
338:
339: boolean combine = false;
340: if (lastPaymentInfo != null) {
341: if (lastPaymentInfo.equals(pi)) {
342: if (((lastPaymentInfo.noteLines + pi.noteLines) <= maxNoteLines)) {
343: LOG.debug("performFormat() Combining");
344: pg.setDisbursementNbr(new Integer(-1)); // Mark it for later
345: lastPaymentInfo.noteLines += pi.noteLines;
346: combine = true;
347: }
348: }
349: }
350:
351: if (!combine) {
352: LOG.debug("performFormat() Not combining");
353: lastPaymentInfo = pi;
354: }
355: }
356: }
357: }
358:
359: // step 3 now assign disbursement numbers
360: LOG.debug("performFormat() Assigning disbursement numbers");
361: pass2(proc.getCampus(), disbursementTypes, paymentStatusCodes,
362: proc, fps);
363:
364: // step 4 save the summarizing info
365: LOG.debug("performFormat() Save summarizing information");
366: fps.save(processSummaryDao);
367:
368: // step 5 tell the extract batch job to start
369: LOG.debug("performFormat() Start extract batch job");
370: triggerExtract(procId);
371:
372: // step 6 end the format process for this campus
373: LOG
374: .debug("performFormat() End the format process for this campus");
375: endFormatProcess(proc.getCampus());
376:
377: // step 7 return all the process summaries
378: List processSummaryResults = processSummaryDao
379: .getByPaymentProcess(proc);
380: return convertProcessSummary2FormatResult(processSummaryResults);
381: }
382:
383: private void triggerExtract(Integer procId) {
384: LOG.debug("triggerExtract() started");
385:
386: saveProcessId(procId);
387: String emailAddress = parameterService
388: .getParameterValue(
389: ParameterConstants.PRE_DISBURSEMENT_ALL.class,
390: PdpConstants.ApplicationParameterKeys.NO_PAYMENT_FILE_EMAIL);
391: schedulerService.runJob("pdpExtractChecksJob", emailAddress);
392: }
393:
394: private void saveProcessId(Integer id) {
395: Map fields = new HashMap();
396: fields.put("parameterNamespaceCode", "KFS-PD");
397: fields.put("parameterDetailTypeCode", "All");
398: fields
399: .put(
400: "parameterName",
401: PdpConstants.ApplicationParameterKeys.EXTRACT_PROCESS_ID);
402: Parameter processParam = (Parameter) businessObjectService
403: .findByPrimaryKey(Parameter.class, fields);
404: if (processParam == null) {
405: processParam = new Parameter();
406: processParam.setParameterNamespaceCode("KFS-PD");
407: processParam.setParameterDetailTypeCode("All");
408: processParam.setParameterTypeCode("CONFG");
409: processParam
410: .setParameterName(PdpConstants.ApplicationParameterKeys.EXTRACT_PROCESS_ID);
411: processParam.setParameterConstraintCode("A");
412: processParam.setParameterWorkgroupName("KUALI_FMSOPS");
413: }
414: processParam.setParameterValue(id.toString());
415: businessObjectService.save(processParam);
416: }
417:
418: private List convertProcessSummary2FormatResult(
419: List processSummaryResults) {
420: List results = new ArrayList();
421: for (Iterator iter = processSummaryResults.iterator(); iter
422: .hasNext();) {
423: ProcessSummary element = (ProcessSummary) iter.next();
424: FormatResult fr = new FormatResult(element.getProcess()
425: .getId(), element.getCustomer());
426: fr.setSortGroupOverride(element.getSortGroupId());
427: fr.setAmount(element.getProcessTotalAmount());
428: fr.setPayments(element.getProcessTotalCount().intValue());
429: fr.setBeginDisbursementNbr(element
430: .getBeginDisbursementNbr().intValue());
431: fr.setEndDisbursementNbr(element.getEndDisbursementNbr()
432: .intValue());
433: fr.setDisbursementType(element.getDisbursementType());
434: results.add(fr);
435: }
436: Collections.sort(results);
437: return results;
438: }
439:
440: // If the start format process was run and the user doesn't want to continue,
441: // this needs to be run to set all payments back to open
442: public void clearUnfinishedFormat(Integer procId) {
443: LOG.debug("clearUnfinishedFormat() started");
444:
445: PaymentProcess proc = processDao.get(procId);
446: LOG.debug("clearUnfinishedFormat() Process: " + proc);
447:
448: formatPaymentDao.unmarkPaymentsForFormat(proc);
449:
450: endFormatProcess(proc.getCampus());
451: }
452:
453: // If the start format process was run and errored out,
454: // this needs to be run to allow formats to continue to function
455: public void resetFormatPayments(Integer procId) {
456: LOG.debug("resetFormatPayments() started");
457: clearUnfinishedFormat(procId);
458: }
459:
460: // Mark the process log so a format only happens once per campus. Mark all the
461: // payments that will be formatted and return a summary
462: public List startFormatProcess(PdpUser user, String campus,
463: List customers, Date paydate, boolean immediate,
464: String paymentTypes) {
465: LOG.debug("startFormatProcess() started");
466:
467: for (Iterator iter = customers.iterator(); iter.hasNext();) {
468: CustomerProfile element = (CustomerProfile) iter.next();
469: LOG.debug("startFormatProcess() Customer: " + element);
470: }
471:
472: PaymentStatus formatStatus = (PaymentStatus) referenceService
473: .getCode("PaymentStatus",
474: PdpConstants.PaymentStatusCodes.FORMAT);
475:
476: Date now = new Date();
477: formatProcessDao.add(campus, now);
478:
479: // Create the process
480: PaymentProcess p = processDao.createProcess(campus, user);
481:
482: // Mark all of them ready for format
483: formatPaymentDao.markPaymentsForFormat(p, customers, paydate,
484: immediate, paymentTypes);
485:
486: // summarize them
487: PreFormatProcessSummary fps = new PreFormatProcessSummary();
488: Iterator i = paymentGroupDao.getByProcess(p);
489:
490: int count = 0;
491: while (i.hasNext()) {
492: PaymentGroup pg = (PaymentGroup) i.next();
493:
494: count++;
495: fps.add(pg);
496: }
497:
498: if (count == 0) {
499: LOG
500: .debug("startFormatProcess() No payments to process. Format process ending");
501: endFormatProcess(campus);
502: }
503:
504: return convertProcessSummary2FormatResult(fps
505: .getProcessSummaryList());
506: }
507:
508: public void endFormatProcess(String campus) {
509: LOG.debug("endFormatProcess() starting");
510:
511: formatProcessDao.removeByCampus(campus);
512: }
513:
514: public List getAllCustomerProfiles() {
515: LOG.debug("getAllCustomerProfiles() started");
516:
517: return customerProfileDao.getAll();
518: }
519:
520: public List getAllDisbursementNumberRanges() {
521: LOG.debug("getAllDisbursementNumberRanges() started");
522:
523: return disbursementNumberRangeDao.getAll();
524: }
525:
526: // This is the second pass. It determines the
527: // disbursement number and creates GL entries
528: private void pass2(String campus, Map disbursementTypes,
529: Map paymentStatusCodes, PaymentProcess p,
530: PostFormatProcessSummary fps)
531: throws DisbursementRangeExhaustedException,
532: MissingDisbursementRangeException {
533: LOG.debug("pass2() starting");
534:
535: // This is the date used for last update
536: Date now = new Date();
537: Timestamp nowTs = new Timestamp(now.getTime());
538:
539: List disbursementRanges = paymentDetailDao
540: .getDisbursementNumberRanges(campus);
541:
542: int checkNumber = 0;
543:
544: Iterator payGroupIterator = paymentGroupDao.getByProcess(p);
545: while (payGroupIterator.hasNext()) {
546: PaymentGroup pg = (PaymentGroup) payGroupIterator.next();
547: LOG.debug("performFormat() Payment Group ID " + pg.getId());
548:
549: DisbursementNumberRange range = getRange(
550: disbursementRanges, pg.getBank(), now);
551:
552: if (range == null) {
553: String err = "No disbursement range for bankId="
554: + pg.getBank().getId() + ",campusId=" + campus
555: + ",disbursementType="
556: + pg.getBank().getDisbursementType().getCode();
557: LOG.error("pass2() " + err);
558: throw new MissingDisbursementRangeException(err);
559: }
560:
561: if ("CHCK".equals(pg.getDisbursementType().getCode())) {
562: if ((pg.getDisbursementNbr() != null)
563: && (pg.getDisbursementNbr().intValue() == -1)) {
564: pg.setDisbursementNbr(new Integer(checkNumber));
565: } else {
566: int number = 1 + range.getLastAssignedDisbNbr()
567: .intValue();
568: checkNumber = number; // Save for next payment
569: if (number > range.getEndDisbursementNbr()
570: .intValue()) {
571: String err = "No more disbursement numbers for bankId="
572: + pg.getBank().getId()
573: + ",campusId="
574: + campus
575: + ",disbursementType="
576: + pg.getBank().getDisbursementType()
577: .getCode();
578: LOG.error("pass2() " + err);
579: throw new MissingDisbursementRangeException(err);
580: }
581: pg.setDisbursementNbr(new Integer(number));
582:
583: range.setLastAssignedDisbNbr(new Integer(number));
584: range.setLastUpdateUser(p.getProcessUser());
585: range.setLastUpdate(nowTs); // This is needed so we know which ranges to save at the end of the format
586:
587: // Update the summary information
588: fps.setDisbursementNumber(pg, new Integer(number));
589: }
590: } else if ("ACH".equals(pg.getDisbursementType().getCode())) {
591: int number = 1 + range.getLastAssignedDisbNbr()
592: .intValue();
593: if (number > range.getEndDisbursementNbr().intValue()) {
594: String err = "No more disbursement numbers for bankId="
595: + pg.getBank().getId()
596: + ",campusId="
597: + campus
598: + ",disbursementType="
599: + pg.getBank().getDisbursementType()
600: .getCode();
601: LOG.error("pass2() " + err);
602: throw new MissingDisbursementRangeException(err);
603: }
604: pg.setDisbursementNbr(new Integer(number));
605:
606: range.setLastAssignedDisbNbr(new Integer(number));
607: range.setLastUpdateUser(p.getProcessUser());
608: range.setLastUpdate(nowTs); // This is needed so we know which ranges to save at the end of the format
609:
610: // Update the summary information
611: fps.setDisbursementNumber(pg, new Integer(number));
612: } else {
613: // if it isn't check or ach, we're in trouble
614: LOG.error("pass2() Payment group " + pg.getId()
615: + " must be CHCK or ACH. It is: "
616: + pg.getDisbursementType());
617: throw new IllegalArgumentException("Payment group "
618: + pg.getId() + " must be Check or ACH");
619: }
620: paymentGroupDao.save(pg);
621:
622: // Generate a GL entry for CHCK & ACH
623: for (Iterator iter = pg.getPaymentDetails().iterator(); iter
624: .hasNext();) {
625: PaymentDetail element = (PaymentDetail) iter.next();
626: glPendingTransactionService
627: .createProcessPaymentTransaction(element, pg
628: .getBatch().getCustomerProfile()
629: .getRelieveLiabilities());
630: }
631: }
632:
633: // Update all the ranges
634: LOG.debug("pass2() Save ranges");
635: int rc = 0;
636: for (Iterator iter = disbursementRanges.iterator(); iter
637: .hasNext();) {
638: DisbursementNumberRange element = (DisbursementNumberRange) iter
639: .next();
640: if (nowTs.equals(element.getLastUpdate())) {
641: rc++;
642: paymentDetailDao.saveDisbursementNumberRange(element);
643: }
644: }
645: LOG.debug("pass2() " + rc + " ranges saved");
646: }
647:
648: private DisbursementNumberRange getRange(List ranges, Bank bank,
649: Date today) {
650: LOG.debug("getRange() Looking for bank = " + bank.getId()
651: + " for " + today);
652: for (Iterator iter = ranges.iterator(); iter.hasNext();) {
653: DisbursementNumberRange element = (DisbursementNumberRange) iter
654: .next();
655: Date eff = element.getDisbNbrEffectiveDt();
656: Date exp = element.getDisbNbrExpirationDt();
657:
658: if (element.getBank().equals(bank)) {
659: LOG.debug("getRange() Found bank");
660: }
661: if (element.getBank().equals(bank)
662: && (today.getTime() >= eff.getTime())
663: && (today.getTime() <= exp.getTime())) {
664: LOG.debug("getRange() Found match");
665: return element;
666: }
667: }
668: return null;
669: }
670:
671: public List getFormatSummary(Integer procId) {
672: LOG.debug("getFormatSummary() starting");
673: List processSummaryResults = processSummaryDao
674: .getByProcessId(procId);
675: return convertProcessSummary2FormatResult(processSummaryResults);
676: }
677:
678: public List getMostCurrentProcesses() {
679: LOG.debug("getMostCurrent() starting");
680: return processDao.getMostCurrentProcesses(new Integer(
681: getFormatSummaryListSize()));
682: }
683:
684: private class PaymentInfo {
685: public CustomerProfile customer;
686: public String payeeName;
687: public String line1Address;
688: public int noteLines;
689: public String payeeId;
690: public String payeeIdType;
691:
692: public int hashCode() {
693: return new HashCodeBuilder(3, 5).append(customer).append(
694: payeeName).append(line1Address).toHashCode();
695: }
696:
697: public boolean equals(Object obj) {
698: if (!(obj instanceof PaymentInfo)) {
699: return false;
700: }
701: PaymentInfo o = (PaymentInfo) obj;
702: return new EqualsBuilder().append(customer, o.customer)
703: .append(payeeName, o.payeeName).append(
704: line1Address, o.line1Address).append(
705: payeeId, o.payeeId).append(payeeIdType,
706: o.payeeIdType).isEquals();
707: }
708:
709: public String toString() {
710: return new ToStringBuilder(this ).append("customer",
711: this .customer).append("payeeName", this .payeeName)
712: .append("line1Address", this .line1Address).append(
713: "noteLines", this .noteLines).append(
714: "payeeId", this .payeeId).append(
715: "payeeIdType", this .payeeIdType).toString();
716: }
717: }
718:
719: // ***************************************************
720: // IoC stuff below here
721: // ***************************************************
722:
723: // Inject
724: public void setFormatPaymentDao(FormatPaymentDao fpd) {
725: formatPaymentDao = fpd;
726: }
727:
728: // Inject
729: public void setGlPendingTransactionService(
730: GlPendingTransactionService gs) {
731: glPendingTransactionService = gs;
732: }
733:
734: // Inject
735: public void setReferenceService(ReferenceService rs) {
736: referenceService = rs;
737: }
738:
739: // Inject
740: public void setAchService(AchService as) {
741: achService = as;
742: }
743:
744: // Inject
745: public void setProcessDao(ProcessDao pd) {
746: processDao = pd;
747: }
748:
749: // Inject
750: public void setCustomerProfileDao(CustomerProfileDao cpd) {
751: customerProfileDao = cpd;
752: }
753:
754: // Inject
755: public void setDisbursementNumberRangeDao(
756: DisbursementNumberRangeDao dnrd) {
757: disbursementNumberRangeDao = dnrd;
758: }
759:
760: // Inject
761: public void setFormatProcessDao(FormatProcessDao fpd) {
762: formatProcessDao = fpd;
763: }
764:
765: // Inject
766: public void setPaymentGroupDao(PaymentGroupDao pgd) {
767: paymentGroupDao = pgd;
768: }
769:
770: // Inject
771: public void setPaymentDetailDao(PaymentDetailDao pdd) {
772: paymentDetailDao = pdd;
773: }
774:
775: // Inject
776: public void setProcessSummaryDao(ProcessSummaryDao psd) {
777: processSummaryDao = psd;
778: }
779:
780: // Inject
781: public void setSchedulerService(SchedulerService ss) {
782: schedulerService = ss;
783: }
784:
785: public void setParameterService(ParameterService parameterService) {
786: this .parameterService = parameterService;
787: }
788:
789: public void setBusinessObjectService(BusinessObjectService bos) {
790: this.businessObjectService = bos;
791: }
792:
793: }
|