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.PurchaseOrderStatuses;
21  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
22  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.core.api.datetime.DateTimeService;
25  import org.kuali.rice.core.api.util.type.KualiDecimal;
26  import org.kuali.rice.kew.api.exception.WorkflowException;
27  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
28  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
29  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
30  
31  import java.math.BigDecimal;
32  import java.util.List;
33  
34  /**
35   * Purchase Order Retransmit Document
36   */
37  public class PurchaseOrderRetransmitDocument extends PurchaseOrderDocument {
38      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderRetransmitDocument.class);
39  
40      protected boolean shouldDisplayRetransmitTab;
41  
42      /**
43       * Default constructor.
44       */
45      public PurchaseOrderRetransmitDocument() {
46          super();
47      }
48  
49      /**
50       * General Ledger pending entries are not created for this document. Overriding this method so that entries are not created.
51       *
52       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#customPrepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
53       */
54      @Override
55      public void customPrepareForSave(KualiDocumentEvent event) {
56          // do not set the accounts in sourceAccountingLines; this document should not create GL entries
57      }
58  
59      /**
60       * Adds up the total amount of the items selected by the user for retransmit, then return the amount.
61       *
62       * @return KualiDecimal the total amount of the items selected by the user for retransmit.
63       */
64      public KualiDecimal getTotalDollarAmountForRetransmit() {
65          // We should only add up the amount of the items that were selected for retransmit.
66          KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
67          for (PurchaseOrderItem item : (List<PurchaseOrderItem>) getItems()) {
68              if (item.isItemSelectedForRetransmitIndicator()) {
69                  KualiDecimal totalAmount = item.getTotalAmount();
70                  KualiDecimal itemTotal = (totalAmount != null) ? totalAmount : KualiDecimal.ZERO;
71                  total = total.add(itemTotal);
72              }
73          }
74  
75          return total;
76      }
77  
78      public KualiDecimal getTotalPreTaxDollarAmountForRetransmit() {
79          // We should only add up the amount of the items that were selected for retransmit.
80          KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
81          for (PurchaseOrderItem item : (List<PurchaseOrderItem>) getItems()) {
82              if (item.isItemSelectedForRetransmitIndicator()) {
83                  KualiDecimal extendedPrice = item.getExtendedPrice();
84                  KualiDecimal itemTotal = (extendedPrice != null) ? extendedPrice : KualiDecimal.ZERO;
85                  total = total.add(itemTotal);
86              }
87          }
88  
89          return total;
90      }
91  
92      public KualiDecimal getTotalTaxDollarAmountForRetransmit() {
93          // We should only add up the amount of the items that were selected for retransmit.
94          KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
95          for (PurchaseOrderItem item : (List<PurchaseOrderItem>) getItems()) {
96              if (item.isItemSelectedForRetransmitIndicator()) {
97                  KualiDecimal taxAmount = item.getItemTaxAmount();
98                  KualiDecimal itemTotal = (taxAmount != null) ? taxAmount : KualiDecimal.ZERO;
99                  total = total.add(itemTotal);
100             }
101         }
102 
103         return total;
104     }
105 
106     /**
107      * When Purchase Order Retransmit document has been Processed through Workflow, the PO status remains to "OPEN" and the last
108      * transmit date is updated.
109      *
110      * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#doRouteStatusChange()
111      */
112     @Override
113     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
114         super.doRouteStatusChange(statusChangeEvent);
115 
116         try {
117             // DOCUMENT PROCESSED
118             if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isProcessed()) {
119                 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this);
120                 setPurchaseOrderLastTransmitTimestamp(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
121                 updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_OPEN);
122             }
123             // DOCUMENT DISAPPROVED
124             else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
125                 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedChangePODocuments(this);
126 
127                 // for app doc status
128                 try {
129                     String nodeName = SpringContext.getBean(WorkflowDocumentService.class).getCurrentRouteLevelName(this.getFinancialSystemDocumentHeader().getWorkflowDocument());
130                     String reqStatus = PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(nodeName);
131                     updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.getPurchaseOrderAppDocDisapproveStatuses().get(reqStatus));
132                 } catch (WorkflowException e) {
133                     logAndThrowRuntimeException("Error saving routing data while saving App Doc Status " + getDocumentNumber(), e);
134                 }
135             }
136             // DOCUMENT CANCELED
137             else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
138                 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledChangePODocuments(this);
139                 // for app doc status
140                 updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.APPDOC_CANCELLED);
141             }
142         } catch (WorkflowException e) {
143             logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
144         }
145     }
146 
147     public boolean isShouldDisplayRetransmitTab() {
148         return shouldDisplayRetransmitTab;
149     }
150 
151     public void setShouldDisplayRetransmitTab(boolean shouldDisplayRetransmitTab) {
152         this.shouldDisplayRetransmitTab = shouldDisplayRetransmitTab;
153     }
154 
155 }