EffectiveDateCO

package xxhr.oracle.apps.pqh.selfservice.common.webui;

import java.sql.CallableStatement;
import java.sql.Connection;

import java.util.Date;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.sql.Types;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;


import oracle.apps.fnd.common.MessageToken;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OABodyBean;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageDateFieldBean;
import oracle.apps.pqh.selfservice.common.webui.EffectiveDateCO;

import oracle.jdbc.OracleCallableStatement;


public class EffectiveDateCOEx41 extends EffectiveDateCO {

    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean);

        //SimpleDateFormat f = new SimpleDateFormat("dd-mon-yyyy");
        OAApplicationModule aml = pageContext.getApplicationModule(webBean);
        int person_id = pageContext.getEmployeeId();
        pageContext.writeDiagnostics(webBean,
                                     "person_id in Resign Page : " + person_id,
                                     4);
        OADBTransaction tr = aml.getOADBTransaction();
        try {
            pageContext.writeDiagnostics(webBean, "After Try : ", 4);
            CallableStatement cs = null;
            String stmt =
                "BEGIN ABRAJ_EMP_RESIGN_LAST_DATE_KK(?,?,?,?,?,?); END;";
            cs = (OracleCallableStatement)tr.createCallableStatement(stmt, 0);

            cs.setInt(1, person_id);
            cs.registerOutParameter(2, Types.VARCHAR);
            cs.registerOutParameter(3, Types.NUMERIC);
            cs.registerOutParameter(4, Types.VARCHAR);
            cs.registerOutParameter(5, Types.VARCHAR);
            cs.registerOutParameter(6, Types.DATE);
            try {
                cs.execute();
            } catch (Exception e) {
                throw new OAException(e.getMessage(), (byte)0);
            }
            try {
                String dateStr = cs.getString(2);

                // embed the JavaScript "onLoad" event...
                OABodyBean bodyBean = (OABodyBean)pageContext.getRootWebBean();
                String javaS =
                    "return document.getElementById(\"HrEffectiveDate\").value=\"" +
                    dateStr + "\"";
                //String javaS = "return document.getElementById(\"HrEffectiveDate\").value=\"01-Oct-2013\"";

                bodyBean.setOnLoad(javaS);

                if (cs.getString(3).equals("30")) {
                    throw new OAException("NOTE : You have to Serve 1 Month(s) notice period.",
                                          (byte)2);
                }

                if (cs.getString(3).equals("90")) {
                    throw new OAException("NOTE : You have to Serve 3 Month(s) notice period.",
                                          (byte)2);
                }

            } catch (NullPointerException ne) {
                String s = "";
                throw new OAException(" You Have To Serve the Last Date : " +
                                      cs.getDate(2), (byte)2);
            }

            cs.close();
            tr.commit();
        } catch (SQLException s) {
            System.out.println(s.getMessage());
        }
    }


    public void processFormRequest(OAPageContext pageContext,
                                   OAWebBean webBean) {

        String dateStr = null;
        String dateStr1 = null;
        //code to get default date
        //SimpleDateFormat f = new SimpleDateFormat("dd-mon-yyyy");
        OAApplicationModule aml = pageContext.getApplicationModule(webBean);
        int person_id = pageContext.getEmployeeId();
        pageContext.writeDiagnostics(webBean,
                                     "person_id in Resign Page : " + person_id,
                                     4);
        OADBTransaction tr = aml.getOADBTransaction();
        try {
            pageContext.writeDiagnostics(webBean, "After Try : ", 4);
            CallableStatement cs = null;
            String stmt =
                "BEGIN ABRAJ_EMP_RESIGN_LAST_DATE_KK(?,?,?,?,?,?); END;";
            cs = (OracleCallableStatement)tr.createCallableStatement(stmt, 0);

            cs.setInt(1, person_id);
            cs.registerOutParameter(2, Types.VARCHAR);
            cs.registerOutParameter(3, Types.NUMERIC);
            cs.registerOutParameter(4, Types.VARCHAR);
            cs.registerOutParameter(5, Types.VARCHAR);
            cs.registerOutParameter(6, Types.DATE);
            try {
                cs.execute();
            } catch (Exception e) {
                throw new OAException(e.getMessage(), (byte)0);
            }
            try {
                dateStr = cs.getString(5);
                dateStr1 = cs.getString(2);
            } catch (NullPointerException ne) {
                String s = "";
                throw new OAException(" You Have To Serve the Last Date : " +
                                      cs.getDate(2), (byte)2);
            }

            cs.close();
            tr.commit();
        } catch (SQLException s) {
            System.out.println(s.getMessage());
        }

        //end getting default date

        //start getting current value                                      
        OAMessageDateFieldBean effDateOld =
            (OAMessageDateFieldBean)webBean.findChildRecursive("HrEffectiveDate");
        java.util.Date date = null;
        String s2 = null;
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = simpledateformat.parse(effDateOld.getValue(pageContext).toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (date == null)
            date = pageContext.getCurrentDBDate();
        if (date != null)
            s2 = simpledateformat.format(date);
        //if(true) throw new OAException("my Effective Date: "+s2, OAException.INFORMATION);

        if (!s2.equalsIgnoreCase(dateStr)) {
            MessageToken[] tokens = { };
            //OAException message =
            throw new OAException("PER", "XXA_ABRAJ_LWD_DATE_MSG", tokens,
                                  OAException.ERROR, null);
            //throw new OAException("Cannot change Effective Date, should be: "+ message, OAException.ERROR);
        }

        super.processFormRequest(pageContext, webBean);
    }

}

No comments:

Post a Comment