Subversion Repositories SmartDukaan

Rev

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

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