Subversion Repositories SmartDukaan

Rev

Rev 7291 | Rev 8904 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7291 Rev 8901
Line 31... Line 31...
31
 * vendor prices and vendor mapping keys.
31
 * vendor prices and vendor mapping keys.
32
 *
32
 *
33
 */
33
 */
34
public class ItemForm extends DialogBox implements ComingSoon{
34
public class ItemForm extends DialogBox implements ComingSoon{
35
 
35
 
36
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
36
	interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
37
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
37
	private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
38
    
38
 
39
    private final static CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
39
	private final static CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
40
    private final int TABLE_INDEX_VENDORID = 0,
40
	private final int TABLE_INDEX_VENDORID = 0,
41
                      TABLE_INDEX_VENDOR_DESC = 1, 
41
	TABLE_INDEX_VENDOR_DESC = 1, 
42
                      TABLE_INDEX_ITEM_KEY = 2,
42
	TABLE_INDEX_ITEM_KEY = 2,
43
                      TABLE_INDEX_MOP = 2,
43
	TABLE_INDEX_MOP = 2,
44
                      TABLE_INDEX_DP = 3,
44
	TABLE_INDEX_DP = 3,
45
                      TABLE_INDEX_TP = 4,
45
	TABLE_INDEX_TP = 4,
46
                      TABLE_INDEX_NLC = 5;
46
	TABLE_INDEX_NLC = 5;
47
    
47
 
48
    private static boolean entityIdMandatory = Utils.isEntityIdMandatory();
48
	private static boolean entityIdMandatory = Utils.isEntityIdMandatory();
49
 
49
 
50
    @UiField TextBox productGroup, catalogItemId;
50
	@UiField TextBox productGroup, catalogItemId,existingItemId;
51
    @UiField TextBox brand, modelNumber, modelName, color, comments,holdInventory,defaultInventory;
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;
52
	@UiField TextBox mrp, sellingPrice, weight, bestDealText, bestDealValue, bestSellingRank,bestDealsDetailsText,bestDealsDetailsLink, minStockLevel, numOfDaysStock, freebieItemId,asin;
53
    @UiField DateBox startDate, retireDate, comingSoonStartDate, expectedArrivalDate;
53
	@UiField DateBox startDate, retireDate, comingSoonStartDate, expectedArrivalDate;
54
    @UiField Button addButton, cancelButton, comingSoonButton;
54
	@UiField Button addButton, cancelButton, comingSoonButton,searchButton;
55
    @UiField CheckBox defaultForEntity, risky, itemType, hasItemNo, clearance, showSellingPrice;
55
	@UiField CheckBox defaultForEntity, risky, itemType, hasItemNo, clearance, showSellingPrice;
56
    @UiField FlexTable headerVendor, vendorTable;
56
	@UiField FlexTable headerVendor, vendorTable;
57
    @UiField FlexTable headerVendorM, vendorTableM;
57
	@UiField FlexTable headerVendorM, vendorTableM;
58
    @UiField ListBox preferredVendor,preferredInsurer;
58
	@UiField ListBox preferredVendor,preferredInsurer;
59
    
59
 
60
    public ItemForm(){
60
	public ItemForm(){
61
        setText("Add New Item");
61
		setText("Add New Item");
62
        setWidget(uiBinder.createAndBindUi(this));
62
		setWidget(uiBinder.createAndBindUi(this));
63
        initVendorKeysHeader();
63
		initVendorKeysHeader();
64
        initVendorPricesHeader();
64
		initVendorPricesHeader();
65
        preferredVendor.addItem("select");
65
		preferredVendor.addItem("select");
66
        for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
66
		for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
67
        	preferredVendor.addItem(e.getValue());
67
			preferredVendor.addItem(e.getValue());
68
        }
68
		}
69
        if(!entityIdMandatory) {
69
		if(!entityIdMandatory) {
70
        	catalogItemId.setEnabled(false);
70
			catalogItemId.setEnabled(false);
71
        }
71
		}
72
        preferredInsurer.addItem("select", "0");
72
		preferredInsurer.addItem("select", "0");
73
        for(Entry<Long, String> e : Utils.getAllInsurers().entrySet()){
73
		for(Entry<Long, String> e : Utils.getAllInsurers().entrySet()){
74
        	preferredInsurer.addItem(e.getValue(),e.getKey().toString());
74
			preferredInsurer.addItem(e.getValue(),e.getKey().toString());
75
        }
75
		}
76
        
76
 
77
    }
77
	}
78
    
78
 
79
    /**
79
	/**
80
     * initialises vendor item key table header. Creates an Add button and
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 
81
	 * adds click event listener to it to create and pop up a dialog for adding 
82
     * a new vendor item key. 
82
	 * a new vendor item key. 
83
     */
83
	 */
