<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.Date,java.text.DateFormat,java.text.SimpleDateFormat,java.text.DecimalFormat" %>
<%@ page import="java.util.*" %>

<%!

//INSERT INTO promis.workdaily(workid,workdate,staffid) VALUES(1,TO_DATE('2020-05-28','YYYY-MM-DD'),198)
//HttpServletRequest request,HttpSession session
public boolean getCheckIn(Connection con,String workdate,String staffid) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid ";
    sql+=",TO_CHAR(checkindatetime,'YYYY-MM-DD HH24:MI:SS') checkindatetime ";
    //sql+=",TO_CHAR(checkoutdatetime,'HH24:MI:SS') checkouttime ";
    //sql+=",checkoutip ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE workdate=? ";
    sql+="AND staffid=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,workdate);
    ps.setString(2,staffid);
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
        if (rs.getString("checkindatetime")!=null) {
            result=true;
        }
        rs.close();
    }
    ps.close();

    return result;
}//getCheckIn

public boolean getCheckOut(Connection con,String workdate,String staffid) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid ";
    sql+=",TO_CHAR(checkoutdatetime,'YYYY-MM-DD HH24:MI:SS') checkoutdatetime ";
    //sql+=",TO_CHAR(checkoutdatetime,'HH24:MI:SS') checkouttime ";
    //sql+=",checkoutip ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE workdate=? ";
    sql+="AND staffid=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,workdate);
    ps.setString(2,staffid);
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
        if (rs.getString("checkoutdatetime")!=null) {
            result=true;
        }
        rs.close();
    }
    ps.close();

    return result;
}//getCheckOut

public ResultSet getWorkCheckIn(Connection con,String workid) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid,workdetail ";
    sql+=",TO_CHAR(checkindatetime,'YYYY-MM-DD HH24:MI:SS') checkindatetime ";
    sql+=",TO_CHAR(checkindatetime,'HH24:MI:SS') checkintime ";
    sql+=",checkinip ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE workid=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,workid);
    ResultSet rs = ps.executeQuery();

    return rs;
}//getWorkCheckIn

public ResultSet getWorkCheckOut(Connection con,String workdate,String staffid) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid,workdetail ";
    sql+=",TO_CHAR(checkoutdatetime,'YYYY-MM-DD HH24:MI:SS') checkoutdatetime ";
    sql+=",TO_CHAR(checkoutdatetime,'HH24:MI:SS') checkouttime ";
    sql+=",checkoutip ";
    sql+="FROM promis.workdaily ";
    //sql+="WHERE workid=? ";
    sql+="WHERE workdate=? ";
    sql+="AND staffid=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,workdate);
    ps.setString(2,staffid);
    ResultSet rs = ps.executeQuery();

    return rs;
}//getWorkCheckIn

public ResultSet getWorkProblem(Connection con,String workdate,String staffid) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid,workproblem, worksite ";
    sql+=",to_char(workdatetime,'YYYY-MM-DD HH24:MI:SS') workdatetime ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE workdate=? ";
    sql+="AND staffid=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,workdate);
    ps.setString(2,staffid);
    ResultSet rs = ps.executeQuery();

    return rs;
}//getWorkProblem

/*
public ResultSet getWorkDetail(Connection con,String workid) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid,workdetail,(workdate||' 00:00:00') workdatetime ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE workid=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,workid);
    ResultSet rs = ps.executeQuery();

    return rs;
}//getWorkDetail
*/
public ResultSet getWorkDetail(Connection con,String workdate,String staffid) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid,workdetail, worksite ";
    sql+=",to_char(workdatetime,'YYYY-MM-DD HH24:MI:SS') workdatetime ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE workdate=? ";
    sql+="AND staffid=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,workdate);
    ps.setString(2,staffid);
    ResultSet rs = ps.executeQuery();

    return rs;
}//getWorkDetail

public boolean getWork(Connection con,String staffid,String workdate,HttpSession session) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid,workdate,staffid ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE staffid=? ";
    sql+="AND workdate=? ";
    
    //sql+="AND  TO_CHAR(workdate,'YYYY-MM-DD')=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,staffid);
    ps.setString(2,workdate);
    ResultSet rs = ps.executeQuery();

    if (rs.next()) {
        session.setAttribute("workid",rs.getString("workid"));
        session.setAttribute("staffid",rs.getString("staffid"));
        //session.setAttribute("workdate",rs.getString("workdate"));
        session.setAttribute("entryworkdate",rs.getString("workdate"));
        session.setAttribute("dailyworkid",rs.getString("workid"));
        result=true;
        rs.close();
    }
    ps.close();
    
    return result;
}//getWork

