Subversion Repositories SmartDukaan

Rev

Rev 9841 | Rev 11671 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1961 ankur.sing 1
package in.shop2020.catalog.dashboard.client;
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
4431 phani.kuma 4
import in.shop2020.catalog.dashboard.shared.ItemInventory;
6530 vikram.rag 5
import in.shop2020.catalog.dashboard.shared.ItemWarehouse;
3558 rajveer 6
import in.shop2020.catalog.dashboard.shared.SourcePricings;
2066 ankur.sing 7
import in.shop2020.catalog.dashboard.shared.Utils;
2119 ankur.sing 8
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
9
import in.shop2020.catalog.dashboard.shared.VendorPricings;
5504 phani.kuma 10
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
1961 ankur.sing 11
 
5427 amit.gupta 12
import java.util.ArrayList;
1961 ankur.sing 13
import java.util.Date;
2066 ankur.sing 14
import java.util.HashMap;
5427 amit.gupta 15
import java.util.Iterator;
16
import java.util.List;
1992 ankur.sing 17
import java.util.Map;
18
import java.util.Map.Entry;
1961 ankur.sing 19
 
20
import com.google.gwt.core.client.GWT;
5427 amit.gupta 21
import com.google.gwt.dom.client.Style.Unit;
1961 ankur.sing 22
import com.google.gwt.event.dom.client.ClickEvent;
1992 ankur.sing 23
import com.google.gwt.event.dom.client.ClickHandler;
24
import com.google.gwt.resources.client.CssResource;
1961 ankur.sing 25
import com.google.gwt.uibinder.client.UiBinder;
26
import com.google.gwt.uibinder.client.UiField;
5427 amit.gupta 27
import com.google.gwt.uibinder.client.UiHandler;
1961 ankur.sing 28
import com.google.gwt.user.client.Window;
2126 ankur.sing 29
import com.google.gwt.user.client.rpc.AsyncCallback;
1961 ankur.sing 30
import com.google.gwt.user.client.ui.Button;
2066 ankur.sing 31
import com.google.gwt.user.client.ui.CheckBox;
5427 amit.gupta 32
import com.google.gwt.user.client.ui.DialogBox;
1992 ankur.sing 33
import com.google.gwt.user.client.ui.FlexTable;
34
import com.google.gwt.user.client.ui.HTMLTable.Cell;
1961 ankur.sing 35
import com.google.gwt.user.client.ui.Label;
4506 phani.kuma 36
import com.google.gwt.user.client.ui.ListBox;
1961 ankur.sing 37
import com.google.gwt.user.client.ui.ResizeComposite;
38
import com.google.gwt.user.client.ui.TextBox;
5427 amit.gupta 39
import com.google.gwt.user.client.ui.VerticalPanel;
1961 ankur.sing 40
import com.google.gwt.user.client.ui.Widget;
2068 ankur.sing 41
import com.google.gwt.user.datepicker.client.DateBox;
1961 ankur.sing 42
 
2427 ankur.sing 43
/**
44
 * Panel contains fields for item details. Some of these fields are editable.
45
 * It also contains vendor item pricings, vendor item keys, and item availability in tabular format.
46
 * Item availability is made invisible for time being 
47
 */
5217 amit.gupta 48
public class ItemDetails extends ResizeComposite implements ComingSoon {
1961 ankur.sing 49
 
10484 vikram.rag 50
	private final int TABLE_INDEX_MAPPING_VENDOR_DESC = 0, 
51
	TABLE_INDEX_MAPPING_ITEM_KEY = 1,
52
	TABLE_INDEX_MAPPING_BUTTON = 2,
53
	TABLE_INDEX_MAPPING_VENDORID = 3, 
54
	TABLE_INDEX_MAPPING_ITEM_KEY_OLD = 4;
3558 rajveer 55
 
10484 vikram.rag 56
	private final int TABLE_INDEX_PRICING_VENDOR_DESC = 0, 
57
	TABLE_INDEX_PRICING_MOP = 1,
58
	TABLE_INDEX_PRICING_DP = 2,
59
	TABLE_INDEX_PRICING_TP = 3,
60
	TABLE_INDEX_PRICING_NLC = 4,
61
	TABLE_INDEX_PRICING_BUTTON = 5,
62
	TABLE_INDEX_PRICING_VENDORID = 6;
3558 rajveer 63
 
10484 vikram.rag 64
	private final int TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC = 0, 
65
	TABLE_INDEX_SOURCE_PRICING_MRP = 1,
66
	TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE = 2,
67
	TABLE_INDEX_SOURCE_PRICING_BUTTON = 3,
68
	TABLE_INDEX_SOURCE_PRICING_SOURCE_ID = 4;
2066 ankur.sing 69
 
10484 vikram.rag 70
	private final int TABLE_INDEX_WAREHOUSE_ID = 0,
71
	TABLE_INDEX_WAREHOUSE_DESC = 1,
72
	TABLE_INDEX_WAREHOUSE_INVA = 2,
73
	TABLE_INDEX_WAREHOUSE_INVR = 3,
74
	TABLE_INDEX_WAREHOUSE_HELD = 4,
75
	TABLE_INDEX_WAREHOUSE_EBAY_HELD = 5,
76
	TABLE_INDEX_WAREHOUSE_SNAPDEAL_HELD = 6,
77
	TABLE_INDEX_WAREHOUSE_FLIPKART_HELD = 7,
78
	TABLE_INDEX_WAREHOUSE_GET_BUTTON = 8,
79
	TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON = 9;
2066 ankur.sing 80
 
10484 vikram.rag 81
	private final int TABLE_INDEX_WAREHOUSE_NAME = 0,
82
	TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON = 1;
1961 ankur.sing 83
 
10484 vikram.rag 84
	private final int TABLE_INDEX_STATE_NAME = 0,
85
	TABLE_INDEX_STATE_TAX_PERCENTAGE = 1;
1961 ankur.sing 86
 
2066 ankur.sing 87
 
10484 vikram.rag 88
	private final int TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID = 0,
89
	TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP = 1,
90
	TABLE_INDEX_SIMILAR_ITEMS_BRAND = 2,
91
	TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER = 3,
92
	TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME = 4,
93
	TABLE_INDEX_SIMILAR_ITEMS_CATEGORY = 5,
94
	TABLE_INDEX_SIMILAR_ITEMS_BUTTON = 6;
2066 ankur.sing 95
 
10484 vikram.rag 96
	private final int TABLE_INDEX_VOUCHERS_TYPE = 0,
97
	TABLE_INDEX_VOUCHERS_AMOUNT = 1,
98
	TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON = 2,
99
	TABLE_INDEX_VOUCHERS_DEL_BUTTON = 3;
2066 ankur.sing 100
 
10484 vikram.rag 101
	private final String MANDATORY_MRP = "MRP",
102
	MANDATORY_WEIGHT = "Weight",
103
	MANDATORY_BEST_DEAL_TEXT = "Best Deal Text",
104
	MANDATORY_BEST_DEAL_DETAIL_TEXT = "Best Deal Detail Text",
105
	MANDATORY_BEST_DEAL_DETAIL_LINK = "Best Deal Detail Link",
106
	MANDATORY_BRAND = "Brand",
107
	MANDATORY_MODEL_NO = "Model Number",
108
	MANDATORY_MODEL_NAME = "Model Name";
4649 phani.kuma 109
 
2066 ankur.sing 110
 
10484 vikram.rag 111
	private final String OPTIONAL_SELLING_PRICE = "Selling Price",	
112
	OPTIONAL_VENDOR_PRICING = "Vendor Pricing",
113
	OPTIONAL_PREFERRED_VENDOR = "Preferred Vendor",
114
	OPTIONAL_PREFERRED_INSURER = "Preferred Insurer",
115
	OPTIONAL_SOURCE_PRICING = "Source Pricing",
116
	OPTIONAL_FREEBIE_ITEM_ID = "Freebie Item Id";
5217 amit.gupta 117
 
10484 vikram.rag 118
	private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",
119
	VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",
120
	BUTTON_WIDTH = "50px";
1992 ankur.sing 121
 
10484 vikram.rag 122
	private Map<String, String> ConfigMap;
123
	interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
124
	private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
125
	private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
126
	Map<String, Object> mandatoryChangedValMap;
127
	Map<String, Object> optionalChangedValMap;
2066 ankur.sing 128
 
10484 vikram.rag 129
 
130
	interface ItemDetailStyle extends CssResource{
131
		String greenLabel();
132
		String fieldChanged();
133
	}
134
 
135
	private Item item, newItem;
136
	private CatalogDashboard catalogDashboardPanel;
137
 
138
	@UiField ItemDetailStyle style;
139
	@UiField Label itemId;
140
	@UiField TextBox brand, modelNumber, modelName, color;
141
	@UiField Label contentCategory, catalogItemId, productGroup;
142
	@UiField TextBox statusDesc, comments;
143
	@UiField TextBox sellingPrice, mrp, weight;
144
	@UiField Label addedOn, retireDate, updatedOn;
145
	@UiField Label itemStatus;
146
	@UiField TextBox bestDealsText, bestDealsValue ,bestDealsDetailsText,bestDealsDetailsLink; 
147
	@UiField FlexTable headerAvailability, availabilityTable;
148
	@UiField FlexTable headerVendorItemKey, tableVendorItemKey;
149
	@UiField FlexTable headerVendorPrices, tableVendorPrices;
150
	@UiField FlexTable headerSourcePrices, tableSourcePrices;
151
	@UiField TextBox bestSellingRank;
152
	@UiField TextBox expectedDelay;
153
	@UiField CheckBox defaultForEntity, risky, warehouseStickiness, itemType, hasItemNo, showSellingPrice, holdOverride;
154
	@UiField DateBox startDate, expectedArrivalDate, comingSoonStartDate;
155
	@UiField FlexTable headerSimilarItems, tableSimilarItems;
156
	@UiField ListBox preferredVendor,preferredInsurer;
157
	@UiField Button comingSoonButton;
158
	@UiField FlexTable headerVouchers, tableVouchers;
159
	@UiField FlexTable headerIgnoredWarehouse,tableIgnoredWarehouse;
160
	@UiField FlexTable headerVatDetails,tableVatDetails;
161
	@UiField TextBox minStockLevel, numOfDaysStock;
162
	@UiField TextBox lastNdaySale, websiteLastNdaySale, amazonLastNdaySale, ebayLastNdaySale, snapdealLastNdaySale, flipkartLastNdaySale;
163
	@UiField TextBox freebieItemId;
164
	@UiField TextBox asin;
165
	@UiField TextBox holdInventory;
166
	@UiField TextBox defaultInventory;
167
 
168
	public ItemDetails(Item item){
169
		this();
170
		setItemDetails(item);
171
	}
172
 
173
	public ItemDetails() {
174
		initWidget(uiBinder.createAndBindUi(this));
175
		initAvailabilityHeader();
176
		initVendorKeysHeader();
177
		initVendorPricingHeader();
178
		initSourcePricingHeader();
179
		initSimilarItemList();
180
		initVoucherHeader();
181
		initIgnoredWarehouseHeader();
182
		preferredVendor.addItem("null");
183
		preferredInsurer.addItem("null");
184
		getConfigdataforPriceCompare();
185
	}
186
 
187
	public void getConfigdataforPriceCompare(){
188
		catalogService.getConfigdataforPriceCompare(new AsyncCallback<Map<String,String>>() {
189
			@Override
190
			public void onSuccess(Map<String, String> result) {
191
				ConfigMap = result;
192
			}
193
			@Override
194
			public void onFailure(Throwable caught) {
195
				caught.printStackTrace();
196
			}
197
		});
198
	}
199
 
200
	/**
201
	 * Sets the UI fields with item object attributes
202
	 * Also populates tables for vendor prices, keys and item availability
203
	 * @param item
204
	 */
205
	public void setItemDetails(Item item){
206
		this.item = item;
207
		itemId.setText(item.getId()+"");
208
		productGroup.setText(item.getProductGroup());
209
		brand.setText(item.getBrand());
210
		modelNumber.setText(item.getModelNumber());
211
		modelName.setText(item.getModelName());
212
		color.setText(item.getColor());
213
 
214
		statusDesc.setText(item.getItemStatusDesc());
215
		contentCategory.setText(item.getContentCategory()+"");
216
		comments.setText(item.getComments());
217
		catalogItemId.setText(item.getCatalogItemId() + "");
218
		preferredInsurer.clear();
219
		preferredVendor.clear();
220
		int index = -1;
221
		if (item.getPreferredVendor() == null) {
222
			index++;
223
			preferredVendor.addItem("select");
224
		}
225
 
226
		if((item.getVendorPricesMap() == null || item.getVendorPricesMap().isEmpty())) {
227
			if(item.getPreferredVendor() != null) {
228
				index++;
229
				preferredVendor.addItem(Utils.getVendorDesc(item.getPreferredVendor()));
230
			}
231
		}
232
		else {
233
			for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
234
				index++;
235
				preferredVendor.addItem(Utils.getVendorDesc(vendorDetail.getVendorId()));
236
				if(item.getPreferredVendor() != null && item.getPreferredVendor() == vendorDetail.getVendorId()) {
237
					preferredVendor.setSelectedIndex(index);
238
				}
239
			}
240
 
241
			if(item.getPreferredVendor() != null && !item.getVendorPricesMap().containsKey(item.getPreferredVendor())){
242
				index++;
243
				preferredVendor.addItem(Utils.getVendorDesc(item.getPreferredVendor()));
244
				preferredVendor.setSelectedIndex(index);
245
			}
246
		}
247
		index=0;
248
		preferredInsurer.addItem("select","0");
249
		preferredInsurer.setSelectedIndex(0);
250
		for (Map.Entry<Long, String> entry : Utils.getAllInsurers().entrySet()){
251
			index++;
252
			preferredInsurer.addItem(entry.getValue(),entry.getKey().toString());
253
			if(item.getPreferredInsurer()==entry.getKey()){
254
				preferredInsurer.setSelectedIndex(index);  
255
			}
256
		}
257
		mrp.setText(item.getMrp() != null ? item.getMrp()+"" : "");
258
		sellingPrice.setText(item.getSellingPrice() != null ? item.getSellingPrice()+"" : "");
259
		weight.setText(item.getWeight() != null ? item.getWeight()+"" : "");
260
		expectedDelay.setValue(item.getExpectedDelay()+"");
261
		warehouseStickiness.setValue(item.isWarehouseStickiness());
262
 
263
		hasItemNo.setValue(item.isHasItemNo());
264
		itemType.setValue(item.isItemType());
265
		showSellingPrice.setValue(item.isShowSellingPrice());
266
		holdOverride.setValue(item.isHoldOverride());
267
 
268
		startDate.setValue(new Date(item.getStartDate()));
269
		if(item.getComingSoonStartDate() != null){
270
			comingSoonStartDate.setValue(new Date(item.getComingSoonStartDate()));
271
		}else {
272
			comingSoonStartDate.setValue(null);
273
		}
274
 
275
		if(item.getExpectedArrivalDate() != null){
276
			expectedArrivalDate.setValue(new Date(item.getExpectedArrivalDate()));
277
		}else {
278
			expectedArrivalDate.setValue(null);
279
		}
280
		addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
281
		retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
282
		updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
283
 
284
		bestDealsText.setText(item.getBestDealsText());
285
		bestDealsDetailsText.setText(item.getBestDealsDetailsText());
286
		bestDealsDetailsLink.setText(item.getBestDealsDetailsLink());
287
		bestDealsValue.setText(item.getBestDealsValue() != null ? item.getBestDealsValue()+"" : "");
288
		bestSellingRank.setText(item.getBestSellingRank() != null ? item.getBestSellingRank()+"" : "");
289
		minStockLevel.setText(item.getMinStockLevel() != null ? item.getMinStockLevel()+"" : "");
290
		lastNdaySale.setText(item.getSaleHistory().get(0L));
291
		websiteLastNdaySale.setText(item.getSaleHistory().get(1L));
292
		amazonLastNdaySale.setText(item.getSaleHistory().get(3L));
293
		ebayLastNdaySale.setText(item.getSaleHistory().get(6L));
294
		snapdealLastNdaySale.setText(item.getSaleHistory().get(7L));
295
		flipkartLastNdaySale.setText(item.getSaleHistory().get(8L));
296
		numOfDaysStock.setText(item.getNumOfDaysStock() != null ? item.getNumOfDaysStock()+"" : "");
297
		defaultForEntity.setValue(item.isDefaultForEntity());
298
		risky.setValue(item.isRisky());
299
 
300
		itemStatus.setText(item.getItemStatus());
301
		freebieItemId.setText(item.getFreebieItemId().toString());
302
		asin.setText(item.getAsin());
303
		holdInventory.setText(Long.toString(item.getHoldInventory()));
304
		defaultInventory.setText(Long.toString(item.getDefaultInventory()));
305
		initVatDetailsHeader();
306
		updateVatDetailsTable(item.getStateNameVatPercentageMap());
307
		updateAvailabilityTable(item.getItemInventory());
308
		updateVendorKeysTable(item.getVendorKeysMap());
309
		updateVendorPricingTable(item.getVendorPricesMap());
310
		updateSourcePricingTable(item.getSourcePricesMap());
311
		updateSimilarItemsTable(item.getSimilarItems());
312
		updateVoucherTable(item.getVouchersMap());
313
		updateTableIgnoredWarehouse();
314
	}
