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.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_CREDIT_CODE;
39  
40  
41  
42  
43  public class PurchaseOrderVoidDocument extends PurchaseOrderDocument {
44      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderVoidDocument.class);
45  
46      
47  
48  
49  
50  
51  
52      @Override
53      public void prepareForSave(KualiDocumentEvent event) {
54          if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
55              setSourceAccountingLines(new ArrayList());
56              setGeneralLedgerPendingEntries(new ArrayList());
57          }
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                  SpringContext.getBean(PurapGeneralLedgerService.class).generateEntriesVoidPurchaseOrder(this);
75  
76                  
77                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this);
78  
79                  
80                  updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_VOID);
81              }
82              
83              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
84                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedChangePODocuments(this);
85                  
86                  try {
87                      String nodeName = SpringContext.getBean(WorkflowDocumentService.class).getCurrentRouteLevelName(this.getFinancialSystemDocumentHeader().getWorkflowDocument());
88                      String reqStatus = PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(nodeName);
89                      updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(reqStatus));
90                  } catch (WorkflowException e) {
91                      logAndThrowRuntimeException("Error saving routing data while saving App Doc Status " + getDocumentNumber(), e);
92                  }
93              }
94              
95              else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
96                  SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledChangePODocuments(this);
97                  
98                  updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_CANCELLED);
99              }
100         } catch (WorkflowException e) {
101             logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
102         }
103     }
104 
105     
106 
107 
108 
109     @Override
110     public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
111         super.customizeExplicitGeneralLedgerPendingEntry(postable, explicitEntry);
112 
113         SpringContext.getBean(PurapGeneralLedgerService.class).customizeGeneralLedgerPendingEntry(this, (AccountingLine) postable, explicitEntry, getPurapDocumentIdentifier(), GL_CREDIT_CODE, PurapDocTypeCodes.PO_DOCUMENT, true);
114 
115         
116         explicitEntry.setFinancialDocumentTypeCode(PurapDocTypeCodes.PO_VOID_DOCUMENT);
117         explicitEntry.setFinancialDocumentApprovedCode(OLEConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED);
118     }
119 
120     @Override
121     public List<GeneralLedgerPendingEntrySourceDetail> getGeneralLedgerPendingEntrySourceDetails() {
122         List<GeneralLedgerPendingEntrySourceDetail> accountingLines = new ArrayList<GeneralLedgerPendingEntrySourceDetail>();
123         if (getGlOnlySourceAccountingLines() != null) {
124             Iterator iter = getGlOnlySourceAccountingLines().iterator();
125             while (iter.hasNext()) {
126                 accountingLines.add((GeneralLedgerPendingEntrySourceDetail) iter.next());
127             }
128         }
129         return accountingLines;
130     }
131 
132 }