Subversion Repositories SmartDukaan

Rev

Rev 6241 | Rev 6532 | 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
						Window.alert("On update called.");
593
					       if(Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().contains(new ItemWarehouse(item.getId(),warehouseId))) {
594
	                            Window.alert("Warehouse already deactivated");
595
	                            return false;
596
	                        }
597
					       Window.alert("After contains.");
598
	                       catalogService.addtoIgnoredInventoryUpdateItemsIdsWarehouseIds(item.getId(),warehouseId,new AsyncCallback<Boolean>() {
599
		                        @Override
600
		                        public void onSuccess(Boolean result) {
601
		                        	if(result) {
602
		                        		Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().add(new ItemWarehouse(item.getId(),warehouseId));
603
		                                Window.alert("Warehouse deactivated successfully");
604
		                            }
605
		                            else {
606
		                                GWT.log("Error Deactivating warehouse");
607
		                                Window.alert("Error Deactivating warehouse");
608
		                            }
609
		                        }
610
		                        @Override
611
		                        public void onFailure(Throwable caught) {
612
		                            caught.printStackTrace();
613
		                            Window.alert("Error Deactivating warehouse");
614
		                        }
615
		                    });
616
	                        return true;
617
	                    }
618
					});
619
            	deactivateWarehouseDialog.show();
620
            }
621
        });
622
    }
623
 
4423 phani.kuma 624
 
5504 phani.kuma 625
    private void initVoucherHeader(){
626
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
627
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
628
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
629
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
630
 
631
    	headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_TYPE, "Voucher Type");
632
    	headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_AMOUNT, "Voucher Amount");
633
        headerVouchers.getCellFormatter().setVisible(0, TABLE_INDEX_VOUCHERS_DEL_BUTTON, false);
634
        Button addButton = new Button("Add");
635
        headerVouchers.setWidget(0, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, addButton);
636
        addButton.addClickHandler(new ClickHandler() {
637
            @Override
638
            public void onClick(ClickEvent event) {
639
            	VoucherItemDialog voucherItemDialog = new VoucherItemDialog();
640
            	voucherItemDialog.updateButton.setText("Add");
641
            	voucherItemDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
642
                    @Override
643
                    public boolean onUpdate(final String voucherType, final long voucherAmount) {
644
                        if(!voucherExists(voucherType)) {
645
                            Window.alert("Voucher already exists");
646
                            return false;
647
                        }
5516 phani.kuma 648
                        Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);;
649
                        catalogService.addVoucher(item.getCatalogItemId(), voucherTypeValue, voucherAmount, new AsyncCallback<Boolean>() {
5504 phani.kuma 650
	                        @Override
651
	                        public void onSuccess(Boolean result) {
652
	                        	if(result) {
653
	                                GWT.log("Voucher Added");
654
	                                VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
655
	                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
656
	                                newvouchersMap.put(voucherType, newvoucher);
657
	                                item.setVouchersMap(newvouchersMap);
658
	                                updateVoucherTable(item.getVouchersMap());
659
	                                Window.alert("Voucher Added successfully.");
660
	                            }
661
	                            else {
662
	                                GWT.log("Error Adding Voucher");
663
	                                Window.alert("Error Adding Voucher");
664
	                            }
665
	                        }
666
	                        @Override
667
	                        public void onFailure(Throwable caught) {
668
	                            caught.printStackTrace();
669
	                            Window.alert("Error deleting voucher");
670
	                        }
671
	                    });
672
                        return true;
673
                    }
674
                });
675
            	voucherItemDialog.show();
676
            }
677
        });
678
    }
679
 
4423 phani.kuma 680
    /**
2427 ankur.sing 681
     * Clear and populate item availability table.
682
     * @param availabilityMap
683
     */
6530 vikram.rag 684
 
4431 phani.kuma 685
    private void updateAvailabilityTable(Map<Long, ItemInventory> itemInventoryMap){
1992 ankur.sing 686
        availabilityTable.removeAllRows();
4431 phani.kuma 687
        if(itemInventoryMap == null || itemInventoryMap.isEmpty()) {
1992 ankur.sing 688
            return;
689
        }
4431 phani.kuma 690
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "100px");
2105 ankur.sing 691
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
4431 phani.kuma 692
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVA, "100px");
693
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INVR, "100px");
694
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_GET_BUTTON, "100px");
695
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_UPDATE_BUTTON, "100px");
2066 ankur.sing 696
 
1992 ankur.sing 697
        int i=0;
4431 phani.kuma 698
        for(ItemInventory warehousedata : itemInventoryMap.values()){
699
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, warehousedata.getWarehouseId() + "");
700
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(warehousedata.getWarehouseId()) + "");
701
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INVA, warehousedata.getAvailability() + "");
702
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INVR, warehousedata.getReserved() + "");
1992 ankur.sing 703
            i++;
704
        }
705
    }
4423 phani.kuma 706
 
2427 ankur.sing 707
    /**
708
     * Clear and populate vendor item key table with keys in the passed argument.
709
     * With each row in the table, an edit button is created and click event listener 
710
     * is added to it to edit that vendor item key row.
711
     * @param vendorKeysMap
712
     */
713
    private void updateVendorKeysTable(Map<String, VendorItemMapping> vendorKeysMap){
714
        tableVendorItemKey.removeAllRows();
2119 ankur.sing 715
 
2427 ankur.sing 716
        if(vendorKeysMap == null || vendorKeysMap.isEmpty()) {
2119 ankur.sing 717
            return;
718
        }
2427 ankur.sing 719
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
720
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
721
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
722
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
723
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 724
 
2119 ankur.sing 725
        int i=0;
2427 ankur.sing 726
        for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()){
2359 ankur.sing 727
            VendorItemMapping vendorMapping = e.getValue();
2427 ankur.sing 728
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDORID, vendorMapping.getVendorId() + "");
729
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));
730
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY, vendorMapping.getItemKey());
731
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1));
2119 ankur.sing 732
            Button editButton = new Button("Edit");
2427 ankur.sing 733
            tableVendorItemKey.setWidget(i, TABLE_INDEX_MAPPING_BUTTON, editButton);
2119 ankur.sing 734
            editButton.addClickHandler(new ClickHandler() {
735
                @Override
736
                public void onClick(ClickEvent event) {
2427 ankur.sing 737
                    Cell cell = tableVendorItemKey.getCellForEvent(event);
2119 ankur.sing 738
                    int row = cell.getRowIndex();
2427 ankur.sing 739
                    long vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
740
                    editVendorKey(vendorId, row);
2119 ankur.sing 741
                }
742
            });
2427 ankur.sing 743
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_VENDORID, false);
744
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2359 ankur.sing 745
            i++;
2119 ankur.sing 746
        }
747
    }
748
 
2427 ankur.sing 749
    /**
750
     * Clear and populate vendor prices table with prices in the passed argument.
751
     * With each row in the table, an edit button is created and click event listener 
752
     * is added to it to edit that vendor prices row.
753
     * @param vendorPricingMap
754
     */
755
    private void updateVendorPricingTable(Map<Long, VendorPricings> vendorPricingMap){
756
        tableVendorPrices.removeAllRows();
2105 ankur.sing 757
 
2119 ankur.sing 758
        if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {
1992 ankur.sing 759
            return;
760
        }
2427 ankur.sing 761
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
762
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
763
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
764
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
765
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
766
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 767
 
768
 
1992 ankur.sing 769
        int i=0;
2119 ankur.sing 770
        for(VendorPricings vendorDetail : vendorPricingMap.values()){
2427 ankur.sing 771
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDORID, vendorDetail.getVendorId() + "");
772
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
773
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_MOP, vendorDetail.getMop() + "");
774
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_DP, vendorDetail.getDealerPrice() + "");
775
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_TP, vendorDetail.getTransferPrice() + "");
1992 ankur.sing 776
            Button editButton = new Button("Edit");
2427 ankur.sing 777
            tableVendorPrices.setWidget(i, TABLE_INDEX_PRICING_BUTTON, editButton);
1992 ankur.sing 778
            editButton.addClickHandler(new ClickHandler() {
779
                @Override
780
                public void onClick(ClickEvent event) {
2427 ankur.sing 781
                    Cell cell = tableVendorPrices.getCellForEvent(event);
1992 ankur.sing 782
                    int row = cell.getRowIndex();
2427 ankur.sing 783
                    long vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
784
                    editVendorPrices(vendorId, row);
1992 ankur.sing 785
                }
786
            });
