Subversion Repositories SmartDukaan

Rev

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

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