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