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.PurapDocTypeCodes;
21  import org.kuali.ole.module.purap.PurapConstants.PurchaseOrderStatuses;
22  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
23  import org.kuali.ole.module.purap.service.PurapGeneralLedgerService;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.businessobject.AccountingLine;
26  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
27  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
28  import org.kuali.ole.sys.context.SpringContext;
29  import org.kuali.rice.kew.api.exception.WorkflowException;
30  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
31  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
32  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
33  
34  import java.util.ArrayList;
35  import java.util.Iterator;
36  import java.util.List;
37  
38  import static org.kuali.ole.sys.OLEConstants.GL_DEBIT_CODE;
39  
40  /**
41   * Purchase Order Reopen Document
42   */
43  public class PurchaseOrderReopenDocument extends PurchaseOrderDocument {
44      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderReopenDocument.class);
45  
46      /**
47       * General Ledger pending entries are not created on save for this document. They are created when the document has been finally
48       * processed. Overriding this method so that entries are not created yet.
49       *
50       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
51       */
52      @Override
53      public void prepareForSave(KualiDocumentEvent event) {
54          LOG.info("prepareForSave(KualiDocumentEvent) do not create gl entries");
55         // setSourceAccountingLines(new ArrayList());
56         // setGeneralLedgerPendingEntries(new ArrayList());
57          super.prepareForSave(event);
58      }
59  
60      /**
61       * When Purchase Order Reopen document has been processed through Workflow, the general ledger entries are created and the PO
62       * status changes to "OPEN".
63       *
64       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#doRouteStatusChange()
65       */
66      @Override
67      public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
68          super.doRouteStatusChange(statusChangeEvent);
69  
70          try {
71              // DOCUMENT PROCESSED
72              if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isProcessed()) {
73                  // generate GL entries
74                  SpringContext.getBean(PurapGeneralLedgerService.class).generateEntriesReopenPurchaseOrder(this);
75  
76                  // update indicators
77                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this);
78  
79                  // set purap status
80                  updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_OPEN);
81              }
82              // DOCUMENT DISAPPROVED
83              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
84                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedReopenPODocuments(this);
85  
86                  // for app doc status
87                  try {
88                      String nodeName = SpringContext.getBean(WorkflowDocumentService.class).getCurrentRouteLevelName(this.getFinancialSystemDocumentHeader().getWorkflowDocument());
89                      String reqStatus = PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(nodeName);
90                      updateAndSaveAppDocStatus(reqStatus);
91                  } catch (WorkflowException e) {
92                      logAndThrowRuntimeException("Error saving routing data while saving App Doc Status " + getDocumentNumber(), e);
93                  }
94              }
95              // DOCUMENT CANCELED
96              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
97                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledReopenPODocuments(this);
98                  // for app doc status
99                  updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_CANCELLED);
100             }
101         } catch (WorkflowException e) {
102             logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
103         }
104     }
105 
106     /**
107      * @see org.kuali.module.purap.rules.PurapAccountingDocumentRuleBase#customizeExplicitGeneralLedgerPendingEntry(org.kuali.ole.sys.document.AccountingDocument,
108      *      org.kuali.ole.sys.businessobject.AccountingLine, org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry)
109      */
110     @Override
111     public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
112         super.customizeExplicitGeneralLedgerPendingEntry(postable, explicitEntry);
113 
114         SpringContext.getBean(PurapGeneralLedgerService.class).customizeGeneralLedgerPendingEntry(this, (AccountingLine) postable, explicitEntry, getPurapDocumentIdentifier(), GL_DEBIT_CODE, PurapDocTypeCodes.PO_DOCUMENT, true);
115 
116         // don't think i should have to override this, but default isn't getting the right PO doc
117         explicitEntry.setFinancialDocumentTypeCode(PurapDocTypeCodes.PO_REOPEN_DOCUMENT);
118         explicitEntry.setFinancialDocumentApprovedCode(OLEConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED);
119     }
120 
121     @Override
122     public List<GeneralLedgerPendingEntrySourceDetail> getGeneralLedgerPendingEntrySourceDetails() {
123         List<GeneralLedgerPendingEntrySourceDetail> accountingLines = new ArrayList<GeneralLedgerPendingEntrySourceDetail>();
124         if (getGlOnlySourceAccountingLines() != null) {
125             Iterator iter = getGlOnlySourceAccountingLines().iterator();
126             while (iter.hasNext()) {
127                 accountingLines.add((GeneralLedgerPendingEntrySourceDetail) iter.next());
128             }
129         }
130         return accountingLines;
131     }
132 
133 
134 }