Subversion Repositories SmartDukaan

Rev

Rev 6899 | Rev 7190 | 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;
6530 vikram.rag 5
import in.shop2020.catalog.dashboard.shared.ItemWarehouse;
3558 rajveer 6
import in.shop2020.catalog.dashboard.shared.SourcePricings;
2066 ankur.sing 7
import in.shop2020.catalog.dashboard.shared.Utils;
2119 ankur.sing 8
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
9
import in.shop2020.catalog.dashboard.shared.VendorPricings;
5504 phani.kuma 10
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
1961 ankur.sing 11
 
5427 amit.gupta 12
import java.util.ArrayList;
1961 ankur.sing 13
import java.util.Date;
2066 ankur.sing 14
import java.util.HashMap;
5427 amit.gupta 15
import java.util.Iterator;
16
import java.util.List;
1992 ankur.sing 17
import java.util.Map;
18
import java.util.Map.Entry;
1961 ankur.sing 19
 
20
import com.google.gwt.core.client.GWT;
5427 amit.gupta 21
import com.google.gwt.dom.client.Style.Unit;
1961 ankur.sing 22
import com.google.gwt.event.dom.client.ClickEvent;
1992 ankur.sing 23
import com.google.gwt.event.dom.client.ClickHandler;
24
import com.google.gwt.resources.client.CssResource;
1961 ankur.sing 25
import com.google.gwt.uibinder.client.UiBinder;
26
import com.google.gwt.uibinder.client.UiField;
5427 amit.gupta 27
import com.google.gwt.uibinder.client.UiHandler;
1961 ankur.sing 28
import com.google.gwt.user.client.Window;
2126 ankur.sing 29
import com.google.gwt.user.client.rpc.AsyncCallback;
1961 ankur.sing 30
import com.google.gwt.user.client.ui.Button;
2066 ankur.sing 31
import com.google.gwt.user.client.ui.CheckBox;
5427 amit.gupta 32
import com.google.gwt.user.client.ui.DialogBox;
1992 ankur.sing 33
import com.google.gwt.user.client.ui.FlexTable;
34
import com.google.gwt.user.client.ui.HTMLTable.Cell;
1961 ankur.sing 35
import com.google.gwt.user.client.ui.Label;
4506 phani.kuma 36
import com.google.gwt.user.client.ui.ListBox;
1961 ankur.sing 37
import com.google.gwt.user.client.ui.ResizeComposite;
38
import com.google.gwt.user.client.ui.TextBox;
5427 amit.gupta 39
import com.google.gwt.user.client.ui.VerticalPanel;
1961 ankur.sing 40
import com.google.gwt.user.client.ui.Widget;
2068 ankur.sing 41
import com.google.gwt.user.datepicker.client.DateBox;
1961 ankur.sing 42
 
2427 ankur.sing 43
/**
44
 * Panel contains fields for item details. Some of these fields are editable.
45
 * It also contains vendor item pricings, vendor item keys, and item availability in tabular format.
46
 * Item availability is made invisible for time being 
47
 */
5217 amit.gupta 48
public class ItemDetails extends ResizeComposite implements ComingSoon {
1961 ankur.sing 49
 
2359 ankur.sing 50
    private final int TABLE_INDEX_MAPPING_VENDOR_DESC = 0, 
51
                      TABLE_INDEX_MAPPING_ITEM_KEY = 1,
52
                      TABLE_INDEX_MAPPING_BUTTON = 2,
53
                      TABLE_INDEX_MAPPING_VENDORID = 3, 
54
                      TABLE_INDEX_MAPPING_ITEM_KEY_OLD = 4;
55
 
56
    private final int TABLE_INDEX_PRICING_VENDOR_DESC = 0, 
3558 rajveer 57
    				  TABLE_INDEX_PRICING_MOP = 1,
2359 ankur.sing 58
                      TABLE_INDEX_PRICING_DP = 2,
59
                      TABLE_INDEX_PRICING_TP = 3,
6759 amar.kumar 60
                      TABLE_INDEX_PRICING_NLC = 4,
61
                      TABLE_INDEX_PRICING_BUTTON = 5,
62
                      TABLE_INDEX_PRICING_VENDORID = 6;
3558 rajveer 63
 
64
    private final int TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC = 0, 
65
    				  TABLE_INDEX_SOURCE_PRICING_MRP = 1,
66
    				  TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE = 2,
67
    				  TABLE_INDEX_SOURCE_PRICING_BUTTON = 3,
68
    				  TABLE_INDEX_SOURCE_PRICING_SOURCE_ID = 4;
69
 
2119 ankur.sing 70
    private final int TABLE_INDEX_WAREHOUSE_ID = 0,
71
                      TABLE_INDEX_WAREHOUSE_DESC = 1,
4431 phani.kuma 72
                      TABLE_INDEX_WAREHOUSE_INVA = 2,
73
                      TABLE_INDEX_WAREHOUSE_INVR = 3,
74
                      TABLE_INDEX_WAREHOUSE_GET_BUTTON = 4,
75
                      TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON = 5;
2359 ankur.sing 76
 
6530 vikram.rag 77
    private final int TABLE_INDEX_WAREHOUSE_NAME = 0,
78
    				  TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON = 1;    
79
 
4423 phani.kuma 80
    private final int TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID = 0,
81
                      TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP = 1,
82
                      TABLE_INDEX_SIMILAR_ITEMS_BRAND = 2,
83
                      TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER = 3,
84
                      TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME = 4,
85
                      TABLE_INDEX_SIMILAR_ITEMS_CATEGORY = 5,
86
                      TABLE_INDEX_SIMILAR_ITEMS_BUTTON = 6;
87
 
5504 phani.kuma 88
    private final int TABLE_INDEX_VOUCHERS_TYPE = 0,
89
                      TABLE_INDEX_VOUCHERS_AMOUNT = 1,
90
                      TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON = 2,
91
                      TABLE_INDEX_VOUCHERS_DEL_BUTTON = 3;
92
 
5427 amit.gupta 93
    private final String MANDATORY_MRP = "MRP",
94
					  MANDATORY_WEIGHT = "Weight",
95
					  MANDATORY_BEST_DEAL_TEXT = "Best Deal Text",
6777 vikram.rag 96
					  MANDATORY_BEST_DEAL_DETAIL_TEXT = "Best Deal Detail Text",
97
					  MANDATORY_BEST_DEAL_DETAIL_LINK = "Best Deal Detail Link",
5427 amit.gupta 98
					  MANDATORY_BRAND = "Brand",
99
					  MANDATORY_MODEL_NO = "Model Number",
100
					  MANDATORY_MODEL_NAME = "Model Name";
101
 
102
    private final String OPTIONAL_SELLING_PRICE = "Selling Price",	
103
    				  OPTIONAL_VENDOR_PRICING = "Vendor Pricing",
104
    				  OPTIONAL_PREFERRED_VENDOR = "Preferred Vendor",
6838 vikram.rag 105
    				  OPTIONAL_PREFERRED_INSURER = "Preferred Insurer",
5427 amit.gupta 106
    				  OPTIONAL_SOURCE_PRICING = "Source Pricing";
107
 
2359 ankur.sing 108
    private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",
109
                         VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",
110
                         BUTTON_WIDTH = "50px";
2066 ankur.sing 111
 
4649 phani.kuma 112
    private Map<String, String> ConfigMap;
2066 ankur.sing 113
    interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
114
    private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
2126 ankur.sing 115
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
5427 amit.gupta 116
    Map<String, Object> mandatoryChangedValMap;
117
    Map<String, Object> optionalChangedValMap;
2066 ankur.sing 118
 
1961 ankur.sing 119
 
2066 ankur.sing 120
    interface ItemDetailStyle extends CssResource{
121
        String greenLabel();
122
        String fieldChanged();
123
    }
1961 ankur.sing 124
 
2105 ankur.sing 125
    private Item item, newItem;
2489 ankur.sing 126
    private CatalogDashboard catalogDashboardPanel;
2066 ankur.sing 127
 
128
    @UiField ItemDetailStyle style;
129
    @UiField Label itemId;
4762 phani.kuma 130
    @UiField TextBox brand, modelNumber, modelName, color;
131
    @UiField Label contentCategory, catalogItemId, productGroup;
2359 ankur.sing 132
    @UiField TextBox statusDesc, comments;
2105 ankur.sing 133
    @UiField TextBox sellingPrice, mrp, weight;
134
    @UiField Label addedOn, retireDate, updatedOn;
2066 ankur.sing 135
    @UiField Label itemStatus;
6777 vikram.rag 136
    @UiField TextBox bestDealsText, bestDealsValue ,bestDealsDetailsText,bestDealsDetailsLink; 
2066 ankur.sing 137
    @UiField FlexTable headerAvailability, availabilityTable;
2427 ankur.sing 138
    @UiField FlexTable headerVendorItemKey, tableVendorItemKey;
139
    @UiField FlexTable headerVendorPrices, tableVendorPrices;
3558 rajveer 140
    @UiField FlexTable headerSourcePrices, tableSourcePrices;
2066 ankur.sing 141
    @UiField TextBox bestSellingRank;
3359 chandransh 142
    @UiField TextBox expectedDelay;
6241 amit.gupta 143
    @UiField CheckBox defaultForEntity, risky, warehouseStickiness, itemType, hasItemNo, clearance, showSellingPrice;
5217 amit.gupta 144
    @UiField DateBox startDate, expectedArrivalDate, comingSoonStartDate;
4423 phani.kuma 145
    @UiField FlexTable headerSimilarItems, tableSimilarItems;
6838 vikram.rag 146
    @UiField ListBox preferredVendor,preferredInsurer;
5217 amit.gupta 147
    @UiField Button comingSoonButton;
5504 phani.kuma 148
    @UiField FlexTable headerVouchers, tableVouchers;
6530 vikram.rag 149
    @UiField FlexTable headerIgnoredWarehouse,tableIgnoredWarehouse;
6813 amar.kumar 150
    @UiField TextBox minStockLevel, numOfDaysStock;
2066 ankur.sing 151
 
152
    public ItemDetails(Item item){
2105 ankur.sing 153
        this();
2066 ankur.sing 154
        setItemDetails(item);
155
    }
156
 
157
    public ItemDetails() {
158
        initWidget(uiBinder.createAndBindUi(this));
159
        initAvailabilityHeader();
2427 ankur.sing 160
        initVendorKeysHeader();
161
        initVendorPricingHeader();
3558 rajveer 162
        initSourcePricingHeader();
4423 phani.kuma 163
        initSimilarItemList();
5504 phani.kuma 164
        initVoucherHeader();
6530 vikram.rag 165
        initIgnoredWarehouseHeader();
4506 phani.kuma 166
        preferredVendor.addItem("null");
6838 vikram.rag 167
        preferredInsurer.addItem("null");
4649 phani.kuma 168
        getConfigdataforPriceCompare();
2066 ankur.sing 169
    }
170
 
4649 phani.kuma 171
    public void getConfigdataforPriceCompare(){
172
    	catalogService.getConfigdataforPriceCompare(new AsyncCallback<Map<String,String>>() {
173
            @Override
174
            public void onSuccess(Map<String, String> result) {
175
            	ConfigMap = result;
176
            }
177
            @Override
178
            public void onFailure(Throwable caught) {
179
                caught.printStackTrace();
180
            }
181
        });
182
    }
183
 
2427 ankur.sing 184
    /**
185
     * Sets the UI fields with item object attributes
186
     * Also populates tables for vendor prices, keys and item availability
187
     * @param item
188
     */
2066 ankur.sing 189
    public void setItemDetails(Item item){
190
        this.item = item;
191
        itemId.setText(item.getId()+"");
192
        productGroup.setText(item.getProductGroup());
193
        brand.setText(item.getBrand());
194
        modelNumber.setText(item.getModelNumber());
195
        modelName.setText(item.getModelName());
196
        color.setText(item.getColor());
197
 
2359 ankur.sing 198
        statusDesc.setText(item.getItemStatusDesc());
2105 ankur.sing 199
        contentCategory.setText(item.getContentCategory()+"");
2066 ankur.sing 200
        comments.setText(item.getComments());
201
        catalogItemId.setText(item.getCatalogItemId() + "");
6838 vikram.rag 202
        preferredInsurer.clear();
4583 phani.kuma 203
        preferredVendor.clear();
204
        int index = -1;
205
        if (item.getPreferredVendor() == null) {
206
        	index++;
207
        	preferredVendor.addItem("null");
208
        }
209
 
210
        if((item.getVendorPricesMap() == null || item.getVendorPricesMap().isEmpty())) {
211
        	if(item.getPreferredVendor() != null) {
212
        		index++;
213
        		preferredVendor.addItem(Utils.getVendorDesc(item.getPreferredVendor()));
214
        	}
215
        }
216
        else {
217
        	for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
218
        		index++;
219
        		preferredVendor.addItem(Utils.getVendorDesc(vendorDetail.getVendorId()));
220
        		if(item.getPreferredVendor() != null && item.getPreferredVendor() == vendorDetail.getVendorId()) {
4506 phani.kuma 221
	        		preferredVendor.setSelectedIndex(index);
222
	        	}
4583 phani.kuma 223
        	}
224
 
225
        	if(item.getPreferredVendor() != null && !item.getVendorPricesMap().containsKey(item.getPreferredVendor())){
226
        		index++;
227
            	preferredVendor.addItem(Utils.getVendorDesc(item.getPreferredVendor()));
228
            	preferredVendor.setSelectedIndex(index);
229
        	}
4506 phani.kuma 230
        }
6899 vikram.rag 231
        index=0;
232
        preferredInsurer.addItem("null","0");
233
        preferredInsurer.setSelectedIndex(0);
6838 vikram.rag 234
    	for (Map.Entry<Long, String> entry : Utils.getAllInsurers().entrySet()){
235
    		index++;
236
    		preferredInsurer.addItem(entry.getValue(),entry.getKey().toString());
237
    		if(item.getPreferredInsurer()==entry.getKey()){
238
    			preferredInsurer.setSelectedIndex(index);  
239
    		}
240
    	}
5384 phani.kuma 241
 
2489 ankur.sing 242
        mrp.setText(item.getMrp() != null ? item.getMrp()+"" : "");
243
        sellingPrice.setText(item.getSellingPrice() != null ? item.getSellingPrice()+"" : "");
244
        weight.setText(item.getWeight() != null ? item.getWeight()+"" : "");
3359 chandransh 245
        expectedDelay.setValue(item.getExpectedDelay()+"");
4413 anupam.sin 246
        warehouseStickiness.setValue(item.isWarehouseStickiness());
2068 ankur.sing 247
 
5384 phani.kuma 248
        hasItemNo.setValue(item.isHasItemNo());
249
        itemType.setValue(item.isItemType());
5460 phani.kuma 250
        clearance.setValue(item.isClearance());
6241 amit.gupta 251
        showSellingPrice.setValue(item.isShowSellingPrice());
5384 phani.kuma 252
 
2068 ankur.sing 253
        startDate.setValue(new Date(item.getStartDate()));
5217 amit.gupta 254
        if(item.getComingSoonStartDate() != null){
255
        	comingSoonStartDate.setValue(new Date(item.getComingSoonStartDate()));
256
        }else {
257
        	comingSoonStartDate.setValue(null);
258
        }
259
 
260
        if(item.getExpectedArrivalDate() != null){
261
        	expectedArrivalDate.setValue(new Date(item.getExpectedArrivalDate()));
262
        }else {
263
        	expectedArrivalDate.setValue(null);
264
        }
2068 ankur.sing 265
        addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
266
        retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
267
        updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
1992 ankur.sing 268
 
2066 ankur.sing 269
        bestDealsText.setText(item.getBestDealsText());
6777 vikram.rag 270
        bestDealsDetailsText.setText(item.getBestDealsDetailsText());
271
        bestDealsDetailsLink.setText(item.getBestDealsDetailsLink());
2489 ankur.sing 272
        bestDealsValue.setText(item.getBestDealsValue() != null ? item.getBestDealsValue()+"" : "");
273
        bestSellingRank.setText(item.getBestSellingRank() != null ? item.getBestSellingRank()+"" : "");
6813 amar.kumar 274
        minStockLevel.setText(item.getMinStockLevel() != null ? item.getMinStockLevel()+"" : "");
275
        numOfDaysStock.setText(item.getNumOfDaysStock() != null ? item.getNumOfDaysStock()+"" : "");
2066 ankur.sing 276
        defaultForEntity.setValue(item.isDefaultForEntity());
2252 ankur.sing 277
        risky.setValue(item.isRisky());
1992 ankur.sing 278
 
2066 ankur.sing 279
        itemStatus.setText(item.getItemStatus());
280
 
4431 phani.kuma 281
        updateAvailabilityTable(item.getItemInventory());
2427 ankur.sing 282
        updateVendorKeysTable(item.getVendorKeysMap());
283
        updateVendorPricingTable(item.getVendorPricesMap());
3558 rajveer 284
        updateSourcePricingTable(item.getSourcePricesMap());
4423 phani.kuma 285
        updateSimilarItemsTable(item.getSimilarItems());
5504 phani.kuma 286
        updateVoucherTable(item.getVouchersMap());
6530 vikram.rag 287
        updateTableIgnoredWarehouse();
1992 ankur.sing 288
    }
