/*
 * Created on 2005.06.20.
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package com.etixpert.evolution.gui.servlets.pageactions;

import java.math.BigDecimal;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.etixpert.evolution.*;
import com.etixpert.evolution.gui.servlets.*;
import org.apache.log4j.*;


/**
 * @author Suveges Gyorgy
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class deleteorderdetail extends PageActionHandler {
    String error;
	String details;
	String currentID;
	/**
	 * 
	 */
	public deleteorderdetail() {
		super();
		  error = "order_error";
	      details = "order_details";
	      currentID = "CURRENT_ORDER_ID";
	}

	/* (non-Javadoc)
	 * @see com.etixpert.evolution.gui.servlets.pageactions.PageActionHandler#handle(javax.servlet.http.HttpServletRequest)
	 */
	protected void handle(HttpServletRequest request, HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession();
		Map m = (Map) session.getAttribute(details);
		String pos = request.getParameter("pos");
		int ipos = Integer.parseInt(pos);
        
		m.remove(pos);
		
		int count = 0;
		try {
			count = ((Integer)m.get("count")).intValue();
		} catch (Exception e) {
			throw new EvolutionException("Unconsistent state: count cannot be reached from order_details");
		}
		
		for (int j = ipos+1; j<count; j++) {
			m.put(String.valueOf(j-1), m.remove(String.valueOf(j)));
		}
		m.put("count", new Integer(count-1));       
	}
    
}