Subversion Repositories SmartDukaan

Rev

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