public boolean getWorkOnCurrentDate(Connection con,String staffid,String workdate,HttpSession session) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT workid,workdate,staffid ";
    sql+="FROM promis.workdaily ";
    sql+="WHERE staffid=? ";
    sql+="AND workdate=? ";
    
    //sql+="AND  TO_CHAR(workdate,'YYYY-MM-DD')=? ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,staffid);
    ps.setString(2,workdate);
    ResultSet rs = ps.executeQuery();

    if (rs.next()) {
        //session.setAttribute("workid",rs.getString("workid"));
        session.setAttribute("staffid",rs.getString("staffid"));
        session.setAttribute("dailyworkdate",rs.getString("workdate"));
        session.setAttribute("entryworkdate",rs.getString("workdate"));
        session.setAttribute("dailyworkid",rs.getString("workid"));
        result=true;
        rs.close();
    }
    ps.close();
    
    return result;
}//getWorkOnCurrentDate


public boolean setCreateWork_ok(Connection con,String workid,String staffid,String workdate,HttpServletRequest request,HttpSession session) throws SQLException 
{
    String sql="";
    //sql+="INSERT INTO promis.workdaily(workid,workdate,staffid,checkindatetime,checkinip) ";
    sql+="INSERT INTO promis.workdaily(workid,workdate,staffid) ";
    sql+="VALUES(?,?,?) ";

    String ip=request.getRemoteHost();

    java.util.Date today = new java.util.Date();
    java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());

    //checkindatetime, ipcheckin
    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        int n=1;
        ps.setInt(n++,Integer.parseInt(workid));
        ps.setString(n++,workdate);
        ps.setString(n++,staffid);
        ps.executeUpdate();   
        result=true;
        session.setAttribute("workid",String.valueOf(workid));
        session.setAttribute("workdate",workdate);
        session.setAttribute("staffid",staffid);
    } catch (Exception e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }
    
    return result;
}//

public boolean setCreateWork(Connection con,String workid,String staffid,String workdate,HttpServletRequest request,HttpSession session) throws SQLException 
{
    String sql="";
    sql+="INSERT INTO promis.workdaily(workid,workdate,staffid,checkindatetime,checkinip,workdatetime) ";
    //sql+="INSERT INTO promis.workdaily(workid,workdate,staffid,workdatetime) ";
    sql+="VALUES(?,?,?,?,?,?) ";

    String ip=request.getRemoteHost();

    //java.util.Date today = new java.util.Date();
    //java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());
    //java.sql.Timestamp  timestamp = getCalendarTimestamp(workdate+" 00:00:00");
    //checkindatetime, ipcheckin
    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        //java.sql.Timestamp timestamp=getCalendarTimestamp(workdate+" 00:00:00");
        java.util.Date today = new java.util.Date();
        java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());
        java.sql.Timestamp workdatetimestamp=getCalendarTimestamp(workdate+" 00:00:00");

        int n=1;
        ps.setInt(n++,Integer.parseInt(workid));
        ps.setString(n++,workdate);
        ps.setString(n++,staffid);
        ps.setTimestamp(n++,timestamp);
        ps.setString(n++,ip);
        ps.setTimestamp(n++,workdatetimestamp);
        ps.executeUpdate();   
        result=true;
        session.setAttribute("workid",String.valueOf(workid));
        session.setAttribute("dailyworkid",String.valueOf(workid));
        session.setAttribute("workdate",workdate);
        session.setAttribute("staffid",staffid);
    } catch (Exception e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }
    
    return result;
}//

