Subversion Repositories SmartDukaan

Rev

Rev 4762 | Rev 5119 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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