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