Subversion Repositories SmartDukaan

Rev

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