84
    private void initVendorKeysHeader(){
84
	private void initVendorKeysHeader(){
85
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
85
		headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
86
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
86
		headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
87
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
87
		headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
88
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
88
		headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
89
 
89
 
90
        headerVendorM.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
90
		headerVendorM.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
91
        headerVendorM.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor");
91
		headerVendorM.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor");
92
        headerVendorM.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
92
		headerVendorM.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
93
        
93
 
94
        headerVendorM.getCellFormatter().setVisible(0, TABLE_INDEX_VENDORID, false);
94
		headerVendorM.getCellFormatter().setVisible(0, TABLE_INDEX_VENDORID, false);
95
        
95
 
96
        Button addButton = new Button("Add");
96
		Button addButton = new Button("Add");
97
        headerVendorM.setWidget(0, TABLE_INDEX_ITEM_KEY + 1, addButton);
97
		headerVendorM.setWidget(0, TABLE_INDEX_ITEM_KEY + 1, addButton);
98
        addButton.addClickHandler(new ClickHandler() {
98
		addButton.addClickHandler(new ClickHandler() {
99
            @Override
99
			@Override
100
            public void onClick(ClickEvent event) {
100
			public void onClick(ClickEvent event) {
101
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
101
				VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
102
                        modelNumber.getText().trim(), color.getText().trim());
102
						modelNumber.getText().trim(), color.getText().trim());
103
                vendorMappingDialog.updateButton.setText("Add");
103
				vendorMappingDialog.updateButton.setText("Add");
104
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
104
				vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
105
                    @Override
105
					@Override
106
                    public boolean onUpdate(String key, long vendorId) {
106
					public boolean onUpdate(String key, long vendorId) {
107
                        final int row = vendorTableM.getRowCount();
107
						final int row = vendorTableM.getRowCount();
108
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
108
						vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
109
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
109
						vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
110
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
110
						vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "400px");
111
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
111
						vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
112
                        
112
 
113
                        vendorTableM.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
113
						vendorTableM.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
114
                        vendorTableM.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
114
						vendorTableM.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
115
                        vendorTableM.setText(row, TABLE_INDEX_ITEM_KEY, key);
115
						vendorTableM.setText(row, TABLE_INDEX_ITEM_KEY, key);
116
                        Button removeButton = new Button("X");
116
						Button removeButton = new Button("X");
117
                        vendorTableM.setWidget(row, TABLE_INDEX_ITEM_KEY + 1, removeButton);
117
						vendorTableM.setWidget(row, TABLE_INDEX_ITEM_KEY + 1, removeButton);
118
                        
118
 
119
                        vendorTableM.getCellFormatter().setVisible(row, TABLE_INDEX_VENDORID, false);
119
						vendorTableM.getCellFormatter().setVisible(row, TABLE_INDEX_VENDORID, false);
120
                        removeButton.addClickHandler(new ClickHandler() {
120
						removeButton.addClickHandler(new ClickHandler() {
121
                            @Override
121
							@Override
122
                            public void onClick(ClickEvent event) {
122
							public void onClick(ClickEvent event) {
123
                                vendorTableM.removeRow(row);
123
								vendorTableM.removeRow(row);
124
                            }
124
							}
125
                        });
125
						});
126
                        return true;
126
						return true;
127
                    }
127
					}
128
                });
128
				});
129
                vendorMappingDialog.show();
129
				vendorMappingDialog.show();
130
            }
130
			}
131
        });
131
		});
132
    }
132
	}
133
    
133
 
134
    /**
134
	/**
135
     * initialises vendor prices table header. Creates an Add button and
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 
136
	 * adds click event listener to it to create and pop up a dialog for adding 
137
     * a prices for a new vendor 
137
	 * a prices for a new vendor 
138
     */
138
	 */
139
    private void initVendorPricesHeader(){
139
	private void initVendorPricesHeader(){
140
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
140
		headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
141
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
141
		headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
142
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
142
		headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
143
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
143
		headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
144
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
144
		headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
145
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_NLC, "128px");
145
		headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_NLC, "128px");
146
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_NLC + 1, "50px");
146
		headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_NLC + 1, "50px");
147
 
147
 
148
        headerVendor.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
148
		headerVendor.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
149
        headerVendor.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor");
149
		headerVendor.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor");
150
        headerVendor.setText(0, TABLE_INDEX_MOP, "MOP");
150
		headerVendor.setText(0, TABLE_INDEX_MOP, "MOP");
151
        headerVendor.setText(0, TABLE_INDEX_DP, "Dealer Price");
151
		headerVendor.setText(0, TABLE_INDEX_DP, "Dealer Price");
152
        headerVendor.setText(0, TABLE_INDEX_TP, "Transfer Price");
152
		headerVendor.setText(0, TABLE_INDEX_TP, "Transfer Price");
153
        headerVendor.setText(0, TABLE_INDEX_NLC, "NLC");
153
		headerVendor.setText(0, TABLE_INDEX_NLC, "NLC");
154
        
154
 
155
        headerVendor.getCellFormatter().setVisible(0, TABLE_INDEX_VENDORID, false);
155
		headerVendor.getCellFormatter().setVisible(0, TABLE_INDEX_VENDORID, false);
156
        
156
 
157
        Button addButton = new Button("Add");
157
		Button addButton = new Button("Add");
158
        headerVendor.setWidget(0, TABLE_INDEX_NLC + 1, addButton);
158
		headerVendor.setWidget(0, TABLE_INDEX_NLC + 1, addButton);
159
        addButton.addClickHandler(new ClickHandler() {
159
		addButton.addClickHandler(new ClickHandler() {
160
            @Override
160
			@Override
161
            public void onClick(ClickEvent event) {
161
			public void onClick(ClickEvent event) {
162
                VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
162
				VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
163
                vendorPricesDialog.updateButton.setText("Add");
163
				vendorPricesDialog.updateButton.setText("Add");
164
                vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
164
				vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
165
                    @Override
165
					@Override
166
                    public boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId) {
166
					public boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId) {
167
                        if(!vendorExists(vendorId)) {
167
						if(!vendorExists(vendorId)) {
168
                            Window.alert("Vendor already exists");
168
							Window.alert("Vendor already exists");
169
                            return false;
169
							return false;
170
                        }
170
						}
171
                        /*if(!validateVendorPrices(mop, dp, tp)) {
171
						/*if(!validateVendorPrices(mop, dp, tp)) {
172
                            return false;
172
                            return false;
173
                        }*/
173
                        }*/
174
                        final int row = vendorTable.getRowCount();
174
						final int row = vendorTable.getRowCount();
175
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
175
						vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
176
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
176
						vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
177
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
177
						vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
178
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
178
						vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
179
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
179
						vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
180
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC, "128px");
180
						vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC, "128px");
181
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC + 1, "50px");
181
						vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC + 1, "50px");
182
                        
182
 
183
                        vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
183
						vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
184
                        vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
184
						vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
185
                        vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
185
						vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
186
                        vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
186
						vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
187
                        vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
187
						vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
188
                        vendorTable.setText(row, TABLE_INDEX_NLC, nlc + "");
188
						vendorTable.setText(row, TABLE_INDEX_NLC, nlc + "");
189
                        
189
 
190
                        vendorTable.getCellFormatter().setVisible(row, TABLE_INDEX_VENDORID, false);
190
						vendorTable.getCellFormatter().setVisible(row, TABLE_INDEX_VENDORID, false);
191
                        
191
 
192
                        Button removeButton = new Button("X");
192
						Button removeButton = new Button("X");
193
                        vendorTable.setWidget(row, TABLE_INDEX_NLC + 1, removeButton);
193
						vendorTable.setWidget(row, TABLE_INDEX_NLC + 1, removeButton);
194
                        removeButton.addClickHandler(new ClickHandler() {
194
						removeButton.addClickHandler(new ClickHandler() {
195
                            @Override
195
							@Override
196
                            public void onClick(ClickEvent event) {
196
							public void onClick(ClickEvent event) {
197
                                vendorTable.removeRow(row);
197
								vendorTable.removeRow(row);
198
                            }
198
							}
199
                        });
199
						});
200
                        return true;
200
						return true;
201
                    }