315
 
316
	/**
317
	 * initialise item availability table header.
318
	 */
319
	private void initAvailabilityHeader(){
320
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "100px");
321
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "250px");
322
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVA, "100px");
323
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVR, "100px");
324
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_HELD, "100px");
325
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_EBAY_HELD, "80px");
326
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_SNAPDEAL_HELD, "80px");
327
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_FLIPKART_HELD, "80px");
328
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_GET_BUTTON, "100px");
329
		headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, "100px");
330
 
331
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");
332
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");
333
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INVA, "Availability");
334
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INVR, "Reserved");
335
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_HELD, "Held");
336
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_EBAY_HELD, "Ebay Held");
337
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_SNAPDEAL_HELD, "Snapdeal Held");
338
		headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_FLIPKART_HELD, "Flipkart Held");
339
 
340
		Button getLiveDataButton = new Button("Get Live Data");
341
		headerAvailability.setWidget(0, TABLE_INDEX_WAREHOUSE_GET_BUTTON, getLiveDataButton);
342
		getLiveDataButton.addClickHandler(new ClickHandler() {
343
			@Override
344
			public void onClick(ClickEvent event) {
345
				catalogService.getProdItemInventory(item.getId(), new AsyncCallback<Map<Long, ItemInventory>>() {
346
					@Override
347
					public void onSuccess(Map<Long, ItemInventory> itemInventoryMap) {
348
						if(itemInventoryMap != null) {
349
							GWT.log("Inventory Data fetched");
350
							item.setItemInventory(itemInventoryMap);
351
							updateAvailabilityTable(item.getItemInventory());
352
						}
353
						else {
354
							GWT.log("Error fetching Inventory Data");
355
							Window.alert("Error fetching Inventory Data");
356
						}
357
					}
358
					@Override
359
					public void onFailure(Throwable caught) {
360
						caught.printStackTrace();
361
						Window.alert("Error fetching Inventory Data");
362
					}
363
				});
364
			}
365
		});
366
 
367
		Button updateLiveDataButton = new Button("Update Live Data");
368
		headerAvailability.setWidget(0, TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, updateLiveDataButton);
369
		/* code to be rewritten later
4431 phani.kuma 370
        updateLiveDataButton.addClickHandler(new ClickHandler() {
371
            @Override
372
            public void onClick(ClickEvent event) {
373
            	catalogService.getProdItemInventory(item.getId(), new AsyncCallback<Map<Long, ItemInventory>>() {
374
                    @Override
375
                    public void onSuccess(Map<Long, ItemInventory> itemInventoryMap) {
376
                        if(itemInventoryMap != null) {
377
                            GWT.log("Inventory Data fetched");
378
                            item.setItemInventory(itemInventoryMap);
379
                            updateAvailabilityTable(item.getItemInventory());
380
                        }
381
                        else {
382
                            GWT.log("Error fetching Inventory Data");
383
                            Window.alert("Error fetching Inventory Data");
384
                        }
385
                    }
386
                    @Override
387
                    public void onFailure(Throwable caught) {
388
                        caught.printStackTrace();
389
                        Window.alert("Error fetching Inventory Data");
390
                    }
391
                });
392
            }
393
        });
10484 vikram.rag 394
		 */
395
		headerAvailability.getCellFormatter().setVisible(0, TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, false);
1992 ankur.sing 396
 
10484 vikram.rag 397
	}
2066 ankur.sing 398
 
10484 vikram.rag 399
	/**
400
	 * initialises vendor item key table header. Creates an Add button and
401
	 * adds click event listener to it to create and pop up a dialog for adding 
402
	 * a new vendor item key. 
403
	 */
404
	private void initVendorKeysHeader(){
405
		headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
406
		headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
407
		headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
408
		headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
409
		headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2119 ankur.sing 410
 
10484 vikram.rag 411
		headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDORID, "Vendor Id");
412
		headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDOR_DESC, "Vendor");
413
		headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY, "Item Key");
414
		headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, "Prev Item Key");
2119 ankur.sing 415
 
10484 vikram.rag 416
		headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_VENDORID, false);
417
		headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2066 ankur.sing 418
 
10484 vikram.rag 419
		Button addButton = new Button("Add");
420
		headerVendorItemKey.setWidget(0, TABLE_INDEX_MAPPING_BUTTON, addButton);
421
		addButton.addClickHandler(new ClickHandler() {
422
			@Override
423
			public void onClick(ClickEvent event) {
424
				VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
425
						modelNumber.getText().trim(), color.getText().trim());
426
				vendorMappingDialog.updateButton.setText("Add");
427
				vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
428
					@Override
429
					public boolean onUpdate(String key, long vendorId) {
430
						int row = tableVendorItemKey.getRowCount();
431
						tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
432
						tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
433
						tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
434
						tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
435
 
436
						tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDORID, vendorId + "");
437
						tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
438
						tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, key);
439
						tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, key);
440
 
441
						tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_VENDORID, false);
442
						tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
443
						return true;
444
					}
445
				});
446
				vendorMappingDialog.show();
447
			}
448
		});
449
	}
450
 
451
	/**
452
	 * initialises vendor prices table header. Creates an Add button and
453
	 * adds click event listener to it to create and pop up a dialog for adding 
454
	 * a prices for a new vendor 
455
	 */
456
	private void initVendorPricingHeader(){
457
		headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
458
		headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
459
		headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
460
		headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
461
		headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
462
		headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_NLC, PRICE_WIDTH);
463
		headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
464
 
465
		headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDORID, "Vendor Id");
466
		headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDOR_DESC, "Vendor");
467
		headerVendorPrices.setText(0, TABLE_INDEX_PRICING_MOP, "MOP");
468
		headerVendorPrices.setText(0, TABLE_INDEX_PRICING_DP, "Dealer Price");
469
		headerVendorPrices.setText(0, TABLE_INDEX_PRICING_TP, "Transfer Price");
470
		headerVendorPrices.setText(0, TABLE_INDEX_PRICING_NLC, "NLC");
471
 
472
		headerVendorPrices.getCellFormatter().setVisible(0, TABLE_INDEX_PRICING_VENDORID, false);
473
 
474
		Button addButton = new Button("Add");
475
		headerVendorPrices.setWidget(0, TABLE_INDEX_PRICING_BUTTON, addButton);
476
		addButton.addClickHandler(new ClickHandler() {
477
			@Override
478
			public void onClick(ClickEvent event) {
479
				VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
480
				vendorPricesDialog.updateButton.setText("Add");
481
				vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
482
					@Override
483
					public boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId) {
484
						if(!vendorExists(vendorId)) {
485
							Window.alert("Vendor already exists");
486
							return false;
487
						}
488
						/*if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 489
                            return false;
2119 ankur.sing 490
                        }*/
10484 vikram.rag 491
						int row = tableVendorPrices.getRowCount();
492
						tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
493
						tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
494
						tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
495
						tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
496
						tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
497
						tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_NLC, PRICE_WIDTH);
3558 rajveer 498
 
10484 vikram.rag 499
						tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDORID, vendorId + "");
500
						tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
501
						tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
502
						tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
503
						tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
504
						tableVendorPrices.setText(row, TABLE_INDEX_PRICING_NLC, nlc + "");
3558 rajveer 505
 
10484 vikram.rag 506
						tableVendorPrices.getCellFormatter().setVisible(row, TABLE_INDEX_PRICING_VENDORID, false);
507
						return true;
508
					}
509
				});
