1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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.businessobject.PurchaseOrderView;
23  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
24  import org.kuali.ole.module.purap.service.PurapGeneralLedgerService;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.businessobject.AccountingLine;
27  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
28  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
29  import org.kuali.ole.sys.context.SpringContext;
30  import org.kuali.rice.kew.api.exception.WorkflowException;
31  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
32  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
33  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
34  
35  import java.util.ArrayList;
36  import java.util.Iterator;
37  import java.util.List;
38  
39  import static org.kuali.ole.sys.OLEConstants.GL_CREDIT_CODE;
40  
41  
42  
43  
44  public class PurchaseOrderCloseDocument extends PurchaseOrderDocument {
45      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderCloseDocument.class);
46  
47      
48  
49  
50  
51  
52  
53      @Override
54      public void prepareForSave(KualiDocumentEvent event) {
55          LOG.info("prepareForSave(KualiDocumentEvent) do not create gl entries");
56          setSourceAccountingLines(new ArrayList());
57          setGeneralLedgerPendingEntries(new ArrayList());
58      }
59  
60      
61  
62  
63  
64  
65  
66      @Override
67      public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
68          super.doRouteStatusChange(statusChangeEvent);
69  
70          try {
71              
72              if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isProcessed()) {
73                  
74                  
75  
76                  
77                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this);
78  
79                  
80                  updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_CLOSED);
81              }
82              
83              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
84                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedChangePODocuments(this);
85  
86                  
87                  try {
88                      String nodeName = SpringContext.getBean(WorkflowDocumentService.class).getCurrentRouteLevelName(this.getFinancialSystemDocumentHeader().getWorkflowDocument());
89                      String reqStatus = PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(nodeName);
90                      updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(reqStatus));
91  
92                  } catch (WorkflowException e) {
93                      logAndThrowRuntimeException("Error saving routing data while saving App Doc Status " + getDocumentNumber(), e);
94                  }
95  
96              }
97              
98              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
99                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledChangePODocuments(this);
100                 
101                 updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_CLOSED);
102             }
103         } catch (WorkflowException e) {
104             logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
105         }
106     }
107 
108     
109 
110 
111 
112     @Override
113     public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
114         super.customizeExplicitGeneralLedgerPendingEntry(postable, explicitEntry);
115 
116         SpringContext.getBean(PurapGeneralLedgerService.class).customizeGeneralLedgerPendingEntry(this, (AccountingLine) postable, explicitEntry, getPurapDocumentIdentifier(), GL_CREDIT_CODE, PurapDocTypeCodes.PO_DOCUMENT, true);
117 
118         
119         explicitEntry.setFinancialDocumentTypeCode(PurapDocTypeCodes.PO_CLOSE_DOCUMENT);
120         explicitEntry.setFinancialDocumentApprovedCode(OLEConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED);
121     }
122 
123     @Override
124     public List<GeneralLedgerPendingEntrySourceDetail> getGeneralLedgerPendingEntrySourceDetails() {
125         List<GeneralLedgerPendingEntrySourceDetail> accountingLines = new ArrayList<GeneralLedgerPendingEntrySourceDetail>();
126         if (getGlOnlySourceAccountingLines() != null) {
127             Iterator iter = getGlOnlySourceAccountingLines().iterator();
128             while (iter.hasNext()) {
129                 accountingLines.add((GeneralLedgerPendingEntrySourceDetail) iter.next());
130             }
131         }
132         return accountingLines;
133     }
134 
135     
136     @Override
137     public List<String> getWorkflowEngineDocumentIdsToLock() {
138         List<String> docIdStrings = new ArrayList<String>();
139         docIdStrings.add(getDocumentNumber());
140         String currentDocumentTypeName = this.getFinancialSystemDocumentHeader().getWorkflowDocument()
141                 .getDocumentTypeName();
142 
143         List<PurchaseOrderView> relatedPoViews = getRelatedViews().getRelatedPurchaseOrderViews();
144         for (PurchaseOrderView poView : relatedPoViews) {
145             if (poView.isPurchaseOrderCurrentIndicator()) {
146                 docIdStrings.add(poView.getDocumentNumber());
147             }
148         }
149         if (LOG.isDebugEnabled()) {
150             LOG.debug("***** getWorkflowEngineDocumentIdsToLock(" + this.documentNumber + ") = '" + docIdStrings + "'");
151         }
152         return docIdStrings;
153     }
154 
155 }