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