Subversion Repositories SmartDukaan

Rev

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

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