510
				vendorPricesDialog.show();
511
			}
512
		});
513
	}
3558 rajveer 514
 
10484 vikram.rag 515
	/**
516
	 * initialises source prices table header. Creates an Add button and
517
	 * adds click event listener to it to create and pop up a dialog for adding 
518
	 * a prices for a new source 
519
	 */
520
	private void initSourcePricingHeader(){
521
		headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, VENDOR_ID_WIDTH);
522
		headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, VENDOR_DESC_WIDTH);
523
		headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_MRP, PRICE_WIDTH);
524
		headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, PRICE_WIDTH);
525
		headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_BUTTON, BUTTON_WIDTH);
526
 
527
		headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, "Source Id");
528
		headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, "Source");
529
		headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_MRP, "MRP");
530
		headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, "Selling Price");
531
 
532
		headerSourcePrices.getCellFormatter().setVisible(0, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, false);
533
 
534
		Button addButton = new Button("Add");
535
		headerSourcePrices.setWidget(0, TABLE_INDEX_SOURCE_PRICING_BUTTON, addButton);
536
		addButton.addClickHandler(new ClickHandler() {
537
			@Override
538
			public void onClick(ClickEvent event) {
539
				SourcePricesDialog sourcePricesDialog = new SourcePricesDialog(mrp.getText().trim(), sellingPrice.getText().trim());
540
				//SourcePricesDialog sourcePricesDialog = new SourcePricesDialog();
541
				sourcePricesDialog.updateButton.setText("Add");
542
				sourcePricesDialog.setSourcePriceUpdateListener(new SourcePricesDialog.SourcePriceUpdateListener() {
4423 phani.kuma 543
					@Override
10484 vikram.rag 544
					public boolean onUpdate(double mrp, double sellingPrice, long sourceId) {
545
						if(!sourceExists(sourceId)) {
546
							Window.alert("Source already exists");
547
							return false;
548
						}
549
 
550
						int row = tableSourcePrices.getRowCount();
551
						tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, VENDOR_ID_WIDTH);
552
						tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, VENDOR_DESC_WIDTH);
553
						tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_MRP, PRICE_WIDTH);
554
						tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, PRICE_WIDTH);
555
 
556
						tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, sourceId + "");
557
						tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, Utils.getSourceDesc(sourceId));
558
						tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_MRP, mrp + "");
559
						tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sellingPrice + "");
560
 
561
						tableSourcePrices.getCellFormatter().setVisible(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, false);
562
						return true;
563
					}
564
				});
565
				sourcePricesDialog.show();
566
			}
567
		});
568
	}
569
 
570
	/**
571
	 * initialises similar items table header. Creates an Add button and
572
	 * adds click event listener to it to create and pop up a dialog for adding 
573
	 * a new similar item. 
574
	 */
575
	private void initSimilarItemList() {
576
		headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, PRICE_WIDTH);
577
		headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, PRICE_WIDTH);
578
		headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BRAND, PRICE_WIDTH);
579
		headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, PRICE_WIDTH);
580
		headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, PRICE_WIDTH);
581
		headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, "150px");
582
		headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BUTTON, BUTTON_WIDTH);
583
 
584
		headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, "Catalog ItemId");
585
		headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, "Product Group");
586
		headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_BRAND, "Brand");
587
		headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, "Model Number");
588
		headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, "Model Name");
589
		headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, "Category");
590
 
591
		Button addButton = new Button("Add");
592
		headerSimilarItems.setWidget(0, TABLE_INDEX_SIMILAR_ITEMS_BUTTON, addButton);
593
		addButton.addClickHandler(new ClickHandler() {
594
			@Override
595
			public void onClick(ClickEvent event) {
596
				AddSimilarItemDialog addSimilarItemDialog = new AddSimilarItemDialog();
597
				addSimilarItemDialog.setAddSimilarItemUpdateListener(new AddSimilarItemDialog.AddSimilarItemUpdateListener() {
598
					@Override
4423 phani.kuma 599
					public boolean onUpdate(long catalogItemId) {
600
						if (item.getSimilarItems().containsKey(catalogItemId)) {
601
							Window.alert("Similar Item exists.");
602
							return false;
603
						}
604
						else {
10484 vikram.rag 605
							catalogService.addSimilarItem(item.getId(), catalogItemId, new AsyncCallback<Item>() {
606
								@Override
607
								public void onSuccess(Item similarItem) {
608
									if(similarItem != null) {
609
										GWT.log("Similar Item Added");
610
										Map<Long, Item> newsimilarItems = item.getSimilarItems();
611
										newsimilarItems.put(similarItem.getCatalogItemId(), similarItem);
612
										item.setSimilarItems(newsimilarItems);
613
										updateSimilarItemsTable(item.getSimilarItems());
614
										Window.alert("Similar Item Added successfully.");
615
									}
616
									else {
617
										GWT.log("Error Adding Similar Item");
618
										Window.alert("Error Adding Similar Item");
619
									}
620
								}
621
								@Override
622
								public void onFailure(Throwable caught) {
623
									caught.printStackTrace();
624
									Window.alert("Error deleting Similar Item");
625
								}
626
							});
627
							return true;
4423 phani.kuma 628
						}
629
					}
630
				});
10484 vikram.rag 631
				addSimilarItemDialog.show();
632
			}
633
		});
634
	}
635
	private void initVatDetailsHeader(){
636
		headerVatDetails.getColumnFormatter().setWidth(TABLE_INDEX_STATE_NAME, "80px");
637
		headerVatDetails.getColumnFormatter().setWidth(TABLE_INDEX_STATE_TAX_PERCENTAGE, "50px");
638
		headerVatDetails.setText(0, TABLE_INDEX_STATE_NAME, "State Name");
639
		headerVatDetails.setText(0, TABLE_INDEX_STATE_TAX_PERCENTAGE, "Tax Percentage");
640
 
641
	}
642
	private void updateVatDetailsTable(Map<String,String> stateVatPercentage){
643
		tableVatDetails.removeAllRows();
644
		if(stateVatPercentage == null || stateVatPercentage.isEmpty()) {
645
			return;
646
		}
647
		tableVatDetails.getColumnFormatter().setWidth(TABLE_INDEX_STATE_NAME, "80px");
648
		tableVatDetails.getColumnFormatter().setWidth(TABLE_INDEX_STATE_TAX_PERCENTAGE, "50px");
649
		int i=0;
650
		for(Entry<String,String> e : stateVatPercentage.entrySet()){
651
			tableVatDetails.setText(i, TABLE_INDEX_STATE_NAME, e.getKey() +"");
652
			if(e.getValue().equals("-1.0")){
653
				tableVatDetails.setText(i, TABLE_INDEX_STATE_TAX_PERCENTAGE, "N.A" + "");
654
			}
655
			else{
656
				tableVatDetails.setText(i, TABLE_INDEX_STATE_TAX_PERCENTAGE, e.getValue()+" %" + "");
657
			}
658
			i++;
659
		}
660
	}
661
	private void initIgnoredWarehouseHeader(){
662
		headerIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_NAME, "100px");
663
		headerIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, BUTTON_WIDTH);
664
		headerIgnoredWarehouse.setText(0, TABLE_INDEX_WAREHOUSE_NAME, "Warehouse Desc");
665
		Button addButton = new Button("Add");
666
		headerIgnoredWarehouse.setWidget(0,TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON,addButton);
667
		addButton.addClickHandler(new ClickHandler() {
668
			@Override
669
			public void onClick(ClickEvent event) {
670
				DeactivateWarehouseDialog deactivateWarehouseDialog = new DeactivateWarehouseDialog(new ArrayList<Long>(item.getVendorPricesMap().keySet()));
671
				deactivateWarehouseDialog.updateButton.setText("Add");
672
				deactivateWarehouseDialog.setDeactivateWarehouseListener(new DeactivateWarehouseDialog.DeactivateWarehouseListener(){
6530 vikram.rag 673
					@Override
674
					public boolean onUpdate(final long warehouseId) {
10484 vikram.rag 675
						if(Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().contains(new ItemWarehouse(item.getId(),warehouseId))) {
676
							Window.alert("Warehouse already deactivated");
677
							return false;
678
						}
679
						catalogService.addtoIgnoredInventoryUpdateItemsIdsWarehouseIds(item.getId(),warehouseId,new AsyncCallback<Boolean>() {
680
							@Override
681
							public void onSuccess(Boolean result) {
682
								if(result) {
683
									Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().add(new ItemWarehouse(item.getId(),warehouseId));
684
									int index1 = tableIgnoredWarehouse.insertRow(0);
685
									addRowToIgnoredWarehouseTable(index1, warehouseId, Utils.getAllWarehouses().get(warehouseId));
4423 phani.kuma 686
 
10484 vikram.rag 687
									Window.alert("Warehouse deactivated successfully");
688
								}
689
								else {
690
									GWT.log("Error Deactivating warehouse");
691
									Window.alert("Error Deactivating warehouse");
692
								}
693
							}
694
							@Override
695
							public void onFailure(Throwable caught) {
696
								caught.printStackTrace();
697
								Window.alert("Error Deactivating warehouse");
698
							}
699
						});
700
						return true;
701
					}
702
				});
703
				deactivateWarehouseDialog.show();
704
			}
705
		});
706
	}
5504 phani.kuma 707
 
2066 ankur.sing 708
 
10484 vikram.rag 709
	private void initVoucherHeader(){
710
		headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
711
		headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
712
		headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
713
		headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
4423 phani.kuma 714
 
10484 vikram.rag 715
		headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_TYPE, "Voucher Type");
716
		headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_AMOUNT, "Voucher Amount");
717
		headerVouchers.getCellFormatter().setVisible(0, TABLE_INDEX_VOUCHERS_DEL_BUTTON, false);
718
		Button addButton = new Button("Add");
719
		headerVouchers.setWidget(0, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, addButton);
720
		addButton.addClickHandler(new ClickHandler() {
721
			@Override
722
			public void onClick(ClickEvent event) {
723
				VoucherItemDialog voucherItemDialog = new VoucherItemDialog();
724
				voucherItemDialog.updateButton.setText("Add");
725
				voucherItemDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
726
					@Override
727
					public boolean onUpdate(final String voucherType, final long voucherAmount) {
728
						if(!voucherExists(voucherType)) {
729
							Window.alert("Voucher already exists");
730
							return false;
731
						}
732
						Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);;
733
						catalogService.addVoucher(item.getCatalogItemId(), voucherTypeValue, voucherAmount, new AsyncCallback<Boolean>() {
734
							@Override
735
							public void onSuccess(Boolean result) {
736
								if(result) {
737
									GWT.log("Voucher Added");
738
									VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
739
									Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
740
									newvouchersMap.put(voucherType, newvoucher);
741
									item.setVouchersMap(newvouchersMap);
742
									updateVoucherTable(item.getVouchersMap());
743
									Window.alert("Voucher Added successfully.");
744
								}
745
								else {
746
									GWT.log("Error Adding Voucher");
747
									Window.alert("Error Adding Voucher");
748
								}
749
							}
750
							@Override
751
							public void onFailure(Throwable caught) {
752
								caught.printStackTrace();
753
								Window.alert("Error deleting voucher");
754
							}
755
						});
756
						return true;
757
					}
758
				});
759
				voucherItemDialog.show();
760
			}
761
		});
762
	}
2066 ankur.sing 763
 
10484 vikram.rag 764
	/**
765
	 * Clear and populate item availability table.
766
	 * @param availabilityMap
767
	 */
2119 ankur.sing 768
 
10484 vikram.rag 769
	private void updateAvailabilityTable(Map<Long, ItemInventory> itemInventoryMap){
770
		availabilityTable.removeAllRows();
771
		if(itemInventoryMap == null || itemInventoryMap.isEmpty()) {
772
			return;
773
		}
774
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "100px");
775
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
776
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVA, "100px");
777
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVR, "100px");
778
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_HELD, "100px");
779
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_EBAY_HELD, "80px");
780
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_SNAPDEAL_HELD, "80px");
781
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_FLIPKART_HELD, "80px");
782
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_GET_BUTTON, "100px");
783
		availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, "100px");
2066 ankur.sing 784
 
10484 vikram.rag 785
		int i=0;
