View Javadoc
1   /*
2    * Copyright 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.module.purap.document.service.impl;
17  
18  import org.kuali.ole.integration.purap.PurchasingAccountsPayableModuleService;
19  import org.kuali.ole.integration.purap.PurchasingAccountsPayableSensitiveData;
20  import org.kuali.ole.module.purap.PurapConstants;
21  import org.kuali.ole.module.purap.PurapParameterConstants;
22  import org.kuali.ole.module.purap.businessobject.SensitiveData;
23  import org.kuali.ole.module.purap.document.PaymentRequestDocument;
24  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
25  import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
26  import org.kuali.ole.module.purap.document.service.CreditMemoService;
27  import org.kuali.ole.module.purap.document.service.PaymentRequestService;
28  import org.kuali.ole.module.purap.document.service.PurapService;
29  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
30  import org.kuali.ole.sys.context.SpringContext;
31  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32  import org.kuali.rice.krad.bo.Note;
33  import org.kuali.rice.krad.service.BusinessObjectService;
34  import org.kuali.rice.krad.service.DocumentService;
35  import org.kuali.rice.krad.service.NoteService;
36  import org.kuali.rice.krad.util.ObjectUtils;
37  
38  import java.sql.Date;
39  import java.util.*;
40  
41  public class PurchasingAccountsPayableModuleServiceImpl implements PurchasingAccountsPayableModuleService {
42      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchasingAccountsPayableModuleServiceImpl.class);
43  
44      private PurchaseOrderService purchaseOrderService;
45      private PurapService purapService;
46      private DocumentService documentService;
47  
48      /**
49       * @see org.kuali.ole.integration.service.PurchasingAccountsPayableModuleService#addAssignedAssetNumbers(java.lang.Integer,
50       *      java.util.List)
51       */
52      public void addAssignedAssetNumbers(Integer purchaseOrderNumber, String principalId, String noteText) {
53          PurchaseOrderDocument document = purchaseOrderService.getCurrentPurchaseOrder(purchaseOrderNumber);
54  
55          try {
56              Note assetNote = SpringContext.getBean(DocumentService.class).createNoteFromDocument(document, noteText);
57              // set the initiator user info to the new note
58              assetNote.setAuthorUniversalIdentifier(principalId);
59              document.addNote(assetNote);
60              SpringContext.getBean(NoteService.class).save(assetNote);
61          } catch (Exception e) {
62              throw new RuntimeException(e);
63          }
64      }
65  
66      /**
67       * @see org.kuali.ole.integration.service.PurchasingAccountsPayableModuleService#getPurchaseOrderInquiryUrl(java.lang.Integer)
68       */
69      public String getPurchaseOrderInquiryUrl(Integer purchaseOrderNumber) {
70          PurchaseOrderDocument po = purchaseOrderService.getCurrentPurchaseOrder(purchaseOrderNumber);
71          if (ObjectUtils.isNotNull(po)) {
72              return "purapPurchaseOrder.do?methodToCall=docHandler&docId=" + po.getDocumentNumber() + "&command=displayDocSearchView";
73          } else {
74              return "";
75          }
76      }
77  
78      /**
79       * @see org.kuali.ole.integration.service.PurchasingAccountsPayableModuleService#getAllSensitiveDatas()
80       */
81      public List<PurchasingAccountsPayableSensitiveData> getAllSensitiveDatas() {
82          List<PurchasingAccountsPayableSensitiveData> sensitiveDatas = new ArrayList<PurchasingAccountsPayableSensitiveData>();
83          Collection sensitiveDatasAsObjects = SpringContext.getBean(BusinessObjectService.class).findAll(SensitiveData.class);
84          for (Object rm : sensitiveDatasAsObjects) {
85              sensitiveDatas.add((PurchasingAccountsPayableSensitiveData) rm);
86          }
87          return sensitiveDatas;
88      }
89  
90      /**
91       * @see org.kuali.ole.integration.service.PurchasingAccountsPayableModuleService#getSensitiveDataByCode(java.lang.String)
92       */
93      public PurchasingAccountsPayableSensitiveData getSensitiveDataByCode(String sensitiveDataCode) {
94          Map primaryKeys = new HashMap();
95          primaryKeys.put("sensitiveDataCode", sensitiveDataCode);
96          return (PurchasingAccountsPayableSensitiveData) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(SensitiveData.class, primaryKeys);
97      }
98  
99      /**
100      * @see org.kuali.ole.integration.service.PurchasingAccountsPayableModuleService#isPurchasingBatchDocument(java.lang.String)
101      */
102     public boolean isPurchasingBatchDocument(String documentTypeCode) {
103         if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT.equals(documentTypeCode) || PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT.equals(documentTypeCode)) {
104             return true;
105         }
106         return false;
107     }
108 
109     /**
110      * @see org.kuali.ole.integration.service.PurchasingAccountsPayableModuleService#handlePurchasingBatchCancels(java.lang.String)
111      */
112     public void handlePurchasingBatchCancels(String documentNumber, String documentTypeCode, boolean primaryCancel, boolean disbursedPayment) {
113         ParameterService parameterService = SpringContext.getBean(ParameterService.class);
114         PaymentRequestService paymentRequestService = SpringContext.getBean(PaymentRequestService.class);
115         CreditMemoService creditMemoService = SpringContext.getBean(CreditMemoService.class);
116 
117         String preqCancelNote = parameterService.getParameterValueAsString(PaymentRequestDocument.class, PurapParameterConstants.PURAP_PDP_PREQ_CANCEL_NOTE);
118         String preqResetNote = parameterService.getParameterValueAsString(PaymentRequestDocument.class, PurapParameterConstants.PURAP_PDP_PREQ_RESET_NOTE);
119         String cmCancelNote = parameterService.getParameterValueAsString(VendorCreditMemoDocument.class, PurapParameterConstants.PURAP_PDP_CM_CANCEL_NOTE);
120         String cmResetNote = parameterService.getParameterValueAsString(VendorCreditMemoDocument.class, PurapParameterConstants.PURAP_PDP_CM_RESET_NOTE);
121 
122         if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT.equals(documentTypeCode)) {
123             PaymentRequestDocument pr = paymentRequestService.getPaymentRequestByDocumentNumber(documentNumber);
124             if (pr != null) {
125                 if (disbursedPayment || primaryCancel) {
126                     paymentRequestService.cancelExtractedPaymentRequest(pr, preqCancelNote);
127                 } else {
128                     paymentRequestService.resetExtractedPaymentRequest(pr, preqResetNote);
129                 }
130             } else {
131                 LOG.error("processPdpCancels() DOES NOT EXIST, CANNOT PROCESS - Payment Request with doc type of " + documentTypeCode + " with id " + documentNumber);
132             }
133         } else if (PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT.equals(documentTypeCode)) {
134             VendorCreditMemoDocument cm = creditMemoService.getCreditMemoByDocumentNumber(documentNumber);
135             if (cm != null) {
136                 if (disbursedPayment || primaryCancel) {
137                     creditMemoService.cancelExtractedCreditMemo(cm, cmCancelNote);
138                 } else {
139                     creditMemoService.resetExtractedCreditMemo(cm, cmResetNote);
140                 }
141             } else {
142                 LOG.error("processPdpCancels() DOES NOT EXIST, CANNOT PROCESS - Credit Memo with doc type of " + documentTypeCode + " with id " + documentNumber);
143             }
144         }
145     }
146 
147     /**
148      * @see org.kuali.ole.integration.service.PurchasingAccountsPayableModuleService#handlePurchasingBatchPaids(java.lang.String)
149      */
150     public void handlePurchasingBatchPaids(String documentNumber, String documentTypeCode, Date processDate) {
151         ParameterService parameterService = SpringContext.getBean(ParameterService.class);
152         PaymentRequestService paymentRequestService = SpringContext.getBean(PaymentRequestService.class);
153         CreditMemoService creditMemoService = SpringContext.getBean(CreditMemoService.class);
154 
155         if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT.equals(documentTypeCode)) {
156             PaymentRequestDocument pr = paymentRequestService.getPaymentRequestByDocumentNumber(documentNumber);
157             if (pr != null) {
158                 paymentRequestService.markPaid(pr, processDate);
159             } else {
160                 LOG.error("processPdpPaids() DOES NOT EXIST, CANNOT MARK - Payment Request with doc type of " + documentTypeCode + " with id " + documentNumber);
161             }
162         } else if (PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT.equals(documentTypeCode)) {
163             VendorCreditMemoDocument cm = creditMemoService.getCreditMemoByDocumentNumber(documentNumber);
164             if (cm != null) {
165                 creditMemoService.markPaid(cm, processDate);
166             } else {
167                 LOG.error("processPdpPaids() DOES NOT EXIST, CANNOT PROCESS - Credit Memo with doc type of " + documentTypeCode + " with id " + documentNumber);
168             }
169         }
170 
171     }
172 
173     public String getB2BUrlString() {
174         return PurapConstants.B2B_URL_STRING;
175     }
176 
177     public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
178         this.purchaseOrderService = purchaseOrderService;
179     }
180 
181     public void setDocumentService(DocumentService documentService) {
182         this.documentService = documentService;
183     }
184 
185     public void setPurapService(PurapService purapService) {
186         this.purapService = purapService;
187     }
188 
189 }
190