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.HashMap;
021: import java.util.Iterator;
022:
023: import org.kuali.core.util.KualiDecimal;
024: import org.kuali.core.util.ObjectUtils;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.module.purap.document.CreditMemoDocument;
027: import org.kuali.module.purap.service.AccountsPayableService;
028: import org.kuali.module.purap.util.ExpiredOrClosedAccountEntry;
029:
030: /**
031: * Item line Business Object for Credit Memo Document.
032: */
033: public class CreditMemoItem extends AccountsPayableItemBase {
034: private KualiDecimal poInvoicedTotalQuantity;
035: private BigDecimal poUnitPrice;
036: private KualiDecimal poExtendedPrice;
037: private KualiDecimal preqInvoicedTotalQuantity;
038: private BigDecimal preqUnitPrice;
039: private KualiDecimal preqExtendedPrice;
040:
041: /**
042: * Default constructor.
043: */
044: public CreditMemoItem() {
045: }
046:
047: /**
048: * Constructs a CreditMemoItem object from an existing Purchase Order Item. - Delegate
049: *
050: * @param cmDocument the Credit Memo Document this item belongs to.
051: * @param poItem the Purchase Order Item to copy from.
052: */
053: public CreditMemoItem(CreditMemoDocument cmDocument,
054: PurchaseOrderItem poItem) {
055: this (cmDocument, poItem,
056: new HashMap<String, ExpiredOrClosedAccountEntry>());
057: }
058:
059: /**
060: * Constructs a CreditMemoItem object from an existing Purchase Order Item, and check and process expired or closed accounts
061: * item might contain.
062: *
063: * @param cmDocument the Credit Memo Document this item belongs to.
064: * @param poItem the Purchase Order Item to copy from.
065: * @param expiredOrClosedAccountList the list of expired or closed accounts to check against.
066: */
067: public CreditMemoItem(
068: CreditMemoDocument cmDocument,
069: PurchaseOrderItem poItem,
070: HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
071: super ();
072:
073: setPurapDocumentIdentifier(cmDocument
074: .getPurapDocumentIdentifier());
075: setItemLineNumber(poItem.getItemLineNumber());
076: setPoInvoicedTotalQuantity(poItem
077: .getItemInvoicedTotalQuantity());
078: setPoUnitPrice(poItem.getItemUnitPrice());
079: setPoExtendedPrice(poItem.getItemInvoicedTotalAmount());
080: setItemTypeCode(poItem.getItemTypeCode());
081:
082: if ((ObjectUtils.isNotNull(this .getItemType()) && !this
083: .getItemType().isQuantityBasedGeneralLedgerIndicator())) {
084: // setting unit price to be null to be more consistent with other below the line
085: this .setItemUnitPrice(null);
086: } else {
087: setItemUnitPrice(poItem.getItemUnitPrice());
088: }
089:
090: setItemCatalogNumber(poItem.getItemCatalogNumber());
091: setItemDescription(poItem.getItemDescription());
092:
093: if (getPoInvoicedTotalQuantity() == null) {
094: setPoInvoicedTotalQuantity(KualiDecimal.ZERO);
095: }
096: if (getPoUnitPrice() == null) {
097: setPoUnitPrice(BigDecimal.ZERO);
098: }
099: if (getPoExtendedPrice() == null) {
100: setPoExtendedPrice(KualiDecimal.ZERO);
101: }
102:
103: for (Iterator iter = poItem.getSourceAccountingLines()
104: .iterator(); iter.hasNext();) {
105: PurchaseOrderAccount account = (PurchaseOrderAccount) iter
106: .next();
107:
108: // check if this account is expired/closed and replace as needed
109: SpringContext.getBean(AccountsPayableService.class)
110: .processExpiredOrClosedAccount(account,
111: expiredOrClosedAccountList);
112:
113: getSourceAccountingLines().add(
114: new CreditMemoAccount(account));
115: }
116: }
117:
118: /**
119: * Constructs a CreditMemoItem object from an existing Payment Request or Purchase Order Item.
120: *
121: * @param cmDocument the Credit Memo Document this item belongs to.
122: * @param preqItem the Payment Request Item to copy from.
123: * @param poItem the Purchase Order Item to copy from.
124: */
125: public CreditMemoItem(CreditMemoDocument cmDocument,
126: PaymentRequestItem preqItem, PurchaseOrderItem poItem) {
127: super ();
128:
129: setPurapDocumentIdentifier(cmDocument
130: .getPurapDocumentIdentifier());
131: setItemLineNumber(preqItem.getItemLineNumber());
132:
133: // take invoiced quantities from the lower of the preq and po if different
134: if (poItem.getItemInvoicedTotalQuantity() != null
135: && preqItem.getItemQuantity() != null
136: && poItem.getItemInvoicedTotalQuantity().isLessThan(
137: preqItem.getItemQuantity())) {
138: setPreqInvoicedTotalQuantity(poItem
139: .getItemInvoicedTotalQuantity());
140: setPreqExtendedPrice(poItem.getItemInvoicedTotalAmount());
141: } else {
142: setPreqInvoicedTotalQuantity(preqItem.getItemQuantity());
143: setPreqExtendedPrice(preqItem.getExtendedPrice());
144: }
145:
146: setPreqUnitPrice(preqItem.getItemUnitPrice());
147: setItemTypeCode(preqItem.getItemTypeCode());
148:
149: if ((ObjectUtils.isNotNull(this .getItemType()) && !this
150: .getItemType().isQuantityBasedGeneralLedgerIndicator())) {
151: // setting unit price to be null to be more consistent with other below the line
152: this .setItemUnitPrice(null);
153: } else {
154: setItemUnitPrice(preqItem.getItemUnitPrice());
155: }
156:
157: setItemCatalogNumber(preqItem.getItemCatalogNumber());
158: setItemDescription(preqItem.getItemDescription());
159:
160: if (getPreqInvoicedTotalQuantity() == null) {
161: setPreqInvoicedTotalQuantity(KualiDecimal.ZERO);
162: }
163: if (getPreqUnitPrice() == null) {
164: setPreqUnitPrice(BigDecimal.ZERO);
165: }
166: if (getPreqExtendedPrice() == null) {
167: setPreqExtendedPrice(KualiDecimal.ZERO);
168: }
169:
170: for (Iterator iter = preqItem.getSourceAccountingLines()
171: .iterator(); iter.hasNext();) {
172: PaymentRequestAccount account = (PaymentRequestAccount) iter
173: .next();
174: getSourceAccountingLines().add(
175: new CreditMemoAccount(account));
176: }
177: }
178:
179: /**
180: * Constructs a CreditMemoItem object from an existing Payment Request Item, and check and process expired or closed accounts
181: * item might contain.
182: *
183: * @param cmDocument the Credit Memo Document this item belongs to.
184: * @param preqItem the Payment Request Item to copy from.
185: * @param poItem the Purchase Order Item to copy from.
186: * @param expiredOrClosedAccountList the list of expired or closed accounts to check against.
187: */
188: public CreditMemoItem(
189: CreditMemoDocument cmDocument,
190: PaymentRequestItem preqItem,
191: PurchaseOrderItem poItem,
192: HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
193: super ();
194:
195: setPurapDocumentIdentifier(cmDocument
196: .getPurapDocumentIdentifier());
197: setItemLineNumber(preqItem.getItemLineNumber());
198:
199: // take invoiced quantities from the lower of the preq and po if different
200: if (poItem.getItemInvoicedTotalQuantity() != null
201: && preqItem.getItemQuantity() != null
202: && poItem.getItemInvoicedTotalQuantity().isLessThan(
203: preqItem.getItemQuantity())) {
204: setPreqInvoicedTotalQuantity(poItem
205: .getItemInvoicedTotalQuantity());
206: setPreqExtendedPrice(poItem.getItemInvoicedTotalAmount());
207: } else {
208: setPreqInvoicedTotalQuantity(preqItem.getItemQuantity());
209: setPreqExtendedPrice(preqItem.getExtendedPrice());
210: }
211:
212: setPreqUnitPrice(preqItem.getItemUnitPrice());
213: setItemTypeCode(preqItem.getItemTypeCode());
214: setItemUnitPrice(preqItem.getItemUnitPrice());
215: setItemCatalogNumber(preqItem.getItemCatalogNumber());
216: setItemDescription(preqItem.getItemDescription());
217:
218: if (getPreqInvoicedTotalQuantity() == null) {
219: setPreqInvoicedTotalQuantity(KualiDecimal.ZERO);
220: }
221: if (getPreqUnitPrice() == null) {
222: setPreqUnitPrice(BigDecimal.ZERO);
223: }
224: if (getPreqExtendedPrice() == null) {
225: setPreqExtendedPrice(KualiDecimal.ZERO);
226: }
227:
228: for (Iterator iter = preqItem.getSourceAccountingLines()
229: .iterator(); iter.hasNext();) {
230: PaymentRequestAccount account = (PaymentRequestAccount) iter
231: .next();
232:
233: // check if this account is expired/closed and replace as needed
234: SpringContext.getBean(AccountsPayableService.class)
235: .processExpiredOrClosedAccount(account,
236: expiredOrClosedAccountList);
237:
238: getSourceAccountingLines().add(
239: new CreditMemoAccount(account));
240: }
241: }
242:
243: /**
244: * @see org.kuali.module.purap.bo.PurApItemBase#getAccountingLineClass()
245: */
246: @Override
247: public Class<CreditMemoAccount> getAccountingLineClass() {
248: return CreditMemoAccount.class;
249: }
250:
251: public KualiDecimal getPoExtendedPrice() {
252: return poExtendedPrice;
253: }
254:
255: public void setPoExtendedPrice(KualiDecimal poExtendedCost) {
256: this .poExtendedPrice = poExtendedCost;
257: }
258:
259: public KualiDecimal getPoInvoicedTotalQuantity() {
260: return poInvoicedTotalQuantity;
261: }
262:
263: public void setPoInvoicedTotalQuantity(
264: KualiDecimal poInvoicedTotalQuantity) {
265: this .poInvoicedTotalQuantity = poInvoicedTotalQuantity;
266: }
267:
268: public BigDecimal getPoUnitPrice() {
269: return poUnitPrice;
270: }
271:
272: public void setPoUnitPrice(BigDecimal poUnitPrice) {
273: this .poUnitPrice = poUnitPrice;
274: }
275:
276: public KualiDecimal getPreqExtendedPrice() {
277: return preqExtendedPrice;
278: }
279:
280: public void setPreqExtendedPrice(KualiDecimal preqExtendedCost) {
281: this .preqExtendedPrice = preqExtendedCost;
282: }
283:
284: public KualiDecimal getPreqInvoicedTotalQuantity() {
285: return preqInvoicedTotalQuantity;
286: }
287:
288: public void setPreqInvoicedTotalQuantity(
289: KualiDecimal preqInvoicedTotalQuantity) {
290: this .preqInvoicedTotalQuantity = preqInvoicedTotalQuantity;
291: }
292:
293: public BigDecimal getPreqUnitPrice() {
294: return preqUnitPrice;
295: }
296:
297: public void setPreqUnitPrice(BigDecimal preqUnitPrice) {
298: this.preqUnitPrice = preqUnitPrice;
299: }
300: }
|