1 package org.kuali.ole.select.document.service.impl;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.select.businessobject.OlePaymentRequestItem;
5 import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
6 import org.kuali.ole.select.businessobject.OlePurchaseOrderLineForInvoice;
7 import org.kuali.ole.select.businessobject.OlePurchaseOrderTotal;
8 import org.kuali.ole.select.document.OlePurchaseOrderDocument;
9 import org.kuali.ole.select.document.service.OleInvoiceItemService;
10 import org.kuali.rice.core.api.util.type.KualiDecimal;
11 import org.kuali.rice.krad.service.BusinessObjectService;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13
14 import java.math.BigDecimal;
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20
21
22
23
24
25
26
27 public class OleInvoiceItemServiceImpl implements OleInvoiceItemService {
28
29
30 private BusinessObjectService businessObjectService;
31
32 public BusinessObjectService getBusinessObjectService() {
33 if (null == businessObjectService) {
34 businessObjectService = KRADServiceLocator.getBusinessObjectService();
35 }
36 return businessObjectService;
37 }
38
39 public List<OlePurchaseOrderLineForInvoice> getOlePurchaseOrderLineForInvoice(OlePurchaseOrderDocument oleInvoiceDocument) {
40 List<OlePurchaseOrderLineForInvoice> olePurchaseOrderLineForInvoiceList = new ArrayList<OlePurchaseOrderLineForInvoice>();
41 OlePurchaseOrderLineForInvoice olePurchaseOrderLineForInvoice;
42 for (OlePurchaseOrderItem item : (List<OlePurchaseOrderItem>) oleInvoiceDocument.getItems()) {
43 if (item.getItemType().getItemTypeCode().equals(OLEConstants.ITM_TYP_CODE)) {
44 if (item.isItemForInvoice()) {
45 olePurchaseOrderLineForInvoice = new OlePurchaseOrderLineForInvoice();
46 olePurchaseOrderLineForInvoice.setItemId(item.getItemTitleId());
47 olePurchaseOrderLineForInvoice.setItemTitle(item.getItemDescription() != null ? item.getItemDescription() : "");
48 KualiDecimal noOfCopiesReceived = new KualiDecimal(0.0);
49 if (item.getNoOfCopiesInvoiced() != null) {
50 noOfCopiesReceived = item.getNoOfCopiesInvoiced().kualiDecimalValue();
51 }
52 olePurchaseOrderLineForInvoice.setAmount((item.getItemListPrice().multiply(noOfCopiesReceived)).toString());
53 olePurchaseOrderLineForInvoiceList.add(olePurchaseOrderLineForInvoice);
54 }
55 }
56 }
57 return olePurchaseOrderLineForInvoiceList;
58 }
59
60
61 public List<OlePurchaseOrderTotal> getOlePurchaseOrderTotal(OlePurchaseOrderDocument oleInvoiceDocument) {
62
63 OlePurchaseOrderTotal olePurchaseOrderTotal;
64 BigDecimal encumAmt = new BigDecimal(0.0);
65 BigDecimal encumbranceTotalAmount = new BigDecimal(0.0);
66 List<OlePurchaseOrderTotal> olePurchaseOrderTotalList = new ArrayList<OlePurchaseOrderTotal>();
67 for (OlePurchaseOrderItem item : (List<OlePurchaseOrderItem>) oleInvoiceDocument.getItems()) {
68 olePurchaseOrderTotal = new OlePurchaseOrderTotal();
69 String poId = oleInvoiceDocument.getPurapDocumentIdentifier().toString();
70 olePurchaseOrderTotal.setPoNumber(poId);
71 if (item.getItemType().getItemTypeCode().equals(OLEConstants.ITM_TYP_CODE)) {
72 KualiDecimal noOfCopiesRcvd = new KualiDecimal(0.0);
73 if (item.getNoOfCopiesInvoiced() != null) {
74 noOfCopiesRcvd = item.getNoOfCopiesInvoiced().kualiDecimalValue();
75 }
76 encumAmt = encumAmt.add((item.getItemUnitPrice().multiply(noOfCopiesRcvd.bigDecimalValue())));
77 olePurchaseOrderTotal.setEncumbranceAmount(encumAmt.toString());
78 BigDecimal paidAmount = getTotalPaidItem(item.getItemIdentifier());
79 if (paidAmount.intValue() > 0) {
80 if (noOfCopiesRcvd != null && item.getItemListPrice() != null) {
81 encumbranceTotalAmount = ((noOfCopiesRcvd.bigDecimalValue()).multiply(item.getItemListPrice().bigDecimalValue()));
82 olePurchaseOrderTotal.setEncumbranceTotalAmount(encumbranceTotalAmount);
83 }
84 }
85 olePurchaseOrderTotal.setPaidAmount(paidAmount);
86 }
87 olePurchaseOrderTotalList.add(olePurchaseOrderTotal);
88 }
89 return olePurchaseOrderTotalList;
90 }
91
92
93 public BigDecimal getTotalPaidItem(Integer poItemId) {
94 Map preqMap = new HashMap();
95 preqMap.put("poItemIdentifier", poItemId);
96 preqMap.put("itemTypeCode", OLEConstants.ITM_TYP_CODE);
97 List<OlePaymentRequestItem> olePaymentRequestItem = (List<OlePaymentRequestItem>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePaymentRequestItem.class, preqMap);
98 BigDecimal paidAmt = new BigDecimal(0.0);
99 if (olePaymentRequestItem.size() > 0) {
100 BigDecimal itmQty = new BigDecimal(olePaymentRequestItem.get(0).getItemQuantity().longValue());
101 paidAmt = olePaymentRequestItem.get(0).getItemUnitPrice().multiply(itmQty);
102 }
103 return paidAmt;
104 }
105
106
107 public List<OlePurchaseOrderLineForInvoice> getOlePurchaseOrderLineForInvoiceForAddItem(OlePurchaseOrderDocument olePurchaseOrderDocument) {
108
109 List<OlePurchaseOrderLineForInvoice> olePurchaseOrderLineForInvoiceList = new ArrayList<OlePurchaseOrderLineForInvoice>();
110 OlePurchaseOrderLineForInvoice olePurchaseOrderLineForInvoice;
111 for (OlePurchaseOrderItem item : (List<OlePurchaseOrderItem>) olePurchaseOrderDocument.getItems()) {
112 if (item.getItemType().getItemTypeCode().equals(OLEConstants.ITM_TYP_CODE)) {
113 olePurchaseOrderLineForInvoice = new OlePurchaseOrderLineForInvoice();
114 olePurchaseOrderLineForInvoice.setItemId(item.getItemTitleId());
115 olePurchaseOrderLineForInvoice.setItemTitle(item.getItemDescription() != null ? item.getItemDescription() : "");
116 KualiDecimal noOfCopiesReceived = item.getItemQuantity();
117 olePurchaseOrderLineForInvoice.setAmount((item.getItemListPrice().multiply(noOfCopiesReceived)).toString());
118 olePurchaseOrderLineForInvoiceList.add(olePurchaseOrderLineForInvoice);
119 }
120 }
121 return olePurchaseOrderLineForInvoiceList;
122
123 }
124
125
126 public List<OlePurchaseOrderTotal> getOlePurchaseOrderTotalForAddItem(OlePurchaseOrderDocument olePurchaseOrderDocument) {
127
128 OlePurchaseOrderTotal olePurchaseOrderTotal;
129 List<OlePurchaseOrderTotal> olePurchaseOrderTotalList = new ArrayList<OlePurchaseOrderTotal>();
130 BigDecimal encumAmt = new BigDecimal(0.0);
131 BigDecimal encumbranceTotalAmount = new BigDecimal(0.0);
132 olePurchaseOrderTotal = new OlePurchaseOrderTotal();
133 String poId = olePurchaseOrderDocument.getPurapDocumentIdentifier().toString();
134 olePurchaseOrderTotal.setPoNumber(poId);
135 for (OlePurchaseOrderItem item : (List<OlePurchaseOrderItem>) olePurchaseOrderDocument.getItems()) {
136 if (item.getItemType().getItemTypeCode().equals(OLEConstants.ITM_TYP_CODE)) {
137 KualiDecimal noOfCopiesRcvd = item.getItemQuantity();
138 encumAmt = encumAmt.add((item.getItemUnitPrice().multiply(noOfCopiesRcvd.bigDecimalValue())));
139 olePurchaseOrderTotal.setEncumbranceAmount(encumAmt.toString());
140 BigDecimal paidAmount = getTotalPaidItem(item.getItemIdentifier());
141 olePurchaseOrderTotal.setPaidAmount(paidAmount);
142 if (paidAmount.intValue() > 0) {
143 if (noOfCopiesRcvd != null && item.getItemListPrice() != null) {
144 encumbranceTotalAmount = ((noOfCopiesRcvd.bigDecimalValue()).multiply(item.getItemListPrice().bigDecimalValue()));
145 olePurchaseOrderTotal.setEncumbranceTotalAmount(encumbranceTotalAmount);
146 }
147 }
148 }
149 }
150 olePurchaseOrderTotalList.add(olePurchaseOrderTotal);
151
152 return olePurchaseOrderTotalList;
153 }
154
155
156 }