Subversion Repositories SmartDukaan

Rev

Rev 4583 | Rev 4762 | 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;
95
    @UiField TextBox productGroup, brand, modelNumber, modelName, color;
2105 ankur.sing 96
    @UiField Label contentCategory, catalogItemId;
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());
848
        newItem.setVendorCategory(item.getVendorCategory());
2066 ankur.sing 849
        newItem.setProductGroup(productGroup.getText().trim());
850
        newItem.setBrand(brand.getText().trim());
851
        newItem.setModelNumber(modelNumber.getText().trim());
852
        newItem.setModelName(modelName.getText().trim());
853
        newItem.setColor(color.getText().trim());
2119 ankur.sing 854
        newItem.setContentCategory(contentCategory.getText());
2066 ankur.sing 855
        newItem.setComments(comments.getText().trim());
856
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
2126 ankur.sing 857
 
2068 ankur.sing 858
        try {
2126 ankur.sing 859
            if(!mrp.getText().trim().isEmpty()) {
860
                double mrpValue = Double.parseDouble(mrp.getText().trim());
861
                if(mrpValue <= 0) {
862
                    throw new NumberFormatException("Negative value of MRP");
863
                }
864
                newItem.setMrp(mrpValue);
865
            }
2068 ankur.sing 866
        } catch(NumberFormatException ex) {
2126 ankur.sing 867
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
868
            return false;
2068 ankur.sing 869
        }
870
        try {
2126 ankur.sing 871
            if(!sellingPrice.getText().trim().isEmpty()) {
872
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
873
            if(spValue <= 0) {
874
                throw new NumberFormatException("Negative value of Selling price");
875
            }
876
            newItem.setSellingPrice(spValue);
877
            }
878
        } catch(NumberFormatException ex) {
879
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
880
            return false;
2068 ankur.sing 881
        }
882
        try {
2126 ankur.sing 883
            if(!weight.getText().trim().isEmpty()) {
884
                double wtValue = Double.parseDouble(weight.getText().trim());
885
                if(wtValue <= 0) {
886
                    throw new NumberFormatException("Negative value of Weight");
887
                }
888
                newItem.setWeight(wtValue);
889
            }
2068 ankur.sing 890
        } catch(NumberFormatException ex) {
2126 ankur.sing 891
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
892
            return false;
2068 ankur.sing 893
        }
2126 ankur.sing 894
        try {
895
            if(!startDate.getTextBox().getText().trim().equals("")) {
896
                newItem.setStartDate(startDate.getValue().getTime());
897
            }
898
        } catch(Exception ex) {
899
            Window.alert("Invalid start date format");
900
            return false;
901
        }
2066 ankur.sing 902
        newItem.setBestDealsText(bestDealsText.getText().trim());
2068 ankur.sing 903
        try {
2126 ankur.sing 904
            if(!bestDealsValue.getText().trim().equals("")) {
905
                double bdValue = Double.parseDouble(bestDealsValue.getText().trim());
906
                if(bdValue < 0) {
907
                    throw new NumberFormatException("Negative value of BestDealValue");
908
                }
909
                newItem.setBestDealsValue(bdValue);
910
            }
2068 ankur.sing 911
        } catch(NumberFormatException ex) {
2126 ankur.sing 912
            Window.alert("Invalid best deal value format");
913
            return false;
2068 ankur.sing 914
        }
3363 chandransh 915
 
2068 ankur.sing 916
        try {
2126 ankur.sing 917
            if(!bestSellingRank.getText().trim().equals("")) {
918
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
919
                if(bsrValue < 0) {
920
                    throw new NumberFormatException("Negative value of Best Selling Rank");
921
                }
922
                newItem.setBestSellingRank(bsrValue);
923
            }
924
        } catch(NumberFormatException ex) {
925
            Window.alert("Invalid best selling rank format");
926
            return false;
2068 ankur.sing 927
        }