2066 ankur.sing 289
 
2427 ankur.sing 290
    /**
291
     * initialise item availability table header.
292
     */
2066 ankur.sing 293
    private void initAvailabilityHeader(){
4431 phani.kuma 294
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "100px");
2105 ankur.sing 295
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
4431 phani.kuma 296
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVA, "100px");
297
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVR, "100px");
298
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_GET_BUTTON, "100px");
299
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, "100px");
2066 ankur.sing 300
 
301
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");
302
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");
4431 phani.kuma 303
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INVA, "Availability");
304
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INVR, "Reserved");
305
 
306
        Button getLiveDataButton = new Button("Get Live Data");
307
        headerAvailability.setWidget(0, TABLE_INDEX_WAREHOUSE_GET_BUTTON, getLiveDataButton);
308
        getLiveDataButton.addClickHandler(new ClickHandler() {
309
            @Override
310
            public void onClick(ClickEvent event) {
311
            	catalogService.getProdItemInventory(item.getId(), new AsyncCallback<Map<Long, ItemInventory>>() {
312
                    @Override
313
                    public void onSuccess(Map<Long, ItemInventory> itemInventoryMap) {
314
                        if(itemInventoryMap != null) {
315
                            GWT.log("Inventory Data fetched");
316
                            item.setItemInventory(itemInventoryMap);
317
                            updateAvailabilityTable(item.getItemInventory());
318
                        }
319
                        else {
320
                            GWT.log("Error fetching Inventory Data");
321
                            Window.alert("Error fetching Inventory Data");
322
                        }
323
                    }
324
                    @Override
325
                    public void onFailure(Throwable caught) {
326
                        caught.printStackTrace();
327
                        Window.alert("Error fetching Inventory Data");
328
                    }
329
                });
330
            }
331
        });
332
 
333
        Button updateLiveDataButton = new Button("Update Live Data");
334
        headerAvailability.setWidget(0, TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, updateLiveDataButton);
335
        /* code to be rewritten later
336
        updateLiveDataButton.addClickHandler(new ClickHandler() {
337
            @Override
338
            public void onClick(ClickEvent event) {
339
            	catalogService.getProdItemInventory(item.getId(), new AsyncCallback<Map<Long, ItemInventory>>() {
340
                    @Override
341
                    public void onSuccess(Map<Long, ItemInventory> itemInventoryMap) {
342
                        if(itemInventoryMap != null) {
343
                            GWT.log("Inventory Data fetched");
344
                            item.setItemInventory(itemInventoryMap);
345
                            updateAvailabilityTable(item.getItemInventory());
346
                        }
347
                        else {
348
                            GWT.log("Error fetching Inventory Data");
349
                            Window.alert("Error fetching Inventory Data");
350
                        }
351
                    }
352
                    @Override
353
                    public void onFailure(Throwable caught) {
354
                        caught.printStackTrace();
355
                        Window.alert("Error fetching Inventory Data");
356
                    }
357
                });
358
            }
359
        });
360
        */
361
        headerAvailability.getCellFormatter().setVisible(0, TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, false);
1992 ankur.sing 362
 
363
    }
2066 ankur.sing 364
 
2427 ankur.sing 365
    /**
366
     * initialises vendor item key table header. Creates an Add button and
367
     * adds click event listener to it to create and pop up a dialog for adding 
368
     * a new vendor item key. 
369
     */
370
    private void initVendorKeysHeader(){
371
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
372
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
373
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
374
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
375
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2119 ankur.sing 376
 
2427 ankur.sing 377
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDORID, "Vendor Id");
378
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDOR_DESC, "Vendor");
379
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY, "Item Key");
380
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, "Prev Item Key");
2119 ankur.sing 381
 
2427 ankur.sing 382
        headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_VENDORID, false);
383
        headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2359 ankur.sing 384
 
2119 ankur.sing 385
        Button addButton = new Button("Add");
2427 ankur.sing 386
        headerVendorItemKey.setWidget(0, TABLE_INDEX_MAPPING_BUTTON, addButton);
2119 ankur.sing 387
        addButton.addClickHandler(new ClickHandler() {
388
            @Override
389
            public void onClick(ClickEvent event) {
2126 ankur.sing 390
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
391
                        modelNumber.getText().trim(), color.getText().trim());
2119 ankur.sing 392
                vendorMappingDialog.updateButton.setText("Add");
393
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
394
                    @Override
395
                    public boolean onUpdate(String key, long vendorId) {
2427 ankur.sing 396
                        int row = tableVendorItemKey.getRowCount();
397
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
398
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
399
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
400
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
2119 ankur.sing 401
 
2427 ankur.sing 402
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDORID, vendorId + "");
403
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
404
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, key);
405
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, key);
2359 ankur.sing 406
 
2427 ankur.sing 407
                        tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_VENDORID, false);
408
                        tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2119 ankur.sing 409
                        return true;
410
                    }
411
                });
412
                vendorMappingDialog.show();
413
            }
414
        });
415
    }
416
 
2427 ankur.sing 417
    /**
418
     * initialises vendor prices table header. Creates an Add button and
419
     * adds click event listener to it to create and pop up a dialog for adding 
420
     * a prices for a new vendor 
421
     */
422
    private void initVendorPricingHeader(){
423
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
424
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
425
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
426
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
427
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
6759 amar.kumar 428
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_NLC, PRICE_WIDTH);
2427 ankur.sing 429
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 430
 
2427 ankur.sing 431
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDORID, "Vendor Id");
432
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDOR_DESC, "Vendor");
433
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_MOP, "MOP");
434
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_DP, "Dealer Price");
435
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_TP, "Transfer Price");
6759 amar.kumar 436
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_NLC, "NLC");
2105 ankur.sing 437
 
2427 ankur.sing 438
        headerVendorPrices.getCellFormatter().setVisible(0, TABLE_INDEX_PRICING_VENDORID, false);
2359 ankur.sing 439
 
2105 ankur.sing 440
        Button addButton = new Button("Add");
2427 ankur.sing 441
        headerVendorPrices.setWidget(0, TABLE_INDEX_PRICING_BUTTON, addButton);
2105 ankur.sing 442
        addButton.addClickHandler(new ClickHandler() {
443
            @Override
444
            public void onClick(ClickEvent event) {
2119 ankur.sing 445
                VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
446
                vendorPricesDialog.updateButton.setText("Add");
447
                vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2105 ankur.sing 448
                    @Override
6759 amar.kumar 449
                    public boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId) {
2105 ankur.sing 450
                        if(!vendorExists(vendorId)) {
451
                            Window.alert("Vendor already exists");
452
                            return false;
453
                        }
2119 ankur.sing 454
                        /*if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 455
                            return false;
2119 ankur.sing 456
                        }*/
2427 ankur.sing 457
                        int row = tableVendorPrices.getRowCount();
458
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
459
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
460
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
461
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
462
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
6759 amar.kumar 463
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_NLC, PRICE_WIDTH);
2105 ankur.sing 464
 
2427 ankur.sing 465
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDORID, vendorId + "");
466
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
467
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
468
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
6760 amit.gupta 469
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
6759 amar.kumar 470
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_NLC, nlc + "");
2359 ankur.sing 471
 
2427 ankur.sing 472
                        tableVendorPrices.getCellFormatter().setVisible(row, TABLE_INDEX_PRICING_VENDORID, false);
2105 ankur.sing 473
                        return true;
474
                    }
475
                });
2119 ankur.sing 476
                vendorPricesDialog.show();
2105 ankur.sing 477
            }
478
        });
2066 ankur.sing 479
    }
2105 ankur.sing 480
 
2427 ankur.sing 481
    /**
3558 rajveer 482
     * initialises source prices table header. Creates an Add button and
483
     * adds click event listener to it to create and pop up a dialog for adding 
484
     * a prices for a new source 
485
     */
486
    private void initSourcePricingHeader(){
487
        headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, VENDOR_ID_WIDTH);