201
					}
202
                });
202
				});
203
                vendorPricesDialog.show();
203
				vendorPricesDialog.show();
204
            }
204
			}
205
        });
205
		});
206
    }
206
	}
207
 
207
	@UiHandler("searchButton")
208
    @UiHandler("addButton")
208
	/**
209
    /**
209
	 * On search button click the item id is searched if it exists then the attributes of the item id are filled into the item form.
210
     * On add button click a new Item instance is created and all the information from UI fields is dumped in this item instance.
210
	 * Else an alert is displayed showing item id does not exists.
211
     * This item instance is then passed to the service to be added to the database.
211
	 */
212
     */
212
	void searchItem(ClickEvent event){
213
    void addItem(ClickEvent event) {
213
		preferredVendor.clear();
214
    	if(entityIdMandatory) {
214
		preferredInsurer.clear();  
215
    		long entityId = 0;
215
		catalogItemId.setText(null);
216
    		try {
216
		productGroup.setText(null);
217
                if(!catalogItemId.getText().trim().isEmpty()) {
217
		brand.setText(null);
218
                    entityId = Long.parseLong(catalogItemId.getText().trim());
218
		modelNumber.setText(null);
219
                    if(entityId <= 0) {
219
		modelName.setText(null);
220
                        throw new NumberFormatException("Invalid value of Catalog Item Id");
220
		comments.setText(null);
221
                    }
221
		mrp.setText(null);
222
                }
222
		sellingPrice.setText(null);
223
                else {
223
		weight.setText(null);
224
                	Window.alert("Catalog Item Id can not be empty");
224
		hasItemNo.setValue(null);
225
                	return;
225
		itemType.setValue(null);
226
                }
226
		showSellingPrice.setValue(null);
227
            } catch(NumberFormatException ex) {
227
		startDate.setValue(null);
228
                Window.alert("Invalid value of Catalog Item Id");
228
		this.comingSoonStartDate.setValue(null);
229
                return;
229
		this.expectedArrivalDate.setValue(null);
230
            }
230
		bestDealText.setText(null);
231
	    	catalogService.checkEntityId(entityId, new AsyncCallback<Boolean>() {
231
		bestDealsDetailsText.setText(null);
232
	            @Override
232
		bestDealsDetailsLink.setText(null);
233
	            public void onFailure(Throwable caught) {
233
		bestDealValue.setText(null);
234
	                GWT.log("Error checking Catalog Item Id");
234
		showSellingPrice.setValue(null);
235
	                Window.alert("Error checking Catalog Item Id");
235
		bestSellingRank.setText(null);
236
	                return;
236
		minStockLevel.setText(null);
237
	            }
237
		numOfDaysStock.setText(null);
238
	            @Override
238
		defaultForEntity.setValue(null);
239
	            public void onSuccess(Boolean result) {
239
		freebieItemId.setText(null);
240
		        	if(!result) {
240
		asin.setText(null);
241
	                    Window.alert("Invalid value of Catalog Item Id");
241
		holdInventory.setText(null);
242
	                    return;
242
		defaultInventory.setText(null);
243
	                }
243
		color.setText(null);
244
	                addNewItem();
244
		vendorTable.removeAllRows(); 
245
		        }
245
		if(!existingItemId.getText().trim().isEmpty()){
246
	        });
246
			long id = Long.parseLong(existingItemId.getText().trim());
247
    	}
247
 
248
    	else {
248
			if(id <= 0) {
249
	        catalogService.checkSimilarItem(brand.getText().trim(), modelNumber.getText().trim(),
249
				throw new NumberFormatException("Invalid value of Item Id");
250
	        		modelName.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
250
			}
251
	            @Override
251
			else{
252
	            public void onFailure(Throwable caught) {
252
				catalogService.getItem(id, new AsyncCallback<Item>() {
253
	                GWT.log("Error checking similar item");
253
					@Override
254
	                Window.alert("Error checking similar item");
254
					public void onFailure(Throwable caught) {
255
	                return;
255
						Window.alert("Unable to fetch item details.");
256
	            }
256
					}
257
	            @Override
257
					@Override
258
	            public void onSuccess(Long result) {
258
					public void onSuccess(Item result) {
259
	                if(result != 0) {
259
						if(result !=null){
260
	                    Window.alert("Similar product exists with Item Id " + result);
260
							fillItemForm(result);
261
	                    return;
261
						}
262
	                }
262
						else{
263
	                addNewItem();
263
							Window.alert("Invalid Item Id not found");
264
	            }
264
						}
265
	        });
265
					}
266
    	}
266
				});
267
    }
267
 
268
    
268
			}
269
    private void addNewItem() {
269
		}
270
        Item item = new Item();
270
		else{
271
        
271
			Window.alert("Please enter item id");
272
        if(!productGroup.getText().trim().isEmpty()) {
272
			GWT.log("Please enter an item id ");
273
        	item.setProductGroup(productGroup.getText().trim());
273
		}
-
 
274
	}
-
 
275
 
-
 
276
 
-
 
277
	/**
-
 
278
	 * This method is called if the valid item is returned and it populates the item entries in Item Form.
-
 
279
	 * 
-
 
280
	 */
-
 
281
	public void fillItemForm(Item item){
-
 
282
		int index = 0;
-
 
283
		preferredVendor.addItem("select");
-
 
284
        if (item.getPreferredVendor() == null) {
-
 
285
        	preferredVendor.setSelectedIndex(index);
-
 
286
        }
-
 
287
        
-
 
288
        if((item.getVendorPricesMap() == null || item.getVendorPricesMap().isEmpty())) {
-
 
289
        	if(item.getPreferredVendor() != null) {
-
 
290
        		index++;
-
 
291
        		preferredVendor.addItem(Utils.getVendorDesc(item.getPreferredVendor()));
-
 
292
        	}
274
        }
293
        }
275
        else {
294
        else {
276
        	Window.alert("Product Group can not be empty.");
295
        	for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
277
            return;
296
        		index++;
278
        }
-
 
279
        
-
 
280
        if(entityIdMandatory) {
-
 
281
	        try {
-
 
282
	            if(!catalogItemId.getText().trim().isEmpty()) {
-
 
283
	                long entityId = Long.parseLong(catalogItemId.getText().trim());
297
        		preferredVendor.addItem(Utils.getVendorDesc(vendorDetail.getVendorId()));
284
	                if(entityId <= 0) {
-
 
285
	                    throw new NumberFormatException("Invalid value of Catalog Item Id");
298
        		if(item.getPreferredVendor() != null && item.getPreferredVendor() == vendorDetail.getVendorId()) {
286
	                }
-
 
287
	                item.setCatalogItemId(entityId);
299
	        		preferredVendor.setSelectedIndex(index);
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
	        }
300
	        	}
297
        }
301
        	}
298
        
-
 
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 {
-
 
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);
-
 
311
            }
-
 
312
        } catch(NumberFormatException ex) {
-
 
313
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
-
 
314
            return;
-
 
315
        }
