<%@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.*"  %>

<jsp:useBean id="WELEXPM007_CPN" class="com.csc.library.system.Task" scope="page"/>
<%
WELEXPM007_CPN.setChannel(request,response);
UIManager screen = (UIManager) WELEXPM007_CPN.process("SingleEntry","WELEXPM007_GPF");
screen.referLangOff();
CheckNull chk=new CheckNull();
CscCalendar cs=new CscCalendar();
String cmd=chk.chkNullString(request.getParameter("__cmd"));
String budyear=chk.chkNullString(request.getParameter("__budyear"),cs.getThaiYYYY());  
int years=Integer.parseInt(cs.getThaiYYYY());  

//if(screen.getRecord().getConfirmStatus()>0 && cmd.equals("save")){
//			response.sendRedirect("WELEXPM006_CPN.jsp");
//}

%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<script  language="JavaScript" src="../JS/SCREEN.js"></script>
<script type='text/javascript' src="../JS/ICONSMENU.js"></script>
<script language='javascript' src="../JS/HOTKEY.js"></script>
<script src="../JS/VIEWCALENDAR.js"></script>
<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
<SCRIPT TYPE='text/JavaScript' SRC='/hr/dwr/interface/SearchDWR.js'></SCRIPT>
<SCRIPT TYPE='text/JavaScript' SRC='/hr/dwr/engine.js'></SCRIPT>
<SCRIPT TYPE='text/JavaScript' SRC='/hr/dwr/util.js'></SCRIPT>
<SCRIPT TYPE='text/JavaScript' SRC="/hr/dwr/interface/SystemCode.js"></SCRIPT>
<SCRIPT TYPE='text/JavaScript' SRC="/hr/dwr/interface/CscCalendar.js"></SCRIPT>
<SCRIPT TYPE='text/javascript' SRC='/hr/dwr/interface/ExpenseGL.js'></SCRIPT>

<script language="javascript">
<!--
function opennew(page){
    window.open(page,"Help","height=400,width=600,resizable=yes,status=yes");
}

function GoSave() {
	checkValid();
}
function GoDelete(){ edelete(); }
function GoSearch(){ search(); }
function GoUpdate(){ 
}

 function goHelp(helpName,inputName){
	var helpReturn;
	var fixcon=document.cscform.__fixCon.value;
		 	if(inputName=="__employeeid" ){
		 		helpReturn="__employeeid:employeeid,__fullname:fullname,__branch_cost:memployee.branch,__branchdesc:mbranch.tdesc";
			}else if(inputName=="__costtype" ){
		 		helpReturn="__costtype:payment_code,__costtypedesc:mgl.description"; 	
			}else if(inputName=="__costcenter" ){
		 		helpReturn="__costcenter:accountid,__costcenterdesc:maccount_exp.tdesc"; 	
			}else if(inputName=="__branch_cost" ){
		 		helpReturn="__branch_cost:branchid,__branchdesc:tdesc"; 
			}else if(inputName=="__welid" ){
		 		helpReturn="__welid:welid,__weldesc:tdesc"; 		
				document.cscform.__fixCon.value="welgid='0004'";
			}else  if(inputName=="__branch_cost" ){
		 		helpReturn="__branch_cost:branchid"; 
			}else  if(inputName=="__acc_code" ){
		 		helpReturn="__acc_code:accountid,__accountdesc:tdesc"; 
			}else  if(inputName=="__tobranch" ){
		 		helpReturn="__tobranch:branchid,__tobranchdesc:tdesc"; 
			}
	     linkHelp_Return(helpName,helpReturn);
		 document.cscform.__fixCon.value=fixcon;
}