2066 ankur.sing 928
        newItem.setDefaultForEntity(defaultForEntity.getValue());
2252 ankur.sing 929
        newItem.setRisky(risky.getValue());
2119 ankur.sing 930
 
3363 chandransh 931
        try {
932
            String expectedDelayText = expectedDelay.getText().trim();
933
            if(!expectedDelayText.equals("")){
934
                newItem.setExpectedDelay(Integer.parseInt(expectedDelayText));
935
            }
936
        } catch(NumberFormatException nfe) {
937
            Window.alert("Invalid expected delay");
938
            return false;
939
        }
940
 
941
        try {
942
            String preferredWarehouseText = preferredWarehouse.getText().trim();
943
            if(!preferredWarehouseText.equals("")){
944
                newItem.setPreferredWarehouse(Long.parseLong(preferredWarehouseText) + "");
945
            }
946
        }catch(NumberFormatException nfe){
947
            Window.alert("Invalid Preferred Warehouse");
948
            return false;
949
        }
950
 
4413 anupam.sin 951
        try {
952
            String defaultWarehouseText = defaultWarehouse.getText().trim();
953
            if(!defaultWarehouseText.equals("")){
954
                newItem.setDefaultWarehouse(Long.parseLong(defaultWarehouseText) + "");
955
            }
956
        }catch(NumberFormatException nfe){
957
            Window.alert("Invalid Default Warehouse");
958
            return false;
959
        }
960
 
4583 phani.kuma 961
        if((item.getPreferredVendor() == null || item.getVendorPricesMap() == null || item.getVendorPricesMap().isEmpty()) && preferredVendor.getSelectedIndex() == 0) {
962
        	newItem.setPreferredVendor(item.getPreferredVendor());
963
        }
964
    	else {
4506 phani.kuma 965
    		long vendorId = Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex()));
966
            newItem.setPreferredVendor(vendorId);
967
    	}
968
 
4413 anupam.sin 969
        newItem.setWarehouseStickiness(warehouseStickiness.getValue());
970
 
2126 ankur.sing 971
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
972
          Add the instance to map and set the map to the item instance created above.*/
973
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
2119 ankur.sing 974
        VendorPricings v;
2427 ankur.sing 975
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
2119 ankur.sing 976
            v = new VendorPricings();
2427 ankur.sing 977
            v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));
978
            v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));
979
            v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));
980
            v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));
2126 ankur.sing 981
            vendorPrices.put(v.getVendorId(), v);
2066 ankur.sing 982
        }
2126 ankur.sing 983
        newItem.setVendorPricesMap(vendorPrices);
2359 ankur.sing 984
        newItem.setItemStatusDesc(statusDesc.getText().trim());
2427 ankur.sing 985
 
2126 ankur.sing 986
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
987
        Add the instance to map and set the map to the item instance created above.*/
2359 ankur.sing 988
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
2126 ankur.sing 989
        VendorItemMapping vMapping;
2427 ankur.sing 990
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
2126 ankur.sing 991
            vMapping = new VendorItemMapping();
2427 ankur.sing 992
            vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));
993
            vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));
994
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);
2119 ankur.sing 995
        }
2359 ankur.sing 996
        newItem.setVendorKeysMap(vendorMappings);
2119 ankur.sing 997
 
3558 rajveer 998
        /*Create an instance of SourcePricings for each row in source pricing table. Set the source prices to the instance.
999
        Add the instance to map and set the map to the item instance created above.*/
1000
		  Map<Long, SourcePricings> sourcePrices = new HashMap<Long, SourcePricings>();
1001
		  SourcePricings s;
1002
		  for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1003
		      s = new SourcePricings();
1004
		      s.setMrp(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP)));
1005
		      s.setSellingPrice(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE)));
1006
		      s.setSourceId(Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID)));
1007
		      sourcePrices.put(s.getSourceId(), s);
1008
		  }
1009
		newItem.setSourcePricesMap(sourcePrices);
1010
 
