Subversion Repositories SmartDukaan

Rev

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