302
        	
316
        try {
-
 
317
            if(!sellingPrice.getText().trim().isEmpty()) {
-
 
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);
-
 
323
            }
-
 
324
        } catch(NumberFormatException ex) {
-
 
325
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
303
        	if(item.getPreferredVendor() != null && !item.getVendorPricesMap().containsKey(item.getPreferredVendor())){
326
            return;
304
        		index++;
327
        }
-
 
328
        try {
-
 
329
            if(!weight.getText().trim().isEmpty()) {
-
 
330
                double wtValue = Double.parseDouble(weight.getText().trim());
305
            	preferredVendor.addItem(Utils.getVendorDesc(item.getPreferredVendor()));
331
                if(wtValue <= 0) {
-
 
332
                    throw new NumberFormatException("Negative value of Weight");
-
 
333
                }
-
 
334
                item.setWeight(wtValue);
306
            	preferredVendor.setSelectedIndex(index);
335
            }
-
 
336
        } catch(NumberFormatException ex) {
-
 
337
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
-
 
338
            return;
-
 
339
        }
307
        	}
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
        }
308
        }
348
        if(comingSoonStartDate.getValue()==null){
-
 
349
        	item.setComingSoonStartDate(null);
-
 
350
        }else {
309
        index=0;
351
        	item.setComingSoonStartDate(comingSoonStartDate.getValue().getTime());
-
 
352
        }
-
 
353
        if(expectedArrivalDate.getValue()==null){
310
        preferredInsurer.addItem("select","0");
354
        	item.setExpectedArrivalDate(null);
311
        preferredInsurer.setSelectedIndex(0);
355
        }else {
-
 
356
        	item.setExpectedArrivalDate(expectedArrivalDate.getValue().getTime());
-
 
357
        }
-
 
358
        item.setBestDealsText(bestDealText.getText().trim());
-
 
359
        item.setBestDealsDetailsText(bestDealsDetailsText.getText().trim());
-
 
360
        item.setBestDealsDetailsLink(bestDealsDetailsLink.getText().trim());
312
    	for (Map.Entry<Long, String> entry : Utils.getAllInsurers().entrySet()){
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
        }
-
 
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);
-
 
393
	        }else {
-
 
394
	        	item.setMinStockLevel(0L);
-
 
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());
-
 
409
	        } else {
-
 
410
	        	item.setNumOfDaysStock(0);
-
 
411
	        }
-
 
412
	    } catch(NumberFormatException ex) {
-
 
413
	    	item.setNumOfDaysStock(0);
-
 
414
	        Window.alert("Invalid min Stock Level. Setting it to zero(0)");
-
 
415
	        return;
313
    		index++;
416
	    }
-
 
417
	    
-
 
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
	    item.setAsin(asin.getText().trim());
-
 
431
	    	    
-
 
432
        try {
-
 
433
            if(!holdInventory.getText().trim().equals("")) {
-
 
434
                long hold_inventory = Long.parseLong(holdInventory.getText().trim());
314
    		preferredInsurer.addItem(entry.getValue(),entry.getKey().toString());
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
        }
-
 
457
        item.setDefaultForEntity(defaultForEntity.getValue());
-
 
458
        item.setRisky(risky.getValue());
-
 
459
        item.setHasItemNo(hasItemNo.getValue());
-
 
460
        item.setItemType(itemType.getValue());
315
    		if(item.getPreferredInsurer()==entry.getKey()){
461
        if(preferredVendor.getSelectedIndex() == 0) {
316
    			preferredInsurer.setSelectedIndex(index);  
462
        	Window.alert("Invalid Vendor Selected");
-
 
463
            return;
-
 
464
        }
317
    		}
465
    	else {
-
 
466
    		item.setPreferredVendor(Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex())));
