Source Code Cross Referenced for PaymentMaintenanceServiceImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » pdp » 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.pdp.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        /*
017:         * Created on Aug 12, 2004
018:         */
019:        package org.kuali.module.pdp.service.impl;
020:
021:        import java.util.List;
022:
023:        import org.kuali.core.mail.InvalidAddressException;
024:        import org.kuali.core.mail.MailMessage;
025:        import org.kuali.core.service.MailService;
026:        import org.kuali.kfs.service.ParameterService;
027:        import org.kuali.kfs.service.impl.ParameterConstants;
028:        import org.kuali.module.pdp.PdpConstants;
029:        import org.kuali.module.pdp.bo.AchAccountNumber;
030:        import org.kuali.module.pdp.bo.Code;
031:        import org.kuali.module.pdp.bo.CustomerProfile;
032:        import org.kuali.module.pdp.bo.PaymentChange;
033:        import org.kuali.module.pdp.bo.PaymentDetail;
034:        import org.kuali.module.pdp.bo.PaymentGroup;
035:        import org.kuali.module.pdp.bo.PaymentGroupHistory;
036:        import org.kuali.module.pdp.bo.PaymentNoteText;
037:        import org.kuali.module.pdp.bo.PaymentStatus;
038:        import org.kuali.module.pdp.bo.PdpUser;
039:        import org.kuali.module.pdp.dao.AchAccountNumberDao;
040:        import org.kuali.module.pdp.dao.PaymentDetailDao;
041:        import org.kuali.module.pdp.dao.PaymentGroupDao;
042:        import org.kuali.module.pdp.dao.PaymentGroupHistoryDao;
043:        import org.kuali.module.pdp.exception.CancelPaymentException;
044:        import org.kuali.module.pdp.exception.PdpException;
045:        import org.kuali.module.pdp.service.EnvironmentService;
046:        import org.kuali.module.pdp.service.GlPendingTransactionService;
047:        import org.kuali.module.pdp.service.PaymentMaintenanceService;
048:        import org.kuali.module.pdp.service.ReferenceService;
049:        import org.kuali.module.pdp.service.SecurityRecord;
050:        import org.kuali.module.pdp.utilities.GeneralUtilities;
051:        import org.springframework.transaction.annotation.Transactional;
052:
053:        /**
054:         * @author HSTAPLET
055:         */
056:        @Transactional
057:        public class PaymentMaintenanceServiceImpl implements 
058:                PaymentMaintenanceService {
059:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
060:                    .getLogger(PaymentMaintenanceServiceImpl.class);
061:
062:            // Payment Status Codes
063:            private static String HELD_CD = "HELD";
064:            private static String OPEN_CD = "OPEN";
065:            private static String CANCEL_PAYMENT_CD = "CPAY";
066:            private static String CANCEL_DISBURSEMENT_CD = "CDIS";
067:            private static String EXTRACTED_CD = "EXTR";
068:            private static String PENDING_ACH_CD = "PACH";
069:            private static String HELD_TAX_EMPLOYEE_CD = "HTXE";
070:            private static String HELD_TAX_NRA_CD = "HTXN";
071:            private static String HELD_TAX_NRA_EMPL_CD = "HTXB";
072:
073:            // Payment Change Codes
074:            private static String CANCEL_PAYMENT_CHNG_CD = "CP";
075:            private static String HOLD_CHNG_CD = "HP";
076:            private static String REMOVE_HOLD_CHNG_CD = "RHP";
077:            private static String CHANGE_IMMEDIATE_CHNG_CD = "IMP";
078:            private static String CANCEL_DISBURSEMENT_CHNG_CD = "CD";
079:            private static String CANCEL_REISSUE_CHNG_CD = "CRD";
080:
081:            private PaymentGroupDao paymentGroupDao;
082:            private PaymentDetailDao paymentDetailDao;
083:            private AchAccountNumberDao achAccountNumberDao;
084:            private PaymentGroupHistoryDao paymentGroupHistoryDao;
085:            private ReferenceService referenceService;
086:            private GlPendingTransactionService glPendingTransactionService;
087:            private EnvironmentService environmentService;
088:            private MailService mailService;
089:            private ParameterService parameterService;
090:
091:            public void changeStatus(PaymentGroup paymentGroup,
092:                    String newPaymentStatus, String changeStatus, String note,
093:                    PdpUser user) {
094:                LOG.debug("changeStatus() enter method with new status of "
095:                        + newPaymentStatus);
096:                PaymentGroupHistory paymentGroupHistory = new PaymentGroupHistory();
097:                Code cd = referenceService.getCode("PaymentChange",
098:                        changeStatus);
099:                paymentGroupHistory.setPaymentChange((PaymentChange) cd);
100:                paymentGroupHistory.setOrigPaymentStatus(paymentGroup
101:                        .getPaymentStatus());
102:                paymentGroupHistory.setChangeUser(user);
103:                paymentGroupHistory.setChangeNoteText(note);
104:                paymentGroupHistory.setPaymentGroup(paymentGroup);
105:                paymentGroupHistoryDao.save(paymentGroupHistory);
106:
107:                Code code = referenceService.getCode("PaymentStatus",
108:                        newPaymentStatus);
109:                paymentGroup.setPaymentStatus((PaymentStatus) code);
110:                paymentGroupDao.save(paymentGroup);
111:                LOG
112:                        .debug("changeStatus() Status has been changed; exit method.");
113:            }
114:
115:            public void changeStatus(PaymentGroup paymentGroup,
116:                    String newPaymentStatus, String changeStatus, String note,
117:                    PdpUser user, PaymentGroupHistory paymentGroupHistory) {
118:                LOG.debug("changeStatus() enter method with new status of "
119:                        + newPaymentStatus);
120:                Code cd = referenceService.getCode("PaymentChange",
121:                        changeStatus);
122:                paymentGroupHistory.setPaymentChange((PaymentChange) cd);
123:                paymentGroupHistory.setOrigPaymentStatus(paymentGroup
124:                        .getPaymentStatus());
125:                paymentGroupHistory.setChangeUser(user);
126:                paymentGroupHistory.setChangeNoteText(note);
127:                paymentGroupHistory.setPaymentGroup(paymentGroup);
128:                paymentGroupHistoryDao.save(paymentGroupHistory);
129:
130:                Code code = referenceService.getCode("PaymentStatus",
131:                        newPaymentStatus);
132:                if (paymentGroup.getPaymentStatus() != ((PaymentStatus) code)) {
133:                    paymentGroup.setPaymentStatus((PaymentStatus) code);
134:                }
135:                paymentGroupDao.save(paymentGroup);
136:
137:                LOG
138:                        .debug("changeStatus() Status has been changed; exit method.");
139:            }
140:
141:            /**
142:             * cancelPendingPayment() This method cancels the pending payment of the given payment id if the following rules apply. -
143:             * Payment status must be: "open", "held", or "pending/ACH".
144:             * 
145:             * @param paymentGroupId (Integer) Primary key of the PaymentGroup that the Payment Detail to be canceled belongs to.
146:             * @param paymentDetailId (Integer) Primary key of the PaymentDetail that was actually canceled.
147:             * @param note (String) Change note text entered by user.
148:             * @param user (User) Actor making change.
149:             */
150:            public void cancelPendingPayment(Integer paymentGroupId,
151:                    Integer paymentDetailId, String note, PdpUser user,
152:                    SecurityRecord sr) throws PdpException {
153:                // All actions must be performed on entire group not individual detail record
154:                LOG
155:                        .debug("cancelPendingPayment() Enter method to cancel pending payment with group id = "
156:                                + paymentGroupId);
157:                LOG
158:                        .debug("cancelPendingPayment() payment detail id being cancelled = "
159:                                + paymentDetailId);
160:                PaymentGroup paymentGroup = paymentGroupDao.get(paymentGroupId);
161:                if (paymentGroup == null) {
162:                    LOG
163:                            .debug("cancelPendingPayment() Pending payment not found; throw exception.");
164:                    throw new CancelPaymentException(
165:                            "Pending payment not found.");
166:                }
167:
168:                String paymentStatus = paymentGroup.getPaymentStatus()
169:                        .getCode();
170:                if (!(CANCEL_PAYMENT_CD.equals(paymentStatus))) {
171:                    LOG.debug("cancelPendingPayment() Payment status is "
172:                            + paymentStatus + "; continue with cancel.");
173:                    if ((HELD_TAX_EMPLOYEE_CD.equals(paymentStatus))
174:                            || (HELD_TAX_NRA_CD.equals(paymentStatus))
175:                            || (HELD_TAX_NRA_EMPL_CD.equals(paymentStatus))) {
176:                        if (sr.isTaxHoldersRole() || sr.isSysAdminRole()) {
177:                            changeStatus(paymentGroup, CANCEL_PAYMENT_CD,
178:                                    CANCEL_PAYMENT_CHNG_CD, note, user);
179:                            // set primary cancel indicator for EPIC to use
180:                            PaymentDetail pd = paymentDetailDao
181:                                    .get(paymentDetailId);
182:                            if (pd != null) {
183:                                pd.setPrimaryCancelledPayment(Boolean.TRUE);
184:                            }
185:                            paymentDetailDao.save(pd);
186:                            sendCancelEmail(paymentGroup, note, user);
187:                            LOG
188:                                    .debug("cancelPendingPayment() Pending payment cancelled and mail was sent; exit method.");
189:                        } else {
190:                            LOG
191:                                    .debug("cancelPendingPayment() Payment status is "
192:                                            + paymentStatus
193:                                            + "; user does not have rights to cancel");
194:                            throw new CancelPaymentException(
195:                                    "Invalid status to cancel pending payment.");
196:                        }
197:                    } else if (OPEN_CD.equals(paymentStatus)
198:                            || HELD_CD.equals(paymentStatus)) {
199:                        if (sr.isCancelRole()) {
200:                            changeStatus(paymentGroup, CANCEL_PAYMENT_CD,
201:                                    CANCEL_PAYMENT_CHNG_CD, note, user);
202:                            // set primary cancel indicator for EPIC to use
203:                            PaymentDetail pd = paymentDetailDao
204:                                    .get(paymentDetailId);
205:                            if (pd != null) {
206:                                pd.setPrimaryCancelledPayment(Boolean.TRUE);
207:                                PaymentNoteText payNoteText = new PaymentNoteText();
208:                                payNoteText.setCustomerNoteLineNbr(pd
209:                                        .getNotes().size() + 1);
210:                                payNoteText.setCustomerNoteText(note);
211:                                pd.addNote(payNoteText);
212:                            }
213:                            paymentDetailDao.save(pd);
214:                            LOG
215:                                    .debug("cancelPendingPayment() Pending payment cancelled; exit method.");
216:                        } else {
217:                            LOG
218:                                    .debug("cancelPendingPayment() Payment status is "
219:                                            + paymentStatus
220:                                            + "; user does not have rights to cancel");
221:                            throw new CancelPaymentException(
222:                                    "Invalid status to cancel pending payment.");
223:                        }
224:                    } else {
225:                        LOG.debug("cancelPendingPayment() Payment status is "
226:                                + paymentStatus
227:                                + "; cannot cancel payment in this status");
228:                        throw new CancelPaymentException(
229:                                "Invalid status to cancel pending payment.");
230:                    }
231:                } else {
232:                    LOG
233:                            .debug("cancelPendingPayment() Pending payment group has already been cancelled; exit method.");
234:                }
235:            }// end cancelPendingPayment()
236:
237:            /**
238:             * holdPendingPayment() This method holds pending payment of the given payment id if the following rules apply. - Payment status
239:             * must be: "open".
240:             * 
241:             * @param paymentGroupId (Integer) Primary key of the PaymentGroup that the Payment Detail to be held belongs to.
242:             * @param note (String) Change note text entered by user.
243:             * @param user (User) Actor making change.
244:             */
245:            public void holdPendingPayment(Integer paymentGroupId, String note,
246:                    PdpUser user) throws PdpException {
247:                // All actions must be performed on entire group not individual detail record
248:                LOG
249:                        .debug("holdPendingPayment() Enter method to hold pending payment with id = "
250:                                + paymentGroupId);
251:                PaymentGroup paymentGroup = paymentGroupDao.get(paymentGroupId);
252:                if (paymentGroup == null) {
253:                    LOG
254:                            .debug("holdPendingPayment() Pending payment not found; throw exception.");
255:                    throw new CancelPaymentException(
256:                            "Pending payment not found.");
257:                }
258:
259:                String paymentStatus = paymentGroup.getPaymentStatus()
260:                        .getCode();
261:                if (!(HELD_CD.equals(paymentStatus))) {
262:                    if (OPEN_CD.equals(paymentStatus)) {
263:                        LOG.debug("holdPendingPayment() Payment status is "
264:                                + paymentStatus + "; continue with hold.");
265:                        changeStatus(paymentGroup, HELD_CD, HOLD_CHNG_CD, note,
266:                                user);
267:                        LOG
268:                                .debug("holdPendingPayment() Pending payment was put on hold; exit method.");
269:                    } else {
270:                        LOG.debug("holdPendingPayment() Payment status is "
271:                                + paymentStatus
272:                                + "; cannot hold payment in this status");
273:                        throw new CancelPaymentException(
274:                                "Invalid status to hold pending payment.");
275:                    }
276:                } else {
277:                    LOG
278:                            .debug("holdPendingPayment() Pending payment group has already been held; exit method.");
279:                }
280:
281:            }// end holdPendingPayment()
282:
283:            /**
284:             * removeHoldPendingPayment() This method removes holds on pending payments of the given payment id if the following rules
285:             * apply. - Payment status must be: "held".
286:             * 
287:             * @param paymentGroupId (Integer) Primary key of the PaymentGroup that the Payment Detail to be un-held belongs to.
288:             * @param note (String) Change note text entered by user.
289:             * @param user (User) Actor making change.
290:             * @param sr (SecurityRecord) User's rights
291:             */
292:            public void removeHoldPendingPayment(Integer paymentGroupId,
293:                    String note, PdpUser user, SecurityRecord sr)
294:                    throws PdpException {
295:                // All actions must be performed on entire group not individual detail record
296:                LOG
297:                        .debug("removeHoldPendingPayment() Enter method to hold pending payment with id = "
298:                                + paymentGroupId);
299:                PaymentGroup paymentGroup = paymentGroupDao.get(paymentGroupId);
300:                if (paymentGroup == null) {
301:                    LOG
302:                            .debug("removeHoldPendingPayment() Payment not found; throw exception.");
303:                    throw new CancelPaymentException(
304:                            "Pending payment not found.");
305:                }
306:
307:                String paymentStatus = paymentGroup.getPaymentStatus()
308:                        .getCode();
309:                if (!(OPEN_CD.equals(paymentStatus))) {
310:                    LOG.debug("removeHoldPendingPayment() Payment status is "
311:                            + paymentStatus + "; continue with hold removal.");
312:                    if ((HELD_TAX_EMPLOYEE_CD.equals(paymentStatus))
313:                            || (HELD_TAX_NRA_CD.equals(paymentStatus))
314:                            || (HELD_TAX_NRA_EMPL_CD.equals(paymentStatus))) {
315:                        if (sr.isTaxHoldersRole() || sr.isSysAdminRole()) {
316:                            changeStatus(paymentGroup, OPEN_CD,
317:                                    REMOVE_HOLD_CHNG_CD, note, user);
318:                            LOG
319:                                    .debug("removeHoldPendingPayment() Pending payment was taken off hold; exit method.");
320:                        } else {
321:                            LOG
322:                                    .debug("removeHoldPendingPayment() Payment status is "
323:                                            + paymentStatus
324:                                            + "; user does not have rights to cancel");
325:                            throw new CancelPaymentException(
326:                                    "Invalid status to hold pending payment.");
327:                        }
328:                    } else if (HELD_CD.equals(paymentStatus)) {
329:                        if (sr.isHoldRole()) {
330:                            changeStatus(paymentGroup, OPEN_CD,
331:                                    REMOVE_HOLD_CHNG_CD, note, user);
332:                            LOG
333:                                    .debug("removeHoldPendingPayment() Pending payment was taken off hold; exit method.");
334:                        } else {
335:                            LOG
336:                                    .debug("removeHoldPendingPayment() Payment status is "
337:                                            + paymentStatus
338:                                            + "; user does not have rights to cancel");
339:                            throw new CancelPaymentException(
340:                                    "Invalid status to hold pending payment.");
341:                        }
342:                    } else {
343:                        LOG
344:                                .debug("removeHoldPendingPayment() Payment status is "
345:                                        + paymentStatus
346:                                        + "; cannot remove hold on payment in this status");
347:                        throw new CancelPaymentException(
348:                                "Invalid status to hold pending payment.");
349:                    }
350:                } else {
351:                    LOG
352:                            .debug("removeHoldPendingPayment() Pending payment group has already been un-held; exit method.");
353:                }
354:            }// end removeHoldPendingPayment()
355:
356:            public void changeImmediateFlag(Integer paymentGroupId,
357:                    String note, PdpUser user) {
358:                // All actions must be performed on entire group not individual detail record
359:                LOG
360:                        .debug("changeImmediateFlag() Enter method to hold pending payment with id = "
361:                                + paymentGroupId);
362:                PaymentGroupHistory paymentGroupHistory = new PaymentGroupHistory();
363:                PaymentGroup paymentGroup = paymentGroupDao.get(paymentGroupId);
364:
365:                paymentGroupHistory.setOrigProcessImmediate(paymentGroup
366:                        .getProcessImmediate());
367:
368:                if (paymentGroup.getProcessImmediate().equals(
369:                        new Boolean("True"))) {
370:                    paymentGroup.setProcessImmediate(new Boolean("False"));
371:                } else {
372:                    paymentGroup.setProcessImmediate(new Boolean("True"));
373:                }
374:
375:                changeStatus(paymentGroup, paymentGroup.getPaymentStatus()
376:                        .getCode(), CHANGE_IMMEDIATE_CHNG_CD, note, user,
377:                        paymentGroupHistory);
378:                LOG.debug("changeImmediateFlag() exit method.");
379:            }
380:
381:            /**
382:             * cancelDisbursement() This method cancels all disbursements with the same disbursment number as that of the given payment id
383:             * if the following rules apply. - Payment status must be: "extr".
384:             * 
385:             * @param paymentGroupId (Integer) Primary key of the PaymentGroup that the Payment Detail to be cancelled belongs to.
386:             * @param paymentDetailId (Integer) Primary key of the PaymentDetail that was actually cancelled.
387:             * @param note (String) Change note text entered by user.
388:             * @param user (User) Actor making change.
389:             */
390:            public void cancelDisbursement(Integer paymentGroupId,
391:                    Integer paymentDetailId, String note, PdpUser user)
392:                    throws PdpException {
393:                // All actions must be performed on entire group not individual detail record
394:                LOG
395:                        .debug("cancelDisbursement() Enter method to cancel disbursement with id = "
396:                                + paymentGroupId);
397:                PaymentGroup paymentGroup = paymentGroupDao.get(paymentGroupId);
398:                if (paymentGroup == null) {
399:                    LOG
400:                            .debug("cancelDisbursement() Disbursement not found; throw exception.");
401:                    throw new CancelPaymentException("Disbursement not found.");
402:                }
403:
404:                String paymentStatus = paymentGroup.getPaymentStatus()
405:                        .getCode();
406:                if (!(CANCEL_DISBURSEMENT_CD.equals(paymentStatus))) {
407:                    if (((EXTRACTED_CD.equals(paymentStatus)) && (paymentGroup
408:                            .getDisbursementDate() != null))
409:                            || (PENDING_ACH_CD.equals(paymentStatus))) {
410:                        LOG.debug("cancelDisbursement() Payment status is "
411:                                + paymentStatus + "; continue with cancel.");
412:                        List<PaymentGroup> allDisbursementPaymentGroups = paymentGroupDao
413:                                .getByDisbursementNumber(paymentGroup
414:                                        .getDisbursementNbr());
415:
416:                        for (PaymentGroup element : allDisbursementPaymentGroups) {
417:                            PaymentGroupHistory pgh = new PaymentGroupHistory();
418:                            if ((element.getDisbursementType() != null)
419:                                    && (element.getDisbursementType().getCode()
420:                                            .equals("CHCK"))) {
421:                                pgh
422:                                        .setPmtCancelExtractStat(new Boolean(
423:                                                "False"));
424:                            }
425:                            changeStatus(element, CANCEL_DISBURSEMENT_CD,
426:                                    CANCEL_DISBURSEMENT_CHNG_CD, note, user,
427:                                    pgh);
428:                            glPendingTransactionService
429:                                    .createCancellationTransaction(element);
430:                        }
431:                        // set primary cancel indicator for EPIC to use
432:                        PaymentDetail pd = paymentDetailDao
433:                                .get(paymentDetailId);
434:                        if (pd != null) {
435:                            pd.setPrimaryCancelledPayment(Boolean.TRUE);
436:                        }
437:                        paymentDetailDao.save(pd);
438:
439:                        LOG
440:                                .debug("cancelDisbursement() Disbursement cancelled; exit method.");
441:                    } else {
442:                        LOG.debug("cancelDisbursement() Payment status is "
443:                                + paymentStatus + " and disbursement date is "
444:                                + paymentGroup.getDisbursementDate()
445:                                + "; cannot cancel payment in this status");
446:                        throw new CancelPaymentException(
447:                                "Invalid disbursement to cancel.");
448:                    }
449:                } else {
450:                    LOG
451:                            .debug("cancelDisbursement() Disbursement has already been cancelled; exit method.");
452:                }
453:            }// end cancelDisbursement()
454:
455:            /**
456:             * cancelReissueDisbursement() This method cancels and re-opens all disbursements with the same disbursment number as that of
457:             * the given payment id if the following rules apply. - Payment status must be: "extr".
458:             * 
459:             * @param paymentGroupId (Integer) Primary key of the PaymentGroup that the Payment Detail to be canceled/reissued belongs to.
460:             * @param note (String) Change note text entered by user.
461:             * @param user (User) Actor making change.
462:             */
463:            public void cancelReissueDisbursement(Integer paymentGroupId,
464:                    String note, PdpUser user) throws PdpException {
465:                // All actions must be performed on entire group not individual detail record
466:                LOG
467:                        .debug("cancelReissueDisbursement() Enter method to cancel disbursement with id = "
468:                                + paymentGroupId);
469:                PaymentGroup paymentGroup = paymentGroupDao.get(paymentGroupId);
470:                if (paymentGroup == null) {
471:                    LOG
472:                            .debug("cancelReissueDisbursement() Disbursement not found; throw exception.");
473:                    throw new CancelPaymentException("Disbursement not found.");
474:                }
475:
476:                String paymentStatus = paymentGroup.getPaymentStatus()
477:                        .getCode();
478:                if (!(OPEN_CD.equals(paymentStatus))) {
479:                    if (((EXTRACTED_CD.equals(paymentStatus)) && (paymentGroup
480:                            .getDisbursementDate() != null))
481:                            || (PENDING_ACH_CD.equals(paymentStatus))) {
482:                        LOG
483:                                .debug("cancelReissueDisbursement() Payment status is "
484:                                        + paymentStatus
485:                                        + "; continue with cancel.");
486:                        List<PaymentGroup> allDisbursementPaymentGroups = paymentGroupDao
487:                                .getByDisbursementNumber(paymentGroup
488:                                        .getDisbursementNbr());
489:
490:                        for (PaymentGroup pg : allDisbursementPaymentGroups) {
491:                            PaymentGroupHistory pgh = new PaymentGroupHistory();
492:
493:                            if ((pg.getDisbursementType() != null)
494:                                    && (pg.getDisbursementType().getCode()
495:                                            .equals("CHCK"))) {
496:                                pgh
497:                                        .setPmtCancelExtractStat(new Boolean(
498:                                                "False"));
499:                            }
500:                            pgh.setOrigProcessImmediate(pg
501:                                    .getProcessImmediate());
502:                            pgh.setOrigPmtSpecHandling(pg
503:                                    .getPymtSpecialHandling());
504:                            pgh.setBank(pg.getBank());
505:                            pgh.setOrigPaymentDate(pg.getPaymentDate());
506:                            pgh.setOrigDisburseDate(pg.getDisbursementDate());
507:                            pgh.setOrigAchBankRouteNbr(pg
508:                                    .getAchBankRoutingNbr());
509:                            pgh.setOrigDisburseNbr(pg.getDisbursementNbr());
510:                            pgh.setOrigAdviceEmail(pg.getAdviceEmailAddress());
511:                            pgh.setDisbursementType(pg.getDisbursementType());
512:                            pgh.setProcess(pg.getProcess());
513:
514:                            glPendingTransactionService
515:                                    .createCancelReissueTransaction(pg);
516:                            LOG
517:                                    .debug("cancelReissueDisbursement() Status is '"
518:                                            + paymentStatus
519:                                            + "; delete row from AchAccountNumber table.");
520:                            AchAccountNumber achAccountNumber = pg
521:                                    .getAchAccountNumber();
522:                            if (achAccountNumber != null) {
523:                                achAccountNumberDao.delete(achAccountNumber);
524:                                pg.setAchAccountNumber(null);
525:                            }
526:
527:                            pg.setBank(null);
528:                            pg.setDisbursementDate(null);
529:                            pg.setAchBankRoutingNbr(null);
530:                            pg.setAchAccountType(null);
531:                            pg.setPhysCampusProcessCd(null);
532:                            pg.setDisbursementNbr(null);
533:                            pg.setAdviceEmailAddress(null);
534:                            pg.setDisbursementType(null);
535:                            pg.setProcess(null);
536:                            changeStatus(pg, OPEN_CD, CANCEL_REISSUE_CHNG_CD,
537:                                    note, user, pgh);
538:                        }
539:
540:                        LOG
541:                                .debug("cancelReissueDisbursement() Disbursement cancelled and reissued; exit method.");
542:                    } else {
543:                        LOG
544:                                .debug("cancelReissueDisbursement() Payment status is "
545:                                        + paymentStatus
546:                                        + " and disbursement date is "
547:                                        + paymentGroup.getDisbursementDate()
548:                                        + "; cannot cancel payment");
549:                        throw new CancelPaymentException(
550:                                "Invalid disbursement to cancel and reissue.");
551:                    }
552:                } else {
553:                    LOG
554:                            .debug("cancelReissueDisbursement() Disbursement already cancelled and reissued; exit method.");
555:                }
556:            }// end cancelReissueDisbursement()
557:
558:            public void sendCancelEmail(PaymentGroup paymentGroup, String note,
559:                    PdpUser user) {
560:                LOG.debug("sendCancelEmail() starting");
561:                MailMessage message = new MailMessage();
562:
563:                if (environmentService.isProduction()) {
564:                    message.setSubject("PDP --- Cancelled Payment by Tax");
565:                } else {
566:                    String env = environmentService.getEnvironment();
567:                    message.setSubject(env
568:                            + "-PDP --- Cancelled Payment by Tax");
569:                }
570:
571:                CustomerProfile cp = paymentGroup.getBatch()
572:                        .getCustomerProfile();
573:                String toAddresses = cp.getAdviceReturnEmailAddr();
574:                String toAddressList[] = toAddresses.split(",");
575:
576:                if (toAddressList.length > 0) {
577:                    for (int i = 0; i < toAddressList.length; i++) {
578:                        if (toAddressList[i] != null) {
579:                            message.addToAddress(toAddressList[i].trim());
580:                        }
581:                    }
582:                }
583:                // message.addToAddress(cp.getAdviceReturnEmailAddr());
584:
585:                String ccAddresses = parameterService
586:                        .getParameterValue(
587:                                ParameterConstants.PRE_DISBURSEMENT_ALL.class,
588:                                PdpConstants.ApplicationParameterKeys.TAX_CANCEL_EMAIL_LIST);
589:                String ccAddressList[] = ccAddresses.split(",");
590:
591:                if (ccAddressList.length > 0) {
592:                    for (int i = 0; i < ccAddressList.length; i++) {
593:                        if (ccAddressList[i] != null) {
594:                            message.addCcAddress(ccAddressList[i].trim());
595:                        }
596:                    }
597:                }
598:
599:                String fromAddressList[] = { mailService.getBatchMailingList() };
600:
601:                if (fromAddressList.length > 0) {
602:                    for (int i = 0; i < fromAddressList.length; i++) {
603:                        if (fromAddressList[i] != null) {
604:                            message.setFromAddress(fromAddressList[i].trim());
605:                        }
606:                    }
607:                }
608:
609:                StringBuffer body = new StringBuffer();
610:                if (paymentGroup.getPaymentDetails().size() > 1) {
611:                    body
612:                            .append("The following payments have been cancelled by the Financial Management Services Tax Department.  The payments were cancelled for the following reason:\n\n");
613:                } else {
614:                    body
615:                            .append("The following payment has been cancelled by the Financial Management Services Tax Department.  The payment was cancelled for the following reason:\n\n");
616:                }
617:                body.append(note + "\n\n");
618:                String taxEmail = parameterService
619:                        .getParameterValue(
620:                                ParameterConstants.PRE_DISBURSEMENT_ALL.class,
621:                                PdpConstants.ApplicationParameterKeys.TAX_GROUP_EMAIL_ADDRESS);
622:                if (GeneralUtilities.isStringEmpty(taxEmail)) {
623:                    body
624:                            .append("Please contact the Financial Management Services Tax Department if you have questions regarding this cancellation.\n\n");
625:                } else {
626:                    body
627:                            .append("Please contact the Financial Management Services Tax Department at "
628:                                    + taxEmail
629:                                    + " if you have questions regarding this cancellation.\n\n");
630:                }
631:
632:                if (paymentGroup.getPaymentDetails().size() > 1) {
633:                    body
634:                            .append("The following payment details were cancelled:\n\n");
635:                } else {
636:                    body
637:                            .append("The following payment detail was cancelled:\n\n");
638:                }
639:                for (PaymentDetail pd : paymentGroup.getPaymentDetails()) {
640:                    body.append("Payee Name: " + paymentGroup.getPayeeName()
641:                            + "\n");
642:                    body.append("Net Payment Amount: "
643:                            + pd.getNetPaymentAmount() + "\n");
644:                    body.append("Source Document Number: "
645:                            + pd.getCustPaymentDocNbr() + "\n");
646:                    body.append("Invoice Number: " + pd.getInvoiceNbr() + "\n");
647:                    body.append("Purchase Order Number: "
648:                            + pd.getPurchaseOrderNbr() + "\n");
649:                    body.append("Payment Detail ID: " + pd.getId() + "\n\n");
650:
651:                }
652:
653:                if (paymentGroup.getPaymentDetails().size() > 1) {
654:                    body
655:                            .append("The cancelled payment details were sent to PDP as part of the following batch:\n\n");
656:                } else {
657:                    body
658:                            .append("The cancelled payment detail was sent to PDP as part of the following batch:\n\n");
659:                }
660:                body.append("Batch ID: " + paymentGroup.getBatch().getId()
661:                        + "\n");
662:                body.append("Chart: " + cp.getChartCode() + "\n");
663:                body.append("Organization: " + cp.getOrgCode() + "\n");
664:                body.append("Sub Unit: " + cp.getSubUnitCode() + "\n");
665:                body.append("Creation Date: "
666:                        + paymentGroup.getBatch()
667:                                .getCustomerFileCreateTimestamp() + "\n");
668:                body.append("Payment Count: "
669:                        + paymentGroup.getBatch().getPaymentCount() + "\n");
670:                body.append("Payment Total Amount: "
671:                        + paymentGroup.getBatch().getPaymentTotalAmount());
672:
673:                message.setMessage(body.toString());
674:                try {
675:                    mailService.sendMessage(message);
676:                } catch (InvalidAddressException e) {
677:                    LOG
678:                            .error(
679:                                    "sendErrorEmail() Invalid email address. Message not sent",
680:                                    e);
681:                }
682:            }
683:
684:            /**
685:             * inject
686:             * 
687:             * @param dao
688:             */
689:            public void setPaymentGroupDao(PaymentGroupDao dao) {
690:                paymentGroupDao = dao;
691:            }
692:
693:            /**
694:             * inject
695:             * 
696:             * @param dao
697:             */
698:            public void setPaymentDetailDao(PaymentDetailDao dao) {
699:                paymentDetailDao = dao;
700:            }
701:
702:            /**
703:             * inject
704:             * 
705:             * @param dao
706:             */
707:            public void setPaymentGroupHistoryDao(PaymentGroupHistoryDao dao) {
708:                paymentGroupHistoryDao = dao;
709:            }
710:
711:            /**
712:             * inject
713:             * 
714:             * @param service
715:             */
716:            public void setReferenceService(ReferenceService service) {
717:                referenceService = service;
718:            }
719:
720:            /**
721:             * inject
722:             * 
723:             * @param dao
724:             */
725:            public void setAchAccountNumberDao(AchAccountNumberDao dao) {
726:                achAccountNumberDao = dao;
727:            }
728:
729:            /**
730:             * inject
731:             * 
732:             * @param service
733:             */
734:            public void setGlPendingTransactionService(
735:                    GlPendingTransactionService service) {
736:                glPendingTransactionService = service;
737:            }
738:
739:            /**
740:             * inject
741:             * 
742:             * @param service
743:             */
744:            public void setEnvironmentService(
745:                    EnvironmentService environmentService) {
746:                this .environmentService = environmentService;
747:            }
748:
749:            /**
750:             * inject
751:             * 
752:             * @param service
753:             */
754:            public void setMailService(MailService mailService) {
755:                this .mailService = mailService;
756:            }
757:
758:            public void setParameterService(ParameterService parameterService) {
759:                this.parameterService = parameterService;
760:            }
761:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.