Subversion Repositories SmartDukaan

Rev

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