-
 
467
    	}
318
    	}
-
 
319
		catalogItemId.setText(Long.toString(item.getCatalogItemId()));
-
 
320
		productGroup.setText(item.getProductGroup());
-
 
321
		brand.setText(item.getBrand());
-
 
322
		modelNumber.setText(item.getModelNumber());
-
 
323
		modelName.setText(item.getModelName());
-
 
324
		comments.setText(item.getComments());
-
 
325
		mrp.setText(item.getMrp() != null ? item.getMrp()+"" : "");
-
 
326
		sellingPrice.setText(item.getSellingPrice() != null ? item.getSellingPrice()+"" : "");
-
 
327
		weight.setText(item.getWeight() != null ? item.getWeight()+"" : "");
-
 
328
		hasItemNo.setValue(item.isHasItemNo());
-
 
329
		itemType.setValue(item.isItemType());
-
 
330
		showSellingPrice.setValue(item.isShowSellingPrice());
-
 
331
		startDate.setValue(new Date(item.getStartDate()));
-
 
332
		if(item.getComingSoonStartDate() != null){
-
 
333
			this.comingSoonStartDate.setValue(new Date(item.getComingSoonStartDate()));
-
 
334
		}else {
-
 
335
			this.comingSoonStartDate.setValue(null);
-
 
336
		}
-
 
337
		if(item.getExpectedArrivalDate() != null){
-
 
338
			this.expectedArrivalDate.setValue(new Date(item.getExpectedArrivalDate()));
-
 
339
		}else {
-
 
340
			this.expectedArrivalDate.setValue(null);
-
 
341
		}
-
 
342
		bestDealText.setText(item.getBestDealsText());
-
 
343
		bestDealsDetailsText.setText(item.getBestDealsDetailsText());
-
 
344
		bestDealsDetailsLink.setText(item.getBestDealsDetailsLink());
-
 
345
		bestDealValue.setText(item.getBestDealsValue() != null ? item.getBestDealsValue()+"" : "");
-
 
346
		showSellingPrice.setValue(item.isShowSellingPrice());
-
 
347
		bestSellingRank.setText(item.getBestSellingRank() != null ? item.getBestSellingRank()+"" : "");
-
 
348
		minStockLevel.setText(item.getMinStockLevel() != null ? item.getMinStockLevel()+"" : "");
-
 
349
		numOfDaysStock.setText(item.getNumOfDaysStock() != null ? item.getNumOfDaysStock()+"" : "");
-
 
350
		defaultForEntity.setValue(item.isDefaultForEntity());
-
 
351
		freebieItemId.setText(item.getFreebieItemId().toString());
-
 
352
		asin.setText(item.getAsin());
-
 
353
		holdInventory.setText(Long.toString(item.getHoldInventory()));
-
 
354
		defaultInventory.setText(Long.toString(item.getDefaultInventory()));
-
 
355
		Map<Long, VendorPricings> map = item.getVendorPricesMap();
-
 
356
		for (Map.Entry<Long, VendorPricings> vendorItem : map.entrySet()) {
-
 
357
			final int row = vendorTable.getRowCount();
-
 
358
			long vendorId = vendorItem.getKey();
-
 
359
			double mop = vendorItem.getValue().getMop();
-
 
360
			double dp  = vendorItem.getValue().getDealerPrice();
-
 
361
			double tp =  vendorItem.getValue().getTransferPrice();
-
 
362
			double nlc = vendorItem.getValue().getNlc();
-
 
363
			vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
-
 
364
			vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
-
 
365
			vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
-
 
366
			vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
-
 
367
			vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
-
 
368
			vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC, "128px");
-
 
369
			vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_NLC + 1, "50px");
-
 
370
			vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
-
 
371
			vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
-
 
372
			vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
-
 
373
			vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
-
 
374
			vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
-
 
375
			vendorTable.setText(row, TABLE_INDEX_NLC, nlc + "");
-
 
376
			vendorTable.getCellFormatter().setVisible(row, TABLE_INDEX_VENDORID, false);
-
 
377
			Button removeButton = new Button("X");
-
 
378
			vendorTable.setWidget(row, TABLE_INDEX_NLC + 1, removeButton);
-
 
379
			removeButton.addClickHandler(new ClickHandler() {
-
 
380
				@Override
-
 
381
				public void onClick(ClickEvent event) {
-
 
382
					vendorTable.removeRow(row);
-
 
383
				}
-
 
384
			});
-
 
385
		}
-
 
386
	}
-
 
387
 
-
 
388
 
-
 
389
	@UiHandler("addButton")
-
 
390
	/**
-
 
391
	 * On add button click a new Item instance is created and all the information from UI fields is dumped in this item instance.
-
 
392
	 * This item instance is then passed to the service to be added to the database.
-
 
393
	 */
-
 
