Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
2066 ankur.sing 1
package in.shop2020.catalog.dashboard.client;
2
 
2105 ankur.sing 3
import in.shop2020.catalog.dashboard.shared.Item;
4
import in.shop2020.catalog.dashboard.shared.Utils;
2119 ankur.sing 5
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
6
import in.shop2020.catalog.dashboard.shared.VendorPricings;
5217 amit.gupta 7
import java.util.Date;
2105 ankur.sing 8
import java.util.HashMap;
9
import java.util.Map;
4725 phani.kuma 10
import java.util.Map.Entry;
2105 ankur.sing 11
import com.google.gwt.core.client.GWT;
12
import com.google.gwt.event.dom.client.ClickEvent;
13
import com.google.gwt.event.dom.client.ClickHandler;
14
import com.google.gwt.uibinder.client.UiBinder;
15
import com.google.gwt.uibinder.client.UiField;
16
import com.google.gwt.uibinder.client.UiHandler;
17
import com.google.gwt.user.client.Window;
18
import com.google.gwt.user.client.rpc.AsyncCallback;
19
import com.google.gwt.user.client.ui.Button;
20
import com.google.gwt.user.client.ui.CheckBox;
21
import com.google.gwt.user.client.ui.DialogBox;
22
import com.google.gwt.user.client.ui.FlexTable;
23
import com.google.gwt.user.client.ui.ListBox;
24
import com.google.gwt.user.client.ui.TextBox;
25
import com.google.gwt.user.client.ui.Widget;
26
import com.google.gwt.user.datepicker.client.DateBox;
27
 
2427 ankur.sing 28
/**
29
 * ItemForm is a DialogBox which is created on the click of Add Item button in ItemActions.
30
 * This contains UI fields to fill up item attributes. It also contains tables for adding
31
 * vendor prices and vendor mapping keys.
32
 *
33
 */
5217 amit.gupta 34
public class ItemForm extends DialogBox implements ComingSoon{
2105 ankur.sing 35
 
36
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
37
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
38
 
5586 phani.kuma 39
    private final static CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
2119 ankur.sing 40
    private final int TABLE_INDEX_VENDORID = 0,
41
                      TABLE_INDEX_VENDOR_DESC = 1, 
42
                      TABLE_INDEX_ITEM_KEY = 2,
43
                      TABLE_INDEX_MOP = 2,
44
                      TABLE_INDEX_DP = 3,
6759 amar.kumar 45
                      TABLE_INDEX_TP = 4,
46
                      TABLE_INDEX_NLC = 5;
5586 phani.kuma 47
 
48
    private static boolean entityIdMandatory = Utils.isEntityIdMandatory();
2105 ankur.sing 49
 
5586 phani.kuma 50
    @UiField TextBox productGroup, catalogItemId;
2105 ankur.sing 51
    @UiField TextBox brand, modelNumber, modelName, color, comments;
7190 amar.kumar 52
    @UiField TextBox mrp, sellingPrice, weight, bestDealText, bestDealValue, bestSellingRank,bestDealsDetailsText,bestDealsDetailsLink, minStockLevel, numOfDaysStock, freebieItemId;
5217 amit.gupta 53
    @UiField DateBox startDate, retireDate, comingSoonStartDate, expectedArrivalDate;
54
    @UiField Button addButton, cancelButton, comingSoonButton;
6241 amit.gupta 55
    @UiField CheckBox defaultForEntity, risky, itemType, hasItemNo, clearance, showSellingPrice;
2105 ankur.sing 56
    @UiField FlexTable headerVendor, vendorTable;
2119 ankur.sing 57
    @UiField FlexTable headerVendorM, vendorTableM;
6838 vikram.rag 58
    @UiField ListBox preferredVendor,preferredInsurer;
2105 ankur.sing 59
 
60
    public ItemForm(){
61
        setText("Add New Item");
62
        setWidget(uiBinder.createAndBindUi(this));
2427 ankur.sing 63
        initVendorKeysHeader();
64
        initVendorPricesHeader();
4762 phani.kuma 65
        preferredVendor.addItem("select");
4725 phani.kuma 66
        for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
67
        	preferredVendor.addItem(e.getValue());
68
        }
5586 phani.kuma 69
        if(!entityIdMandatory) {
70
        	catalogItemId.setEnabled(false);
71
        }
6904 amit.gupta 72
        preferredInsurer.addItem("select", "0");
6838 vikram.rag 73
        for(Entry<Long, String> e : Utils.getAllInsurers().entrySet()){
74
        	preferredInsurer.addItem(e.getValue(),e.getKey().toString());
75
        }
76
 
2105 ankur.sing 77
    }