public boolean setCreateWorkDaily(Connection con,String workid,String staffid,String workdate,HttpServletRequest request,HttpSession session) throws SQLException 
{
    String sql="";
    //sql+="INSERT INTO promis.workdaily(workid,workdate,staffid,checkindatetime,checkinip,workdatetime) ";
    sql+="INSERT INTO promis.workdaily(workid,workdate,staffid,workdatetime) ";
    sql+="VALUES(?,?,?,?) ";

    String ip=request.getRemoteHost();

    //java.util.Date today = new java.util.Date();
    //java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());
    //java.sql.Timestamp  timestamp = getCalendarTimestamp(workdate+" 00:00:00");
    //checkindatetime, ipcheckin
    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        //java.sql.Timestamp timestamp=getCalendarTimestamp(workdate+" 00:00:00");
        java.util.Date today = new java.util.Date();
        java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());
        java.sql.Timestamp workdatetimestamp=getCalendarTimestamp(workdate+" 00:00:00");

        int n=1;
        ps.setInt(n++,Integer.parseInt(workid));
        ps.setString(n++,workdate);
        ps.setString(n++,staffid);
        //ps.setTimestamp(n++,timestamp);
        //ps.setString(n++,ip);
        ps.setTimestamp(n++,workdatetimestamp);
        ps.executeUpdate();   
        result=true;
        //session.setAttribute("workid",String.valueOf(workid));
        session.setAttribute("dailyworkid",String.valueOf(workid));
        session.setAttribute("dailyworkdate",workdate);
        session.setAttribute("staffid",staffid);
    } catch (Exception e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }
    
    return result;
}//

public int getNewWorkId(Connection con) throws SQLException 
{
    String sql="";
    sql+="SELECT (NVL(max(workid),0)+1) workid  ";
    sql+="FROM promis.workdaily ";

    int workid=0;
    PreparedStatement ps = con.prepareStatement(sql);
    ResultSet rs = ps.executeQuery();

    if (rs.next()) {
        workid=rs.getInt("workid");
        rs.close();
    }
    ps.close();
    
    return workid;
}

public boolean setUpdateWork(Connection con,String workid,String workdetail,HttpServletRequest request) throws SQLException 
{
    String sql="";
    sql+="UPDATE promis.workdaily ";
    sql+="SET workdetail=? ";
    sql+=",updatedatetime=? ";
    sql+=",updateip=? ";
    sql+="WHERE workid=? ";
    
    String ip=request.getRemoteHost();

    java.util.Date today = new java.util.Date();
    java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());

    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        int n=1;
        //String detail="";
        if (workdetail.length()>3000) workdetail=workdetail.substring(0,3000);
        ps.setString(n++,workdetail); 
        ps.setTimestamp(n++,timestamp);
        ps.setString(n++,ip);
        ps.setString(n++,workid);
        ps.executeUpdate();  
        result=true;     
    } catch (SQLException e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }//try

    return result;
} //setExamUpdateWork

public boolean setUpdateWork(Connection con,String workid,String workdetail,String worksite,HttpServletRequest request) throws SQLException 
{
    String sql="";
    sql+="UPDATE promis.workdaily ";
    sql+="SET workdetail=? ";
    sql+=",worksite=? ";
    sql+=",updatedatetime=? ";
    sql+=",updateip=? ";
    sql+="WHERE workid=? ";
    
    String ip=request.getRemoteHost();

    java.util.Date today = new java.util.Date();
    java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());

    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        int n=1;
        //String detail="";
        if (workdetail.length()>3000) workdetail=workdetail.substring(0,3000);
        ps.setString(n++,workdetail); 
        ps.setString(n++,worksite); 
        ps.setTimestamp(n++,timestamp);
        ps.setString(n++,ip);
        ps.setString(n++,workid);
        ps.executeUpdate();  
        result=true;     
    } catch (SQLException e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }//try

    return result;
} //setExamUpdateWork

public boolean setUpdateWorkProblem(Connection con,String workid,String workproblem,HttpServletRequest request) throws SQLException 
{
    String sql="";
    sql+="UPDATE promis.workdaily ";
    sql+="SET workproblem=? ";
    sql+=",updatedatetime=? ";
    sql+=",updateip=? ";
    sql+="WHERE workid=? ";
    
    String ip=request.getRemoteHost();

    java.util.Date today = new java.util.Date();
    java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());

    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        int n=1;
        if (workproblem.length()>500) workproblem=workproblem.substring(0,500);
        ps.setString(n++,workproblem); 
        ps.setTimestamp(n++,timestamp);
        ps.setString(n++,ip);
        ps.setString(n++,workid);
        ps.executeUpdate();  
        result=true;     
    } catch (SQLException e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }//try

    return result;
} //setExamUpdateWorkProblem

