Subversion Repositories SmartDukaan

Rev

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