2126 ankur.sing 1011
        newItem.setContentCategoryId(item.getContentCategoryId());
1012
        newItem.setFeatureId(item.getFeatureId());
1013
        newItem.setFeatureDescription(item.getFeatureDescription());
1014
        newItem.setAddedOn(item.getAddedOn());
1015
        newItem.setRetireDate(item.getRetireDate());
1016
        newItem.setUpdatedOn(item.getUpdatedOn());
1017
        newItem.setItemStatus(item.getItemStatus());
1018
        newItem.setOtherInfo(item.getOtherInfo());
4431 phani.kuma 1019
        newItem.setItemInventory(item.getItemInventory());
4423 phani.kuma 1020
        newItem.setSimilarItems(item.getSimilarItems());
2119 ankur.sing 1021
 
2126 ankur.sing 1022
        return true;
2066 ankur.sing 1023
    }
1024
 
2427 ankur.sing 1025
    /**
1026
     * This method is called when Edit button is clicked corresponding to a row in 
1027
     * vendor prices table. It will pop up a form to edit the vendor prices.
1028
     * @param vendorId
1029
     * @param row
1030
     */
1031
    private void editVendorPrices(final long vendorId, final int row) {
1032
        String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
1033
        String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
1034
        String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
2119 ankur.sing 1035
        VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);
2105 ankur.sing 1036
        pricesDialog.updateButton.setText("Update");
2119 ankur.sing 1037
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2066 ankur.sing 1038
            @Override
2119 ankur.sing 1039
            public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
1040
                if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 1041
                    return false;
1042
                }
2427 ankur.sing 1043
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
1044
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
1045
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
2105 ankur.sing 1046
                return true;
2066 ankur.sing 1047
            }
1048
        });
1049
        pricesDialog.show();
1050
    }
2119 ankur.sing 1051
 
2427 ankur.sing 1052
    /**
1053
     * This method is called when Edit button is clicked corresponding to a row in 
3558 rajveer 1054
     * vendor prices table. It will pop up a form to edit the vendor prices.
1055
     * @param vendorId
1056
     * @param row
1057
     */
1058
    private void editSourcePrices(final long sourceId, final int row) {
1059
        String mrp = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP);
1060
        String sellingPrice = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE);
1061
        SourcePricesDialog pricesDialog = new SourcePricesDialog(mrp, sellingPrice);
1062
        pricesDialog.updateButton.setText("Update");
1063
        pricesDialog.setSourcePriceUpdateListener(new SourcePricesDialog.SourcePriceUpdateListener() {
1064
            @Override
1065
            public boolean onUpdate(double mrp, double sellingPrice, long sourceId) {
1066
                if(!validateSourcePrices(mrp, sellingPrice)) {
1067
                    return false;
1068
                }
1069
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_MRP, mrp + "");
1070
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sellingPrice + "");
1071
                return true;
1072
            }
1073
        });
1074
        pricesDialog.show();
1075
    }
1076
 
1077
 
1078
    /**
1079
     * This method is called when Edit button is clicked corresponding to a row in 
2427 ankur.sing 1080
     * vendor item key table. It will pop up a form to edit the item key.
1081
     * @param vendorId
1082
     * @param row
1083
     */
1084
    private void editVendorKey(final long vendorId, final int row) {
1085
        String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2126 ankur.sing 1086
        VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
1087
                modelNumber.getText().trim(), color.getText().trim(), key);
2119 ankur.sing 1088
        mappingDialog.updateButton.setText("Update");
1089
        mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
1090
            @Override
1091
            public boolean onUpdate(String itemKey, long vendorId) {
1092
                if(itemKey == null || itemKey.equals("")) {
1093
                    Window.alert("Item key cannot be empty.");
1094
                    return false;
1095
                }
2427 ankur.sing 1096
                tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
2119 ankur.sing 1097
                return true;
1098
            }
1099
        });
1100
        mappingDialog.show();
1101
    }
