/*
 * 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.*;
import javax.servlet.http.HttpSession;
import com.etixpert.evolution.*;
import com.etixpert.evolution.gui.servlets.*;
import org.apache.log4j.*;


/**
 * @author Peter Albert
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class deleteneworderdetail extends PageActionHandler {
    protected String newDetails;
    protected String newError;
    protected String toNewPos;
	/**
	 * 
	 */
	public deleteneworderdetail() {
		super();
		newDetails="new_order_details";
	    newError="new_order_error";
	    toNewPos = "to_new_pos";
		// TODO Auto-generated constructor stub
	}

	/* (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(newDetails);
		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));     
		session.setAttribute(toNewPos, null); 
	}
    
}