*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
FloorForm floorForm = (FloorForm) form;
RestaurantManager manager = new RestaurantManager();
String floorId = (String) floorForm.getFloorId();
String place = (String) floorForm.getId();
String str = (String) floorForm.getMode();
String[] array = null;
int mode = 0;
if (!str.equals("")) {
mode = Integer.valueOf(str);
}
List<TicketLineInfo> linesList = new ArrayList<TicketLineInfo>();
List products = new ArrayList<ProductInfoExt>();
TicketInfo ticket;
switch (mode) {
//removes products
case 1:
ticket = manager.findTicket(place);
linesList = ticket.getM_aLines();
array = floorForm.getParameters();
if (array != null) {
for (int i = 0; i < array.length; i++) {
if (linesList.get(Integer.valueOf(array[i])).getMultiply() > 1) {
linesList.get(Integer.valueOf(array[i])).setMultiply(linesList.get(Integer.valueOf(array[i])).getMultiply() - 1);
}
}
}
manager.updateLineFromTicket(place, ticket);
for (Object line : linesList) {
TicketLineInfo li = (TicketLineInfo) line;
products.add(manager.findProductById(li.getProductid()));
}
request.setAttribute("product", products.get(0));
request.setAttribute("place", place);
request.setAttribute("placeName", manager.findPlaceNameById(place));
request.setAttribute("line", linesList.get(Integer.valueOf(array[0])));
request.setAttribute("lineNo", array[0]);
request.setAttribute("total", manager.getTotalOfaTicket(place));
return mapping.findForward(UPDATE);
case 4:
ticket = manager.findTicket(place);
linesList = ticket.getM_aLines();
array = floorForm.getParameters();
int var = Integer.parseInt(array[0]);
linesList.remove(var);
if (linesList.size() > var && manager.findProductById(linesList.get(var).getProductid()).isCom()) {
linesList.remove(var);
while (linesList.size() > var && manager.findProductById(linesList.get(var).getProductid()).isCom()) {
linesList.remove(var);
if (linesList.size() == var) {
break;
}
}
}
manager.updateLineFromTicket(place, ticket);
for (Object line : linesList) {
TicketLineInfo li = (TicketLineInfo) line;
products.add(manager.findProductById(li.getProductid()));
}
request.setAttribute("floorName", manager.findFloorById(manager.findPlaceById(place).getFloor()).getName());
request.setAttribute("place", place);
request.setAttribute("placeName", manager.findPlaceNameById(place));
request.setAttribute("floorId", floorId);
request.setAttribute("lines", linesList);
request.setAttribute("products", products);
request.setAttribute("total", manager.getTotalOfaTicket(place));
return mapping.findForward(SUCCESS);
//edits lines
case 2:
ticket = manager.findTicket(place);
linesList = ticket.getM_aLines();
String[] index = floorForm.getParameters();
//if null go to default and refresh products. that's why no break
linesList.get(Integer.valueOf(index[0])).setMultiply(Double.valueOf(index[1]));
manager.updateLineFromTicket(floorForm.getId(), ticket);
for (Object line : linesList) {
TicketLineInfo li = (TicketLineInfo) line;
products.add(manager.findProductById(li.getProductid()));
}
break;
//increment product
case 3:
ticket = manager.findTicket(place);
linesList = ticket.getM_aLines();
array = floorForm.getParameters();
if (array != null) {
for (int i = 0; i < array.length; i++) {
linesList.get(Integer.valueOf(array[i])).setMultiply(linesList.get(Integer.valueOf(array[i])).getMultiply() + 1); //strange
}
}