public boolean setUpdateWorkProblem(Connection con,String workid,String workproblem,String worksite,HttpServletRequest request) throws SQLException 
{
    String sql="";
    sql+="UPDATE promis.workdaily ";
    sql+="SET workproblem=? ";
    sql+=",worksite=? ";
    sql+=",updatedatetime=? ";
    sql+=",updateip=? ";
    sql+="WHERE workid=? ";
    
    String ip=request.getRemoteHost();

    java.util.Date today = new java.util.Date();
    java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());

    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        int n=1;
        if (workproblem.length()>500) workproblem=workproblem.substring(0,500);
        ps.setString(n++,workproblem); 
        ps.setString(n++,worksite); 
        ps.setTimestamp(n++,timestamp);
        ps.setString(n++,ip);
        ps.setString(n++,workid);
        ps.executeUpdate();  
        result=true;     
    } catch (SQLException e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }//try

    return result;
} //setExamUpdateWorkProblem

public boolean setWorkCheckIn(Connection con,String workid,HttpServletRequest request) throws SQLException 
{
    String sql="";
    sql+="UPDATE promis.workdaily ";
    sql+="SET checkindatetime=? ";
    sql+=",checkinip=? ";
    sql+="WHERE workid=? ";
    
    String ip=request.getRemoteHost();

    java.util.Date today = new java.util.Date();
    java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());

    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        int n=1;
        ps.setTimestamp(n++,timestamp);
        ps.setString(n++,ip);
        ps.setString(n++,workid);
        ps.executeUpdate();  
        result=true;     
    } catch (SQLException e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }//try

    return result;
} //setWorkCheckIn

public boolean setWorkCheckOut(Connection con,String workid,HttpServletRequest request) throws SQLException 
{
    String sql="";
    sql+="UPDATE promis.workdaily ";
    sql+="SET checkoutdatetime=? ";
    sql+=",checkoutip=? ";
    sql+="WHERE workid=? ";
    
    String ip=request.getRemoteHost();

    java.util.Date today = new java.util.Date();
    java.sql.Timestamp  timestamp = new java.sql.Timestamp(today.getTime());

    boolean result=false;
    PreparedStatement ps = con.prepareStatement(sql);
    try {
        int n=1;
        ps.setTimestamp(n++,timestamp);
        ps.setString(n++,ip);
        ps.setString(n++,workid);
        ps.executeUpdate();  
        result=true;     
    } catch (SQLException e) {
        result=false;
    } finally {
        if (ps!=null) ps.close();
    }//try

    return result;
} //setWorkCheckOut


public boolean getUpdateFingerScanIn(Connection con,String staffid,String workdate,HttpSession session) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT pin,checkdatetime,checktype,staffid ";
    sql+=",to_char(checkdatetime,'YYYY-MM-DD HH24:MI:SS') scancheckin ";
    sql+="FROM ";
    sql+="( ";
    sql+="SELECT t.pin,t.checkdatetime ";
    sql+=",CASE WHEN to_char(t.checkdatetime,'HH24:MI:SS') < '16:30:00' THEN 1 ";
    sql+="ELSE 2 END  checktype ";
    sql+=",b.staffid ";
    sql+="FROM promis.workchecktime t,promis.staffattbarcode b ";
    sql+="WHERE t.pin=b.barcode ";
    sql+="AND b.staffid=? ";
    sql+="AND to_char(t.checkdatetime,'YYYY-MM-DD')=? ";
    sql+="ORDER BY t.checkdatetime ";
    sql+=") ";
    sql+="WHERE checktype=1 ";
    sql+="ORDER BY checkdatetime  ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,staffid);
    ps.setString(2,workdate);
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
        String scancheckin=rs.getString("scancheckin");        
        sql ="UPDATE promis.workdaily ";
        sql+="SET scancheckin=? ";
        sql+="WHERE workid=? ";
        //rs.close();
        ps = con.prepareStatement(sql);
        try {
            //int n=1;
            String workid=(String)session.getAttribute("workid");
            java.sql.Timestamp timestamp=getCalendarTimestamp(scancheckin);
            //java.sql.Timestamp timestamp=getCalendarTimestamp("2021-07-11 07:17:37");
            ps.setTimestamp(1,timestamp);
            ps.setString(2,workid);
            ps.executeUpdate();  
            result=true;     
        } catch (Exception e1) {
            result=false;
        } //try
    } //while
    if (rs!=null) rs.close();
    if (ps!=null) ps.close();
    
    return result;
}//getUpdateFingerScanIn

