Subversion Repositories SmartDukaan

Rev

Rev 5127 | Rev 5309 | 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());
1053
        newItem.setOtherInfo(item.getOtherInfo());
4431 phani.kuma 1054
        newItem.setItemInventory(item.getItemInventory());
4423 phani.kuma 1055
        newItem.setSimilarItems(item.getSimilarItems());
2119 ankur.sing 1056
 
2126 ankur.sing 1057
        return true;
2066 ankur.sing 1058
    }
1059
 
2427 ankur.sing 1060
    /**
1061
     * This method is called when Edit button is clicked corresponding to a row in 
1062
     * vendor prices table. It will pop up a form to edit the vendor prices.
1063
     * @param vendorId
1064
     * @param row
1065
     */
1066
    private void editVendorPrices(final long vendorId, final int row) {
1067
        String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
1068
        String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
1069
        String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
2119 ankur.sing 1070
        VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);
2105 ankur.sing 1071
        pricesDialog.updateButton.setText("Update");
2119 ankur.sing 1072
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2066 ankur.sing 1073
            @Override
2119 ankur.sing 1074
            public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
1075
                if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 1076
                    return false;
1077
                }
2427 ankur.sing 1078
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
1079
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
1080
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
2105 ankur.sing 1081
                return true;
2066 ankur.sing 1082
            }
1083
        });
1084
        pricesDialog.show();
1085
    }
2119 ankur.sing 1086
 
2427 ankur.sing 1087
    /**
1088
     * This method is called when Edit button is clicked corresponding to a row in 
3558 rajveer 1089
     * vendor prices table. It will pop up a form to edit the vendor prices.
1090
     * @param vendorId
1091
     * @param row
1092
     */
1093
    private void editSourcePrices(final long sourceId, final int row) {
1094
        String mrp = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP);
1095
        String sellingPrice = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE);
1096
        SourcePricesDialog pricesDialog = new SourcePricesDialog(mrp, sellingPrice);
1097
        pricesDialog.updateButton.setText("Update");
1098
        pricesDialog.setSourcePriceUpdateListener(new SourcePricesDialog.SourcePriceUpdateListener() {
1099
            @Override
1100
            public boolean onUpdate(double mrp, double sellingPrice, long sourceId) {
1101
                if(!validateSourcePrices(mrp, sellingPrice)) {
1102
                    return false;
1103
                }
1104
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_MRP, mrp + "");
1105
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sellingPrice + "");
1106
                return true;
1107
            }
1108
        });
1109
        pricesDialog.show();
1110
    }
1111
 
1112
 
1113
    /**
1114
     * This method is called when Edit button is clicked corresponding to a row in 
2427 ankur.sing 1115
     * vendor item key table. It will pop up a form to edit the item key.
1116
     * @param vendorId
1117
     * @param row
1118
     */
1119
    private void editVendorKey(final long vendorId, final int row) {
1120
        String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2126 ankur.sing 1121
        VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
1122
                modelNumber.getText().trim(), color.getText().trim(), key);
2119 ankur.sing 1123
        mappingDialog.updateButton.setText("Update");
1124
        mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
1125
            @Override
1126
            public boolean onUpdate(String itemKey, long vendorId) {
1127
                if(itemKey == null || itemKey.equals("")) {
1128
                    Window.alert("Item key cannot be empty.");
1129
                    return false;
1130
                }
2427 ankur.sing 1131
                tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
2119 ankur.sing 1132
                return true;
1133
            }
1134
        });
1135
        mappingDialog.show();
1136
    }
2066 ankur.sing 1137
 
2427 ankur.sing 1138
    /**
1139
     * This method compares all the editable UI fields values with attributes in the item object.
1140
     * If they differ, the attribute name is appended to a string.
1141
     * @return String showing attributes which are changed by the user for confirmation.
1142
     *      <br>Empty string if nothing is changed.
1143
     */
2252 ankur.sing 1144
    private String isItemChanged() {
1145
        StringBuilder sb = new StringBuilder("");
4762 phani.kuma 1146
 
2489 ankur.sing 1147
        if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
2387 ankur.sing 1148
            sb.append("\n-Brand");
2066 ankur.sing 1149
        }