//-->
</script>
        <script type="text/javascript" src="../JS/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="../JS/jquery/js/jquery-ui.js"></script>
        <script type="text/javascript" src="../JS/jquery.blockUI.js"></script>
        <link href="../JS/jquery/css/redmond/jquery-ui-1.7.1.custom.css" rel="stylesheet" type="text/css">
		<script type="text/javascript">		
		ThaiCode[226]="ยอดที่เบิกได้=";
		EngCode[226]="Can request this value=";				
		ThaiCode[227]="กรุณากรอกครั้งที่";
		EngCode[227]="Invalid data in caseid";				
		
		     <%
					CscCalendar cs3=new CscCalendar();
					cs3.decDate(1000);
			%>
			var date30=new Date(<%=cs3.getYear()%>, <%=cs3.getMonth()%>, <%=cs3.getDate()%>);
			function showDate(mypicker){
				$(function() {
					$("#"+mypicker.id).datepicker({dateFormat: "dd-mm-yy",showAnim: "fadeIn",showOn: "focus",direction: 'up'});
				});
			}
			
			$(document).ready(function() {
					$("input[name='__complainid']").attr({readOnly:"true"});
			});
			
		function chkInputDate(obj) {
		var temp = obj.value;
		var tempdate = obj.value.split("-");
		var chk = true;
		//ตรวจสอบดูว่าพิมเป็นตัวอักษรหรือไม่
		if (!chkIntNotChar (temp)) {
			alert(MyAlert[30]); 
			obj.value = datePresent(); 
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ากรอกตัวเลขครบแปดหลักแล้วหรือไม่
		else if ((obj.value.length < 8) && (obj.value.length > 0)) { 
			alert(MyAlert[31]); 
			obj.value = datePresent();
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่าถ้ากรอกวันที่ครบแปดตัวเลขแล้ว กรอก วัน เดือน ปี ถูกต้องหรือไม่ ( โดยเรียก script checkTrueDay(str) )
		else if ( (tempdate[0].length == 2) && (tempdate[1].length == 2) && (tempdate[2].length == 4) && (temp.length > 0 ) && (!checkTrueDay(delWordDate(temp))) ) {
			alert(MyAlert[31]);
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ากรอก วันเป็นเลขสองหลัก เดือนเป็นเลขสองหลัก และปีเป็นเลขสี่หลักหรือป่าว
		else if ( (tempdate[0].length != 2 || tempdate[1].length != 2 || tempdate[2].length != 4) && temp.length > 0  ) {
			alert(MyAlert[31]);
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ากรอกวันเกินสิบตัวเลขหรือไม่ ( กรณีที่เกิดคือ copy คำมาแปะอาจเป็นภาษาไทย หรือ อักษร )
		else if ( (temp != delWordDate(obj.value)) && (temp.length > 10) ) {
			obj.value = datePresent(); 
			alert(MyAlert[31]); 
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ารูปแบบวันที่อยู่ในรูปของ ddmmyyyy หรือ dd-mm-yyyy แล้วหรือยัง
		else if ( tempdate.length != 3 ) 	{
			obj.value = datePresent();
			alert(MyAlert[31]); 
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่า วันที่กรอกเป็นเลขสองหลัก เดือนเป็นเลขสองหลัก และปีเป็นเลขสี่หลักหรือไม่
		else if (  (tempdate[0].length != 2) && (tempdate[1].length != 2) && (tempdate[2].length != 4)  )   {
			obj.value = datePresent();
			alert(MyAlert[31]); 
			obj.select();
			chk = false;
		}
		return chk; //ถ้ากรอกวันที่ถูกต้องตามเงื่อนไขแล้วจะ retrun เป็น true
	}			
	
			function checkNumFloatNotBlank(obj,limitstart,limitend) {
				with( document.cscform ){
					if(obj.value != "") {
						checkNumFloat(obj,limitstart,limitend)
					} else {
						obj.value = "1.00";	
					}
				}
			}		
			
			
		function checkValid(){
					with(document.cscform){
							var expbudget="{'employeeid':'"+__employeeid.value+"','glcode':'"+__welid.value+"','kms':'"+__distance.value.replace(/,/g,"")+"','amtreq':'"+__cost.value.replace(/,/g,"")+"'}";
							dwr.engine.beginBatch();
							 dwr.engine.setOrdered(true);
							ExpenseGL.checkBudget(expbudget,resultBudget);
							dwr.engine.endBatch();
					}
			}
			
	var resultBudget=function(data1){ 
		returnValue=eval("("+data1+")");	
		if(returnValue.flag==1){
			if((document.cscform.__cost.value.replace(/,/g,""))>(returnValue.result*1)){
					document.cscform.__cost.value=returnValue.result;
					insertComma(document.cscform.__cost);
					alert(MyCode[226]+" "+document.cscform.__cost.value);
			}else{
				if(document.cscform.__caseid.value==""){				
					alert(MyCode[227]);
					document.cscform.__caseid.focus();					
				}else{
					confirmSave();
				}
			}
		}else{
			//alert(MyCode[0]);
			confirmSave();
		}		
	};			
					
function backPage(){
		with(document.cscform){
					action="WELEXPM006_GPF.jsp";
					submit();
		}
}						
		</script>			

</head>
<body onLoad="MM_preloadImages('../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="__screen"  value="WELEXPM007_GPF"> 
  <input type="hidden" name="__help" value="">
  <input name="__fixCon" type="hidden" value="">
  <input type="hidden" name="__cmd"  value="">
  <input type="hidden" name="__calendar">
  <script language="javascript">getInputFormatDate();</script>
  <input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>">
  <input type="hidden" name="__user" value="<%=screen.getUProfile().getUserId()%>">
  <input name="__notNull" type="hidden" value="<%=screen.getRequire()%>,caseid">
  <input name="__companyid" type="hidden" value='<%=screen.getUProfile().get("companyid")%>'> 
   <input type="hidden" name="__referPage" value="">
   <input type="hidden" name="__budgetyear" value="">
	<input type="hidden" name="__emp_position" value="<%=screen.getDataLabel("emp_position")%>">
	<input type="hidden" name="__emp_group" value="<%=screen.getDataLabel("emp_group")%>">
	<input type="hidden" name="__bu1" value="<%=screen.getDataLabel("bu1")%>">
	<input type="hidden" name="__bu2" value="<%=screen.getDataLabel("bu2")%>">
	<input type="hidden" name="__bu3" value="<%=screen.getDataLabel("bu3")%>">
	<input type="hidden" name="__bu4" value="<%=screen.getDataLabel("bu4")%>">
	<input type="hidden" name="__bu5" value="<%=screen.getDataLabel("bu5")%>">
	<input type="hidden" name="__job" value="<%=screen.getDataLabel("job")%>">
	<input type="hidden" name="__branch" value="<%=screen.getDataLabel("branch")%>">
	<input type="hidden" name="__bossid" value="<%=screen.getDataLabel("bossid")%>">
  	<input type="hidden" name="__status" value="1">
	<input type="hidden" name="__welid" value="EXP000001">
 
        <script language="javascript">
	 var titlename=swap2String('History of vehicle expenses over time 21.00');
	 document.write(Icons("WELEXPM007_CPN,"+titlename));
	 </script>
   <br>
  <div align="center">
    <table cellpadding="0" cellspacing="0"  class="maxsize">
      <tr > 
        <td colspan="2" class="header" >WELEXPM007_GPF, 
          <script language="javascript">swapLang('History of vehicle expenses over time 21.00');</script>&nbsp;</td>
      </tr>
      <tr > 
        <td ><table  border="0" cellpadding="0" cellspacing="0" class="inframe" >
            <tr> 
              <td class="blankspace"> </td>
            </tr>
            <tr> 
              <td> <table border="0" cellspacing="0" cellpadding="0"  class="maxsize">
                  <tr> 
                    <td width="272" class="columnlabel"><span class="header"><%=screen.getLabel("complainid")%>&nbsp;</td>
                    <td width="1026"><input type="text" name="__complainid" value="<%=screen.getDataLabel("complainid")%>"></td>
                  </tr>
                  <tr> 
                    <td width="272" class="columnlabel"><span class="header"><%=screen.getLabel("caseid")%>&nbsp;</td>
                    <td width="1026"><input type="text" name="__caseid" value="<%=chk.chkNullString(screen.getDataLabel("caseid"),"1")%>" size="3" maxlength="2" onKeyPress="chkInteger();"></td>
                  </tr>
                  <tr> 
                    <td width="272" class="columnlabel"><span class="header"><%=screen.getLabel("EMPLOYEEID")%>&nbsp;</td>
                    <td width="1026"><%=screen.getInput("EMPLOYEEID")%> <a onMouseOver="MM_swapImage('__workarea_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)" onMouseOut="MM_swapImgRestore()" href="javascript:goHelp('MBRANCHHELP','__branch_cost');">
                    <input type="text" name="__fullname" value="<%=screen.getDataLabel("memployee","fullname")%>" size="50" readonly >
                    </a>
                    <div align="left"></div></td>
                  </tr>
                  <tr> 
                    <td class="columnlabel"><%=screen.getLabel("occurdate")%>&nbsp;</td>
                    <td><INPUT TYPE="text" NAME="__occurdate"  id="__occurdate" SIZE="10" VALUE="<%=screen.getDataLabel("occurdate")%>" onClick="showDate(this);" readonly onFocus="showDate(this);"  onMouseDown="showDate(this);" >
                    <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image121','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" alt="Calendar" name="Image121" width="20"  border="0" align="absmiddle" id="Image121" onClick="viewCal('__occurdate')"></a></td>
                  </tr>
                  <tr> 
                    <td class="columnlabel"><%=screen.getLabel("budyear")%>&nbsp;</td>
                    <td><select name="__budyear">
                      <%for(int i=(years-1);i<=years;i++){%>
                      <option value="<%=i%>"  <%if(budyear.equals(String.valueOf(i))){ out.println("selected");}%>><%=i%></option>
                      <%}%>
                    </select></td>
                  </tr>				  		  
                  <tr> 
                    <td class="columnlabel"><%=screen.getLabel("tobranch")%>&nbsp;</td>
                    <td><input name="__tobranch"  onmouseout="toolTip()" onKeyUp="sysIsEdit();" onKeyPress="chkSpecialStr(event);" onFocus="this.select();" onBlur="trimValue(this);" type="text" size="30" maxLength="30" value="<%=screen.getDataLabel("tobranch")%>" /><span style="display:none">
                      <input type="text" name="__tobranchdesc" value="<%//=screen.getDataLabel("v1mbranch","tdesc")%>" size="50" readonly ></span></td>
                  </tr>
			  <%
			  screen.setInputType("APPROVESTATUS","list");
			  %>				  
                  <tr> 
                    <td class="columnlabel"><%=screen.getLabel("distance")%>&nbsp;</td>
                    <td><%=screen.getInput("distance")%></td>
                  </tr>				  
                  <tr> 
                    <td class="columnlabel"><%=screen.getLabel("starttime")%>&nbsp;</td>
                    <td><%=screen.getInput("starttime")%>                    </td>
                  </tr>				  		  
                  <!--tr> 
                    <td class="columnlabel"><%=screen.getLabel("status")%>&nbsp;</td>
                    <td><%=screen.getInput("status")%>                    </td>
                  </tr-->				  
                  <tr> 
                    <td class="columnlabel"><%=screen.getLabel("approvestatus")%>&nbsp;</td>
                    <td><%=screen.getInput("approvestatus")%>                    </td>
                  </tr>				  
                  <tr> 
                    <td class="columnlabel"><%=screen.getLabel("reqcost")%>&nbsp;</td>
                    <td><%=screen.getInput("reqcost")%>                    </td>
                  </tr>
                  <tr style="display:none"> 
                    <td class="columnlabel"><%=screen.getLabel("cost")%>&nbsp;</td>
                    <td><%=screen.getInput("cost")%></td>
                  </tr>
                  <tr>
                    <td class="columnlabel"><span class="column-label">
                      <SCRIPT LANGUAGE="JavaScript">swapLang('Remark')</SCRIPT>
                    </span>&nbsp;</td>
                    <td><%=screen.getInput("remarknote")%> </td>
                  </tr>
              </table></td>
            </tr>
            <tr> 
              <td ><div align="right"><a href="JavaScript:backPage();"><img src="../IMAGES/BUTTON/BACK.gif" width="73" height="23"></a></div>&nbsp;&nbsp;</td>
            </tr>
          </table></td>
      </tr>
      <tr> 
        <td class="bottom" > </td>
      </tr>
    </table>
  </div>
<!----------BEGIN CSC ENDING ZONE ------------------------>

<%=screen.endJSP()%>

<!----------END CSC ENDING ZONE -------------------------->
</form>
</body>
</html>