public boolean getUpdateFingerScanOut(Connection con,String staffid,String workdate,HttpSession session) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT pin,checkdatetime,checktype,staffid ";
    sql+=",to_char(checkdatetime,'YYYY-MM-DD HH24:MI:SS') scancheckout ";
    sql+="FROM ";
    sql+="( ";
    sql+="SELECT t.pin,t.checkdatetime, ";
    sql+="CASE WHEN to_char(t.checkdatetime,'HH24:MI:SS') < '16:30:00' THEN 1 ";
    sql+="ELSE 2 END  checktype ";
    sql+=",b.staffid ";
    sql+="FROM promis.workchecktime t,promis.staffattbarcode b ";
    sql+="WHERE t.pin=b.barcode ";
    sql+="AND b.staffid=? ";
    sql+="AND to_char(t.checkdatetime,'YYYY-MM-DD')=? ";
    sql+="ORDER BY t.checkdatetime ";
    sql+=") ";
    sql+="WHERE checktype=2 ";
    sql+="ORDER BY checkdatetime desc ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,staffid);
    ps.setString(2,workdate);
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
        String scancheckout=rs.getString("scancheckout");        
        sql ="UPDATE promis.workdaily ";
        sql+="SET scancheckout=? ";
        sql+="WHERE workid=? ";
        //rs.close();
        ps = con.prepareStatement(sql);
        try {
            //int n=1;
            String workid=(String)session.getAttribute("workid");
            java.sql.Timestamp timestamp=getCalendarTimestamp(scancheckout);
            //java.sql.Timestamp timestamp=getCalendarTimestamp("2021-07-11 17:27:37");
            ps.setTimestamp(1,timestamp);
            ps.setString(2,workid);
            ps.executeUpdate();  
            result=true;     
        } catch (Exception e1) {
            result=false;
        } //try
    } //while
    if (rs!=null) rs.close();
    if (ps!=null) ps.close();
    
    return result;
}//getUpdateFingerScanOut
public boolean getUpdateFingerScanOutBefore(Connection con,String staffid,String workdate) throws SQLException 
{
    boolean result=false;
    String sql="";
    sql+="SELECT pin,checkdatetime,checktype,staffid ";
    sql+=",to_char(checkdatetime,'YYYY-MM-DD HH24:MI:SS') scancheckout ";
    sql+="FROM ";
    sql+="( ";
    sql+="SELECT t.pin,t.checkdatetime, ";
    sql+="CASE WHEN to_char(t.checkdatetime,'HH24:MI:SS') < '16:30:00' THEN 1 ";
    sql+="ELSE 2 END  checktype ";
    sql+=",b.staffid ";
    sql+="FROM promis.workchecktime t,promis.staffattbarcode b ";
    sql+="WHERE t.pin=b.barcode ";
    sql+="AND b.staffid=? ";
    sql+="AND to_char(t.checkdatetime,'YYYY-MM-DD')=? ";
    sql+="ORDER BY t.checkdatetime ";
    sql+=") ";
    sql+="WHERE checktype=2 ";
    sql+="ORDER BY checkdatetime desc ";

    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1,staffid);
    ps.setString(2,workdate);
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
        String scancheckout=rs.getString("scancheckout");        
        sql ="UPDATE promis.workdaily ";
        sql+="SET scancheckout=? ";
        sql+="WHERE staffid=? ";
        sql+="AND workdate=? ";
        //rs.close();
        ps = con.prepareStatement(sql);
        try {
            int n=1;
            //String workid=(String)session.getAttribute("workid");
            java.sql.Timestamp timestamp=getCalendarTimestamp(scancheckout);
            //java.sql.Timestamp timestamp=getCalendarTimestamp("2021-07-11 17:27:37");
            ps.setTimestamp(n++,timestamp);
            ps.setString(n++,staffid);
            ps.setString(n++,workdate);
            ps.executeUpdate();  
            result=true;     
        } catch (Exception e1) {
            result=false;
        } //try
    } //while
    if (rs!=null) rs.close();
    if (ps!=null) ps.close();
    
    return result;
}//getUpdateFingerScanOut
%>