786
		for(ItemInventory warehousedata : itemInventoryMap.values()){
787
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, warehousedata.getWarehouseId() + "");
788
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(warehousedata.getWarehouseId()) + "");
789
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INVA, warehousedata.getAvailability() + "");
790
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INVR, warehousedata.getReserved() + "");
791
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_HELD, warehousedata.getHeld() + "");
792
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_EBAY_HELD, warehousedata.getEbayHeld() + "");
793
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_SNAPDEAL_HELD, warehousedata.getSnapdealHeld() + "");
794
			availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_FLIPKART_HELD, warehousedata.getFlipkartHeld() + "");
2066 ankur.sing 795
 
10484 vikram.rag 796
			i++;
797
		}
798
	}
2066 ankur.sing 799
 
10484 vikram.rag 800
	/**
801
	 * Clear and populate vendor item key table with keys in the passed argument.
802
	 * With each row in the table, an edit button is created and click event listener 
803
	 * is added to it to edit that vendor item key row.
804
	 * @param vendorKeysMap
805
	 */
806
	private void updateVendorKeysTable(Map<String, VendorItemMapping> vendorKeysMap){
807
		tableVendorItemKey.removeAllRows();
3558 rajveer 808
 
10484 vikram.rag 809
		if(vendorKeysMap == null || vendorKeysMap.isEmpty()) {
810
			return;
811
		}
812
		tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
813
		tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
814
		tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
815
		tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
816
		tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
4423 phani.kuma 817
 
10484 vikram.rag 818
		int i=0;
819
		for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()){
820
			VendorItemMapping vendorMapping = e.getValue();
821
			tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDORID, vendorMapping.getVendorId() + "");
822
			tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));
823
			tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY, vendorMapping.getItemKey());
824
			tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1));
825
			Button editButton = new Button("Edit");
826
			tableVendorItemKey.setWidget(i, TABLE_INDEX_MAPPING_BUTTON, editButton);
827
			editButton.addClickHandler(new ClickHandler() {
828
				@Override
829
				public void onClick(ClickEvent event) {
830
					Cell cell = tableVendorItemKey.getCellForEvent(event);
831
					int row = cell.getRowIndex();
832
					long vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
833
					editVendorKey(vendorId, row);
834
				}
835
			});
836
			tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_VENDORID, false);
837
			tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
838
			i++;
839
		}
840
	}
4423 phani.kuma 841
 
10484 vikram.rag 842
	/**
843
	 * Clear and populate vendor prices table with prices in the passed argument.
844
	 * With each row in the table, an edit button is created and click event listener 
845
	 * is added to it to edit that vendor prices row.
846
	 * @param vendorPricingMap
847
	 */
848
	private void updateVendorPricingTable(Map<Long, VendorPricings> vendorPricingMap){
849
		tableVendorPrices.removeAllRows();
4423 phani.kuma 850
 
10484 vikram.rag 851
		if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {
852
			return;
853
		}
854
		tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
855
		tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
856
		tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
857
		tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
858
		tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
859
		tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_NLC, PRICE_WIDTH);
860
		tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
5504 phani.kuma 861
 
862
 
10484 vikram.rag 863
		int i=0;
864
		for(VendorPricings vendorDetail : vendorPricingMap.values()){
865
			tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDORID, vendorDetail.getVendorId() + "");
866
			tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
867
			tableVendorPrices.setText(i, TABLE_INDEX_PRICING_MOP, vendorDetail.getMop() + "");
868
			tableVendorPrices.setText(i, TABLE_INDEX_PRICING_DP, vendorDetail.getDealerPrice() + "");
869
			tableVendorPrices.setText(i, TABLE_INDEX_PRICING_TP, vendorDetail.getTransferPrice() + "");
870
			tableVendorPrices.setText(i, TABLE_INDEX_PRICING_NLC, vendorDetail.getNlc() + "");
871
			Button editButton = new Button("Edit");
872
			tableVendorPrices.setWidget(i, TABLE_INDEX_PRICING_BUTTON, editButton);
873
			editButton.addClickHandler(new ClickHandler() {
874
				@Override
875
				public void onClick(ClickEvent event) {
876
					Cell cell = tableVendorPrices.getCellForEvent(event);
877
					int row = cell.getRowIndex();
878
					long vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
879
					editVendorPrices(vendorId, row);
880
				}
881
			});
882
			tableVendorPrices.getCellFormatter().setVisible(i, TABLE_INDEX_PRICING_VENDORID, false);
883
			i++;
884
		}
6532 amit.gupta 885
	}
886
 
887
	/**
10484 vikram.rag 888
	 * Clear and populate vendor prices table with prices in the passed argument.
889
	 * With each row in the table, an edit button is created and click event listener 
890
	 * is added to it to edit that vendor prices row.
891
	 * @param sourcePricingMap
892
	 */
893
	private void updateSourcePricingTable(Map<Long, SourcePricings> sourcePricingMap){
894
		tableSourcePrices.removeAllRows();
895
 
896
		if(sourcePricingMap == null || sourcePricingMap.isEmpty()) {
897
			return;
898
		}
899
		tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, VENDOR_ID_WIDTH);
900
		tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, VENDOR_DESC_WIDTH);
901
		tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_MRP, PRICE_WIDTH);
902
		tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, PRICE_WIDTH);
903
		tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_BUTTON, BUTTON_WIDTH);
904
 
905
		int i=0;
906
		for(SourcePricings sourceDetail : sourcePricingMap.values()){
907
			tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, sourceDetail.getSourceId() + "");
908
			tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, Utils.getSourceDesc(sourceDetail.getSourceId()));
909
			tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_MRP, sourceDetail.getMrp() + "");
910
			tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sourceDetail.getSellingPrice() + "");
911
 
912
			Button editButton = new Button("Edit");
913
			tableSourcePrices.setWidget(i, TABLE_INDEX_SOURCE_PRICING_BUTTON, editButton);
914
			editButton.addClickHandler(new ClickHandler() {
915
				@Override
916
				public void onClick(ClickEvent event) {
917
					Cell cell = tableSourcePrices.getCellForEvent(event);
918
					int row = cell.getRowIndex();
919
					long sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
920
					editSourcePrices(sourceId, row);
921
				}
922
			});
923
			tableSourcePrices.getCellFormatter().setVisible(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, false);
924
			i++;
925
		}
926
	}
927
 
928
	/**
929
	 * Clear and populate similar items table with items in the passed argument.
930
	 * With each row in the table, an delete button is created and click event listener 
931
	 * is added to it to delete that similar item row.
932
	 * @param similarItems
933
	 */
934
	private void updateSimilarItemsTable(Map<Long, Item> similarItems){
935
		tableSimilarItems.removeAllRows();
936
 
937
		if(similarItems == null || similarItems.isEmpty()) {
938
			return;
939
		}
940
		tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, PRICE_WIDTH);
941
		tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, PRICE_WIDTH);
942
		tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BRAND, PRICE_WIDTH);
943
		tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, PRICE_WIDTH);
944
		tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, PRICE_WIDTH);
945
		tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, "150px");
946
		tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BUTTON, BUTTON_WIDTH);
947
 
948
 
949
		int i=0;
950
		for(Item similarItemDetail : similarItems.values()){
951
			tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, similarItemDetail.getCatalogItemId() + "");
952
			tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, similarItemDetail.getProductGroup() + "");
953
			tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_BRAND, similarItemDetail.getBrand() + "");
954
			tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, similarItemDetail.getModelNumber() + "");
955
			tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, similarItemDetail.getModelName() + "");
956
			tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, similarItemDetail.getContentCategory() + "");
957
 
958
			Button deleteButton = new Button("Delete");
959
			tableSimilarItems.setWidget(i, TABLE_INDEX_SIMILAR_ITEMS_BUTTON, deleteButton);
960
			deleteButton.addClickHandler(new ClickHandler() {
961
				@Override
962
				public void onClick(ClickEvent event) {
963
					Cell cell = tableSimilarItems.getCellForEvent(event);
964
					final int row = cell.getRowIndex();
965
					long catalogItemId = Long.parseLong(tableSimilarItems.getText(row, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID));
966
 
967
					catalogService.deleteSimilarItem(item.getId(), catalogItemId, new AsyncCallback<Boolean>() {
968
						@Override
969
						public void onSuccess(Boolean result) {
970
							if(result) {
971
								GWT.log("Similar Item deleted");
972
								long catalogItemId = Long.parseLong(tableSimilarItems.getText(row, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID)); 
973
								tableSimilarItems.removeRow(row);
974
								Map<Long, Item> newsimilarItems = item.getSimilarItems();
975
								newsimilarItems.remove(catalogItemId);
976
								item.setSimilarItems(newsimilarItems);
977
							}
978
							else {
979
								GWT.log("Error deleting Similar Item");
980
								Window.alert("Error deleting Similar Item");
981
							}
982
						}
983
						@Override
984
						public void onFailure(Throwable caught) {
985
							caught.printStackTrace();
986
							Window.alert("Error deleting Similar Item");
987
						}
988
					});
989
				}
990
			});
991
			i++;
992
		}
993
	}
994
 
995
	private void updateVoucherTable(Map<String, VoucherItemMapping> vouchersMap){
996
		tableVouchers.removeAllRows();
997
 
998
		if(vouchersMap == null || vouchersMap.isEmpty()) {
999
			return;
1000
		}
1001
		tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
1002
		tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
1003
		tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
1004
		tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
1005
 
1006
		int i=0;
1007
		for(VoucherItemMapping voucher : vouchersMap.values()){
1008
			tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_TYPE, voucher.getVoucherType());
1009
			tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_AMOUNT, voucher.getAmount() + "");
1010
 
1011
			Button editButton = new Button("Edit");
1012
			tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, editButton);
1013
			editButton.addClickHandler(new ClickHandler() {
1014
				@Override
1015
				public void onClick(ClickEvent event) {
1016
					Cell cell = tableVouchers.getCellForEvent(event);
1017
					final int row = cell.getRowIndex();
1018
					String voucherAmount = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_AMOUNT);
1019
					VoucherItemDialog voucherDialog = new VoucherItemDialog(voucherAmount);
1020
					voucherDialog.updateButton.setText("Update");
1021
					voucherDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
1022
						@Override
1023
						public boolean onUpdate(final String voucherType, final long voucherAmount) {
1024
							Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);
1025
							catalogService.addVoucher(item.getCatalogItemId(), voucherTypeValue, voucherAmount, new AsyncCallback<Boolean>() {
1026
								@Override
1027
								public void onSuccess(Boolean result) {
1028
									if(result) {
1029
										GWT.log("Voucher Updated");
1030
										VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
1031
										Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
1032
										newvouchersMap.remove(voucherType);
1033
										newvouchersMap.put(voucherType, newvoucher);
1034
										item.setVouchersMap(newvouchersMap);
1035
										updateVoucherTable(item.getVouchersMap());
1036
										Window.alert("Voucher Updated successfully.");
1037
									}
1038
									else {
1039
										GWT.log("Error Updating Voucher");
1040
										Window.alert("Error Updating Voucher");
1041
									}
1042
								}
1043
								@Override
1044
								public void onFailure(Throwable caught) {
1045
									caught.printStackTrace();
1046
									Window.alert("Error Updating voucher");
1047
								}
1048
							});
1049
							return true;
1050
						}
1051
					});
1052
					voucherDialog.show();
1053
				}
1054
			});
1055
 
1056
			Button deleteButton = new Button("Delete");
1057
			tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_DEL_BUTTON, deleteButton);
1058
			deleteButton.addClickHandler(new ClickHandler() {
1059
				@Override
1060
				public void onClick(ClickEvent event) {
1061
					Cell cell = tableVouchers.getCellForEvent(event);
1062
					final int row = cell.getRowIndex();
1063
					String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
1064
					Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);
1065
					catalogService.deleteVoucher(item.getCatalogItemId(), voucherTypeValue, new AsyncCallback<Boolean>() {
1066
						@Override
1067
						public void onSuccess(Boolean result) {
1068
							if(result) {
1069
								GWT.log("Voucher deleted");
1070
								String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
1071
								tableVouchers.removeRow(row);
1072
								Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
1073
								newvouchersMap.remove(voucherType);
1074
								item.setVouchersMap(newvouchersMap);
1075
							}
1076
							else {
1077
								GWT.log("Error deleting Voucher");
1078
								Window.alert("Error deleting Voucher");
1079
							}
1080
						}
1081
						@Override
1082
						public void onFailure(Throwable caught) {
1083
							caught.printStackTrace();
1084
							Window.alert("Error deleting Voucher");
1085
						}
1086
					});
1087
				}
1088
			});
1089
			i++;
1090
		}
1091
	}
