package amortizacionesServlet;

    import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;

import m05bAmortizacionesEJB.m05Amortizaciones;
import m05bAmortizacionesEJB.m05AmortizacionesHome;
import m05bAmortizacionesEJB.m05AmortizacionesPK;
import m05bBD.m05bAmortizaciones;
import m05bClasses.m05bFileLog;
public class m05bGenerarAmortizacionesServlet extends javax.servlet.http.HttpServlet{


    public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

        performTask(request, response);

    }
    /**
     * Returns the servlet info string.
     */
    public String getServletInfo() {

        return super.getServletInfo();

    }
    /**
     * Initializes the servlet.
     */
    public void init() {
        // insert code to initialize the servlet here

    }
    /**
     * Process incoming requests for information
     *
     * @param request Object that encapsulates the request to the servlet
     * @param response Object that encapsulates the response from the servlet
     */
    public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {

        try

        {
            // Insert user code from here.

            String codigo;
            String matricula;
            String sURL = "";

            HttpSession session = request.getSession(true);

            codigo = new String(request.getParameter("Codigo"));
            matricula = new String (request.getParameter("Matricula"));

            try{
                m05AmortizacionesPK primaryKey = new m05AmortizacionesPK();
                primaryKey.amo_codigo = codigo;
                InitialContext ctx2 = new InitialContext();
                m05AmortizacionesHome amortizaEBHome = (m05AmortizacionesHome) ctx2.lookup("m05Amortizaciones");
                m05Amortizaciones amortizaEB = amortizaEBHome.findByPrimaryKey(primaryKey);
                m05bAmortizaciones amortiza = amortizaEB.getAmortizaciones();
                session.setAttribute("m05bAmortizaciones", amortiza);


                sURL = response.encodeRedirectURL("m05bVehAmortizaJsp.jsp?Matricula=" + matricula +  "&Codigo="+codigo);
                RequestDispatcher rd;
                rd = request.getRequestDispatcher(sURL);
                try{
                    rd.forward(request, response);
                }
                catch (ServletException e){
                  System.err.println("Exception: OutletMaintenanceS.service: " + e);
                  response.sendRedirect("m05bError.jsp");
                }
            } catch (Exception SQLException) {
            	m05bFileLog miLog = new m05bFileLog();
            	miLog.addTraza(SQLException);		
                response.sendRedirect("m05bError.jsp");
            }

        }
        catch(Throwable theException)
        {
            // uncomment the following line when unexpected exceptions
            // are occuring to aid in debugging the problem.
         	m05bFileLog miLog = new m05bFileLog();
        	miLog.addTraza(theException);
        }
    }

}
