Subversion Repositories SmartDukaan

Rev

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