/*
 * 
 * Created on May 30, 2005
 * 
 * Peter Albert
 * Etixpert Kft.
 * Copyright(c) 2005
 * 
 */
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 javax.servlet.jsp.jstl.fmt.LocaleSupport;

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 new_orderchange_quantity extends PageActionHandler {
    protected String newDetails;
    protected String newError;
    protected String toNewPos;
    protected String disableVorauskassa = "false";
    /**
     * 
     */
    public new_orderchange_quantity() {
        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");
        Map mod = (Map)m.get(pos);
        
        String payMethodId = request.getParameter("pay_method_id");
        
        String newQ = request.getParameter("quantity"+pos);
        
        int i;
        try {
        	i = Integer.parseInt(newQ);
        	//if (i<0) throw new Exception();
        } catch (Exception e) {
        	session.setAttribute(newError, LocaleSupport.getLocalizedMessage(pageContext, "INVALID_COUNT"));
        	return;
        }

        if (i < 0) {
        	int userId = new Integer((String)session.getAttribute("USER_LOGGED_ID"));
        	if (userId > 100) {
                mod.put("quantity", new String[] {"1"});
                session.setAttribute(toNewPos, null);
                return;
        	}
        }
        
        /*if (i < 0 && !"4".equals(payMethodId)) {
        	session.setAttribute(newError,LocaleSupport.getLocalizedMessage(pageContext, "LIMIT_CREDIT_NOTES"));
        	return;
        }
        */
        
        mod.put("quantity", new String[] {newQ});
        session.setAttribute(toNewPos, null);

        
    }
    
}
