Subversion Repositories SmartDukaan

Rev

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

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