Subversion Repositories SmartDukaan

Rev

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