488
        headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, VENDOR_DESC_WIDTH);
489
        headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_MRP, PRICE_WIDTH);
490
        headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, PRICE_WIDTH);
491
        headerSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_BUTTON, BUTTON_WIDTH);
492
 
493
        headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, "Source Id");
494
        headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, "Source");
495
        headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_MRP, "MRP");
496
        headerSourcePrices.setText(0, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, "Selling Price");
497
 
498
        headerSourcePrices.getCellFormatter().setVisible(0, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, false);
499
 
500
        Button addButton = new Button("Add");
501
        headerSourcePrices.setWidget(0, TABLE_INDEX_SOURCE_PRICING_BUTTON, addButton);
502
        addButton.addClickHandler(new ClickHandler() {
503
            @Override
504
            public void onClick(ClickEvent event) {
3567 rajveer 505
                SourcePricesDialog sourcePricesDialog = new SourcePricesDialog(mrp.getText().trim(), sellingPrice.getText().trim());
506
                //SourcePricesDialog sourcePricesDialog = new SourcePricesDialog();
3558 rajveer 507
                sourcePricesDialog.updateButton.setText("Add");
508
                sourcePricesDialog.setSourcePriceUpdateListener(new SourcePricesDialog.SourcePriceUpdateListener() {
509
                    @Override
510
                    public boolean onUpdate(double mrp, double sellingPrice, long sourceId) {
511
                        if(!sourceExists(sourceId)) {
512
                            Window.alert("Source already exists");
513
                            return false;
514
                        }
515
 
516
                        int row = tableSourcePrices.getRowCount();
517
                        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, VENDOR_ID_WIDTH);
518
                        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, VENDOR_DESC_WIDTH);
519
                        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_MRP, PRICE_WIDTH);
520
                        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, PRICE_WIDTH);
521
 
522
                        tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, sourceId + "");
523
                        tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, Utils.getSourceDesc(sourceId));
524
                        tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_MRP, mrp + "");
525
                        tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sellingPrice + "");
526
 
527
                        tableSourcePrices.getCellFormatter().setVisible(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, false);
528
                        return true;
529
                    }
530
                });
531
                sourcePricesDialog.show();
532
            }
533
        });
534
    }
535
 
536
    /**
4423 phani.kuma 537
     * initialises similar items table header. Creates an Add button and
538
     * adds click event listener to it to create and pop up a dialog for adding 
539
     * a new similar item. 
540
     */
541
    private void initSimilarItemList() {
542
    	headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, PRICE_WIDTH);
543
    	headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, PRICE_WIDTH);
544
    	headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BRAND, PRICE_WIDTH);
545
    	headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, PRICE_WIDTH);
546
    	headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, PRICE_WIDTH);
547
    	headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, "150px");
548
    	headerSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BUTTON, BUTTON_WIDTH);
549
 
550
    	headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, "Catalog ItemId");
551
    	headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, "Product Group");
552
    	headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_BRAND, "Brand");
553
    	headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, "Model Number");
554
    	headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, "Model Name");
555
    	headerSimilarItems.setText(0, TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, "Category");
556
 
557
        Button addButton = new Button("Add");
558
        headerSimilarItems.setWidget(0, TABLE_INDEX_SIMILAR_ITEMS_BUTTON, addButton);
559
        addButton.addClickHandler(new ClickHandler() {
560
            @Override
561
            public void onClick(ClickEvent event) {
562
            	AddSimilarItemDialog addSimilarItemDialog = new AddSimilarItemDialog();
563
            	addSimilarItemDialog.setAddSimilarItemUpdateListener(new AddSimilarItemDialog.AddSimilarItemUpdateListener() {
564
					@Override
565
					public boolean onUpdate(long catalogItemId) {
566
						if (item.getSimilarItems().containsKey(catalogItemId)) {
567
							Window.alert("Similar Item exists.");
568
							return false;
569
						}
570
						else {
571
		                    catalogService.addSimilarItem(item.getId(), catalogItemId, new AsyncCallback<Item>() {
572
		                        @Override
573
		                        public void onSuccess(Item similarItem) {
574
		                            if(similarItem != null) {
575
		                                GWT.log("Similar Item Added");
576
		                                Map<Long, Item> newsimilarItems = item.getSimilarItems();
577
		                                newsimilarItems.put(similarItem.getCatalogItemId(), similarItem);
578
		                                item.setSimilarItems(newsimilarItems);
579
		                                updateSimilarItemsTable(item.getSimilarItems());
580
		                                Window.alert("Similar Item Added successfully.");
581
		                            }
582
		                            else {
583
		                                GWT.log("Error Adding Similar Item");
584
		                                Window.alert("Error Adding Similar Item");
585
		                            }
586
		                        }
587
		                        @Override
588
		                        public void onFailure(Throwable caught) {
589
		                            caught.printStackTrace();
590
		                            Window.alert("Error deleting Similar Item");
591
		                        }
592
		                    });
593
	                        return true;
594
						}
595
					}
596
				});
597
            	addSimilarItemDialog.show();
598
            }
599
        });
600
    }
6530 vikram.rag 601
 
602
    private void initIgnoredWarehouseHeader(){
603
    	headerIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_NAME, "100px");
604
    	headerIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, BUTTON_WIDTH);
605
    	headerIgnoredWarehouse.setText(0, TABLE_INDEX_WAREHOUSE_NAME, "Warehouse Desc");
606
    	Button addButton = new Button("Add");
607
    	headerIgnoredWarehouse.setWidget(0,TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON,addButton);
608
        addButton.addClickHandler(new ClickHandler() {
609
            @Override
610
            public void onClick(ClickEvent event) {
611
            	DeactivateWarehouseDialog deactivateWarehouseDialog = new DeactivateWarehouseDialog(new ArrayList<Long>(item.getVendorPricesMap().keySet()));
612
            	deactivateWarehouseDialog.updateButton.setText("Add");
613
        	    deactivateWarehouseDialog.setDeactivateWarehouseListener(new DeactivateWarehouseDialog.DeactivateWarehouseListener(){
614
					@Override
615
					public boolean onUpdate(final long warehouseId) {
616
					       if(Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().contains(new ItemWarehouse(item.getId(),warehouseId))) {
617
	                            Window.alert("Warehouse already deactivated");
618
	                            return false;
619
	                        }
620
	                       catalogService.addtoIgnoredInventoryUpdateItemsIdsWarehouseIds(item.getId(),warehouseId,new AsyncCallback<Boolean>() {
621
		                        @Override
622
		                        public void onSuccess(Boolean result) {
623
		                        	if(result) {
624
		                        		Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().add(new ItemWarehouse(item.getId(),warehouseId));
6532 amit.gupta 625
		                        		int index1 = tableIgnoredWarehouse.insertRow(0);
626
		                        		addRowToIgnoredWarehouseTable(index1, warehouseId, Utils.getAllWarehouses().get(warehouseId));
627
 
6530 vikram.rag 628
		                                Window.alert("Warehouse deactivated successfully");
629
		                            }
630
		                            else {
631
		                                GWT.log("Error Deactivating warehouse");
632
		                                Window.alert("Error Deactivating warehouse");
633
		                            }
634
		                        }
635
		                        @Override
636
		                        public void onFailure(Throwable caught) {
637
		                            caught.printStackTrace();
638
		                            Window.alert("Error Deactivating warehouse");
639
		                        }
640
		                    });
641
	                        return true;
642
	                    }
643
					});
644
            	deactivateWarehouseDialog.show();
645
            }
646
        });
647
    }
648
 
4423 phani.kuma 649
 
5504 phani.kuma 650
    private void initVoucherHeader(){
651
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
652
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
653
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
654
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
655
 
656
    	headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_TYPE, "Voucher Type");
657
    	headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_AMOUNT, "Voucher Amount");
658
        headerVouchers.getCellFormatter().setVisible(0, TABLE_INDEX_VOUCHERS_DEL_BUTTON, false);
659
        Button addButton = new Button("Add");
660
        headerVouchers.setWidget(0, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, addButton);
661
        addButton.addClickHandler(new ClickHandler() {
662
            @Override
663
            public void onClick(ClickEvent event) {
664
            	VoucherItemDialog voucherItemDialog = new VoucherItemDialog();
665
            	voucherItemDialog.updateButton.setText("Add");
666
            	voucherItemDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
667
                    @Override
668
                    public boolean onUpdate(final String voucherType, final long voucherAmount) {
669
                        if(!voucherExists(voucherType)) {
670
                            Window.alert("Voucher already exists");
671
                            return false;
672
                        }
5516 phani.kuma 673
                        Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);;
674
                        catalogService.addVoucher(item.getCatalogItemId(), voucherTypeValue, voucherAmount, new AsyncCallback<Boolean>() {
5504 phani.kuma 675
	                        @Override
676
	                        public void onSuccess(Boolean result) {
677
	                        	if(result) {
678
	                                GWT.log("Voucher Added");
679
	                                VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
680
	                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
681
	                                newvouchersMap.put(voucherType, newvoucher);
682
	                                item.setVouchersMap(newvouchersMap);
683
	                                updateVoucherTable(item.getVouchersMap());
684
	                                Window.alert("Voucher Added successfully.");
685
	                            }
686
	                            else {
687
	                                GWT.log("Error Adding Voucher");
688
	                                Window.alert("Error Adding Voucher");
689
	                            }
690
	                        }
691
	                        @Override
692
	                        public void onFailure(Throwable caught) {
693
	                            caught.printStackTrace();
694
	                            Window.alert("Error deleting voucher");
695
	                        }
696
	                    });
697
                        return true;
698
                    }
699
                });
700
            	voucherItemDialog.show();
701
            }
702
        });
703
    }
704
 
4423 phani.kuma 705
    /**
2427 ankur.sing 706
     * Clear and populate item availability table.
707
     * @param availabilityMap
708
     */
6530 vikram.rag 709
 
4431 phani.kuma 710
    private void updateAvailabilityTable(Map<Long, ItemInventory> itemInventoryMap){
1992 ankur.sing 711
        availabilityTable.removeAllRows();
4431 phani.kuma 712
        if(itemInventoryMap == null || itemInventoryMap.isEmpty()) {
1992 ankur.sing 713
            return;
714
        }
4431 phani.kuma 715
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "100px");
2105 ankur.sing 716
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
4431 phani.kuma 717
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVA, "100px");
718
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVR, "100px");
719
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_GET_BUTTON, "100px");
720
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, "100px");
2066 ankur.sing 721
 
1992 ankur.sing 722
        int i=0;
4431 phani.kuma 723
        for(ItemInventory warehousedata : itemInventoryMap.values()){
724
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, warehousedata.getWarehouseId() + "");
725
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(warehousedata.getWarehouseId()) + "");
726
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INVA, warehousedata.getAvailability() + "");
727
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INVR, warehousedata.getReserved() + "");
1992 ankur.sing 728
            i++;
729
        }
730
    }
4423 phani.kuma 731
 
2427 ankur.sing 732
    /**
733
     * Clear and populate vendor item key table with keys in the passed argument.
734
     * With each row in the table, an edit button is created and click event listener 
735
     * is added to it to edit that vendor item key row.
736
     * @param vendorKeysMap
737
     */
738
    private void updateVendorKeysTable(Map<String, VendorItemMapping> vendorKeysMap){
739
        tableVendorItemKey.removeAllRows();
2119 ankur.sing 740
 
2427 ankur.sing 741
        if(vendorKeysMap == null || vendorKeysMap.isEmpty()) {
2119 ankur.sing 742
            return;
743
        }
2427 ankur.sing 744
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
745
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
746
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
747
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
748
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 749
 
2119 ankur.sing 750
        int i=0;
2427 ankur.sing 751
        for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()){
2359 ankur.sing 752
            VendorItemMapping vendorMapping = e.getValue();
2427 ankur.sing 753
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDORID, vendorMapping.getVendorId() + "");
754
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));
755
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY, vendorMapping.getItemKey());
756
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1));
2119 ankur.sing 757
            Button editButton = new Button("Edit");
2427 ankur.sing 758
            tableVendorItemKey.setWidget(i, TABLE_INDEX_MAPPING_BUTTON, editButton);
2119 ankur.sing 759
            editButton.addClickHandler(new ClickHandler() {
760
                @Override
761
                public void onClick(ClickEvent event) {
2427 ankur.sing 762
                    Cell cell = tableVendorItemKey.getCellForEvent(event);
2119 ankur.sing 763
                    int row = cell.getRowIndex();
2427 ankur.sing 764
                    long vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
765
                    editVendorKey(vendorId, row);
2119 ankur.sing 766
                }
767
            });
