View Javadoc
1   /*
2    * Copyright 2012 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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  package org.kuali.ole.select.businessobject;
17  
18  import org.kuali.ole.DocumentUniqueIDPrefix;
19  import org.kuali.ole.module.purap.businessobject.CreditMemoItem;
20  import org.kuali.ole.module.purap.businessobject.PaymentRequestAccount;
21  import org.kuali.ole.module.purap.businessobject.PurApAccountingLineBase;
22  import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
23  import org.kuali.ole.module.purap.document.service.AccountsPayableService;
24  import org.kuali.ole.module.purap.document.service.PurapService;
25  import org.kuali.ole.module.purap.util.ExpiredOrClosedAccountEntry;
26  import org.kuali.ole.pojo.OleOrderRecord;
27  import org.kuali.ole.select.OleSelectConstant;
28  import org.kuali.ole.select.document.OleVendorCreditMemoDocument;
29  import org.kuali.ole.select.lookup.DocData;
30  import org.kuali.ole.sys.context.SpringContext;
31  import org.kuali.rice.core.api.util.type.KualiDecimal;
32  import org.kuali.rice.krad.service.BusinessObjectService;
33  import org.kuali.rice.krad.util.ObjectUtils;
34  
35  import java.math.BigDecimal;
36  import java.util.HashMap;
37  
38  public class OleCreditMemoItem extends CreditMemoItem {
39  
40      // Foreign Currency Conversion
41      protected String itemCurrencyType;
42      protected KualiDecimal itemForeignListPrice;
43      protected KualiDecimal itemForeignDiscount;
44      protected String itemForeignDiscountType;
45      protected KualiDecimal itemForeignDiscountAmt;
46      protected KualiDecimal itemForeignUnitCost;
47      protected KualiDecimal itemExchangeRate;
48      protected KualiDecimal itemUnitCostUSD;
49      //Bib details
50      private BibInfoBean bibInfoBean;
51      private DocData docData;
52      private OleOrderRecord oleOrderRecord;
53      protected String itemTitleId;
54      protected String bibUUID;
55      private String docFormat;
56      protected BigDecimal itemSurcharge;
57  
58      protected KualiDecimal foreignCurrencyExtendedPrice;
59      protected boolean additionalChargeUsd;
60  
61      public BibInfoBean getBibInfoBean() {
62          return bibInfoBean;
63      }
64  
65      public void setBibInfoBean(BibInfoBean bibInfoBean) {
66          this.bibInfoBean = bibInfoBean;
67      }
68  
69      public DocData getDocData() {
70          return docData;
71      }
72  
73      public void setDocData(DocData docData) {
74          this.docData = docData;
75      }
76  
77      public OleOrderRecord getOleOrderRecord() {
78          return oleOrderRecord;
79      }
80  
81      public void setOleOrderRecord(OleOrderRecord oleOrderRecord) {
82          this.oleOrderRecord = oleOrderRecord;
83      }
84  
85      public String getItemTitleId() {
86          return itemTitleId;
87      }
88  
89      public void setItemTitleId(String itemTitleId) {
90          this.itemTitleId = itemTitleId;
91      }
92  
93      public String getBibUUID() {
94          return bibUUID;
95      }
96  
97      public void setBibUUID(String bibUUID) {
98          this.bibUUID = bibUUID;
99      }
100 
101     public KualiDecimal getForeignCurrencyExtendedPrice() {
102         return foreignCurrencyExtendedPrice;
103     }
104 
105     public void setForeignCurrencyExtendedPrice(KualiDecimal foreignCurrencyExtendedPrice) {
106         this.foreignCurrencyExtendedPrice = foreignCurrencyExtendedPrice;
107     }
108 
109     public boolean isAdditionalChargeUsd() {
110         return additionalChargeUsd;
111     }
112 
113     public void setAdditionalChargeUsd(boolean additionalChargeUsd) {
114         this.additionalChargeUsd = additionalChargeUsd;
115     }
116 
117     /**
118      * Default constructor.
119      */
120     public OleCreditMemoItem() {
121         this.setPoInvoicedTotalQuantity(new KualiDecimal(1));
122         this.setItemQuantity(new KualiDecimal(1.0));
123         this.setPoUnitPrice(new BigDecimal(0.0));
124     }
125 
126     public String getDocFormat() {
127         return docFormat;
128     }
129 
130     public void setDocFormat(String docFormat) {
131         this.docFormat = docFormat;
132     }
133 
134     /**
135      * Constructs a CreditMemoItem object from an existing Purchase Order Item. - Delegate
136      *
137      * @param cmDocument the Credit Memo Document this item belongs to.
138      * @param poItem     the Purchase Order Item to copy from.
139      */
140     public OleCreditMemoItem(VendorCreditMemoDocument cmDocument, OlePurchaseOrderItem poItem) {
141         super(cmDocument, poItem, new HashMap<String, ExpiredOrClosedAccountEntry>());
142     }
143 
144     /**
145      * Constructs a CreditMemoItem object from an existing Purchase Order Item, and check and process expired or closed accounts
146      * item might contain.
147      *
148      * @param cmDocument                 the Credit Memo Document this item belongs to.
149      * @param poItem                     the Purchase Order Item to copy from.
150      * @param expiredOrClosedAccountList the list of expired or closed accounts to check against.
151      */
152     public OleCreditMemoItem(VendorCreditMemoDocument cmDocument, OlePurchaseOrderItem poItem, HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
153 
154         setPurapDocumentIdentifier(cmDocument.getPurapDocumentIdentifier());
155         setPurapDocument(cmDocument);
156         setItemLineNumber(poItem.getItemLineNumber());
157         setPoInvoicedTotalQuantity(poItem.getItemInvoicedTotalQuantity());
158         setPoUnitPrice(poItem.getItemUnitPrice());
159         setPoTotalAmount(poItem.getItemInvoicedTotalAmount());
160         setItemTypeCode(poItem.getItemTypeCode());
161         setBibInfoBean(poItem.getBibInfoBean());
162         this.setBibUUID(poItem.getItemTitleId());
163         setItemTitleId(poItem.getItemTitleId());
164         setItemQuantity(poItem.getItemQuantity());
165         if(poItem.getItemTitleId()!=null){
166             this.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(poItem.getItemTitleId()));
167         }
168         //recalculate tax
169         SpringContext.getBean(PurapService.class).calculateTax(cmDocument);
170 
171         if ((ObjectUtils.isNotNull(this.getItemType()) && this.getItemType().isAmountBasedGeneralLedgerIndicator())) {
172             // setting unit price to be null to be more consistent with other below the line
173             this.setItemUnitPrice(null);
174         } else {
175             setItemUnitPrice(poItem.getItemUnitPrice());
176         }
177 
178         setItemCatalogNumber(poItem.getItemCatalogNumber());
179 
180         setItemDescription(poItem.getItemDescription());
181 
182         if (getPoInvoicedTotalQuantity() == null) {
183             setPoInvoicedTotalQuantity(KualiDecimal.ZERO);
184         }
185         if (getPoUnitPrice() == null) {
186             setPoUnitPrice(BigDecimal.ZERO);
187         }
188         if (getPoTotalAmount() == null) {
189             setPoTotalAmount(KualiDecimal.ZERO);
190         }
191 
192         for (Object element : poItem.getSourceAccountingLines()) {
193             PurApAccountingLineBase account = (PurApAccountingLineBase) element;
194             account.getAmount();
195             // check if this account is expired/closed and replace as needed
196             SpringContext.getBean(AccountsPayableService.class).processExpiredOrClosedAccount(account, expiredOrClosedAccountList);
197 
198             getSourceAccountingLines().add(new OleCreditMemoAccount(account));
199         }
200 
201         // Foreign Currency Conversion
202         setItemCurrencyType(poItem.getItemCurrencyType());
203         setItemForeignListPrice(poItem.getItemForeignListPrice());
204         setItemForeignDiscount(poItem.getItemForeignDiscount());
205         setItemForeignDiscountAmt(poItem.getItemForeignDiscountAmt());
206         setItemForeignDiscountType(poItem.getItemForeignDiscountType());
207         setItemForeignUnitCost(poItem.getItemForeignUnitCost());
208         setItemExchangeRate(poItem.getItemExchangeRate());
209         setItemUnitCostUSD(poItem.getItemUnitCostUSD());
210 
211     }
212 
213     /**
214      * Constructs a CreditMemoItem object from an existing Payment Request Item, and check and process expired or closed accounts
215      * item might contain.
216      *
217      * @param cmDocument                 the Credit Memo Document this item belongs to.
218      * @param preqItem                   the Payment Request Item to copy from.
219      * @param poItem                     the Purchase Order Item to copy from.
220      * @param expiredOrClosedAccountList the list of expired or closed accounts to check against.
221      */
222     public OleCreditMemoItem(VendorCreditMemoDocument cmDocument, OlePaymentRequestItem preqItem, OlePurchaseOrderItem poItem, HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
223 
224         super();
225 
226         setPurapDocumentIdentifier(cmDocument.getPurapDocumentIdentifier());
227         setItemLineNumber(preqItem.getItemLineNumber());
228         this.setPurapDocument(cmDocument);
229         setItemQuantity(preqItem.getItemQuantity());
230         this.setBibUUID(preqItem.getItemTitleId());
231         /*
232          * // take invoiced quantities from the lower of the preq and po if different if (poItem.getItemInvoicedTotalQuantity() !=
233          * null && preqItem.getItemQuantity() != null &&
234          * poItem.getItemInvoicedTotalQuantity().isLessThan(preqItem.getItemQuantity())) {
235          * setPreqInvoicedTotalQuantity(poItem.getItemInvoicedTotalQuantity());
236          * setPreqTotalAmount(poItem.getItemInvoicedTotalAmount()); } else {
237          */
238         setPreqInvoicedTotalQuantity(preqItem.getItemQuantity());
239         setPreqTotalAmount(preqItem.getTotalAmount());
240         /* } */
241 
242         setPreqUnitPrice(preqItem.getItemUnitPrice());
243         setItemTypeCode(preqItem.getItemTypeCode());
244         if ((ObjectUtils.isNotNull(this.getItemType()) && this.getItemType().isAmountBasedGeneralLedgerIndicator())) {
245             // setting unit price to be null to be more consistent with other below the line
246             this.setItemUnitPrice(null);
247         } else {
248             setItemUnitPrice(preqItem.getItemUnitPrice());
249         }
250 
251         setItemCatalogNumber(preqItem.getItemCatalogNumber());
252         setItemDescription(preqItem.getItemDescription());
253 
254         setCapitalAssetTransactionTypeCode(preqItem.getCapitalAssetTransactionTypeCode());
255 
256         if (getPreqInvoicedTotalQuantity() == null) {
257             setPreqInvoicedTotalQuantity(KualiDecimal.ZERO);
258         }
259         if (getPreqUnitPrice() == null) {
260             setPreqUnitPrice(BigDecimal.ZERO);
261         }
262         if (getPreqTotalAmount() == null) {
263             setPreqTotalAmount(KualiDecimal.ZERO);
264         }
265 
266         for (Object element : preqItem.getSourceAccountingLines()) {
267             PaymentRequestAccount account = (PaymentRequestAccount) element;
268 
269             // check if this account is expired/closed and replace as needed
270             SpringContext.getBean(AccountsPayableService.class).processExpiredOrClosedAccount(account, expiredOrClosedAccountList);
271 
272             getSourceAccountingLines().add(new OleCreditMemoAccount(account));
273         }
274 
275         // Foreign Currency Conversion
276         setItemCurrencyType(preqItem.getItemCurrencyType());
277         setItemForeignListPrice(preqItem.getItemForeignListPrice());
278         setItemForeignDiscount(preqItem.getItemForeignDiscount());
279         setItemForeignDiscountAmt(preqItem.getItemForeignDiscountAmt());
280         setItemForeignDiscountType(preqItem.getItemForeignDiscountType());
281         setItemForeignUnitCost(preqItem.getItemForeignUnitCost());
282         setItemExchangeRate(preqItem.getItemExchangeRate());
283         setItemUnitCostUSD(preqItem.getItemUnitCostUSD());
284 
285     }
286 
287     public String getItemCurrencyType() {
288         return itemCurrencyType;
289     }
290 
291     public void setItemCurrencyType(String itemCurrencyType) {
292         this.itemCurrencyType = itemCurrencyType;
293     }
294 
295     public KualiDecimal getItemForeignListPrice() {
296         return itemForeignListPrice;
297     }
298 
299     public void setItemForeignListPrice(KualiDecimal itemForeignListPrice) {
300         this.itemForeignListPrice = itemForeignListPrice;
301     }
302 
303     public KualiDecimal getItemForeignDiscount() {
304         return itemForeignDiscount;
305     }
306 
307     public void setItemForeignDiscount(KualiDecimal itemForeignDiscount) {
308         this.itemForeignDiscount = itemForeignDiscount;
309     }
310 
311     public String getItemForeignDiscountType() {
312         return itemForeignDiscountType;
313     }
314 
315     public void setItemForeignDiscountType(String itemForeignDiscountType) {
316         this.itemForeignDiscountType = itemForeignDiscountType;
317     }
318 
319     public KualiDecimal getItemForeignDiscountAmt() {
320         return itemForeignDiscountAmt;
321     }
322 
323     public void setItemForeignDiscountAmt(KualiDecimal itemForeignDiscountAmt) {
324         this.itemForeignDiscountAmt = itemForeignDiscountAmt;
325     }
326 
327     public KualiDecimal getItemForeignUnitCost() {
328         return itemForeignUnitCost;
329     }
330 
331     public void setItemForeignUnitCost(KualiDecimal itemForeignUnitCost) {
332         this.itemForeignUnitCost = itemForeignUnitCost;
333     }
334 
335     public KualiDecimal getItemExchangeRate() {
336         return itemExchangeRate;
337     }
338 
339     public void setItemExchangeRate(KualiDecimal itemExchangeRate) {
340         this.itemExchangeRate = itemExchangeRate;
341     }
342 
343     public KualiDecimal getItemUnitCostUSD() {
344         return itemUnitCostUSD;
345     }
346 
347     public void setItemUnitCostUSD(KualiDecimal itemUnitCostUSD) {
348         this.itemUnitCostUSD = itemUnitCostUSD;
349     }
350 
351     public BigDecimal getItemSurcharge() {
352         return itemSurcharge;
353     }
354 
355     public void setItemSurcharge(BigDecimal itemSurcharge) {
356         this.itemSurcharge = itemSurcharge;
357     }
358 
359     /**
360      * @see org.kuali.ole.module.purap.businessobject.PurchasingItemBase#getAccountingLineClass()
361      */
362     @Override
363     public Class getAccountingLineClass() {
364         return OleCreditMemoAccount.class;
365     }
366 
367     /**
368      * Constructs a OlePaymentRequestItem.java.
369      *
370      * @param olePoi
371      * @param vendorCreditMemoDoc
372      * @param expiredOrClosedAccountList
373      */
374     public OleCreditMemoItem(OleInvoiceItem olePoi, OleVendorCreditMemoDocument vendorCreditMemoDoc, HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
375         super(olePoi, vendorCreditMemoDoc, expiredOrClosedAccountList);
376 
377         this.setPurapDocument(vendorCreditMemoDoc);
378         //LOG.debug("Inside OlePaymentRequestItem Constructor");
379         //LOG.debug("Setting the Format,Discount and Price Details");
380         //notes = new ArrayList<OlePaymentRequestNote>();
381         // OleInvoiceItem olePoi = (OleInvoiceItem)poi;
382         olePoi.getItemTypeCode();
383         this.setItemForeignListPrice(olePoi.getItemForeignListPrice());
384         this.setItemForeignDiscount(olePoi.getItemForeignDiscount());
385         this.setItemForeignDiscountType(olePoi.getItemForeignDiscountType());
386         this.setItemForeignDiscountAmt(olePoi.getItemForeignDiscountAmt());
387         this.setItemForeignUnitCost(olePoi.getItemForeignUnitCost());
388         this.setItemExchangeRate(olePoi.getItemExchangeRate());
389         this.setItemUnitCostUSD(olePoi.getItemUnitCostUSD());
390         this.setTotalAmount(olePoi.getTotalAmount());
391         this.setItemTypeCode(olePoi.getItemTypeCode());
392         this.setExtendedPrice(olePoi.getExtendedPrice());
393         /*this.setFormatTypeId(olePoi.getFormatTypeId());
394         this.setItemNoOfParts(olePoi.getItemNoOfParts());
395         this.setItemListPrice(olePoi.getItemListPrice());
396         this.setItemDiscount(olePoi.getItemDiscount());
397         this.setItemDiscountType(olePoi.getItemDiscountType());*/
398         this.setItemCatalogNumber(olePoi.getItemCatalogNumber());
399         //this.set(olePoi.getItemIdentifier());
400         this.setExtendedPrice(olePoi.getExtendedPrice());
401         this.setBibInfoBean(olePoi.getBibInfoBean());
402         this.setItemTitleId(olePoi.getItemTitleId());
403         this.setItemQuantity(olePoi.getItemQuantity());
404         this.setItemUnitPrice(olePoi.getItemUnitPrice());
405         this.setExtendedPrice(olePoi.getExtendedPrice());
406         if (vendorCreditMemoDoc.getPaymentMethodId() != null) {
407             OlePaymentMethod olePaymentMethod = SpringContext.getBean(BusinessObjectService.class)
408                     .findBySinglePrimaryKey(OlePaymentMethod.class, vendorCreditMemoDoc.getPaymentMethodId());
409             vendorCreditMemoDoc.setPaymentMethod(olePaymentMethod.getPaymentMethod());
410             vendorCreditMemoDoc.setPaymentMethodId(olePaymentMethod.getPaymentMethodId());
411         }
412 
413         // added for OLE-2203
414         this.setItemCurrencyType(OleSelectConstant.USD);
415         //this.setReceiptStatusId(olePoi.getReceiptStatusId());
416     }
417 }