2427 ankur.sing 787
            tableVendorPrices.getCellFormatter().setVisible(i, TABLE_INDEX_PRICING_VENDORID, false);
2359 ankur.sing 788
            i++;
1992 ankur.sing 789
        }
790
    }
2066 ankur.sing 791
 
2427 ankur.sing 792
    /**
3558 rajveer 793
     * Clear and populate vendor prices table with prices in the passed argument.
794
     * With each row in the table, an edit button is created and click event listener 
795
     * is added to it to edit that vendor prices row.
796
     * @param sourcePricingMap
797
     */
798
    private void updateSourcePricingTable(Map<Long, SourcePricings> sourcePricingMap){
799
        tableSourcePrices.removeAllRows();
800
 
801
        if(sourcePricingMap == null || sourcePricingMap.isEmpty()) {
802
            return;
803
        }
804
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, VENDOR_ID_WIDTH);
805
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, VENDOR_DESC_WIDTH);
806
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_MRP, PRICE_WIDTH);
807
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, PRICE_WIDTH);
808
        tableSourcePrices.getColumnFormatter().setWidth(TABLE_INDEX_SOURCE_PRICING_BUTTON, BUTTON_WIDTH);
809
 
810
        int i=0;
811
        for(SourcePricings sourceDetail : sourcePricingMap.values()){
812
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, sourceDetail.getSourceId() + "");
813
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_DESC, Utils.getSourceDesc(sourceDetail.getSourceId()));
814
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_MRP, sourceDetail.getMrp() + "");
815
            tableSourcePrices.setText(i, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sourceDetail.getSellingPrice() + "");
816
 
817
            Button editButton = new Button("Edit");
818
            tableSourcePrices.setWidget(i, TABLE_INDEX_SOURCE_PRICING_BUTTON, editButton);
819
            editButton.addClickHandler(new ClickHandler() {
820
                @Override
821
                public void onClick(ClickEvent event) {
822
                    Cell cell = tableSourcePrices.getCellForEvent(event);
823
                    int row = cell.getRowIndex();
824
                    long sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
825
                    editSourcePrices(sourceId, row);
826
                }
827
            });
828
            tableSourcePrices.getCellFormatter().setVisible(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID, false);
829
            i++;
830
        }
831
    }
832
 
833
    /**
4423 phani.kuma 834
     * Clear and populate similar items table with items in the passed argument.
835
     * With each row in the table, an delete button is created and click event listener 
836
     * is added to it to delete that similar item row.
837
     * @param similarItems
838
     */
839
    private void updateSimilarItemsTable(Map<Long, Item> similarItems){
840
    	tableSimilarItems.removeAllRows();
841
 
842
        if(similarItems == null || similarItems.isEmpty()) {
843
            return;
844
        }
845
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, PRICE_WIDTH);
846
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, PRICE_WIDTH);
847
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BRAND, PRICE_WIDTH);
848
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, PRICE_WIDTH);
849
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, PRICE_WIDTH);
850
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, "150px");
851
        tableSimilarItems.getColumnFormatter().setWidth(TABLE_INDEX_SIMILAR_ITEMS_BUTTON, BUTTON_WIDTH);
852
 
853
 
854
        int i=0;
855
        for(Item similarItemDetail : similarItems.values()){
856
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID, similarItemDetail.getCatalogItemId() + "");
857
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_PRODUCT_GROUP, similarItemDetail.getProductGroup() + "");
858
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_BRAND, similarItemDetail.getBrand() + "");
859
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER, similarItemDetail.getModelNumber() + "");
860
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME, similarItemDetail.getModelName() + "");
861
        	tableSimilarItems.setText(i, TABLE_INDEX_SIMILAR_ITEMS_CATEGORY, similarItemDetail.getContentCategory() + "");
862
 
863
        	Button deleteButton = new Button("Delete");
864
            tableSimilarItems.setWidget(i, TABLE_INDEX_SIMILAR_ITEMS_BUTTON, deleteButton);
865
            deleteButton.addClickHandler(new ClickHandler() {
866
                @Override
867
                public void onClick(ClickEvent event) {
868
                    Cell cell = tableSimilarItems.getCellForEvent(event);
869
                    final int row = cell.getRowIndex();
870
                    long catalogItemId = Long.parseLong(tableSimilarItems.getText(row, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID));
871
 
872
                    catalogService.deleteSimilarItem(item.getId(), catalogItemId, new AsyncCallback<Boolean>() {
873
                        @Override
874
                        public void onSuccess(Boolean result) {
875
                            if(result) {
876
                                GWT.log("Similar Item deleted");
877
                                long catalogItemId = Long.parseLong(tableSimilarItems.getText(row, TABLE_INDEX_SIMILAR_ITEMS_CATALOG_ITEM_ID)); 
878
                                tableSimilarItems.removeRow(row);
879
                                Map<Long, Item> newsimilarItems = item.getSimilarItems();
880
                                newsimilarItems.remove(catalogItemId);
881
                                item.setSimilarItems(newsimilarItems);
882
                            }
883
                            else {
884
                                GWT.log("Error deleting Similar Item");
885
                                Window.alert("Error deleting Similar Item");
886
                            }
887
                        }
888
                        @Override
889
                        public void onFailure(Throwable caught) {
890
                            caught.printStackTrace();
891
                            Window.alert("Error deleting Similar Item");
892
                        }
893
                    });
894
                }
895
            });
896
            i++;
897
        }
898
    }
899
 
5504 phani.kuma 900
    private void updateVoucherTable(Map<String, VoucherItemMapping> vouchersMap){
901
    	tableVouchers.removeAllRows();
902
 
903
        if(vouchersMap == null || vouchersMap.isEmpty()) {
904
            return;
905
        }
906
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
907
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
908
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
909
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
910
 
911
        int i=0;
912
        for(VoucherItemMapping voucher : vouchersMap.values()){
913
        	tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_TYPE, voucher.getVoucherType());
914
        	tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_AMOUNT, voucher.getAmount() + "");
915
 
916
            Button editButton = new Button("Edit");
917
            tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, editButton);
918
            editButton.addClickHandler(new ClickHandler() {
919
                @Override
920
                public void onClick(ClickEvent event) {
921
                    Cell cell = tableVouchers.getCellForEvent(event);
922
                    final int row = cell.getRowIndex();
923
                    String voucherAmount = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_AMOUNT);
924
                    VoucherItemDialog voucherDialog = new VoucherItemDialog(voucherAmount);
925
                    voucherDialog.updateButton.setText("Update");
926
                    voucherDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
927
                        @Override
928
                        public boolean onUpdate(final String voucherType, final long voucherAmount) {
5516 phani.kuma 929
                        	Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);
930
                        	catalogService.addVoucher(item.getCatalogItemId(), voucherTypeValue, voucherAmount, new AsyncCallback<Boolean>() {
5504 phani.kuma 931
    	                        @Override
932
    	                        public void onSuccess(Boolean result) {
933
    	                        	if(result) {
934
    	                                GWT.log("Voucher Updated");
935
    	                                VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
936
    	                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
937
    	                                newvouchersMap.remove(voucherType);
938
    	                                newvouchersMap.put(voucherType, newvoucher);
939
    	                                item.setVouchersMap(newvouchersMap);
940
    	                                updateVoucherTable(item.getVouchersMap());
941
    	                                Window.alert("Voucher Updated successfully.");
942
    	                            }
943
    	                            else {
944
    	                                GWT.log("Error Updating Voucher");
945
    	                                Window.alert("Error Updating Voucher");
946
    	                            }
947
    	                        }
948
    	                        @Override
949
    	                        public void onFailure(Throwable caught) {
950
    	                            caught.printStackTrace();
951
    	                            Window.alert("Error Updating voucher");
952
    	                        }
953
    	                    });
954
                            return true;
955
                        }
956
                    });
957
                    voucherDialog.show();
958
                }
959
            });
960
 
961
            Button deleteButton = new Button("Delete");
962
            tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_DEL_BUTTON, deleteButton);