2427 ankur.sing 768
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_VENDORID, false);
769
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2359 ankur.sing 770
            i++;
2119 ankur.sing 771
        }
772
    }
773
 
2427 ankur.sing 774
    /**
775
     * Clear and populate vendor prices table with prices in the passed argument.
776
     * With each row in the table, an edit button is created and click event listener 
777
     * is added to it to edit that vendor prices row.
778
     * @param vendorPricingMap
779
     */
780
    private void updateVendorPricingTable(Map<Long, VendorPricings> vendorPricingMap){
781
        tableVendorPrices.removeAllRows();
2105 ankur.sing 782
 
2119 ankur.sing 783
        if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {
1992 ankur.sing 784
            return;
785
        }
2427 ankur.sing 786
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
787
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
788
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
789
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
790
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
6759 amar.kumar 791
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_NLC, PRICE_WIDTH);
2427 ankur.sing 792
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 793
 
794
 
1992 ankur.sing 795
        int i=0;
2119 ankur.sing 796
        for(VendorPricings vendorDetail : vendorPricingMap.values()){
2427 ankur.sing 797
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDORID, vendorDetail.getVendorId() + "");
798
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
799
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_MOP, vendorDetail.getMop() + "");
800
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_DP, vendorDetail.getDealerPrice() + "");
801
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_TP, vendorDetail.getTransferPrice() + "");
6759 amar.kumar 802
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_NLC, vendorDetail.getNlc() + "");
1992 ankur.sing 803
            Button editButton = new Button("Edit");
2427 ankur.sing 804
            tableVendorPrices.setWidget(i, TABLE_INDEX_PRICING_BUTTON, editButton);
1992 ankur.sing 805
            editButton.addClickHandler(new ClickHandler() {
806
                @Override
807
                public void onClick(ClickEvent event) {
2427 ankur.sing 808
                    Cell cell = tableVendorPrices.getCellForEvent(event);
1992 ankur.sing 809
                    int row = cell.getRowIndex();
2427 ankur.sing 810
                    long vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
811
                    editVendorPrices(vendorId, row);
1992 ankur.sing 812
                }
813
            });
2427 ankur.sing 814
            tableVendorPrices.getCellFormatter().setVisible(i, TABLE_INDEX_PRICING_VENDORID, false);
2359 ankur.sing 815
            i++;
1992 ankur.sing 816
        }
817
    }
2066 ankur.sing 818
 
2427 ankur.sing 819
    /**
3558 rajveer 820
     * Clear and populate vendor prices table with prices in the passed argument.
821
     * With each row in the table, an edit button is created and click event listener 
822
     * is added to it to edit that vendor prices row.
823
     * @param sourcePricingMap
824
     */
825
    private void updateSourcePricingTable(Map<Long, SourcePricings> sourcePricingMap){
826
        tableSourcePrices.removeAllRows();
827
 
828
        if(sourcePricingMap == null || sourcePricingMap.isEmpty()) {
829
            return;
830
        }
831
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, VENDOR_ID_WIDTH);
832
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, VENDOR_DESC_WIDTH);
833
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_MRP, PRICE_WIDTH);
834
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, PRICE_WIDTH);
835
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_BUTTON, BUTTON_WIDTH);
836
 
837
        int i=0;
838
        for(SourcePricings sourceDetail : sourcePricingMap.values()){
839
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, sourceDetail.getSourceId() + "");
840
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, Utils.getSourceDesc(sourceDetail.getSourceId()));
841
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_MRP, sourceDetail.getMrp() + "");
842
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sourceDetail.getSellingPrice() + "");
843
 
844
            Button editButton = new Button("Edit");
845
            tableSourcePrices.setWidget(i, TABLE_INDEX_SOURCE_PRICING_BUTTON, editButton);
846
            editButton.addClickHandler(new ClickHandler() {
847
                @Override
848
                public void onClick(ClickEvent event) {
849
                    Cell cell = tableSourcePrices.getCellForEvent(event);
850
                    int row = cell.getRowIndex();
851
                    long sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
852
                    editSourcePrices(sourceId, row);
853
                }
854
            });
855
            tableSourcePrices.getCellFormatter().setVisible(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, false);
856
            i++;
857
        }
858
    }
859
 
860
    /**
4423 phani.kuma 861
     * Clear and populate similar items table with items in the passed argument.
862
     * With each row in the table, an delete button is created and click event listener 
863
     * is added to it to delete that similar item row.
864
     * @param similarItems
865
     */
866
    private void updateSimilarItemsTable(Map<Long, Item> similarItems){
867
    	tableSimilarItems.removeAllRows();
868
 
869
        if(similarItems == null || similarItems.isEmpty()) {
870
            return;
871
        }
872
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, PRICE_WIDTH);
873
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, PRICE_WIDTH);
874
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BRAND, PRICE_WIDTH);
875
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, PRICE_WIDTH);
876
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, PRICE_WIDTH);
877
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, "150px");
878
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BUTTON, BUTTON_WIDTH);
879
 
880
 
881
        int i=0;
882
        for(Item similarItemDetail : similarItems.values()){
883
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, similarItemDetail.getCatalogItemId() + "");
884
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, similarItemDetail.getProductGroup() + "");
885
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_BRAND, similarItemDetail.getBrand() + "");
886
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, similarItemDetail.getModelNumber() + "");
887
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, similarItemDetail.getModelName() + "");
888
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, similarItemDetail.getContentCategory() + "");
889
 
890
        	Button deleteButton = new Button("Delete");
891
            tableSimilarItems.setWidget(i, TABLE_INDEX_SIMILAR_ITEMS_BUTTON, deleteButton);
892
            deleteButton.addClickHandler(new ClickHandler() {
893
                @Override
894
                public void onClick(ClickEvent event) {
895
                    Cell cell = tableSimilarItems.getCellForEvent(event);
896
                    final int row = cell.getRowIndex();
897
                    long catalogItemId = Long.parseLong(tableSimilarItems.getText(row, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID));
898
 
899
                    catalogService.deleteSimilarItem(item.getId(), catalogItemId, new AsyncCallback<Boolean>() {
900
                        @Override
901
                        public void onSuccess(Boolean result) {
902
                            if(result) {
903
                                GWT.log("Similar Item deleted");
904
                                long catalogItemId = Long.parseLong(tableSimilarItems.getText(row, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID)); 
905
                                tableSimilarItems.removeRow(row);
906
                                Map<Long, Item> newsimilarItems = item.getSimilarItems();
907
                                newsimilarItems.remove(catalogItemId);
908
                                item.setSimilarItems(newsimilarItems);
909
                            }
910
                            else {
911
                                GWT.log("Error deleting Similar Item");
912
                                Window.alert("Error deleting Similar Item");
913
                            }
914
                        }
915
                        @Override
916
                        public void onFailure(Throwable caught) {
917
                            caught.printStackTrace();
918
                            Window.alert("Error deleting Similar Item");
919
                        }
920
                    });
921
                }
922
            });
923
            i++;
924
        }
925
    }
926
 
5504 phani.kuma 927
    private void updateVoucherTable(Map<String, VoucherItemMapping> vouchersMap){
928
    	tableVouchers.removeAllRows();
929
 
930
        if(vouchersMap == null || vouchersMap.isEmpty()) {
931
            return;
932
        }
933
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
934
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
935
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
936
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
937
 
938
        int i=0;
939
        for(VoucherItemMapping voucher : vouchersMap.values()){
940
        	tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_TYPE, voucher.getVoucherType());
941
        	tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_AMOUNT, voucher.getAmount() + "");
942
 
943
            Button editButton = new Button("Edit");
944
            tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, editButton);
945
            editButton.addClickHandler(new ClickHandler() {
946
                @Override
947
                public void onClick(ClickEvent event) {
948
                    Cell cell = tableVouchers.getCellForEvent(event);
949
                    final int row = cell.getRowIndex();
950
                    String voucherAmount = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_AMOUNT);
951
                    VoucherItemDialog voucherDialog = new VoucherItemDialog(voucherAmount);
952
                    voucherDialog.updateButton.setText("Update");
953
                    voucherDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
954
                        @Override
955
                        public boolean onUpdate(final String voucherType, final long voucherAmount) {
5516 phani.kuma 956
                        	Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);
957
                        	catalogService.addVoucher(item.getCatalogItemId(), voucherTypeValue, voucherAmount, new AsyncCallback<Boolean>() {
5504 phani.kuma 958
    	                        @Override
959
    	                        public void onSuccess(Boolean result) {
960
    	                        	if(result) {
961
    	                                GWT.log("Voucher Updated");
962
    	                                VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
963
    	                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
964
    	                                newvouchersMap.remove(voucherType);
965
    	                                newvouchersMap.put(voucherType, newvoucher);
966
    	                                item.setVouchersMap(newvouchersMap);
967
    	                                updateVoucherTable(item.getVouchersMap());
968
    	                                Window.alert("Voucher Updated successfully.");
969
    	                            }
970
    	                            else {
971
    	                                GWT.log("Error Updating Voucher");
972
    	                                Window.alert("Error Updating Voucher");
973
    	                            }
974
    	                        }
975
    	                        @Override
976
    	                        public void onFailure(Throwable caught) {
977
    	                            caught.printStackTrace();
978
    	                            Window.alert("Error Updating voucher");
979
    	                        }
980
    	                    });
981
                            return true;
982
                        }
983
                    });
984
                    voucherDialog.show();
985
                }
986
            });
987
 
988
            Button deleteButton = new Button("Delete");
989
            tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_DEL_BUTTON, deleteButton);
990
            deleteButton.addClickHandler(new ClickHandler() {
991
                @Override
992
                public void onClick(ClickEvent event) {
993
                    Cell cell = tableVouchers.getCellForEvent(event);
994
                    final int row = cell.getRowIndex();
995
                    String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
5516 phani.kuma 996
                    Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);
997
                    catalogService.deleteVoucher(item.getCatalogItemId(), voucherTypeValue, new AsyncCallback<Boolean>() {
5504 phani.kuma 998
                        @Override
999
                        public void onSuccess(Boolean result) {
1000
                            if(result) {
1001
                                GWT.log("Voucher deleted");
1002
                                String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
1003
                                tableVouchers.removeRow(row);
1004
                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
1005
                                newvouchersMap.remove(voucherType);
1006
                                item.setVouchersMap(newvouchersMap);
1007
                            }
1008
                            else {
1009
                                GWT.log("Error deleting Voucher");
1010
                                Window.alert("Error deleting Voucher");
1011
                            }
1012
                        }
1013
                        @Override
1014
                        public void onFailure(Throwable caught) {
1015
                            caught.printStackTrace();
1016
                            Window.alert("Error deleting Voucher");
1017
                        }
1018
                    });
1019
                }
1020
            });
1021
            i++;
1022
        }
1023
    }
6530 vikram.rag 1024
    private void updateTableIgnoredWarehouse(){
1025
    	tableIgnoredWarehouse.removeAllRows();
1026
    	List<ItemWarehouse> itemWarehouses = Utils.getignoredInventoryUpdateItemsIdsWarehouseIds();
6532 amit.gupta 1027
    	Map<Long,String> ignoredWarehouses = new HashMap<Long, String>();
6530 vikram.rag 1028
    	for(ItemWarehouse itemWarehouse:itemWarehouses){
1029
    		if(itemWarehouse.getItemId()==item.getId()){
1030
    			ignoredWarehouses.put(itemWarehouse.getWarehouseId(),Utils.getAllWarehouses().get(itemWarehouse.getWarehouseId()));	
1031
    		}
1032
 
1033
    	}		
1034
    	tableIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_NAME, "100px");
1035
        tableIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, BUTTON_WIDTH);
1036
 
1037
        int i=0;
1038
        for(final Map.Entry<Long,String> entry : ignoredWarehouses.entrySet()){
6532 amit.gupta 1039
        	addRowToIgnoredWarehouseTable(i, entry.getKey(), entry.getValue());
6530 vikram.rag 1040
            i++;
1041
        }
1042
    }
5504 phani.kuma 1043
 
