<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.csc.library.entry.*,com.csc.library.database.DataSet" %>
<%@ page import="com.csc.library.utilities.*,com.csc.library.session.*,com.csc.library.components.*" %>
<jsp:useBean id="ASR002" scope="page" class="com.csc.library.system.Task"/>
<%
   ASR002.setChannel(request ,response);
   ReportEntry screen=null;
   screen=(ReportEntry)ASR002.process("ReportEntry",request.getParameter("__screen"));
   CheckNull chk = new CheckNull();

   DbRecord rec_emp = new InitialRecord(screen.getUProfile()).getDbRecord("Memployee");
   String bu1 = rec_emp.getField("bu1").getDescription();
   String bu2 = rec_emp.getField("bu2").getDescription();
   String bu3 = rec_emp.getField("bu3").getDescription();
   String bu4 = rec_emp.getField("bu4").getDescription();
   String bu5 = rec_emp.getField("bu5").getDescription();

   String bu1_tdesc = "";
   String bu1_edesc = "";
   String bu2_tdesc = "";
   String bu2_edesc = "";
   String bu3_tdesc = "";
   String bu3_edesc = "";
   String bu4_tdesc = "";
   String bu4_edesc = "";
   String bu5_tdesc = "";
   String bu5_edesc = "";

   DbInquiry inq_swaplang = new InitialInquiry(screen.getUProfile()).getDbInquiry("swaplang_detail");
   inq_swaplang.setColumn("*");
   inq_swaplang.setFilter("upper(codeid) in ('BU1','BU2','BU3','BU4','BU5')");
   inq_swaplang.setOrderBy("codeid");
   inq_swaplang.refresh();
   inq_swaplang.referLangOff();
   while(inq_swaplang.next()){
       String codeid = inq_swaplang.getString("codeid");
       if(codeid.equalsIgnoreCase("BU1")){
           bu1_tdesc = inq_swaplang.getString("thai");
           bu1_edesc = inq_swaplang.getString("eng");
       } else if(codeid.equalsIgnoreCase("BU2")){
           bu2_tdesc = inq_swaplang.getString("thai");
           bu2_edesc = inq_swaplang.getString("eng");
       } else if(codeid.equalsIgnoreCase("BU3")){
           bu3_tdesc = inq_swaplang.getString("thai");
           bu3_edesc = inq_swaplang.getString("eng");
       } else if(codeid.equalsIgnoreCase("BU4")){
           bu4_tdesc = inq_swaplang.getString("thai");
           bu4_edesc = inq_swaplang.getString("eng");
       } else if(codeid.equalsIgnoreCase("BU5")){
           bu5_tdesc = inq_swaplang.getString("thai");
           bu5_edesc = inq_swaplang.getString("eng");
       }
   }
%>
<html ng-app="myHR">
<head>
<title>ReportOption</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<link href="../CSS/bootstrap.css" rel="stylesheet"  type="text/css">
<link href="../CSS/bootstrap_csc_backend.css" rel="stylesheet"  type="text/css">
<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
<script type='text/javascript' src="../JS/bootstrap.js"></script>
<script language='javascript' src='../JS/SCREEN.js'></script>
<script src="../JS/angular-1.3.15/angular.js" type="text/javascript"></script>
<script src="../JS/ANGULAR/SCREEN_ANGULAR.js" type="text/javascript"></script>
<script src="../JS/jquery-2.1.3.min.js" type="text/javascript"></script>
<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
<script src="../JS/VIEWCALENDAR.js"></script>