963
            deleteButton.addClickHandler(new ClickHandler() {
964
                @Override
965
                public void onClick(ClickEvent event) {
966
                    Cell cell = tableVouchers.getCellForEvent(event);
967
                    final int row = cell.getRowIndex();
968
                    String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
5516 phani.kuma 969
                    Long voucherTypeValue = Utils.getVoucherTypeId(voucherType);
970
                    catalogService.deleteVoucher(item.getCatalogItemId(), voucherTypeValue, new AsyncCallback<Boolean>() {
5504 phani.kuma 971
                        @Override
972
                        public void onSuccess(Boolean result) {
973
                            if(result) {
974
                                GWT.log("Voucher deleted");
975
                                String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
976
                                tableVouchers.removeRow(row);
977
                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
978
                                newvouchersMap.remove(voucherType);
979
                                item.setVouchersMap(newvouchersMap);
980
                            }
981
                            else {
982
                                GWT.log("Error deleting Voucher");
983
                                Window.alert("Error deleting Voucher");
984
                            }
985
                        }
986
                        @Override
987
                        public void onFailure(Throwable caught) {
988
                            caught.printStackTrace();
989
                            Window.alert("Error deleting Voucher");
990
                        }
991
                    });
992
                }
993
            });
994
            i++;
995
        }
996
    }
6530 vikram.rag 997
    private void updateTableIgnoredWarehouse(){
998
    	tableIgnoredWarehouse.removeAllRows();
999
    	List<ItemWarehouse> itemWarehouses = Utils.getignoredInventoryUpdateItemsIdsWarehouseIds();
1000
    	Map<Long,String> ignoredWarehouses = null;
1001
    	for(ItemWarehouse itemWarehouse:itemWarehouses){
1002
    		if(itemWarehouse.getItemId()==item.getId()){
1003
    			ignoredWarehouses.put(itemWarehouse.getWarehouseId(),Utils.getAllWarehouses().get(itemWarehouse.getWarehouseId()));	
1004
    		}
1005
 
1006
    	}		
1007
    	tableIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_NAME, "100px");
1008
        tableIgnoredWarehouse.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, BUTTON_WIDTH);
1009
 
1010
        int i=0;
1011
        for(final Map.Entry<Long,String> entry : ignoredWarehouses.entrySet()){
1012
        	tableIgnoredWarehouse.setText(i,TABLE_INDEX_WAREHOUSE_NAME,entry.getValue());
1013
        	Button deleteButton = new Button("Delete");
1014
            tableVouchers.setWidget(i, TABLE_INDEX_WAREHOUSE_ADD_DEL_BUTTON, deleteButton);
1015
            deleteButton.addClickHandler(new ClickHandler() {
1016
                @Override
1017
                public void onClick(ClickEvent event) {
1018
                    Cell cell = tableVouchers.getCellForEvent(event);
1019
                    final int row = cell.getRowIndex();
1020
                    catalogService.deleteFromIgnoredInventoryUpdateItemsIdsWarehouseIds(item.getCatalogItemId(),entry.getKey(), new AsyncCallback<Boolean>() {
1021
                        @Override
1022
                        public void onSuccess(Boolean result) {
1023
                            if(result) {
1024
                                GWT.log("Warehouse will now be in sync");
1025
                                tableVouchers.removeRow(row);
1026
                                Window.alert("Warehouse deleted from list ");
1027
                                Utils.getignoredInventoryUpdateItemsIdsWarehouseIds().remove(new ItemWarehouse(item.getCatalogItemId(),entry.getKey()));
1028
                                }
1029
                            else {
1030
                                GWT.log("Error deleting Warehouse");
1031
                                Window.alert("Error deleting Warehouse");
1032
                            }
1033
                        }
1034
                        @Override
1035
                        public void onFailure(Throwable caught) {
1036
                            caught.printStackTrace();
1037
                            Window.alert("Error deleting Warehouse");
1038
                        }
1039
                    });
1040
                }
1041
            });
1042
            i++;
1043
        }
1044
    }
5504 phani.kuma 1045
 
4423 phani.kuma 1046
    /**
2427 ankur.sing 1047
     * called on the click event of update item button in ItemActions
1048
     */
2126 ankur.sing 1049
    void updateItem() {
1050
        if(item == null) {
1051
            Window.alert("Please select an item to update.");
1052
            return;
1053
        }
2066 ankur.sing 1054
        try {
2126 ankur.sing 1055
            if(!createNewItem()) {
1056
                return;
1057
            }
2066 ankur.sing 1058
        } catch(NumberFormatException ex) {
2126 ankur.sing 1059
            ex.printStackTrace();
1060
            GWT.log("Number format exception");
1061
        }
5427 amit.gupta 1062
        String paramsChanged = isItemChanged();
1063
        if(paramsChanged.equals("")) {
1064
        	Window.alert("Nothing to update. Please change intended item parameters and try again.");
1065
        	return;
1066
        } else {
1067
        	if(item.getSameItemsWithDifferentColors().size()>0 && optionalChangedValMap.size()>0 ){
1068
        		createDialog(paramsChanged);
1069
        	} else {
6096 amit.gupta 1070
        		String paramsChanged1  = "";
1071
        		paramsChanged1 = "You have changed following items.\n" + paramsChanged;
1072
        		Window.alert(paramsChanged1);
5427 amit.gupta 1073
        		validateNUpdate();
1074
        	}
6096 amit.gupta 1075
        	if("\n-Expected Delay".equals(paramsChanged)){
6099 amit.gupta 1076
        		if(Window.confirm("Would You like to update Expected delay on prod?")){
6105 amit.gupta 1077
	        		catalogService.updateExpectedDelayOnProd(newItem, new AsyncCallback<String>() {
6099 amit.gupta 1078
	                    @Override
1079
	                    public void onSuccess(String result) {
1080
	                        Window.alert(result);
1081
	                    }
1082
	                    @Override
1083
	                    public void onFailure(Throwable caught) {
1084
	                        Window.alert("Error while updating item on production");
1085
	                    }
1086
	                });
1087
        		}
6096 amit.gupta 1088
        	}
5427 amit.gupta 1089
        }
1090
    }
1091
 
1092
 
1093
    private void validateNUpdate() {
1094
    	if(!Utils.validateItem(newItem)) {
2066 ankur.sing 1095
            return;
1096
        }
2126 ankur.sing 1097
 
4649 phani.kuma 1098
        final String[] messageList = new String[2];
1099
 
1100
    	String sellingpricemessage = compareSellingPricewithBreakEven();
1101
    	if(sellingpricemessage.equals("false")) {
1102
    		return;
1103
    	}
1104
    	else if(!sellingpricemessage.equals("true")) {
1105
    		messageList[0] = sellingpricemessage;
1106
    	}
1107
 
1108
        String preferredvendormessage = checkTransferPriceforPreferredVendor();
1109
        if(preferredvendormessage.equals("false")) {
1110
        	return;
1111
        }
1112
        else if(!preferredvendormessage.equals("true")) {
1113
        	messageList[1] = preferredvendormessage;
1114
        }
1115
 
2126 ankur.sing 1116
        /*if(!validatePrices()) {
1117
            return;
1118
        }*/
1119
        catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
1120
            @Override
1121
            public void onSuccess(Boolean result) {
1122
                if(result) {
4649 phani.kuma 1123
                	for(int i = 0; i < messageList.length; i++) {
1124
                		if(messageList[i] != null) {
1125
                			logAuthorization(messageList[i]);
1126
                		}
1127
                	}
5427 amit.gupta 1128
                	if(optionalChangedValMap.size()>0 || mandatoryChangedValMap.size()>0){
1129
	                	for(Long itemId : item.getSameItemsWithDifferentColors()){
1130
	                		updateItem(itemId);
1131
	                	}
1132
                	}
2126 ankur.sing 1133
                    item = newItem;
1134
                    GWT.log("Item updated. Id = " + item.getId());
2489 ankur.sing 1135
                    catalogDashboardPanel.getItemListWidget().updateItem(item);
1136
                    getFreshItemFromDB(item.getId());
2126 ankur.sing 1137
                    Window.alert("Item updated successfully.");
1138
                }
1139
                else {
1140
                    GWT.log("Error updating item");
1141
                    Window.alert("Error updating item");
1142
                }
1143
            }
1144
            @Override
1145
            public void onFailure(Throwable caught) {
1146
                caught.printStackTrace();
1147
                Window.alert("Error while updating item");
1148
            }
1149
        });