78
 
2427 ankur.sing 79
    /**
80
     * initialises vendor item key table header. Creates an Add button and
81
     * adds click event listener to it to create and pop up a dialog for adding 
82
     * a new vendor item key. 
83
     */
84
    private void initVendorKeysHeader(){
2119 ankur.sing 85
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
86
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
2359 ankur.sing 87
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
2119 ankur.sing 88
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
89
 
90
        headerVendorM.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
2359 ankur.sing 91
        headerVendorM.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor");
2119 ankur.sing 92
        headerVendorM.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
93
 
2359 ankur.sing 94
        headerVendorM.getCellFormatter().setVisible(0, TABLE_INDEX_VENDORID, false);
95
 
2119 ankur.sing 96
        Button addButton = new Button("Add");
97
        headerVendorM.setWidget(0, TABLE_INDEX_ITEM_KEY + 1, addButton);
98
        addButton.addClickHandler(new ClickHandler() {
99
            @Override
100
            public void onClick(ClickEvent event) {
2126 ankur.sing 101
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
102
                        modelNumber.getText().trim(), color.getText().trim());
2119 ankur.sing 103
                vendorMappingDialog.updateButton.setText("Add");
104
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
105
                    @Override
106
                    public boolean onUpdate(String key, long vendorId) {
107
                        final int row = vendorTableM.getRowCount();
108
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
109
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
2359 ankur.sing 110
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
2119 ankur.sing 111
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
112
 
113
                        vendorTableM.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
114
                        vendorTableM.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
115
                        vendorTableM.setText(row, TABLE_INDEX_ITEM_KEY, key);
116
                        Button removeButton = new Button("X");
117
                        vendorTableM.setWidget(row, TABLE_INDEX_ITEM_KEY + 1, removeButton);
2359 ankur.sing 118
 
119
                        vendorTableM.getCellFormatter().setVisible(row, TABLE_INDEX_VENDORID, false);
2119 ankur.sing 120
                        removeButton.addClickHandler(new ClickHandler() {
121
                            @Override
122
                            public void onClick(ClickEvent event) {
123
                                vendorTableM.removeRow(row);
124
                            }
125
                        });
126
                        return true;
127
                    }
128
                });
129
                vendorMappingDialog.show();
130
            }
131
        });
132
    }
2105 ankur.sing 133
 
2427 ankur.sing 134
    /**
135
     * initialises vendor prices table header. Creates an Add button and
136
     * adds click event listener to it to create and pop up a dialog for adding 
137
     * a prices for a new vendor 
138
     */
139
    private void initVendorPricesHeader(){
2105 ankur.sing 140
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
141
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
142
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
143
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
144
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
6759 amar.kumar 145
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_NLC, "128px");
146
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_NLC + 1, "50px");
2105 ankur.sing 147
 
148
        headerVendor.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
2359 ankur.sing 149
        headerVendor.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor");
2105 ankur.sing 150
        headerVendor.setText(0, TABLE_INDEX_MOP, "MOP");
151
        headerVendor.setText(0, TABLE_INDEX_DP, "Dealer Price");
152
        headerVendor.setText(0, TABLE_INDEX_TP, "Transfer Price");
6759 amar.kumar 153
        headerVendor.setText(0, TABLE_INDEX_NLC, "NLC");
2119 ankur.sing 154
 
2359 ankur.sing 155
        headerVendor.getCellFormatter().setVisible(0, TABLE_INDEX_VENDORID, false);
156
 
2119 ankur.sing 157
        Button addButton = new Button("Add");
6759 amar.kumar 158
        headerVendor.setWidget(0, TABLE_INDEX_NLC + 1, addButton);
