Subversion Repositories SmartDukaan

Rev

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

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