2066 ankur.sing 1150
    }
2126 ankur.sing 1151
 
2489 ankur.sing 1152
    private void getFreshItemFromDB(long id) {
1153
        catalogService.getItem(id, new AsyncCallback<Item>() {
1154
            @Override
1155
            public void onSuccess(Item result) {
1156
                setItemDetails(result);
1157
            }
1158
            @Override
1159
            public void onFailure(Throwable caught) {
1160
                caught.printStackTrace();
1161
                Window.alert("Unable to fetch item details.");
1162
            }
1163
        });
1164
    }
1165
 
2427 ankur.sing 1166
    /**
1167
     * This method is called while updating item.<br> It will create a new Item object and set 
1168
     * its editable attributes with UI fields values and non-editable attributes with old Item
1169
     * object attributes. This new Item object is then passed to the service to update item in the database.
1170
     * <br>If update is successful, the old Item object is replaced with the new Item object. 
1171
     * @return true if new Item object is created successfully
1172
     *     <br>false if some error occurs due to NumberFormatException
1173
     */
2126 ankur.sing 1174
    private boolean createNewItem() {
2066 ankur.sing 1175
        newItem = new Item();
2489 ankur.sing 1176
        newItem.setId(item.getId());
2066 ankur.sing 1177
        newItem.setProductGroup(productGroup.getText().trim());
1178
        newItem.setBrand(brand.getText().trim());
1179
        newItem.setModelNumber(modelNumber.getText().trim());
1180
        newItem.setModelName(modelName.getText().trim());
1181
        newItem.setColor(color.getText().trim());
2119 ankur.sing 1182
        newItem.setContentCategory(contentCategory.getText());
2066 ankur.sing 1183
        newItem.setComments(comments.getText().trim());
1184
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
2126 ankur.sing 1185
 
2068 ankur.sing 1186
        try {
2126 ankur.sing 1187
            if(!mrp.getText().trim().isEmpty()) {
1188
                double mrpValue = Double.parseDouble(mrp.getText().trim());
1189
                if(mrpValue <= 0) {
1190
                    throw new NumberFormatException("Negative value of MRP");
1191
                }
1192
                newItem.setMrp(mrpValue);
1193
            }
2068 ankur.sing 1194
        } catch(NumberFormatException ex) {
2126 ankur.sing 1195
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
1196
            return false;
2068 ankur.sing 1197
        }
1198
        try {
2126 ankur.sing 1199
            if(!sellingPrice.getText().trim().isEmpty()) {
1200
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
1201
            if(spValue <= 0) {
1202
                throw new NumberFormatException("Negative value of Selling price");
1203
            }
1204
            newItem.setSellingPrice(spValue);
1205
            }
1206
        } catch(NumberFormatException ex) {
1207
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
1208
            return false;
2068 ankur.sing 1209
        }
1210
        try {
2126 ankur.sing 1211
            if(!weight.getText().trim().isEmpty()) {
1212
                double wtValue = Double.parseDouble(weight.getText().trim());
1213
                if(wtValue <= 0) {
1214
                    throw new NumberFormatException("Negative value of Weight");
1215
                }
1216
                newItem.setWeight(wtValue);
1217
            }
2068 ankur.sing 1218
        } catch(NumberFormatException ex) {
2126 ankur.sing 1219
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
1220
            return false;
2068 ankur.sing 1221
        }
2126 ankur.sing 1222
        try {
1223
            if(!startDate.getTextBox().getText().trim().equals("")) {
1224
                newItem.setStartDate(startDate.getValue().getTime());
1225
            }
1226
        } catch(Exception ex) {
1227
            Window.alert("Invalid start date format");
1228
            return false;
1229
        }
2066 ankur.sing 1230
        newItem.setBestDealsText(bestDealsText.getText().trim());
5217 amit.gupta 1231
        Date comingSoonStartDt  = comingSoonStartDate.getValue();
1232
        Date expectedArrivalDt  = expectedArrivalDate.getValue();
1233
        if(comingSoonStartDt == null){
1234
        	newItem.setComingSoonStartDate(null);
1235
        }else {
1236
        	newItem.setComingSoonStartDate(comingSoonStartDt.getTime());
1237
        }
1238
        if(expectedArrivalDt == null){
1239
        	newItem.setExpectedArrivalDate(null);
1240
        }else {
1241
        	newItem.setExpectedArrivalDate(expectedArrivalDt.getTime());
1242
        }
2068 ankur.sing 1243
        try {
2126 ankur.sing 1244
            if(!bestDealsValue.getText().trim().equals("")) {
1245
                double bdValue = Double.parseDouble(bestDealsValue.getText().trim());
1246
                if(bdValue < 0) {
1247
                    throw new NumberFormatException("Negative value of BestDealValue");
1248
                }
1249
                newItem.setBestDealsValue(bdValue);
1250
            }
2068 ankur.sing 1251
        } catch(NumberFormatException ex) {
2126 ankur.sing 1252
            Window.alert("Invalid best deal value format");
1253
            return false;
2068 ankur.sing 1254
        }
3363 chandransh 1255
 
2068 ankur.sing 1256
        try {
2126 ankur.sing 1257
            if(!bestSellingRank.getText().trim().equals("")) {
1258
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
1259
                if(bsrValue < 0) {
1260
                    throw new NumberFormatException("Negative value of Best Selling Rank");
1261
                }
1262
                newItem.setBestSellingRank(bsrValue);
1263
            }
1264
        } catch(NumberFormatException ex) {
1265
            Window.alert("Invalid best selling rank format");
1266
            return false;
2068 ankur.sing 1267
        }
2066 ankur.sing 1268
        newItem.setDefaultForEntity(defaultForEntity.getValue());
2252 ankur.sing 1269
        newItem.setRisky(risky.getValue());
6241 amit.gupta 1270
        newItem.setShowSellingPrice(showSellingPrice.getValue());
3363 chandransh 1271
        try {
1272
            String expectedDelayText = expectedDelay.getText().trim();
1273
            if(!expectedDelayText.equals("")){
1274
                newItem.setExpectedDelay(Integer.parseInt(expectedDelayText));
1275
            }
1276
        } catch(NumberFormatException nfe) {
1277
            Window.alert("Invalid expected delay");
1278
            return false;
1279
        }
1280
 
4583 phani.kuma 1281
        if((item.getPreferredVendor() == null || item.getVendorPricesMap() == null || item.getVendorPricesMap().isEmpty()) && preferredVendor.getSelectedIndex() == 0) {
1282
        	newItem.setPreferredVendor(item.getPreferredVendor());
1283
        }
1284
    	else {
4506 phani.kuma 1285
    		long vendorId = Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex()));
1286
            newItem.setPreferredVendor(vendorId);
1287
    	}
1288
 
4413 anupam.sin 1289
        newItem.setWarehouseStickiness(warehouseStickiness.getValue());
5384 phani.kuma 1290
        newItem.setHasItemNo(hasItemNo.getValue());
1291
        newItem.setItemType(itemType.getValue());
5460 phani.kuma 1292
        newItem.setClearance(clearance.getValue());
4413 anupam.sin 1293
 
2126 ankur.sing 1294
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
1295
          Add the instance to map and set the map to the item instance created above.*/
1296
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
2119 ankur.sing 1297
        VendorPricings v;
2427 ankur.sing 1298
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
2119 ankur.sing 1299
            v = new VendorPricings();
2427 ankur.sing 1300
            v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));
1301
            v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));
1302
            v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));
1303
            v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));
2126 ankur.sing 1304
            vendorPrices.put(v.getVendorId(), v);
2066 ankur.sing 1305
        }
2126 ankur.sing 1306
        newItem.setVendorPricesMap(vendorPrices);
2359 ankur.sing 1307
        newItem.setItemStatusDesc(statusDesc.getText().trim());
2427 ankur.sing 1308
 
2126 ankur.sing 1309
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
1310
        Add the instance to map and set the map to the item instance created above.*/