2119 ankur.sing 159
        addButton.addClickHandler(new ClickHandler() {
160
            @Override
161
            public void onClick(ClickEvent event) {
162
                VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
163
                vendorPricesDialog.updateButton.setText("Add");
164
                vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
165
                    @Override
6759 amar.kumar 166
                    public boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId) {
2119 ankur.sing 167
                        if(!vendorExists(vendorId)) {
168
                            Window.alert("Vendor already exists");
169
                            return false;
170
                        }
171
                        /*if(!validateVendorPrices(mop, dp, tp)) {
172
                            return false;
173
                        }*/
174
                        final int row = vendorTable.getRowCount();
175
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
176
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
177
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
178
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
179
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
6759 amar.kumar 180
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC, "128px");
181
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC + 1, "50px");
2119 ankur.sing 182
 
183
                        vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
184
                        vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
185
                        vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
186
                        vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
187
                        vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
6759 amar.kumar 188
                        vendorTable.setText(row, TABLE_INDEX_NLC, nlc + "");
2359 ankur.sing 189
 
190
                        vendorTable.getCellFormatter().setVisible(row, TABLE_INDEX_VENDORID, false);
191
 
2119 ankur.sing 192
                        Button removeButton = new Button("X");
6759 amar.kumar 193
                        vendorTable.setWidget(row, TABLE_INDEX_NLC + 1, removeButton);
2119 ankur.sing 194
                        removeButton.addClickHandler(new ClickHandler() {
195
                            @Override
196
                            public void onClick(ClickEvent event) {
197
                                vendorTable.removeRow(row);
198
                            }
199
                        });
200
                        return true;
201
                    }
202
                });
203
                vendorPricesDialog.show();
204
            }
205
        });
2105 ankur.sing 206
    }
207
 
208
    @UiHandler("addButton")
209
    /**
2359 ankur.sing 210
     * On add button click a new Item instance is created and all the information from UI fields is dumped in this item instance.
2427 ankur.sing 211
     * This item instance is then passed to the service to be added to the database.
2105 ankur.sing 212
     */
213
    void addItem(ClickEvent event) {
5586 phani.kuma 214
    	if(entityIdMandatory) {
215
    		long entityId = 0;
216
    		try {
217
                if(!catalogItemId.getText().trim().isEmpty()) {
218
                    entityId = Long.parseLong(catalogItemId.getText().trim());
219
                    if(entityId <= 0) {
220
                        throw new NumberFormatException("Invalid value of Catalog Item Id");
221
                    }
222
                }
223
                else {
224
                	Window.alert("Catalog Item Id can not be empty");
225
                	return;
226
                }
227
            } catch(NumberFormatException ex) {
228
                Window.alert("Invalid value of Catalog Item Id");
2119 ankur.sing 229
                return;
230
            }
5586 phani.kuma 231
	    	catalogService.checkEntityId(entityId, new AsyncCallback<Boolean>() {
232
	            @Override
233
	            public void onFailure(Throwable caught) {
234
	                GWT.log("Error checking Catalog Item Id");
235
	                Window.alert("Error checking Catalog Item Id");
236
	                return;
237
	            }
238
	            @Override
239
	            public void onSuccess(Boolean result) {
240
		        	if(!result) {
241
	                    Window.alert("Invalid value of Catalog Item Id");
242
	                    return;
243
	                }
244
	                addNewItem();
245
		        }
246
	        });
247
    	}
248
    	else {
249
	        catalogService.checkSimilarItem(brand.getText().trim(), modelNumber.getText().trim(),
250
	        		modelName.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
251
	            @Override
252
	            public void onFailure(Throwable caught) {
253
	                GWT.log("Error checking similar item");
254
	                Window.alert("Error checking similar item");
255
	                return;
256
	            }
257
	            @Override
258
	            public void onSuccess(Long result) {
259
	                if(result != 0) {
260
	                    Window.alert("Similar product exists with Item Id " + result);
261
	                    return;
262
	                }
263
	                addNewItem();
264
	            }
265
	        });
266
    	}
2119 ankur.sing 267
    }
268
 
