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