2359 ankur.sing 1311
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
2126 ankur.sing 1312
        VendorItemMapping vMapping;
2427 ankur.sing 1313
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
2126 ankur.sing 1314
            vMapping = new VendorItemMapping();
2427 ankur.sing 1315
            vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));
1316
            vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));
1317
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);
2119 ankur.sing 1318
        }
2359 ankur.sing 1319
        newItem.setVendorKeysMap(vendorMappings);
2119 ankur.sing 1320
 
3558 rajveer 1321
        /*Create an instance of SourcePricings for each row in source pricing table. Set the source prices to the instance.
1322
        Add the instance to map and set the map to the item instance created above.*/
1323
		  Map<Long, SourcePricings> sourcePrices = new HashMap<Long, SourcePricings>();
1324
		  SourcePricings s;
1325
		  for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1326
		      s = new SourcePricings();
1327
		      s.setMrp(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP)));
1328
		      s.setSellingPrice(Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE)));
1329
		      s.setSourceId(Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID)));
1330
		      sourcePrices.put(s.getSourceId(), s);
1331
		  }
1332
		newItem.setSourcePricesMap(sourcePrices);
1333
 
2126 ankur.sing 1334
        newItem.setContentCategoryId(item.getContentCategoryId());
1335
        newItem.setFeatureId(item.getFeatureId());
1336
        newItem.setFeatureDescription(item.getFeatureDescription());
1337
        newItem.setAddedOn(item.getAddedOn());
1338
        newItem.setRetireDate(item.getRetireDate());
1339
        newItem.setUpdatedOn(item.getUpdatedOn());
1340
        newItem.setItemStatus(item.getItemStatus());
4431 phani.kuma 1341
        newItem.setItemInventory(item.getItemInventory());
4423 phani.kuma 1342
        newItem.setSimilarItems(item.getSimilarItems());
5504 phani.kuma 1343
        newItem.setVouchersMap(item.getVouchersMap());
2119 ankur.sing 1344
 
2126 ankur.sing 1345
        return true;
2066 ankur.sing 1346
    }
1347
 
2427 ankur.sing 1348
    /**
1349
     * This method is called when Edit button is clicked corresponding to a row in 
1350
     * vendor prices table. It will pop up a form to edit the vendor prices.
1351
     * @param vendorId
1352
     * @param row
1353
     */
1354
    private void editVendorPrices(final long vendorId, final int row) {
1355
        String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
1356
        String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
1357
        String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
2119 ankur.sing 1358
        VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);
2105 ankur.sing 1359
        pricesDialog.updateButton.setText("Update");
2119 ankur.sing 1360
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2066 ankur.sing 1361
            @Override
2119 ankur.sing 1362
            public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
1363
                if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 1364
                    return false;
1365
                }
2427 ankur.sing 1366
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
1367
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
1368
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
2105 ankur.sing 1369
                return true;
2066 ankur.sing 1370
            }
1371
        });
1372
        pricesDialog.show();
1373
    }
2119 ankur.sing 1374
 
2427 ankur.sing 1375
    /**
1376
     * This method is called when Edit button is clicked corresponding to a row in 
3558 rajveer 1377
     * vendor prices table. It will pop up a form to edit the vendor prices.
1378
     * @param vendorId
1379
     * @param row
1380
     */
1381
    private void editSourcePrices(final long sourceId, final int row) {
1382
        String mrp = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP);
1383
        String sellingPrice = tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE);
1384
        SourcePricesDialog pricesDialog = new SourcePricesDialog(mrp, sellingPrice);
1385
        pricesDialog.updateButton.setText("Update");
1386
        pricesDialog.setSourcePriceUpdateListener(new SourcePricesDialog.SourcePriceUpdateListener() {
1387
            @Override
1388
            public boolean onUpdate(double mrp, double sellingPrice, long sourceId) {
1389
                if(!validateSourcePrices(mrp, sellingPrice)) {
1390
                    return false;
1391
                }
1392
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_MRP, mrp + "");
1393
                tableSourcePrices.setText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE, sellingPrice + "");
1394
                return true;
1395
            }
1396
        });
1397
        pricesDialog.show();
1398
    }
1399
 
1400
 
1401
    /**
1402
     * This method is called when Edit button is clicked corresponding to a row in 
2427 ankur.sing 1403
     * vendor item key table. It will pop up a form to edit the item key.
1404
     * @param vendorId
1405
     * @param row
1406
     */
1407
    private void editVendorKey(final long vendorId, final int row) {
1408
        String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2126 ankur.sing 1409
        VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
1410
                modelNumber.getText().trim(), color.getText().trim(), key);
2119 ankur.sing 1411
        mappingDialog.updateButton.setText("Update");
1412
        mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
1413
            @Override
1414
            public boolean onUpdate(String itemKey, long vendorId) {
1415
                if(itemKey == null || itemKey.equals("")) {
1416
                    Window.alert("Item key cannot be empty.");
1417
                    return false;
1418
                }
2427 ankur.sing 1419
                tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
2119 ankur.sing 1420
                return true;
1421
            }
1422
        });
1423
        mappingDialog.show();
1424
    }
2066 ankur.sing 1425
 
2427 ankur.sing 1426
    /**
1427
     * This method compares all the editable UI fields values with attributes in the item object.
1428
     * If they differ, the attribute name is appended to a string.
1429
     * @return String showing attributes which are changed by the user for confirmation.
1430
     *      <br>Empty string if nothing is changed.
1431
     */
2252 ankur.sing 1432
    private String isItemChanged() {
1433
        StringBuilder sb = new StringBuilder("");
5427 amit.gupta 1434
        mandatoryChangedValMap = new HashMap<String, Object>();
1435
        optionalChangedValMap = new HashMap<String, Object>();
2489 ankur.sing 1436
        if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
5427 amit.gupta 1437
        	mandatoryChangedValMap.put(MANDATORY_BRAND, brand.getText().trim());
2387 ankur.sing 1438
            sb.append("\n-Brand");
2066 ankur.sing 1439
        }
2489 ankur.sing 1440
        if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
5427 amit.gupta 1441
        	mandatoryChangedValMap.put(MANDATORY_MODEL_NO, modelNumber.getText().trim());
2387 ankur.sing 1442
            sb.append("\n-Model Number");
2066 ankur.sing 1443
        }
2489 ankur.sing 1444
        if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
5427 amit.gupta 1445
        	mandatoryChangedValMap.put(MANDATORY_MODEL_NAME, modelName.getText().trim());
2387 ankur.sing 1446
            sb.append("\n-Model Name");
2066 ankur.sing 1447
        }
2489 ankur.sing 1448
        if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
2387 ankur.sing 1449
            sb.append("\n-Color");
2066 ankur.sing 1450
        }
2489 ankur.sing 1451
        if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
2387 ankur.sing 1452
            sb.append("\n-Status Description");
2359 ankur.sing 1453
        }
2489 ankur.sing 1454
        if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
2387 ankur.sing 1455
            sb.append("\n-Comments");
2066 ankur.sing 1456
        }
2489 ankur.sing 1457
        if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
5427 amit.gupta 1458
        	mandatoryChangedValMap.put(MANDATORY_MRP, newItem.getMrp());
2387 ankur.sing 1459
            sb.append("\n-MRP");
2066 ankur.sing 1460
        }
2489 ankur.sing 1461
        if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
5427 amit.gupta 1462
        	optionalChangedValMap.put(OPTIONAL_SELLING_PRICE, newItem.getSellingPrice());
2387 ankur.sing 1463
            sb.append("\n-Selling Price");
2027 ankur.sing 1464
        }
2489 ankur.sing 1465
        if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
5427 amit.gupta 1466
        	mandatoryChangedValMap.put(MANDATORY_WEIGHT, newItem.getWeight());
2387 ankur.sing 1467
            sb.append("\n-Weight");
2027 ankur.sing 1468
        }
2489 ankur.sing 1469
        if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
5427 amit.gupta 1470
        	mandatoryChangedValMap.put(MANDATORY_BEST_DEAL_TEXT, bestDealsText.getText().trim());
2387 ankur.sing 1471
            sb.append("\n-Best Deal Text");
2066 ankur.sing 1472
        }
2489 ankur.sing 1473
        if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
2387 ankur.sing 1474
            sb.append("\n-Best Deal Value");
