<%@page contentType="text/html; charset=UTF-8" %>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*" %>
<%@ page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*" %>
<%@ page import="com.csc.library.databean.Simhtraining" %>
<jsp:useBean id="TRE005_6" class="com.csc.library.system.Task" scope="page"/>
<%
  TRE005_6.setChannel(request, response);
  UIManager screen = (UIManager) TRE005_6.process("MultiEntry", "TRE005_PHATRA", true);

  MultiLine multi = screen.getMultiLine("HTRAINEETIME");
  MultiLine multiTime = screen.getMultiLine("HTRAININGTIME");

  screen.referLangOn();

  CheckNull chk = new CheckNull();
  String trainDateSearch = chk.chkNullString(request.getParameter("__trainDateSearch"));
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html ng-app="myHR">
<head>
  <title></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 type='text/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 language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
  <script language="javascript">getTitleName();</script>
  <script src="../JS/VIEWCALENDAR.js"></script>
  <script language="JavaScript" src='../JS/ICONSMENU.js'></script>
  <script language='javascript' src='../JS/HOTKEY.js'></script>
  <script language="javascript">

      function GoSave() {
          confirmSave();
      }
      function GoSearch() {
          search();
      }
      function GoDelete() {
          edelete();
      }
      function GoUpdate() {
          update();
          GoSearch();
      }
      function checkCF() {
          checkConfirm();
      }

      function chkTrain() {
          with (document.cscform) {
              for (i = 0; i < elements.length; i++) {
                  elements[i].checked = false;
              }
          }
      }
      function deleteRec() {
          var recDelete = "";
          with (window.document.cscform) {
              bCon = confirm(MyCode[4]);
              if (bCon == true) {
                  for (i = 0; i < elements.length; i++) {
                      if (elements[i].type == "checkbox") {
                          if (elements[i].checked == true) {
                              recDelete = recDelete + "#" + elements[i].value;
                          }
                      }
                  }
                  __reccordDelete.value = recDelete;
                  __cmd.value = "save";
                  __confirm.value = "s";
                  submit();
              }
          }
      }
      function checkupdate() {
          with (document.cscform) {
              for (i = 0; i < elements.length; i++) {
                  if (elements[i].name.indexOf("$") > -1) {
                      if (elements[i].value == "") {
                          alert(MyCode[26]);
                          break;
                      } else {
                          update();
                          break;
                      }
                  }
              }
          }
      }
      function goSearchDate() {
          with (document.cscform) {
              setFixDate();
              submit();
          }

      }
      function setFixDate() {
          with (document.cscform) {
              if (__traindate.options[__traindate.selectedIndex].value != "") {
                  __trainDateSearch.value = __traindate.options[__traindate.selectedIndex].value;
                  __fixDate.value = __traindate.options[__traindate.selectedIndex].value;
              } else {
                  __trainDateSearch.value = "";
                  __fixDate.value = "";
              }
          }
      }
      function setChkBoxValue(line) {
          with (document.cscform) {
              staTime = eval("__HTRAINEETIME$STATUS$" + line);
              chkBox = eval("chk$" + line);
              if (chkBox.checked) {
                  staTime.value = "1";
              } else {
                  staTime.value = "0";
              }
          }
      }
      function checkAll() {
          with (document.cscform) {
              for (i = 0; i < elements.length; i++) {
                  if (elements[i].type == "checkbox") {
                      elements[i].checked = true;
                      staTime = eval("__HTRAINEETIME$STATUS$" + elements[i].value);
                      staTime.value = "1";
                  }
              }
          }
      }
      function decheckAll() {
          with (document.cscform) {
              for (i = 0; i < elements.length; i++) {
                  if (elements[i].type == "checkbox") {
                      elements[i].checked = false;
                      staTime = eval("__HTRAINEETIME$STATUS$" + elements[i].value);
                      staTime.value = "0";
                  }
              }
          }
      }
      function getAllDate() {
          if (getLang() == "tha") {
              document.write("ทั้งหมด");
          } else {
              document.write("all date");
          }
      }
      function childMulti(record, traineeid, traindate) {
          with (document.cscform) {
              window.open(__childMulti.value + ".jsp?__cmd=&__gorec=" + record + "&__ack=edit" +
                  "&__traineeid=" + traineeid +
                  "&__traindate=" + traindate +
                  "&__fixDate=" + __fixDate.value +
                  "&__trainingid=" + window.parent.document.forms[0].__trainingid.value +
                  "&__headMulti=" + cscform.__screen.value +
                  "&__companyid=" + window.parent.cscform.__companyid.value, "TraineeTime", "left=150,top=150,width=700,height=280,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
          }
      }
      function calTwoTime_Break(time1, time2, ttime, bt) {
          if (time1.value != "" && time2.value != "") {
              if (parseFloat(time1.value) <= parseFloat(time2.value)) {
                  var tmp = time1.value.split(".");
                  var tm1 = (tmp[0] * 60) + parseInt(tmp[1]);
                  tmp = time2.value.split(".");
                  var tm2 = (tmp[0] * 60) + parseInt(tmp[1]);
                  tmp = bt.value.split(".");
                  var tm3 = (tmp[0] * 60) + parseInt(tmp[1]);
                  var total = (tm2 - tm1) - tm3;
                  var tmpMin = (total % 60) + "";
                  if (tmpMin.length < 2) {
                      tmpMin = "0" + tmpMin;
                  }
                  var tmpMax = parseInt((total / 60)) + "";
                  ttime.value = tmpMax + "." + tmpMin;
              } else {
                  ttime.value = "0.00";
              }
          } else {
              ttime.value = "0.00";
          }
          if (parseFloat(ttime.value) < 0.00) {
              ttime.value = "0.00";
          }
      }

      function genTrneeTime() {
          with (document.cscform) {
              if (__recTTime.value > 0) {
                  with (document.cscform) {
//					window.parent.restTabPages();
                      __isgen.value = "1";
                      __cmd.value = "ack";
                      submit();
                  }
              } else {
                  if (getLang() == "tha") {
                      alert("ไม่สามารถทำแบบบันทึกวันเวลาเข้าอบรมของพนักงานได้\nกรุณาเพิ่มข้อมูลของวันที่และเวลาการอบรมของรุ่น " + __crsid.value);
                  } else {
                      alert("   con't generate form training time   \nplease insert date and time for trainingid " + __crsid.value)
                  }
              }
          }
      }
  </script>
</head>
<body leftmargin="0" topmargin="0"
      onLoad="MM_preloadImages('addswap.gif','editswap.gif','deleteswap.gif','helpmenuswap.gif','exitswap.gif','searchmenuswap.gif','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif')">
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
<script language="javascript">initToolTips();</script>
<form name="cscform" method="post" action="?">


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

  <%=screen.InitialVariable()%>

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

  <input type="hidden" name="__cmd" value="ack">
  <input type="hidden" name="__screen" value="TRE005_PHATRA">
  <input type="hidden" name="__childMulti" value="TRE005_6C_PHATRA">
  <input type="hidden" name="__help" value="">
  <input type="hidden" name="__gorec" value="">
  <input type="hidden" name="__ack" value="">
  <input type="hidden" name="__fixDate" value="<%=chk.chkNullString(request.getParameter("__fixDate"))%>">
  <input type="hidden" name="__trainDateSearch"
         value="<%=chk.chkNullString(request.getParameter("__trainDateSearch"))%>">
  <input type="hidden" name="__childFilter" value="">
  <input type="hidden" name="__trainingid" value="<%=chk.chkNullString(request.getParameter("__trainingid"))%>">
  <input type="hidden" name="__multiTable" value="HTRAINEETIME">
  <input name="__companyid" type="hidden" value="<%=screen.getUProfile().get("companyid")%>">
  <input type="hidden" name="__maxrec" value="<%=screen.getTable("HTRAININGTIME").recCount()%>">
  <input type="hidden" name="__notNull" value="<%=screen.getRequire()%>">
  <input type="hidden" name="__fixCon" value="">
  <input type="hidden" name="__confirm" value="0">
  <input type="hidden" name="__recTTime" value="<%=screen.getRecord().getChild("HTRAININGTIME").recCount()%>">
  <input type="hidden" name="__isgen" value="0">
  <table border="0" cellpadding="0" cellspacing="0" bordercolor="#3366CC" class="maxsize">
    <tr>
      <td class="header">TRE005_6_PHATRA,
        <script language="javascript">swapLang('To record training time of Trainee');</script>
        &nbsp;
      </td>
    </tr>
    <tr>
      <td class="blankspace"></td>
    </tr>
    <tr>
      <td>
        <table cellpadding="0" cellspacing="0" class="maxsize">
          <tr>
            <td width="80%" align="right"><%=multi.getLabel("HTRAINEETIME", "TRAINDATE")%>&nbsp;
              <select name="__traindate">
                <option value="" <%=(trainDateSearch.equals("")) ? "selected" : ""%> >
                  <script language="javascript">getAllDate();</script>
                </option>
                <%
                  multiTime.goFirst();
                  for (int i = 1; !multiTime.eof(); i++) {
                %>
                <option
                  value="<%=multiTime.getData("start_date")%>" <%=(trainDateSearch.equals(multiTime.getData("start_date"))) ? "selected" : ""%> >
                  <%=multiTime.getData("start_date") + " : " + multiTime.getData("start_time") + "-" + multiTime.getData("end_time")%>
                </option>
                <%
                    multiTime.next();
                  }
                %>
              </select>
            </td>
            <td align="left">&nbsp;&nbsp;<button type="button" class="btn btn-primary width100" swlang code="SW013170"
                                                 onClick="goSearchDate();">VIEW
            </button>&nbsp;
              <button type="button" class="btn btn-primary width100" swlang code="SW013176" onClick="genTrneeTime();">
                GENDATA
              </button>&nbsp;
            </td>
          </tr>
          <tr>
            <td class="blankspace" colspan="2"></td>
          </tr>
        </table>
        <table border="0" cellpadding="0" cellspacing="1" id="rsTable" name="rsTable" bgcolor="#333333"
               class="maxsize  tablewithborder" cols="8">
          <tr align="center">
            <td class="row3" width="14%"><a href="javascript:sortTable(0, rsTable);">
              <script language="JavaScript">swapLang('Date');</script>
            </a></td>
            <td class="row3" width="5%"><%=multi.getLabel("HTRAINEETIME", "STATUS")%>
            </td>
            <td class="row3" width="14%"><a
              href="javascript:sortTable(1, rsTable);"><%=multi.getLabel("HTRAINEETIME", "TRAINEEID")%>
            </a></td>
            <td class="row3" width="25%">
              <script language="JavaScript">swapLang('Name Surname');</script>
            </td>
            <td class="row3" width="10%"><%=multi.getLabel("HTRAINEETIME", "START_TIME")%>
            </td>
            <td class="row3" width="10%"><%=multi.getLabel("HTRAINEETIME", "END_TIME")%>
            </td>
            <td class="row3" width="10%"><%=multi.getLabel("HTRAINEETIME", "TIMEBREAK")%>
            </td>
            <td class="row3" width="10%"><%=multi.getLabel("HTRAINEETIME", "T_HOUR")%>
            </td>
            <td class="row3" width="8%"><%=multi.getLabel("HTRAINEETIME", "REMARK")%>
            </td>
          </tr>
          <%
            String isgen = chk.chkNullString(request.getParameter("__isgen"));
            if (isgen.equals("1")) {
              Simhtraining hraining = (Simhtraining) screen.getRecord("Htraining");
              hraining.genTraineeTime();
            }
            String fixDate = chk.chkNullString(request.getParameter("__fixDate"));
            multi.goFirst();
            for (int i = 1; !multi.eof(); i++) {
              multi.getTable().referLangOn();
              if (fixDate.equals("")) {
          %>
          <tr align="center">
            <td class="inframe">
              <div align="center"><%=multi.getData("TRAINDATE")%>
              </div>
            </td>
            <td class="inframe">
              <div align="center">
                <input name="__HTRAINEETIME$STATUS$<%=multi.getDataLabel("line_no")%>" type="hidden"
                       value="<%=multi.getDataLabel("STATUS")%>">
                <input name="chk$<%=multi.getDataLabel("line_no")%>"
                       type="checkbox" <%=(multi.getDataLabel("STATUS").equals("1"))?"checked":""%>
                       onclick="setChkBoxValue('<%=multi.getDataLabel("line_no")%>');"
                       value="<%=multi.getDataLabel("line_no")%>">
              </div>
            </td>
            <td class="inframe">
              <div align="center"><%=multi.getDataLabel("TRAINEEID")%>
              </div>
            </td>
            <td class="inframe">
              <div align="left">
                &nbsp;&nbsp;<%=multi.getDataLabel("V3MPREFIX", "TDESC") + multi.getDataLabel("V3MEMPLOYEE", "FNAME") + "  " + multi.getDataLabel("V3MEMPLOYEE", "LNAME")%>
              </div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$START_TIME$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='4' VALUE='<%=multi.getDataLabel("START_TIME")%>' onClick=""
                                         onChange="" onKeyPress="chkInteger();" onKeyUp="sysIsEdit();" dir=""
                                         onBlur="chkTimeOver(this,23,0);chkTwoTime(this,__HTRAINEETIME$END_TIME$<%=multi.getDataLabel("line_no")%>,1);calTwoTime_Break(this,__HTRAINEETIME$END_TIME$<%=multi.getDataLabel("line_no")%>,__HTRAINEETIME$T_HOUR$<%=multi.getDataLabel("line_no")%>,__HTRAINEETIME$TIMEBREAK$<%=multi.getDataLabel("line_no")%>);"
                                         onFocus="delDot(this);" class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$END_TIME$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='4' VALUE='<%=multi.getDataLabel("END_TIME")%>' onClick=""
                                         onChange="" onKeyPress="chkInteger();" onKeyUp="sysIsEdit();" dir=""
                                         onBlur="chkTimeOver(this,23,0);chkTwoTime(__HTRAINEETIME$START_TIME$<%=multi.getDataLabel("line_no")%>,this,2);calTwoTime_Break(__HTRAINEETIME$START_TIME$<%=multi.getDataLabel("line_no")%>,this,__HTRAINEETIME$T_HOUR$<%=multi.getDataLabel("line_no")%>,__HTRAINEETIME$TIMEBREAK$<%=multi.getDataLabel("line_no")%>);"
                                         onFocus="delDot(this);" class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$TIMEBREAK$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='4' VALUE='<%=multi.getDataLabel("TIMEBREAK")%>' onClick=""
                                         onChange="" readonly onKeyPress="chkInteger();" onKeyUp="sysIsEdit();" dir=""
                                         class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$T_HOUR$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='5' VALUE='<%=multi.getDataLabel("T_HOUR")%>' onClick=""
                                         onChange="" dir="" readonly class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><a
                href="javaScript:childMulti('<%=multi.getData("LINE_NO")%>','<%=multi.getData("TRAINEEID")%>','<%=multi.getData("TRAININGID")%>');"><img
                src="../IMAGES/BUTTON/MAIN/EDIT24.gif" border="0"></a></div>
            </td>
          </tr>
          <%
          } else {
            if (fixDate.equals(multi.getData("TRAINDATE"))) {
          %>
          <tr align="center">
            <td class="inframe">
              <div align="center"><%=multi.getData("TRAINDATE")%>
              </div>
            </td>
            <td class="inframe">
              <div align="center">
                <input name="__HTRAINEETIME$STATUS$<%=multi.getDataLabel("line_no")%>" type="hidden"
                       value="<%=multi.getDataLabel("STATUS")%>">
                <input name="chk$<%=multi.getDataLabel("line_no")%>"
                       type="checkbox" <%=(multi.getDataLabel("STATUS").equals("1"))?"checked":""%>
                       onclick="setChkBoxValue('<%=multi.getDataLabel("line_no")%>');"
                       value="<%=multi.getDataLabel("line_no")%>">
              </div>
            </td>
            <td class="inframe">
              <div align="center"><%=multi.getDataLabel("TRAINEEID")%>
              </div>
            </td>
            <td class="inframe">
              <div align="center">
                &nbsp;&nbsp;<%=multi.getDataLabel("V3MPREFIX", "TDESC") + multi.getDataLabel("V3MEMPLOYEE", "FNAME") + "  " + multi.getDataLabel("V3MEMPLOYEE", "LNAME")%>
              </div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$START_TIME$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='4' VALUE='<%=multi.getDataLabel("START_TIME")%>' onClick=""
                                         onChange="" onKeyPress="chkInteger();" onKeyUp="sysIsEdit();" dir=""
                                         onBlur="chkTimeOver(this,23,0);chkTwoTime(this,__HTRAINEETIME$END_TIME$<%=multi.getDataLabel("line_no")%>,1);calTwoTime_Break(this,__HTRAINEETIME$END_TIME$<%=multi.getDataLabel("line_no")%>,__HTRAINEETIME$T_HOUR$<%=multi.getDataLabel("line_no")%>,__HTRAINEETIME$TIMEBREAK$<%=multi.getDataLabel("line_no")%>);"
                                         onFocus="delDot(this);" class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$END_TIME$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='4' VALUE='<%=multi.getDataLabel("END_TIME")%>' onClick=""
                                         onChange="" onKeyPress="chkInteger();" onKeyUp="sysIsEdit();" dir=""
                                         onBlur="chkTimeOver(this,23,0);chkTwoTime(__HTRAINEETIME$START_TIME$<%=multi.getDataLabel("line_no")%>,this,2);calTwoTime_Break(__HTRAINEETIME$START_TIME$<%=multi.getDataLabel("line_no")%>,this,__HTRAINEETIME$T_HOUR$<%=multi.getDataLabel("line_no")%>,__HTRAINEETIME$TIMEBREAK$<%=multi.getDataLabel("line_no")%>);"
                                         onFocus="delDot(this);" class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$TIMEBREAK$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='4' VALUE='<%=multi.getDataLabel("TIMEBREAK")%>' onClick=""
                                         onChange="" readonly onKeyPress="chkInteger();" onKeyUp="sysIsEdit();" dir=""
                                         class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><INPUT TYPE='text' Name='__HTRAINEETIME$T_HOUR$<%=multi.getDataLabel("line_no")%>'
                                         SIZE='5' MAXLENGTH='5' VALUE='<%=multi.getDataLabel("T_HOUR")%>' onClick=""
                                         onChange="" dir="" readonly class="numeric"></div>
            </td>
            <td class="inframe">
              <div align="center"><a
                href="javaScript:childMulti('<%=multi.getData("LINE_NO")%>','<%=multi.getData("TRAINEEID")%>','<%=multi.getData("TRAININGID")%>');"><img
                src="../IMAGES/BUTTON/MAIN/EDIT24.gif" border="0"></a></div>
            </td>
          </tr>
          <%
                }
              }
              multi.next();
            }
          %>

        </table>
      </td>
    </tr>
    <tr>
      <td class="blankspace"></td>
    </tr>

    <tr>
      <td class="buttonline" colspan="7">
        <div align="center">
          <button type="button" class="btn btn-primary width100" swlang code="SW002185" onClick="checkAll();">SELECT
            ALL
          </button>&nbsp;
          <button type="button" class="btn btn-primary width100" swlang code="SW013164" onClick="decheckAll();">DESELECT
            ALL
          </button>
        </div>
      </td>
    </tr>
    <tr>
      <td class="blankspace"></td>
    </tr>
  </table>
</form>
<script language="javascript">window.parent.setTabPages();</script>
</body>
</html>