2066 ankur.sing 1102
 
2427 ankur.sing 1103
    /**
1104
     * This method compares all the editable UI fields values with attributes in the item object.
1105
     * If they differ, the attribute name is appended to a string.
1106
     * @return String showing attributes which are changed by the user for confirmation.
1107
     *      <br>Empty string if nothing is changed.
1108
     */
2252 ankur.sing 1109
    private String isItemChanged() {
1110
        StringBuilder sb = new StringBuilder("");
2489 ankur.sing 1111
        if(!checkParameterIfEqual(productGroup.getText().trim(), item.getProductGroup())) {
2387 ankur.sing 1112
            sb.append("\n-Product Group");
2066 ankur.sing 1113
        }
2489 ankur.sing 1114
        if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
2387 ankur.sing 1115
            sb.append("\n-Brand");
2066 ankur.sing 1116
        }
2489 ankur.sing 1117
        if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
2387 ankur.sing 1118
            sb.append("\n-Model Number");
2066 ankur.sing 1119
        }
2489 ankur.sing 1120
        if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
2387 ankur.sing 1121
            sb.append("\n-Model Name");
2066 ankur.sing 1122
        }
2489 ankur.sing 1123
        if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
2387 ankur.sing 1124
            sb.append("\n-Color");
2066 ankur.sing 1125
        }
2489 ankur.sing 1126
        if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
2387 ankur.sing 1127
            sb.append("\n-Status Description");
2359 ankur.sing 1128
        }
2489 ankur.sing 1129
        if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
2387 ankur.sing 1130
            sb.append("\n-Comments");
2066 ankur.sing 1131
        }
2489 ankur.sing 1132
        if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
2387 ankur.sing 1133
            sb.append("\n-MRP");
2066 ankur.sing 1134
        }
2489 ankur.sing 1135
        if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
2387 ankur.sing 1136
            sb.append("\n-Selling Price");
2027 ankur.sing 1137
        }
2489 ankur.sing 1138
        if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
2387 ankur.sing 1139
            sb.append("\n-Weight");
2027 ankur.sing 1140
        }
2489 ankur.sing 1141
        if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
2387 ankur.sing 1142
            sb.append("\n-Best Deal Text");
2066 ankur.sing 1143
        }
2489 ankur.sing 1144
        if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
2387 ankur.sing 1145
            sb.append("\n-Best Deal Value");
2027 ankur.sing 1146
        }
2489 ankur.sing 1147
        if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
2387 ankur.sing 1148
            sb.append("\n-Best Selling Rank");
2066 ankur.sing 1149
        }
1150
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
2387 ankur.sing 1151
            sb.append("\n-Default For Entity Flag");
2066 ankur.sing 1152
        }
2252 ankur.sing 1153
        if(item.isRisky() != risky.getValue()) {
2387 ankur.sing 1154
            sb.append("\n-Risky Flag");
2252 ankur.sing 1155
        }
2489 ankur.sing 1156
        if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
2387 ankur.sing 1157
            sb.append("\n-Start Date");
2068 ankur.sing 1158
        }
3524 chandransh 1159
        if(!checkParameterIfEqual(newItem.getExpectedDelay(), item.getExpectedDelay())) {
3362 chandransh 1160
            sb.append("\n-Expected Delay");
1161
        }
3524 chandransh 1162
        if(!checkParameterIfEqual(newItem.getPreferredWarehouse(), item.getPreferredWarehouse())) {
3362 chandransh 1163
            sb.append("\n-Preferred Warehouse");
1164
        }
4413 anupam.sin 1165
        if(!checkParameterIfEqual(newItem.getDefaultWarehouse(), item.getDefaultWarehouse())) {
1166
            sb.append("\n-Default Warehouse");
1167
        }
1168
        if(item.isWarehouseStickiness() != warehouseStickiness.getValue()) {
1169
            sb.append("\n-Warehouse Stickiness Flag");
1170
        }
