Subversion Repositories SmartDukaan

Rev

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