Subversion Repositories SmartDukaan

Rev

Rev 7260 | Rev 8901 | 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;
7291 vikram.rag 51
    @UiField TextBox brand, modelNumber, modelName, color, comments,holdInventory,defaultInventory;
52
    @UiField TextBox mrp, sellingPrice, weight, bestDealText, bestDealValue, bestSellingRank,bestDealsDetailsText,bestDealsDetailsLink, minStockLevel, numOfDaysStock, freebieItemId,asin;
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
        }
7291 vikram.rag 430
	    item.setAsin(asin.getText().trim());
431
 
432
        try {
433
            if(!holdInventory.getText().trim().equals("")) {
434
                long hold_inventory = Long.parseLong(holdInventory.getText().trim());
435
                if(hold_inventory < 0) {
436
                    throw new NumberFormatException("Negative value of Hold Inventory");
437
                }
438
                item.setHoldInventory(hold_inventory);
439
            }
440
        } catch(NumberFormatException ex) {
441
            Window.alert("Invalid Hold Inventory Value");
442
            return;
443
        }
444
 
445
        try {
446
            if(!defaultInventory.getText().trim().equals("")) {
447
                long default_inventory = Long.parseLong(defaultInventory.getText().trim());
448
                if(default_inventory < 0) {
449
                    throw new NumberFormatException("Negative value of Default Inventory");
450
                }
451
                item.setDefaultInventory(default_inventory);
452
            }
453
        } catch(NumberFormatException ex) {
454
            Window.alert("Invalid Default Inventory Value");
455
            return;
456
        }
2105 ankur.sing 457
        item.setDefaultForEntity(defaultForEntity.getValue());
2252 ankur.sing 458
        item.setRisky(risky.getValue());
5384 phani.kuma 459
        item.setHasItemNo(hasItemNo.getValue());
460
        item.setItemType(itemType.getValue());
4762 phani.kuma 461
        if(preferredVendor.getSelectedIndex() == 0) {
462
        	Window.alert("Invalid Vendor Selected");
463
            return;
464
        }
465
    	else {
466
    		item.setPreferredVendor(Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex())));
467
    	}
2105 ankur.sing 468
 
6838 vikram.rag 469
        item.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
470
 
471
 
2119 ankur.sing 472
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
2105 ankur.sing 473
          Add the instance to map and set the map to the item instance created above.*/
2119 ankur.sing 474
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
475
        VendorPricings v;
2105 ankur.sing 476
        for(int row = 0; row < vendorTable.getRowCount(); row++) {
2119 ankur.sing 477
            v = new VendorPricings();
2105 ankur.sing 478
            v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
479
            v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
480
            v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
481
            v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
6759 amar.kumar 482
            v.setNlc(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_NLC)));
2105 ankur.sing 483
            vendorPrices.put(v.getVendorId(), v);
484
        }
2119 ankur.sing 485
        item.setVendorPricesMap(vendorPrices);
2105 ankur.sing 486
 
2119 ankur.sing 487
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
488
        Add the instance to map and set the map to the item instance created above.*/
2359 ankur.sing 489
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
2119 ankur.sing 490
        VendorItemMapping vMapping;
491
        for(int row = 0; row < vendorTableM.getRowCount(); row++) {
492
            vMapping = new VendorItemMapping();
493
            vMapping.setItemKey(vendorTableM.getText(row, TABLE_INDEX_ITEM_KEY));
494
            vMapping.setVendorId(Long.parseLong(vendorTableM.getText(row, TABLE_INDEX_VENDORID)));
2359 ankur.sing 495
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + vMapping.getItemKey(), vMapping);
2119 ankur.sing 496
        }
2359 ankur.sing 497
        item.setVendorKeysMap(vendorMappings);
2119 ankur.sing 498
 
499
        if(!Utils.validateItem(item)) {
500
            return;
501
        }
502
 
2427 ankur.sing 503
        /*Service method to add item. */
