001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.bo;
018:
019: import java.math.BigDecimal;
020: import java.util.ArrayList;
021: import java.util.LinkedHashMap;
022: import java.util.List;
023:
024: import org.kuali.core.util.KualiDecimal;
025: import org.kuali.core.util.ObjectUtils;
026: import org.kuali.module.purap.PurapPropertyConstants;
027: import org.kuali.module.purap.document.PurchaseOrderDocument;
028:
029: /**
030: * Purchase Order Item Business Object.
031: */
032: public class PurchaseOrderItem extends PurchasingItemBase {
033: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
034: .getLogger(PurchaseOrderItem.class);
035:
036: private String documentNumber;
037: private KualiDecimal itemInvoicedTotalQuantity;
038: private KualiDecimal itemInvoicedTotalAmount;
039: private KualiDecimal itemReceivedTotalQuantity;
040: private KualiDecimal itemReturnedTotalQuantity;
041: private KualiDecimal itemOutstandingEncumberedQuantity;
042: private KualiDecimal itemOutstandingEncumberedAmount;
043: private boolean itemActiveIndicator = true;
044: private String purchaseOrderCommodityCd;
045:
046: private PurchaseOrderDocument purchaseOrder;
047:
048: // Not persisted to DB
049: private boolean itemSelectedForRetransmitIndicator;
050:
051: /**
052: * Default constructor.
053: */
054: public PurchaseOrderItem() {
055:
056: }
057:
058: /**
059: * Constructor.
060: *
061: * @param ri - Requisition Item
062: * @param po - Purchase Order Document
063: */
064: public PurchaseOrderItem(RequisitionItem ri,
065: PurchaseOrderDocument po) {
066: super ();
067:
068: this .setPurchaseOrder(po);
069:
070: this .setItemLineNumber(ri.getItemLineNumber());
071: this .setItemUnitOfMeasureCode(ri.getItemUnitOfMeasureCode());
072: this .setItemQuantity(ri.getItemQuantity());
073: this .setItemCatalogNumber(ri.getItemCatalogNumber());
074: this .setItemDescription(ri.getItemDescription());
075: this .setItemCapitalAssetNoteText(ri
076: .getItemCapitalAssetNoteText());
077: this .setItemUnitPrice(ri.getItemUnitPrice());
078: this .setItemAuxiliaryPartIdentifier(ri
079: .getItemAuxiliaryPartIdentifier());
080: this .setItemAssignedToTradeInIndicator(ri
081: .getItemAssignedToTradeInIndicator());
082:
083: this .setExternalOrganizationB2bProductReferenceNumber(ri
084: .getExternalOrganizationB2bProductReferenceNumber());
085: this .setExternalOrganizationB2bProductTypeName(ri
086: .getExternalOrganizationB2bProductTypeName());
087:
088: this .setCapitalAssetTransactionTypeCode(ri
089: .getCapitalAssetTransactionTypeCode());
090: this .setItemTypeCode(ri.getItemTypeCode());
091:
092: if (ri.getSourceAccountingLines() != null
093: && ri.getSourceAccountingLines().size() > 0) {
094: List accounts = new ArrayList();
095: for (PurApAccountingLine account : ri
096: .getSourceAccountingLines()) {
097: PurchaseOrderAccount poAccount = new PurchaseOrderAccount(
098: account);
099: poAccount.setPurchaseOrderItem(this );
100: accounts.add(poAccount);
101: }
102: this .setSourceAccountingLines(accounts);
103: }
104: // By default, set the item active indicator to true.
105: // In amendment, the user can set it to false when they click on
106: // the inactivate button.
107: this .setItemActiveIndicator(true);
108: }
109:
110: public boolean isItemActiveIndicator() {
111: return itemActiveIndicator;
112: }
113:
114: public void setItemActiveIndicator(boolean itemActiveIndicator) {
115: this .itemActiveIndicator = itemActiveIndicator;
116: }
117:
118: public KualiDecimal getItemInvoicedTotalAmount() {
119: return itemInvoicedTotalAmount;
120: }
121:
122: public void setItemInvoicedTotalAmount(
123: KualiDecimal itemInvoicedTotalAmount) {
124: this .itemInvoicedTotalAmount = itemInvoicedTotalAmount;
125: }
126:
127: public KualiDecimal getItemInvoicedTotalQuantity() {
128: return itemInvoicedTotalQuantity;
129: }
130:
131: public void setItemInvoicedTotalQuantity(
132: KualiDecimal itemInvoicedTotalQuantity) {
133: this .itemInvoicedTotalQuantity = itemInvoicedTotalQuantity;
134: }
135:
136: public KualiDecimal getItemOutstandingEncumberedQuantity() {
137: return itemOutstandingEncumberedQuantity;
138: }
139:
140: public void setItemOutstandingEncumberedQuantity(
141: KualiDecimal itemOutstandingEncumberedQuantity) {
142: this .itemOutstandingEncumberedQuantity = itemOutstandingEncumberedQuantity;
143: }
144:
145: public KualiDecimal getItemOutstandingEncumberedAmount() {
146: return itemOutstandingEncumberedAmount;
147: }
148:
149: public void setItemOutstandingEncumberedAmount(
150: KualiDecimal itemOutstandingEncumbranceAmount) {
151: this .itemOutstandingEncumberedAmount = itemOutstandingEncumbranceAmount;
152: }
153:
154: public KualiDecimal getItemReceivedTotalQuantity() {
155: return itemReceivedTotalQuantity;
156: }
157:
158: public void setItemReceivedTotalQuantity(
159: KualiDecimal itemReceivedTotalQuantity) {
160: this .itemReceivedTotalQuantity = itemReceivedTotalQuantity;
161: }
162:
163: public KualiDecimal getItemReturnedTotalQuantity() {
164: return itemReturnedTotalQuantity;
165: }
166:
167: public void setItemReturnedTotalQuantity(
168: KualiDecimal itemReturnedTotalQuantity) {
169: this .itemReturnedTotalQuantity = itemReturnedTotalQuantity;
170: }
171:
172: public PurchaseOrderDocument getPurchaseOrder() {
173: if (ObjectUtils.isNull(purchaseOrder)) {
174: refreshReferenceObject(PurapPropertyConstants.PURCHASE_ORDER);
175: }
176: return purchaseOrder;
177: }
178:
179: public void setPurchaseOrder(PurchaseOrderDocument purchaseOrder) {
180: this .purchaseOrder = purchaseOrder;
181: }
182:
183: public String getPurchaseOrderCommodityCd() {
184: return purchaseOrderCommodityCd;
185: }
186:
187: public void setPurchaseOrderCommodityCd(
188: String purchaseOrderCommodityCd) {
189: this .purchaseOrderCommodityCd = purchaseOrderCommodityCd;
190: }
191:
192: public String getDocumentNumber() {
193: return documentNumber;
194: }
195:
196: public void setDocumentNumber(String documentNumber) {
197: this .documentNumber = documentNumber;
198: }
199:
200: public boolean isItemSelectedForRetransmitIndicator() {
201: return itemSelectedForRetransmitIndicator;
202: }
203:
204: public void setItemSelectedForRetransmitIndicator(
205: boolean itemSelectedForRetransmitIndicator) {
206: this .itemSelectedForRetransmitIndicator = itemSelectedForRetransmitIndicator;
207: }
208:
209: /**
210: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
211: */
212: @Override
213: protected LinkedHashMap toStringMapper() {
214: LinkedHashMap m = new LinkedHashMap();
215: m.put("documentNumber", this .documentNumber);
216: if (this .getItemIdentifier() != null) {
217: m
218: .put("itemIdentifier", this .getItemIdentifier()
219: .toString());
220: }
221: return m;
222: }
223:
224: /**
225: * @see org.kuali.module.purap.bo.PurApItem#getAccountingLineClass()
226: */
227: public Class getAccountingLineClass() {
228: return PurchaseOrderAccount.class;
229: }
230:
231: /**
232: *
233: * This method returns the total item paid amount
234: * @return
235: */
236: public KualiDecimal getItemPaidAmount() {
237: if (!(this .isItemActiveIndicator())) {
238: return KualiDecimal.ZERO;
239: }
240: return this .getItemInvoicedTotalAmount();
241: }
242:
243: public KualiDecimal getItemEncumbranceRelievedAmount() {
244: // check that it is active else return zero
245: if (this == null || !this .isItemActiveIndicator()) {
246: return KualiDecimal.ZERO;
247: }
248: // setup outstanding amount and get totalEncumberance from this.getExtendedCost()
249: KualiDecimal outstandingAmount = KualiDecimal.ZERO;
250: KualiDecimal totalEncumberance = this .getExtendedPrice();
251:
252: ItemType iT = this .getItemType();
253: // if service add the po outstanding amount to outstandingamount
254: if (!iT.isQuantityBasedGeneralLedgerIndicator()) {
255: outstandingAmount = outstandingAmount.add(this
256: .getItemOutstandingEncumberedAmount());
257: } else {
258: // else add outstanding quantity * unitprice
259: BigDecimal qty = new BigDecimal(this
260: .getOutstandingQuantity().toString());
261: outstandingAmount = outstandingAmount.add(new KualiDecimal(
262: this .getItemUnitPrice().multiply(qty)));
263: }
264:
265: // return the total encumberance subtracted by the outstandingamount from above
266: return totalEncumberance.subtract(outstandingAmount);
267: }
268:
269: public KualiDecimal getOutstandingQuantity() {
270: KualiDecimal outstandingQuantity = (this .getItemQuantity() != null) ? this
271: .getItemQuantity()
272: : KualiDecimal.ZERO;
273: KualiDecimal invoicedQuantity = (this
274: .getItemInvoicedTotalQuantity() != null) ? this
275: .getItemInvoicedTotalQuantity() : KualiDecimal.ZERO;
276: return outstandingQuantity.subtract(invoicedQuantity);
277: }
278:
279: public boolean isCanInactivateItem() {
280: if (versionNumber == null) {
281: // don't allow newly added item to be inactivatable.
282: return false;
283: } else if (versionNumber != null
284: && itemActiveIndicator
285: && !getPurchaseOrder()
286: .getContainsUnpaidPaymentRequestsOrCreditMemos()) {
287: return true;
288: }
289: return false;
290: }
291: }
|