001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.pdp.batch.service.impl;
017    
018    import java.util.List;
019    
020    import org.kuali.kfs.pdp.batch.service.AchAdviceNotificationService;
021    import org.kuali.kfs.pdp.businessobject.CustomerProfile;
022    import org.kuali.kfs.pdp.businessobject.PaymentDetail;
023    import org.kuali.kfs.pdp.businessobject.PaymentGroup;
024    import org.kuali.kfs.pdp.dataaccess.PaymentGroupDao;
025    import org.kuali.kfs.pdp.service.PaymentGroupService;
026    import org.kuali.kfs.pdp.service.PdpEmailService;
027    import org.kuali.kfs.sys.service.NonTransactional;
028    import org.kuali.rice.kns.service.BusinessObjectService;
029    import org.kuali.rice.kns.service.DateTimeService;
030    
031    /**
032     * @see org.kuali.kfs.pdp.batch.service.AchAdviceNotificationService
033     */
034    public class AchAdviceNotificationServiceImpl implements AchAdviceNotificationService {
035        private PdpEmailService pdpEmailService;
036        private PaymentGroupService paymentGroupService;
037    
038        private DateTimeService dateTimeService;
039        private BusinessObjectService businessObjectService;
040    
041        /**
042         * Set to NonTransactional so the payment advice email sent date will be updated and saved after the email is sent
043         * 
044         * @see org.kuali.kfs.pdp.batch.service.AchAdviceNotificationService#sendAdviceNotifications()
045         */
046        @NonTransactional
047        public void sendAdviceNotifications() {
048            // get list of payments to send notification for
049            List<PaymentGroup> paymentGroups = paymentGroupService.getAchPaymentsNeedingAdviceNotification();
050            for (PaymentGroup paymentGroup : paymentGroups) {
051                CustomerProfile customer = paymentGroup.getBatch().getCustomerProfile();
052    
053                // verify the customer profile is setup to create advices
054                if (customer.getAdviceCreate()) {
055                    for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
056                        pdpEmailService.sendAchAdviceEmail(paymentGroup, paymentDetail, customer);
057                    }
058                }
059    
060                // update advice sent date on payment
061                paymentGroup.setAdviceEmailSentDate(dateTimeService.getCurrentTimestamp());
062                businessObjectService.save(paymentGroup);
063            }
064        }
065    
066        /**
067         * Sets the pdpEmailService attribute value.
068         * 
069         * @param pdpEmailService The pdpEmailService to set.
070         */
071        @NonTransactional
072        public void setPdpEmailService(PdpEmailService pdpEmailService) {
073            this.pdpEmailService = pdpEmailService;
074        }
075    
076        /**
077         * Sets the dateTimeService attribute value.
078         * 
079         * @param dateTimeService The dateTimeService to set.
080         */
081        @NonTransactional
082        public void setDateTimeService(DateTimeService dateTimeService) {
083            this.dateTimeService = dateTimeService;
084        }
085    
086        /**
087         * Sets the businessObjectService attribute value.
088         * 
089         * @param businessObjectService The businessObjectService to set.
090         */
091        @NonTransactional
092        public void setBusinessObjectService(BusinessObjectService businessObjectService) {
093            this.businessObjectService = businessObjectService;
094        }
095    
096        /**
097         * Sets the paymentGroupService attribute value.
098         * 
099         * @param paymentGroupService The paymentGroupService to set.
100         */
101        @NonTransactional
102        public void setPaymentGroupService(PaymentGroupService paymentGroupService) {
103            this.paymentGroupService = paymentGroupService;
104        }
105    }