394
	void addItem(ClickEvent event) {
-
 
395
		if(entityIdMandatory) {
-
 
396
			long entityId = 0;
-
 
397
			try {
-
 
398
				if(!catalogItemId.getText().trim().isEmpty()) {
-
 
399
					entityId = Long.parseLong(catalogItemId.getText().trim());
-
 
400
					if(entityId <= 0) {
-
 
401
						throw new NumberFormatException("Invalid value of Catalog Item Id");
-
 
402
					}
-
 
403
				}
-
 
404
				else {
-
 
405
					Window.alert("Catalog Item Id can not be empty");
-
 
406
					return;
-
 
407
				}
-
 
408
			} catch(NumberFormatException ex) {
-
 
409
				Window.alert("Invalid value of Catalog Item Id");
-
 
410
				return;
-
 
411
			}
-
 
412
			catalogService.checkEntityId(entityId, new AsyncCallback<Boolean>() {
-
 
413
				@Override
-
 
414
				public void onFailure(Throwable caught) {
-
 
415
					GWT.log("Error checking Catalog Item Id");
-
 
416
					Window.alert("Error checking Catalog Item Id");
-
 
417
					return;
-
 
418
				}
-
 
419
				@Override
-
 
420
				public void onSuccess(Boolean result) {
-
 
421
					if(!result) {
-
 
422
						Window.alert("Invalid value of Catalog Item Id");
-
 
423
						return;
-
 
424
					}
-
 
425
					addNewItem();
-
 
426
				}
-
 
427
			});
-
 
428
		}
-
 
429
		else {
-
 
430
			catalogService.checkSimilarItem(brand.getText().trim(), modelNumber.getText().trim(),
-
 
431
					modelName.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
-
 
432
				@Override
-
 
433
				public void onFailure(Throwable caught) {
-
 
434
					GWT.log("Error checking similar item");
-
 
435
					Window.alert("Error checking similar item");
-
 
436
					return;
-
 
437
				}
-
 
438
				@Override
-
 
439
				public void onSuccess(Long result) {
-
 
440
					if(result != 0) {
-
 
441
						Window.alert("Similar product exists with Item Id " + result);
-
 
442
						return;
-
 
443
					}
-
 
444
					addNewItem();
-
 
445
				}
-
 
446
			});
-
 
447
		}
-
 
448
	}
-
 
449
 
-
 