6532 amit.gupta 1044
    private void addRowToIgnoredWarehouseTable(int i, final Long whId, final String whName) {
1045
    	tableIgnoredWarehouse.setText(i,TABLE_INDEX_WAREHOUSE_NAME,whName);
1046
    	Button deleteButton = new Button("Delete");
1047
    	tableIgnoredWarehouse.setWidget(i, TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, deleteButton);
1048
        deleteButton.addClickHandler(new ClickHandler() {
1049
            @Override
1050
            public void onClick(ClickEvent event) {
1051
                Cell cell = tableIgnoredWarehouse.getCellForEvent(event);
1052
                final int row = cell.getRowIndex();
1053
                catalogService.deleteFromIgnoredInventoryUpdateItemsIdsWarehouseIds(item.getId(),whId, new AsyncCallback<Boolean>() {
1054
                    @Override
1055
                    public void onSuccess(Boolean result) {
1056
                        if(result) {
1057
                            GWT.log("Warehouse will now be in sync");
1058
                            tableIgnoredWarehouse.removeRow(row);
1059
                            Window.alert("Warehouse deleted from list ");
1060
                            Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().remove(new ItemWarehouse(item.getId(),whId));
1061
                            }
1062
                        else {
1063
                            GWT.log("Error deleting Warehouse");
1064
                            Window.alert("Error deleting Warehouse");
1065
                        }
1066
                    }
1067
                    @Override
1068
                    public void onFailure(Throwable caught) {
1069
                        caught.printStackTrace();
1070
                        Window.alert("Error deleting Warehouse");
1071
                    }
1072
                });
1073
            }
1074
        });
1075
 
1076
	}
1077
 
1078
	/**
2427 ankur.sing 1079
     * called on the click event of update item button in ItemActions
1080
     */
2126 ankur.sing 1081
    void updateItem() {
1082
        if(item == null) {
1083
            Window.alert("Please select an item to update.");
1084
            return;
1085
        }
2066 ankur.sing 1086
        try {
2126 ankur.sing 1087
            if(!createNewItem()) {
1088
                return;
1089
            }
2066 ankur.sing 1090
        } catch(NumberFormatException ex) {
2126 ankur.sing 1091
            ex.printStackTrace();
1092
            GWT.log("Number format exception");
1093
        }
5427 amit.gupta 1094
        String paramsChanged = isItemChanged();
1095
        if(paramsChanged.equals("")) {
1096
        	Window.alert("Nothing to update. Please change intended item parameters and try again.");
1097
        	return;
1098
        } else {
1099
        	if(item.getSameItemsWithDifferentColors().size()>0 && optionalChangedValMap.size()>0 ){
1100
        		createDialog(paramsChanged);
1101
        	} else {
6096 amit.gupta 1102
        		String paramsChanged1  = "";
1103
        		paramsChanged1 = "You have changed following items.\n" + paramsChanged;
1104
        		Window.alert(paramsChanged1);
5427 amit.gupta 1105
        		validateNUpdate();
1106
        	}
7182 amit.gupta 1107
        	if("\n-Expected Delay".equals(paramsChanged) || "\n-Has Serial Number Flag".equals(paramsChanged)){
1108
        		catalogService.updateExpectedDelayOnProd(newItem, new AsyncCallback<String>() {
1109
                    @Override
1110
                    public void onSuccess(String result) {
1111
                        Window.alert(result);
1112
                    }
1113
                    @Override
1114
                    public void onFailure(Throwable caught) {
1115
                        Window.alert("Error while updating item on production");
1116
                    }
1117
                });
6096 amit.gupta 1118
        	}
5427 amit.gupta 1119
        }
1120
    }
1121
 
1122
 
1123
    private void validateNUpdate() {
1124
    	if(!Utils.validateItem(newItem)) {
2066 ankur.sing 1125
            return;
1126
        }
2126 ankur.sing 1127
 
4649 phani.kuma 1128
        final String[] messageList = new String[2];
1129
 
1130
    	String sellingpricemessage = compareSellingPricewithBreakEven();
1131
    	if(sellingpricemessage.equals("false")) {
1132
    		return;
1133
    	}
1134
    	else if(!sellingpricemessage.equals("true")) {
1135
    		messageList[0] = sellingpricemessage;
1136
    	}
1137
 
1138
        String preferredvendormessage = checkTransferPriceforPreferredVendor();
1139
        if(preferredvendormessage.equals("false")) {
1140
        	return;
1141
        }
1142
        else if(!preferredvendormessage.equals("true")) {
1143
        	messageList[1] = preferredvendormessage;
1144
        }
1145
 
2126 ankur.sing 1146
        /*if(!validatePrices()) {
1147
            return;
1148
        }*/
1149
        catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
1150
            @Override
1151
            public void onSuccess(Boolean result) {
1152
                if(result) {
4649 phani.kuma 1153
                	for(int i = 0; i < messageList.length; i++) {
1154
                		if(messageList[i] != null) {
1155
                			logAuthorization(messageList[i]);
1156
                		}
1157
                	}
5427 amit.gupta 1158
                	if(optionalChangedValMap.size()>0 || mandatoryChangedValMap.size()>0){
1159
	                	for(Long itemId : item.getSameItemsWithDifferentColors()){
1160
	                		updateItem(itemId);
1161
	                	}
1162
                	}
2126 ankur.sing 1163
                    item = newItem;
1164
                    GWT.log("Item updated. Id = " + item.getId());
2489 ankur.sing 1165
                    catalogDashboardPanel.getItemListWidget().updateItem(item);
1166
                    getFreshItemFromDB(item.getId());
2126 ankur.sing 1167
                    Window.alert("Item updated successfully.");
1168
                }
1169
                else {
1170
                    GWT.log("Error updating item");
1171
                    Window.alert("Error updating item");
1172
                }
1173
            }
1174
            @Override
1175
            public void onFailure(Throwable caught) {
1176
                caught.printStackTrace();
1177
                Window.alert("Error while updating item");
1178
            }
1179
        });
2066 ankur.sing 1180
    }
2126 ankur.sing 1181
 
2489 ankur.sing 1182
    private void getFreshItemFromDB(long id) {
1183
        catalogService.getItem(id, new AsyncCallback<Item>() {
1184
            @Override
1185
            public void onSuccess(Item result) {
1186
                setItemDetails(result);
1187
            }
1188
            @Override
1189
            public void onFailure(Throwable caught) {
1190
                caught.printStackTrace();
1191
                Window.alert("Unable to fetch item details.");
1192
            }
1193
        });
1194
    }
1195
 
2427 ankur.sing 1196
    /**
1197
     * This method is called while updating item.<br> It will create a new Item object and set 
1198
     * its editable attributes with UI fields values and non-editable attributes with old Item
1199
     * object attributes. This new Item object is then passed to the service to update item in the database.
1200
     * <br>If update is successful, the old Item object is replaced with the new Item object. 
1201
     * @return true if new Item object is created successfully
1202
     *     <br>false if some error occurs due to NumberFormatException
1203
     */
2126 ankur.sing 1204
    private boolean createNewItem() {
2066 ankur.sing 1205
        newItem = new Item();
2489 ankur.sing 1206
        newItem.setId(item.getId());
2066 ankur.sing 1207
        newItem.setProductGroup(productGroup.getText().trim());
1208
        newItem.setBrand(brand.getText().trim());
1209
        newItem.setModelNumber(modelNumber.getText().trim());
1210
        newItem.setModelName(modelName.getText().trim());
1211
        newItem.setColor(color.getText().trim());
2119 ankur.sing 1212
        newItem.setContentCategory(contentCategory.getText());
2066 ankur.sing 1213
        newItem.setComments(comments.getText().trim());
1214
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
2126 ankur.sing 1215
 
2068 ankur.sing 1216
        try {
2126 ankur.sing 1217
            if(!mrp.getText().trim().isEmpty()) {
1218
                double mrpValue = Double.parseDouble(mrp.getText().trim());
1219
                if(mrpValue <= 0) {
1220
                    throw new NumberFormatException("Negative value of MRP");
1221
                }
1222
                newItem.setMrp(mrpValue);
1223
            }
2068 ankur.sing 1224
        } catch(NumberFormatException ex) {
2126 ankur.sing 1225
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
1226
            return false;
2068 ankur.sing 1227
        }
1228
        try {
2126 ankur.sing 1229
            if(!sellingPrice.getText().trim().isEmpty()) {
1230
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
1231
            if(spValue <= 0) {
1232
                throw new NumberFormatException("Negative value of Selling price");
1233
            }
1234
            newItem.setSellingPrice(spValue);
1235
            }
1236
        } catch(NumberFormatException ex) {
1237
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
1238
            return false;
2068 ankur.sing 1239
        }
1240
        try {
2126 ankur.sing 1241
            if(!weight.getText().trim().isEmpty()) {
1242
                double wtValue = Double.parseDouble(weight.getText().trim());
1243
                if(wtValue <= 0) {
1244
                    throw new NumberFormatException("Negative value of Weight");
1245
                }
1246
                newItem.setWeight(wtValue);
1247
            }
2068 ankur.sing 1248
        } catch(NumberFormatException ex) {
2126 ankur.sing 1249
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
1250
            return false;
2068 ankur.sing 1251
        }
2126 ankur.sing 1252
        try {
1253
            if(!startDate.getTextBox().getText().trim().equals("")) {
1254
                newItem.setStartDate(startDate.getValue().getTime());
1255
            }
1256
        } catch(Exception ex) {
1257
            Window.alert("Invalid start date format");
1258
            return false;
1259
        }
2066 ankur.sing 1260
        newItem.setBestDealsText(bestDealsText.getText().trim());
6777 vikram.rag 1261
        newItem.setBestDealsDetailsText(bestDealsDetailsText.getText().trim());
1262
        newItem.setBestDealsDetailsLink(bestDealsDetailsLink.getText().trim());
5217 amit.gupta 1263
        Date comingSoonStartDt  = comingSoonStartDate.getValue();
1264
        Date expectedArrivalDt  = expectedArrivalDate.getValue();
1265
        if(comingSoonStartDt == null){
1266
        	newItem.setComingSoonStartDate(null);
1267
        }else {
1268
        	newItem.setComingSoonStartDate(comingSoonStartDt.getTime());
1269
        }
1270
        if(expectedArrivalDt == null){
1271
        	newItem.setExpectedArrivalDate(null);
1272
        }else {
1273
        	newItem.setExpectedArrivalDate(expectedArrivalDt.getTime());
1274
        }
2068 ankur.sing 1275
        try {
2126 ankur.sing 1276
            if(!bestDealsValue.getText().trim().equals("")) {
1277
                double bdValue = Double.parseDouble(bestDealsValue.getText().trim());
1278
                if(bdValue < 0) {
1279
                    throw new NumberFormatException("Negative value of BestDealValue");
1280
                }
1281
                newItem.setBestDealsValue(bdValue);
1282
            }
2068 ankur.sing 1283
        } catch(NumberFormatException ex) {
2126 ankur.sing 1284
            Window.alert("Invalid best deal value format");
1285
            return false;
2068 ankur.sing 1286
        }
3363 chandransh 1287
 
2068 ankur.sing 1288
        try {
2126 ankur.sing 1289
            if(!bestSellingRank.getText().trim().equals("")) {
1290
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
1291
                if(bsrValue < 0) {
1292
                    throw new NumberFormatException("Negative value of Best Selling Rank");
1293
                }
1294
                newItem.setBestSellingRank(bsrValue);
1295
            }
1296
        } catch(NumberFormatException ex) {
1297
            Window.alert("Invalid best selling rank format");
1298
            return false;
2068 ankur.sing 1299
        }
2066 ankur.sing 1300
        newItem.setDefaultForEntity(defaultForEntity.getValue());
2252 ankur.sing 1301
        newItem.setRisky(risky.getValue());
6813 amar.kumar 1302
 
1303
        try {
1304
            if(!minStockLevel.getText().trim().equals("")) {
1305
                long minStock = Long.parseLong(minStockLevel.getText().trim());
1306
                if(minStock < 0) {
1307
                    throw new NumberFormatException("Negative value of Minimum Stock Level");
1308
                }
1309
                newItem.setMinStockLevel(minStock);
1310
            }
1311
        } catch(NumberFormatException ex) {
1312
            Window.alert("Invalid minimum Stock Level format");
1313
            return false;
1314
        }
1315
 
1316
        try {
1317
            if(!numOfDaysStock.getText().trim().equals("")) {
1318
                long numDays = Long.parseLong(numOfDaysStock.getText().trim());
1319
                if(numDays < 0) {
1320
                    throw new NumberFormatException("Negative value of num Of Days ");
1321
                }
1322
                newItem.setNumOfDaysStock(new Long(numDays).intValue());
1323
            }
1324
        } catch(NumberFormatException ex) {
1325
            Window.alert("Invalid number Of Days format");
1326
            return false;
1327
        }
6241 amit.gupta 1328
        newItem.setShowSellingPrice(showSellingPrice.getValue());
3363 chandransh 1329
        try {
1330
            String expectedDelayText = expectedDelay.getText().trim();
1331
            if(!expectedDelayText.equals("")){
1332
                newItem.setExpectedDelay(Integer.parseInt(expectedDelayText));
1333
            }
1334
        } catch(NumberFormatException nfe) {
1335
            Window.alert("Invalid expected delay");
1336
            return false;
1337
        }
1338
 
4583 phani.kuma 1339
        if((item.getPreferredVendor() == null || item.getVendorPricesMap() == null || item.getVendorPricesMap().isEmpty()) && preferredVendor.getSelectedIndex() == 0) {
1340
        	newItem.setPreferredVendor(item.getPreferredVendor());
1341
        }
1342
    	else {
4506 phani.kuma 1343
    		long vendorId = Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex()));
