Subversion Repositories SmartDukaan

Rev

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

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