Subversion Repositories SmartDukaan

Rev

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