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.purap.service.impl;
017:
018: import java.sql.Date;
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.kuali.core.service.DateTimeService;
024: import org.kuali.core.service.DocumentService;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.kfs.service.ParameterService;
027: import org.kuali.kfs.service.impl.ParameterConstants;
028: import org.kuali.module.financial.document.DisbursementVoucherDocument;
029: import org.kuali.module.financial.rules.DisbursementVoucherRuleConstants;
030: import org.kuali.module.financial.service.DisbursementVoucherExtractService;
031: import org.kuali.module.pdp.PdpConstants;
032: import org.kuali.module.pdp.bo.PaymentDetail;
033: import org.kuali.module.pdp.service.PaymentDetailService;
034: import org.kuali.module.pdp.service.PaymentGroupService;
035: import org.kuali.module.purap.PurapConstants;
036: import org.kuali.module.purap.PurapParameterConstants;
037: import org.kuali.module.purap.document.CreditMemoDocument;
038: import org.kuali.module.purap.document.PaymentRequestDocument;
039: import org.kuali.module.purap.service.CreditMemoService;
040: import org.kuali.module.purap.service.PaymentRequestService;
041: import org.kuali.module.purap.service.ProcessPdpCancelPaidService;
042: import org.springframework.transaction.annotation.Transactional;
043:
044: import edu.iu.uis.eden.exception.WorkflowException;
045:
046: /**
047: * Implementation of ProcessPdpCancelPaidService
048: */
049: @Transactional
050: public class ProcessPdpCancelPaidServiceImpl implements
051: ProcessPdpCancelPaidService {
052: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
053: .getLogger(ProcessPdpCancelPaidServiceImpl.class);
054:
055: private PaymentGroupService paymentGroupService;
056: private PaymentDetailService paymentDetailService;
057: private PaymentRequestService paymentRequestService;
058: private CreditMemoService creditMemoService;
059: private ParameterService parameterService;
060: private DateTimeService dateTimeService;
061: private DisbursementVoucherExtractService dvExtractService;
062:
063: /**
064: * @see org.kuali.module.purap.service.ProcessPdpCancelPaidService#processPdpCancels()
065: */
066: public void processPdpCancels() {
067: LOG.debug("processPdpCancels() started");
068:
069: Date processDate = dateTimeService.getCurrentSqlDate();
070:
071: String organization = parameterService.getParameterValue(
072: ParameterConstants.PURCHASING_BATCH.class,
073: PurapParameterConstants.PURAP_PDP_EPIC_ORG_CODE);
074: String purapSubUnit = parameterService.getParameterValue(
075: ParameterConstants.PURCHASING_BATCH.class,
076: PurapParameterConstants.PURAP_PDP_EPIC_SBUNT_CODE);
077: String dvSubUnit = parameterService
078: .getParameterValue(
079: DisbursementVoucherDocument.class,
080: DisbursementVoucherRuleConstants.DvPdpExtractGroup.DV_PDP_SBUNT_CODE);
081:
082: List<String> subUnits = new ArrayList<String>();
083: subUnits.add(purapSubUnit);
084: subUnits.add(dvSubUnit);
085:
086: String preqCancelNote = parameterService.getParameterValue(
087: PaymentRequestDocument.class,
088: PurapParameterConstants.PURAP_PDP_PREQ_CANCEL_NOTE);
089: String preqResetNote = parameterService.getParameterValue(
090: PaymentRequestDocument.class,
091: PurapParameterConstants.PURAP_PDP_PREQ_RESET_NOTE);
092: String cmCancelNote = parameterService.getParameterValue(
093: CreditMemoDocument.class,
094: PurapParameterConstants.PURAP_PDP_CM_CANCEL_NOTE);
095: String cmResetNote = parameterService.getParameterValue(
096: CreditMemoDocument.class,
097: PurapParameterConstants.PURAP_PDP_CM_RESET_NOTE);
098:
099: Iterator details = paymentDetailService
100: .getUnprocessedCancelledDetails(organization, subUnits);
101: while (details.hasNext()) {
102: PaymentDetail paymentDetail = (PaymentDetail) details
103: .next();
104:
105: String documentTypeCode = paymentDetail
106: .getFinancialDocumentTypeCode();
107: String documentNumber = paymentDetail
108: .getCustPaymentDocNbr();
109:
110: boolean primaryCancel = paymentDetail
111: .getPrimaryCancelledPayment();
112: boolean disbursedPayment = PdpConstants.PaymentStatusCodes.CANCEL_PAYMENT
113: .equals(paymentDetail.getPaymentGroup()
114: .getPaymentStatusCode());
115:
116: if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT
117: .equals(documentTypeCode)) {
118: PaymentRequestDocument pr = paymentRequestService
119: .getPaymentRequestByDocumentNumber(documentNumber);
120: if (pr != null) {
121: if (disbursedPayment || primaryCancel) {
122: paymentRequestService
123: .cancelExtractedPaymentRequest(pr,
124: preqCancelNote);
125: } else {
126: paymentRequestService
127: .resetExtractedPaymentRequest(pr,
128: preqResetNote);
129: }
130: } else {
131: LOG
132: .error("processPdpCancels() DOES NOT EXIST, CANNOT PROCESS - Payment Request with doc type of "
133: + documentTypeCode
134: + " with id "
135: + documentNumber);
136: }
137: } else if (PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT
138: .equals(documentTypeCode)) {
139: CreditMemoDocument cm = creditMemoService
140: .getCreditMemoByDocumentNumber(documentNumber);
141: if (cm != null) {
142: if (disbursedPayment || primaryCancel) {
143: creditMemoService.cancelExtractedCreditMemo(cm,
144: cmCancelNote);
145: } else {
146: creditMemoService.resetExtractedCreditMemo(cm,
147: cmResetNote);
148: }
149: } else {
150: LOG
151: .error("processPdpCancels() DOES NOT EXIST, CANNOT PROCESS - Credit Memo with doc type of "
152: + documentTypeCode
153: + " with id "
154: + documentNumber);
155: }
156: } else if (DisbursementVoucherRuleConstants.DOCUMENT_TYPE_CHECKACH
157: .equals(documentTypeCode)) {
158: DisbursementVoucherDocument dv = dvExtractService
159: .getDocumentById(documentNumber);
160: if (dv != null) {
161: if (disbursedPayment || primaryCancel) {
162: dvExtractService
163: .cancelExtractedDisbursementVoucher(dv,
164: processDate);
165: } else {
166: dvExtractService
167: .resetExtractedDisbursementVoucher(dv,
168: processDate);
169: }
170: }
171: } else {
172: LOG.error("processPdpCancels() Unknown document type ("
173: + documentTypeCode + ") for document ID: "
174: + documentNumber);
175: throw new IllegalArgumentException(
176: "Unknown document type (" + documentTypeCode
177: + ") for document ID: "
178: + documentNumber);
179: }
180:
181: paymentGroupService.processCancelledGroup(paymentDetail
182: .getPaymentGroup(), processDate);
183: }
184: }
185:
186: /**
187: * @see org.kuali.module.purap.service.ProcessPdpCancelPaidService#processPdpPaids()
188: */
189: public void processPdpPaids() {
190: LOG.debug("processPdpPaids() started");
191:
192: Date processDate = dateTimeService.getCurrentSqlDate();
193:
194: String organization = parameterService.getParameterValue(
195: ParameterConstants.PURCHASING_BATCH.class,
196: PurapParameterConstants.PURAP_PDP_EPIC_ORG_CODE);
197: String purapSubUnit = parameterService.getParameterValue(
198: ParameterConstants.PURCHASING_BATCH.class,
199: PurapParameterConstants.PURAP_PDP_EPIC_SBUNT_CODE);
200: String dvSubUnit = parameterService
201: .getParameterValue(
202: DisbursementVoucherDocument.class,
203: DisbursementVoucherRuleConstants.DvPdpExtractGroup.DV_PDP_SBUNT_CODE);
204:
205: List<String> subUnits = new ArrayList<String>();
206: subUnits.add(purapSubUnit);
207: subUnits.add(dvSubUnit);
208:
209: Iterator details = paymentDetailService
210: .getUnprocessedPaidDetails(organization, subUnits);
211: while (details.hasNext()) {
212: PaymentDetail paymentDetail = (PaymentDetail) details
213: .next();
214:
215: String documentTypeCode = paymentDetail
216: .getFinancialDocumentTypeCode();
217: String documentNumber = paymentDetail
218: .getCustPaymentDocNbr();
219:
220: if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT
221: .equals(documentTypeCode)) {
222: PaymentRequestDocument pr = paymentRequestService
223: .getPaymentRequestByDocumentNumber(documentNumber);
224: if (pr != null) {
225: paymentRequestService.markPaid(pr, processDate);
226: } else {
227: LOG
228: .error("processPdpPaids() DOES NOT EXIST, CANNOT MARK - Payment Request with doc type of "
229: + documentTypeCode
230: + " with id "
231: + documentNumber);
232: }
233: } else if (PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT
234: .equals(documentTypeCode)) {
235: CreditMemoDocument cm = creditMemoService
236: .getCreditMemoByDocumentNumber(documentNumber);
237: if (cm != null) {
238: creditMemoService.markPaid(cm, processDate);
239: } else {
240: LOG
241: .error("processPdpPaids() DOES NOT EXIST, CANNOT PROCESS - Credit Memo with doc type of "
242: + documentTypeCode
243: + " with id "
244: + documentNumber);
245: }
246: } else if (documentTypeCode
247: .equals(DisbursementVoucherRuleConstants.DOCUMENT_TYPE_CHECKACH)) {
248: DisbursementVoucherDocument dv = dvExtractService
249: .getDocumentById(documentNumber);
250: dvExtractService.markDisbursementVoucherAsPaid(dv,
251: processDate);
252: } else {
253: LOG.error("processPdpPaids() Unknown document type ("
254: + documentTypeCode + ") for document ID: "
255: + documentNumber);
256: throw new IllegalArgumentException(
257: "Unknown document type (" + documentTypeCode
258: + ") for document ID: "
259: + documentNumber);
260: }
261:
262: paymentGroupService.processPaidGroup(paymentDetail
263: .getPaymentGroup(), processDate);
264: }
265: }
266:
267: /**
268: * @see org.kuali.module.purap.service.ProcessPdpCancelPaidService#processPdpCancelsAndPaids()
269: */
270: public void processPdpCancelsAndPaids() {
271: LOG.debug("processPdpCancelsAndPaids() started");
272:
273: processPdpCancels();
274: processPdpPaids();
275: }
276:
277: public void setPaymentDetailService(
278: PaymentDetailService paymentDetailService) {
279: this .paymentDetailService = paymentDetailService;
280: }
281:
282: public void setPaymentGroupService(
283: PaymentGroupService paymentGroupService) {
284: this .paymentGroupService = paymentGroupService;
285: }
286:
287: public void setCreditMemoService(CreditMemoService creditMemoService) {
288: this .creditMemoService = creditMemoService;
289: }
290:
291: public void setParameterService(ParameterService parameterService) {
292: this .parameterService = parameterService;
293: }
294:
295: public void setPaymentRequestService(
296: PaymentRequestService paymentRequestService) {
297: this .paymentRequestService = paymentRequestService;
298: }
299:
300: public void setDateTimeService(DateTimeService dts) {
301: this .dateTimeService = dts;
302: }
303:
304: /**
305: * Sets the dvExtractService attribute value.
306: * @param dvExtractService The dvExtractService to set.
307: */
308: public void setDvExtractService(
309: DisbursementVoucherExtractService dvExtractService) {
310: this.dvExtractService = dvExtractService;
311: }
312:
313: }
|