Subversion Repositories SmartDukaan

Rev

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