Subversion Repositories SmartDukaan

Rev

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