Subversion Repositories SmartDukaan

Rev

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