1092
	private void updateTableIgnoredWarehouse(){
1093
		tableIgnoredWarehouse.removeAllRows();
1094
		List<ItemWarehouse> itemWarehouses = Utils.getignoredInventoryUpdateItemsIdsWarehouseIds();
1095
		Map<Long,String> ignoredWarehouses = new HashMap<Long, String>();
1096
		for(ItemWarehouse itemWarehouse:itemWarehouses){
1097
			if(itemWarehouse.getItemId()==item.getId()){
1098
				ignoredWarehouses.put(itemWarehouse.getWarehouseId(),Utils.getAllWarehouses().get(itemWarehouse.getWarehouseId()));	
1099
			}
1100
 
1101
		}		
1102
		tableIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_NAME, "100px");
1103
		tableIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, BUTTON_WIDTH);
1104
 
1105
		int i=0;
1106
		for(final Map.Entry<Long,String> entry : ignoredWarehouses.entrySet()){
1107
			addRowToIgnoredWarehouseTable(i, entry.getKey(), entry.getValue());
1108
			i++;
1109
		}
1110
	}
1111
 
1112
	private void addRowToIgnoredWarehouseTable(int i, final Long whId, final String whName) {
1113
		tableIgnoredWarehouse.setText(i,TABLE_INDEX_WAREHOUSE_NAME,whName);
1114
		Button deleteButton = new Button("Delete");
1115
		tableIgnoredWarehouse.setWidget(i, TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, deleteButton);
1116
		deleteButton.addClickHandler(new ClickHandler() {
1117
			@Override
1118
			public void onClick(ClickEvent event) {
1119
				Cell cell = tableIgnoredWarehouse.getCellForEvent(event);
1120
				final int row = cell.getRowIndex();
1121
				catalogService.deleteFromIgnoredInventoryUpdateItemsIdsWarehouseIds(item.getId(),whId, new AsyncCallback<Boolean>() {
1122
					@Override
1123
					public void onSuccess(Boolean result) {
1124
						if(result) {
1125
							GWT.log("Warehouse will now be in sync");
1126
							tableIgnoredWarehouse.removeRow(row);
1127
							Window.alert("Warehouse deleted from list ");
1128
							Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().remove(new ItemWarehouse(item.getId(),whId));
1129
						}
1130
						else {
1131
							GWT.log("Error deleting Warehouse");
1132
							Window.alert("Error deleting Warehouse");
1133
						}
1134
					}
1135
					@Override
1136
					public void onFailure(Throwable caught) {
1137
						caught.printStackTrace();
1138
						Window.alert("Error deleting Warehouse");
1139
					}
1140
				});
1141
			}
1142
		});
1143
 
1144
	}
1145
 
1146
	/**
1147
	 * called on the click event of update item button in ItemActions
1148
	 */
1149
	void updateItem() {
1150
		if(item == null) {
1151
			Window.alert("Please select an item to update.");
1152
			return;
1153
		}
1154
		try {
1155
			if(!createNewItem()) {
1156
				return;
1157
			}
1158
		} catch(NumberFormatException ex) {
1159
			ex.printStackTrace();
1160
			GWT.log("Number format exception");
1161
		}
1162
		String paramsChanged = isItemChanged();
1163
		if(paramsChanged.equals("")) {
1164
			Window.alert("Nothing to update. Please change intended item parameters and try again.");
1165
			return;
1166
		} else {
1167
			if(item.getSameItemsWithDifferentColors().size()>0 && optionalChangedValMap.size()>0 ){
1168
				createDialog(paramsChanged);
1169
			} else {
1170
				String paramsChanged1  = "";
1171
				paramsChanged1 = "You have changed following items.\n" + paramsChanged;
1172
				Window.alert(paramsChanged1);
1173
				validateNUpdate();
1174
			}
1175
			if("\n-Expected Delay".equals(paramsChanged) || "\n-Has Serial Number Flag".equals(paramsChanged)){
1176
				catalogService.updateExpectedDelayOnProd(newItem, new AsyncCallback<String>() {
1177
					@Override
1178
					public void onSuccess(String result) {
1179
						Window.alert(result);
1180
					}
1181
					@Override
1182
					public void onFailure(Throwable caught) {
1183
						Window.alert("Error while updating item on production");
1184
					}
1185
				});
1186
			}
1187
		}
1188
	}
1189
 
1190
 
1191
	private void validateNUpdate() {
1192
		if(!Utils.validateItem(newItem)) {
1193
			return;
1194
		}
1195
 
1196
		final String[] messageList = new String[2];
1197
 
1198
		String sellingpricemessage = compareSellingPricewithBreakEven();
1199
		if(sellingpricemessage.equals("false")) {
1200
			return;
1201
		}
1202
		else if(!sellingpricemessage.equals("true")) {
1203
			messageList[0] = sellingpricemessage;
1204
		}
1205
 
1206
		String preferredvendormessage = checkTransferPriceforPreferredVendor();
1207
		if(preferredvendormessage.equals("false")) {
1208
			return;
1209
		}
1210
		else if(!preferredvendormessage.equals("true")) {
1211
			messageList[1] = preferredvendormessage;
1212
		}
1213
 
1214
		/*if(!validatePrices()) {
2126 ankur.sing 1215
            return;
1216
        }*/
10484 vikram.rag 1217
		catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
1218
			@Override
1219
			public void onSuccess(Boolean result) {
1220
				if(result) {
1221
					for(int i = 0; i < messageList.length; i++) {
1222
						if(messageList[i] != null) {
1223
							logAuthorization(messageList[i]);
1224
						}
1225
					}
1226
					if(optionalChangedValMap.size()>0 || mandatoryChangedValMap.size()>0){
1227
						for(Long itemId : item.getSameItemsWithDifferentColors()){
1228
							updateItem(itemId);
1229
						}
1230
					}
1231
					item = newItem;
1232
					GWT.log("Item updated. Id = " + item.getId());
1233
					catalogDashboardPanel.getItemListWidget().updateItem(item);
1234
					getFreshItemFromDB(item.getId());
1235
					Window.alert("Item updated successfully.");
1236
				}
1237
				else {
1238
					GWT.log("Error updating item");
1239
					Window.alert("Error updating item");
1240
				}
1241
			}
1242
			@Override
1243
			public void onFailure(Throwable caught) {
1244
				caught.printStackTrace();
1245
				Window.alert("Error while updating item");
1246
			}
1247
		});
1248
	}
1249
 
1250
	private void getFreshItemFromDB(long id) {
1251
		catalogService.getItem(id, new AsyncCallback<Item>() {
1252
			@Override
1253
			public void onSuccess(Item result) {
1254
				setItemDetails(result);
1255
			}
1256
			@Override
1257
			public void onFailure(Throwable caught) {
1258
				caught.printStackTrace();
1259
				Window.alert("Unable to fetch item details.");
1260
			}
1261
		});
1262
	}
1263
 
1264
	/**
1265
	 * This method is called while updating item.<br> It will create a new Item object and set 
1266
	 * its editable attributes with UI fields values and non-editable attributes with old Item
1267
	 * object attributes. This new Item object is then passed to the service to update item in the database.
1268
	 * <br>If update is successful, the old Item object is replaced with the new Item object. 
1269
	 * @return true if new Item object is created successfully
1270
	 *     <br>false if some error occurs due to NumberFormatException
1271
	 */
1272
	private boolean createNewItem() {
1273
		newItem = new Item();
1274
		newItem.setId(item.getId());
1275
		newItem.setProductGroup(productGroup.getText().trim());
1276
		newItem.setBrand(brand.getText().trim());
1277
		newItem.setModelNumber(modelNumber.getText().trim());
1278
		newItem.setModelName(modelName.getText().trim());
1279
		newItem.setColor(color.getText().trim());
1280
		newItem.setContentCategory(contentCategory.getText());
1281
		newItem.setComments(comments.getText().trim());
1282
		newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
1283
 
1284
		try {
1285
			if(!mrp.getText().trim().isEmpty()) {
1286
				double mrpValue = Double.parseDouble(mrp.getText().trim());
1287
				if(mrpValue <= 0) {
1288
					throw new NumberFormatException("Negative value of MRP");
1289
				}
1290
				newItem.setMrp(mrpValue);
1291
			}
1292
		} catch(NumberFormatException ex) {
1293
			Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
1294
			return false;
1295
		}
1296
		try {
1297
			if(!sellingPrice.getText().trim().isEmpty()) {
1298
				double spValue = Double.parseDouble(sellingPrice.getText().trim());
1299
				if(spValue <= 0) {
1300
					throw new NumberFormatException("Negative value of Selling price");
1301
				}
1302
				newItem.setSellingPrice(spValue);
1303
			}
1304
		} catch(NumberFormatException ex) {
1305
			Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
1306
			return false;
1307
		}
1308
		try {
1309
			if(!weight.getText().trim().isEmpty()) {
1310
				double wtValue = Double.parseDouble(weight.getText().trim());
1311
				if(wtValue <= 0) {
1312
					throw new NumberFormatException("Negative value of Weight");
1313
				}
1314
				newItem.setWeight(wtValue);
1315
			}
1316
		} catch(NumberFormatException ex) {
1317
			Window.alert("Invalid weight format/value. Value shoule be greater than zero");
1318
			return false;
1319
		}
1320
		try {
1321
			if(!startDate.getTextBox().getText().trim().equals("")) {
1322
				newItem.setStartDate(startDate.getValue().getTime());
1323
			}
1324
		} catch(Exception ex) {
1325
			Window.alert("Invalid start date format");
1326
			return false;
1327
		}
1328
		newItem.setBestDealsText(bestDealsText.getText().trim());
1329
		newItem.setBestDealsDetailsText(bestDealsDetailsText.getText().trim());
1330
		newItem.setBestDealsDetailsLink(bestDealsDetailsLink.getText().trim());
1331
		Date comingSoonStartDt  = comingSoonStartDate.getValue();
1332
		Date expectedArrivalDt  = expectedArrivalDate.getValue();
1333
		if(comingSoonStartDt == null){
1334
			newItem.setComingSoonStartDate(null);
1335
		}else {
1336
			newItem.setComingSoonStartDate(comingSoonStartDt.getTime());
1337
		}
1338
		if(expectedArrivalDt == null){
1339
			newItem.setExpectedArrivalDate(null);
1340
		}else {
1341
			newItem.setExpectedArrivalDate(expectedArrivalDt.getTime());
1342
		}
1343
		try {
1344
			if(!bestDealsValue.getText().trim().equals("")) {
1345
				double bdValue = Double.parseDouble(bestDealsValue.getText().trim());
1346
				if(bdValue < 0) {
1347
					throw new NumberFormatException("Negative value of BestDealValue");
1348
				}
1349
				newItem.setBestDealsValue(bdValue);
1350
			}
1351
		} catch(NumberFormatException ex) {
1352
			Window.alert("Invalid best deal value format");
1353
			return false;
1354
		}
1355
 
1356
		try {
1357
			if(!bestSellingRank.getText().trim().equals("")) {
1358
				long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
1359
				if(bsrValue < 0) {
1360
					throw new NumberFormatException("Negative value of Best Selling Rank");
1361
				}
1362
				newItem.setBestSellingRank(bsrValue);
1363
			}
1364
		} catch(NumberFormatException ex) {
1365
			Window.alert("Invalid best selling rank format");
1366
			return false;
1367
		}
1368
		newItem.setDefaultForEntity(defaultForEntity.getValue());
1369
		newItem.setRisky(risky.getValue());
1370
 
1371
		try {
1372
			if(!minStockLevel.getText().trim().equals("")) {
1373
				long minStock = Long.parseLong(minStockLevel.getText().trim());
1374
				if(minStock < 0) {
1375
					throw new NumberFormatException("Negative value of Minimum Stock Level");
1376
				}
1377
				newItem.setMinStockLevel(minStock);
1378
			}
1379
		} catch(NumberFormatException ex) {
1380
			Window.alert("Invalid minimum Stock Level format");
1381
			return false;
1382
		}
1383
 
1384
		try {
1385
			if(!numOfDaysStock.getText().trim().equals("")) {
1386
				long numDays = Long.parseLong(numOfDaysStock.getText().trim());
1387
				if(numDays < 0) {
1388
					throw new NumberFormatException("Negative value of num Of Days ");
1389
				}
1390
				newItem.setNumOfDaysStock(new Long(numDays).intValue());
1391
			}
1392
		} catch(NumberFormatException ex) {
1393
			Window.alert("Invalid number Of Days format");
1394
			return false;
1395
		}
1396
		newItem.setShowSellingPrice(showSellingPrice.getValue());
1397
		newItem.setHoldOverride(holdOverride.getValue());
1398
		try {
1399
			String expectedDelayText = expectedDelay.getText().trim();
1400
			if(!expectedDelayText.equals("")){
1401
				newItem.setExpectedDelay(Integer.parseInt(expectedDelayText));
1402
			}
1403
		} catch(NumberFormatException nfe) {
1404
			Window.alert("Invalid expected delay");
1405
			return false;
1406
		}
1407
		try {
1408
			if(!freebieItemId.getText().trim().equals("")) {
1409
				long freeItemId = Long.parseLong(freebieItemId.getText().trim());
1410
				if(freeItemId < 0) {
1411
					throw new NumberFormatException("Negative value of freebieItemId ");
1412
				}
1413
				newItem.setFreebieItemId(new Long(freeItemId));
1414
			}
1415
		} catch(NumberFormatException ex) {
1416
			Window.alert("Invalid freebie ItemId");
1417
			return false;
1418
		}
1419
		if((item.getPreferredVendor() == null || item.getVendorPricesMap() == null || item.getVendorPricesMap().isEmpty()) && preferredVendor.getSelectedIndex() == 0) {
1420
			newItem.setPreferredVendor(item.getPreferredVendor());
1421
		}
1422
		else {
1423
			long vendorId = Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex()));
