<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*,com.csc.library.session.*,com.csc.library.components.*,com.csc.library.report.*,java.util.*,java.text.DecimalFormat;"%>
<jsp:useBean id="VACACCRUE001_PROCESS" scope="page" class="com.csc.library.system.Task" />
<jsp:useBean id="SAVEDATA" class="com.csc.library.databean.Vacaccrue_save" scope="page" />
<html ng-app="myHR">
<% 
	
   VACACCRUE001_PROCESS.setChannel(request ,response);
   HelpEntry screen = (HelpEntry) VACACCRUE001_PROCESS.process("HelpEntry", "VACACCRUE001_PROCESS");   
	
    //code java 
	
	CheckNull chk = new CheckNull();
	CscCalendar cs = new CscCalendar();
	
	int year = cs.getYear();
	String month = chk.chkNullString(request.getParameter("__Month"),"1");
	String std1 = chk.chkNullString(VACACCRUE001_PROCESS.getParameter("__startdate1"),"01-01-"+year);
	String std2 = chk.chkNullString(VACACCRUE001_PROCESS.getParameter("__startdate2"),"31-12-"+year);
	String cmd = chk.chkNullString(VACACCRUE001_PROCESS.getParameter("__cmd"),"");
	String emp1 = chk.chkNullString(VACACCRUE001_PROCESS.getParameter("__emp1"));
	String emp2 = chk.chkNullString(VACACCRUE001_PROCESS.getParameter("__emp2"));
	String leavetype = chk.chkNullString(request.getParameter("__leavetype"),"");
	
	if (cmd.equalsIgnoreCase("save")) {
            System.out.println("*********************** save condition ***********************");
			    SAVEDATA.setUProfile(screen.getUProfile());
				SAVEDATA.setMonth(month);
				if(emp2.equals("")){
					SAVEDATA.ProcessData(emp1,emp1,leavetype,std1,std2);
				}else if(emp1.equals("")){
					SAVEDATA.ProcessData(emp2,emp2,leavetype,std1,std2);
				}else if(!emp1.equals("")){
					SAVEDATA.ProcessData(emp1,emp2,leavetype,std1,std2);
				}else if(!emp2.equals("")){
					SAVEDATA.ProcessData(emp1,emp2,leavetype,std1,std2);
				}else if(emp1.equals("") && emp2.equals("")){
					SAVEDATA.ProcessData("1234isylzjko","1234isylzjko",leavetype,std1,std2);
				}
				cmd = "savecomplete";
    }
	
	
	
    

	ListBox listPeriodType = new ListBox();
	listPeriodType.setUProfile(screen.getUProfile()); 
	listPeriodType.setName("Period_option");
	listPeriodType.setValidCode("MONTHCODE_PROCESS");
	listPeriodType.setDisable("false");
	listPeriodType.setChecked(chk.chkNullString(VACACCRUE001_PROCESS.getParameter("Period_option"),"January"));

	ListBox listLeaveType = new ListBox();
	listLeaveType.setUProfile(screen.getUProfile()); 
	listLeaveType.setName("Leave_option");
	listLeaveType.setValidCode("LEAVE_TYPE");
	listLeaveType.setDisable("false");
	listLeaveType.setChecked(chk.chkNullString(VACACCRUE001_PROCESS.getParameter("Leave_option"),"Working day"));

	DbInquiry inq = new InitialInquiry(screen.getUProfile()).getDbInquiry("VACATION_PROFILE");
	inq.setColumn("VAC_CODE,VACID,TDESC,EDESC");
	inq.refresh();	
%>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<script src="../JS/jquery-1.7.2.js"></script>
<script src="../JS/SCREEN.js"></script>
<script src="../JS/angular-1.3.15/angular.js"></script>
<script type='text/JavaScript' SRC='../JS/ANGULAR/SWAPLANG.js'></script>
<script type="text/javascript" src="/hr/dwr/interface/CscCalendar.js"></script>
<script type='text/javascript' src='../JS/ICONSMENU.js'></script>
<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
<script src="../JS/VIEWCALENDAR.js"></script>
<script src='../JS/ICONSMENU.js'></script>
<script src='../JS/HOTKEY.js'></script>
<script src="../JS/DATEINPUT.js"></script>
<script src="../JS/CscBase.js"></script>
<script src="../JS/CscCalendar.js"></script>
<script>getTitleName();</script>
<script TYPE='text/JavaScript' SRC='../JS/CscCalendarV3.js'></script>
<script type="text/JavaScript">

//-->
function goHelp(helpName,inputName){
	var helpReturn;
	var fixcon;
	if(inputName.indexOf("__emp") > -1){
		helpReturn = inputName+":employeeid"
		fixcon = "employeeid";
	}
	fixcon="";
	linkHelp_Return(helpName,helpReturn,fixcon);
}