2489 ankur.sing 1150
        if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
2387 ankur.sing 1151
            sb.append("\n-Model Number");
2066 ankur.sing 1152
        }
2489 ankur.sing 1153
        if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
2387 ankur.sing 1154
            sb.append("\n-Model Name");
2066 ankur.sing 1155
        }
2489 ankur.sing 1156
        if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
2387 ankur.sing 1157
            sb.append("\n-Color");
2066 ankur.sing 1158
        }
2489 ankur.sing 1159
        if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
2387 ankur.sing 1160
            sb.append("\n-Status Description");
2359 ankur.sing 1161
        }
2489 ankur.sing 1162
        if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
2387 ankur.sing 1163
            sb.append("\n-Comments");
2066 ankur.sing 1164
        }
2489 ankur.sing 1165
        if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
2387 ankur.sing 1166
            sb.append("\n-MRP");
2066 ankur.sing 1167
        }
2489 ankur.sing 1168
        if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
2387 ankur.sing 1169
            sb.append("\n-Selling Price");
2027 ankur.sing 1170
        }
2489 ankur.sing 1171
        if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
2387 ankur.sing 1172
            sb.append("\n-Weight");
2027 ankur.sing 1173
        }
2489 ankur.sing 1174
        if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
2387 ankur.sing 1175
            sb.append("\n-Best Deal Text");
2066 ankur.sing 1176
        }
2489 ankur.sing 1177
        if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
2387 ankur.sing 1178
            sb.append("\n-Best Deal Value");
2027 ankur.sing 1179
        }
2489 ankur.sing 1180
        if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
2387 ankur.sing 1181
            sb.append("\n-Best Selling Rank");
2066 ankur.sing 1182
        }
1183
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
2387 ankur.sing 1184
            sb.append("\n-Default For Entity Flag");
2066 ankur.sing 1185
        }
2252 ankur.sing 1186
        if(item.isRisky() != risky.getValue()) {
2387 ankur.sing 1187
            sb.append("\n-Risky Flag");
2252 ankur.sing 1188
        }
2489 ankur.sing 1189
        if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
2387 ankur.sing 1190
            sb.append("\n-Start Date");
2068 ankur.sing 1191
        }
5217 amit.gupta 1192
        if(!checkParameterIfEqual(newItem.getExpectedArrivalDate(), item.getExpectedArrivalDate())) {
1193
        	sb.append("\n-Expected Arrival Date");
1194
        }
1195
        if(!checkParameterIfEqual(newItem.getComingSoonStartDate(), item.getComingSoonStartDate())) {
1196
        	sb.append("\n-Coming Soon Start Date");
1197
        }
3524 chandransh 1198
        if(!checkParameterIfEqual(newItem.getExpectedDelay(), item.getExpectedDelay())) {
3362 chandransh 1199
            sb.append("\n-Expected Delay");
1200
        }
3524 chandransh 1201
        if(!checkParameterIfEqual(newItem.getPreferredWarehouse(), item.getPreferredWarehouse())) {
3362 chandransh 1202
            sb.append("\n-Preferred Warehouse");
1203
        }
4413 anupam.sin 1204
        if(!checkParameterIfEqual(newItem.getDefaultWarehouse(), item.getDefaultWarehouse())) {
1205
            sb.append("\n-Default Warehouse");
1206
        }
1207
        if(item.isWarehouseStickiness() != warehouseStickiness.getValue()) {
1208
            sb.append("\n-Warehouse Stickiness Flag");
1209
        }
4506 phani.kuma 1210
        if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor())) {
1211
            sb.append("\n-Preferred Vendor");
1212
        }
3362 chandransh 1213
 
2126 ankur.sing 1214
        VendorPricings vendorPricings;
2066 ankur.sing 1215
        long vendorId;
2427 ankur.sing 1216
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
1217
            vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
2126 ankur.sing 1218
            vendorPricings = item.getVendorPricesMap().get(vendorId);
2359 ankur.sing 1219
            if(vendorPricings == null) {
2387 ankur.sing 1220
                sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
2359 ankur.sing 1221
                continue;
1222
            }
