Subversion Repositories SmartDukaan

Rev

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