2027 ankur.sing 1475
        }
2489 ankur.sing 1476
        if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
2387 ankur.sing 1477
            sb.append("\n-Best Selling Rank");
2066 ankur.sing 1478
        }
1479
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
2387 ankur.sing 1480
            sb.append("\n-Default For Entity Flag");
2066 ankur.sing 1481
        }
2252 ankur.sing 1482
        if(item.isRisky() != risky.getValue()) {
2387 ankur.sing 1483
            sb.append("\n-Risky Flag");
2252 ankur.sing 1484
        }
2489 ankur.sing 1485
        if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
2387 ankur.sing 1486
            sb.append("\n-Start Date");
2068 ankur.sing 1487
        }
5217 amit.gupta 1488
        if(!checkParameterIfEqual(newItem.getExpectedArrivalDate(), item.getExpectedArrivalDate())) {
1489
        	sb.append("\n-Expected Arrival Date");
1490
        }
1491
        if(!checkParameterIfEqual(newItem.getComingSoonStartDate(), item.getComingSoonStartDate())) {
1492
        	sb.append("\n-Coming Soon Start Date");
1493
        }
3524 chandransh 1494
        if(!checkParameterIfEqual(newItem.getExpectedDelay(), item.getExpectedDelay())) {
3362 chandransh 1495
            sb.append("\n-Expected Delay");
1496
        }
4413 anupam.sin 1497
        if(item.isWarehouseStickiness() != warehouseStickiness.getValue()) {
1498
            sb.append("\n-Warehouse Stickiness Flag");
1499
        }
4506 phani.kuma 1500
        if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor())) {
5427 amit.gupta 1501
        	optionalChangedValMap.put(OPTIONAL_PREFERRED_VENDOR, newItem.getPreferredVendor());
4506 phani.kuma 1502
            sb.append("\n-Preferred Vendor");
1503
        }
5384 phani.kuma 1504
        if(item.isHasItemNo() != hasItemNo.getValue()) {
1505
            sb.append("\n-Has Item Number Flag");
1506
        }
1507
        if(item.isItemType() != itemType.getValue()) {
1508
            sb.append("\n-Has Serial Number Flag");
1509
        }
5460 phani.kuma 1510
        if(item.isClearance() != clearance.getValue()) {
1511
            sb.append("\n-Marked For Clearence Sale");
1512
        }
6241 amit.gupta 1513
        if(item.isShowSellingPrice() != showSellingPrice.getValue()) {
1514
        	sb.append("\n-Coming Soon item pricing marked");
1515
        }
3362 chandransh 1516
 
2126 ankur.sing 1517
        VendorPricings vendorPricings;
2066 ankur.sing 1518
        long vendorId;
5427 amit.gupta 1519
        boolean vendorPricingsChanged = false;
2427 ankur.sing 1520
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
1521
            vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
2126 ankur.sing 1522
            vendorPricings = item.getVendorPricesMap().get(vendorId);
2359 ankur.sing 1523
            if(vendorPricings == null) {
2387 ankur.sing 1524
                sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
5427 amit.gupta 1525
                vendorPricingsChanged = true;
2359 ankur.sing 1526
                continue;
1527
            }
2427 ankur.sing 1528
            if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
5427 amit.gupta 1529
            	vendorPricingsChanged = true;
2387 ankur.sing 1530
                sb.append("\n-MOP (Vendor:" + vendorId + ")");
2066 ankur.sing 1531
            }
2427 ankur.sing 1532
            if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
5427 amit.gupta 1533
            	vendorPricingsChanged = true;
2387 ankur.sing 1534
                sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 1535
            }
2427 ankur.sing 1536
            if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
5427 amit.gupta 1537
            	vendorPricingsChanged = true;
2066 ankur.sing 1538
            }
1539
        }
5427 amit.gupta 1540
        if(vendorPricingsChanged){
1541
        	sb.append("\n-Vendor Pricing");
1542
        	optionalChangedValMap.put(OPTIONAL_VENDOR_PRICING, newItem.getVendorPricesMap());
1543
        }
2387 ankur.sing 1544
 
3558 rajveer 1545
        SourcePricings sourcePricings;
5427 amit.gupta 1546
        boolean sourcePricingsChanged = false;
3558 rajveer 1547
        long sourceId;
1548
        for(int row = 0; row < tableSourcePrices.getRowCount(); row++) {
1549
            sourceId = Long.parseLong(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1550
            sourcePricings = item.getSourcePricesMap().get(sourceId);
1551
            if(sourcePricings == null) {
5427 amit.gupta 1552
            	sourcePricingsChanged = true;
3558 rajveer 1553
                sb.append("\n-Source Prices (Source:" + sourceId + ")");
1554
                continue;
1555
            }
1556
            if(sourcePricings.getMrp() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_MRP))) {
5427 amit.gupta 1557
            	sourcePricingsChanged = true;
3558 rajveer 1558
                sb.append("\n-MRP (Source:" + sourceId + ")");
1559
            }
1560
            if(sourcePricings.getSellingPrice() != Double.parseDouble(tableSourcePrices.getText(row, TABLE_INDEX_SOURCE_PRICING_SELLING_PRICE))) {
5427 amit.gupta 1561
            	sourcePricingsChanged = true;
3558 rajveer 1562
                sb.append("\n-Selling Price (Source:" + sourceId + ")");
1563
            }
1564
        }
5427 amit.gupta 1565
        if(sourcePricingsChanged){
1566
        	sb.append("\n-Source Pricing");
1567
        	optionalChangedValMap.put(OPTIONAL_SOURCE_PRICING, newItem.getSourcePricesMap());
1568
        }
3558 rajveer 1569
 
5427 amit.gupta 1570
 
2387 ankur.sing 1571
        VendorItemMapping mapping;
1572
        String old_key, new_key;
2427 ankur.sing 1573
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
1574
            vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
1575
            old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
1576
            new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2387 ankur.sing 1577
            mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
1578
            if(mapping == null || !old_key.equals(new_key)) {
1579
                sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
1580
                continue;
1581
            }
1582
        }
2252 ankur.sing 1583
        return sb.toString();
2066 ankur.sing 1584
    }
1585
 
2566 chandransh 1586
    @SuppressWarnings("unused")
1587
	private boolean validatePrices() {
2066 ankur.sing 1588
        if(newItem.getSellingPrice() > newItem.getMrp()) {
1589
            Window.alert("Selling price cannot be more than MRP");
1590
            return false;
1591
        }
2119 ankur.sing 1592
        for(VendorPricings v : newItem.getVendorPricesMap().values()) {
2105 ankur.sing 1593
            if(newItem.getMrp() < v.getMop()) {
1594
                Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1595
                return false;
1596
            }
2105 ankur.sing 1597
            if(v.getTransferPrice() > v.getMop()) {
1598
                Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 1599
                return false;
1600
            }
1601
        }
1602
        return true;
1603
    }
2105 ankur.sing 1604
 
2119 ankur.sing 1605
    private boolean validateVendorPrices(double mop, double dp, double tp) {
2489 ankur.sing 1606
        if(item.getMrp() != null && item.getMrp() < mop) {
2105 ankur.sing 1607
            Window.alert("MOP cannot be more than MRP.");
1608
            return false;
1992 ankur.sing 1609
        }
2105 ankur.sing 1610
        if(tp > mop) {
1611
            Window.alert("Transfer Price cannot be more than MOP.");
1612
            return false;
1992 ankur.sing 1613
        }
2105 ankur.sing 1614
        return true;
1992 ankur.sing 1615
    }
3558 rajveer 1616
 
1617
    private boolean validateSourcePrices(double mrp, double sellingPrice) {
1618
        if(sellingPrice > mrp) {
1619
            Window.alert("Selling Price cannot be more than MRP.");
1620
            return false;
1621
        }
1622
        return true;
1623
    }
1624
 
2105 ankur.sing 1625
 
1626
    public long getItemId() {
1627
        return item == null ? 0 : item.getId();
1628
    }
1629
 
1630
    public Item getItem() {
1631
        return item;
1632
    }
1633
 