2427 ankur.sing 1223
            if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
2387 ankur.sing 1224
                sb.append("\n-MOP (Vendor:" + vendorId + ")");
2066 ankur.sing 1225
            }
2427 ankur.sing 1226
            if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
2387 ankur.sing 1227
                sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 1228
            }
2427 ankur.sing 1229
            if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
2387 ankur.sing 1230
                sb.append("\n-Transfer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 1231
            }
1232
        }
2387 ankur.sing 1233
 
3558 rajveer 1234
        SourcePricings sourcePricings;
1235
        long sourceId;
1236
        for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1237
            sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1238
            sourcePricings = item.getSourcePricesMap().get(sourceId);
1239
            if(sourcePricings == null) {
1240
                sb.append("\n-Source Prices (Source:" + sourceId + ")");
1241
                continue;
1242
            }
1243
            if(sourcePricings.getMrp() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP))) {
1244
                sb.append("\n-MRP (Source:" + sourceId + ")");
1245
            }
1246
            if(sourcePricings.getSellingPrice() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE))) {
1247
                sb.append("\n-Selling Price (Source:" + sourceId + ")");
1248
            }
1249
        }
1250
 
2387 ankur.sing 1251
        VendorItemMapping mapping;
1252
        String old_key, new_key;
2427 ankur.sing 1253
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
1254
            vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
1255
            old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
1256
            new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2387 ankur.sing 1257
            mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
1258
            if(mapping == null || !old_key.equals(new_key)) {
1259
                sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
1260
                continue;
1261
            }
1262
        }
2252 ankur.sing 1263
        return sb.toString();
2066 ankur.sing 1264
    }
1265
 
2566 chandransh 1266
    @SuppressWarnings("unused")
1267
	private boolean validatePrices() {
2066 ankur.sing 1268
        if(newItem.getSellingPrice() > newItem.getMrp()) {
1269
            Window.alert("Selling price cannot be more than MRP");
1270
            return false;
1271
        }
2119 ankur.sing 1272
        for(VendorPricings v : newItem.getVendorPricesMap().values()) {
2105 ankur.sing 1273
            if(newItem.getMrp() < v.getMop()) {
1274
                Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1275
                return false;
1276
            }
2105 ankur.sing 1277
            if(v.getTransferPrice() > v.getMop()) {
1278
                Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1279
                return false;
1280
            }
1281
        }
1282
        return true;
1283
    }
2105 ankur.sing 1284
 
2119 ankur.sing 1285
    private boolean validateVendorPrices(double mop, double dp, double tp) {
2489 ankur.sing 1286
        if(item.getMrp() != null && item.getMrp() < mop) {
2105 ankur.sing 1287
            Window.alert("MOP cannot be more than MRP.");
1288
            return false;
1992 ankur.sing 1289
        }
2105 ankur.sing 1290
        if(tp > mop) {
1291
            Window.alert("Transfer Price cannot be more than MOP.");
1292
            return false;
1992 ankur.sing 1293
        }
2105 ankur.sing 1294
        return true;
1992 ankur.sing 1295
    }
3558 rajveer 1296
 
1297
    private boolean validateSourcePrices(double mrp, double sellingPrice) {
1298
        if(sellingPrice > mrp) {
1299
            Window.alert("Selling Price cannot be more than MRP.");
1300
            return false;
1301
        }
1302
        return true;
1303
    }
1304
 
2105 ankur.sing 1305
 
1306
    public long getItemId() {
1307
        return item == null ? 0 : item.getId();
1308
    }
1309
 
1310
    public Item getItem() {
1311
        return item;
1312
    }
1313
 
2427 ankur.sing 1314
    /**
1315
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
1316
     * @param vendorId
1317
     * @return true if parameter vendor Id is already added to vendor prices table.
1318
     *      <br>else false
1319
     */
2105 ankur.sing 1320
    private boolean vendorExists(long vendorId) {
1321
        long id;
2427 ankur.sing 1322
        for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
1323
            id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
2105 ankur.sing 1324
            if(vendorId == id) {
1325
                return false;
1326
            }
1992 ankur.sing 1327
        }
2105 ankur.sing 1328
        return true;