2126 ankur.sing 269
    private void addNewItem() {
2105 ankur.sing 270
        Item item = new Item();
271
 
4762 phani.kuma 272
        if(!productGroup.getText().trim().isEmpty()) {
273
        	item.setProductGroup(productGroup.getText().trim());
274
        }
275
        else {
276
        	Window.alert("Product Group can not be empty.");
277
            return;
278
        }
5586 phani.kuma 279
 
280
        if(entityIdMandatory) {
281
	        try {
282
	            if(!catalogItemId.getText().trim().isEmpty()) {
283
	                long entityId = Long.parseLong(catalogItemId.getText().trim());
284
	                if(entityId <= 0) {
285
	                    throw new NumberFormatException("Invalid value of Catalog Item Id");
286
	                }
287
	                item.setCatalogItemId(entityId);
288
	            }
289
	            else {
290
	            	Window.alert("Catalog Item Id can not be empty");
291
	            	return;
292
	            }
293
	        } catch(NumberFormatException ex) {
294
	            Window.alert("Invalid value of Catalog Item Id");
295
	            return;
296
	        }
297
        }
298
 
2105 ankur.sing 299
        item.setBrand(brand.getText().trim());
300
        item.setModelNumber(modelNumber.getText().trim());
301
        item.setModelName(modelName.getText().trim());
302
        item.setColor(color.getText().trim());
303
        item.setComments(comments.getText().trim());
304
        try {
2126 ankur.sing 305
            if(!mrp.getText().trim().isEmpty()) {
306
                double mrpValue = Double.parseDouble(mrp.getText().trim());
307
                if(mrpValue <= 0) {
308
                    throw new NumberFormatException("Negative value of MRP");
309
                }
310
                item.setMrp(mrpValue);
2105 ankur.sing 311
            }
312
        } catch(NumberFormatException ex) {
2126 ankur.sing 313
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
2105 ankur.sing 314
            return;
315
        }
316
        try {
2126 ankur.sing 317
            if(!sellingPrice.getText().trim().isEmpty()) {
2427 ankur.sing 318
                double spValue = Double.parseDouble(sellingPrice.getText().trim());
319
                if(spValue <= 0) {
320
                    throw new NumberFormatException("Negative value of Selling price");
321
                }
322
                item.setSellingPrice(spValue);
2126 ankur.sing 323
            }
2105 ankur.sing 324
        } catch(NumberFormatException ex) {
2126 ankur.sing 325
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
2105 ankur.sing 326
            return;
327
        }
328
        try {
2126 ankur.sing 329
            if(!weight.getText().trim().isEmpty()) {
2105 ankur.sing 330
                double wtValue = Double.parseDouble(weight.getText().trim());
2126 ankur.sing 331
                if(wtValue <= 0) {
2105 ankur.sing 332
                    throw new NumberFormatException("Negative value of Weight");
333
                }
334
                item.setWeight(wtValue);
335
            }
336
        } catch(NumberFormatException ex) {
2126 ankur.sing 337
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
2105 ankur.sing 338
            return;
339
        }
340
        try {
341
            if(!startDate.getTextBox().getText().trim().equals("")) {
342
                item.setStartDate(startDate.getValue().getTime());
343
            }
344
        } catch(Exception ex) {
345
            Window.alert("Invalid start date format");
346
            return;
347
        }
5217 amit.gupta 348
        if(comingSoonStartDate.getValue()==null){
349
        	item.setComingSoonStartDate(null);
350
        }else {
351
        	item.setComingSoonStartDate(comingSoonStartDate.getValue().getTime());
352
        }
353
        if(expectedArrivalDate.getValue()==null){
354
        	item.setExpectedArrivalDate(null);
355
        }else {
356
        	item.setExpectedArrivalDate(expectedArrivalDate.getValue().getTime());
357
        }
2105 ankur.sing 358
        item.setBestDealsText(bestDealText.getText().trim());
6777 vikram.rag 359
        item.setBestDealsDetailsText(bestDealsDetailsText.getText().trim());
360
        item.setBestDealsDetailsLink(bestDealsDetailsLink.getText().trim());
2105 ankur.sing 361
        try {
362
            if(!bestDealValue.getText().trim().equals("")) {
363
                double bdValue = Double.parseDouble(bestDealValue.getText().trim());
364
                if(bdValue < 0) {
365
                    throw new NumberFormatException("Negative value of BestDealValue");
366
                }
367
                item.setBestDealsValue(bdValue);
368
            }
369
        } catch(NumberFormatException ex) {
370
            Window.alert("Invalid best deal value format");
371
            return;
372
        }
373
        try {
374
            if(!bestSellingRank.getText().trim().equals("")) {
375
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
376
                if(bsrValue < 0) {
377
                    throw new NumberFormatException("Negative value of Best Selling Rank");
378
                }
379
                item.setBestSellingRank(bsrValue);
380
            }
381
        } catch(NumberFormatException ex) {
382
            Window.alert("Invalid best selling rank format");
383
            return;
384
        }
6813 amar.kumar 385
 
386
        try {
387
	        if(!minStockLevel.getText().trim().equals("")) {
388
	            long msl = Long.parseLong(minStockLevel.getText().trim());
389
	            if(msl < 0) {
390
	                throw new NumberFormatException("Negative value of Min Stock Value");
391
	            }
392
	            item.setMinStockLevel(msl);
6830 amar.kumar 393
	        }else {
394
	        	item.setMinStockLevel(0L);
6813 amar.kumar 395
	        }
396
	    } catch(NumberFormatException ex) {
397
	    	item.setMinStockLevel(0L);
398
	        Window.alert("Invalid min Stock Level. Setting it to zero(0)");
399
	        return;
400
	    }
401
 
402
	    try {
403
	        if(!numOfDaysStock.getText().trim().equals("")) {
404
	            Long nds = Long.parseLong(numOfDaysStock.getText().trim());
405
	            if(nds < 0) {
406
	                throw new NumberFormatException("Negative value of Num of Days Of Stock");
407
	            }
408
	            item.setNumOfDaysStock(nds.intValue());
6830 amar.kumar 409
	        } else {
410
	        	item.setNumOfDaysStock(0);
6813 amar.kumar 411
	        }
412
	    } catch(NumberFormatException ex) {
413
	    	item.setNumOfDaysStock(0);
414
	        Window.alert("Invalid min Stock Level. Setting it to zero(0)");
415
	        return;
416
	    }
417
 
7190 amar.kumar 418
	    try {
419
            if(!freebieItemId.getText().trim().equals("")) {
420
                long freeItemId = Long.parseLong(freebieItemId.getText().trim());
421
                if(freeItemId < 0) {
422
                    throw new NumberFormatException("Negative value of freebieItemId ");
423
                }
424
                item.setFreebieItemId(new Long(freeItemId));
425
            }
426
        } catch(NumberFormatException ex) {
427
            Window.alert("Invalid freebie ItemId");
428
            return;
429
        }
430
 
2105 ankur.sing 431
        item.setDefaultForEntity(defaultForEntity.getValue());
2252 ankur.sing 432
        item.setRisky(risky.getValue());
5384 phani.kuma 433
        item.setHasItemNo(hasItemNo.getValue());
434
        item.setItemType(itemType.getValue());
5460 phani.kuma 435
        item.setClearance(clearance.getValue());
4762 phani.kuma 436
        if(preferredVendor.getSelectedIndex() == 0) {
437
        	Window.alert("Invalid Vendor Selected");
438
            return;
439
        }
440
    	else {
441
    		item.setPreferredVendor(Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex())));
