001 /* 002 * Copyright 2011 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 017 package org.kuali.kfs.module.purap.document; 018 019 import static org.kuali.kfs.sys.KFSConstants.GL_DEBIT_CODE; 020 021 import java.util.ArrayList; 022 import java.util.Iterator; 023 import java.util.List; 024 025 import org.kuali.kfs.module.purap.PurapConstants; 026 import org.kuali.kfs.module.purap.PurapConstants.PurapDocTypeCodes; 027 import org.kuali.kfs.module.purap.PurapWorkflowConstants.NodeDetails; 028 import org.kuali.kfs.module.purap.document.service.PurapService; 029 import org.kuali.kfs.module.purap.document.service.PurchaseOrderService; 030 import org.kuali.kfs.module.purap.service.PurapGeneralLedgerService; 031 import org.kuali.kfs.sys.KFSConstants; 032 import org.kuali.kfs.sys.businessobject.AccountingLine; 033 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry; 034 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail; 035 import org.kuali.kfs.sys.context.SpringContext; 036 import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO; 037 import org.kuali.rice.kns.rule.event.KualiDocumentEvent; 038 039 /** 040 * Purchase Order Reopen Document 041 */ 042 public class PurchaseOrderReopenDocument extends PurchaseOrderDocument { 043 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderReopenDocument.class); 044 045 /** 046 * Default constructor. 047 */ 048 public PurchaseOrderReopenDocument() { 049 super(); 050 } 051 052 /** 053 * General Ledger pending entries are not created on save for this document. They are created when the document has been finally 054 * processed. Overriding this method so that entries are not created yet. 055 * 056 * @see org.kuali.kfs.module.purap.document.PurchaseOrderDocument#prepareForSave(org.kuali.rice.kns.rule.event.KualiDocumentEvent) 057 */ 058 @Override 059 public void prepareForSave(KualiDocumentEvent event) { 060 LOG.info("prepareForSave(KualiDocumentEvent) do not create gl entries"); 061 setSourceAccountingLines(new ArrayList()); 062 setGeneralLedgerPendingEntries(new ArrayList()); 063 } 064 065 @Override 066 public List<Long> getWorkflowEngineDocumentIdsToLock() { 067 return super.getWorkflowEngineDocumentIdsToLock(); 068 } 069 070 /** 071 * When Purchase Order Reopen document has been processed through Workflow, the general ledger entries are created and the PO 072 * status changes to "OPEN". 073 * 074 * @see org.kuali.kfs.module.purap.document.PurchaseOrderDocument#doRouteStatusChange() 075 */ 076 @Override 077 public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) { 078 super.doRouteStatusChange(statusChangeEvent); 079 080 // DOCUMENT PROCESSED 081 if (getDocumentHeader().getWorkflowDocument().stateIsProcessed()) { 082 // generate GL entries 083 SpringContext.getBean(PurapGeneralLedgerService.class).generateEntriesReopenPurchaseOrder(this); 084 085 // update indicators 086 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this); 087 088 // set purap status 089 SpringContext.getBean(PurapService.class).updateStatus(this, PurapConstants.PurchaseOrderStatuses.OPEN); 090 } 091 // DOCUMENT DISAPPROVED 092 else if (getDocumentHeader().getWorkflowDocument().stateIsDisapproved()) { 093 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedReopenPODocuments(this); 094 } 095 // DOCUMENT CANCELED 096 else if (getDocumentHeader().getWorkflowDocument().stateIsCanceled()) { 097 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledReopenPODocuments(this); 098 } 099 100 } 101 102 public NodeDetails getNodeDetailEnum(String newNodeName) { 103 // no statuses to set means no node details 104 return null; 105 } 106 107 /** 108 * @see org.kuali.module.purap.rules.PurapAccountingDocumentRuleBase#customizeExplicitGeneralLedgerPendingEntry(org.kuali.kfs.sys.document.AccountingDocument, 109 * org.kuali.kfs.sys.businessobject.AccountingLine, org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) 110 */ 111 @Override 112 public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) { 113 super.customizeExplicitGeneralLedgerPendingEntry(postable, explicitEntry); 114 115 SpringContext.getBean(PurapGeneralLedgerService.class).customizeGeneralLedgerPendingEntry(this, (AccountingLine)postable, explicitEntry, getPurapDocumentIdentifier(), GL_DEBIT_CODE, PurapDocTypeCodes.PO_DOCUMENT, true); 116 117 // don't think i should have to override this, but default isn't getting the right PO doc 118 explicitEntry.setFinancialDocumentTypeCode(PurapDocTypeCodes.PO_REOPEN_DOCUMENT); 119 explicitEntry.setFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED); 120 } 121 122 @Override 123 public List<GeneralLedgerPendingEntrySourceDetail> getGeneralLedgerPendingEntrySourceDetails() { 124 List<GeneralLedgerPendingEntrySourceDetail> accountingLines = new ArrayList<GeneralLedgerPendingEntrySourceDetail>(); 125 if (getGlOnlySourceAccountingLines() != null) { 126 Iterator iter = getGlOnlySourceAccountingLines().iterator(); 127 while (iter.hasNext()) { 128 accountingLines.add((GeneralLedgerPendingEntrySourceDetail) iter.next()); 129 } 130 } 131 return accountingLines; 132 } 133 134 135 }