View Javadoc
1   /*
2    * Copyright 2007 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  
17  package org.kuali.ole.module.purap.document;
18  
19  import org.kuali.ole.module.purap.PurapConstants;
20  import org.kuali.ole.module.purap.PurapConstants.PurchaseOrderStatuses;
21  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.kew.api.exception.WorkflowException;
24  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
25  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
26  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
27  
28  /**
29   * Purchase Order Payment Hold Document
30   */
31  public class PurchaseOrderPaymentHoldDocument extends PurchaseOrderDocument {
32      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderPaymentHoldDocument.class);
33  
34      /**
35       * General Ledger pending entries are not created for this document. Overriding this method so that entries are not created.
36       *
37       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#customPrepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
38       */
39      @Override
40      public void customPrepareForSave(KualiDocumentEvent event) {
41          // do not set the accounts in sourceAccountingLines; this document should not create GL entries
42      }
43  
44      /**
45       * When Purchase Order Payment Hold document has been Processed through Workflow, the PO status changes to "Payment Hold".
46       *
47       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#doRouteStatusChange()
48       */
49      @Override
50      public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
51          super.doRouteStatusChange(statusChangeEvent);
52  
53          try {
54              // DOCUMENT PROCESSED
55              if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isProcessed()) {
56                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this);
57  
58                  // for app doc status
59                  updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_PAYMENT_HOLD);
60              }
61              // DOCUMENT DISAPPROVED
62              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
63                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedChangePODocuments(this);
64  
65                  // for app doc status
66                  try {
67                      String nodeName = SpringContext.getBean(WorkflowDocumentService.class).getCurrentRouteLevelName(this.getFinancialSystemDocumentHeader().getWorkflowDocument());
68                      String reqStatus = PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(nodeName);
69                      updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(reqStatus));
70                  } catch (WorkflowException e) {
71                      logAndThrowRuntimeException("Error saving routing data while saving App Doc Status " + getDocumentNumber(), e);
72                  }
73  
74              }
75              // DOCUMENT CANCELED
76              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
77                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledChangePODocuments(this);
78                  // for app doc status
79                  updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.APPDOC_CANCELLED);
80              }
81          } catch (WorkflowException e) {
82              logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
83          }
84      }
85  }