4506 phani.kuma 1171
        if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor())) {
1172
            sb.append("\n-Preferred Vendor");
1173
        }
3362 chandransh 1174
 
2126 ankur.sing 1175
        VendorPricings vendorPricings;
2066 ankur.sing 1176
        long vendorId;
2427 ankur.sing 1177
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
1178
            vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
2126 ankur.sing 1179
            vendorPricings = item.getVendorPricesMap().get(vendorId);
2359 ankur.sing 1180
            if(vendorPricings == null) {
2387 ankur.sing 1181
                sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
2359 ankur.sing 1182
                continue;
1183
            }
2427 ankur.sing 1184
            if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
2387 ankur.sing 1185
                sb.append("\n-MOP (Vendor:" + vendorId + ")");
2066 ankur.sing 1186
            }
2427 ankur.sing 1187
            if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
2387 ankur.sing 1188
                sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 1189
            }
2427 ankur.sing 1190
            if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
2387 ankur.sing 1191
                sb.append("\n-Transfer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 1192
            }
1193
        }
2387 ankur.sing 1194
 
3558 rajveer 1195
        SourcePricings sourcePricings;
1196
        long sourceId;
1197
        for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1198
            sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1199
            sourcePricings = item.getSourcePricesMap().get(sourceId);
1200
            if(sourcePricings == null) {
1201
                sb.append("\n-Source Prices (Source:" + sourceId + ")");
1202
                continue;
1203
            }
1204
            if(sourcePricings.getMrp() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP))) {
1205
                sb.append("\n-MRP (Source:" + sourceId + ")");
1206
            }
1207
            if(sourcePricings.getSellingPrice() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE))) {
1208
                sb.append("\n-Selling Price (Source:" + sourceId + ")");
1209
            }
1210
        }
1211
 
2387 ankur.sing 1212
        VendorItemMapping mapping;
1213
        String old_key, new_key;
2427 ankur.sing 1214
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
1215
            vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
1216
            old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
1217
            new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2387 ankur.sing 1218
            mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
1219
            if(mapping == null || !old_key.equals(new_key)) {
1220
                sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
1221
                continue;
1222
            }
1223
        }
2252 ankur.sing 1224
        return sb.toString();
2066 ankur.sing 1225
    }
1226
 
2566 chandransh 1227
    @SuppressWarnings("unused")
1228
	private boolean validatePrices() {
2066 ankur.sing 1229
        if(newItem.getSellingPrice() > newItem.getMrp()) {
1230
            Window.alert("Selling price cannot be more than MRP");
1231
            return false;
1232
        }
2119 ankur.sing 1233
        for(VendorPricings v : newItem.getVendorPricesMap().values()) {
2105 ankur.sing 1234
            if(newItem.getMrp() < v.getMop()) {
1235
                Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1236
                return false;
1237
            }
2105 ankur.sing 1238
            if(v.getTransferPrice() > v.getMop()) {
1239
                Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1240
                return false;
1241
            }
1242
        }
1243
        return true;
1244
    }
2105 ankur.sing 1245
 
2119 ankur.sing 1246
    private boolean validateVendorPrices(double mop, double dp, double tp) {
2489 ankur.sing 1247
        if(item.getMrp() != null && item.getMrp() < mop) {
2105 ankur.sing 1248
            Window.alert("MOP cannot be more than MRP.");
1249
            return false;
1992 ankur.sing 1250
        }
2105 ankur.sing 1251
        if(tp > mop) {
1252
            Window.alert("Transfer Price cannot be more than MOP.");
1253
            return false;
1992 ankur.sing 1254
        }
2105 ankur.sing 1255
        return true;
1992 ankur.sing 1256
    }
3558 rajveer 1257
 
1258
    private boolean validateSourcePrices(double mrp, double sellingPrice) {
1259
        if(sellingPrice > mrp) {
1260
            Window.alert("Selling Price cannot be more than MRP.");
1261
            return false;
1262
        }
1263
        return true;
1264
    }
