| 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.uibinder.client.UiHandler;
|
|
|
20 |
import com.google.gwt.user.client.Window;
|
|
|
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 |
|
|
|
31 |
public class ItemDetails extends ResizeComposite {
|
|
|
32 |
|
| 2119 |
ankur.sing |
33 |
private final int TABLE_INDEX_VENDORID = 0,
|
|
|
34 |
TABLE_INDEX_VENDOR_DESC = 1,
|
|
|
35 |
TABLE_INDEX_ITEM_KEY = 2,
|
|
|
36 |
TABLE_INDEX_MOP = 2,
|
|
|
37 |
TABLE_INDEX_DP = 3,
|
|
|
38 |
TABLE_INDEX_TP = 4;
|
|
|
39 |
private final int TABLE_INDEX_WAREHOUSE_ID = 0,
|
|
|
40 |
TABLE_INDEX_WAREHOUSE_DESC = 1,
|
|
|
41 |
TABLE_INDEX_WAREHOUSE_INV = 2;
|
| 2066 |
ankur.sing |
42 |
|
|
|
43 |
interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
|
|
|
44 |
private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
|
|
|
45 |
|
|
|
46 |
public interface ItemUpdateListener {
|
| 1992 |
ankur.sing |
47 |
void onItemUpdate(Item item);
|
| 2066 |
ankur.sing |
48 |
}
|
| 1961 |
ankur.sing |
49 |
|
| 2066 |
ankur.sing |
50 |
interface ItemDetailStyle extends CssResource{
|
|
|
51 |
String greenLabel();
|
|
|
52 |
String fieldChanged();
|
|
|
53 |
}
|
| 1961 |
ankur.sing |
54 |
|
| 2066 |
ankur.sing |
55 |
private ItemUpdateListener itemUpdateListener;
|
|
|
56 |
|
| 2105 |
ankur.sing |
57 |
private Item item, newItem;
|
| 2066 |
ankur.sing |
58 |
|
|
|
59 |
@UiField ItemDetailStyle style;
|
|
|
60 |
@UiField Label itemId;
|
|
|
61 |
@UiField TextBox productGroup, brand, modelNumber, modelName, color;
|
| 2105 |
ankur.sing |
62 |
@UiField Label contentCategory, catalogItemId;
|
| 2066 |
ankur.sing |
63 |
@UiField TextBox comments;
|
| 2105 |
ankur.sing |
64 |
@UiField TextBox sellingPrice, mrp, weight;
|
|
|
65 |
@UiField Label addedOn, retireDate, updatedOn;
|
| 2066 |
ankur.sing |
66 |
@UiField Label itemStatus;
|
|
|
67 |
@UiField TextBox bestDealsText, bestDealsValue;
|
|
|
68 |
@UiField FlexTable headerAvailability, availabilityTable;
|
| 2105 |
ankur.sing |
69 |
@UiField FlexTable headerVendorM, vendorTableM;
|
|
|
70 |
@UiField FlexTable headerVendor, vendorTable;
|
| 2066 |
ankur.sing |
71 |
@UiField TextBox bestSellingRank;
|
|
|
72 |
@UiField CheckBox defaultForEntity;
|
|
|
73 |
@UiField Button submit;
|
| 2068 |
ankur.sing |
74 |
@UiField DateBox startDate;
|
| 2066 |
ankur.sing |
75 |
|
|
|
76 |
public ItemDetails(Item item){
|
| 2105 |
ankur.sing |
77 |
this();
|
| 2066 |
ankur.sing |
78 |
setItemDetails(item);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public ItemDetails() {
|
|
|
82 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
83 |
initAvailabilityHeader();
|
| 2119 |
ankur.sing |
84 |
initMappingHeader();
|
| 2066 |
ankur.sing |
85 |
initPricingHeader();
|
| 2119 |
ankur.sing |
86 |
|
| 2105 |
ankur.sing |
87 |
headerAvailability.setVisible(false);
|
|
|
88 |
availabilityTable.setVisible(false);
|
| 2066 |
ankur.sing |
89 |
}
|
|
|
90 |
|
|
|
91 |
public void setItemDetails(Item item){
|
|
|
92 |
this.item = item;
|
|
|
93 |
itemId.setText(item.getId()+"");
|
|
|
94 |
productGroup.setText(item.getProductGroup());
|
|
|
95 |
brand.setText(item.getBrand());
|
|
|
96 |
modelNumber.setText(item.getModelNumber());
|
|
|
97 |
modelName.setText(item.getModelName());
|
|
|
98 |
color.setText(item.getColor());
|
|
|
99 |
|
| 2105 |
ankur.sing |
100 |
contentCategory.setText(item.getContentCategory()+"");
|
| 2066 |
ankur.sing |
101 |
comments.setText(item.getComments());
|
|
|
102 |
catalogItemId.setText(item.getCatalogItemId() + "");
|
|
|
103 |
|
|
|
104 |
mrp.setText(item.getMrp()+"");
|
|
|
105 |
sellingPrice.setText(item.getSellingPrice()+"");
|
|
|
106 |
weight.setText(item.getWeight()+"");
|
| 2068 |
ankur.sing |
107 |
|
|
|
108 |
startDate.setValue(new Date(item.getStartDate()));
|
|
|
109 |
|
|
|
110 |
addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
|
|
|
111 |
retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
|
|
|
112 |
updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
|
| 1992 |
ankur.sing |
113 |
|
| 2066 |
ankur.sing |
114 |
bestDealsText.setText(item.getBestDealsText());
|
|
|
115 |
bestDealsValue.setText(item.getBestDealsValue()+"");
|
|
|
116 |
|
|
|
117 |
bestSellingRank.setText(item.getBestSellingRank()+"");
|
|
|
118 |
defaultForEntity.setValue(item.isDefaultForEntity());
|
| 1992 |
ankur.sing |
119 |
|
| 2066 |
ankur.sing |
120 |
itemStatus.setText(item.getItemStatus());
|
|
|
121 |
|
|
|
122 |
updateAvailabilityTable(item.getAvailability());
|
| 2119 |
ankur.sing |
123 |
updateMappingTable(item.getVendorMappingsMap());
|
|
|
124 |
updatePricingTable(item.getVendorPricesMap());
|
| 1992 |
ankur.sing |
125 |
}
|
| 2066 |
ankur.sing |
126 |
|
|
|
127 |
private void initAvailabilityHeader(){
|
| 1992 |
ankur.sing |
128 |
// Initialize the header.
|
| 2066 |
ankur.sing |
129 |
headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
|
| 2105 |
ankur.sing |
130 |
headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
|
| 2066 |
ankur.sing |
131 |
headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
|
|
|
132 |
|
|
|
133 |
headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");
|
|
|
134 |
headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");
|
|
|
135 |
headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INV, "Availability");
|
| 1992 |
ankur.sing |
136 |
|
|
|
137 |
}
|
| 2066 |
ankur.sing |
138 |
|
| 2119 |
ankur.sing |
139 |
private void initMappingHeader(){
|
|
|
140 |
// Initialize the header.
|
|
|
141 |
headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
|
|
|
142 |
headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
|
|
|
143 |
headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
|
|
|
144 |
headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
|
|
|
145 |
|
|
|
146 |
headerVendorM.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
|
|
|
147 |
headerVendorM.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor Desc");
|
|
|
148 |
headerVendorM.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
|
|
|
149 |
|
|
|
150 |
Button addButton = new Button("Add");
|
|
|
151 |
headerVendorM.setWidget(0, TABLE_INDEX_ITEM_KEY + 1, addButton);
|
|
|
152 |
addButton.addClickHandler(new ClickHandler() {
|
|
|
153 |
@Override
|
|
|
154 |
public void onClick(ClickEvent event) {
|
|
|
155 |
VendorMappingDialog vendorMappingDialog = new VendorMappingDialog();
|
|
|
156 |
vendorMappingDialog.updateButton.setText("Add");
|
|
|
157 |
vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
|
|
|
158 |
@Override
|
|
|
159 |
public boolean onUpdate(String key, long vendorId) {
|
|
|
160 |
int row = vendorTableM.getRowCount();
|
|
|
161 |
vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
|
|
|
162 |
vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
|
|
|
163 |
vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
|
|
|
164 |
|
|
|
165 |
vendorTableM.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
|
|
|
166 |
vendorTableM.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
|
|
|
167 |
vendorTableM.setText(row, TABLE_INDEX_ITEM_KEY, key);
|
|
|
168 |
return true;
|
|
|
169 |
}
|
|
|
170 |
});
|
|
|
171 |
vendorMappingDialog.show();
|
|
|
172 |
}
|
|
|
173 |
});
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
|
| 2066 |
ankur.sing |
177 |
private void initPricingHeader(){
|
|
|
178 |
// Initialize the header.
|
| 2105 |
ankur.sing |
179 |
headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
|
|
|
180 |
headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
|
|
|
181 |
headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
|
|
|
182 |
headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
|
|
|
183 |
headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
|
|
|
184 |
headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
|
| 2119 |
ankur.sing |
185 |
headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP + 1, "50px");
|
| 2066 |
ankur.sing |
186 |
|
| 2105 |
ankur.sing |
187 |
headerVendor.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
|
|
|
188 |
headerVendor.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor Desc");
|
|
|
189 |
headerVendor.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
|
|
|
190 |
headerVendor.setText(0, TABLE_INDEX_MOP, "MOP");
|
|
|
191 |
headerVendor.setText(0, TABLE_INDEX_DP, "Dealer Price");
|
|
|
192 |
headerVendor.setText(0, TABLE_INDEX_TP, "Transfer Price");
|
|
|
193 |
|
|
|
194 |
Button addButton = new Button("Add");
|
|
|
195 |
headerVendor.setWidget(0, TABLE_INDEX_TP + 1, addButton);
|
|
|
196 |
addButton.addClickHandler(new ClickHandler() {
|
|
|
197 |
@Override
|
|
|
198 |
public void onClick(ClickEvent event) {
|
| 2119 |
ankur.sing |
199 |
VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
|
|
|
200 |
vendorPricesDialog.updateButton.setText("Add");
|
|
|
201 |
vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
|
| 2105 |
ankur.sing |
202 |
@Override
|
| 2119 |
ankur.sing |
203 |
public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
|
| 2105 |
ankur.sing |
204 |
if(!vendorExists(vendorId)) {
|
|
|
205 |
Window.alert("Vendor already exists");
|
|
|
206 |
return false;
|
|
|
207 |
}
|
| 2119 |
ankur.sing |
208 |
/*if(!validateVendorPrices(mop, dp, tp)) {
|
| 2105 |
ankur.sing |
209 |
return false;
|
| 2119 |
ankur.sing |
210 |
}*/
|
| 2105 |
ankur.sing |
211 |
int row = vendorTable.getRowCount();
|
|
|
212 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
|
|
|
213 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
|
|
|
214 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
|
|
|
215 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
|
|
|
216 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
|
|
|
217 |
|
|
|
218 |
vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
|
|
|
219 |
vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
|
|
|
220 |
vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
|
|
|
221 |
vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
|
|
|
222 |
vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
|
|
|
223 |
return true;
|
|
|
224 |
}
|
|
|
225 |
});
|
| 2119 |
ankur.sing |
226 |
vendorPricesDialog.show();
|
| 2105 |
ankur.sing |
227 |
}
|
|
|
228 |
});
|
| 2066 |
ankur.sing |
229 |
}
|
| 2105 |
ankur.sing |
230 |
|
| 1992 |
ankur.sing |
231 |
private void updateAvailabilityTable(Map<Long, Long> availabilityMap){
|
|
|
232 |
availabilityTable.removeAllRows();
|
|
|
233 |
if(availabilityMap == null) {
|
|
|
234 |
return;
|
|
|
235 |
}
|
| 2066 |
ankur.sing |
236 |
availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
|
| 2105 |
ankur.sing |
237 |
availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
|
| 2066 |
ankur.sing |
238 |
availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
|
|
|
239 |
|
|
|
240 |
|
| 1992 |
ankur.sing |
241 |
int i=0;
|
|
|
242 |
for(Entry<Long, Long> availability : availabilityMap.entrySet()){
|
| 2066 |
ankur.sing |
243 |
availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, availability.getKey() + "");
|
|
|
244 |
availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(availability.getKey()));
|
|
|
245 |
availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INV, availability.getValue() + "");
|
| 1992 |
ankur.sing |
246 |
i++;
|
|
|
247 |
}
|
|
|
248 |
}
|
| 2119 |
ankur.sing |
249 |
|
|
|
250 |
private void updateMappingTable(Map<Long, VendorItemMapping> vendorMappingsMap){
|
|
|
251 |
vendorTableM.removeAllRows();
|
|
|
252 |
|
|
|
253 |
if(vendorMappingsMap == null || vendorMappingsMap.isEmpty()) {
|
|
|
254 |
return;
|
|
|
255 |
}
|
|
|
256 |
vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
|
|
|
257 |
vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
|
|
|
258 |
vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
|
|
|
259 |
vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
|
| 2066 |
ankur.sing |
260 |
|
| 2119 |
ankur.sing |
261 |
int i=0;
|
|
|
262 |
for(VendorItemMapping vendorMapping : vendorMappingsMap.values()){
|
|
|
263 |
vendorTableM.setText(i, TABLE_INDEX_VENDORID, vendorMapping.getVendorId() + "");
|
|
|
264 |
vendorTableM.setText(i, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));
|
|
|
265 |
vendorTableM.setText(i, TABLE_INDEX_ITEM_KEY, vendorMapping.getItemKey());
|
|
|
266 |
Button editButton = new Button("Edit");
|
|
|
267 |
vendorTableM.setWidget(i, TABLE_INDEX_ITEM_KEY + 1, editButton);
|
|
|
268 |
i++;
|
|
|
269 |
editButton.addClickHandler(new ClickHandler() {
|
|
|
270 |
@Override
|
|
|
271 |
public void onClick(ClickEvent event) {
|
|
|
272 |
Cell cell = vendorTableM.getCellForEvent(event);
|
|
|
273 |
int row = cell.getRowIndex();
|
|
|
274 |
long vendorId = Long.parseLong(vendorTableM.getText(row, TABLE_INDEX_VENDORID));
|
|
|
275 |
updateVendorMapping(vendorId, row);
|
|
|
276 |
}
|
|
|
277 |
});
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
private void updatePricingTable(Map<Long, VendorPricings> vendorPricingMap){
|
| 2105 |
ankur.sing |
282 |
vendorTable.removeAllRows();
|
|
|
283 |
|
| 2119 |
ankur.sing |
284 |
if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {
|
| 1992 |
ankur.sing |
285 |
return;
|
|
|
286 |
}
|
| 2105 |
ankur.sing |
287 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
|
|
|
288 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
|
|
|
289 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
|
|
|
290 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
|
|
|
291 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
|
| 2119 |
ankur.sing |
292 |
vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP + 1, "50px");
|
| 2066 |
ankur.sing |
293 |
|
|
|
294 |
|
| 1992 |
ankur.sing |
295 |
int i=0;
|
| 2119 |
ankur.sing |
296 |
for(VendorPricings vendorDetail : vendorPricingMap.values()){
|
| 2105 |
ankur.sing |
297 |
vendorTable.setText(i, TABLE_INDEX_VENDORID, vendorDetail.getVendorId() + "");
|
|
|
298 |
vendorTable.setText(i, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
|
|
|
299 |
vendorTable.setText(i, TABLE_INDEX_MOP, vendorDetail.getMop() + "");
|
|
|
300 |
vendorTable.setText(i, TABLE_INDEX_DP, vendorDetail.getDealerPrice() + "");
|
|
|
301 |
vendorTable.setText(i, TABLE_INDEX_TP, vendorDetail.getTransferPrice() + "");
|
| 1992 |
ankur.sing |
302 |
Button editButton = new Button("Edit");
|
| 2105 |
ankur.sing |
303 |
vendorTable.setWidget(i, TABLE_INDEX_TP + 1, editButton);
|
| 1992 |
ankur.sing |
304 |
i++;
|
|
|
305 |
editButton.addClickHandler(new ClickHandler() {
|
|
|
306 |
@Override
|
|
|
307 |
public void onClick(ClickEvent event) {
|
| 2105 |
ankur.sing |
308 |
Cell cell = vendorTable.getCellForEvent(event);
|
| 1992 |
ankur.sing |
309 |
int row = cell.getRowIndex();
|
| 2105 |
ankur.sing |
310 |
long vendorId = Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID));
|
| 1992 |
ankur.sing |
311 |
updateVendorPrices(vendorId, row);
|
|
|
312 |
}
|
|
|
313 |
});
|
|
|
314 |
}
|
|
|
315 |
}
|
| 2066 |
ankur.sing |
316 |
|
|
|
317 |
public void setItemUpdateListener(ItemUpdateListener itemUpdatelistener) {
|
|
|
318 |
this.itemUpdateListener = itemUpdatelistener;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
@UiHandler("submit")
|
|
|
322 |
void onSubmitPressed(ClickEvent clickEvent) {
|
|
|
323 |
try {
|
| 2068 |
ankur.sing |
324 |
updateItem();
|
| 2066 |
ankur.sing |
325 |
if(!isItemChanged()) {
|
|
|
326 |
Window.alert("Nothing to update. Please change intended item parameters and try again.");
|
|
|
327 |
return;
|
|
|
328 |
}
|
| 2119 |
ankur.sing |
329 |
if(!Utils.validateItem(newItem)) {
|
|
|
330 |
return;
|
|
|
331 |
}
|
| 2068 |
ankur.sing |
332 |
|
| 2119 |
ankur.sing |
333 |
/*if(!validatePrices()) {
|
| 2066 |
ankur.sing |
334 |
return;
|
| 2119 |
ankur.sing |
335 |
}*/
|
| 2105 |
ankur.sing |
336 |
//updateItem(); -- Calling this method above. A new item is created with updated data.
|
| 2066 |
ankur.sing |
337 |
} catch(NumberFormatException ex) {
|
|
|
338 |
return;
|
|
|
339 |
}
|
|
|
340 |
itemUpdateListener.onItemUpdate(newItem);
|
| 2027 |
ankur.sing |
341 |
GWT.log("Item updated. Id = " + item.getId());
|
| 2066 |
ankur.sing |
342 |
item = newItem;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
private void updateItem() throws NumberFormatException {
|
|
|
346 |
newItem = new Item();
|
|
|
347 |
newItem.setId(Long.parseLong(itemId.getText()));
|
|
|
348 |
newItem.setProductGroup(productGroup.getText().trim());
|
|
|
349 |
newItem.setBrand(brand.getText().trim());
|
|
|
350 |
newItem.setModelNumber(modelNumber.getText().trim());
|
|
|
351 |
newItem.setModelName(modelName.getText().trim());
|
|
|
352 |
newItem.setColor(color.getText().trim());
|
| 2119 |
ankur.sing |
353 |
newItem.setContentCategory(contentCategory.getText());
|
| 2066 |
ankur.sing |
354 |
newItem.setComments(comments.getText().trim());
|
|
|
355 |
newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
|
|
|
356 |
newItem.setFeatureId(item.getFeatureId());
|
|
|
357 |
newItem.setFeatureDescription(item.getFeatureDescription());
|
| 2068 |
ankur.sing |
358 |
try {
|
|
|
359 |
newItem.setMrp(Double.parseDouble(mrp.getText().trim()));
|
|
|
360 |
} catch(NumberFormatException ex) {
|
|
|
361 |
Window.alert("Invalid MRP format");
|
|
|
362 |
throw new NumberFormatException();
|
|
|
363 |
}
|
|
|
364 |
try {
|
|
|
365 |
newItem.setSellingPrice(Double.parseDouble(sellingPrice.getText().trim()));
|
|
|
366 |
}
|
|
|
367 |
catch(NumberFormatException ex) {
|
|
|
368 |
Window.alert("Invalid Selling Price format");
|
|
|
369 |
throw new NumberFormatException();
|
|
|
370 |
}
|
|
|
371 |
try {
|
|
|
372 |
newItem.setWeight(Double.parseDouble(weight.getText().trim()));
|
|
|
373 |
} catch(NumberFormatException ex) {
|
|
|
374 |
Window.alert("Invalid Weight format");
|
|
|
375 |
throw new NumberFormatException();
|
|
|
376 |
}
|
| 2066 |
ankur.sing |
377 |
newItem.setAddedOn(item.getAddedOn());
|
| 2068 |
ankur.sing |
378 |
newItem.setStartDate(startDate.getValue().getTime());
|
| 2066 |
ankur.sing |
379 |
newItem.setRetireDate(item.getRetireDate());
|
|
|
380 |
newItem.setUpdatedOn(item.getUpdatedOn());
|
|
|
381 |
newItem.setItemStatus(item.getItemStatus());
|
|
|
382 |
newItem.setOtherInfo(item.getOtherInfo());
|
|
|
383 |
newItem.setBestDealsText(bestDealsText.getText().trim());
|
| 2068 |
ankur.sing |
384 |
try {
|
|
|
385 |
newItem.setBestDealsValue(Double.parseDouble(bestDealsValue.getText().trim()));
|
|
|
386 |
} catch(NumberFormatException ex) {
|
|
|
387 |
Window.alert("Invalid Best Deals Value format");
|
|
|
388 |
throw new NumberFormatException();
|
|
|
389 |
}
|
|
|
390 |
try {
|
|
|
391 |
newItem.setBestSellingRank(Long.parseLong(bestSellingRank.getText().trim()));
|
|
|
392 |
} catch (NumberFormatException ex) {
|
|
|
393 |
Window.alert("Invalid Best Selling Rank format");
|
|
|
394 |
throw new NumberFormatException();
|
|
|
395 |
}
|
|
|
396 |
|
| 2066 |
ankur.sing |
397 |
newItem.setDefaultForEntity(defaultForEntity.getValue());
|
|
|
398 |
newItem.setAvailability(item.getAvailability());
|
| 2119 |
ankur.sing |
399 |
|
|
|
400 |
Map<Long, VendorPricings> vendorPricings = new HashMap<Long, VendorPricings>();
|
|
|
401 |
VendorPricings v;
|
| 2105 |
ankur.sing |
402 |
for(int row = 0; row < vendorTable.getRowCount(); row++) {
|
| 2119 |
ankur.sing |
403 |
v = new VendorPricings();
|
| 2105 |
ankur.sing |
404 |
v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
|
|
|
405 |
v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
|
|
|
406 |
v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
|
|
|
407 |
v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
|
| 2119 |
ankur.sing |
408 |
vendorPricings.put(v.getVendorId(), v);
|
| 2105 |
ankur.sing |
409 |
newItem.setMop(v.getMop());
|
|
|
410 |
newItem.setDealerPrice(v.getDealerPrice());
|
|
|
411 |
newItem.setTransferPrice(v.getTransferPrice());
|
| 2066 |
ankur.sing |
412 |
}
|
| 2119 |
ankur.sing |
413 |
newItem.setVendorPricesMap(vendorPricings);
|
| 2027 |
ankur.sing |
414 |
|
| 2119 |
ankur.sing |
415 |
Map<Long, VendorItemMapping> vendorMapping = new HashMap<Long, VendorItemMapping>();
|
|
|
416 |
VendorItemMapping vM;
|
|
|
417 |
for(int row = 0; row < vendorTableM.getRowCount(); row++) {
|
|
|
418 |
vM = new VendorItemMapping();
|
|
|
419 |
vM.setVendorId(Long.parseLong(vendorTableM.getText(row, TABLE_INDEX_VENDORID)));
|
|
|
420 |
vM.setItemKey(vendorTableM.getText(row, TABLE_INDEX_ITEM_KEY));
|
|
|
421 |
vendorMapping.put(vM.getVendorId(), vM);
|
|
|
422 |
}
|
|
|
423 |
newItem.setVendorMappingsMap(vendorMapping);
|
|
|
424 |
|
|
|
425 |
|
| 2066 |
ankur.sing |
426 |
/*item.setProductGroup(productGroup.getText().trim());
|
|
|
427 |
item.setBrand(brand.getText().trim());
|
|
|
428 |
item.setModelName(modelName.getText().trim());
|
|
|
429 |
item.setModelNumber(modelNumber.getText().trim());
|
|
|
430 |
item.setColor(color.getText().trim());
|
|
|
431 |
item.setComments(comments.getText().trim());
|
|
|
432 |
item.setMrp(Double.parseDouble(this.mrp.getText()));
|
|
|
433 |
item.setSellingPrice(Double.parseDouble(this.sellingPrice.getText()));
|
|
|
434 |
item.setWeight(Double.parseDouble(this.weight.getText()));
|
|
|
435 |
item.setBestDealsText(bestDealsText.getText().trim());
|
|
|
436 |
item.setBestDealsValue(Double.parseDouble(bestDealsValue.getText().trim()));
|
|
|
437 |
item.setBestSellingRank(Long.parseLong(bestSellingRank.getText().trim()));
|
|
|
438 |
item.setDefaultForEntity(defaultForEntity.getValue());
|
|
|
439 |
for(int row = 0; row < pricingTable.getRowCount(); row++) {
|
|
|
440 |
long vendorId = Long.parseLong(pricingTable.getText(row, TABLE_INDEX_VENDORID));
|
|
|
441 |
double mop = Double.parseDouble(pricingTable.getText(row, TABLE_INDEX_MOP));
|
|
|
442 |
double dp = Double.parseDouble(pricingTable.getText(row, TABLE_INDEX_DP));
|
|
|
443 |
double tp = Double.parseDouble(pricingTable.getText(row, TABLE_INDEX_TP));
|
|
|
444 |
item.getVendorPricings().get(vendorId)[Item.INDEX_MOP] = mop;
|
|
|
445 |
item.getVendorPricings().get(vendorId)[Item.INDEX_DP] = dp;
|
|
|
446 |
item.getVendorPricings().get(vendorId)[Item.INDEX_TP] = tp;
|
|
|
447 |
item.setMop(mop);
|
|
|
448 |
item.setDealerPrice(dp);
|
|
|
449 |
item.setTransferPrice(tp);
|
|
|
450 |
}*/
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
private void updateVendorPrices(final long vendorId, final int row) {
|
| 2105 |
ankur.sing |
454 |
String mop = vendorTable.getText(row, TABLE_INDEX_MOP);
|
|
|
455 |
String dp = vendorTable.getText(row, TABLE_INDEX_DP);
|
|
|
456 |
String tp = vendorTable.getText(row, TABLE_INDEX_TP);
|
|
|
457 |
String key = vendorTable.getText(row, TABLE_INDEX_ITEM_KEY);
|
| 2119 |
ankur.sing |
458 |
VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);
|
| 2105 |
ankur.sing |
459 |
pricesDialog.updateButton.setText("Update");
|
| 2119 |
ankur.sing |
460 |
pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
|
| 2066 |
ankur.sing |
461 |
@Override
|
| 2119 |
ankur.sing |
462 |
public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
|
|
|
463 |
if(!validateVendorPrices(mop, dp, tp)) {
|
| 2105 |
ankur.sing |
464 |
return false;
|
|
|
465 |
}
|
|
|
466 |
vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
|
|
|
467 |
vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
|
|
|
468 |
vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
|
|
|
469 |
return true;
|
| 2066 |
ankur.sing |
470 |
}
|
|
|
471 |
});
|
|
|
472 |
pricesDialog.show();
|
|
|
473 |
}
|
| 2119 |
ankur.sing |
474 |
|
|
|
475 |
private void updateVendorMapping(final long vendorId, final int row) {
|
|
|
476 |
String key = vendorTableM.getText(row, TABLE_INDEX_ITEM_KEY);
|
|
|
477 |
VendorMappingDialog mappingDialog = new VendorMappingDialog(key);
|
|
|
478 |
mappingDialog.updateButton.setText("Update");
|
|
|
479 |
mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
|
|
|
480 |
@Override
|
|
|
481 |
public boolean onUpdate(String itemKey, long vendorId) {
|
|
|
482 |
if(itemKey == null || itemKey.equals("")) {
|
|
|
483 |
Window.alert("Item key cannot be empty.");
|
|
|
484 |
return false;
|
|
|
485 |
}
|
|
|
486 |
vendorTableM.setText(row, TABLE_INDEX_ITEM_KEY, itemKey);
|
|
|
487 |
return true;
|
|
|
488 |
}
|
|
|
489 |
});
|
|
|
490 |
mappingDialog.show();
|
|
|
491 |
}
|
| 2066 |
ankur.sing |
492 |
|
|
|
493 |
private boolean isItemChanged() {
|
|
|
494 |
if(!productGroup.getText().trim().equals(item.getProductGroup())) {
|
|
|
495 |
return true;
|
|
|
496 |
}
|
|
|
497 |
if(!brand.getText().trim().equals(item.getBrand())) {
|
|
|
498 |
return true;
|
|
|
499 |
}
|
|
|
500 |
if(!modelNumber.getText().trim().equals(item.getModelNumber())) {
|
|
|
501 |
return true;
|
|
|
502 |
}
|
|
|
503 |
if(!modelName.getText().trim().equals(item.getModelName())) {
|
|
|
504 |
return true;
|
|
|
505 |
}
|
|
|
506 |
if(!color.getText().trim().equals(item.getColor())) {
|
|
|
507 |
return true;
|
|
|
508 |
}
|
|
|
509 |
if(!comments.getText().trim().equals(item.getComments())) {
|
|
|
510 |
return true;
|
|
|
511 |
}
|
|
|
512 |
try {
|
|
|
513 |
if(item.getMrp() != Double.parseDouble(mrp.getText().trim())) {
|
|
|
514 |
return true;
|
|
|
515 |
}
|
|
|
516 |
} catch(NumberFormatException ex) {
|
|
|
517 |
Window.alert("Invalid MRP format");
|
|
|
518 |
throw new NumberFormatException();
|
|
|
519 |
}
|
|
|
520 |
try {
|
|
|
521 |
if(item.getSellingPrice() != Double.parseDouble(sellingPrice.getText().trim())) {
|
|
|
522 |
return true;
|
|
|
523 |
}
|
|
|
524 |
} catch(NumberFormatException ex) {
|
| 2027 |
ankur.sing |
525 |
Window.alert("Invalid Selling Price format");
|
|
|
526 |
throw new NumberFormatException();
|
|
|
527 |
}
|
| 2066 |
ankur.sing |
528 |
try {
|
|
|
529 |
if(item.getWeight() != Double.parseDouble(weight.getText().trim())) {
|
|
|
530 |
return true;
|
|
|
531 |
}
|
|
|
532 |
} catch(NumberFormatException ex) {
|
| 2027 |
ankur.sing |
533 |
Window.alert("Invalid Weight format");
|
|
|
534 |
throw new NumberFormatException();
|
|
|
535 |
}
|
| 2066 |
ankur.sing |
536 |
if(!bestDealsText.getText().trim().equals(item.getBestDealsText())) {
|
|
|
537 |
return true;
|
|
|
538 |
}
|
|
|
539 |
try {
|
|
|
540 |
if(item.getBestDealsValue() != Double.parseDouble(bestDealsValue.getText().trim())) {
|
|
|
541 |
return true;
|
|
|
542 |
}
|
|
|
543 |
} catch(NumberFormatException ex) {
|
| 2027 |
ankur.sing |
544 |
Window.alert("Invalid Best Deals Value format");
|
|
|
545 |
throw new NumberFormatException();
|
|
|
546 |
}
|
| 2066 |
ankur.sing |
547 |
try{
|
|
|
548 |
if(item.getBestSellingRank() != Long.parseLong(bestSellingRank.getText().trim())) {
|
|
|
549 |
return true;
|
| 1992 |
ankur.sing |
550 |
}
|
| 2066 |
ankur.sing |
551 |
} catch (NumberFormatException ex) {
|
|
|
552 |
Window.alert("Invalid Best Selling Rank format");
|
|
|
553 |
throw new NumberFormatException();
|
|
|
554 |
}
|
|
|
555 |
if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
|
|
|
556 |
return true;
|
|
|
557 |
}
|
| 2068 |
ankur.sing |
558 |
|
|
|
559 |
if(newItem.getStartDate() != item.getStartDate()) {
|
|
|
560 |
return true;
|
|
|
561 |
}
|
| 2066 |
ankur.sing |
562 |
|
| 2119 |
ankur.sing |
563 |
VendorPricings vendorDetails;
|
| 2066 |
ankur.sing |
564 |
long vendorId;
|
| 2105 |
ankur.sing |
565 |
for(int row = 0; row < vendorTable.getRowCount(); row++) {
|
|
|
566 |
vendorId = Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID));
|
| 2119 |
ankur.sing |
567 |
vendorDetails = item.getVendorPricesMap().get(vendorId);
|
| 2105 |
ankur.sing |
568 |
if(vendorDetails.getMop() != Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP))) {
|
| 2066 |
ankur.sing |
569 |
return true;
|
|
|
570 |
}
|
| 2105 |
ankur.sing |
571 |
if(vendorDetails.getDealerPrice() != Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP))) {
|
| 2066 |
ankur.sing |
572 |
return true;
|
|
|
573 |
}
|
| 2105 |
ankur.sing |
574 |
if(vendorDetails.getTransferPrice() != Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP))) {
|
| 2066 |
ankur.sing |
575 |
return true;
|
|
|
576 |
}
|
|
|
577 |
}
|
|
|
578 |
return false;
|
|
|
579 |
}
|
|
|
580 |
|
|
|
581 |
private boolean validatePrices() {
|
|
|
582 |
if(newItem.getSellingPrice() > newItem.getMrp()) {
|
|
|
583 |
Window.alert("Selling price cannot be more than MRP");
|
|
|
584 |
return false;
|
|
|
585 |
}
|
| 2119 |
ankur.sing |
586 |
for(VendorPricings v : newItem.getVendorPricesMap().values()) {
|
| 2105 |
ankur.sing |
587 |
if(newItem.getMrp() < v.getMop()) {
|
|
|
588 |
Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
|
| 2066 |
ankur.sing |
589 |
return false;
|
|
|
590 |
}
|
| 2105 |
ankur.sing |
591 |
if(v.getTransferPrice() > v.getMop()) {
|
|
|
592 |
Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
|
| 2066 |
ankur.sing |
593 |
return false;
|
|
|
594 |
}
|
|
|
595 |
}
|
|
|
596 |
return true;
|
|
|
597 |
}
|
| 2105 |
ankur.sing |
598 |
|
| 2119 |
ankur.sing |
599 |
private boolean validateVendorPrices(double mop, double dp, double tp) {
|
| 2105 |
ankur.sing |
600 |
if(item.getMrp() < mop) {
|
|
|
601 |
Window.alert("MOP cannot be more than MRP.");
|
|
|
602 |
return false;
|
| 1992 |
ankur.sing |
603 |
}
|
| 2105 |
ankur.sing |
604 |
if(tp > mop) {
|
|
|
605 |
Window.alert("Transfer Price cannot be more than MOP.");
|
|
|
606 |
return false;
|
| 1992 |
ankur.sing |
607 |
}
|
| 2105 |
ankur.sing |
608 |
return true;
|
| 1992 |
ankur.sing |
609 |
}
|
| 2105 |
ankur.sing |
610 |
|
|
|
611 |
public long getItemId() {
|
|
|
612 |
return item == null ? 0 : item.getId();
|
|
|
613 |
}
|
|
|
614 |
|
|
|
615 |
public Item getItem() {
|
|
|
616 |
return item;
|
|
|
617 |
}
|
|
|
618 |
|
|
|
619 |
private boolean vendorExists(long vendorId) {
|
|
|
620 |
long id;
|
|
|
621 |
for(int i = 0; i < vendorTable.getRowCount(); i++) {
|
|
|
622 |
id = Long.parseLong(vendorTable.getText(i, TABLE_INDEX_VENDORID));
|
|
|
623 |
if(vendorId == id) {
|
|
|
624 |
return false;
|
|
|
625 |
}
|
| 1992 |
ankur.sing |
626 |
}
|
| 2105 |
ankur.sing |
627 |
return true;
|
| 1992 |
ankur.sing |
628 |
}
|
| 1961 |
ankur.sing |
629 |
}
|