442
    	}
2105 ankur.sing 443
 
6838 vikram.rag 444
        item.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
445
 
446
 
2119 ankur.sing 447
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
2105 ankur.sing 448
          Add the instance to map and set the map to the item instance created above.*/
2119 ankur.sing 449
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
450
        VendorPricings v;
2105 ankur.sing 451
        for(int row = 0; row < vendorTable.getRowCount(); row++) {
2119 ankur.sing 452
            v = new VendorPricings();
2105 ankur.sing 453
            v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
454
            v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
455
            v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
456
            v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
6759 amar.kumar 457
            v.setNlc(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_NLC)));
2105 ankur.sing 458
            vendorPrices.put(v.getVendorId(), v);
459
        }
2119 ankur.sing 460
        item.setVendorPricesMap(vendorPrices);
2105 ankur.sing 461
 
2119 ankur.sing 462
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
463
        Add the instance to map and set the map to the item instance created above.*/
2359 ankur.sing 464
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
2119 ankur.sing 465
        VendorItemMapping vMapping;
466
        for(int row = 0; row < vendorTableM.getRowCount(); row++) {
467
            vMapping = new VendorItemMapping();
468
            vMapping.setItemKey(vendorTableM.getText(row, TABLE_INDEX_ITEM_KEY));
469
            vMapping.setVendorId(Long.parseLong(vendorTableM.getText(row, TABLE_INDEX_VENDORID)));
2359 ankur.sing 470
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + vMapping.getItemKey(), vMapping);
2119 ankur.sing 471
        }
2359 ankur.sing 472
        item.setVendorKeysMap(vendorMappings);
2119 ankur.sing 473
 