function GoSave(){
	with(document.cscform){		    	
		aCon=confirm(MyCode[1]);// จะบันทึกหรือไม่
		if (aCon==true)	{
			__cmd.value = 'save';
			
			submit();
			
		}
	}
}
$(document).ready(function(){

$('select[name=__Period_option]').on("change",function(){
 with(document.cscform){
  var setMonth = $('select[name=__Period_option]').find(":selected").val();
      
	  __Month.value = setMonth;
 		if(setMonth === '1'||setMonth === '3'||setMonth === '5'||setMonth === '7'||setMonth === '8'||setMonth === '10'||setMonth === '12')
			{
				 if (setMonth === '1')
				 {
					 __startdate1.value = '01-01-'+__year.value;
				     __startdate2.value = '31-01-'+__year.value;
				 }
				 else if (setMonth === '3')
				 {
					 __startdate1.value = '01-03-'+__year.value;
				     __startdate2.value = '31-03-'+__year.value;
				 }
				 else if (setMonth === '5')
				 {
					 __startdate1.value = '01-05-'+__year.value;
				     __startdate2.value = '31-05-'+__year.value;
				 }
				 else if (setMonth === '7')
				 {
					 __startdate1.value = '01-07-'+__year.value;
				     __startdate2.value = '31-07-'+__year.value;
				 }
				  else if (setMonth === '8')
				 {
					 __startdate1.value = '01-08-'+__year.value;
				     __startdate2.value = '31-08-'+__year.value;
				 }
				  else if (setMonth === '10')
				 {
					 __startdate1.value = '01-10-'+__year.value;
				     __startdate2.value = '31-10-'+__year.value;
				 }
				   else if (setMonth === '12')
				 {
					 __startdate1.value = '01-12-'+__year.value;
				     __startdate2.value = '31-12-'+__year.value;
				 }
			}
		else if (setMonth === '4'||setMonth === '6'||setMonth === '9'||setMonth === '11')
			{
				 if (setMonth === '4')
				 {
					 __startdate1.value = '01-04-'+__year.value;
				     __startdate2.value = '30-04-'+__year.value;
				 }
				 else if (setMonth === '6')
				 {
					 __startdate1.value = '01-06-'+__year.value;
				     __startdate2.value = '30-06-'+__year.value;
				 }
				  else if (setMonth === '9')
				 {
					 __startdate1.value = '01-09-'+__year.value;
				     __startdate2.value = '30-09-'+__year.value;
				 }
				  else if (setMonth === '11')
				 {
					 __startdate1.value = '01-11-'+__year.value;
				     __startdate2.value = '30-11-'+__year.value;
				 }
			}
		else if (setMonth === '2')
		{
			if((__year.value)%4 === 0){
				__startdate1.value = '01-02-'+__year.value;
				__startdate2.value = '29-02-'+__year.value;
			}else{
				__startdate1.value = '01-02-'+__year.value;
				__startdate2.value = '28-02-'+__year.value;
			}
		}
		else
		{
				__startdate1.value = '';
			    __startdate2.value = '';
		}
	}
 });
});

function setdefaultDate(){
	with(document.cscform){
		var onMonth = __Month.value;
		$('select[name=__Period_option]').val(onMonth);
		$('#name_month_as_of').text(onMonth);
		if(onMonth === '1'||onMonth === '3'||onMonth === '5'||onMonth === '7'||onMonth === '8'||onMonth === '10'||onMonth === '12'){
			if(onMonth === '10'||onMonth === '12'){
				__startdate1.value = '01-'+onMonth+'-'+__year.value;
				__startdate2.value = '31-'+onMonth+'-'+__year.value;
			}
			else{
				__startdate1.value = '01-0'+onMonth+'-'+__year.value;
				__startdate2.value = '31-0'+onMonth+'-'+__year.value;
			}
		}else if(onMonth === '4'||onMonth === '6'||onMonth === '9'||onMonth === '11'){
			if(onMonth === '11'){
				__startdate1.value = '01-'+onMonth+'-'+__year.value;
				__startdate2.value = '30-'+onMonth+'-'+__year.value;
			}else{
				__startdate1.value = '01-0'+onMonth+'-'+__year.value;
				__startdate2.value = '30-0'+onMonth+'-'+__year.value;
			}
		}
		else{
			if((__year.value)%4 === 0){
				__startdate1.value = '01-02-'+__year.value;
				__startdate2.value = '29-02-'+__year.value;
			}else{
				__startdate1.value = '01-02-'+__year.value;
				__startdate2.value = '28-02-'+__year.value;
			}
		}
	}
}
</script>

</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="setdefaultDate();">
<form name="cscform" method="post" action ="VACACCRUE001_PROCESS.jsp">
 

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

