001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.kuali.kfs.module.purap.document;
018
019 import java.math.BigDecimal;
020 import java.util.List;
021
022 import org.kuali.kfs.module.purap.PurapConstants;
023 import org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem;
024 import org.kuali.kfs.module.purap.document.service.PurapService;
025 import org.kuali.kfs.module.purap.document.service.PurchaseOrderService;
026 import org.kuali.kfs.sys.context.SpringContext;
027 import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
028 import org.kuali.rice.kns.rule.event.KualiDocumentEvent;
029 import org.kuali.rice.kns.service.DateTimeService;
030 import org.kuali.rice.kns.util.KualiDecimal;
031
032 /**
033 * Purchase Order Retransmit Document
034 */
035 public class PurchaseOrderRetransmitDocument extends PurchaseOrderDocument {
036 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderRetransmitDocument.class);
037
038 protected boolean shouldDisplayRetransmitTab;
039
040 /**
041 * Default constructor.
042 */
043 public PurchaseOrderRetransmitDocument() {
044 super();
045 }
046
047 /**
048 * General Ledger pending entries are not created for this document. Overriding this method so that entries are not created.
049 *
050 * @see org.kuali.kfs.module.purap.document.PurchaseOrderDocument#customPrepareForSave(org.kuali.rice.kns.rule.event.KualiDocumentEvent)
051 */
052 @Override
053 public void customPrepareForSave(KualiDocumentEvent event) {
054 // do not set the accounts in sourceAccountingLines; this document should not create GL entries
055 }
056
057 /**
058 * Adds up the total amount of the items selected by the user for retransmit, then return the amount.
059 *
060 * @return KualiDecimal the total amount of the items selected by the user for retransmit.
061 */
062 public KualiDecimal getTotalDollarAmountForRetransmit() {
063 // We should only add up the amount of the items that were selected for retransmit.
064 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
065 for (PurchaseOrderItem item : (List<PurchaseOrderItem>) getItems()) {
066 if (item.isItemSelectedForRetransmitIndicator()) {
067 KualiDecimal totalAmount = item.getTotalAmount();
068 KualiDecimal itemTotal = (totalAmount != null) ? totalAmount : KualiDecimal.ZERO;
069 total = total.add(itemTotal);
070 }
071 }
072
073 return total;
074 }
075
076 public KualiDecimal getTotalPreTaxDollarAmountForRetransmit() {
077 // We should only add up the amount of the items that were selected for retransmit.
078 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
079 for (PurchaseOrderItem item : (List<PurchaseOrderItem>) getItems()) {
080 if (item.isItemSelectedForRetransmitIndicator()) {
081 KualiDecimal extendedPrice = item.getExtendedPrice();
082 KualiDecimal itemTotal = (extendedPrice != null) ? extendedPrice : KualiDecimal.ZERO;
083 total = total.add(itemTotal);
084 }
085 }
086
087 return total;
088 }
089
090 public KualiDecimal getTotalTaxDollarAmountForRetransmit() {
091 // We should only add up the amount of the items that were selected for retransmit.
092 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
093 for (PurchaseOrderItem item : (List<PurchaseOrderItem>) getItems()) {
094 if (item.isItemSelectedForRetransmitIndicator()) {
095 KualiDecimal taxAmount = item.getItemTaxAmount();
096 KualiDecimal itemTotal = (taxAmount != null) ? taxAmount : KualiDecimal.ZERO;
097 total = total.add(itemTotal);
098 }
099 }
100
101 return total;
102 }
103
104 @Override
105 public List<Long> getWorkflowEngineDocumentIdsToLock() {
106 return super.getWorkflowEngineDocumentIdsToLock();
107 }
108
109 /**
110 * When Purchase Order Retransmit document has been Processed through Workflow, the PO status remains to "OPEN" and the last
111 * transmit date is updated.
112 *
113 * @see org.kuali.kfs.module.purap.document.PurchaseOrderDocument#doRouteStatusChange()
114 */
115 @Override
116 public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) {
117 super.doRouteStatusChange(statusChangeEvent);
118
119 // DOCUMENT PROCESSED
120 if (getDocumentHeader().getWorkflowDocument().stateIsProcessed()) {
121 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForApprovedPODocuments(this);
122 setPurchaseOrderLastTransmitTimestamp(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
123 SpringContext.getBean(PurapService.class).updateStatus(this, PurapConstants.PurchaseOrderStatuses.OPEN);
124 }
125 // DOCUMENT DISAPPROVED
126 else if (getDocumentHeader().getWorkflowDocument().stateIsDisapproved()) {
127 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForDisapprovedChangePODocuments(this);
128 }
129 // DOCUMENT CANCELED
130 else if (getDocumentHeader().getWorkflowDocument().stateIsCanceled()) {
131 SpringContext.getBean(PurchaseOrderService.class).setCurrentAndPendingIndicatorsForCancelledChangePODocuments(this);
132 }
133
134 }
135
136 public boolean isShouldDisplayRetransmitTab() {
137 return shouldDisplayRetransmitTab;
138 }
139
140 public void setShouldDisplayRetransmitTab(boolean shouldDisplayRetransmitTab) {
141 this.shouldDisplayRetransmitTab = shouldDisplayRetransmitTab;
142 }
143
144 }