1992 ankur.sing 1329
    }
2387 ankur.sing 1330
 
2427 ankur.sing 1331
    /**
3558 rajveer 1332
     * This method is used while adding source prices to ensure that there is only one row in the table for a source.
1333
     * @param sourceId
1334
     * @return true if parameter vendor Id is already added to source prices table.
1335
     *      <br>else false
1336
     */
1337
    private boolean sourceExists(long sourceId) {
1338
        long id;
1339
        for(int i = 0; i < tableSourcePrices.getRowCount(); i++) {
1340
            id = Long.parseLong(tableSourcePrices.getText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1341
            if(sourceId == id) {
1342
                return false;
1343
            }
1344
        }
1345
        return true;
1346
    }
1347
 
1348
    /**
2427 ankur.sing 1349
     * This method is used to check if any of the string item attributes is changed by the user.
2489 ankur.sing 1350
     * @param o1
1351
     * @param o2
2427 ankur.sing 1352
     * @return true if two strings are equal
1353
     *      <br>true if one of them is null and another is empty.
1354
     *      <br>false otherwise
1355
     */
2489 ankur.sing 1356
    private boolean checkParameterIfEqual(Object o1, Object o2) {
1357
        if(o1 == o2) {
2387 ankur.sing 1358
            return true;
1359
        }
2489 ankur.sing 1360
        if(o1 != null && o2 != null && o1.equals(o2)) {
2387 ankur.sing 1361
            return true;
1362
        }
2489 ankur.sing 1363
        if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
2387 ankur.sing 1364
            return true;
1365
        }
1366
        return false;
1367
    }
2489 ankur.sing 1368
 
1369
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
1370
        this.catalogDashboardPanel = catalogDashboardPanel;
1371
    }
4649 phani.kuma 1372
 
1373
    private String compareSellingPricewithBreakEven() {
1374
    	String message = "false";
1375
    	if(newItem.getWeight() == null) {
1376
    		Window.alert("Weight is empty.");
1377
            return message;
1378
    	}
1379
    	if(newItem.getSellingPrice() == null) {
1380
    		Window.alert("Selling Price is empty.");
1381
            return message;
1382
    	}
1383
 
1384
    	double transferPrice;
1385
    	if(newItem.getPreferredVendor() == null && !newItem.getVendorPricesMap().isEmpty()) {
1386
    		transferPrice = -1;
1387
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1388
				if(transferPrice > vendorDetail.getTransferPrice() || transferPrice == -1){
1389
					transferPrice = vendorDetail.getTransferPrice();
1390
				}
1391
			}
1392
    	}
1393
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1394
    		transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();    		
1395
    	}
1396
    	else{
1397
    		Window.alert("Add vendor to Vendor Prices and then change the Selling Price.");
1398
            return message;
1399
    	}
1400
 
1401
    	double weightfactor = Math.ceil((newItem.getWeight() * 1000)/Double.parseDouble(ConfigMap.get("courier_weight_factor")));
1402
		double couriercost = Double.parseDouble(ConfigMap.get("courier_cost_factor")) * weightfactor;
1403
		double costfactor = (Double.parseDouble(ConfigMap.get("transfer_price_percentage")) * transferPrice)/100;
1404
		double breakeven;
1405
		if(costfactor < Double.parseDouble(ConfigMap.get("transfer_price_factor"))){
1406
			breakeven = transferPrice + couriercost + Double.parseDouble(ConfigMap.get("breakeven_additon_factor"));
1407
		}
1408
		else{
1409
			breakeven = (transferPrice + couriercost)/Double.parseDouble(ConfigMap.get("breakeven_divisor"));
1410
		}
1411
 
1412
		if(breakeven > newItem.getSellingPrice()) {
1413
			message = "Selling Price("+newItem.getSellingPrice()+") is less than Breakeven Price("+breakeven+").";
1414
			if(Window.confirm(message)){
1415
				return message;
1416
			}
1417
			else{
1418
				message = "false";
1419
				Window.alert("Updation of Item is canceled.");
1420
				return message;
1421
			}
1422
		}
1423
		else {
1424
			message = "true";
1425
	        return message;
1426
		}
