Subversion Repositories SmartDukaan

Rev

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