Subversion Repositories SmartDukaan

Rev

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