1424
			newItem.setPreferredVendor(vendorId);
1425
		}
1426
		newItem.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
1427
		newItem.setWarehouseStickiness(warehouseStickiness.getValue());
1428
		newItem.setHasItemNo(hasItemNo.getValue());
1429
		newItem.setItemType(itemType.getValue());
1430
		newItem.setAsin(asin.getText().trim());
1431
		try {
1432
			if(!holdInventory.getText().trim().equals("")) {
1433
				long hold_inventory = Long.parseLong(holdInventory.getText().trim());
1434
				if(hold_inventory < 0) {
1435
					throw new NumberFormatException("Negative value of Hold Inventory");
1436
				}
1437
				newItem.setHoldInventory(hold_inventory);
1438
			}
1439
		} catch(NumberFormatException ex) {
1440
			Window.alert("Invalid Hold Inventory Value");
1441
			return false;
1442
		}
1443
 
1444
		try {
1445
			if(!defaultInventory.getText().trim().equals("")) {
1446
				long default_inventory = Long.parseLong(defaultInventory.getText().trim());
1447
				if(default_inventory < 0) {
1448
					throw new NumberFormatException("Negative value of Default Inventory");
1449
				}
1450
				newItem.setDefaultInventory(default_inventory);
1451
			}
1452
		} catch(NumberFormatException ex) {
1453
			Window.alert("Invalid Default Inventory Value");
1454
			return false;
1455
		}
1456
		/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
2126 ankur.sing 1457
          Add the instance to map and set the map to the item instance created above.*/
10484 vikram.rag 1458
		Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
1459
		VendorPricings v;
1460
		for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
1461
			v = new VendorPricings();
1462
			v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));
1463
			v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));
1464
			v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));
1465
			v.setNlc(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_NLC)));
1466
			v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));
1467
			vendorPrices.put(v.getVendorId(), v);
1468
		}
1469
		newItem.setVendorPricesMap(vendorPrices);
1470
		newItem.setItemStatusDesc(statusDesc.getText().trim());
1471
 
1472
		/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
2126 ankur.sing 1473
        Add the instance to map and set the map to the item instance created above.*/
10484 vikram.rag 1474
		Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
1475
		VendorItemMapping vMapping;
1476
		for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
1477
			vMapping = new VendorItemMapping();
1478
			vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));
1479
			vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));
1480
			vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);
1481
		}
1482
		newItem.setVendorKeysMap(vendorMappings);
1483
 
1484
		/*Create an instance of SourcePricings for each row in source pricing table. Set the source prices to the instance.
3558 rajveer 1485
        Add the instance to map and set the map to the item instance created above.*/
10484 vikram.rag 1486
		Map<Long, SourcePricings> sourcePrices = new HashMap<Long, SourcePricings>();
1487
		SourcePricings s;
1488
		for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1489
			s = new SourcePricings();
1490
			s.setMrp(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP)));
1491
			s.setSellingPrice(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE)));
1492
			s.setSourceId(Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID)));
1493
			sourcePrices.put(s.getSourceId(), s);
1494
		}
3558 rajveer 1495
		newItem.setSourcePricesMap(sourcePrices);
2066 ankur.sing 1496
 
10484 vikram.rag 1497
		newItem.setContentCategoryId(item.getContentCategoryId());
1498
		newItem.setFeatureId(item.getFeatureId());
1499
		newItem.setFeatureDescription(item.getFeatureDescription());
1500
		newItem.setAddedOn(item.getAddedOn());
1501
		newItem.setRetireDate(item.getRetireDate());
1502
		newItem.setUpdatedOn(item.getUpdatedOn());
1503
		newItem.setItemStatus(item.getItemStatus());
1504
		newItem.setItemInventory(item.getItemInventory());
1505
		newItem.setSimilarItems(item.getSimilarItems());
1506
		newItem.setVouchersMap(item.getVouchersMap());
3558 rajveer 1507
 
10484 vikram.rag 1508
		return true;
1509
	}
2066 ankur.sing 1510
 
10484 vikram.rag 1511
	/**
1512
	 * This method is called when Edit button is clicked corresponding to a row in 
1513
	 * vendor prices table. It will pop up a form to edit the vendor prices.
1514
	 * @param vendorId
1515
	 * @param row
1516
	 */
1517
	private void editVendorPrices(final long vendorId, final int row) {
1518
		String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
1519
		String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
1520
		String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
1521
		String nlc = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_NLC);
1522
		VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp, nlc);
1523
		pricesDialog.updateButton.setText("Update");
1524
		pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
1525
			@Override
1526
			public boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId) {
1527
				if(!validateVendorPrices(mop, dp, tp, nlc)) {
1528
					return false;
1529
				}
1530
				tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
1531
				tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
1532
				tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
1533
				tableVendorPrices.setText(row, TABLE_INDEX_PRICING_NLC, nlc + "");
1534
				return true;
1535
			}
1536
		});
1537
		pricesDialog.show();
1538
	}
1539
 
1540
	/**
1541
	 * This method is called when Edit button is clicked corresponding to a row in 
1542
	 * vendor prices table. It will pop up a form to edit the vendor prices.
1543
	 * @param vendorId
1544
	 * @param row
1545
	 */
1546
	private void editSourcePrices(final long sourceId, final int row) {
1547
		String mrp = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP);
1548
		String sellingPrice = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE);
1549
		SourcePricesDialog pricesDialog = new SourcePricesDialog(mrp, sellingPrice);
1550
		pricesDialog.updateButton.setText("Update");
1551
		pricesDialog.setSourcePriceUpdateListener(new SourcePricesDialog.SourcePriceUpdateListener() {
1552
			@Override
1553
			public boolean onUpdate(double mrp, double sellingPrice, long sourceId) {
1554
				if(!validateSourcePrices(mrp, sellingPrice)) {
1555
					return false;
1556
				}
1557
				tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_MRP, mrp + "");
1558
				tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sellingPrice + "");
1559
				return true;
1560
			}
1561
		});
1562
		pricesDialog.show();
1563
	}
1564
 
1565
 
1566
	/**
1567
	 * This method is called when Edit button is clicked corresponding to a row in 
1568
	 * vendor item key table. It will pop up a form to edit the item key.
1569
	 * @param vendorId
1570
	 * @param row
1571
	 */
1572
	private void editVendorKey(final long vendorId, final int row) {
1573
		String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
1574
		VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
1575
				modelNumber.getText().trim(), color.getText().trim(), key);
1576
		mappingDialog.updateButton.setText("Update");
1577
		mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
1578
			@Override
1579
			public boolean onUpdate(String itemKey, long vendorId) {
1580
				if(itemKey == null || itemKey.equals("")) {
1581
					Window.alert("Item key cannot be empty.");
1582
					return false;
1583
				}
1584
				tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
1585
				return true;
1586
			}
1587
		});
1588
		mappingDialog.show();
1589
	}
1590
 
1591
	/**
1592
	 * This method compares all the editable UI fields values with attributes in the item object.
1593
	 * If they differ, the attribute name is appended to a string.
1594
	 * @return String showing attributes which are changed by the user for confirmation.
1595
	 *      <br>Empty string if nothing is changed.
1596
	 */
1597
	private String isItemChanged() {
1598
		StringBuilder sb = new StringBuilder("");
1599
		mandatoryChangedValMap = new HashMap<String, Object>();
1600
		optionalChangedValMap = new HashMap<String, Object>();
1601
		if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
1602
			mandatoryChangedValMap.put(MANDATORY_BRAND, brand.getText().trim());
1603
			sb.append("\n-Brand");
1604
		}
1605
		if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
1606
			mandatoryChangedValMap.put(MANDATORY_MODEL_NO, modelNumber.getText().trim());
1607
			sb.append("\n-Model Number");
1608
		}
1609
		if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
1610
			mandatoryChangedValMap.put(MANDATORY_MODEL_NAME, modelName.getText().trim());
1611
			sb.append("\n-Model Name");
1612
		}
1613
		if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
1614
			sb.append("\n-Color");
1615
		}
1616
		if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
1617
			sb.append("\n-Status Description");
1618
		}
1619
		if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
1620
			sb.append("\n-Comments");
1621
		}
1622
		if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
1623
			mandatoryChangedValMap.put(MANDATORY_MRP, newItem.getMrp());
1624
			sb.append("\n-MRP");
1625
		}
1626
		if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
1627
			optionalChangedValMap.put(OPTIONAL_SELLING_PRICE, newItem.getSellingPrice());
1628
			sb.append("\n-Selling Price");
1629
		}
1630
		if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
1631
			mandatoryChangedValMap.put(MANDATORY_WEIGHT, newItem.getWeight());
1632
			sb.append("\n-Weight");
1633
		}
1634
		if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
1635
			mandatoryChangedValMap.put(MANDATORY_BEST_DEAL_TEXT, bestDealsText.getText().trim());
1636
			sb.append("\n-Best Deal Text");
1637
		}
1638
		if(!checkParameterIfEqual(bestDealsDetailsText.getText().trim(), item.getBestDealsDetailsText())) {
1639
			mandatoryChangedValMap.put(MANDATORY_BEST_DEAL_DETAIL_TEXT, bestDealsDetailsText.getText().trim());
1640
			sb.append("\n-Best Deal Detail Text");
1641
		}
1642
		if(!checkParameterIfEqual(bestDealsDetailsLink.getText().trim(), item.getBestDealsDetailsLink())) {
1643
			mandatoryChangedValMap.put(MANDATORY_BEST_DEAL_DETAIL_LINK, bestDealsDetailsLink.getText().trim());
1644
			sb.append("\n-Best Deal Detail Link");
1645
		}
1646
		if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
1647
			sb.append("\n-Best Deal Value");
1648
		}
1649
		if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
1650
			sb.append("\n-Best Selling Rank");
1651
		}
1652
		if(!checkParameterIfEqual(newItem.getMinStockLevel(), item.getMinStockLevel())) {
1653
			sb.append("\n-Min Stock Level");
1654
		}
1655
		if(!checkParameterIfEqual(newItem.getNumOfDaysStock(), item.getNumOfDaysStock())) {
1656
			sb.append("\n-Number Of Days Of Stock");
1657
		}
1658
		if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
1659
			sb.append("\n-Default For Entity Flag");
1660
		}
1661
		if(item.isRisky() != risky.getValue()) {
1662
			sb.append("\n-Risky Flag");
1663
		}
1664
		if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
1665
			sb.append("\n-Start Date");
1666
		}
1667
		if(!checkParameterIfEqual(newItem.getExpectedArrivalDate(), item.getExpectedArrivalDate())) {
1668
			sb.append("\n-Expected Arrival Date");
1669
		}
1670
		if(!checkParameterIfEqual(newItem.getComingSoonStartDate(), item.getComingSoonStartDate())) {
1671
			sb.append("\n-Coming Soon Start Date");
1672
		}
1673
		if(!checkParameterIfEqual(newItem.getExpectedDelay(), item.getExpectedDelay())) {
1674
			sb.append("\n-Expected Delay");
1675
		}
