Subversion Repositories SmartDukaan

Rev

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