2105 ankur.sing 504
        catalogService.addItem(item, new AsyncCallback<Long>() {
505
            @Override
506
            public void onSuccess(Long result) {
507
                if(result == null || result == 0) {
508
                    Window.alert("Error while adding item");
509
                    return;
510
                }
511
                Window.alert("Item added successfully. Id = " + result);
512
                hide();
513
            }
514
            @Override
515
            public void onFailure(Throwable caught) {
2427 ankur.sing 516
                caught.printStackTrace();
2105 ankur.sing 517
                Window.alert("Error while adding item");
518
            }
519
        });
520
    }
521
 
522
    @UiHandler("cancelButton")
523
    void closeForm(ClickEvent event) {
524
        this.hide();
525
    }
2427 ankur.sing 526
 
2105 ankur.sing 527
    /**
528
     * Checks if vendor details already exists corresponding to the vendor Id parameter. 
529
     */
530
    private boolean vendorExists(long vendorId) {
531
        long id;
532
        for(int i = 0; i < vendorTable.getRowCount(); i++) {
533
            id = Long.parseLong(vendorTable.getText(i, TABLE_INDEX_VENDORID));
534
            if(vendorId == id) {
535
                return false;
536
            }
537
        }
538
        return true;
539
    }
540
 
541
    /**
2119 ankur.sing 542
     * validate vendor prices (MOP, DealerPrice, TransferPrice)
2105 ankur.sing 543
     */
2566 chandransh 544
    @SuppressWarnings("unused")
545
	private boolean validateVendorPrices(double mop, double dp, double tp) {
2105 ankur.sing 546
        double mrpValue;
547
        try {
548
            mrpValue = Double.parseDouble(mrp.getText().trim());
549
        } catch (NumberFormatException ex) {
550
            Window.alert("Invalid MRP value.");
551
            return false;
552
        }
553
        if(mrpValue < mop) {
554
            Window.alert("MOP cannot be more than MRP.");
555
            return false;
556
        }
557
        if(tp > mop) {
558
            Window.alert("Transfer Price cannot be more than MOP.");
559
            return false;
560
        }
561
        return true;
562
    }
5217 amit.gupta 563
 
564
	@UiHandler("comingSoonButton")
565
	void onComingSoonButtonClick(ClickEvent event) {
566
		ComingSoonDialog cd = new ComingSoonDialog(this);
567
		cd.show();
568
	}
569
 
570
	public void setComingSoonStartDate(Date date){
571
		this.comingSoonStartDate.setValue(date);
572
	}
573
	public void setBestDealsText(String bestDealsText){
574
		this.bestDealText.setText(bestDealsText);
575
	}
576
 
577
	public void setExpectedArrivalDate(Date date){
578
		this.expectedArrivalDate.setValue(date);
579
	}
580
 
6241 amit.gupta 581
	public void setShowPrice(boolean b){
582
		this.showSellingPrice.setValue(b);
583
	}
584
 
585
	public boolean isShowPrice(){
586
		return this.showSellingPrice.getValue();
587
	}
588
 
5217 amit.gupta 589
	@Override
590
	public String getBestDealsText() {
591
		return this.bestDealText.getValue();
592
	}
593
 
594
	@Override
595
	public Date getComingSoonStartDate() {
596
		return this.comingSoonStartDate.getValue();
597
	}
598
 
599
	@Override
600
	public Date getExpectedArrivalDate() {
6241 amit.gupta 601
		return this.expectedArrivalDate.getValue();
5217 amit.gupta 602
	}
6777 vikram.rag 603
 
604
	public TextBox getBestDealsDetailsText() {
605
		return bestDealsDetailsText;
606
	}
607
 
608
	public void setBestDealsDetailsText(TextBox bestDealsDetailsText) {
609
		this.bestDealsDetailsText = bestDealsDetailsText;
610
	}
611
 
612
	public TextBox getBestDealsDetailsLink() {
613
		return bestDealsDetailsLink;
614
	}
615
 
616
	public void setBestDealsDetailsLink(TextBox bestDealsDetailsLink) {
617
		this.bestDealsDetailsLink = bestDealsDetailsLink;
618
	}
2066 ankur.sing 619
}