1676
		if(item.isWarehouseStickiness() != warehouseStickiness.getValue()) {
1677
			sb.append("\n-Warehouse Stickiness Flag");
1678
		}
1679
		if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor())) {
1680
			optionalChangedValMap.put(OPTIONAL_PREFERRED_VENDOR, newItem.getPreferredVendor());
1681
			sb.append("\n-Preferred Vendor");
1682
		}
1683
		if(!checkParameterIfEqual(newItem.getPreferredInsurer(), item.getPreferredInsurer())) {
1684
			optionalChangedValMap.put(OPTIONAL_PREFERRED_INSURER, newItem.getPreferredInsurer());
1685
			sb.append("\n-Preferred Insurer");
1686
		}
1687
		if(item.isHasItemNo() != hasItemNo.getValue()) {
1688
			sb.append("\n-Has Item Number Flag");
1689
		}
1690
		if(item.isItemType() != itemType.getValue()) {
1691
			sb.append("\n-Has Serial Number Flag");
1692
		}
1693
		if(item.isShowSellingPrice() != showSellingPrice.getValue()) {
1694
			sb.append("\n-Coming Soon item pricing marked");
1695
		}
1696
		if(item.isHoldOverride() != holdOverride.getValue()) {
1697
			sb.append("\n-Hold Override is marked");
1698
		}
1699
		if(!checkParameterIfEqual(newItem.getFreebieItemId(), item.getFreebieItemId())) {
1700
			optionalChangedValMap.put(OPTIONAL_FREEBIE_ITEM_ID, freebieItemId.getText().trim());
1701
			sb.append("\n-Freebie Item Id");
1702
		}
1703
		if(!checkParameterIfEqual(asin.getText().trim(), item.getAsin())) {
1704
			sb.append("\n-Asin");
1705
		}
1706
		if(!checkParameterIfEqual(newItem.getHoldInventory(), item.getHoldInventory())) {
1707
			sb.append("\n-Hold Inventory");
1708
		}
1709
		if(!checkParameterIfEqual(newItem.getDefaultInventory(), item.getDefaultInventory())) {
1710
			sb.append("\n-Default Inventory");
1711
		}
1712
		VendorPricings vendorPricings;
1713
		long vendorId;
1714
		boolean vendorPricingsChanged = false;
1715
		for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
1716
			vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
1717
			vendorPricings = item.getVendorPricesMap().get(vendorId);
1718
			if(vendorPricings == null) {
1719
				sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
1720
				vendorPricingsChanged = true;
1721
				continue;
1722
			}
1723
			if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
1724
				vendorPricingsChanged = true;
1725
				sb.append("\n-MOP (Vendor:" + vendorId + ")");
1726
			}
1727
			if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
1728
				vendorPricingsChanged = true;
1729
				sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
1730
			}
1731
			if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
1732
				vendorPricingsChanged = true;
1733
			}
1734
			if(vendorPricings.getNlc() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_NLC))) {
1735
				vendorPricingsChanged = true;
1736
			}
1737
		}
1738
		if(vendorPricingsChanged){
1739
			sb.append("\n-Vendor Pricing");
1740
			optionalChangedValMap.put(OPTIONAL_VENDOR_PRICING, newItem.getVendorPricesMap());
1741
		}
1742
 
1743
		SourcePricings sourcePricings;
1744
		boolean sourcePricingsChanged = false;
1745
		long sourceId;
1746
		for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1747
			sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1748
			sourcePricings = item.getSourcePricesMap().get(sourceId);
1749
			if(sourcePricings == null) {
1750
				sourcePricingsChanged = true;
1751
				sb.append("\n-Source Prices (Source:" + sourceId + ")");
1752
				continue;
1753
			}
1754
			if(sourcePricings.getMrp() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP))) {
1755
				sourcePricingsChanged = true;
1756
				sb.append("\n-MRP (Source:" + sourceId + ")");
1757
			}
1758
			if(sourcePricings.getSellingPrice() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE))) {
1759
				sourcePricingsChanged = true;
1760
				sb.append("\n-Selling Price (Source:" + sourceId + ")");
1761
			}
1762
		}
1763
		if(sourcePricingsChanged){
1764
			sb.append("\n-Source Pricing");
1765
			optionalChangedValMap.put(OPTIONAL_SOURCE_PRICING, newItem.getSourcePricesMap());
1766
		}
1767
 
1768
 
1769
		VendorItemMapping mapping;
1770
		String old_key, new_key;
1771
		for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
1772
			vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
1773
			old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
1774
			new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
1775
			mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
1776
			if(mapping == null || !old_key.equals(new_key)) {
1777
				sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
1778
				continue;
1779
			}
1780
		}
1781
		return sb.toString();
1782
	}
1783
 
1784
	@SuppressWarnings("unused")
2566 chandransh 1785
	private boolean validatePrices() {
10484 vikram.rag 1786
		if(newItem.getSellingPrice() > newItem.getMrp()) {
1787
			Window.alert("Selling price cannot be more than MRP");
1788
			return false;
1789
		}
1790
		for(VendorPricings v : newItem.getVendorPricesMap().values()) {
1791
			if(newItem.getMrp() < v.getMop()) {
1792
				Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
1793
				return false;
1794
			}
1795
			if(v.getTransferPrice() > v.getMop()) {
1796
				Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
1797
				return false;
1798
			}
1799
		}
1800
		return true;
1801
	}
3558 rajveer 1802
 
10484 vikram.rag 1803
	private boolean validateVendorPrices(double mop, double dp, double tp, double nlc) {
1804
		if(item.getMrp() != null && item.getMrp() < mop) {
1805
			Window.alert("MOP cannot be more than MRP.");
1806
			return false;
1807
		}
1808
		if(tp > mop) {
1809
			Window.alert("Transfer Price cannot be more than MOP.");
1810
			return false;
1811
		}
1812
		if(tp < nlc) {
1813
			Window.alert("Transfer Price cannot be less than NLC.");
1814
			return false;
1815
		}
1816
		return true;
1817
	}
3558 rajveer 1818
 
10484 vikram.rag 1819
	private boolean validateSourcePrices(double mrp, double sellingPrice) {
1820
		if(sellingPrice > mrp) {
1821
			Window.alert("Selling Price cannot be more than MRP.");
1822
			return false;
1823
		}
1824
		return true;
1825
	}
1826
 
1827
 
1828
	public long getItemId() {
1829
		return item == null ? 0 : item.getId();
1830
	}
1831
 
1832
	public Item getItem() {
1833
		return item;
1834
	}
1835
 
1836
	private boolean voucherExists(String voucherType) {
1837
		for(int i = 0; i < tableVouchers.getRowCount(); i++) {
1838
			if(voucherType.equals(tableVouchers.getText(i, TABLE_INDEX_VOUCHERS_TYPE))) {
1839
				return false;
1840
			}
1841
		}
1842
		return true;
1843
	}
1844
 
1845
	/**
1846
	 * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
1847
	 * @param vendorId
1848
	 * @return true if parameter vendor Id is already added to vendor prices table.
1849
	 *      <br>else false
1850
	 */
1851
	private boolean vendorExists(long vendorId) {
1852
		long id;
1853
		for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
1854
			id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
1855
			if(vendorId == id) {
1856
				return false;
1857
			}
1858
		}
1859
		return true;
1860
	}
1861
 
1862
	/**
1863
	 * This method is used while adding source prices to ensure that there is only one row in the table for a source.
1864
	 * @param sourceId
1865
	 * @return true if parameter vendor Id is already added to source prices table.
1866
	 *      <br>else false
1867
	 */
1868
	private boolean sourceExists(long sourceId) {
1869
		long id;
1870
		for(int i = 0; i < tableSourcePrices.getRowCount(); i++) {
1871
			id = Long.parseLong(tableSourcePrices.getText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1872
			if(sourceId == id) {
1873
				return false;
1874
			}
1875
		}
1876
		return true;
1877
	}
1878
 
1879
	/**
1880
	 * This method is used to check if any of the string item attributes is changed by the user.
1881
	 * @param o1
1882
	 * @param o2
1883
	 * @return true if two strings are equal
1884
	 *      <br>true if one of them is null and another is empty.
1885
	 *      <br>false otherwise
1886
	 */
1887
	private boolean checkParameterIfEqual(Object o1, Object o2) {
1888
		if(o1 == o2) {
1889
			return true;
1890
		}
1891
		if(o1 != null && o2 != null && o1.equals(o2)) {
1892
			return true;
1893
		}
1894
		if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
1895
			return true;
1896
		}
1897
		return false;
1898
	}
1899
 
1900
	public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
1901
		this.catalogDashboardPanel = catalogDashboardPanel;
1902
	}
1903
 
1904
	private String compareSellingPricewithBreakEven() {
1905
		String message = "false";
1906
		if(newItem.getWeight() == null) {
1907
			Window.alert("Weight is empty.");
1908
			return message;
1909
		}
1910
		if(newItem.getSellingPrice() == null) {
1911
			Window.alert("Selling Price is empty.");
1912
			return message;
1913
		}
1914
 
1915
		double transferPrice;
1916
		if(newItem.getPreferredVendor() == null && !newItem.getVendorPricesMap().isEmpty()) {
1917
			transferPrice = -1;
4649 phani.kuma 1918
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
6779 rajveer 1919
				if(transferPrice > vendorDetail.getNlc() || transferPrice == -1){
1920
					transferPrice = vendorDetail.getNlc();
4649 phani.kuma 1921
				}
1922
			}
10484 vikram.rag 1923
		}
1924
		else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1925
			transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getNlc();    		
1926
		}
1927
		else{
1928
			Window.alert("Add vendor to Vendor Prices and then change the Selling Price.");
1929
			return message;
1930
		}
4649 phani.kuma 1931
 
10484 vikram.rag 1932
		double weightfactor = Math.ceil((newItem.getWeight() * 1000)/Double.parseDouble(ConfigMap.get("courier_weight_factor")));
4649 phani.kuma 1933
		double couriercost = Double.parseDouble(ConfigMap.get("courier_cost_factor")) * weightfactor;
1934
		double costfactor = (Double.parseDouble(ConfigMap.get("transfer_price_percentage")) * transferPrice)/100;
1935
		double breakeven;
1936
		if(costfactor < Double.parseDouble(ConfigMap.get("transfer_price_factor"))){
1937
			breakeven = transferPrice + couriercost + Double.parseDouble(ConfigMap.get("breakeven_additon_factor"));
1938
		}
1939
		else{
1940
			breakeven = (transferPrice + couriercost)/Double.parseDouble(ConfigMap.get("breakeven_divisor"));
1941
		}
10484 vikram.rag 1942
 
4649 phani.kuma 1943
		if(breakeven > newItem.getSellingPrice()) {
1944
			message = "Selling Price("+newItem.getSellingPrice()+") is less than Breakeven Price("+breakeven+").";
1945
			if(Window.confirm(message)){
1946
				return message;
1947
			}
1948
			else{
1949
				message = "false";
1950
				Window.alert("Updation of Item is canceled.");
1951
				return message;
1952
			}
1953
		}
1954
		else {
1955
			message = "true";
10484 vikram.rag 1956
			return message;
4649 phani.kuma 1957
		}
10484 vikram.rag 1958
	}
1959
 
1960
	private String checkTransferPriceforPreferredVendor() {
1961
		String message = "false";
1962
		if(newItem.getPreferredVendor() == null) {
1963
			message = "true";
1964
			return message;
1965
		}
1966
		else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1967
			double transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();
1968
			double mintransferPrice = -1;
1969
			String minvendor = "";
1970
			boolean compareTransferPrices = false;
4649 phani.kuma 1971
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1972
				if(mintransferPrice > vendorDetail.getTransferPrice() || mintransferPrice == -1){
1973
					mintransferPrice = vendorDetail.getTransferPrice();
1974
					minvendor = Utils.getVendorDesc(vendorDetail.getVendorId());
1975
				}
1976
			}
1977
			if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor()) || item.getVendorPricesMap().isEmpty()) {
1978
				compareTransferPrices = true;
1979
			}
1980
			else {
1981
				double oldmintransferPrice = -1;
1982
				for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
1983
					if(oldmintransferPrice > vendorDetail.getTransferPrice() || oldmintransferPrice == -1){
1984
						oldmintransferPrice = vendorDetail.getTransferPrice();
1985
					}
1986
				}
1987
				if(mintransferPrice < oldmintransferPrice){
1988
					compareTransferPrices = true;
1989
				}
1990
			}
