| 1961 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
| 2066 |
ankur.sing |
4 |
import in.shop2020.catalog.dashboard.shared.Utils;
|
| 2119 |
ankur.sing |
5 |
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
|
|
|
6 |
import in.shop2020.catalog.dashboard.shared.VendorPricings;
|
| 1961 |
ankur.sing |
7 |
|
|
|
8 |
import java.util.Date;
|
| 2066 |
ankur.sing |
9 |
import java.util.HashMap;
|
| 1992 |
ankur.sing |
10 |
import java.util.Map;
|
|
|
11 |
import java.util.Map.Entry;
|
| 1961 |
ankur.sing |
12 |
|
|
|
13 |
import com.google.gwt.core.client.GWT;
|
|
|
14 |
import com.google.gwt.event.dom.client.ClickEvent;
|
| 1992 |
ankur.sing |
15 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
16 |
import com.google.gwt.resources.client.CssResource;
|
| 1961 |
ankur.sing |
17 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
18 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
19 |
import com.google.gwt.user.client.Window;
|
| 2126 |
ankur.sing |
20 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
| 1961 |
ankur.sing |
21 |
import com.google.gwt.user.client.ui.Button;
|
| 2066 |
ankur.sing |
22 |
import com.google.gwt.user.client.ui.CheckBox;
|
| 1992 |
ankur.sing |
23 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
24 |
import com.google.gwt.user.client.ui.HTMLTable.Cell;
|
| 1961 |
ankur.sing |
25 |
import com.google.gwt.user.client.ui.Label;
|
|
|
26 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
27 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
28 |
import com.google.gwt.user.client.ui.Widget;
|
| 2068 |
ankur.sing |
29 |
import com.google.gwt.user.datepicker.client.DateBox;
|
| 1961 |
ankur.sing |
30 |
|
| 2427 |
ankur.sing |
31 |
/**
|
|
|
32 |
* Panel contains fields for item details. Some of these fields are editable.
|
|
|
33 |
* It also contains vendor item pricings, vendor item keys, and item availability in tabular format.
|
|
|
34 |
* Item availability is made invisible for time being
|
|
|
35 |
*/
|
| 1961 |
ankur.sing |
36 |
public class ItemDetails extends ResizeComposite {
|
|
|
37 |
|
| 2359 |
ankur.sing |
38 |
private final int TABLE_INDEX_MAPPING_VENDOR_DESC = 0,
|
|
|
39 |
TABLE_INDEX_MAPPING_ITEM_KEY = 1,
|
|
|
40 |
TABLE_INDEX_MAPPING_BUTTON = 2,
|
|
|
41 |
TABLE_INDEX_MAPPING_VENDORID = 3,
|
|
|
42 |
TABLE_INDEX_MAPPING_ITEM_KEY_OLD = 4;
|
|
|
43 |
|
|
|
44 |
private final int TABLE_INDEX_PRICING_VENDOR_DESC = 0,
|
|
|
45 |
TABLE_INDEX_PRICING_MOP = 1,
|
|
|
46 |
TABLE_INDEX_PRICING_DP = 2,
|
|
|
47 |
TABLE_INDEX_PRICING_TP = 3,
|
|
|
48 |
TABLE_INDEX_PRICING_BUTTON = 4,
|
|
|
49 |
TABLE_INDEX_PRICING_VENDORID = 5;
|
|
|
50 |
|
| 2119 |
ankur.sing |
51 |
private final int TABLE_INDEX_WAREHOUSE_ID = 0,
|
|
|
52 |
TABLE_INDEX_WAREHOUSE_DESC = 1,
|
|
|
53 |
TABLE_INDEX_WAREHOUSE_INV = 2;
|
| 2359 |
ankur.sing |
54 |
|
|
|
55 |
private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",
|
|
|
56 |
VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",
|
|
|
57 |
BUTTON_WIDTH = "50px";
|
| 2066 |
ankur.sing |
58 |
|
|
|
59 |
interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
|
|
|
60 |
private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
|
| 2126 |
ankur.sing |
61 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
| 2066 |
ankur.sing |
62 |
|
| 1961 |
ankur.sing |
63 |
|
| 2066 |
ankur.sing |
64 |
interface ItemDetailStyle extends CssResource{
|
|
|
65 |
String greenLabel();
|
|
|
66 |
String fieldChanged();
|
|
|
67 |
}
|
| 1961 |
ankur.sing |
68 |
|
| 2105 |
ankur.sing |
69 |
private Item item, newItem;
|
| 2489 |
ankur.sing |
70 |
private CatalogDashboard catalogDashboardPanel;
|
| 2066 |
ankur.sing |
71 |
|
|
|
72 |
@UiField ItemDetailStyle style;
|
|
|
73 |
@UiField Label itemId;
|
|
|
74 |
@UiField TextBox productGroup, brand, modelNumber, modelName, color;
|
| 2105 |
ankur.sing |
75 |
@UiField Label contentCategory, catalogItemId;
|
| 2359 |
ankur.sing |
76 |
@UiField TextBox statusDesc, comments;
|
| 2105 |
ankur.sing |
77 |
@UiField TextBox sellingPrice, mrp, weight;
|
|
|
78 |
@UiField Label addedOn, retireDate, updatedOn;
|
| 2066 |
ankur.sing |
79 |
@UiField Label itemStatus;
|
|
|
80 |
@UiField TextBox bestDealsText, bestDealsValue;
|
|
|
81 |
@UiField FlexTable headerAvailability, availabilityTable;
|
| 2427 |
ankur.sing |
82 |
@UiField FlexTable headerVendorItemKey, tableVendorItemKey;
|
|
|
83 |
@UiField FlexTable headerVendorPrices, tableVendorPrices;
|
| 2066 |
ankur.sing |
84 |
@UiField TextBox bestSellingRank;
|
| 3359 |
chandransh |
85 |
@UiField TextBox expectedDelay;
|
|
|
86 |
@UiField TextBox preferredWarehouse;
|
| 2252 |
ankur.sing |
87 |
@UiField CheckBox defaultForEntity, risky;
|
| 2068 |
ankur.sing |
88 |
@UiField DateBox startDate;
|
| 2066 |
ankur.sing |
89 |
|
|
|
90 |
public ItemDetails(Item item){
|
| 2105 |
ankur.sing |
91 |
this();
|
| 2066 |
ankur.sing |
92 |
setItemDetails(item);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public ItemDetails() {
|
|
|
96 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
97 |
initAvailabilityHeader();
|
| 2427 |
ankur.sing |
98 |
initVendorKeysHeader();
|
|
|
99 |
initVendorPricingHeader();
|
| 2119 |
ankur.sing |
100 |
|
| 2105 |
ankur.sing |
101 |
headerAvailability.setVisible(false);
|
|
|
102 |
availabilityTable.setVisible(false);
|
| 2066 |
ankur.sing |
103 |
}
|
|
|
104 |
|
| 2427 |
ankur.sing |
105 |
/**
|
|
|
106 |
* Sets the UI fields with item object attributes
|
|
|
107 |
* Also populates tables for vendor prices, keys and item availability
|
|
|
108 |
* @param item
|
|
|
109 |
*/
|
| 2066 |
ankur.sing |
110 |
public void setItemDetails(Item item){
|
|
|
111 |
this.item = item;
|
|
|
112 |
itemId.setText(item.getId()+"");
|
|
|
113 |
productGroup.setText(item.getProductGroup());
|
|
|
114 |
brand.setText(item.getBrand());
|
|
|
115 |
modelNumber.setText(item.getModelNumber());
|
|
|
116 |
modelName.setText(item.getModelName());
|
|
|
117 |
color.setText(item.getColor());
|
|
|
118 |
|
| 2359 |
ankur.sing |
119 |
statusDesc.setText(item.getItemStatusDesc());
|
| 2105 |
ankur.sing |
120 |
contentCategory.setText(item.getContentCategory()+"");
|
| 2066 |
ankur.sing |
121 |
comments.setText(item.getComments());
|
|
|
122 |
catalogItemId.setText(item.getCatalogItemId() + "");
|
|
|
123 |
|
| 2489 |
ankur.sing |
124 |
mrp.setText(item.getMrp() != null ? item.getMrp()+"" : "");
|
|
|
125 |
sellingPrice.setText(item.getSellingPrice() != null ? item.getSellingPrice()+"" : "");
|
|
|
126 |
weight.setText(item.getWeight() != null ? item.getWeight()+"" : "");
|
| 3359 |
chandransh |
127 |
expectedDelay.setValue(item.getExpectedDelay()+"");
|
|
|
128 |
preferredWarehouse.setValue(item.getPreferredWarehouse()+"");
|
| 2068 |
ankur.sing |
129 |
|
|
|
130 |
startDate.setValue(new Date(item.getStartDate()));
|
|
|
131 |
addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
|
|
|
132 |
retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
|
|
|
133 |
updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
|
| 1992 |
ankur.sing |
134 |
|
| 2066 |
ankur.sing |
135 |
bestDealsText.setText(item.getBestDealsText());
|
| 2489 |
ankur.sing |
136 |
bestDealsValue.setText(item.getBestDealsValue() != null ? item.getBestDealsValue()+"" : "");
|
|
|
137 |
bestSellingRank.setText(item.getBestSellingRank() != null ? item.getBestSellingRank()+"" : "");
|
| 2066 |
ankur.sing |
138 |
defaultForEntity.setValue(item.isDefaultForEntity());
|
| 2252 |
ankur.sing |
139 |
risky.setValue(item.isRisky());
|
| 1992 |
ankur.sing |
140 |
|
| 2066 |
ankur.sing |
141 |
itemStatus.setText(item.getItemStatus());
|
|
|
142 |
|
|
|
143 |
updateAvailabilityTable(item.getAvailability());
|
| 2427 |
ankur.sing |
144 |
updateVendorKeysTable(item.getVendorKeysMap());
|
|
|
145 |
updateVendorPricingTable(item.getVendorPricesMap());
|
| 1992 |
ankur.sing |
146 |
}
|
| 2066 |
ankur.sing |
147 |
|
| 2427 |
ankur.sing |
148 |
/**
|
|
|
149 |
* initialise item availability table header.
|
|
|
150 |
*/
|
| 2066 |
ankur.sing |
151 |
private void initAvailabilityHeader(){
|
|
|
152 |
headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
|
| 2105 |
ankur.sing |
153 |
headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
|
| 2066 |
ankur.sing |
154 |
headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
|
|
|
155 |
|
|
|
156 |
headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");
|
|
|
157 |
headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");
|
|
|
158 |
headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INV, "Availability");
|
| 1992 |
ankur.sing |
159 |
|
|
|
160 |
}
|
| 2066 |
ankur.sing |
161 |
|
| 2427 |
ankur.sing |
162 |
/**
|
|
|
163 |
* initialises vendor item key table header. Creates an Add button and
|
|
|
164 |
* adds click event listener to it to create and pop up a dialog for adding
|
|
|
165 |
* a new vendor item key.
|
|
|
166 |
*/
|
|
|
167 |
private void initVendorKeysHeader(){
|
|
|
168 |
headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
|
|
|
169 |
headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
|
|
|
170 |
headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
|
|
|
171 |
headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
|
|
|
172 |
headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
|
| 2119 |
ankur.sing |
173 |
|
| 2427 |
ankur.sing |
174 |
headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDORID, "Vendor Id");
|
|
|
175 |
headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDOR_DESC, "Vendor");
|
|
|
176 |
headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY, "Item Key");
|
|
|
177 |
headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, "Prev Item Key");
|
| 2119 |
ankur.sing |
178 |
|
| 2427 |
ankur.sing |
179 |
headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_VENDORID, false);
|
|
|
180 |
headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
|
| 2359 |
ankur.sing |
181 |
|
| 2119 |
ankur.sing |
182 |
Button addButton = new Button("Add");
|
| 2427 |
ankur.sing |
183 |
headerVendorItemKey.setWidget(0, TABLE_INDEX_MAPPING_BUTTON, addButton);
|
| 2119 |
ankur.sing |
184 |
addButton.addClickHandler(new ClickHandler() {
|
|
|
185 |
@Override
|
|
|
186 |
public void onClick(ClickEvent event) {
|
| 2126 |
ankur.sing |
187 |
VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(),
|
|
|
188 |
modelNumber.getText().trim(), color.getText().trim());
|
| 2119 |
ankur.sing |
189 |
vendorMappingDialog.updateButton.setText("Add");
|
|
|
190 |
vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
|
|
|
191 |
@Override
|
|
|
192 |
public boolean onUpdate(String key, long vendorId) {
|
| 2427 |
ankur.sing |
193 |
int row = tableVendorItemKey.getRowCount();
|
|
|
194 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
|
|
|
195 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
|
|
|
196 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
|
|
|
197 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
|
| 2119 |
ankur.sing |
198 |
|
| 2427 |
ankur.sing |
199 |
tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDORID, vendorId + "");
|
|
|
200 |
tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
|
|
|
201 |
tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, key);
|
|
|
202 |
tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, key);
|
| 2359 |
ankur.sing |
203 |
|
| 2427 |
ankur.sing |
204 |
tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_VENDORID, false);
|
|
|
205 |
tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
|
| 2119 |
ankur.sing |
206 |
return true;
|
|
|
207 |
}
|
|
|
208 |
});
|
|
|
209 |
vendorMappingDialog.show();
|
|
|
210 |
}
|
|
|
211 |
});
|
|
|
212 |
}
|
|
|
213 |
|
| 2427 |
ankur.sing |
214 |
/**
|
|
|
215 |
* initialises vendor prices table header. Creates an Add button and
|
|
|
216 |
* adds click event listener to it to create and pop up a dialog for adding
|
|
|
217 |
* a prices for a new vendor
|
|
|
218 |
*/
|
|
|
219 |
private void initVendorPricingHeader(){
|
|
|
220 |
headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
|
|
|
221 |
headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
|
|
|
222 |
headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
|
|
|
223 |
headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
|
|
|
224 |
headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
|
|
|
225 |
headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
|
| 2066 |
ankur.sing |
226 |
|
| 2427 |
ankur.sing |
227 |
headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDORID, "Vendor Id");
|
|
|
228 |
headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDOR_DESC, "Vendor");
|
|
|
229 |
headerVendorPrices.setText(0, TABLE_INDEX_PRICING_MOP, "MOP");
|
|
|
230 |
headerVendorPrices.setText(0, TABLE_INDEX_PRICING_DP, "Dealer Price");
|
|
|
231 |
headerVendorPrices.setText(0, TABLE_INDEX_PRICING_TP, "Transfer Price");
|
| 2105 |
ankur.sing |
232 |
|
| 2427 |
ankur.sing |
233 |
headerVendorPrices.getCellFormatter().setVisible(0, TABLE_INDEX_PRICING_VENDORID, false);
|
| 2359 |
ankur.sing |
234 |
|
| 2105 |
ankur.sing |
235 |
Button addButton = new Button("Add");
|
| 2427 |
ankur.sing |
236 |
headerVendorPrices.setWidget(0, TABLE_INDEX_PRICING_BUTTON, addButton);
|
| 2105 |
ankur.sing |
237 |
addButton.addClickHandler(new ClickHandler() {
|
|
|
238 |
@Override
|
|
|
239 |
public void onClick(ClickEvent event) {
|
| 2119 |
ankur.sing |
240 |
VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
|
|
|
241 |
vendorPricesDialog.updateButton.setText("Add");
|
|
|
242 |
vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
|
| 2105 |
ankur.sing |
243 |
@Override
|
| 2119 |
ankur.sing |
244 |
public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
|
| 2105 |
ankur.sing |
245 |
if(!vendorExists(vendorId)) {
|
|
|
246 |
Window.alert("Vendor already exists");
|
|
|
247 |
return false;
|
|
|
248 |
}
|
| 2119 |
ankur.sing |
249 |
/*if(!validateVendorPrices(mop, dp, tp)) {
|
| 2105 |
ankur.sing |
250 |
return false;
|
| 2119 |
ankur.sing |
251 |
}*/
|
| 2427 |
ankur.sing |
252 |
int row = tableVendorPrices.getRowCount();
|
|
|
253 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
|
|
|
254 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
|
|
|
255 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
|
|
|
256 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
|
|
|
257 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
|
| 2105 |
ankur.sing |
258 |
|
| 2427 |
ankur.sing |
259 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDORID, vendorId + "");
|
|
|
260 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
|
|
|
261 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
|
|
|
262 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
|
|
|
263 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
|
| 2359 |
ankur.sing |
264 |
|
| 2427 |
ankur.sing |
265 |
tableVendorPrices.getCellFormatter().setVisible(row, TABLE_INDEX_PRICING_VENDORID, false);
|
| 2105 |
ankur.sing |
266 |
return true;
|
|
|
267 |
}
|
|
|
268 |
});
|
| 2119 |
ankur.sing |
269 |
vendorPricesDialog.show();
|
| 2105 |
ankur.sing |
270 |
}
|
|
|
271 |
});
|
| 2066 |
ankur.sing |
272 |
}
|
| 2105 |
ankur.sing |
273 |
|
| 2427 |
ankur.sing |
274 |
/**
|
|
|
275 |
* Clear and populate item availability table.
|
|
|
276 |
* @param availabilityMap
|
|
|
277 |
*/
|
| 1992 |
ankur.sing |
278 |
private void updateAvailabilityTable(Map<Long, Long> availabilityMap){
|
|
|
279 |
availabilityTable.removeAllRows();
|
|
|
280 |
if(availabilityMap == null) {
|
|
|
281 |
return;
|
|
|
282 |
}
|
| 2066 |
ankur.sing |
283 |
availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
|
| 2105 |
ankur.sing |
284 |
availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
|
| 2066 |
ankur.sing |
285 |
availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
|
|
|
286 |
|
| 1992 |
ankur.sing |
287 |
int i=0;
|
|
|
288 |
for(Entry<Long, Long> availability : availabilityMap.entrySet()){
|
| 2066 |
ankur.sing |
289 |
availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, availability.getKey() + "");
|
|
|
290 |
availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(availability.getKey()));
|
|
|
291 |
availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INV, availability.getValue() + "");
|
| 1992 |
ankur.sing |
292 |
i++;
|
|
|
293 |
}
|
|
|
294 |
}
|
| 2119 |
ankur.sing |
295 |
|
| 2427 |
ankur.sing |
296 |
/**
|
|
|
297 |
* Clear and populate vendor item key table with keys in the passed argument.
|
|
|
298 |
* With each row in the table, an edit button is created and click event listener
|
|
|
299 |
* is added to it to edit that vendor item key row.
|
|
|
300 |
* @param vendorKeysMap
|
|
|
301 |
*/
|
|
|
302 |
private void updateVendorKeysTable(Map<String, VendorItemMapping> vendorKeysMap){
|
|
|
303 |
tableVendorItemKey.removeAllRows();
|
| 2119 |
ankur.sing |
304 |
|
| 2427 |
ankur.sing |
305 |
if(vendorKeysMap == null || vendorKeysMap.isEmpty()) {
|
| 2119 |
ankur.sing |
306 |
return;
|
|
|
307 |
}
|
| 2427 |
ankur.sing |
308 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
|
|
|
309 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
|
|
|
310 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
|
|
|
311 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
|
|
|
312 |
tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
|
| 2066 |
ankur.sing |
313 |
|
| 2119 |
ankur.sing |
314 |
int i=0;
|
| 2427 |
ankur.sing |
315 |
for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()){
|
| 2359 |
ankur.sing |
316 |
VendorItemMapping vendorMapping = e.getValue();
|
| 2427 |
ankur.sing |
317 |
tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDORID, vendorMapping.getVendorId() + "");
|
|
|
318 |
tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));
|
|
|
319 |
tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY, vendorMapping.getItemKey());
|
|
|
320 |
tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1));
|
| 2119 |
ankur.sing |
321 |
Button editButton = new Button("Edit");
|
| 2427 |
ankur.sing |
322 |
tableVendorItemKey.setWidget(i, TABLE_INDEX_MAPPING_BUTTON, editButton);
|
| 2119 |
ankur.sing |
323 |
editButton.addClickHandler(new ClickHandler() {
|
|
|
324 |
@Override
|
|
|
325 |
public void onClick(ClickEvent event) {
|
| 2427 |
ankur.sing |
326 |
Cell cell = tableVendorItemKey.getCellForEvent(event);
|
| 2119 |
ankur.sing |
327 |
int row = cell.getRowIndex();
|
| 2427 |
ankur.sing |
328 |
long vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
|
|
|
329 |
editVendorKey(vendorId, row);
|
| 2119 |
ankur.sing |
330 |
}
|
|
|
331 |
});
|
| 2427 |
ankur.sing |
332 |
tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_VENDORID, false);
|
|
|
333 |
tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
|
| 2359 |
ankur.sing |
334 |
i++;
|
| 2119 |
ankur.sing |
335 |
}
|
|
|
336 |
}
|
|
|
337 |
|
| 2427 |
ankur.sing |
338 |
/**
|
|
|
339 |
* Clear and populate vendor prices table with prices in the passed argument.
|
|
|
340 |
* With each row in the table, an edit button is created and click event listener
|
|
|
341 |
* is added to it to edit that vendor prices row.
|
|
|
342 |
* @param vendorPricingMap
|
|
|
343 |
*/
|
|
|
344 |
private void updateVendorPricingTable(Map<Long, VendorPricings> vendorPricingMap){
|
|
|
345 |
tableVendorPrices.removeAllRows();
|
| 2105 |
ankur.sing |
346 |
|
| 2119 |
ankur.sing |
347 |
if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {
|
| 1992 |
ankur.sing |
348 |
return;
|
|
|
349 |
}
|
| 2427 |
ankur.sing |
350 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
|
|
|
351 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
|
|
|
352 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
|
|
|
353 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
|
|
|
354 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
|
|
|
355 |
tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
|
| 2066 |
ankur.sing |
356 |
|
|
|
357 |
|
| 1992 |
ankur.sing |
358 |
int i=0;
|
| 2119 |
ankur.sing |
359 |
for(VendorPricings vendorDetail : vendorPricingMap.values()){
|
| 2427 |
ankur.sing |
360 |
tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDORID, vendorDetail.getVendorId() + "");
|
|
|
361 |
tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
|
|
|
362 |
tableVendorPrices.setText(i, TABLE_INDEX_PRICING_MOP, vendorDetail.getMop() + "");
|
|
|
363 |
tableVendorPrices.setText(i, TABLE_INDEX_PRICING_DP, vendorDetail.getDealerPrice() + "");
|
|
|
364 |
tableVendorPrices.setText(i, TABLE_INDEX_PRICING_TP, vendorDetail.getTransferPrice() + "");
|
| 1992 |
ankur.sing |
365 |
Button editButton = new Button("Edit");
|
| 2427 |
ankur.sing |
366 |
tableVendorPrices.setWidget(i, TABLE_INDEX_PRICING_BUTTON, editButton);
|
| 1992 |
ankur.sing |
367 |
editButton.addClickHandler(new ClickHandler() {
|
|
|
368 |
@Override
|
|
|
369 |
public void onClick(ClickEvent event) {
|
| 2427 |
ankur.sing |
370 |
Cell cell = tableVendorPrices.getCellForEvent(event);
|
| 1992 |
ankur.sing |
371 |
int row = cell.getRowIndex();
|
| 2427 |
ankur.sing |
372 |
long vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
|
|
|
373 |
editVendorPrices(vendorId, row);
|
| 1992 |
ankur.sing |
374 |
}
|
|
|
375 |
});
|
| 2427 |
ankur.sing |
376 |
tableVendorPrices.getCellFormatter().setVisible(i, TABLE_INDEX_PRICING_VENDORID, false);
|
| 2359 |
ankur.sing |
377 |
i++;
|
| 1992 |
ankur.sing |
378 |
}
|
|
|
379 |
}
|
| 2066 |
ankur.sing |
380 |
|
| 2427 |
ankur.sing |
381 |
/**
|
|
|
382 |
* called on the click event of update item button in ItemActions
|
|
|
383 |
*/
|
| 2126 |
ankur.sing |
384 |
void updateItem() {
|
|
|
385 |
if(item == null) {
|
|
|
386 |
Window.alert("Please select an item to update.");
|
|
|
387 |
return;
|
|
|
388 |
}
|
| 2066 |
ankur.sing |
389 |
try {
|
| 2126 |
ankur.sing |
390 |
if(!createNewItem()) {
|
|
|
391 |
return;
|
|
|
392 |
}
|
| 2252 |
ankur.sing |
393 |
String paramsChanged = isItemChanged();
|
|
|
394 |
if(paramsChanged.equals("")) {
|
| 2066 |
ankur.sing |
395 |
Window.alert("Nothing to update. Please change intended item parameters and try again.");
|
|
|
396 |
return;
|
| 2252 |
ankur.sing |
397 |
} else {
|
|
|
398 |
paramsChanged = "You have changed following items.\n" + paramsChanged;
|
|
|
399 |
Window.alert(paramsChanged);
|
| 2066 |
ankur.sing |
400 |
}
|
|
|
401 |
} catch(NumberFormatException ex) {
|
| 2126 |
ankur.sing |
402 |
ex.printStackTrace();
|
|
|
403 |
GWT.log("Number format exception");
|
|
|
404 |
}
|
|
|
405 |
if(!Utils.validateItem(newItem)) {
|
| 2066 |
ankur.sing |
406 |
return;
|
|
|
407 |
}
|
| 2126 |
ankur.sing |
408 |
|
|
|
409 |
/*if(!validatePrices()) {
|
|
|
410 |
return;
|
|
|
411 |
}*/
|
|
|
412 |
catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
|
|
|
413 |
@Override
|
|
|
414 |
public void onSuccess(Boolean result) {
|
|
|
415 |
if(result) {
|
|
|
416 |
item = newItem;
|
|
|
417 |
GWT.log("Item updated. Id = " + item.getId());
|
| 2489 |
ankur.sing |
418 |
catalogDashboardPanel.getItemListWidget().updateItem(item);
|
|
|
419 |
getFreshItemFromDB(item.getId());
|
| 2126 |
ankur.sing |
420 |
Window.alert("Item updated successfully.");
|
|
|
421 |
}
|
|
|
422 |
else {
|
|
|
423 |
GWT.log("Error updating item");
|
|
|
424 |
Window.alert("Error updating item");
|
|
|
425 |
}
|
|
|
426 |
}
|
|
|
427 |
@Override
|
|
|
428 |
public void onFailure(Throwable caught) {
|
|
|
429 |
caught.printStackTrace();
|
|
|
430 |
Window.alert("Error while updating item");
|
|
|
431 |
}
|
|
|
432 |
});
|
| 2066 |
ankur.sing |
433 |
}
|
| 2126 |
ankur.sing |
434 |
|
| 2489 |
ankur.sing |
435 |
private void getFreshItemFromDB(long id) {
|
|
|
436 |
catalogService.getItem(id, new AsyncCallback<Item>() {
|
|
|
437 |
@Override
|
|
|
438 |
public void onSuccess(Item result) {
|
|
|
439 |
setItemDetails(result);
|
|
|
440 |
}
|
|
|
441 |
@Override
|
|
|
442 |
public void onFailure(Throwable caught) {
|
|
|
443 |
caught.printStackTrace();
|
|
|
444 |
Window.alert("Unable to fetch item details.");
|
|
|
445 |
}
|
|
|
446 |
});
|
|
|
447 |
}
|
|
|
448 |
|
| 2427 |
ankur.sing |
449 |
/**
|
|
|
450 |
* This method is called while updating item.<br> It will create a new Item object and set
|
|
|
451 |
* its editable attributes with UI fields values and non-editable attributes with old Item
|
|
|
452 |
* object attributes. This new Item object is then passed to the service to update item in the database.
|
|
|
453 |
* <br>If update is successful, the old Item object is replaced with the new Item object.
|
|
|
454 |
* @return true if new Item object is created successfully
|
|
|
455 |
* <br>false if some error occurs due to NumberFormatException
|
|
|
456 |
*/
|
| 2126 |
ankur.sing |
457 |
private boolean createNewItem() {
|
| 2066 |
ankur.sing |
458 |
newItem = new Item();
|
| 2489 |
ankur.sing |
459 |
newItem.setId(item.getId());
|
|
|
460 |
newItem.setVendorCategory(item.getVendorCategory());
|
| 2066 |
ankur.sing |
461 |
newItem.setProductGroup(productGroup.getText().trim());
|
|
|
462 |
newItem.setBrand(brand.getText().trim());
|
|
|
463 |
newItem.setModelNumber(modelNumber.getText().trim());
|
|
|
464 |
newItem.setModelName(modelName.getText().trim());
|
|
|
465 |
newItem.setColor(color.getText().trim());
|
| 2119 |
ankur.sing |
466 |
newItem.setContentCategory(contentCategory.getText());
|
| 2066 |
ankur.sing |
467 |
newItem.setComments(comments.getText().trim());
|
|
|
468 |
newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
|
| 2126 |
ankur.sing |
469 |
|
| 2068 |
ankur.sing |
470 |
try {
|
| 2126 |
ankur.sing |
471 |
if(!mrp.getText().trim().isEmpty()) {
|
|
|
472 |
double mrpValue = Double.parseDouble(mrp.getText().trim());
|
|
|
473 |
if(mrpValue <= 0) {
|
|
|
474 |
throw new NumberFormatException("Negative value of MRP");
|
|
|
475 |
}
|
|
|
476 |
newItem.setMrp(mrpValue);
|
|
|
477 |
}
|
| 2068 |
ankur.sing |
478 |
} catch(NumberFormatException ex) {
|
| 2126 |
ankur.sing |
479 |
Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
|
|
|
480 |
return false;
|
| 2068 |
ankur.sing |
481 |
}
|
|
|
482 |
try {
|
| 2126 |
ankur.sing |
483 |
if(!sellingPrice.getText().trim().isEmpty()) {
|
|
|
484 |
double spValue = Double.parseDouble(sellingPrice.getText().trim());
|
|
|
485 |
if(spValue <= 0) {
|
|
|
486 |
throw new NumberFormatException("Negative value of Selling price");
|
|
|
487 |
}
|
|
|
488 |
newItem.setSellingPrice(spValue);
|
|
|
489 |
}
|
|
|
490 |
} catch(NumberFormatException ex) {
|
|
|
491 |
Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
|
|
|
492 |
return false;
|
| 2068 |
ankur.sing |
493 |
}
|
|
|
494 |
try {
|
| 2126 |
ankur.sing |
495 |
if(!weight.getText().trim().isEmpty()) {
|
|
|
496 |
double wtValue = Double.parseDouble(weight.getText().trim());
|
|
|
497 |
if(wtValue <= 0) {
|
|
|
498 |
throw new NumberFormatException("Negative value of Weight");
|
|
|
499 |
}
|
|
|
500 |
newItem.setWeight(wtValue);
|
|
|
501 |
}
|
| 2068 |
ankur.sing |
502 |
} catch(NumberFormatException ex) {
|
| 2126 |
ankur.sing |
503 |
Window.alert("Invalid weight format/value. Value shoule be greater than zero");
|
|
|
504 |
return false;
|
| 2068 |
ankur.sing |
505 |
}
|
| 2126 |
ankur.sing |
506 |
try {
|
|
|
507 |
if(!startDate.getTextBox().getText().trim().equals("")) {
|
|
|
508 |
newItem.setStartDate(startDate.getValue().getTime());
|
|
|
509 |
}
|
|
|
510 |
} catch(Exception ex) {
|
|
|
511 |
Window.alert("Invalid start date format");
|
|
|
512 |
return false;
|
|
|
513 |
}
|
| 2066 |
ankur.sing |
514 |
newItem.setBestDealsText(bestDealsText.getText().trim());
|
| 2068 |
ankur.sing |
515 |
try {
|
| 2126 |
ankur.sing |
516 |
if(!bestDealsValue.getText().trim().equals("")) {
|
|
|
517 |
double bdValue = Double.parseDouble(bestDealsValue.getText().trim());
|
|
|
518 |
if(bdValue < 0) {
|
|
|
519 |
throw new NumberFormatException("Negative value of BestDealValue");
|
|
|
520 |
}
|
|
|
521 |
newItem.setBestDealsValue(bdValue);
|
|
|
522 |
}
|
| 2068 |
ankur.sing |
523 |
} catch(NumberFormatException ex) {
|
| 2126 |
ankur.sing |
524 |
Window.alert("Invalid best deal value format");
|
|
|
525 |
return false;
|
| 2068 |
ankur.sing |
526 |
}
|
|
|
527 |
try {
|
| 2126 |
ankur.sing |
528 |
if(!bestSellingRank.getText().trim().equals("")) {
|
|
|
529 |
long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
|
|
|
530 |
if(bsrValue < 0) {
|
|
|
531 |
throw new NumberFormatException("Negative value of Best Selling Rank");
|
|
|
532 |
}
|
|
|
533 |
newItem.setBestSellingRank(bsrValue);
|
|
|
534 |
}
|
|
|
535 |
} catch(NumberFormatException ex) {
|
|
|
536 |
Window.alert("Invalid best selling rank format");
|
|
|
537 |
return false;
|
| 2068 |
ankur.sing |
538 |
}
|
| 2066 |
ankur.sing |
539 |
newItem.setDefaultForEntity(defaultForEntity.getValue());
|
| 2252 |
ankur.sing |
540 |
newItem.setRisky(risky.getValue());
|
| 2119 |
ankur.sing |
541 |
|
| 2126 |
ankur.sing |
542 |
/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
|
|
|
543 |
Add the instance to map and set the map to the item instance created above.*/
|
|
|
544 |
Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
|
| 2119 |
ankur.sing |
545 |
VendorPricings v;
|
| 2427 |
ankur.sing |
546 |
for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
|
| 2119 |
ankur.sing |
547 |
v = new VendorPricings();
|
| 2427 |
ankur.sing |
548 |
v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));
|
|
|
549 |
v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));
|
|
|
550 |
v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));
|
|
|
551 |
v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));
|
| 2126 |
ankur.sing |
552 |
vendorPrices.put(v.getVendorId(), v);
|
| 2066 |
ankur.sing |
553 |
}
|
| 2126 |
ankur.sing |
554 |
newItem.setVendorPricesMap(vendorPrices);
|
| 2359 |
ankur.sing |
555 |
newItem.setItemStatusDesc(statusDesc.getText().trim());
|
| 2427 |
ankur.sing |
556 |
|
| 2126 |
ankur.sing |
557 |
/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
|
|
|
558 |
Add the instance to map and set the map to the item instance created above.*/
|
| 2359 |
ankur.sing |
559 |
Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
|
| 2126 |
ankur.sing |
560 |
VendorItemMapping vMapping;
|
| 2427 |
ankur.sing |
561 |
for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
|
| 2126 |
ankur.sing |
562 |
vMapping = new VendorItemMapping();
|
| 2427 |
ankur.sing |
563 |
vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));
|
|
|
564 |
vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));
|
|
|
565 |
vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);
|
| 2119 |
ankur.sing |
566 |
}
|
| 2359 |
ankur.sing |
567 |
newItem.setVendorKeysMap(vendorMappings);
|
| 2119 |
ankur.sing |
568 |
|
| 2126 |
ankur.sing |
569 |
newItem.setContentCategoryId(item.getContentCategoryId());
|
|
|
570 |
newItem.setFeatureId(item.getFeatureId());
|
|
|
571 |
newItem.setFeatureDescription(item.getFeatureDescription());
|
|
|
572 |
newItem.setAddedOn(item.getAddedOn());
|
|
|
573 |
newItem.setRetireDate(item.getRetireDate());
|
|
|
574 |
newItem.setUpdatedOn(item.getUpdatedOn());
|
|
|
575 |
newItem.setItemStatus(item.getItemStatus());
|
|
|
576 |
newItem.setOtherInfo(item.getOtherInfo());
|
|
|
577 |
newItem.setAvailability(item.getAvailability());
|
| 2119 |
ankur.sing |
578 |
|
| 2126 |
ankur.sing |
579 |
return true;
|
| 2066 |
ankur.sing |
580 |
}
|
|
|
581 |
|
| 2427 |
ankur.sing |
582 |
/**
|
|
|
583 |
* This method is called when Edit button is clicked corresponding to a row in
|
|
|
584 |
* vendor prices table. It will pop up a form to edit the vendor prices.
|
|
|
585 |
* @param vendorId
|
|
|
586 |
* @param row
|
|
|
587 |
*/
|
|
|
588 |
private void editVendorPrices(final long vendorId, final int row) {
|
|
|
589 |
String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
|
|
|
590 |
String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
|
|
|
591 |
String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
|
| 2119 |
ankur.sing |
592 |
VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);
|
| 2105 |
ankur.sing |
593 |
pricesDialog.updateButton.setText("Update");
|
| 2119 |
ankur.sing |
594 |
pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
|
| 2066 |
ankur.sing |
595 |
@Override
|
| 2119 |
ankur.sing |
596 |
public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
|
|
|
597 |
if(!validateVendorPrices(mop, dp, tp)) {
|
| 2105 |
ankur.sing |
598 |
return false;
|
|
|
599 |
}
|
| 2427 |
ankur.sing |
600 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
|
|
|
601 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
|
|
|
602 |
tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
|
| 2105 |
ankur.sing |
603 |
return true;
|
| 2066 |
ankur.sing |
604 |
}
|
|
|
605 |
});
|
|
|
606 |
pricesDialog.show();
|
|
|
607 |
}
|
| 2119 |
ankur.sing |
608 |
|
| 2427 |
ankur.sing |
609 |
/**
|
|
|
610 |
* This method is called when Edit button is clicked corresponding to a row in
|
|
|
611 |
* vendor item key table. It will pop up a form to edit the item key.
|
|
|
612 |
* @param vendorId
|
|
|
613 |
* @param row
|
|
|
614 |
*/
|
|
|
615 |
private void editVendorKey(final long vendorId, final int row) {
|
|
|
616 |
String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
|
| 2126 |
ankur.sing |
617 |
VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(),
|
|
|
618 |
modelNumber.getText().trim(), color.getText().trim(), key);
|
| 2119 |
ankur.sing |
619 |
mappingDialog.updateButton.setText("Update");
|
|
|
620 |
mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
|
|
|
621 |
@Override
|
|
|
622 |
public boolean onUpdate(String itemKey, long vendorId) {
|
|
|
623 |
if(itemKey == null || itemKey.equals("")) {
|
|
|
624 |
Window.alert("Item key cannot be empty.");
|
|
|
625 |
return false;
|
|
|
626 |
}
|
| 2427 |
ankur.sing |
627 |
tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
|
| 2119 |
ankur.sing |
628 |
return true;
|
|
|
629 |
}
|
|
|
630 |
});
|
|
|
631 |
mappingDialog.show();
|
|
|
632 |
}
|
| 2066 |
ankur.sing |
633 |
|
| 2427 |
ankur.sing |
634 |
/**
|
|
|
635 |
* This method compares all the editable UI fields values with attributes in the item object.
|
|
|
636 |
* If they differ, the attribute name is appended to a string.
|
|
|
637 |
* @return String showing attributes which are changed by the user for confirmation.
|
|
|
638 |
* <br>Empty string if nothing is changed.
|
|
|
639 |
*/
|
| 2252 |
ankur.sing |
640 |
private String isItemChanged() {
|
|
|
641 |
StringBuilder sb = new StringBuilder("");
|
| 2489 |
ankur.sing |
642 |
if(!checkParameterIfEqual(productGroup.getText().trim(), item.getProductGroup())) {
|
| 2387 |
ankur.sing |
643 |
sb.append("\n-Product Group");
|
| 2066 |
ankur.sing |
644 |
}
|
| 2489 |
ankur.sing |
645 |
if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
|
| 2387 |
ankur.sing |
646 |
sb.append("\n-Brand");
|
| 2066 |
ankur.sing |
647 |
}
|
| 2489 |
ankur.sing |
648 |
if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
|
| 2387 |
ankur.sing |
649 |
sb.append("\n-Model Number");
|
| 2066 |
ankur.sing |
650 |
}
|
| 2489 |
ankur.sing |
651 |
if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
|
| 2387 |
ankur.sing |
652 |
sb.append("\n-Model Name");
|
| 2066 |
ankur.sing |
653 |
}
|
| 2489 |
ankur.sing |
654 |
if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
|
| 2387 |
ankur.sing |
655 |
sb.append("\n-Color");
|
| 2066 |
ankur.sing |
656 |
}
|
| 2489 |
ankur.sing |
657 |
if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
|
| 2387 |
ankur.sing |
658 |
sb.append("\n-Status Description");
|
| 2359 |
ankur.sing |
659 |
}
|
| 2489 |
ankur.sing |
660 |
if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
|
| 2387 |
ankur.sing |
661 |
sb.append("\n-Comments");
|
| 2066 |
ankur.sing |
662 |
}
|
| 2489 |
ankur.sing |
663 |
if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
|
| 2387 |
ankur.sing |
664 |
sb.append("\n-MRP");
|
| 2066 |
ankur.sing |
665 |
}
|
| 2489 |
ankur.sing |
666 |
if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
|
| 2387 |
ankur.sing |
667 |
sb.append("\n-Selling Price");
|
| 2027 |
ankur.sing |
668 |
}
|
| 2489 |
ankur.sing |
669 |
if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
|
| 2387 |
ankur.sing |
670 |
sb.append("\n-Weight");
|
| 2027 |
ankur.sing |
671 |
}
|
| 2489 |
ankur.sing |
672 |
if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
|
| 2387 |
ankur.sing |
673 |
sb.append("\n-Best Deal Text");
|
| 2066 |
ankur.sing |
674 |
}
|
| 2489 |
ankur.sing |
675 |
if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
|
| 2387 |
ankur.sing |
676 |
sb.append("\n-Best Deal Value");
|
| 2027 |
ankur.sing |
677 |
}
|
| 2489 |
ankur.sing |
678 |
if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
|
| 2387 |
ankur.sing |
679 |
sb.append("\n-Best Selling Rank");
|
| 2066 |
ankur.sing |
680 |
}
|
|
|
681 |
if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
|
| 2387 |
ankur.sing |
682 |
sb.append("\n-Default For Entity Flag");
|
| 2066 |
ankur.sing |
683 |
}
|
| 2252 |
ankur.sing |
684 |
if(item.isRisky() != risky.getValue()) {
|
| 2387 |
ankur.sing |
685 |
sb.append("\n-Risky Flag");
|
| 2252 |
ankur.sing |
686 |
}
|
| 2489 |
ankur.sing |
687 |
if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
|
| 2387 |
ankur.sing |
688 |
sb.append("\n-Start Date");
|
| 2068 |
ankur.sing |
689 |
}
|
| 2126 |
ankur.sing |
690 |
VendorPricings vendorPricings;
|
| 2066 |
ankur.sing |
691 |
long vendorId;
|
| 2427 |
ankur.sing |
692 |
for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
|
|
|
693 |
vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
|
| 2126 |
ankur.sing |
694 |
vendorPricings = item.getVendorPricesMap().get(vendorId);
|
| 2359 |
ankur.sing |
695 |
if(vendorPricings == null) {
|
| 2387 |
ankur.sing |
696 |
sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
|
| 2359 |
ankur.sing |
697 |
continue;
|
|
|
698 |
}
|
| 2427 |
ankur.sing |
699 |
if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
|
| 2387 |
ankur.sing |
700 |
sb.append("\n-MOP (Vendor:" + vendorId + ")");
|
| 2066 |
ankur.sing |
701 |
}
|
| 2427 |
ankur.sing |
702 |
if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
|
| 2387 |
ankur.sing |
703 |
sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
|
| 2066 |
ankur.sing |
704 |
}
|
| 2427 |
ankur.sing |
705 |
if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
|
| 2387 |
ankur.sing |
706 |
sb.append("\n-Transfer Price (Vendor:" + vendorId + ")");
|
| 2066 |
ankur.sing |
707 |
}
|
|
|
708 |
}
|
| 2387 |
ankur.sing |
709 |
|
|
|
710 |
VendorItemMapping mapping;
|
|
|
711 |
String old_key, new_key;
|
| 2427 |
ankur.sing |
712 |
for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
|
|
|
713 |
vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
|
|
|
714 |
old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
|
|
|
715 |
new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
|
| 2387 |
ankur.sing |
716 |
mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
|
|
|
717 |
if(mapping == null || !old_key.equals(new_key)) {
|
|
|
718 |
sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
|
|
|
719 |
continue;
|
|
|
720 |
}
|
|
|
721 |
}
|
| 2252 |
ankur.sing |
722 |
return sb.toString();
|
| 2066 |
ankur.sing |
723 |
}
|
|
|
724 |
|
| 2566 |
chandransh |
725 |
@SuppressWarnings("unused")
|
|
|
726 |
private boolean validatePrices() {
|
| 2066 |
ankur.sing |
727 |
if(newItem.getSellingPrice() > newItem.getMrp()) {
|
|
|
728 |
Window.alert("Selling price cannot be more than MRP");
|
|
|
729 |
return false;
|
|
|
730 |
}
|
| 2119 |
ankur.sing |
731 |
for(VendorPricings v : newItem.getVendorPricesMap().values()) {
|
| 2105 |
ankur.sing |
732 |
if(newItem.getMrp() < v.getMop()) {
|
|
|
733 |
Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
|
| 2066 |
ankur.sing |
734 |
return false;
|
|
|
735 |
}
|
| 2105 |
ankur.sing |
736 |
if(v.getTransferPrice() > v.getMop()) {
|
|
|
737 |
Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
|
| 2066 |
ankur.sing |
738 |
return false;
|
|
|
739 |
}
|
|
|
740 |
}
|
|
|
741 |
return true;
|
|
|
742 |
}
|
| 2105 |
ankur.sing |
743 |
|
| 2119 |
ankur.sing |
744 |
private boolean validateVendorPrices(double mop, double dp, double tp) {
|
| 2489 |
ankur.sing |
745 |
if(item.getMrp() != null && item.getMrp() < mop) {
|
| 2105 |
ankur.sing |
746 |
Window.alert("MOP cannot be more than MRP.");
|
|
|
747 |
return false;
|
| 1992 |
ankur.sing |
748 |
}
|
| 2105 |
ankur.sing |
749 |
if(tp > mop) {
|
|
|
750 |
Window.alert("Transfer Price cannot be more than MOP.");
|
|
|
751 |
return false;
|
| 1992 |
ankur.sing |
752 |
}
|
| 2105 |
ankur.sing |
753 |
return true;
|
| 1992 |
ankur.sing |
754 |
}
|
| 2105 |
ankur.sing |
755 |
|
|
|
756 |
public long getItemId() {
|
|
|
757 |
return item == null ? 0 : item.getId();
|
|
|
758 |
}
|
|
|
759 |
|
|
|
760 |
public Item getItem() {
|
|
|
761 |
return item;
|
|
|
762 |
}
|
|
|
763 |
|
| 2427 |
ankur.sing |
764 |
/**
|
|
|
765 |
* This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
|
|
|
766 |
* @param vendorId
|
|
|
767 |
* @return true if parameter vendor Id is already added to vendor prices table.
|
|
|
768 |
* <br>else false
|
|
|
769 |
*/
|
| 2105 |
ankur.sing |
770 |
private boolean vendorExists(long vendorId) {
|
|
|
771 |
long id;
|
| 2427 |
ankur.sing |
772 |
for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
|
|
|
773 |
id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
|
| 2105 |
ankur.sing |
774 |
if(vendorId == id) {
|
|
|
775 |
return false;
|
|
|
776 |
}
|
| 1992 |
ankur.sing |
777 |
}
|
| 2105 |
ankur.sing |
778 |
return true;
|
| 1992 |
ankur.sing |
779 |
}
|
| 2387 |
ankur.sing |
780 |
|
| 2427 |
ankur.sing |
781 |
/**
|
|
|
782 |
* This method is used to check if any of the string item attributes is changed by the user.
|
| 2489 |
ankur.sing |
783 |
* @param o1
|
|
|
784 |
* @param o2
|
| 2427 |
ankur.sing |
785 |
* @return true if two strings are equal
|
|
|
786 |
* <br>true if one of them is null and another is empty.
|
|
|
787 |
* <br>false otherwise
|
|
|
788 |
*/
|
| 2489 |
ankur.sing |
789 |
private boolean checkParameterIfEqual(Object o1, Object o2) {
|
|
|
790 |
if(o1 == o2) {
|
| 2387 |
ankur.sing |
791 |
return true;
|
|
|
792 |
}
|
| 2489 |
ankur.sing |
793 |
if(o1 != null && o2 != null && o1.equals(o2)) {
|
| 2387 |
ankur.sing |
794 |
return true;
|
|
|
795 |
}
|
| 2489 |
ankur.sing |
796 |
if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
|
| 2387 |
ankur.sing |
797 |
return true;
|
|
|
798 |
}
|
|
|
799 |
return false;
|
|
|
800 |
}
|
| 2489 |
ankur.sing |
801 |
|
|
|
802 |
public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
|
|
|
803 |
this.catalogDashboardPanel = catalogDashboardPanel;
|
|
|
804 |
}
|
| 1961 |
ankur.sing |
805 |
}
|