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.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
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
44
45 public PurchaseOrderRetransmitDocument() {
46 super();
47 }
48
49
50
51
52
53
54 @Override
55 public void customPrepareForSave(KualiDocumentEvent event) {
56
57 }
58
59
60
61
62
63
64 public KualiDecimal getTotalDollarAmountForRetransmit() {
65
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
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
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
108
109
110
111
112 @Override
113 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
114 super.doRouteStatusChange(statusChangeEvent);
115
116 try {
117
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
124 else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
125 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedChangePODocuments(this);
126
127
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
137 else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isCanceled()) {
138 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledChangePODocuments(this);
139
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 }