Subversion Repositories SmartDukaan

Rev

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