Subversion Repositories SmartDukaan

Rev

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