Subversion Repositories SmartDukaan

Rev

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