5504 phani.kuma 1634
    private boolean voucherExists(String voucherType) {
1635
        for(int i = 0; i < tableVouchers.getRowCount(); i++) {
1636
            if(voucherType.equals(tableVouchers.getText(i, TABLE_INDEX_VOUCHERS_TYPE))) {
1637
                return false;
1638
            }
1639
        }
1640
        return true;
1641
    }
1642
 
2427 ankur.sing 1643
    /**
1644
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
1645
     * @param vendorId
1646
     * @return true if parameter vendor Id is already added to vendor prices table.
1647
     *      <br>else false
1648
     */
2105 ankur.sing 1649
    private boolean vendorExists(long vendorId) {
1650
        long id;
2427 ankur.sing 1651
        for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
1652
            id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
2105 ankur.sing 1653
            if(vendorId == id) {
1654
                return false;
1655
            }
1992 ankur.sing 1656
        }
2105 ankur.sing 1657
        return true;
1992 ankur.sing 1658
    }
2387 ankur.sing 1659
 
2427 ankur.sing 1660
    /**
3558 rajveer 1661
     * This method is used while adding source prices to ensure that there is only one row in the table for a source.
1662
     * @param sourceId
1663
     * @return true if parameter vendor Id is already added to source prices table.
1664
     *      <br>else false
1665
     */
1666
    private boolean sourceExists(long sourceId) {
1667
        long id;
1668
        for(int i = 0; i < tableSourcePrices.getRowCount(); i++) {
1669
            id = Long.parseLong(tableSourcePrices.getText(i, TABLE_INDEX_SOURCE_PRICING_SOURCE_ID));
1670
            if(sourceId == id) {
1671
                return false;
1672
            }
1673
        }
1674
        return true;
1675
    }
1676
 
1677
    /**
2427 ankur.sing 1678
     * This method is used to check if any of the string item attributes is changed by the user.
2489 ankur.sing 1679
     * @param o1
1680
     * @param o2
2427 ankur.sing 1681
     * @return true if two strings are equal
1682
     *      <br>true if one of them is null and another is empty.
1683
     *      <br>false otherwise
1684
     */
2489 ankur.sing 1685
    private boolean checkParameterIfEqual(Object o1, Object o2) {
1686
        if(o1 == o2) {
2387 ankur.sing 1687
            return true;
1688
        }
2489 ankur.sing 1689
        if(o1 != null && o2 != null && o1.equals(o2)) {
2387 ankur.sing 1690
            return true;
1691
        }
2489 ankur.sing 1692
        if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
2387 ankur.sing 1693
            return true;
1694
        }
1695
        return false;
1696
    }
2489 ankur.sing 1697
 
1698
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
1699
        this.catalogDashboardPanel = catalogDashboardPanel;
1700
    }
4649 phani.kuma 1701
 
1702
    private String compareSellingPricewithBreakEven() {
1703
    	String message = "false";
1704
    	if(newItem.getWeight() == null) {
1705
    		Window.alert("Weight is empty.");
1706
            return message;
1707
    	}
1708
    	if(newItem.getSellingPrice() == null) {
1709
    		Window.alert("Selling Price is empty.");
1710
            return message;
1711
    	}
1712
 
1713
    	double transferPrice;
1714
    	if(newItem.getPreferredVendor() == null && !newItem.getVendorPricesMap().isEmpty()) {
1715
    		transferPrice = -1;
1716
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1717
				if(transferPrice > vendorDetail.getTransferPrice() || transferPrice == -1){
1718
					transferPrice = vendorDetail.getTransferPrice();
1719
				}
1720
			}
1721
    	}
1722
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1723
    		transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();    		
1724
    	}
1725
    	else{
1726
    		Window.alert("Add vendor to Vendor Prices and then change the Selling Price.");
1727
            return message;
1728
    	}
1729
 
1730
    	double weightfactor = Math.ceil((newItem.getWeight() * 1000)/Double.parseDouble(ConfigMap.get("courier_weight_factor")));
1731
		double couriercost = Double.parseDouble(ConfigMap.get("courier_cost_factor")) * weightfactor;
1732
		double costfactor = (Double.parseDouble(ConfigMap.get("transfer_price_percentage")) * transferPrice)/100;
1733
		double breakeven;
1734
		if(costfactor < Double.parseDouble(ConfigMap.get("transfer_price_factor"))){
1735
			breakeven = transferPrice + couriercost + Double.parseDouble(ConfigMap.get("breakeven_additon_factor"));
1736
		}
1737
		else{
1738
			breakeven = (transferPrice + couriercost)/Double.parseDouble(ConfigMap.get("breakeven_divisor"));
1739
		}
1740
 
1741
		if(breakeven > newItem.getSellingPrice()) {
1742
			message = "Selling Price("+newItem.getSellingPrice()+") is less than Breakeven Price("+breakeven+").";
1743
			if(Window.confirm(message)){
1744
				return message;
1745
			}
1746
			else{
1747
				message = "false";
1748
				Window.alert("Updation of Item is canceled.");
1749
				return message;
1750
			}
1751
		}
1752
		else {
1753
			message = "true";
1754
	        return message;
1755
		}
1756
    }
1757
 
1758
    private String checkTransferPriceforPreferredVendor() {
1759
    	String message = "false";
1760
    	if(newItem.getPreferredVendor() == null) {
1761
    		message = "true";
1762
    		return message;
1763
    	}
1764
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
1765
    		double transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();
1766
        	double mintransferPrice = -1;
1767
        	String minvendor = "";
1768
        	boolean compareTransferPrices = false;
1769
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
1770
				if(mintransferPrice > vendorDetail.getTransferPrice() || mintransferPrice == -1){
1771
					mintransferPrice = vendorDetail.getTransferPrice();
1772
					minvendor = Utils.getVendorDesc(vendorDetail.getVendorId());
1773
				}
1774
			}
1775
			if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor()) || item.getVendorPricesMap().isEmpty()) {
1776
				compareTransferPrices = true;
1777
			}
1778
			else {
1779
				double oldmintransferPrice = -1;
1780
				for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
1781
					if(oldmintransferPrice > vendorDetail.getTransferPrice() || oldmintransferPrice == -1){
1782
						oldmintransferPrice = vendorDetail.getTransferPrice();
1783
					}
1784
				}
1785
				if(mintransferPrice < oldmintransferPrice){
1786
					compareTransferPrices = true;
1787
				}
1788
			}
1789
			if(compareTransferPrices && transferPrice > mintransferPrice){
1790
				message = "Transfer Price("+transferPrice+") of Preferred Vendor("+Utils.getVendorDesc(newItem.getPreferredVendor())+") is more than Transfer Price("+mintransferPrice+") of "+minvendor+".";
1791
				if(Window.confirm(message)){
1792
					return message;
1793
				}
1794
				else{
1795
					message = "false";
1796
					Window.alert("Updation of Item is canceled.");
1797
					return message;
1798
				}
1799
			}
1800
			else {
1801
				message = "true";
1802
		        return message;
1803
			}
1804
    	}
1805
    	else{
1806
    		Window.alert("Add vendor to Vendor Prices and then change the Preferred Vendor.");
1807
            return message;
1808
    	}
1809
    }
1810
 
1811
    public void logAuthorization(String message) {
1812
    	String username = catalogDashboardPanel.uname;
1813
    	catalogService.addAuthorizationLog(newItem.getId(), username, message, new AsyncCallback<Boolean>() {
1814
            @Override
1815
            public void onSuccess(Boolean result) {
1816
                if(result) {
1817
                    GWT.log("Event is added");
1818
                }
1819
                else {
1820
                    GWT.log("Error adding the event");
1821
                    Window.alert("Error adding the event");
1822
                }
1823
            }
1824
            @Override
1825
            public void onFailure(Throwable caught) {
1826
                caught.printStackTrace();
1827
                Window.alert("Error while adding the event");
1828
            }
1829
        });
1830
    }
5217 amit.gupta 1831
 
1832
	@Override
1833
	public void setComingSoonStartDate(Date date) {
1834
		this.comingSoonStartDate.setValue(date);
1835
 
1836
	}
1837
 
1838
	@Override
1839
	public void setBestDealsText(String bestDealsText) {
1840
		this.bestDealsText.setValue(bestDealsText);
1841
 
1842
	}
1843
 
1844
	@Override
