Subversion Repositories SmartDukaan

Rev

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