Subversion Repositories SmartDukaan

Rev

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