1845
	public void setExpectedArrivalDate(Date date) {
1846
		this.expectedArrivalDate.setValue(date);
1847
 
1848
	}
1849
 
1850
	@Override
1851
	public String getBestDealsText() {
1852
		return this.bestDealsText.getValue();
1853
	}
1854
 
1855
	@Override
1856
	public Date getComingSoonStartDate() {
1857
		return this.comingSoonStartDate.getValue();
1858
	}
1859
 
1860
	@Override
1861
	public Date getExpectedArrivalDate() {
1862
		return this.expectedArrivalDate.getValue();
1863
	}
1864
	@UiHandler("comingSoonButton")
1865
	void onComingSoonButtonClick(ClickEvent event) {
1866
		ComingSoonDialog cd = new ComingSoonDialog(this);
1867
		cd.show();
1868
	}
5427 amit.gupta 1869
 
1870
	private void createDialog(String changedString) {
1871
        VerticalPanel vp = new VerticalPanel();
1872
        final DialogBox db = new DialogBox();
1873
        db.setText("Changed fields");
1874
 
1875
        vp.add(new Label("Check the fields to update all SKUs with similar entity."));
1876
        vp.add(new Label("--------------------------------------------------------"));
1877
        CheckBox allChecked = new CheckBox("Select all");
1878
        if(optionalChangedValMap.size()>1){
1879
	        allChecked.setName("all");
1880
	        allChecked.addClickHandler(new ClickHandler() {
1881
				@Override
1882
				public void onClick(ClickEvent event) {
1883
					CheckBox cb = (CheckBox)event.getSource();
1884
					VerticalPanel vp = (VerticalPanel)cb.getParent();
1885
					Iterator<Widget> iterator = vp.iterator();
1886
					while(iterator.hasNext()){
1887
						Widget w = iterator.next();
1888
						if(w instanceof CheckBox){
1889
							CheckBox cbox = (CheckBox)w;
1890
							if(cbox.getName()!="all"){
1891
								cbox.setValue(cb.getValue());
1892
							}
1893
						}
1894
					}
1895
					if(cb.getValue()){
1896
						cb.setText("Deselect all");
1897
					}else {
1898
						cb.setText("Select all");
1899
					}
1900
				}
1901
			});
1902
	        vp.add(allChecked);
1903
        }
1904
        String[] changedFields = changedString.split("\n-");
1905
        for(String changeField : changedFields){
1906
        	if(optionalChangedValMap.containsKey(changeField)){
1907
        		CheckBox ch = new CheckBox(changeField); 
1908
        		ch.getElement().getStyle().setPadding(10d, Unit.PX);
1909
        		vp.add(ch);
1910
        	} else {
1911
        		Label l = new Label(changeField);
1912
        		l.getElement().getStyle().setMarginLeft(10d, Unit.PX);
1913
        		l.getElement().getStyle().setPadding(10d, Unit.PX);
1914
        		vp.add(l);
1915
        	}
1916
        }
1917
 
1918
        Button submitButton = new Button();
1919
        submitButton.setText("Update");
1920
        submitButton.addClickHandler(new ClickHandler() {
1921
 
1922
			@Override
1923
			public void onClick(ClickEvent event) {
1924
				Button b  = (Button)event.getSource();
1925
				VerticalPanel vp = (VerticalPanel)b.getParent();
1926
				Iterator<Widget> iterator = vp.iterator();
1927
				while(iterator.hasNext()){
1928
					Widget w = iterator.next();
1929
					if(w instanceof CheckBox){
1930
						CheckBox cbox = (CheckBox)w;
1931
						if(cbox.getName()!="all"){
1932
							if(!cbox.getValue()){
1933
								optionalChangedValMap.remove(cbox.getText());
1934
							}
1935
						}
1936
					}
1937
				}
1938
				db.hide();
1939
				List<Item> items = new ArrayList<Item>();
1940
				items.add(newItem);
1941
				validateNUpdate();
1942
				/*for(Long id : item.getSameItemsWithDifferentColors()){
1943
					catalogService.getItem(id, new AsyncCallback<Item>() {
1944
			            @Override
1945
			            public void onSuccess(Item result) {
1946
			                items.add(e)
1947
			            }
1948
			            @Override
1949
			            public void onFailure(Throwable caught) {
1950
			                caught.printStackTrace();
1951
			                Window.alert("Unable to fetch item details.");
1952
			            }
1953
			        });
1954
				}*/
1955
			}
1956
 
1957
		});
1958
     vp.add(submitButton);
1959
     db.add(vp); 
1960
     db.center();
1961
     db.show();   
1962
    }
1963
 
1964
	private void updateItem(Long itemId) {
1965
		catalogService.getItem(itemId, new AsyncCallback<Item>() {
1966
            @Override
1967
            public void onSuccess(Item result) {
1968
            	final Item res = result;
1969
                if(mandatoryChangedValMap.containsKey(MANDATORY_BRAND)){
1970
                	result.setBrand((String)mandatoryChangedValMap.get(MANDATORY_BRAND));
1971
                }
1972
                if(mandatoryChangedValMap.containsKey(MANDATORY_BEST_DEAL_TEXT)){
1973
                	result.setBestDealsText((String)mandatoryChangedValMap.get(MANDATORY_BEST_DEAL_TEXT));
1974
                }
1975
                if(mandatoryChangedValMap.containsKey(MANDATORY_MODEL_NAME)){
1976
                	result.setModelName((String)mandatoryChangedValMap.get(MANDATORY_MODEL_NAME));
1977
                }
1978
                if(mandatoryChangedValMap.containsKey(MANDATORY_MODEL_NO)){
1979
                	result.setModelNumber((String)mandatoryChangedValMap.get(MANDATORY_MODEL_NO));
1980
                }
1981
                if(mandatoryChangedValMap.containsKey(MANDATORY_WEIGHT)){
1982
                	result.setWeight((Double)mandatoryChangedValMap.get(MANDATORY_WEIGHT));
1983
                }
1984
                if(mandatoryChangedValMap.containsKey(MANDATORY_MRP)){
1985
                	result.setMrp((Double)mandatoryChangedValMap.get(MANDATORY_MRP));
1986
                }
1987
                if(optionalChangedValMap.containsKey(OPTIONAL_PREFERRED_VENDOR)){
1988
                	result.setPreferredVendor((Long)optionalChangedValMap.get(OPTIONAL_PREFERRED_VENDOR));
1989
                }
1990
                if(optionalChangedValMap.containsKey(OPTIONAL_SELLING_PRICE)){
1991
                	result.setSellingPrice((Double)optionalChangedValMap.get(OPTIONAL_SELLING_PRICE));
1992
                }
1993
                if(optionalChangedValMap.containsKey(OPTIONAL_SOURCE_PRICING)){
1994
                	result.setSourcePricesMap((Map<Long, SourcePricings>) optionalChangedValMap.get(OPTIONAL_SOURCE_PRICING));
1995
                }
1996
                if(optionalChangedValMap.containsKey(OPTIONAL_VENDOR_PRICING)){
1997
                	result.setVendorPricesMap((Map<Long, VendorPricings>) optionalChangedValMap.get(OPTIONAL_VENDOR_PRICING));
1998
                }
1999
                catalogService.updateItem(result, new AsyncCallback<Boolean>() {
2000
 
2001
					@Override
2002
					public void onSuccess(Boolean result1) {
2003
						if(result1) {
2004
							Window.alert(res.getId() + " updated Successfully");
2005
						}
2006
 
2007
					}
2008
 
2009
					@Override
2010
					public void onFailure(Throwable caught) {
2011
						caught.printStackTrace();
2012
						Window.alert("Error updating item " + res.getId());
2013
 
2014
					}
2015
				});
2016
            }
2017
            @Override
2018
            public void onFailure(Throwable caught) {
2019
                caught.printStackTrace();
2020
                Window.alert("Unable to fetch item details.");
2021
            }
2022
        });
2023
	}
6241 amit.gupta 2024
 
2025
	@Override
2026
	public void setShowPrice(boolean b) {
2027
		this.showSellingPrice.setValue(b);
2028
	}
2029
 
2030
	@Override
2031
	public boolean isShowPrice() {
2032
		return this.showSellingPrice.getValue();
2033
	}
1961 ankur.sing 2034
}