Subversion Repositories SmartDukaan

Rev

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