View Javadoc
1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.pdp.batch.service.impl;
17  
18  import java.sql.Date;
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import org.kuali.ole.fp.batch.service.DisbursementVoucherExtractService;
24  import org.kuali.ole.fp.document.DisbursementVoucherConstants;
25  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
26  import org.kuali.ole.integration.purap.PurchasingAccountsPayableModuleService;
27  import org.kuali.ole.pdp.PdpConstants;
28  import org.kuali.ole.pdp.batch.service.ProcessPdpCancelPaidService;
29  import org.kuali.ole.pdp.businessobject.PaymentDetail;
30  import org.kuali.ole.pdp.service.PaymentDetailService;
31  import org.kuali.ole.pdp.service.PaymentGroupService;
32  import org.kuali.ole.sys.OLEParameterKeyConstants;
33  import org.kuali.ole.sys.service.impl.OleParameterConstants;
34  import org.kuali.rice.core.api.datetime.DateTimeService;
35  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
36  import org.springframework.transaction.annotation.Transactional;
37  
38  /**
39   * Implementation of ProcessPdpCancelPaidService
40   */
41  @Transactional
42  public class ProcessPdpCancelPaidServiceImpl implements ProcessPdpCancelPaidService {
43      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcessPdpCancelPaidServiceImpl.class);
44  
45      protected PaymentGroupService paymentGroupService;
46      protected PaymentDetailService paymentDetailService;
47      protected ParameterService parameterService;
48      protected DateTimeService dateTimeService;
49      protected PurchasingAccountsPayableModuleService purchasingAccountsPayableModuleService;
50      protected DisbursementVoucherExtractService dvExtractService;
51  
52      /**
53       * @see org.kuali.ole.module.purap.service.ProcessPdpCancelPaidService#processPdpCancels()
54       */
55      public void processPdpCancels() {
56          LOG.debug("processPdpCancels() started");
57  
58          Date processDate = dateTimeService.getCurrentSqlDate();
59  
60          String organization = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_ORG_CODE);
61          String purapSubUnit = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_SUB_UNIT_CODE);
62          String dvSubUnit = parameterService.getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.DvPdpExtractGroup.DV_PDP_SBUNT_CODE);
63  
64          List<String> subUnits = new ArrayList<String>();
65          subUnits.add(purapSubUnit);
66          subUnits.add(dvSubUnit);
67  
68          Iterator<PaymentDetail> details = paymentDetailService.getUnprocessedCancelledDetails(organization, subUnits);
69          while (details.hasNext()) {
70              PaymentDetail paymentDetail = details.next();
71  
72              String documentTypeCode = paymentDetail.getFinancialDocumentTypeCode();
73              String documentNumber = paymentDetail.getCustPaymentDocNbr();
74  
75              boolean primaryCancel = paymentDetail.getPrimaryCancelledPayment();
76              boolean disbursedPayment = PdpConstants.PaymentStatusCodes.CANCEL_PAYMENT.equals(paymentDetail.getPaymentGroup().getPaymentStatusCode());
77  
78              if(purchasingAccountsPayableModuleService.isPurchasingBatchDocument(documentTypeCode)) {
79                  purchasingAccountsPayableModuleService.handlePurchasingBatchCancels(documentNumber, documentTypeCode, primaryCancel, disbursedPayment);
80              }
81              else if (DisbursementVoucherConstants.DOCUMENT_TYPE_CHECKACH.equals(documentTypeCode)) {
82                  DisbursementVoucherDocument dv = dvExtractService.getDocumentById(documentNumber);
83                  if (dv != null) {
84                      if (disbursedPayment || primaryCancel) {
85                          dvExtractService.cancelExtractedDisbursementVoucher(dv, processDate);
86                      } else {
87                          dvExtractService.resetExtractedDisbursementVoucher(dv, processDate);
88                      }
89                  }
90              }
91              else {
92                  LOG.warn("processPdpCancels() Unknown document type (" + documentTypeCode + ") for document ID: " + documentNumber);
93                  continue;
94              }
95  
96              paymentGroupService.processCancelledGroup(paymentDetail.getPaymentGroup(), processDate);
97          }
98      }
99  
100     /**
101      * @see org.kuali.ole.module.purap.service.ProcessPdpCancelPaidService#processPdpPaids()
102      */
103     public void processPdpPaids() {
104         LOG.debug("processPdpPaids() started");
105 
106         Date processDate = dateTimeService.getCurrentSqlDate();
107 
108         String organization = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_ORG_CODE);
109         String purapSubUnit = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_SUB_UNIT_CODE);
110         String dvSubUnit = parameterService.getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.DvPdpExtractGroup.DV_PDP_SBUNT_CODE);
111 
112         List<String> subUnits = new ArrayList<String>();
113         subUnits.add(purapSubUnit);
114         subUnits.add(dvSubUnit);
115 
116         Iterator<PaymentDetail> details = paymentDetailService.getUnprocessedPaidDetails(organization, subUnits);
117         while (details.hasNext()) {
118             PaymentDetail paymentDetail = details.next();
119 
120             String documentTypeCode = paymentDetail.getFinancialDocumentTypeCode();
121             String documentNumber = paymentDetail.getCustPaymentDocNbr();
122 
123             if(purchasingAccountsPayableModuleService.isPurchasingBatchDocument(documentTypeCode)) {
124                 purchasingAccountsPayableModuleService.handlePurchasingBatchPaids(documentNumber, documentTypeCode, processDate);
125             }
126             else if (documentTypeCode.equals(DisbursementVoucherConstants.DOCUMENT_TYPE_CHECKACH)) {
127                 DisbursementVoucherDocument dv = dvExtractService.getDocumentById(documentNumber);
128                 dvExtractService.markDisbursementVoucherAsPaid(dv, processDate);
129             }
130             else {
131                 LOG.warn("processPdpPaids() Unknown document type (" + documentTypeCode + ") for document ID: " + documentNumber);
132                 continue;
133             }
134 
135             paymentGroupService.processPaidGroup(paymentDetail.getPaymentGroup(), processDate);
136         }
137     }
138 
139     /**
140      * @see org.kuali.ole.module.purap.service.ProcessPdpCancelPaidService#processPdpCancelsAndPaids()
141      */
142     public void processPdpCancelsAndPaids() {
143         LOG.debug("processPdpCancelsAndPaids() started");
144 
145         processPdpCancels();
146         processPdpPaids();
147     }
148 
149     public void setPaymentDetailService(PaymentDetailService paymentDetailService) {
150         this.paymentDetailService = paymentDetailService;
151     }
152 
153     public void setPaymentGroupService(PaymentGroupService paymentGroupService) {
154         this.paymentGroupService = paymentGroupService;
155     }
156 
157     public void setParameterService(ParameterService parameterService) {
158         this.parameterService = parameterService;
159     }
160 
161     public void setPurchasingAccountsPayableModuleService(PurchasingAccountsPayableModuleService purchasingAccountsPayableModuleService) {
162         this.purchasingAccountsPayableModuleService = purchasingAccountsPayableModuleService;
163     }
164 
165     public void setDateTimeService(DateTimeService dts) {
166         this.dateTimeService = dts;
167     }
168 
169     /**
170      * Sets the dvExtractService attribute value.
171      * @param dvExtractService The dvExtractService to set.
172      */
173     public void setDvExtractService(DisbursementVoucherExtractService dvExtractService) {
174         this.dvExtractService = dvExtractService;
175     }
176     
177 }