450
	private void addNewItem() {
-
 
451
		Item item = new Item();
-
 
452
		if(!productGroup.getText().trim().isEmpty()) {
-
 
453
			item.setProductGroup(productGroup.getText().trim());
-
 
454
		}
-
 
455
		else {
-
 
456
			Window.alert("Product Group can not be empty.");
-
 
457
			return;
-
 
458
		}
-
 
459
 
-
 
460
		if(entityIdMandatory) {
468
        
461
			try {
-
 
462
				if(!catalogItemId.getText().trim().isEmpty()) {
-
 
463
					long entityId = Long.parseLong(catalogItemId.getText().trim());
-
 
464
					if(entityId <= 0) {
-
 
465
						throw new NumberFormatException("Invalid value of Catalog Item Id");
-
 
466
					}
-
 
467
					item.setCatalogItemId(entityId);
-
 
468
				}
-
 
469
				else {
-
 
470
					Window.alert("Catalog Item Id can not be empty");
-
 
471
					return;
-
 
472
				}
-
 
473
			} catch(NumberFormatException ex) {
-
 
474
				Window.alert("Invalid value of Catalog Item Id");
-
 
475
				return;
-
 
476
			}
-
 
477
		}
-
 
478
		item.setBrand(brand.getText().trim());
-
 
479
		item.setModelNumber(modelNumber.getText().trim());
-
 
480
		item.setModelName(modelName.getText().trim());
-
 
481
		item.setColor(color.getText().trim());
-
 
482
		item.setComments(comments.getText().trim());
-
 
483
		try {
-
 
484
			if(!mrp.getText().trim().isEmpty()) {
-
 
485
				double mrpValue = Double.parseDouble(mrp.getText().trim());
-
 
486
				if(mrpValue <= 0) {
-
 
487
					throw new NumberFormatException("Negative value of MRP");
-
 
488
				}
-
 
489
				item.setMrp(mrpValue);
-
 
490
			}
-
 
491
		} catch(NumberFormatException ex) {
-
 
492
			Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
-
 
493
			return;
-
 
494
		}
-
 
495
		try {
-
 
496
			if(!sellingPrice.getText().trim().isEmpty()) {
-
 
497
				double spValue = Double.parseDouble(sellingPrice.getText().trim());
-
 
498
				if(spValue <= 0) {
-
 
499
					throw new NumberFormatException("Negative value of Selling price");
-
 
500
				}
-
 
501
				item.setSellingPrice(spValue);
-
 
502
			}
-
 
503
		} catch(NumberFormatException ex) {
-
 
504
			Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
-
 
505
			return;
-
 
506
		}
-
 
507
		try {
-
 
508
			if(!weight.getText().trim().isEmpty()) {
-
 
509
				double wtValue = Double.parseDouble(weight.getText().trim());
-
 
510
				if(wtValue <= 0) {
-
 
511
					throw new NumberFormatException("Negative value of Weight");
-
 
512
				}
-
 
513
				item.setWeight(wtValue);
-
 
514
			}
-
 
515
		} catch(NumberFormatException ex) {
-
 
516
			Window.alert("Invalid weight format/value. Value shoule be greater than zero");
-
 
517
			return;
-
 
518
		}
-
 
519
		try {
-
 
520
			if(!startDate.getTextBox().getText().trim().equals("")) {
-
 
521
				item.setStartDate(startDate.getValue().getTime());
-
 
522
			}
-
 
523
		} catch(Exception ex) {
-
 
524
			Window.alert("Invalid start date format");
-
 
525
			return;
-
 
526
		}
-
 
527
		if(comingSoonStartDate.getValue()==null){
-
 
528
			item.setComingSoonStartDate(null);
-
 
529
		}else {
-
 
530
			item.setComingSoonStartDate(comingSoonStartDate.getValue().getTime());
-
 
531
		}
-
 
532
		if(expectedArrivalDate.getValue()==null){
-
 
533
			item.setExpectedArrivalDate(null);
-
 
534
		}else {
469
        item.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
535
			item.setExpectedArrivalDate(expectedArrivalDate.getValue().getTime());
-
 
536
		}
-
 
537
		item.setBestDealsText(bestDealText.getText().trim());
-
 
538
		item.setBestDealsDetailsText(bestDealsDetailsText.getText().trim());
-
 
539
		item.setBestDealsDetailsLink(bestDealsDetailsLink.getText().trim());
-
 
540
		try {
-
 
541
			if(!bestDealValue.getText().trim().equals("")) {
-
 
542
				double bdValue = Double.parseDouble(bestDealValue.getText().trim());
-
 
543
				if(bdValue < 0) {
-
 
544
					throw new NumberFormatException("Negative value of BestDealValue");
-
 
545
				}
-
 
546
				item.setBestDealsValue(bdValue);
-
 
547
			}
-
 
548
		} catch(NumberFormatException ex) {
-
 
549
			Window.alert("Invalid best deal value format");
-
 
550
			return;
-
 
551
		}
-
 
552
		try {
-
 
553
			if(!bestSellingRank.getText().trim().equals("")) {
-
 
554
				long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
-
 
555
				if(bsrValue < 0) {
-
 
556
					throw new NumberFormatException("Negative value of Best Selling Rank");
-
 
557
				}
-
 
558
				item.setBestSellingRank(bsrValue);
-
 
559
			}
-
 
560
		} catch(NumberFormatException ex) {
-
 
561
			Window.alert("Invalid best selling rank format");
-
 
562
			return;
-
 
563
		}
-
 
564
 
-
 
565
		try {
-
 
566
			if(!minStockLevel.getText().trim().equals("")) {
-
 
567
				long msl = Long.parseLong(minStockLevel.getText().trim());
-
 
568
				if(msl < 0) {
-
 
569
					throw new NumberFormatException("Negative value of Min Stock Value");
-
 
570
				}
-
 
571
				item.setMinStockLevel(msl);
-
 
572
			}else {
-
 
573
				item.setMinStockLevel(0L);
-
 
574
			}
-
 
575
		} catch(NumberFormatException ex) {
-
 
576
			item.setMinStockLevel(0L);
-
 
577
			Window.alert("Invalid min Stock Level. Setting it to zero(0)");
-
 
578
			return;
-
 
579
		}
-
 
580
 
-
 
581
		try {
-
 
582
			if(!numOfDaysStock.getText().trim().equals("")) {
-
 
583
				Long nds = Long.parseLong(numOfDaysStock.getText().trim());
-
 
584
				if(nds < 0) {
-
 
585
					throw new NumberFormatException("Negative value of Num of Days Of Stock");
-
 
586
				}
-
 
587
				item.setNumOfDaysStock(nds.intValue());
-
 
588
			} else {
-
 
589
				item.setNumOfDaysStock(0);
-
 
590
			}
-
 
591
		} catch(NumberFormatException ex) {
-
 
592
			item.setNumOfDaysStock(0);
-
 
593
			Window.alert("Invalid min Stock Level. Setting it to zero(0)");
-
 
594
			return;
-
 
595
		}
-
 
596
 
-
 
597
		try {
-
 
598
			if(!freebieItemId.getText().trim().equals("")) {
-
 
599
				long freeItemId = Long.parseLong(freebieItemId.getText().trim());
-
 
600
				if(freeItemId < 0) {
-
 
601
					throw new NumberFormatException("Negative value of freebieItemId ");
-
 
602
				}
-
 
603
				item.setFreebieItemId(new Long(freeItemId));
-
 
604
			}
-
 
605
		} catch(NumberFormatException ex) {
-
 
606
			Window.alert("Invalid freebie ItemId");
-
 
607
			return;
-
 
608
		}
-
 
609
		item.setAsin(asin.getText().trim());
-
 
610
 
-
 
611
		try {
-
 
612
			if(!holdInventory.getText().trim().equals("")) {
-
 
613
				long hold_inventory = Long.parseLong(holdInventory.getText().trim());
-
 
614
				if(hold_inventory < 0) {
-
 
615
					throw new NumberFormatException("Negative value of Hold Inventory");
-
 
616
				}
-
 
617
				item.setHoldInventory(hold_inventory);
-
 
618
			}
-
 
619
		} catch(NumberFormatException ex) {
-
 
620
			Window.alert("Invalid Hold Inventory Value");
-
 
621
			return;
-
 
622
		}
-
 
623
 
470
        
624
		try {
-
 
625
			if(!defaultInventory.getText().trim().equals("")) {
-
 
626
				long default_inventory = Long.parseLong(defaultInventory.getText().trim());
-
 
627
				if(default_inventory < 0) {
-
 
628
					throw new NumberFormatException("Negative value of Default Inventory");
471
   	
629
				}
-
 
630
				item.setDefaultInventory(default_inventory);
-
 
631
			}
-
 
632
		} catch(NumberFormatException ex) {
-
 
633
			Window.alert("Invalid Default Inventory Value");
-
 
634
			return;
-
 
635
		}
-
 
636
		item.setDefaultForEntity(defaultForEntity.getValue());
-
 
637
		item.setRisky(risky.getValue());
-
 
638
		item.setHasItemNo(hasItemNo.getValue());
-
 
639
		item.setItemType(itemType.getValue());
-
 
640
		if(preferredVendor.getSelectedIndex() == 0) {
-
 
641
			Window.alert("Invalid Vendor Selected");
-
 
642
			return;
-
 
643
		}
-
 
644
		else {
-
 
645
			item.setPreferredVendor(Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex())));
-
 
646
		}
-
 
647
		item.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
472
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
648
		/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
473
          Add the instance to map and set the map to the item instance created above.*/
649
          Add the instance to map and set the map to the item instance created above.*/
474
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
650
		Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
475
        VendorPricings v;
651
		VendorPricings v;
476
        for(int row = 0; row < vendorTable.getRowCount(); row++) {
652
		for(int row = 0; row < vendorTable.getRowCount(); row++) {
477
            v = new VendorPricings();
653
			v = new VendorPricings();
478
            v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
654
			v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
479
            v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
655
			v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
480
            v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
656
			v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
481
            v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
657
			v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
482
            v.setNlc(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_NLC)));
658
			v.setNlc(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_NLC)));
483
            vendorPrices.put(v.getVendorId(), v);
659
			vendorPrices.put(v.getVendorId(), v);
484
        }
660
		}