1265
 
2105 ankur.sing 1266
 
1267
    public long getItemId() {
1268
        return item == null ? 0 : item.getId();
1269
    }
1270
 
1271
    public Item getItem() {
1272
        return item;
1273
    }
1274
 
2427 ankur.sing 1275
    /**
1276
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
1277
     * @param vendorId
1278
     * @return true if parameter vendor Id is already added to vendor prices table.
1279
     *      <br>else false
1280
     */
2105 ankur.sing 1281
    private boolean vendorExists(long vendorId) {
1282
        long id;
2427 ankur.sing 1283
        for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
1284
            id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
2105 ankur.sing 1285
            if(vendorId == id) {
1286
                return false;
1287
            }
1992 ankur.sing 1288
        }
2105 ankur.sing 1289
        return true;
1992 ankur.sing 1290
    }
2387 ankur.sing 1291
 
2427 ankur.sing 1292
    /**
3558 rajveer 1293
     * This method is used while adding source prices to ensure that there is only one row in the table for a source.
1294
     * @param sourceId
1295
     * @return true if parameter vendor Id is already added to source prices table.
1296
     *      <br>else false
1297
     */
1298
    private boolean sourceExists(long sourceId) {
1299
        long id;
1300
        for(int i = 0; i < tableSourcePrices.getRowCount(); i++) {
1301
            id = Long.parseLong(tableSourcePrices.getText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1302
            if(sourceId == id) {
1303
                return false;
1304
            }
1305
        }
1306
        return true;
1307
    }
1308
 
1309
    /**
2427 ankur.sing 1310
     * This method is used to check if any of the string item attributes is changed by the user.
2489 ankur.sing 1311
     * @param o1
1312
     * @param o2
2427 ankur.sing 1313
     * @return true if two strings are equal
1314
     *      <br>true if one of them is null and another is empty.
1315
     *      <br>false otherwise
1316
     */
2489 ankur.sing 1317
    private boolean checkParameterIfEqual(Object o1, Object o2) {
1318
        if(o1 == o2) {
2387 ankur.sing 1319
            return true;
1320
        }
2489 ankur.sing 1321
        if(o1 != null && o2 != null && o1.equals(o2)) {
2387 ankur.sing 1322
            return true;
1323
        }
2489 ankur.sing 1324
        if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
2387 ankur.sing 1325
            return true;
1326
        }
1327
        return false;
1328
    }
2489 ankur.sing 1329
 
1330
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
1331
        this.catalogDashboardPanel = catalogDashboardPanel;
1332
    }
4649 phani.kuma 1333
 
1334
    private String compareSellingPricewithBreakEven() {
1335
    	String message = "false";
1336
    	if(newItem.getWeight() == null) {
1337
    		Window.alert("Weight is empty.");
1338
            return message;
1339
    	}
1340
    	if(newItem.getSellingPrice() == null) {
1341
    		Window.alert("Selling Price is empty.");
1342
            return message;
1343
    	}
1344
 
1345
    	double transferPrice;
1346
    	if(newItem.getPreferredVendor() == null && !newItem.getVendorPricesMap().isEmpty()) {
1347
    		transferPrice = -1;
1348
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1349
				if(transferPrice > vendorDetail.getTransferPrice() || transferPrice == -1){
1350
					transferPrice = vendorDetail.getTransferPrice();
1351
				}
1352
			}
1353
    	}
1354
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1355
    		transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();    		
1356
    	}
1357
    	else{
1358
    		Window.alert("Add vendor to Vendor Prices and then change the Selling Price.");
1359
            return message;
1360
    	}
1361
 
1362
    	double weightfactor = Math.ceil((newItem.getWeight() * 1000)/Double.parseDouble(ConfigMap.get("courier_weight_factor")));
1363
		double couriercost = Double.parseDouble(ConfigMap.get("courier_cost_factor")) * weightfactor;