1991
			if(compareTransferPrices && transferPrice > mintransferPrice){
1992
				message = "Transfer Price("+transferPrice+") of Preferred Vendor("+Utils.getVendorDesc(newItem.getPreferredVendor())+") is more than Transfer Price("+mintransferPrice+") of "+minvendor+".";
1993
				if(Window.confirm(message)){
1994
					return message;
1995
				}
1996
				else{
1997
					message = "false";
1998
					Window.alert("Updation of Item is canceled.");
1999
					return message;
2000
				}
2001
			}
2002
			else {
2003
				message = "true";
10484 vikram.rag 2004
				return message;
4649 phani.kuma 2005
			}
10484 vikram.rag 2006
		}
2007
		else{
2008
			Window.alert("Add vendor to Vendor Prices and then change the Preferred Vendor.");
2009
			return message;
2010
		}
2011
	}
5217 amit.gupta 2012
 
10484 vikram.rag 2013
	public void logAuthorization(String message) {
2014
		String username = catalogDashboardPanel.uname;
2015
		catalogService.addAuthorizationLog(newItem.getId(), username, message, new AsyncCallback<Boolean>() {
2016
			@Override
2017
			public void onSuccess(Boolean result) {
2018
				if(result) {
2019
					GWT.log("Event is added");
2020
				}
2021
				else {
2022
					GWT.log("Error adding the event");
2023
					Window.alert("Error adding the event");
2024
				}
2025
			}
2026
			@Override
2027
			public void onFailure(Throwable caught) {
2028
				caught.printStackTrace();
2029
				Window.alert("Error while adding the event");
2030
			}
2031
		});
2032
	}
2033
 
5217 amit.gupta 2034
	@Override
2035
	public void setComingSoonStartDate(Date date) {
2036
		this.comingSoonStartDate.setValue(date);
10484 vikram.rag 2037
 
5217 amit.gupta 2038
	}
2039
 
2040
	@Override
2041
	public void setBestDealsText(String bestDealsText) {
2042
		this.bestDealsText.setValue(bestDealsText);
10484 vikram.rag 2043
 
5217 amit.gupta 2044
	}
2045
 
2046
	@Override
2047
	public void setExpectedArrivalDate(Date date) {
2048
		this.expectedArrivalDate.setValue(date);
10484 vikram.rag 2049
 
5217 amit.gupta 2050
	}
2051
 
2052
	@Override
2053
	public String getBestDealsText() {
2054
		return this.bestDealsText.getValue();
2055
	}
7291 vikram.rag 2056
 
6777 vikram.rag 2057
	public void setBestDealsDetailsText(String bestDealsDetailsText) {
2058
		this.bestDealsDetailsText.setValue(bestDealsDetailsText);
10484 vikram.rag 2059
 
6777 vikram.rag 2060
	}
10484 vikram.rag 2061
 
6777 vikram.rag 2062
	public String getBestDealsDetailsText() {
2063
		return this.bestDealsDetailsText.getValue();
2064
	}
5217 amit.gupta 2065
 
2066
	@Override
2067
	public Date getComingSoonStartDate() {
2068
		return this.comingSoonStartDate.getValue();
2069
	}
2070
 
2071
	@Override
2072
	public Date getExpectedArrivalDate() {
2073
		return this.expectedArrivalDate.getValue();
2074
	}
2075
	@UiHandler("comingSoonButton")
2076
	void onComingSoonButtonClick(ClickEvent event) {
2077
		ComingSoonDialog cd = new ComingSoonDialog(this);
2078
		cd.show();
2079
	}
10484 vikram.rag 2080
 
5427 amit.gupta 2081
	private void createDialog(String changedString) {
10484 vikram.rag 2082
		VerticalPanel vp = new VerticalPanel();
2083
		final DialogBox db = new DialogBox();
2084
		db.setText("Changed fields");
2085
 
2086
		vp.add(new Label("Check the fields to update all SKUs with similar entity."));
2087
		vp.add(new Label("--------------------------------------------------------"));
2088
		CheckBox allChecked = new CheckBox("Select all");
2089
		if(optionalChangedValMap.size()>1){
2090
			allChecked.setName("all");
2091
			allChecked.addClickHandler(new ClickHandler() {
5427 amit.gupta 2092
				@Override
2093
				public void onClick(ClickEvent event) {
2094
					CheckBox cb = (CheckBox)event.getSource();
2095
					VerticalPanel vp = (VerticalPanel)cb.getParent();
2096
					Iterator<Widget> iterator = vp.iterator();
2097
					while(iterator.hasNext()){
2098
						Widget w = iterator.next();
2099
						if(w instanceof CheckBox){
2100
							CheckBox cbox = (CheckBox)w;
2101
							if(cbox.getName()!="all"){
2102
								cbox.setValue(cb.getValue());
2103
							}
2104
						}
2105
					}
2106
					if(cb.getValue()){
2107
						cb.setText("Deselect all");
2108
					}else {
2109
						cb.setText("Select all");
2110
					}
2111
				}
2112
			});
10484 vikram.rag 2113
			vp.add(allChecked);
2114
		}
2115
		String[] changedFields = changedString.split("\n-");
2116
		for(String changeField : changedFields){
2117
			if(optionalChangedValMap.containsKey(changeField)){
2118
				CheckBox ch = new CheckBox(changeField); 
2119
				ch.getElement().getStyle().setPadding(10d, Unit.PX);
2120
				vp.add(ch);
2121
			} else {
2122
				Label l = new Label(changeField);
2123
				l.getElement().getStyle().setMarginLeft(10d, Unit.PX);
2124
				l.getElement().getStyle().setPadding(10d, Unit.PX);
2125
				vp.add(l);
2126
			}
2127
		}
5427 amit.gupta 2128
 
10484 vikram.rag 2129
		Button submitButton = new Button();
2130
		submitButton.setText("Update");
2131
		submitButton.addClickHandler(new ClickHandler() {
2132
 
5427 amit.gupta 2133
			@Override
2134
			public void onClick(ClickEvent event) {
2135
				Button b  = (Button)event.getSource();
2136
				VerticalPanel vp = (VerticalPanel)b.getParent();
2137
				Iterator<Widget> iterator = vp.iterator();
2138
				while(iterator.hasNext()){
2139
					Widget w = iterator.next();
2140
					if(w instanceof CheckBox){
2141
						CheckBox cbox = (CheckBox)w;
2142
						if(cbox.getName()!="all"){
2143
							if(!cbox.getValue()){
2144
								optionalChangedValMap.remove(cbox.getText());
2145
							}
2146
						}
2147
					}
2148
				}
2149
				db.hide();
2150
				List<Item> items = new ArrayList<Item>();
2151
				items.add(newItem);
2152
				validateNUpdate();
2153
				/*for(Long id : item.getSameItemsWithDifferentColors()){
2154
					catalogService.getItem(id, new AsyncCallback<Item>() {
2155
			            @Override
2156
			            public void onSuccess(Item result) {
2157
			                items.add(e)
2158
			            }
2159
			            @Override
2160
			            public void onFailure(Throwable caught) {
2161
			                caught.printStackTrace();
2162
			                Window.alert("Unable to fetch item details.");
2163
			            }
2164
			        });
2165
				}*/
2166
			}
10484 vikram.rag 2167
 
5427 amit.gupta 2168
		});
10484 vikram.rag 2169
		vp.add(submitButton);
2170
		db.add(vp); 
2171
		db.center();
2172
		db.show();   
2173
	}
2174
 
5427 amit.gupta 2175
	private void updateItem(Long itemId) {
2176
		catalogService.getItem(itemId, new AsyncCallback<Item>() {
10484 vikram.rag 2177
			@Override
2178
			public void onSuccess(Item result) {
2179
				final Item res = result;
2180
				if(mandatoryChangedValMap.containsKey(MANDATORY_BRAND)){
2181
					result.setBrand((String)mandatoryChangedValMap.get(MANDATORY_BRAND));
2182
				}
2183
				if(mandatoryChangedValMap.containsKey(MANDATORY_BEST_DEAL_TEXT)){
2184
					result.setBestDealsText((String)mandatoryChangedValMap.get(MANDATORY_BEST_DEAL_TEXT));
2185
				}
2186
				if(mandatoryChangedValMap.containsKey(MANDATORY_BEST_DEAL_DETAIL_TEXT)){
2187
					result.setBestDealsDetailsText((String)mandatoryChangedValMap.get(MANDATORY_BEST_DEAL_DETAIL_TEXT));
2188
				}
2189
				if(mandatoryChangedValMap.containsKey(MANDATORY_BEST_DEAL_DETAIL_LINK)){
2190
					result.setBestDealsDetailsLink((String)mandatoryChangedValMap.get(MANDATORY_BEST_DEAL_DETAIL_LINK));
2191
				}
2192
				if(mandatoryChangedValMap.containsKey(MANDATORY_MODEL_NAME)){
2193
					result.setModelName((String)mandatoryChangedValMap.get(MANDATORY_MODEL_NAME));
2194
				}
2195
				if(mandatoryChangedValMap.containsKey(MANDATORY_MODEL_NO)){
2196
					result.setModelNumber((String)mandatoryChangedValMap.get(MANDATORY_MODEL_NO));
2197
				}
2198
				if(mandatoryChangedValMap.containsKey(MANDATORY_WEIGHT)){
2199
					result.setWeight((Double)mandatoryChangedValMap.get(MANDATORY_WEIGHT));
2200
				}
2201
				if(mandatoryChangedValMap.containsKey(MANDATORY_MRP)){
2202
					result.setMrp((Double)mandatoryChangedValMap.get(MANDATORY_MRP));
2203
				}
2204
				if(optionalChangedValMap.containsKey(OPTIONAL_FREEBIE_ITEM_ID)) {
2205
					result.setFreebieItemId((Long)optionalChangedValMap.get(OPTIONAL_FREEBIE_ITEM_ID));
2206
				}
2207
				if(optionalChangedValMap.containsKey(OPTIONAL_PREFERRED_VENDOR)){
2208
					result.setPreferredVendor((Long)optionalChangedValMap.get(OPTIONAL_PREFERRED_VENDOR));
2209
				}
2210
				if(optionalChangedValMap.containsKey(OPTIONAL_PREFERRED_INSURER)){
2211
					result.setPreferredInsurer((Long)optionalChangedValMap.get(OPTIONAL_PREFERRED_INSURER));
2212
				}
2213
				if(optionalChangedValMap.containsKey(OPTIONAL_SELLING_PRICE)){
2214
					result.setSellingPrice((Double)optionalChangedValMap.get(OPTIONAL_SELLING_PRICE));
2215
				}
2216
				if(optionalChangedValMap.containsKey(OPTIONAL_SOURCE_PRICING)){
2217
					result.setSourcePricesMap((Map<Long, SourcePricings>) optionalChangedValMap.get(OPTIONAL_SOURCE_PRICING));
2218
				}
2219
				if(optionalChangedValMap.containsKey(OPTIONAL_VENDOR_PRICING)){
2220
					result.setVendorPricesMap((Map<Long, VendorPricings>) optionalChangedValMap.get(OPTIONAL_VENDOR_PRICING));
2221
				}
2222
				catalogService.updateItem(result, new AsyncCallback<Boolean>() {
2223
 
5427 amit.gupta 2224
					@Override
2225
					public void onSuccess(Boolean result1) {
2226
						if(result1) {
2227
							Window.alert(res.getId() + " updated Successfully");
2228
						}
10484 vikram.rag 2229
 
5427 amit.gupta 2230
					}
10484 vikram.rag 2231
 
5427 amit.gupta 2232
					@Override
2233
					public void onFailure(Throwable caught) {
2234
						caught.printStackTrace();
2235
						Window.alert("Error updating item " + res.getId());
10484 vikram.rag 2236
 
5427 amit.gupta 2237
					}
2238
				});
10484 vikram.rag 2239
			}
2240
			@Override
2241
			public void onFailure(Throwable caught) {
2242
				caught.printStackTrace();
2243
				Window.alert("Unable to fetch item details.");
2244
			}
2245
		});
5427 amit.gupta 2246
	}
6241 amit.gupta 2247
 
2248
	@Override
2249
	public void setShowPrice(boolean b) {
2250
		this.showSellingPrice.setValue(b);
2251
	}
2252
 
2253
	@Override
2254
	public boolean isShowPrice() {
2255
		return this.showSellingPrice.getValue();
2256
	}
1961 ankur.sing 2257
}