1344
            newItem.setPreferredVendor(vendorId);
1345
    	}
6838 vikram.rag 1346
        newItem.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
4413 anupam.sin 1347
        newItem.setWarehouseStickiness(warehouseStickiness.getValue());
5384 phani.kuma 1348
        newItem.setHasItemNo(hasItemNo.getValue());
1349
        newItem.setItemType(itemType.getValue());
5460 phani.kuma 1350
        newItem.setClearance(clearance.getValue());
4413 anupam.sin 1351
 
2126 ankur.sing 1352
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
1353
          Add the instance to map and set the map to the item instance created above.*/
1354
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
2119 ankur.sing 1355
        VendorPricings v;
2427 ankur.sing 1356
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
2119 ankur.sing 1357
            v = new VendorPricings();
2427 ankur.sing 1358
            v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));
1359
            v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));
1360
            v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));
6759 amar.kumar 1361
            v.setNlc(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_NLC)));
2427 ankur.sing 1362
            v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));
2126 ankur.sing 1363
            vendorPrices.put(v.getVendorId(), v);
2066 ankur.sing 1364
        }
2126 ankur.sing 1365
        newItem.setVendorPricesMap(vendorPrices);
2359 ankur.sing 1366
        newItem.setItemStatusDesc(statusDesc.getText().trim());
2427 ankur.sing 1367
 
2126 ankur.sing 1368
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
1369
        Add the instance to map and set the map to the item instance created above.*/
2359 ankur.sing 1370
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
2126 ankur.sing 1371
        VendorItemMapping vMapping;
2427 ankur.sing 1372
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
2126 ankur.sing 1373
            vMapping = new VendorItemMapping();
2427 ankur.sing 1374
            vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));
1375
            vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));
1376
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);
2119 ankur.sing 1377
        }
2359 ankur.sing 1378
        newItem.setVendorKeysMap(vendorMappings);
2119 ankur.sing 1379
 
3558 rajveer 1380
        /*Create an instance of SourcePricings for each row in source pricing table. Set the source prices to the instance.
1381
        Add the instance to map and set the map to the item instance created above.*/
1382
		  Map<Long, SourcePricings> sourcePrices = new HashMap<Long, SourcePricings>();
1383
		  SourcePricings s;
1384
		  for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1385
		      s = new SourcePricings();
1386
		      s.setMrp(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP)));
1387
		      s.setSellingPrice(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE)));
1388
		      s.setSourceId(Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID)));
1389
		      sourcePrices.put(s.getSourceId(), s);
1390
		  }
1391
		newItem.setSourcePricesMap(sourcePrices);
1392
 
2126 ankur.sing 1393
        newItem.setContentCategoryId(item.getContentCategoryId());
1394
        newItem.setFeatureId(item.getFeatureId());
1395
        newItem.setFeatureDescription(item.getFeatureDescription());
1396
        newItem.setAddedOn(item.getAddedOn());
1397
        newItem.setRetireDate(item.getRetireDate());
1398
        newItem.setUpdatedOn(item.getUpdatedOn());
1399
        newItem.setItemStatus(item.getItemStatus());
4431 phani.kuma 1400
        newItem.setItemInventory(item.getItemInventory());
4423 phani.kuma 1401
        newItem.setSimilarItems(item.getSimilarItems());
5504 phani.kuma 1402
        newItem.setVouchersMap(item.getVouchersMap());
2119 ankur.sing 1403
 
2126 ankur.sing 1404
        return true;
2066 ankur.sing 1405
    }
1406
 
2427 ankur.sing 1407
    /**
1408
     * This method is called when Edit button is clicked corresponding to a row in 
1409
     * vendor prices table. It will pop up a form to edit the vendor prices.
1410
     * @param vendorId
1411
     * @param row
1412
     */
1413
    private void editVendorPrices(final long vendorId, final int row) {
1414
        String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
1415
        String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
1416
        String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
6759 amar.kumar 1417
        String nlc = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_NLC);
1418
        VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp, nlc);
2105 ankur.sing 1419
        pricesDialog.updateButton.setText("Update");
2119 ankur.sing 1420
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2066 ankur.sing 1421
            @Override
6759 amar.kumar 1422
            public boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId) {
1423
                if(!validateVendorPrices(mop, dp, tp, nlc)) {
2105 ankur.sing 1424
                    return false;
1425
                }
2427 ankur.sing 1426
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
1427
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
1428
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
6759 amar.kumar 1429
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_NLC, nlc + "");
2105 ankur.sing 1430
                return true;
2066 ankur.sing 1431
            }
1432
        });
1433
        pricesDialog.show();
1434
    }
2119 ankur.sing 1435
 
2427 ankur.sing 1436
    /**
1437
     * This method is called when Edit button is clicked corresponding to a row in 
3558 rajveer 1438
     * vendor prices table. It will pop up a form to edit the vendor prices.
1439
     * @param vendorId
1440
     * @param row
1441
     */
1442
    private void editSourcePrices(final long sourceId, final int row) {
1443
        String mrp = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP);
1444
        String sellingPrice = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE);
1445
        SourcePricesDialog pricesDialog = new SourcePricesDialog(mrp, sellingPrice);
1446
        pricesDialog.updateButton.setText("Update");
1447
        pricesDialog.setSourcePriceUpdateListener(new SourcePricesDialog.SourcePriceUpdateListener() {
1448
            @Override
1449
            public boolean onUpdate(double mrp, double sellingPrice, long sourceId) {
1450
                if(!validateSourcePrices(mrp, sellingPrice)) {
1451
                    return false;
1452
                }
1453
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_MRP, mrp + "");
1454
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sellingPrice + "");
1455
                return true;
1456
            }
1457
        });
1458
        pricesDialog.show();
1459
    }
1460
 
1461
 
1462
    /**
1463
     * This method is called when Edit button is clicked corresponding to a row in 
2427 ankur.sing 1464
     * vendor item key table. It will pop up a form to edit the item key.
1465
     * @param vendorId
1466
     * @param row
1467
     */
1468
    private void editVendorKey(final long vendorId, final int row) {
1469
        String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2126 ankur.sing 1470
        VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
1471
                modelNumber.getText().trim(), color.getText().trim(), key);
2119 ankur.sing 1472
        mappingDialog.updateButton.setText("Update");
1473
        mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
1474
            @Override
1475
            public boolean onUpdate(String itemKey, long vendorId) {
1476
                if(itemKey == null || itemKey.equals("")) {
1477
                    Window.alert("Item key cannot be empty.");
1478
                    return false;
1479
                }
2427 ankur.sing 1480
                tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
2119 ankur.sing 1481
                return true;
1482
            }
1483
        });
1484
        mappingDialog.show();
1485
    }
2066 ankur.sing 1486
 
2427 ankur.sing 1487
    /**
1488
     * This method compares all the editable UI fields values with attributes in the item object.
1489
     * If they differ, the attribute name is appended to a string.
1490
     * @return String showing attributes which are changed by the user for confirmation.
1491
     *      <br>Empty string if nothing is changed.
1492
     */
2252 ankur.sing 1493
    private String isItemChanged() {
1494
        StringBuilder sb = new StringBuilder("");
5427 amit.gupta 1495
        mandatoryChangedValMap = new HashMap<String, Object>();
1496
        optionalChangedValMap = new HashMap<String, Object>();
2489 ankur.sing 1497
        if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
5427 amit.gupta 1498
        	mandatoryChangedValMap.put(MANDATORY_BRAND, brand.getText().trim());
2387 ankur.sing 1499
            sb.append("\n-Brand");
2066 ankur.sing 1500
        }
2489 ankur.sing 1501
        if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
5427 amit.gupta 1502
        	mandatoryChangedValMap.put(MANDATORY_MODEL_NO, modelNumber.getText().trim());
2387 ankur.sing 1503
            sb.append("\n-Model Number");
2066 ankur.sing 1504
        }
2489 ankur.sing 1505
        if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
5427 amit.gupta 1506
        	mandatoryChangedValMap.put(MANDATORY_MODEL_NAME, modelName.getText().trim());
2387 ankur.sing 1507
            sb.append("\n-Model Name");
2066 ankur.sing 1508
        }
2489 ankur.sing 1509
        if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
2387 ankur.sing 1510
            sb.append("\n-Color");
2066 ankur.sing 1511
        }
2489 ankur.sing 1512
        if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
2387 ankur.sing 1513
            sb.append("\n-Status Description");
2359 ankur.sing 1514
        }
2489 ankur.sing 1515
        if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
2387 ankur.sing 1516
            sb.append("\n-Comments");
2066 ankur.sing 1517
        }
2489 ankur.sing 1518
        if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
5427 amit.gupta 1519
        	mandatoryChangedValMap.put(MANDATORY_MRP, newItem.getMrp());
2387 ankur.sing 1520
            sb.append("\n-MRP");
2066 ankur.sing 1521
        }
2489 ankur.sing 1522
        if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
5427 amit.gupta 1523
        	optionalChangedValMap.put(OPTIONAL_SELLING_PRICE, newItem.getSellingPrice());
2387 ankur.sing 1524
            sb.append("\n-Selling Price");
2027 ankur.sing 1525
        }
2489 ankur.sing 1526
        if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
5427 amit.gupta 1527
        	mandatoryChangedValMap.put(MANDATORY_WEIGHT, newItem.getWeight());
2387 ankur.sing 1528
            sb.append("\n-Weight");
2027 ankur.sing 1529
        }
2489 ankur.sing 1530
        if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
5427 amit.gupta 1531
        	mandatoryChangedValMap.put(MANDATORY_BEST_DEAL_TEXT, bestDealsText.getText().trim());
2387 ankur.sing 1532
            sb.append("\n-Best Deal Text");
2066 ankur.sing 1533
        }
6777 vikram.rag 1534
        if(!checkParameterIfEqual(bestDealsDetailsText.getText().trim(), item.getBestDealsDetailsText())) {
1535
        	mandatoryChangedValMap.put(MANDATORY_BEST_DEAL_DETAIL_TEXT, bestDealsDetailsText.getText().trim());
1536
            sb.append("\n-Best Deal Detail Text");
1537
        }
1538
        if(!checkParameterIfEqual(bestDealsDetailsLink.getText().trim(), item.getBestDealsDetailsLink())) {
1539
        	mandatoryChangedValMap.put(MANDATORY_BEST_DEAL_DETAIL_LINK, bestDealsDetailsLink.getText().trim());
1540
            sb.append("\n-Best Deal Detail Link");
1541
        }
2489 ankur.sing 1542
        if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
2387 ankur.sing 1543
            sb.append("\n-Best Deal Value");
2027 ankur.sing 1544
        }
2489 ankur.sing 1545
        if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
2387 ankur.sing 1546
            sb.append("\n-Best Selling Rank");
2066 ankur.sing 1547
        }
6813 amar.kumar 1548
        if(!checkParameterIfEqual(newItem.getMinStockLevel(), item.getMinStockLevel())) {
1549
            sb.append("\n-Min Stock Level");
1550
        }
1551
        if(!checkParameterIfEqual(newItem.getNumOfDaysStock(), item.getNumOfDaysStock())) {
1552
            sb.append("\n-Number Of Days Of Stock");
1553
        }
2066 ankur.sing 1554
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
2387 ankur.sing 1555
            sb.append("\n-Default For Entity Flag");
2066 ankur.sing 1556
        }
2252 ankur.sing 1557
        if(item.isRisky() != risky.getValue()) {
2387 ankur.sing 1558
            sb.append("\n-Risky Flag");
2252 ankur.sing 1559
        }
2489 ankur.sing 1560
        if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
2387 ankur.sing 1561
            sb.append("\n-Start Date");
2068 ankur.sing 1562
        }
5217 amit.gupta 1563
        if(!checkParameterIfEqual(newItem.getExpectedArrivalDate(), item.getExpectedArrivalDate())) {
1564
        	sb.append("\n-Expected Arrival Date");
1565
        }