1427
    }
1428
 
1429
    private String checkTransferPriceforPreferredVendor() {
1430
    	String message = "false";
1431
    	if(newItem.getPreferredVendor() == null) {
1432
    		message = "true";
1433
    		return message;
1434
    	}
1435
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1436
    		double transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();
1437
        	double mintransferPrice = -1;
1438
        	String minvendor = "";
1439
        	boolean compareTransferPrices = false;
1440
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1441
				if(mintransferPrice > vendorDetail.getTransferPrice() || mintransferPrice == -1){
1442
					mintransferPrice = vendorDetail.getTransferPrice();
1443
					minvendor = Utils.getVendorDesc(vendorDetail.getVendorId());
1444
				}
1445
			}
1446
			if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor()) || item.getVendorPricesMap().isEmpty()) {
1447
				compareTransferPrices = true;
1448
			}
1449
			else {
1450
				double oldmintransferPrice = -1;
1451
				for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
1452
					if(oldmintransferPrice > vendorDetail.getTransferPrice() || oldmintransferPrice == -1){
1453
						oldmintransferPrice = vendorDetail.getTransferPrice();
1454
					}
1455
				}
1456
				if(mintransferPrice < oldmintransferPrice){
1457
					compareTransferPrices = true;
1458
				}
1459
			}
1460
			if(compareTransferPrices && transferPrice > mintransferPrice){
1461
				message = "Transfer Price("+transferPrice+") of Preferred Vendor("+Utils.getVendorDesc(newItem.getPreferredVendor())+") is more than Transfer Price("+mintransferPrice+") of "+minvendor+".";
1462
				if(Window.confirm(message)){
1463
					return message;
1464
				}
1465
				else{
1466
					message = "false";
1467
					Window.alert("Updation of Item is canceled.");
1468
					return message;
1469
				}
1470
			}
1471
			else {
1472
				message = "true";
1473
		        return message;
1474
			}
1475
    	}
1476
    	else{
1477
    		Window.alert("Add vendor to Vendor Prices and then change the Preferred Vendor.");
1478
            return message;
1479
    	}
1480
    }
1481
 
1482
    public void logAuthorization(String message) {
1483
    	String username = catalogDashboardPanel.uname;
1484
    	catalogService.addAuthorizationLog(newItem.getId(), username, message, new AsyncCallback<Boolean>() {
1485
            @Override
1486
            public void onSuccess(Boolean result) {
1487
                if(result) {
1488
                    GWT.log("Event is added");
1489
                }
1490
                else {
1491
                    GWT.log("Error adding the event");
1492
                    Window.alert("Error adding the event");
1493
                }
1494
            }
1495
            @Override
1496
            public void onFailure(Throwable caught) {
1497
                caught.printStackTrace();
1498
                Window.alert("Error while adding the event");
1499
            }
1500
        });
1501
    }
5217 amit.gupta 1502
 
1503
	@Override
1504
	public void setComingSoonStartDate(Date date) {
1505
		this.comingSoonStartDate.setValue(date);
1506
 
1507
	}
1508
 
1509
	@Override
1510
	public void setBestDealsText(String bestDealsText) {
1511
		this.bestDealsText.setValue(bestDealsText);
1512
 
1513
	}
1514
 
1515
	@Override
1516
	public void setExpectedArrivalDate(Date date) {
1517
		this.expectedArrivalDate.setValue(date);
1518
 
1519
	}
1520
 
1521
	@Override
1522
	public String getBestDealsText() {
1523
		return this.bestDealsText.getValue();
1524
	}
1525
 
1526
	@Override
1527
	public Date getComingSoonStartDate() {
1528
		return this.comingSoonStartDate.getValue();
1529
	}
1530
 
1531
	@Override
1532
	public Date getExpectedArrivalDate() {
1533
		return this.expectedArrivalDate.getValue();
1534
	}
1535
	@UiHandler("comingSoonButton")
1536
	void onComingSoonButtonClick(ClickEvent event) {
1537
		ComingSoonDialog cd = new ComingSoonDialog(this);
1538
		cd.show();
1539
	}
1961 ankur.sing 1540
}