Subversion Repositories SmartDukaan

Rev

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