485
        item.setVendorPricesMap(vendorPrices);
661
		item.setVendorPricesMap(vendorPrices);
486
        
662
 
487
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
663
		/*Create an instance of VendorKeys 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.*/
664
        Add the instance to map and set the map to the item instance created above.*/
489
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
665
		Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
490
        VendorItemMapping vMapping;
666
		VendorItemMapping vMapping;
491
        for(int row = 0; row < vendorTableM.getRowCount(); row++) {
667
		for(int row = 0; row < vendorTableM.getRowCount(); row++) {
492
            vMapping = new VendorItemMapping();
668
			vMapping = new VendorItemMapping();
493
            vMapping.setItemKey(vendorTableM.getText(row, TABLE_INDEX_ITEM_KEY));
669
			vMapping.setItemKey(vendorTableM.getText(row, TABLE_INDEX_ITEM_KEY));
494
            vMapping.setVendorId(Long.parseLong(vendorTableM.getText(row, TABLE_INDEX_VENDORID)));
670
			vMapping.setVendorId(Long.parseLong(vendorTableM.getText(row, TABLE_INDEX_VENDORID)));
495
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + vMapping.getItemKey(), vMapping);
671
			vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + vMapping.getItemKey(), vMapping);
496
        }
672
		}
497
        item.setVendorKeysMap(vendorMappings);
673
		item.setVendorKeysMap(vendorMappings);
498
        
-
 
499
        if(!Utils.validateItem(item)) {
674
		if(!Utils.validateItem(item)) {
500
            return;
675
			return;
501
        }
676
		}
502
        
677
 
503
        /*Service method to add item. */
678
		/*Service method to add item. */
504
        catalogService.addItem(item, new AsyncCallback<Long>() {
679
		catalogService.addItem(item, new AsyncCallback<Long>() {
505
            @Override
680
			@Override
506
            public void onSuccess(Long result) {
681
			public void onSuccess(Long result) {
507
                if(result == null || result == 0) {
682
				if(result == null || result == 0) {
508
                    Window.alert("Error while adding item");
683
					Window.alert("Error while adding item");
509
                    return;
684
					return;
510
                }
685
				}
511
                Window.alert("Item added successfully. Id = " + result);
686
				Window.alert("Item added successfully. Id = " + result);
512
                hide();
687
				hide();
513
            }
688
			}
514
            @Override
689
			@Override
515
            public void onFailure(Throwable caught) {
690
			public void onFailure(Throwable caught) {
516
                caught.printStackTrace();
691
				caught.printStackTrace();
517
                Window.alert("Error while adding item");
692
				Window.alert("Error while adding item");
518
            }
693
			}
519
        });
694
		});
520
    }
695
	}
521
    
696
 
522
    @UiHandler("cancelButton")
697
	@UiHandler("cancelButton")
523
    void closeForm(ClickEvent event) {
698
	void closeForm(ClickEvent event) {
524
        this.hide();
699
		this.hide();
525
    }
700
	}
526
 
701
 
527
    /**
702
	/**
528
     * Checks if vendor details already exists corresponding to the vendor Id parameter. 
703
	 * Checks if vendor details already exists corresponding to the vendor Id parameter. 
529
     */
704
	 */
530
    private boolean vendorExists(long vendorId) {
705
	private boolean vendorExists(long vendorId) {
531
        long id;
706
		long id;
532
        for(int i = 0; i < vendorTable.getRowCount(); i++) {
707
		for(int i = 0; i < vendorTable.getRowCount(); i++) {
533
            id = Long.parseLong(vendorTable.getText(i, TABLE_INDEX_VENDORID));
708
			id = Long.parseLong(vendorTable.getText(i, TABLE_INDEX_VENDORID));
534
            if(vendorId == id) {
709
			if(vendorId == id) {
535
                return false;
710
				return false;
536
            }
711
			}
537
        }
712
		}
538
        return true;
713
		return true;
539
    }
714
	}
540
    
715
 
541
    /**
716
	/**
542
     * validate vendor prices (MOP, DealerPrice, TransferPrice)
717
	 * validate vendor prices (MOP, DealerPrice, TransferPrice)
543
     */
718
	 */
544
    @SuppressWarnings("unused")
719
	@SuppressWarnings("unused")
545
	private boolean validateVendorPrices(double mop, double dp, double tp) {
720
	private boolean validateVendorPrices(double mop, double dp, double tp) {
546
        double mrpValue;
721
		double mrpValue;
547
        try {
722
		try {
548
            mrpValue = Double.parseDouble(mrp.getText().trim());
723
			mrpValue = Double.parseDouble(mrp.getText().trim());
549
        } catch (NumberFormatException ex) {
724
		} catch (NumberFormatException ex) {
550
            Window.alert("Invalid MRP value.");
725
			Window.alert("Invalid MRP value.");
551
            return false;
726
			return false;
552
        }
727
		}
553
        if(mrpValue < mop) {
728
		if(mrpValue < mop) {
554
            Window.alert("MOP cannot be more than MRP.");
729
			Window.alert("MOP cannot be more than MRP.");
555
            return false;
730
			return false;
556
        }
731
		}
557
        if(tp > mop) {
732
		if(tp > mop) {
558
            Window.alert("Transfer Price cannot be more than MOP.");
733
			Window.alert("Transfer Price cannot be more than MOP.");
559
            return false;
734
			return false;
560
        }
735
		}
561
        return true;
736
		return true;
562
    }
737
	}
563
    
738
 
564
	@UiHandler("comingSoonButton")
739
	@UiHandler("comingSoonButton")
565
	void onComingSoonButtonClick(ClickEvent event) {
740
	void onComingSoonButtonClick(ClickEvent event) {
566
		ComingSoonDialog cd = new ComingSoonDialog(this);
741
		ComingSoonDialog cd = new ComingSoonDialog(this);
567
		cd.show();
742
		cd.show();
568
	}
743
	}