1566
        if(!checkParameterIfEqual(newItem.getComingSoonStartDate(), item.getComingSoonStartDate())) {
1567
        	sb.append("\n-Coming Soon Start Date");
1568
        }
3524 chandransh 1569
        if(!checkParameterIfEqual(newItem.getExpectedDelay(), item.getExpectedDelay())) {
3362 chandransh 1570
            sb.append("\n-Expected Delay");
1571
        }
4413 anupam.sin 1572
        if(item.isWarehouseStickiness() != warehouseStickiness.getValue()) {
1573
            sb.append("\n-Warehouse Stickiness Flag");
1574
        }
4506 phani.kuma 1575
        if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor())) {
5427 amit.gupta 1576
        	optionalChangedValMap.put(OPTIONAL_PREFERRED_VENDOR, newItem.getPreferredVendor());
4506 phani.kuma 1577
            sb.append("\n-Preferred Vendor");
1578
        }
6838 vikram.rag 1579
        if(!checkParameterIfEqual(newItem.getPreferredInsurer(), item.getPreferredInsurer())) {
1580
        	optionalChangedValMap.put(OPTIONAL_PREFERRED_INSURER, newItem.getPreferredInsurer());
1581
            sb.append("\n-Preferred Insurer");
1582
        }
5384 phani.kuma 1583
        if(item.isHasItemNo() != hasItemNo.getValue()) {
1584
            sb.append("\n-Has Item Number Flag");
1585
        }
1586
        if(item.isItemType() != itemType.getValue()) {
1587
            sb.append("\n-Has Serial Number Flag");
1588
        }
5460 phani.kuma 1589
        if(item.isClearance() != clearance.getValue()) {
1590
            sb.append("\n-Marked For Clearence Sale");
1591
        }
6241 amit.gupta 1592
        if(item.isShowSellingPrice() != showSellingPrice.getValue()) {
1593
        	sb.append("\n-Coming Soon item pricing marked");
1594
        }
3362 chandransh 1595
 
2126 ankur.sing 1596
        VendorPricings vendorPricings;
2066 ankur.sing 1597
        long vendorId;
5427 amit.gupta 1598
        boolean vendorPricingsChanged = false;
2427 ankur.sing 1599
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
1600
            vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
2126 ankur.sing 1601
            vendorPricings = item.getVendorPricesMap().get(vendorId);
2359 ankur.sing 1602
            if(vendorPricings == null) {
2387 ankur.sing 1603
                sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
5427 amit.gupta 1604
                vendorPricingsChanged = true;
2359 ankur.sing 1605
                continue;
1606
            }
2427 ankur.sing 1607
            if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
5427 amit.gupta 1608
            	vendorPricingsChanged = true;
2387 ankur.sing 1609
                sb.append("\n-MOP (Vendor:" + vendorId + ")");
2066 ankur.sing 1610
            }
2427 ankur.sing 1611
            if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
5427 amit.gupta 1612
            	vendorPricingsChanged = true;
2387 ankur.sing 1613
                sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 1614
            }
2427 ankur.sing 1615
            if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
5427 amit.gupta 1616
            	vendorPricingsChanged = true;
2066 ankur.sing 1617
            }
6759 amar.kumar 1618
            if(vendorPricings.getNlc() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_NLC))) {
1619
            	vendorPricingsChanged = true;
1620
            }
2066 ankur.sing 1621
        }
5427 amit.gupta 1622
        if(vendorPricingsChanged){
1623
        	sb.append("\n-Vendor Pricing");
1624
        	optionalChangedValMap.put(OPTIONAL_VENDOR_PRICING, newItem.getVendorPricesMap());
1625
        }
2387 ankur.sing 1626
 
3558 rajveer 1627
        SourcePricings sourcePricings;
5427 amit.gupta 1628
        boolean sourcePricingsChanged = false;
3558 rajveer 1629
        long sourceId;
1630
        for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1631
            sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1632
            sourcePricings = item.getSourcePricesMap().get(sourceId);
1633
            if(sourcePricings == null) {
5427 amit.gupta 1634
            	sourcePricingsChanged = true;
3558 rajveer 1635
                sb.append("\n-Source Prices (Source:" + sourceId + ")");
1636
                continue;
1637
            }
1638
            if(sourcePricings.getMrp() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP))) {
5427 amit.gupta 1639
            	sourcePricingsChanged = true;
3558 rajveer 1640
                sb.append("\n-MRP (Source:" + sourceId + ")");
1641
            }
1642
            if(sourcePricings.getSellingPrice() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE))) {
5427 amit.gupta 1643
            	sourcePricingsChanged = true;
3558 rajveer 1644
                sb.append("\n-Selling Price (Source:" + sourceId + ")");
1645
            }
1646
        }
5427 amit.gupta 1647
        if(sourcePricingsChanged){
1648
        	sb.append("\n-Source Pricing");
1649
        	optionalChangedValMap.put(OPTIONAL_SOURCE_PRICING, newItem.getSourcePricesMap());
1650
        }
3558 rajveer 1651
 
5427 amit.gupta 1652
 
2387 ankur.sing 1653
        VendorItemMapping mapping;
1654
        String old_key, new_key;
2427 ankur.sing 1655
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
1656
            vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
1657
            old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
1658
            new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2387 ankur.sing 1659
            mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
1660
            if(mapping == null || !old_key.equals(new_key)) {
1661
                sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
1662
                continue;
1663
            }
1664
        }
2252 ankur.sing 1665
        return sb.toString();
2066 ankur.sing 1666
    }
1667
 
2566 chandransh 1668
    @SuppressWarnings("unused")
1669
	private boolean validatePrices() {
2066 ankur.sing 1670
        if(newItem.getSellingPrice() > newItem.getMrp()) {
1671
            Window.alert("Selling price cannot be more than MRP");
1672
            return false;
1673
        }
2119 ankur.sing 1674
        for(VendorPricings v : newItem.getVendorPricesMap().values()) {
2105 ankur.sing 1675
            if(newItem.getMrp() < v.getMop()) {
1676
                Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1677
                return false;
1678
            }
2105 ankur.sing 1679
            if(v.getTransferPrice() > v.getMop()) {
1680
                Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1681
                return false;
1682
            }
1683
        }
1684
        return true;
1685
    }
2105 ankur.sing 1686
 
6759 amar.kumar 1687
    private boolean validateVendorPrices(double mop, double dp, double tp, double nlc) {
2489 ankur.sing 1688
        if(item.getMrp() != null && item.getMrp() < mop) {
2105 ankur.sing 1689
            Window.alert("MOP cannot be more than MRP.");
1690
            return false;
1992 ankur.sing 1691
        }
2105 ankur.sing 1692
        if(tp > mop) {
1693
            Window.alert("Transfer Price cannot be more than MOP.");
1694
            return false;
1992 ankur.sing 1695
        }
6759 amar.kumar 1696
        if(tp < nlc) {
1697
            Window.alert("Transfer Price cannot be less than NLC.");
1698
            return false;
1699
        }
2105 ankur.sing 1700
        return true;
1992 ankur.sing 1701
    }
3558 rajveer 1702
 
1703
    private boolean validateSourcePrices(double mrp, double sellingPrice) {
1704
        if(sellingPrice > mrp) {
1705
            Window.alert("Selling Price cannot be more than MRP.");
1706
            return false;
1707
        }
1708
        return true;
1709
    }
1710
 
2105 ankur.sing 1711
 
1712
    public long getItemId() {
1713
        return item == null ? 0 : item.getId();
1714
    }
1715
 
1716
    public Item getItem() {
1717
        return item;
1718
    }
1719
 
5504 phani.kuma 1720
    private boolean voucherExists(String voucherType) {
1721
        for(int i = 0; i < tableVouchers.getRowCount(); i++) {
1722
            if(voucherType.equals(tableVouchers.getText(i, TABLE_INDEX_VOUCHERS_TYPE))) {
1723
                return false;
1724
            }
1725
        }
1726
        return true;
1727
    }
1728
 
2427 ankur.sing 1729
    /**
1730
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
1731
     * @param vendorId
1732
     * @return true if parameter vendor Id is already added to vendor prices table.
1733
     *      <br>else false
1734
     */
2105 ankur.sing 1735
    private boolean vendorExists(long vendorId) {
1736
        long id;
2427 ankur.sing 1737
        for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
1738
            id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
2105 ankur.sing 1739
            if(vendorId == id) {
1740
                return false;
1741
            }
1992 ankur.sing 1742
        }
2105 ankur.sing 1743
        return true;
1992 ankur.sing 1744
    }
2387 ankur.sing 1745
 
2427 ankur.sing 1746
    /**
3558 rajveer 1747
     * This method is used while adding source prices to ensure that there is only one row in the table for a source.
1748
     * @param sourceId
1749
     * @return true if parameter vendor Id is already added to source prices table.
1750
     *      <br>else false
1751
     */
1752
    private boolean sourceExists(long sourceId) {
1753
        long id;
1754
        for(int i = 0; i < tableSourcePrices.getRowCount(); i++) {
1755
            id = Long.parseLong(tableSourcePrices.getText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1756
            if(sourceId == id) {
1757
                return false;
1758
            }
1759
        }
1760
        return true;
1761
    }
1762
 
1763
    /**
2427 ankur.sing 1764
     * This method is used to check if any of the string item attributes is changed by the user.
2489 ankur.sing 1765
     * @param o1
1766
     * @param o2
2427 ankur.sing 1767
     * @return true if two strings are equal
1768
     *      <br>true if one of them is null and another is empty.
1769
     *      <br>false otherwise
1770
     */
2489 ankur.sing 1771
    private boolean checkParameterIfEqual(Object o1, Object o2) {
1772
        if(o1 == o2) {
2387 ankur.sing 1773
            return true;
1774
        }
2489 ankur.sing 1775
        if(o1 != null && o2 != null && o1.equals(o2)) {
2387 ankur.sing 1776
            return true;
1777
        }
2489 ankur.sing 1778
        if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
2387 ankur.sing 1779
            return true;
1780
        }
1781
        return false;
1782
    }
2489 ankur.sing 1783
 
1784
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
1785
        this.catalogDashboardPanel = catalogDashboardPanel;
1786
    }
4649 phani.kuma 1787
 
1788
    private String compareSellingPricewithBreakEven() {
1789
    	String message = "false";
1790
    	if(newItem.getWeight() == null) {
1791
    		Window.alert("Weight is empty.");
1792
            return message;
1793
    	}
1794
    	if(newItem.getSellingPrice() == null) {
1795
    		Window.alert("Selling Price is empty.");
1796
            return message;
1797
    	}
1798
 
1799
    	double transferPrice;
1800
    	if(newItem.getPreferredVendor() == null && !newItem.getVendorPricesMap().isEmpty()) {
1801
    		transferPrice = -1;
1802
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
6779 rajveer 1803
				if(transferPrice > vendorDetail.getNlc() || transferPrice == -1){
1804
					transferPrice = vendorDetail.getNlc();
4649 phani.kuma 1805
				}
1806
			}
1807
    	}
1808
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
6779 rajveer 1809
    		transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getNlc();    		
4649 phani.kuma 1810
    	}
1811
    	else{
1812
    		Window.alert("Add vendor to Vendor Prices and then change the Selling Price.");
1813
            return message;
1814
    	}
1815
 
1816
    	double weightfactor = Math.ceil((newItem.getWeight() * 1000)/Double.parseDouble(ConfigMap.get("courier_weight_factor")));
1817
		double couriercost = Double.parseDouble(ConfigMap.get("courier_cost_factor")) * weightfactor;
1818
		double costfactor = (Double.parseDouble(ConfigMap.get("transfer_price_percentage")) * transferPrice)/100;
1819
		double breakeven;
1820
		if(costfactor < Double.parseDouble(ConfigMap.get("transfer_price_factor"))){
1821
			breakeven = transferPrice + couriercost + Double.parseDouble(ConfigMap.get("breakeven_additon_factor"));
1822
		}
1823
		else{
1824
			breakeven = (transferPrice + couriercost)/Double.parseDouble(ConfigMap.get("breakeven_divisor"));
1825
		}
1826
 
1827
		if(breakeven > newItem.getSellingPrice()) {
1828
			message = "Selling Price("+newItem.getSellingPrice()+") is less than Breakeven Price("+breakeven+").";
1829
			if(Window.confirm(message)){
1830
				return message;
1831
			}
1832
			else{
1833
				message = "false";
1834
				Window.alert("Updation of Item is canceled.");
1835
				return message;
1836
			}
1837
		}
1838
		else {
1839
			message = "true";
1840
	        return message;
1841
		}
1842
    }
1843
 