<script language="JavaScript" type="text/JavaScript">
function back(){
    var filter = "bankid = 'CAH'";
    var thaihead = "รายการนำส่งเงินเข้าธนาคาร";
    var enghead = "Cash Peference Report";
	with(document.cscform){
        var salatype = "";
        var gendate = "";
        var period_gendate = "";
        var emp_type = "";
        var table = "";
        //var xml = "";

       /* if($("input[name=__period]:checked").val() === "1"){
            table = "tpytran0";
            xml = "PRR323";
        } else if($("input[name=__period]:checked").val() === "2"){
            table = "mempl_taxm";
            xml = "PRR323_HIS";
        }*/

        if($('#gendate').val() !== ""){
            filter += " and employeeid in (select employeeid from tpytran0 where gendate = '"+$('#gendate').val()+"')";
        }

        $(".emp_type").each(function(){
            if($(this).prop("checked")){
                emp_type = chkComma(emp_type) +  "'"+$(this).val()+"'";
            }
        });

        if(emp_type !== ""){
            filter += " and employeeid in(select employeeid from memployee where emp_type in ("+emp_type+"))";
        }

        $(".salatype").each(function(){
            if($(this).prop("checked")){
                salatype = chkComma(salatype) + "'"+$(this).val()+"'";
            }
        });

        if(salatype !== ""){
            filter += " and salatype in ("+salatype+")";
        }
        /*
		var group_by = __groupby_code.value;
        if(group_by === "BU1"){
            thaihead = "รายการนำส่งเงินเข้าธนาคาร - แยกตาม<%=bu1_tdesc%>";
            enghead = "Cash Peference Report - divide by <%=bu1_edesc%>";
        } else if(group_by === "BU2"){
            thaihead = "รายการนำส่งเงินเข้าธนาคาร - แยกตาม<%=bu2_tdesc%>";
            enghead = "Cash Peference Report - divide by <%=bu2_edesc%>";
        } else if(group_by === "BU3"){
            thaihead = "รายการนำส่งเงินเข้าธนาคาร - แยกตาม<%=bu3_tdesc%>";
            enghead = "Cash Peference Report - divide by <%=bu3_edesc%>";
        } else if(group_by === "BU4"){
            thaihead = "รายการนำส่งเงินเข้าธนาคาร - แยกตาม<%=bu4_tdesc%>";
            enghead = "Cash Peference Report - divide by <%=bu4_edesc%>";
        } else if(group_by === "BU5"){
            thaihead = "รายการนำส่งเงินเข้าธนาคาร - แยกตาม<%=bu5_tdesc%>";
            enghead = "Cash Peference Report - divide by <%=bu5_edesc%>";
        }*/

        //filter += " "+period_gendate+" "+emp_type+" "+salatype+" ";
        //var tdesc = $('input[name=__Pre_tdesc]').val();
        //var edesc = $('input[name=__Pre_edesc]').val();
	}
	with(window.opener.document.cscform){
		console.log("filter ==> "+filter);
		console.log("salatype ==> "+salatype);
		console.log("gendate ==> "+gendate);
		console.log("period_gendate ==> "+period_gendate);
		//console.log("group_by ==> "+group_by);
		//console.log("xml ==> "+xml);
		//console.log("tdesc ==> "+tdesc);
		//console.log("edesc ==> "+edesc);
		__fixfiltertbank_tran0.value = filter;
		//__fixfiltertbank_his0.value = filter;
		//__GROUPBY_CODE.value = group_by;
        //__groupbystd.value = group_by.toLowerCase();
        //__groupby.value = group_by.toLowerCase();
		//__REPORT_XML.value = xml;
		//__screen.value = xml;
		//__orderText.value = group_by;
		//__groupText.value = group_by;
        //__PRE_TDESC.value = tdesc;
        //__PRE_EDESC.value = edesc;
        //__template.value = xml + ".jasper$";
        // __THAIHEAD.value = thaihead;
        //__ENGHEAD.value = enghead;
	}
	window.close();
}

function chkLength(str){
    if(str !== ""){
        str += " and ";
    }
    return str;
}

function chkComma(str){
    if(str !== ""){
        str += ",";
    }
    return str;
}

function goHelp(helpName,inputName){
	with(document.cscform){
		var helpReturn;
		var fixcon = '';
		if(inputName.indexOf("__salatype") > -1){
			helpReturn = inputName+":codeid,MSALATYPE0@TDESC|DESC"
			linkHelp_Return(helpName,helpReturn,fixcon);
		}
	}
}

function postReturn(){
    with(document.cscform){
        submit();
    }
}

$(function(){
    with(document.cscform){
        $('.period').change(function(){
            $('input[name=__salatype]').val("");
            $('.salatypedesc').val("");
            $('.gendate').addClass("hide");
        });
    }

    $('#select_salatype').change(function(){
        $('.salatype').prop('checked', $('#select_salatype').prop('checked'));
        postReturn();
    });

    $('#select_emp_type').change(function(){
        $('.emp_type').prop('checked', $('#select_emp_type').prop('checked'));
    });
});

</script>
<style>
    .hide { display: none }
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif')">
<form name="cscform" method="post" action="PRR323.jsp">


<!----------BEGIN CSC INITIAL ZONE ------------------------>

<%=screen.InitialVariable()%>

<!----------END CSC INITIAL ZONE -------------------------->

