1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.web.struts;
17
18 import org.kuali.ole.module.purap.PurapAuthorizationConstants;
19 import org.kuali.ole.module.purap.businessobject.PurApItem;
20 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
21 import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
22 import org.kuali.ole.sys.OLEConstants;
23 import org.kuali.ole.vnd.businessobject.VendorCustomerNumber;
24 import org.kuali.rice.core.api.util.type.KualiDecimal;
25 import org.kuali.rice.kns.web.ui.ExtraButton;
26
27 import java.math.BigDecimal;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35 public class OlePurchaseOrderForm extends PurchaseOrderForm {
36
37 private static final OLEConstants result = null;
38
39 public OlePurchaseOrderForm() {
40 }
41
42 @Override
43 public PurApItem setupNewPurchasingItemLine() {
44 return new OlePurchaseOrderItem();
45 }
46
47 @Override
48 public PurApItem getAndResetNewPurchasingItemLine() {
49
50 PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
51 OlePurchaseOrderItem reqItem = (OlePurchaseOrderItem) aPurchasingItemLine;
52 setNewPurchasingItemLine(setupNewPurchasingItemLine());
53 OlePurchaseOrderItem reqItems = (OlePurchaseOrderItem) this.getNewPurchasingItemLine();
54
55 PurchaseOrderDocument document = (PurchaseOrderDocument) this.getDocument();
56 if (document.getVendorDetail() != null) {
57 String customerNumber = document.getVendorCustomerNumber();
58
59 List<VendorCustomerNumber> vendorCustomerNumbers = document.getVendorDetail().getVendorCustomerNumbers();
60 if (customerNumber != null && vendorCustomerNumbers != null) {
61 for (VendorCustomerNumber vendorCustomerNumber : vendorCustomerNumbers) {
62 if (vendorCustomerNumber.getVendorCustomerNumber().equalsIgnoreCase(customerNumber)) {
63 if (document.getVendorDetail().getVendorHeader().getVendorForeignIndicator()) {
64 if (customerNumber != null) {
65 reqItems.setItemForeignDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
66 reqItems.setItemForeignDiscountType(vendorCustomerNumber.getVendorDiscountType());
67 }
68
69 reqItems.setItemExchangeRate(reqItem.getItemExchangeRate());
70 setNewPurchasingItemLine(reqItems);
71 } else {
72 if (customerNumber != null) {
73 reqItems.setItemDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
74 reqItems.setItemDiscountType(vendorCustomerNumber.getVendorDiscountType());
75 }
76 setNewPurchasingItemLine(reqItems);
77 }
78 }
79 }
80 } else {
81 reqItems.setItemForeignDiscount(new KualiDecimal(0.0));
82 reqItems.setItemDiscount(new KualiDecimal(0));
83
84 }
85 }
86 return aPurchasingItemLine;
87
88 }
89
90 @Override
91 protected Map<String, ExtraButton> createButtonsMap() {
92
93 HashMap<String, ExtraButton> result = new HashMap<String, ExtraButton>();
94 result = (HashMap) super.createButtonsMap();
95 ExtraButton noPrintButton = new ExtraButton();
96 noPrintButton.setExtraButtonProperty("methodToCall.printPo");
97 noPrintButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_print.gif");
98 noPrintButton.setExtraButtonAltText("Print");
99 result.put(noPrintButton.getExtraButtonProperty(), noPrintButton);
100 return result;
101 }
102
103 @Override
104 public List<ExtraButton> getExtraButtons() {
105 super.getExtraButtons();
106 Map buttonsMap = createButtonsMap();
107 if (!getEditingMode().containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.PRINT_PURCHASE_ORDER)) {
108 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.printPo"));
109 }
110 return extraButtons;
111
112 }
113 }
114