1844
    private String checkTransferPriceforPreferredVendor() {
1845
    	String message = "false";
1846
    	if(newItem.getPreferredVendor() == null) {
1847
    		message = "true";
1848
    		return message;
1849
    	}
1850
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1851
    		double transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();
1852
        	double mintransferPrice = -1;
1853
        	String minvendor = "";
1854
        	boolean compareTransferPrices = false;
1855
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1856
				if(mintransferPrice > vendorDetail.getTransferPrice() || mintransferPrice == -1){
1857
					mintransferPrice = vendorDetail.getTransferPrice();
1858
					minvendor = Utils.getVendorDesc(vendorDetail.getVendorId());
1859
				}
1860
			}
1861
			if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor()) || item.getVendorPricesMap().isEmpty()) {
1862
				compareTransferPrices = true;
1863
			}
1864
			else {
1865
				double oldmintransferPrice = -1;
1866
				for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
1867
					if(oldmintransferPrice > vendorDetail.getTransferPrice() || oldmintransferPrice == -1){
1868
						oldmintransferPrice = vendorDetail.getTransferPrice();
1869
					}
1870
				}
1871
				if(mintransferPrice < oldmintransferPrice){
1872
					compareTransferPrices = true;
1873
				}
1874
			}
1875
			if(compareTransferPrices && transferPrice > mintransferPrice){
1876
				message = "Transfer Price("+transferPrice+") of Preferred Vendor("+Utils.getVendorDesc(newItem.getPreferredVendor())+") is more than Transfer Price("+mintransferPrice+") of "+minvendor+".";
1877
				if(Window.confirm(message)){
1878
					return message;
1879
				}
1880
				else{
1881
					message = "false";
1882
					Window.alert("Updation of Item is canceled.");
1883
					return message;
1884
				}
1885
			}
1886
			else {
1887
				message = "true";
1888
		        return message;
1889
			}
1890
    	}
1891
    	else{
1892
    		Window.alert("Add vendor to Vendor Prices and then change the Preferred Vendor.");
1893
            return message;
1894
    	}
1895
    }
1896
 
1897
    public void logAuthorization(String message) {
1898
    	String username = catalogDashboardPanel.uname;
1899
    	catalogService.addAuthorizationLog(newItem.getId(), username, message, new AsyncCallback<Boolean>() {
1900
            @Override
1901
            public void onSuccess(Boolean result) {
1902
                if(result) {
1903
                    GWT.log("Event is added");
1904
                }
1905
                else {
1906
                    GWT.log("Error adding the event");
1907
                    Window.alert("Error adding the event");
1908
                }
1909
            }
1910
            @Override
1911
            public void onFailure(Throwable caught) {
1912
                caught.printStackTrace();
1913
                Window.alert("Error while adding the event");
1914
            }
1915
        });
1916
    }
5217 amit.gupta 1917
 
1918
	@Override
1919
	public void setComingSoonStartDate(Date date) {
1920
		this.comingSoonStartDate.setValue(date);
1921
 
1922
	}
1923
 
1924
	@Override
1925
	public void setBestDealsText(String bestDealsText) {
1926
		this.bestDealsText.setValue(bestDealsText);
1927
 
1928
	}
1929
 
1930
	@Override
1931
	public void setExpectedArrivalDate(Date date) {
1932
		this.expectedArrivalDate.setValue(date);
1933
 
1934
	}
1935
 
1936
	@Override
1937
	public String getBestDealsText() {
1938
		return this.bestDealsText.getValue();
1939
	}
6777 vikram.rag 1940
 
1941
	public void setBestDealsDetailsText(String bestDealsDetailsText) {
1942
		this.bestDealsDetailsText.setValue(bestDealsDetailsText);
1943
 
1944
	}
1945
 
1946
	public String getBestDealsDetailsText() {
1947
		return this.bestDealsDetailsText.getValue();
1948
	}
5217 amit.gupta 1949
 
1950
	@Override
1951
	public Date getComingSoonStartDate() {
1952
		return this.comingSoonStartDate.getValue();
1953
	}
1954
 
1955
	@Override
1956
	public Date getExpectedArrivalDate() {
1957
		return this.expectedArrivalDate.getValue();
1958
	}
1959
	@UiHandler("comingSoonButton")
1960
	void onComingSoonButtonClick(ClickEvent event) {
1961
		ComingSoonDialog cd = new ComingSoonDialog(this);
1962
		cd.show();
1963
	}
5427 amit.gupta 1964
 
1965
	private void createDialog(String changedString) {
1966
        VerticalPanel vp = new VerticalPanel();
1967
        final DialogBox db = new DialogBox();
1968
        db.setText("Changed fields");
1969
 
1970
        vp.add(new Label("Check the fields to update all SKUs with similar entity."));
1971
        vp.add(new Label("--------------------------------------------------------"));
1972
        CheckBox allChecked = new CheckBox("Select all");
1973
        if(optionalChangedValMap.size()>1){
1974
	        allChecked.setName("all");
1975
	        allChecked.addClickHandler(new ClickHandler() {
1976
				@Override
1977
				public void onClick(ClickEvent event) {
1978
					CheckBox cb = (CheckBox)event.getSource();
1979
					VerticalPanel vp = (VerticalPanel)cb.getParent();
1980
					Iterator<Widget> iterator = vp.iterator();
1981
					while(iterator.hasNext()){
1982
						Widget w = iterator.next();
1983
						if(w instanceof CheckBox){
1984
							CheckBox cbox = (CheckBox)w;
1985
							if(cbox.getName()!="all"){
1986
								cbox.setValue(cb.getValue());
1987
							}
1988
						}
1989
					}
1990
					if(cb.getValue()){
1991
						cb.setText("Deselect all");
1992
					}else {
1993
						cb.setText("Select all");
1994
					}
1995
				}
1996
			});
1997
	        vp.add(allChecked);
1998
        }
1999
        String[] changedFields = changedString.split("\n-");
2000
        for(String changeField : changedFields){
2001
        	if(optionalChangedValMap.containsKey(changeField)){
2002
        		CheckBox ch = new CheckBox(changeField); 
2003
        		ch.getElement().getStyle().setPadding(10d, Unit.PX);
2004
        		vp.add(ch);
2005
        	} else {
2006
        		Label l = new Label(changeField);
2007
        		l.getElement().getStyle().setMarginLeft(10d, Unit.PX);
2008
        		l.getElement().getStyle().setPadding(10d, Unit.PX);
2009
        		vp.add(l);
2010
        	}
2011
        }
2012
 
2013
        Button submitButton = new Button();
2014
        submitButton.setText("Update");
2015
        submitButton.addClickHandler(new ClickHandler() {
2016
 
2017
			@Override
2018
			public void onClick(ClickEvent event) {
2019
				Button b  = (Button)event.getSource();
2020
				VerticalPanel vp = (VerticalPanel)b.getParent();
2021
				Iterator<Widget> iterator = vp.iterator();
2022
				while(iterator.hasNext()){
2023
					Widget w = iterator.next();
2024
					if(w instanceof CheckBox){
2025
						CheckBox cbox = (CheckBox)w;
2026
						if(cbox.getName()!="all"){
2027
							if(!cbox.getValue()){
2028
								optionalChangedValMap.remove(cbox.getText());
2029
							}
2030
						}
2031
					}
2032
				}
2033
				db.hide();
2034
				List<Item> items = new ArrayList<Item>();
2035
				items.add(newItem);
2036
				validateNUpdate();
2037
				/*for(Long id : item.getSameItemsWithDifferentColors()){
2038
					catalogService.getItem(id, new AsyncCallback<Item>() {
2039
			            @Override
2040
			            public void onSuccess(Item result) {
2041
			                items.add(e)
2042
			            }
2043
			            @Override
2044
			            public void onFailure(Throwable caught) {
2045
			                caught.printStackTrace();
2046
			                Window.alert("Unable to fetch item details.");
2047
			            }
2048
			        });
2049
				}*/
2050
			}
2051
 
2052
		});
2053
     vp.add(submitButton);
2054
     db.add(vp); 
2055
     db.center();
2056
     db.show();   
2057
    }
2058
 
2059
	private void updateItem(Long itemId) {
2060
		catalogService.getItem(itemId, new AsyncCallback<Item>() {
2061
            @Override
2062
            public void onSuccess(Item result) {
2063
            	final Item res = result;
2064
                if(mandatoryChangedValMap.containsKey(MANDATORY_BRAND)){
2065
                	result.setBrand((String)mandatoryChangedValMap.get(MANDATORY_BRAND));
2066
                }
2067
                if(mandatoryChangedValMap.containsKey(MANDATORY_BEST_DEAL_TEXT)){
2068
                	result.setBestDealsText((String)mandatoryChangedValMap.get(MANDATORY_BEST_DEAL_TEXT));
2069
                }
6777 vikram.rag 2070
                if(mandatoryChangedValMap.containsKey(MANDATORY_BEST_DEAL_DETAIL_TEXT)){
2071
                	result.setBestDealsDetailsText((String)mandatoryChangedValMap.get(MANDATORY_BEST_DEAL_DETAIL_TEXT));
2072
                }
2073
                if(mandatoryChangedValMap.containsKey(MANDATORY_BEST_DEAL_DETAIL_LINK)){
2074
                	result.setBestDealsDetailsLink((String)mandatoryChangedValMap.get(MANDATORY_BEST_DEAL_DETAIL_LINK));
2075
                }
5427 amit.gupta 2076
                if(mandatoryChangedValMap.containsKey(MANDATORY_MODEL_NAME)){
2077
                	result.setModelName((String)mandatoryChangedValMap.get(MANDATORY_MODEL_NAME));
2078
                }
2079
                if(mandatoryChangedValMap.containsKey(MANDATORY_MODEL_NO)){
2080
                	result.setModelNumber((String)mandatoryChangedValMap.get(MANDATORY_MODEL_NO));
2081
                }
2082
                if(mandatoryChangedValMap.containsKey(MANDATORY_WEIGHT)){
2083
                	result.setWeight((Double)mandatoryChangedValMap.get(MANDATORY_WEIGHT));
2084
                }
2085
                if(mandatoryChangedValMap.containsKey(MANDATORY_MRP)){
2086
                	result.setMrp((Double)mandatoryChangedValMap.get(MANDATORY_MRP));
2087
                }
2088
                if(optionalChangedValMap.containsKey(OPTIONAL_PREFERRED_VENDOR)){
2089
                	result.setPreferredVendor((Long)optionalChangedValMap.get(OPTIONAL_PREFERRED_VENDOR));
2090
                }
6838 vikram.rag 2091
                if(optionalChangedValMap.containsKey(OPTIONAL_PREFERRED_INSURER)){
2092
                	result.setPreferredInsurer((Long)optionalChangedValMap.get(OPTIONAL_PREFERRED_INSURER));
2093
                }
5427 amit.gupta 2094
                if(optionalChangedValMap.containsKey(OPTIONAL_SELLING_PRICE)){
2095
                	result.setSellingPrice((Double)optionalChangedValMap.get(OPTIONAL_SELLING_PRICE));
2096
                }
2097
                if(optionalChangedValMap.containsKey(OPTIONAL_SOURCE_PRICING)){
2098
                	result.setSourcePricesMap((Map<Long, SourcePricings>) optionalChangedValMap.get(OPTIONAL_SOURCE_PRICING));
2099
                }
2100
                if(optionalChangedValMap.containsKey(OPTIONAL_VENDOR_PRICING)){
2101
                	result.setVendorPricesMap((Map<Long, VendorPricings>) optionalChangedValMap.get(OPTIONAL_VENDOR_PRICING));
2102
                }
2103
                catalogService.updateItem(result, new AsyncCallback<Boolean>() {
2104
 
2105
					@Override
2106
					public void onSuccess(Boolean result1) {
2107
						if(result1) {
2108
							Window.alert(res.getId() + " updated Successfully");
2109
						}
2110
 
2111
					}
2112
 
2113
					@Override
2114
					public void onFailure(Throwable caught) {
2115
						caught.printStackTrace();
2116
						Window.alert("Error updating item " + res.getId());
2117
 
2118
					}
2119
				});
2120
            }
2121
            @Override
2122
            public void onFailure(Throwable caught) {
2123
                caught.printStackTrace();
2124
                Window.alert("Unable to fetch item details.");
2125
            }
2126
        });
2127
	}
6241 amit.gupta 2128
 
2129
	@Override
2130
	public void setShowPrice(boolean b) {
2131
		this.showSellingPrice.setValue(b);
2132
	}
2133
 
2134
	@Override
2135
	public boolean isShowPrice() {
2136
		return this.showSellingPrice.getValue();
2137
	}
1961 ankur.sing 2138
}