<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__fixCon" value="">
<input type="hidden" name="__language" value ="<%=screen.getUProfile().get("lang")%>">
<script language="javascript">getInputFormatDate();</script>
<input type="hidden" name="__calendar">
    <div align="center">
    <br>
    <table cellpadding="0"  cellspacing="0" style="width: 800px">
        <tr>
            <td class="header"><span swlang code='SW000128'>Report Option</span>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2">
                <div align="center">
                    <table  cellpadding="0" cellspacing="0" >
                        <tr>
                            <td colspan="2"  class="blankspace"></td>
                        </tr>
                        <tr>
                            <td align="right" width="250" style="vertical-align:top;"><span swlang code='SW000315'>Salatype</span>&nbsp;::&nbsp;</td>
                            <td>
                                &nbsp;<input type="checkbox" id="select_salatype" class="salatype">&nbsp;<span swlang code='SW002185'>Select All</span>
                                <table>
                                    <%
                                        String period = chk.chkNullString(request.getParameter("__period"),"1");
                                        int round = 3;
                                        int max_column = round;
                                        String salatype = "";
                                        DbInquiry inq_salatype0 = new InitialInquiry(screen.getUProfile()).getDbInquiry("msalatype0");
                                        inq_salatype0.setColumn("*");
                                        inq_salatype0.setOrderBy("codeid");
                                        inq_salatype0.refresh();
                                        inq_salatype0.referLangOn();                                    
                                        while(inq_salatype0.next()){
                                            String codeid = inq_salatype0.getString("codeid");
                                            String chksalatype = chk.chkNullString(request.getParameter("salatype"+codeid));
                                            String checked = "";
                                            if(round >= max_column){
                                                out.println("<tr>");
                                                round = 1;
                                            } else {
                                                round++;
                                            }
                                            if(!chksalatype.equals("")){
                                                salatype += "'"+codeid+"',";
                                                checked = "checked";
                                            }
                                    %>
                                        <td><input type="checkbox" value="<%=codeid%>" name="salatype<%=codeid%>" class="salatype" onchange="postReturn();" <%=checked%>>&nbsp;<%=inq_salatype0.getString("tdesc")%></td>
                                    <%
                                            if(round >= max_column){
                                                out.println("</tr>");
                                            }
                                        }
                                        if (!salatype.equals("")) {
                                            salatype = salatype.substring(0, salatype.length() - 1);
                                        }
                                    %>
                                </table>
                            </td>
                        </tr>
                        <%  String period_current = chk.chkNullString(request.getParameter("__period_current")); %>
                        <tr class="gendate">
                            <td align="right"><span swlang code='SW011908'>Period Current</span>&nbsp;::&nbsp;</td>
                            <td>
                                <select name="__period_current" size="0" id="gendate">
                                    <option value="" <%if(period_current.equalsIgnoreCase("")){%>selected<%}%>></option>
                                    <%
                                        if (!salatype.equals("")) {
                                            String sql_cur="select DISTINCT gendate from tpytran0 where salatype in ("+salatype+") order by gendate";
                                            DataSet Per_cur = new DataSet(sql_cur, screen.getUProfile().getDbName(), "");
                                            Per_cur.setFetchAll(false);
                                            Per_cur.initConnection(screen.getUProfile());
                                            while(Per_cur.next()){
                                    %>
                                    <option value="<%=Per_cur.getString("gendate")%>" <%if(period_current.equalsIgnoreCase(Per_cur.getString("gendate"))){%>selected<%}%>><%=Per_cur.getString("gendate")%></option>
                                        <%  } Per_cur.closeConnection(); } %>
                                </select>                               
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2"  class="blankspace"></td>
                        </tr>
                       <tr>
                            <td class="columnlabel" style="vertical-align:top;"><span swlang code='SW002408'>Employment Type</span>&nbsp;::&nbsp;</td>
                            <td>
                                &nbsp;<input type="checkbox" id="select_emp_type" class="emp_type">&nbsp;<span swlang code='SW002185'>Select All</span>
                                <table>
                                <%
                                    round = max_column;
                                	DbInquiry de = new InitialInquiry(screen.getUProfile()).getDbInquiry("MEMPLOYMENT_TYPE");
                                	de.setColumn("*");
                                	de.refresh();
                                	de.referLangOn();
                                	while(de.next()){
                                        String codeid = de.getString("codeid");
                                        String chkemp_type = chk.chkNullString(request.getParameter("emp_type"+codeid));
                                        String checked = "";
                                        if(round >= max_column){
                                            out.println("<tr>");
                                            round = 1;
                                        } else {
                                            round++;
                                        }
                                        if(!chkemp_type.equals("")){
                                            checked = "checked";
                                        }
                                %>
                                    <td><input type="checkbox" value="<%=codeid%>" name="emp_type<%=codeid%>" class="emp_type" <%=checked%>>&nbsp;<%=de.getString("tdesc")%></td>
                                <%
                                        if(round >= max_column){
                                            out.println("</tr>");
                                        }
                                	}
                                %>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" class="blankspace"></td>
                        </tr>

                      <tr>
                        <td  class="buttonline" colspan="7"><div align="center">
                          <button type="button" class="btn btn-primary width100" swlang code="SW013169" onClick="back();">OK</button>&nbsp;
                          <button type="button" class="btn btn-primary width100" swlang code="SW006927" onClick="window.close();">CANCEL</button>
                        </div>
                        </td>
                      </tr>
                        <tr>
                            <td colspan="2" class="blankspace"></td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
        <tr bordercolor="0069B3">
            <td  class="bottom"></td>
        </tr>
    </table>
</div>
<INPUT TYPE="hidden" NAME="__screen" VALUE="<%=request.getParameter("__screen")%>">
</form>
</body>
</html>