<%=screen.InitialVariable()%>
<input type="hidden" name="__cmd" value="<%=VACACCRUE001_PROCESS.getParameter("__cmd")%>"> 
<input type="hidden" name="__screen" value="VACACCRUE001_PROCESS"> 
<input type="hidden" name="__help" value=""> 
<input type="hidden" name="__calendar" value="">
<script language="javascript">getInputFormatDate();</script>
<input type="hidden" name="__companyid" value="<%=screen.getUProfile().get("companyid")%>"> 
<input type="hidden" name="__filterMemployee" value="companyid='<%=screen.getUProfile().get("companyid")%>'">
<input type="hidden" name="__referPage" value="">
<input type="hidden" name="__temp" value="">
<input type="hidden" name="__curDate" value="<%=new CscCalendar().getDate()%>">
<input type="hidden" name="__confirm" value="s">
<input type="hidden" name="__fixCon" value="">
<input type="hidden" name="__employeeid" value="<%=screen.getUProfile().get("employeeid")%>">
<input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>">
<input type="hidden" name="__Month" value="<%=month%>">
<input type="hidden" name="__date1" value="<%=std1%>">
<input type="hidden" name="__date2" value="<%=std2%>">
<input type="hidden" name="__year" value="<%=year%>">


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

<div align="center">

<table height="" align="center" cellpadding="0" cellspacing="0"  border="0" >
    <tr bgcolor="#3366CC">
		<td  height="20" class="header" colspan="4">VACACCRUE001_PROCESS,<script language="javascript">swapLang("PROCESS_DATA");</script>&nbsp;</td>
  		
			<table border="1" cellspacing="0" cellpadding="0" align="center">
				<tr> 
					<td class="blankspace" colspan="2"></td>
				</tr>
					<tr>
					<td align="center" colspan ="2"><H1>Process Data Vacation Accrual</H1></td>
					</tr>
					<tr><td align="right"><strong><swaplang code='SW000350'></swaplang>&nbsp;</strong></td>
						  <td><input type="text" name="__emp1" size="15" value="<%=emp1%>">
						  <a href="javascript:goHelp('MEMPLOYEEHELP','__emp1')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image2','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="Help" name="Image2"  border="0" align="absmiddle"></a> &nbsp;&nbsp;-&nbsp;&nbsp;
						  <input type="text" name="__emp2" size="15" value="<%=emp2%>">
						  <a href="javascript:goHelp('MEMPLOYEEHELP','__emp2')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="Help" name="Image3"  border="0" align="absmiddle"></a></span> </td>
					</tr>
				<tr>
			  <td align="right"><swaplang code='SW000277'></swaplang>&nbsp;</td>
			  <td ><span class="columnobject1"><%=listPeriodType.process()%>
					<input type="text" name="__startdate1" size="10" value="<%=std1%>" onBlur = "chkInputDate2(this,__startdate2)" onKeypress = "chkIntegerOfDate(this.value)" readonly> 
					<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1101','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onClick="viewCal('__startdate1')">
					<img src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" alt="Calendar" name="Image1101" width="20" height="20" border="0" align="absmiddle" id="Image1101"></a>
					&nbsp; - &nbsp;
					<input type="text" name="__startdate2" size="10" value="<%=std2%>"  onBlur = "chkInputDate2(__startdate1,this)" onKeypress = "chkIntegerOfDate(this.value)" readonly> <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1101','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onClick="viewCal('__startdate2')">
					<img src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" alt="Calendar" name="Image1101" width="20" height="20" border="0" align="absmiddle" id="Image1101">
					</td>
				</tr>
				<tr>
		<td><div align="right"><swaplang code='SW000300'></swaplang>&nbsp;</div></td>
		<td><select name="__leavetype"> 
				<%
				while(inq.next())
				{%>		
					  <option value="<%=inq.getString("VAC_CODE")%>"
					  <% if(leavetype.equals(inq.getString("VAC_CODE"))){%>selected<%}%>> <!-- ใช้สำหรับบ ดักเงื่อนไขการ select  -->
					  <%=inq.getString("TDESC")%></option>
				<%}%>
		</select></td>
		</td>
   	</tr>
				<tr>
					
					<td align="center" colspan ="2"><a href="javascript:GoSave();"><img src="../IMAGES/BUTTON/SUBMIT.gif" alt="Submit" border="0" align="absmiddle"></a></td>
				</tr>
				
			   <tr> 
					<td class="blankspace" colspan="2"></td>
				</tr>
				<tr>
				<!-- <td  class="columnlabel">&nbsp;</td>
                      <td width="488" align="right"><script language="javascript">printEditCheck('<%=screen.getDataLabel("edit_by")%>','<%=screen.getDataLabel("edit_date")%>','<%=screen.getDataLabel("edit_time")%>','<%=screen.getDataLabel("approve")%>');
						</script>&nbsp;
						</td> -->
            
				</tr>
				<tr> 
					<td class="blankspace" colspan="2"></td>
				</tr>
				<tr height="20">
					<td  class="bottom" colspan="2"></td>
				</tr>
          	</table> 
	</tr >

	</table>	
  </div>


</form>
</body>
</html>