001/*
002 * Copyright 2007 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 */
016
017package org.kuali.ole.module.purap.document;
018
019import org.kuali.ole.module.purap.PurapConstants;
020import org.kuali.ole.module.purap.PurapConstants.PurchaseOrderStatuses;
021import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
022import org.kuali.ole.sys.context.SpringContext;
023import org.kuali.rice.kew.api.exception.WorkflowException;
024import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
025import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
026import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
027
028/**
029 * Purchase Order Payment Hold Document
030 */
031public class PurchaseOrderPaymentHoldDocument extends PurchaseOrderDocument {
032    protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderPaymentHoldDocument.class);
033
034    /**
035     * General Ledger pending entries are not created for this document. Overriding this method so that entries are not created.
036     *
037     * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#customPrepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
038     */
039    @Override
040    public void customPrepareForSave(KualiDocumentEvent event) {
041        // do not set the accounts in sourceAccountingLines; this document should not create GL entries
042    }
043
044    /**
045     * When Purchase Order Payment Hold document has been Processed through Workflow, the PO status changes to "Payment Hold".
046     *
047     * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#doRouteStatusChange()
048     */
049    @Override
050    public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
051        super.doRouteStatusChange(statusChangeEvent);
052
053        try {
054            // DOCUMENT PROCESSED
055            if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isProcessed()) {
056                SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this);
057
058                // for app doc status
059                updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_PAYMENT_HOLD);
060            }
061            // DOCUMENT DISAPPROVED
062            else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
063                SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedChangePODocuments(this);
064
065                // for app doc status
066                try {
067                    String nodeName = SpringContext.getBean(WorkflowDocumentService.class).getCurrentRouteLevelName(this.getFinancialSystemDocumentHeader().getWorkflowDocument());
068                    String reqStatus = PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(nodeName);
069                    updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(reqStatus));
070                } catch (WorkflowException e) {
071                    logAndThrowRuntimeException("Error saving routing data while saving App Doc Status " + getDocumentNumber(), e);
072                }
073
074            }
075            // DOCUMENT CANCELED
076            else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
077                SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledChangePODocuments(this);
078                // for app doc status
079                updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.APPDOC_CANCELLED);
080            }
081        } catch (WorkflowException e) {
082            logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
083        }
084    }
085}