1364
		double costfactor = (Double.parseDouble(ConfigMap.get("transfer_price_percentage")) * transferPrice)/100;
1365
		double breakeven;
1366
		if(costfactor < Double.parseDouble(ConfigMap.get("transfer_price_factor"))){
1367
			breakeven = transferPrice + couriercost + Double.parseDouble(ConfigMap.get("breakeven_additon_factor"));
1368
		}
1369
		else{
1370
			breakeven = (transferPrice + couriercost)/Double.parseDouble(ConfigMap.get("breakeven_divisor"));
1371
		}
1372
 
1373
		if(breakeven > newItem.getSellingPrice()) {
1374
			message = "Selling Price("+newItem.getSellingPrice()+") is less than Breakeven Price("+breakeven+").";
1375
			if(Window.confirm(message)){
1376
				return message;
1377
			}
1378
			else{
1379
				message = "false";
1380
				Window.alert("Updation of Item is canceled.");
1381
				return message;
1382
			}
1383
		}
1384
		else {
1385
			message = "true";
1386
	        return message;
1387
		}
1388
    }
1389
 
1390
    private String checkTransferPriceforPreferredVendor() {
1391
    	String message = "false";
1392
    	if(newItem.getPreferredVendor() == null) {
1393
    		message = "true";
1394
    		return message;
1395
    	}
1396
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1397
    		double transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();
1398
        	double mintransferPrice = -1;
1399
        	String minvendor = "";
1400
        	boolean compareTransferPrices = false;
1401
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1402
				if(mintransferPrice > vendorDetail.getTransferPrice() || mintransferPrice == -1){
1403
					mintransferPrice = vendorDetail.getTransferPrice();
1404
					minvendor = Utils.getVendorDesc(vendorDetail.getVendorId());
1405
				}
1406
			}
1407
			if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor()) || item.getVendorPricesMap().isEmpty()) {
1408
				compareTransferPrices = true;
1409
			}
1410
			else {
1411
				double oldmintransferPrice = -1;
1412
				for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
1413
					if(oldmintransferPrice > vendorDetail.getTransferPrice() || oldmintransferPrice == -1){
1414
						oldmintransferPrice = vendorDetail.getTransferPrice();
1415
					}
1416
				}
1417
				if(mintransferPrice < oldmintransferPrice){
1418
					compareTransferPrices = true;
1419
				}
1420
			}
1421
			if(compareTransferPrices && transferPrice > mintransferPrice){
1422
				message = "Transfer Price("+transferPrice+") of Preferred Vendor("+Utils.getVendorDesc(newItem.getPreferredVendor())+") is more than Transfer Price("+mintransferPrice+") of "+minvendor+".";
1423
				if(Window.confirm(message)){
1424
					return message;
1425
				}
1426
				else{
1427
					message = "false";
1428
					Window.alert("Updation of Item is canceled.");
1429
					return message;
1430
				}
1431
			}
1432
			else {
1433
				message = "true";
1434
		        return message;
1435
			}
1436
    	}
1437
    	else{
1438
    		Window.alert("Add vendor to Vendor Prices and then change the Preferred Vendor.");
1439
            return message;
1440
    	}
1441
    }
1442
 
1443
    public void logAuthorization(String message) {
1444
    	String username = catalogDashboardPanel.uname;
1445
    	catalogService.addAuthorizationLog(newItem.getId(), username, message, new AsyncCallback<Boolean>() {
1446
            @Override
1447
            public void onSuccess(Boolean result) {
1448
                if(result) {
1449
                    GWT.log("Event is added");
1450
                }
1451
                else {
1452
                    GWT.log("Error adding the event");
1453
                    Window.alert("Error adding the event");
1454
                }
1455
            }
1456
            @Override
1457
            public void onFailure(Throwable caught) {
1458
                caught.printStackTrace();
1459
                Window.alert("Error while adding the event");
1460
            }
1461
        });
1462
    }
1961 ankur.sing 1463
}