Subversion Repositories SmartDukaan

Rev

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