474
        if(!Utils.validateItem(item)) {
475
            return;
476
        }
477
 
2427 ankur.sing 478
        /*Service method to add item. */
2105 ankur.sing 479
        catalogService.addItem(item, new AsyncCallback<Long>() {
480
            @Override
481
            public void onSuccess(Long result) {
482
                if(result == null || result == 0) {
483
                    Window.alert("Error while adding item");
484
                    return;
485
                }
486
                Window.alert("Item added successfully. Id = " + result);
487
                hide();
488
            }
489
            @Override
490
            public void onFailure(Throwable caught) {
2427 ankur.sing 491
                caught.printStackTrace();
2105 ankur.sing 492
                Window.alert("Error while adding item");
493
            }
494
        });
495
    }
496
 
497
    @UiHandler("cancelButton")
498
    void closeForm(ClickEvent event) {
499
        this.hide();
500
    }
2427 ankur.sing 501
 
2105 ankur.sing 502
    /**
503
     * Checks if vendor details already exists corresponding to the vendor Id parameter. 
504
     */
505
    private boolean vendorExists(long vendorId) {
506
        long id;
507
        for(int i = 0; i < vendorTable.getRowCount(); i++) {
508
            id = Long.parseLong(vendorTable.getText(i, TABLE_INDEX_VENDORID));
509
            if(vendorId == id) {
510
                return false;
511
            }
512
        }
513
        return true;
514
    }
515
 
516
    /**
2119 ankur.sing 517
     * validate vendor prices (MOP, DealerPrice, TransferPrice)
2105 ankur.sing 518
     */
2566 chandransh 519
    @SuppressWarnings("unused")
520
	private boolean validateVendorPrices(double mop, double dp, double tp) {
2105 ankur.sing 521
        double mrpValue;
522
        try {
523
            mrpValue = Double.parseDouble(mrp.getText().trim());
524
        } catch (NumberFormatException ex) {
525
            Window.alert("Invalid MRP value.");
526
            return false;
527
        }
528
        if(mrpValue < mop) {
529
            Window.alert("MOP cannot be more than MRP.");
530
            return false;
531
        }
532
        if(tp > mop) {
533
            Window.alert("Transfer Price cannot be more than MOP.");
534
            return false;
535
        }
536
        return true;
537
    }
5217 amit.gupta 538
 
539
	@UiHandler("comingSoonButton")
540
	void onComingSoonButtonClick(ClickEvent event) {
541
		ComingSoonDialog cd = new ComingSoonDialog(this);
542
		cd.show();
543
	}
544
 
545
	public void setComingSoonStartDate(Date date){
546
		this.comingSoonStartDate.setValue(date);
547
	}
548
	public void setBestDealsText(String bestDealsText){
549
		this.bestDealText.setText(bestDealsText);
550
	}
551
 
552
	public void setExpectedArrivalDate(Date date){
553
		this.expectedArrivalDate.setValue(date);
554
	}
555
 
6241 amit.gupta 556
	public void setShowPrice(boolean b){
557
		this.showSellingPrice.setValue(b);
558
	}
559
 
560
	public boolean isShowPrice(){
561
		return this.showSellingPrice.getValue();
562
	}
563
 
5217 amit.gupta 564
	@Override
565
	public String getBestDealsText() {
566
		return this.bestDealText.getValue();
567
	}
568
 
569
	@Override
570
	public Date getComingSoonStartDate() {
571
		return this.comingSoonStartDate.getValue();
572
	}
573
 
574
	@Override
575
	public Date getExpectedArrivalDate() {
6241 amit.gupta 576
		return this.expectedArrivalDate.getValue();
5217 amit.gupta 577
	}
6777 vikram.rag 578
 
579
	public TextBox getBestDealsDetailsText() {
580
		return bestDealsDetailsText;
581
	}
582
 
583
	public void setBestDealsDetailsText(TextBox bestDealsDetailsText) {
584
		this.bestDealsDetailsText = bestDealsDetailsText;
585
	}
586
 
587
	public TextBox getBestDealsDetailsLink() {
588
		return bestDealsDetailsLink;
589
	}
590
 
591
	public void setBestDealsDetailsLink(TextBox bestDealsDetailsLink) {
592
		this.bestDealsDetailsLink = bestDealsDetailsLink;
593
	}
2066 ankur.sing 594
}