Viewing file: function.php (53.12 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<?php
function tabChoose() {
?>
<script type="text/javascript">
<!--
// START tab script
// Adapted from "Javascript + CSS + DOM Magic" by Makiko Itoh
t
// define variables for "if n4 (Netscape 4), if IE (IE 4.x),
// and if n6 (if Netscape 6/W3C-DOM compliant)"
var n4, ie, n6;
// detect browser support for certain key objects/methods
// and assemble a custom document object
var doc,doc2,doc3,sty;
if (document.layers) {
doc = "document.";
doc2 = ".document.";
doc3 = "";
sty = "";
n4 = true;
} else if (document.all) {
doc = "document.all.";
doc2 = "";
doc3 = "";
sty = ".style";
ie = true;
} else if (document.getElementById) {
doc = "document.getElementById('";
doc2 ="')";
doc3 ="')";
sty = "').style";
n6 = true;
}
// display block or none DIV element
function blocknone(divname,tabidname,state,tabcolor,tabbg,cursortype) {
if (n4) {
divObj = eval (doc + divname);
tabObj = eval (doc + tabidname);
}
else {
divObj = eval (doc + divname + sty);
tabObj = eval (doc + tabidname + sty);
}
divObj.display = state;
tabObj.color = tabcolor;
tabObj.backgroundColor = tabbg;
tabObj.cursor = cursortype;
}
// variables that hold the value of the currently active (open) menu
var active_tabcontent = null;
var active_tab1 = null;
// function closes all active menus and turns back to 'off' state
function closeallmenus() {
if (active_tabcontent != null) {
blocknone(active_tabcontent,active_tab1,'none','#000000','#ABCDEF','pointer');
}
}
// function controls tab content visibility
function controlsubmenu(tabcontent,tabid) {
closeallmenus();
blocknone(tabcontent,tabid,'block','#000000','#ffc','text');
active_tabcontent = tabcontent;
active_tab1 = tabid
}
//END guide tab script
-->
</script>
<?php
}
function checkFormatLogin() {
?>
<script>
function checkFormatLogin() {
x = document.forms[0];
ele = new Array(x.length-1);
i=0;
while(i < x.length-1) {
ele[i] = x.elements[i];
i++;
}
i=0;
while(i < ele.length) {
if(ele[i].value == "")
{
alert("กรุณากรอก "+ele[i].name+" !");
ele[i].focus();
return false;
}
if(ele[i].value=="0" && ele[i].type!="hidden")
{
alert("กรุณากรอก "+ele[i].name+" !");
ele[i].focus();
return false;
}
i++;
}
}
</script>
<?php
}
function checkFormat() {
?>
<script>
<?php include_once "wordArr.php";?>
function checkFormat() {
x = document.forms[0];
ele = new Array(x.length-1);
i=0;
while(i < x.length-1) {
ele[i] = x.elements[i];
i++;
}
i=0;
while(i < ele.length) {
if(ele[i].name.indexOf("_Day_ID") == -1 && ele[i].name.indexOf("_Month") == -1 && ele[i].name.indexOf("_Year_ID") == -1){
if(ele[i].value == "")
{
alert("กรุณากรอก"+wordArr[ele[i].name]+" !");
ele[i].focus();
return false;
}
if(ele[i].value=="0" && ele[i].type!="hidden")
{
alert("กรุณากรอก"+wordArr[ele[i].name]+" !");
ele[i].focus();
return false;
}
if(ele[i].type=="radio" && ele[i].checked==false && ele[i+1].type=="radio" && ele[i+1].checked==false)
{
alert("กรุณาเลือก "+wordArr[ele[i].name]+" !");
ele[i].focus();
return false;
}
}
i++;
}
/* if(confirm("กรุณาตรวจสอบข้อมูลให้เรียบร้อยก่อนบันทึก !!"))
return true ;
else
return false ; */
}
</script>
<?php
}
function checkFormatMoney() {
?>
<script>
function checkFormat() {
x = document.forms[0];
ele = new Array(x.length-1);
i=0;
while(i < x.length-1) {
ele[i] = x.elements[i];
i++;
}
i=0;
while(i < ele.length) {
if(ele[i].value == "")
{
alert("กรุณากรอก "+ele[i].name+" !");
ele[i].focus();
return false;
}
i++;
}
if(confirm("คุณต้องการบันทึกข้อมูลแน่นอนใช่หรือไม่?"))
return true ;
else
return false ;
}
</script>
<?php
}
function confirmSubmit() {
?>
<script LANGUAGE="JavaScript">
<!--// Nannette Thacker http://www.shiningstar.net
function confirmSubmit(msg)
{
var agree=confirm(msg);
//var agree=confirm("คุณต้องการลบข้อมูลแน่นอนใช่หรือไม่?");
if (agree)
return true ;
else
return false ;
}
// -->
</script>
<?php
}
function getNowDate() {
$yy = date('Y');
$mm = date('m');
$dd = date('d');
return $yy.'-'.$mm.'-'.$dd;
}
function getNowDateFw() {
$yy = date('Y');
$mm = date('m');
$dd = date('d');
return $dd.'-'.$mm.'-'.$yy;
}
function getNowDateFw2() {
$yy = date('Y');
$mm = date('m');
$dd = date('d');
return $dd.'/'.$mm.'/'.$yy;
}
function getNowDateTh() {
$yy = date('Y')+543;
$mm = date('m');
$dd = date('d');
return $yy.'-'.$mm.'-'.$dd;
}
function getNowDateTh2() {
$yy = date('Y')+543;
$mm = date('m');
$dd = date('d');
return $yy;
}
function getNowDateFwTh() {
$yy = date('Y')+543;
$mm = date('m');
$dd = date('d');
return $dd.'-'.$mm.'-'.$yy;
}
function getDateFwEng($date,$sp="-") {
list($yy, $mm, $dd) = split("[$sp]", $date);
$yy = $yy-543;
return $yy.'-'.$mm.'-'.$dd;
}
function splitDateForm($date,$sp="-") {
list($dd, $mm, $yy) = split("[$sp]", $date);
$yy += 543;
return $yy.'-'.$mm.'-'.$dd;
}
function splitDateForm2($date) {
list($dd, $mm, $yy) = split('[-.-]', $date);
return $yy.'-'.$mm.'-'.$dd;
}
function splitDateForm3($date) {
list($dd, $mm, $yy) = split('[-]', $date);
return $yy.'-'.$mm.'-'.$dd;
}
function splitDateForm4($date) {
list($dd, $mm, $yy) = split('[/]', $date);
$yy += 543;
return $dd.'-'.$mm.'-'.$yy;
}
function splitDateForm5($date) {
list($dd, $mm, $yy) = split('[/]', $date);
return $dd.'-'.$mm.'-'.$yy;
}
function splitDateDb($date,$sp="-") {
list($yy, $mm, $dd) = split('[-]', $date);
$yy -= 543;
return $dd."$sp".$mm."$sp".$yy;
}
function splitDateDbSL($date,$sp="/") {
list($yy, $mm, $dd) = split('[-]', $date);
$yy -= 543;
return $dd."$sp".$mm."$sp".$yy;
}
function splitDateDbL($date,$sp="-") {
list($yy, $mm, $dd) = split('[-]', $date);
$yy -= 543;
return $yy."$sp".$mm."$sp".$dd;
}
function splitDateDbL2($date,$sp="-") {
list($yy, $mm, $dd) = split('[-]', $date);
return $yy."$sp".$mm."$sp".$dd;
}
function splitDateDb2($date) {
list($yy, $mm, $dd) = split('[-.-]', $date);
return $dd.'-'.$mm.'-'.$yy;
}
function splitDateDb2plusdd($date,$pd) {
list($yy, $mm, $dd) = split('[-.-]', $date);
return $dd+$pd.'-'.$mm.'-'.$yy;
}
function splitDateDb2plusdd2($date,$pd) {
list($yy, $mm, $dd) = split('[-.-]', $date);
return $yy.'-'.$mm.'-'.$dd+$pd;
}
function splitDateDb2minusdd2($date,$pd) {
list($yy, $mm, $dd) = split('[-.-]', $date);
return $yy.'-'.$mm.'-'.$dd-$pd;
}
function fullDate($date) {
list($dd, $mm, $yy) = split('[-.-]',$date);
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
if($mm=='01') { $mm='มกราคม'; }
else if($mm=='02') { $mm='กุมภาพันธ์'; }
else if($mm=='03') { $mm='มีนาคม'; }
else if($mm=='04') { $mm='เมษายน'; }
else if($mm=='05') { $mm='พฤษภาคม'; }
else if($mm=='06') { $mm='มิถุนายน'; }
else if($mm=='07') { $mm='กรกฎาคม'; }
else if($mm=='08') { $mm='สิงหาคม'; }
else if($mm=='09') { $mm='กันยายน'; }
else if($mm=='10') { $mm='ตุลาคม'; }
else if($mm=='11') { $mm='พฤศจิกายน'; }
else if($mm=='12') { $mm='ธันวาคม'; }
return "$dd $mm $yy";
}
function fullDateEng($date) {
list($dd, $mm, $yy) = split('[-.-]',$date);
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
if($mm=='01') { $mm='January'; }
else if($mm=='02') { $mm='February'; }
else if($mm=='03') { $mm='March'; }
else if($mm=='04') { $mm='April'; }
else if($mm=='05') { $mm='May'; }
else if($mm=='06') { $mm='June'; }
else if($mm=='07') { $mm='July'; }
else if($mm=='08') { $mm='August'; }
else if($mm=='09') { $mm='September'; }
else if($mm=='10') { $mm='October'; }
else if($mm=='11') { $mm='November'; }
else if($mm=='12') { $mm='December'; }
return "$mm $dd, $yy";
}
function abbreDate($date) {
list($dd, $mm, $yy) = split('[-.-]',$date);
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
if($mm=='01') { $mm='ม.ค.'; }
else if($mm=='02') { $mm='ก.พ.'; }
else if($mm=='03') { $mm='มี.ค.'; }
else if($mm=='04') { $mm='เม.ย.'; }
else if($mm=='05') { $mm='พ.ค.'; }
else if($mm=='06') { $mm='มิ.ย.'; }
else if($mm=='07') { $mm='ก.ค.'; }
else if($mm=='08') { $mm='ส.ค.'; }
else if($mm=='09') { $mm='ก.ย.'; }
else if($mm=='10') { $mm='ต.ค.'; }
else if($mm=='11') { $mm='พ.ย.'; }
else if($mm=='12') { $mm='ธ.ค.'; }
return "$dd $mm $yy";
}
function abbreDate2($date) {
list($yy, $mm, $dd) = split('[-.-]',$date);
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
if($mm=='01') { $mm='ม.ค.'; }
else if($mm=='02') { $mm='ก.พ.'; }
else if($mm=='03') { $mm='มี.ค.'; }
else if($mm=='04') { $mm='เม.ย.'; }
else if($mm=='05') { $mm='พ.ค.'; }
else if($mm=='06') { $mm='มิ.ย.'; }
else if($mm=='07') { $mm='ก.ค.'; }
else if($mm=='08') { $mm='ส.ค.'; }
else if($mm=='09') { $mm='ก.ย.'; }
else if($mm=='10') { $mm='ต.ค.'; }
else if($mm=='11') { $mm='พ.ย.'; }
else if($mm=='12') { $mm='ธ.ค.'; }
return "$dd $mm $yy";
}
function abbreDate2Y($date) {
list($yy, $mm, $dd) = split('[-.-]',$date);
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
if($mm=='01') { $mm='ม.ค.'; }
else if($mm=='02') { $mm='ก.พ.'; }
else if($mm=='03') { $mm='มี.ค.'; }
else if($mm=='04') { $mm='เม.ย.'; }
else if($mm=='05') { $mm='พ.ค.'; }
else if($mm=='06') { $mm='มิ.ย.'; }
else if($mm=='07') { $mm='ก.ค.'; }
else if($mm=='08') { $mm='ส.ค.'; }
else if($mm=='09') { $mm='ก.ย.'; }
else if($mm=='10') { $mm='ต.ค.'; }
else if($mm=='11') { $mm='พ.ย.'; }
else if($mm=='12') { $mm='ธ.ค.'; }
return "$yy";
}
function abbreDate2YTh($yy) {
$yyth = $yy + 543;
return "$yyth";
}
function calTax($amount, $netAmount, $taxRate) {
if($amount > $netAmount)
return round(($amount*$taxRate) / 100, 2);
else
return 0;
}
function calTaxOnClick() {
?>
<script>
function calTaxOnClick(f) {
f.amount.value = f.baht.value,'.',f.satang.value;
if(eval(f.amount.value)>eval(f.netAmt.value) && f.taxAndCheckFlag.value==1)
f.tax.value = (f.amount.value * f.taxRate.value) / 100;
else
f.tax.value = 0;
f.netAmount.value = f.amount.value - f.tax.value;
}
</script>
<?php
}
function openWindow() {
?>
<script language = "JavaScript">
function OpenWindow(FileName,nWidth,nHeight)
{
strOption = "scrollbars=yes,left=0,top=0,width=" + nWidth + ",height=" + nHeight;
SubWin = window.open(FileName,"",strOption);
}
function OpenWindowcenter(FileName,nWidth,nHeight)
{
strOption = "scrollbars=yes,left=200,top=50,width=" + nWidth + ",height=" + nHeight;
SubWin = window.open(FileName,"",strOption);
}
function OpenWindow2(FileName,nWidth,nHeight)
{
strOption = "scrollbars=yes,left=30,top=50,width=" + nWidth + ",height=" + nHeight;
SubWin = window.open(FileName,"",strOption);
}
</script>
<?php
}
function getNowDay() {
$dd = date('d');
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
return $dd;
}
function convertDayNumberToString($dd) {
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
return $dd;
}
function getNowMonth() {
return date('m');
}
function getNowMonthTh($mm) {
//$mm = date('m');
if($mm=='01') { $mm='มกราคม'; }
else if($mm=='02') { $mm='กุมภาพันธ์'; }
else if($mm=='03') { $mm='มีนาคม'; }
else if($mm=='04') { $mm='เมษายน'; }
else if($mm=='05') { $mm='พฤษภาคม'; }
else if($mm=='06') { $mm='มิถุนายน'; }
else if($mm=='07') { $mm='กรกฎาคม'; }
else if($mm=='08') { $mm='สิงหาคม'; }
else if($mm=='09') { $mm='กันยายน'; }
else if($mm=='10') { $mm='ตุลาคม'; }
else if($mm=='11') { $mm='พฤศจิกายน'; }
else if($mm=='12') { $mm='ธันวาคม'; }
return $mm;
}
function convertMonthNumberToString($mm) {
if($mm=='01') { $mm='มกราคม'; }
else if($mm=='02') { $mm='กุมภาพันธ์'; }
else if($mm=='03') { $mm='มีนาคม'; }
else if($mm=='04') { $mm='เมษายน'; }
else if($mm=='05') { $mm='พฤษภาคม'; }
else if($mm=='06') { $mm='มิถุนายน'; }
else if($mm=='07') { $mm='กรกฎาคม'; }
else if($mm=='08') { $mm='สิงหาคม'; }
else if($mm=='09') { $mm='กันยายน'; }
else if($mm=='10') { $mm='ตุลาคม'; }
else if($mm=='11') { $mm='พฤศจิกายน'; }
else if($mm=='12') { $mm='ธันวาคม'; }
return $mm;
}
function getNowYearTh() {
return date('Y')+543;
}
function confirmSubmitInsert() {
?>
<script LANGUAGE="JavaScript">
<!--// Nannette Thacker http://www.shiningstar.net
function confirmSubmitInsert()
{
var agree=confirm("คุณต้องการบันทึกข้อมูลแน่นอนใช่หรือไม่?");
if (agree)
return true ;
else
return false ;
}
// -->
</script>
<?php
}
function ver() {
?>
<script>
function ver(form, msg)
{
var c = 0;
for (var i=0; i<form.length; i++)
{
if(form.elements[i].type == 'checkbox' && form.elements[i].name !='chkAll')
{
if(form.elements[i].checked)
c = c+1;
}
}
if(c==0)
{
//alert('เลือกอย่างน้อยหนึ่งรายการเพื่อการออกงบหน้าใบสำคัญเบิกเงินต่อ');
alert(msg);
return false;
}
}
</script>
<?php
}
function ver2() {
?>
<script>
function ver2(form, msg)
{
var c = 0;
for (var i=0; i<form.length; i++)
{
if(form.elements[i].type == 'checkbox' && form.elements[i].name !='chkAll')
{
if(form.elements[i].checked)
c = c+1;
}
}
if(c != 1)
{
alert(msg);
return false;
}
}
</script>
<?php
}
function CA() {
?>
<script>
function CA(form)
{
for (var i=0; i<form.length; i++)
{
if(form.elements[i].type == 'checkbox')
form.elements[i].checked = form.chkAll.checked;
}
}
</script>
<?php
}
function readNumber($number, $len) {
if($number=='0') { $number = ""; }
else if($number=='1') {
if($len==2) { $number = ""; }
else { $number = "หนึ่ง"; }
}
else if($number=='2') {
if($len==2) { $number = "ยี่"; }
else { $number = "สอง"; }
}
else if($number=='3') { $number = "สาม"; }
else if($number=='4') { $number = "สี่"; }
else if($number=='5') { $number = "ห้า"; }
else if($number=='6') { $number = "หก"; }
else if($number=='7') { $number = "เจ็ด"; }
else if($number=='8') { $number = "แปด"; }
else if($number=='9') { $number = "เก้า"; }
return $number;
}
function readUnit($len) {
if($len=='1') { $len = ""; }
else if($len=='2') { $len = "สิบ"; }
else if($len=='3') { $len = "ร้อย"; }
else if($len=='4') { $len = "พัน"; }
else if($len=='5') { $len = "หมื่น"; }
else if($len=='6') { $len = "แสน"; }
else if($len=='7') { $len = "ล้าน"; }
return $len;
}
function convertNumberToString($amount) {
list($baht, $satang) = split('[.]', $amount);
while(strlen($satang) < 2)
$satang .= '0';
$str = "";
$len = strlen($baht);
$i = 0;
while($i <= strlen($baht)) {
if($len==1 && $baht[$i-1]!=0 && $baht[$i]==1)
$str .= "เอ็ด";
else
$str .= readNumber($baht[$i], $len);
if($baht[$i] != 0)
$str .= readUnit($len);
$len--;
$i++;
}
if($str != "")
$str .= "บาท";
$len = strlen($satang);
$i = 0;
while($i <= strlen($satang)) {
if($len==1 && $satang[$i-1]!=0 && $satang[$i]==1)
$str .= "เอ็ด";
else
$str .= readNumber($satang[$i], $len);
if($satang[$i] != 0)
$str .= readUnit($len);
$len--;
$i++;
}
if($satang != '00')
$str .= "สตางค์";
return $str;
}
//function changeHTML() {
?>
<!--<script language = "JavaScript">
function changeHTML()
{
var oselect = document.getElementById('docType');
var cselectVal = oselect.options[oselect.selectedIndex].value;
var receipts = document.getElementById('receipts');
var education = document.getElementById('education');
if(cselectVal=='0') {
receipts.style.display = 'none';
education.style.display = 'none';
}
else if(cselectVal=='1') {
receipts.style.display = '';
document.insert.receiptsBookNo.value = '';
document.insert.receiptsNo.value = '';
education.style.display = 'none';
document.insert.stNo.value = '-';
}
else if(cselectVal=='2') {
receipts.style.display = 'none';
document.insert.receiptsBookNo.value = '-';
document.insert.receiptsNo.value = '-';
education.style.display = '';
document.insert.stNo.value = '';
}
}
</script>-->
<?php
//}
function changeHTMLInInsertReceiptsList_Paper() {
?>
<script language = "JavaScript">
function changeHTML()
{
var oselect = document.getElementById('tmpReceiptsListId');
var cselectVal = oselect.options[oselect.selectedIndex].value;
var other = document.getElementById('tmpReceiptsListIdOther');
if(cselectVal=='-1') {
other.style.display = '';
document.insert.receiptsList.value = '';
}
else {
other.style.display = 'none';
document.insert.receiptsList.value = '-';
}
}
</script>
<?php
}
function changeHTMLInSubjectServedProject() {
?>
<script language = "JavaScript">
function changeHTML()
{
var oselect = document.getElementById('cashOrCheckCode');
var oselectVal = oselect.options[oselect.selectedIndex].value;
var check = document.getElementById('check');
var bank = document.getElementById('bank');
if(oselectVal == '2') {
check.style.display = '';
bank.style.display = '';
document.insert.checkNo.value = '';
document.insert.bank.value = '';
}
else {
check.style.display = 'none';
bank.style.display = 'none';
document.insert.checkNo.value = '-';
document.insert.bank.value = '-';
}
}
</script>
<?php
}
function changeHTMLInFindPaper() {
?>
<script language = "JavaScript">
function changeHTMLInFindPaper()
{
var oselect = document.getElementById('workType');
var cselectVal = oselect.options[oselect.selectedIndex].value;
var pay = document.getElementById('selectReportPay');
var receipts = document.getElementById('selectReportReceipts');
var dependOnWorkType1 = document.getElementById('dependOnWorkType1');
var dependOnWorkType2 = document.getElementById('dependOnWorkType2');
var yy = document.getElementById('yy');
var mm = document.getElementById('mm');
var dd1 = document.getElementById('dd1');
var dd2 = document.getElementById('dd2');
if(cselectVal=='0') {
pay.style.display = 'none';
receipts.style.display = 'none';
dependOnWorkType1.style.display = 'none';
dependOnWorkType2.style.display = 'none';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='1') {
pay.style.display = '';
document.findPaper.payDocType.selectedIndex = '0';
document.findPaper.payDocType.options[document.findPaper.payDocType.selectedIndex].value = '';
receipts.style.display = 'none';
document.findPaper.receiptsDocType.options[document.findPaper.receiptsDocType.selectedIndex].value = '-';
dependOnWorkType1.style.display = 'none';
dependOnWorkType2.style.display = 'none';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='2') {
pay.style.display = 'none';
document.findPaper.payDocType.options[document.findPaper.payDocType.selectedIndex].value = '-';
receipts.style.display = '';
document.findPaper.receiptsDocType.selectedIndex = '0';
document.findPaper.receiptsDocType.options[document.findPaper.receiptsDocType.selectedIndex].value = '';
dependOnWorkType1.style.display = 'none';
dependOnWorkType2.style.display = 'none';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
}
function changeHTMLInPayDocType()
{
var oselect = document.getElementById('payDocType');
var cselectVal = oselect.options[oselect.selectedIndex].value;
var dependOnWorkType1 = document.getElementById('dependOnWorkType1');
var dependOnWorkType2 = document.getElementById('dependOnWorkType2');
var yy = document.getElementById('yy');
var mm = document.getElementById('mm');
var dd1 = document.getElementById('dd1');
var dd2 = document.getElementById('dd2');
if(cselectVal=='0') {
dependOnWorkType1.style.display = 'none';
dependOnWorkType2.style.display = 'none';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='8') {
dependOnWorkType1.style.display = 'none';
document.findPaper.category1.options[document.findPaper.category1.selectedIndex].value = '-';
dependOnWorkType2.style.display = '';
document.findPaper.category2.selectedIndex = '0';
document.findPaper.category2.options[document.findPaper.category2.selectedIndex].value = '';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else {
dependOnWorkType1.style.display = '';
document.findPaper.category1.selectedIndex = '0';
document.findPaper.category1.options[document.findPaper.category1.selectedIndex].value = '';
dependOnWorkType2.style.display = 'none';
document.findPaper.category2.options[document.findPaper.category2.selectedIndex].value = '-';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
}
function changeHTMLInReceiptsDocType()
{
var oselect = document.getElementById('receiptsDocType');
var cselectVal = oselect.options[oselect.selectedIndex].value;
var dependOnWorkType1 = document.getElementById('dependOnWorkType1');
var dependOnWorkType2 = document.getElementById('dependOnWorkType2');
var yy = document.getElementById('yy');
var mm = document.getElementById('mm');
var dd1 = document.getElementById('dd1');
var dd2 = document.getElementById('dd2');
if(cselectVal=='0') {
dependOnWorkType1.style.display = 'none';
dependOnWorkType2.style.display = 'none';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='1') {
dependOnWorkType1.style.display = 'none';
document.findPaper.category1.options[document.findPaper.category1.selectedIndex].value = '2';
dependOnWorkType2.style.display = 'none';
document.findPaper.category2.options[document.findPaper.category2.selectedIndex].value = '-';
yy.style.display = '';
mm.style.display = '';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else {
dependOnWorkType1.style.display = '';
document.findPaper.category1.selectedIndex = '0';
document.findPaper.category1.options[document.findPaper.category1.selectedIndex].value = '';
dependOnWorkType2.style.display = 'none';
document.findPaper.category2.options[document.findPaper.category2.selectedIndex].value = '-';
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
}
function changeHTML1()
{
var oselect = document.getElementById('category1');
var cselectVal = oselect.options[oselect.selectedIndex].value;
var yy = document.getElementById('yy');
var mm = document.getElementById('mm');
var dd1 = document.getElementById('dd1');
var dd2 = document.getElementById('dd2');
if(cselectVal=='0') {
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='1') {
yy.style.display = '';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='2') {
yy.style.display = '';
mm.style.display = '';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='3') {
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = '';
dd2.style.display = '';
}
}
function changeHTML2()
{
var oselect = document.getElementById('category2');
var cselectVal = oselect.options[oselect.selectedIndex].value;
var yy = document.getElementById('yy');
var mm = document.getElementById('mm');
var dd1 = document.getElementById('dd1');
var dd2 = document.getElementById('dd2');
if(cselectVal=='0') {
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='1') {
yy.style.display = '';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='2') {
yy.style.display = '';
mm.style.display = '';
dd1.style.display = 'none';
dd2.style.display = 'none';
}
else if(cselectVal=='3') {
yy.style.display = 'none';
mm.style.display = 'none';
dd1.style.display = 'none';
dd2.style.display = '';
}
}
</script>
<?php
}
function diff2Dates() {
?>
<script>
function diff2Dates(f)
{
var date1 = f.startDate.value.split("-");
var date2 = f.endDate.value.split("-");
//Set the two dates
date1 = new Date(eval(date1[2]), eval(date1[1]-1), eval(date1[0]));
date2 = new Date(eval(date2[2]), eval(date2[1]-1), eval(date2[0])); //Month is 0-11 in JavaScript
//Set 1 day in milliseconds
var one_day = 1000*60*60*24;
//Calculate difference btw the two dates, and convert to days
var diff = Math.ceil((date2.getTime()-date1.getTime())/(one_day));
if(diff < 0)
{
alert("วันที่ไม่สัมพันธ์กัน");
return false;
}
f.dayAmount.value = diff+1;
}
</script>
<?php
}
function calCoupon() {
?>
<script>
function calCoupon(f)
{
var cnt = f.loop.value;
var x = f;
var baht = f.baht.value;
var satang = f.satang.value;
var amount = parseFloat(baht+"."+satang);
var ele = new Array(cnt-1);
var i = parseInt(cnt) + 14;
var j = 0;
while(i >= 15)
{
ele[j] = x.elements[i];
i--;
j++;
}
if(f.elements[6].checked == true)
f.quantity.value = parseInt(amount / f.inPrice.value);
else if(f.elements[7].checked == true)
f.quantity.value = parseInt(amount / f.outPrice.value);
i = 5;
while(i < ele.length)
{
/*if(parseInt(amount / ele[i].value) > parseInt(ele[i-2].value - ele[i-4].value + 1))
{
alert('ควรทำการเบิกคูปองเล่มใหม่');
return false;
}*/
if(parseInt(amount / ele[i].value) == 0)
ele[i-5].value = '-';
else
ele[i-5].value = parseInt(amount / ele[i].value);
amount = amount % ele[i].value;
i = i + 6;
}
if(amount != 0)
{
i = 0;
while(i < ele.length)
{
ele[i].value = '';
i += 6;
}
}
}
</script>
<?php
}
// returns <0, 0, >0 if date a< date b,date a== date b,date a > date b respectively.
function compareDate($i_sFirstDate, $i_sSecondDate)
{
//Break the Date strings into seperate components
$arrFirstDate = explode ("-", $i_sFirstDate);
$arrSecondDate = explode ("-", $i_sSecondDate);
$intFirstDay = $arrFirstDate[0];
$intFirstMonth = $arrFirstDate[1];
$intFirstYear = $arrFirstDate[2];
$intSecondDay = $arrSecondDate[0];
$intSecondMonth = $arrSecondDate[1];
$intSecondYear = $arrSecondDate[2];
// Calculate the diference of the two dates and return the number of days.
$intDate1Jul = gregoriantojd($intFirstMonth, $intFirstDay, $intFirstYear);
$intDate2Jul = gregoriantojd($intSecondMonth, $intSecondDay, $intSecondYear);
return $intDate1Jul - $intDate2Jul;
}//end Compare Date
function calBankNoteAndCoin() {
?>
<script>
function calBankNoteAndCoin(f)
{
var amount = f.sendToCashAmt.value;
if((amount - (amount % 1000)) != 0)
f.bankNote1.value = amount - (amount % 1000);
else
f.bankNote1.value = '-';
amount %= 1000;
if((amount - (amount % 500)) != 0)
f.bankNote2.value = amount - (amount % 500);
else
f.bankNote2.value = '-';
amount %= 500;
if((amount - (amount % 100)) != 0)
f.bankNote3.value = amount - (amount % 100);
else
f.bankNote3.value = '-';
amount %= 100;
if((amount - (amount % 50)) != 0)
f.bankNote4.value = amount - (amount % 50);
else
f.bankNote4.value = '-';
amount %= 50;
if((amount - (amount % 20)) != 0)
f.bankNote5.value = amount - (amount % 20);
else
f.bankNote5.value = '-';
amount %= 20;
if((amount - (amount % 10)) != 0)
f.coin1.value = amount - (amount % 10);
else
f.coin1.value = '-';
amount %= 10;
if((amount - (amount % 5)) != 0)
f.coin2.value = amount - (amount % 5);
else
f.coin2.value = '-';
amount %= 5;
if((amount - (amount % 1)) != 0)
f.coin3.value = amount - (amount % 1);
else
f.coin3.value = '-';
amount %= 1;
if((amount - (amount % 0.50)) != 0)
f.coin4.value = (amount - (amount % 0.50)) * 100;
else
f.coin4.value = '-';
amount %= 0.50;
if((amount - (amount % 0.25)) != 0)
f.coin5.value = (amount - (amount % 0.25)) * 100;
else
f.coin5.value = '-';
amount %= 0.25;
}
</script>
<?php
}
function calSendToCashAmt() {
?>
<script>
function calSendToCashAmt()
{
var sendToCashAmt = 0;
x = document.forms[0];
ele = new Array(x.length-1);
i=0;
while(i < x.length-1) {
ele[i] = x.elements[i];
i++;
}
i = 8;
while(i < 18)
{
if(ele[i].value != '-')
{
if(i==15 || i==17)
sendToCashAmt = sendToCashAmt + (parseInt(ele[i].value) / 100);
else
sendToCashAmt = sendToCashAmt + parseInt(ele[i].value);
}
i++;
}
if(ele[8].value!='-' && (parseInt(ele[8].value) % 1000) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[8].focus();
return false;
}
if(ele[9].value!='-' && (parseInt(ele[9].value) % 10) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[9].focus();
return false;
}
if(ele[10].value!='-' && (parseInt(ele[10].value) % 500) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[10].focus();
return false;
}
if(ele[11].value!='-' && (parseInt(ele[11].value) % 5) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[11].focus();
return false;
}
if(ele[12].value!='-' && (parseInt(ele[12].value) % 100) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[12].focus();
return false;
}
if(ele[13].value!='-' && (parseInt(ele[13].value) % 1) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[13].focus();
return false;
}
if(ele[14].value!='-' && (parseInt(ele[14].value) % 50) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[14].focus();
return false;
}
if(ele[15].value!='-' && (parseInt(ele[15].value) % 0.50) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[15].focus();
return false;
}
if(ele[16].value!='-' && (parseInt(ele[16].value) % 20) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[16].focus();
return false;
}
if(ele[17].value!='-' && (parseInt(ele[17].value) % 0.25) != 0)
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[17].focus();
return false;
}
if(sendToCashAmt != parseFloat(ele[3].value))
{
alert('จำนวนเงินสดไม่ถูกต้อง');
ele[8].focus();
return false;
}
if(confirm("คุณต้องการบันทึกข้อมูลแน่นอนใช่หรือไม่?"))
return true ;
else
return false ;
}
</script>
<?php
}
function openNewWindow(){
?>
<script LANGUAGE="JavaScript">
function openNewWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
</script>
<?php
}
function autotab() {
?>
<script>
function autotab(original, destination){
if (original.getAttribute && original.value.length==original.getAttribute("maxlength")) destination.focus();
}
</script>
<?php
}
function doCheckAll(){
?>
<script language="javascript">
function doCheckAll(form,do_check){
for (var i=0; i<form.length; i++)
{
if(form.elements[i].type == 'checkbox')
form.elements[i].checked = do_check;
}
}
</script>
<?php
}
function time_diff($from, $to) {
//echo "F".$from."T".$to."<br>";
list($byear,$bmonth,$bday) = explode("-",$from);
list($tyear,$tmonth,$tday) = explode("-",$to);
//echo ">>".$byear.">>".$bmonth.">>".$bday;
//echo "++".$tyear."++".$tmonth."++".$tday;
if($byear<1970){
$mYear_adjust = 1970-$byear;
$byear = 1970;
}else{
$mYear_adjust=0;
}
$a_year = $tyear - $byear;
//echo ">>".$mYear_adjust.">>".$a_year;
$a_month = $tmonth - $bmonth;
$a_month -= ($bday>$tday)?1:0;
//echo ">>".$bday>$tday;
$byear_new = $tyear;
$bmonth_new = $tmonth;
$bmonth_new -= ($bday>$tday)?1:0;
//echo ">>".$mYear_adjust.">>".$a_year;
if($a_month < 0){
$a_month += 12;
$a_year--;
}
if($tday >= $bday){
$a_day = $tday - $bday;
}else{
$tmp_timestamp = mktime(0,0,0,$bmonth_new,1,$byear_new);
$a_day = (date("t",$tmp_timestamp) - $bday)+ $tday;
}
$a_year += $mYear_adjust;
//echo ">>".$mYear_adjust.">>".$a_year;
//echo ">>".$a_year.">>".$a_month.">>".$a_day;
return "$a_year ,$a_month ,$a_day";
}
function time_diff2($from,$to){
$arr = explode("-",$to);
$to = date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2]+1, $arr[0]));
list($byear,$bmonth,$bday) = explode("-",$from);
list($tyear,$tmonth,$tday) = explode("-",$to);
if($byear<1970){
$mYear_adjust = 1970-$byear;
$byear = 1970;
}else{
$mYear_adjust=0;
}
$a_year = $tyear - $byear;
$a_month = $tmonth - $bmonth;
$a_month -= ($bday>$tday)?1:0;
$byear_new = $tyear;
$bmonth_new = $tmonth;
$bmonth_new -= ($bday>$tday)?1:0;
if($a_month < 0){
$a_month += 12;
$a_year--;
}
if($tday >= $bday){
$a_day = $tday - $bday;
}else{
$tmp_timestamp = mktime(0,0,0,$bmonth_new,1,$byear_new);
$a_day = (date("t",$tmp_timestamp) - $bday)+ $tday;
}
$a_year += $mYear_adjust;
//echo "$a_year years,$a_month months,$a_day days";
return "$a_year years,$a_month months,$a_day days";
}
function time_diff3($from,$to){
$arr = explode("-",$to);
$to = date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2]+1, $arr[0]));
list($byear,$bmonth,$bday) = explode("-",$from);
list($tyear,$tmonth,$tday) = explode("-",$to);
if($byear<1970){
$mYear_adjust = 1970-$byear;
$byear = 1970;
}else{
$mYear_adjust=0;
}
$a_year = $tyear - $byear;
$a_month = $tmonth - $bmonth;
$a_month -= ($bday>$tday)?1:0;
$byear_new = $tyear;
$bmonth_new = $tmonth;
$bmonth_new -= ($bday>$tday)?1:0;
if($a_month < 0){
$a_month += 12;
$a_year--;
}
if($tday >= $bday){
$a_day = $tday - $bday;
}else{
$tmp_timestamp = mktime(0,0,0,$bmonth_new,1,$byear_new);
$a_day = (date("t",$tmp_timestamp) - $bday)+ $tday;
}
$a_year += $mYear_adjust;
//echo "$a_year years,$a_month months,$a_day days";
return "$a_year,$a_month,$a_day";
}
function calNumDate($x,$y){
list($year1, $month1, $day1) = split('[,]', $x);
list($year2, $month2, $day2) = split('[,]', $y);
$dayT = $day1+$day2;
$dayTX = ($dayT)%(30);
$monthT = floor(($dayT)/(30));
$monthT = $monthT+$month1+$month2;
$monthTX = ($monthT)%(12);
$yearTX = floor(($monthT)/(12));
$yearT = $yearTX + $year1 + $year2;
return "$yearT,$monthTX,$dayTX";
}
function GetbudYear($xdate){
list($xyear,$xmonth,$xday) = explode("-",$xdate);
if(($xmonth == "10") ||($xmonth == "11")||($xmonth == "12") ){
$xyear=$xyear+543+1;
}else{
$xyear=$xyear+543;
}
return "$xyear";
}
function GetbudYearTh($xdate){
list($xyear,$xmonth,$xday) = explode("-",$xdate);
if(($xmonth == "10") ||($xmonth == "11")||($xmonth == "12") ){
$xyear=$xyear+1;
}else{
$xyear=$xyear;
}
return "$xyear";
}
function performDate($startDate,$endDate){
$arr = explode("-", $startDate);
$arr1 = explode("-", $endDate);
$tot=0;
$flg=true;
while ($flg){
//echo date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))." - ".
// date("w",mktime(0,0,0,$arr[1], $arr[2], $arr[0])). " - ".
// mktime(0,0,0,$arr[1], $arr[2], $arr[0]) . "<br>";
if((date("w",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))!=0)&&(date("w",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))!=6)){
$tot++;
}
$arr[2]++;
if (mktime(0,0,0,$arr[1], $arr[2], $arr[0] ) > mktime(0,0,0,$arr1[1], $arr1[2], $arr1[0])) $flg=false;
}
return $tot;
}
function performDate2($startDate,$endDate){
include_once "../class/clsConnection.php";
include_once "../class/clscalendar.php";
$oC = new Connection();
$oCd = new Calendar($oC->c);
$arr = explode("-", $startDate);
$arr1 = explode("-", $endDate);
$tot=0;
$flg=true;
while ($flg){
//echo date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))." - ".
// date("w",mktime(0,0,0,$arr[1], $arr[2], $arr[0])). " - ".
// mktime(0,0,0,$arr[1], $arr[2], $arr[0]) . "<br>";
if((date("w",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))!=0)&&(date("w",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))!=6) && ($oCd->checkStopDate(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])))==0)){
if($oCd->checkDoubleDate(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))))
$tot = $tot+2;
else
$tot++;
}
$arr[2]++;
if (mktime(0,0,0,$arr[1], $arr[2], $arr[0] ) > mktime(0,0,0,$arr1[1], $arr1[2], $arr1[0])) $flg=false;
}
return $tot;
}
function performDateED($startDate,$endDate){
$arr = explode("-", $startDate);
$arr1 = explode("-", $endDate);
$tot=0;
$flg=true;
while ($flg){
//echo date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0]))." - ".
// date("w",mktime(0,0,0,$arr[1], $arr[2], $arr[0])). " - ".
// mktime(0,0,0,$arr[1], $arr[2], $arr[0]) . "<br>";
$tot++;
$arr[2]++;
if (mktime(0,0,0,$arr[1], $arr[2], $arr[0] ) > mktime(0,0,0,$arr1[1], $arr1[2], $arr1[0])) $flg=false;
}
return $tot;
}
function calAgeWork($startDate,$endDate,$personId){
include_once "../class/clsConnection.php";
include_once "../class/clscalendar.php";
include_once "../class/clshisleave.php";
include_once "../class/clshisleave_edu.php";
$oC = new Connection();
$oCd = new Calendar($oC->c);
$oHl = new Hisleave($oC->c);
$oHle = new Hisleave_edu($oC->c);
//echo "startDate = ".$startDate."<BR>";
//echo "endDate = ".$endDate;
$arr = explode("-", $startDate);
$arr1 = explode("-", $endDate);
$tot=0;
$flg=true;
while ($flg){
//ตรวจสอบว่าเป็นวันทวีคูณหรือเปล่า
if($oCd->checkDoubleDate(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])))){
//echo "if";
if (($oHl->checkHisleaveYes(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) ==0)&&($oHle->checkHisleaveeduYes(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) == 0))
$tot = $tot+2;
}else{
//echo "else";
if(($oHl->checkHisleaveNo(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) ==0) && ($oHle->checkHisleaveeduNo(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) ==0))
$tot++;
}
//echo ">> ".$tot."<BR>";
$arr[2]++;
//echo date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0]));
//echo "<BR>".$endDate;
if (mktime(0,0,0,$arr[1], $arr[2], $arr[0] ) > mktime(0,0,0,$arr1[1], $arr1[2], $arr1[0])) $flg=false;
}
return $tot;
}
function calAgeWork2($startDate,$endDate,$personId){
include_once "../class/clsConnection.php";
include_once "../class/clscalendar.php";
include_once "../class/clshisleave.php";
include_once "../class/clshisleave_edu.php";
$oC = new Connection();
$oCd = new Calendar($oC->c);
$oHl = new Hisleave($oC->c);
$oHle = new Hisleave_edu($oC->c);
$x=time_diff2($startDate,$endDate);
//echo "xxxxxxxxxxxx ".$x;
//echo "startDate = ".$startDate."<BR>";
//echo "endDate = ".$endDate;
$arr = explode("-", $startDate);
$arr1 = explode("-", $endDate);
$double = 0;
$numdelete = 0;
$flg=true;
while ($flg){
//ตรวจสอบว่าเป็นวันทวีคูณหรือเปล่า
if($oCd->checkDoubleDate(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])))){
//echo "if";
if (($oHl->checkHisleaveYes(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) ==0)&&($oHle->checkHisleaveeduYes(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) == 0))
$double++;
else
$numdelete++;
}else{
//echo "else";
if(($oHl->checkHisleaveNo(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) ==0) && ($oHle->checkHisleaveeduNo(date("Y-m-d",mktime(0,0,0,$arr[1], $arr[2], $arr[0])),$personId) ==0))
$numdelete = $numdelete;
else
$numdelete++;
}
$arr[2]++;
if (mktime(0,0,0,$arr[1], $arr[2], $arr[0] ) > mktime(0,0,0,$arr1[1], $arr1[2], $arr1[0])) $flg=false;
}
//echo "x = ".$x."<BR>";
//echo "double = ".$double."<BR>";
//echo "numdelete = ".$numdelete."<BR>";
$totdouble = calChangeDate($double);
$totnumdelete = calChangeDate($numdelete);
//echo "totdouble = ".$totdouble."<BR>";
//echo "totnumdelete = ".$totnumdelete."<BR>";
$tot = calNumDate($x,$totdouble);
//echo "tot 1 = ".$tot;
$tot = calsubDate($tot,$totnumdelete);
//echo "tot 2 =" .$tot;
return $tot;
}
function calAgeWork3($startDate,$endDate,$personId){
include_once "../class/clsConnection.php";
include_once "../class/clscalendar.php";
include_once "../class/clshisleave.php";
include_once "../class/clshisleave_edu.php";
include_once "../class/clshisleave_edu.php";
include_once "../class/clsdoubleDate.php";
include_once "../class/clspersonT.php";
$oC = new Connection();
$oCd = new Calendar($oC->c);
$oHl = new Hisleave($oC->c);
$oHle = new Hisleave_edu($oC->c);
$oDd = new DoubleDate($oC->c);
$oPsT = new PersonT($oC->c);
//echo"<>>>>".$startDate;
//echo $endDate;
$oPsT->SearchByKey($personId);
$oPsT->GetRecord();
$oDd->SearchByPs($personId);
if($oDd->GetRecord() == 1)
{
//echo"<>>>>".$startDate."<BR>";
//echo $oPsT->practicDate."<BR>";
//echo"<>>>>".$endDate."<BR>";
$xo=time_diff2(splitDateDbL($startDate),splitDateDbL($oPsT->startDate));
$yo= $oDd->calDoubleDateAge($startDate,$oPsT->practicDate,$personId);
$zo = $oDd->calDoubleDateLeaveYes($startDate,$oPsT->practicDate,$personId);
$wo = $oHl->calLeaveNo($startDate,$oPsT->practicDate,$personId);
$po = $oHle->calLeaveeduNo($startDate,$oPsT->practicDate,$personId);
$xn=time_diff2(splitDateDbL($oPsT->startDate),splitDateDbL($endDate));
$yn = $oCd->calDoubleDateAge($oPsT->practicDate,$endDate,$personId);
$zn = $oCd->calDoubleDateLeaveYes($oPsT->practicDate,$endDate,$personId);
$wn = $oHl->calLeaveNo($oPsT->practicDate,$endDate,$personId);
$pn = $oHle->calLeaveeduNo($oPsT->practicDate,$endDate,$personId);
$x = calNumDate($xo,$xn);
$y = calNumDate($yo,$yn);
$z = calNumDate($zo,$zn);
$w = calNumDate($wo,$wn);
$p = calNumDate($po,$pn);
//echo ">>>> ".$x."<BR>";
//echo ">>>> ".$y."<BR>";
$tot = calNumDate($x,$y);
//echo ">>>>".$tot."<BR>";
$totsub = calNumDate($z,$w);
//echo ">>>>>".$totsub."<BR>";
$totsub = calNumDate($totsub,$p);
//echo ">>>>>".$totsub."<BR>";
}
else
{
$x=time_diff2(splitDateDbL($startDate),splitDateDbL($endDate));
$y = $oCd->calDoubleDateAge($startDate,$endDate,$personId);
$z = $oCd->calDoubleDateLeaveYes($startDate,$endDate,$personId);
$w = $oHl->calLeaveNo($startDate,$endDate,$personId);
$p = $oHle->calLeaveeduNo($startDate,$endDate,$personId);
//echo ">>>> ".$x."<BR>";
//echo ">>>> ".$y."<BR>";
$tot = calNumDate($x,$y);
//echo ">>>>".$tot."<BR>";
$totsub = calNumDate($z,$w);
//echo ">>>>>".$totsub."<BR>";
$totsub = calNumDate($totsub,$p);
//echo ">>>>>".$totsub."<BR>";
}
return calsubDate($tot,$totsub);
}
function calChangeDate($numDate){
$year = floor(($numDate)/(360));
$month = $numDate%360;
$monthnew = floor(($month)/30);
$day = $month%30;
return "$year,$monthnew,$day";
}
function calsubDate($x,$y){
list($year1, $month1, $day1) = split('[,]', $x);
list($year2, $month2, $day2) = split('[,]', $y);
if($day1 < $day2){
while($day1<=$day2){
if($month1 == 0){
$year1 = $year1-1;
$month1 = $month1+12;
}
$month1 = $month1-1;
$day1 = $day1+30;
}
$dayTX = $day1-$day2;
}else{
$dayTX = $day1-$day2;
}
if($month1 < $month2){
while(month1 <= $month2){
$year1 = $year1-1;
$month1 = $month1+12;
}
$monthTX = $month1 - $month2;
}else{
$monthTX = $month1 - $month2;
}
$yearT = $year1-$year2;
return "$yearT,$monthTX,$dayTX";
}
function calmonth($quitDate,$budYear){
//$budYear = $budYear-543;
$endDate = ($budYear-1)."-09-01";
$arr = explode("-", splitDateDbL($quitDate));
$arr1 = explode("-", splitDateDbL($endDate));
//echo "endDate = ".$quitDate;
//echo "quitDate = ".$endDate;
$flg=true;
$tot = 0;
while ($flg){
$tot++;
$arr[1]--;
//echo "ToT = ".$tot;
if (mktime(0,0,0,$arr[1], $arr[2], $arr[0] ) <= mktime(0,0,0,$arr1[1], $arr1[2], $arr1[0])) $flg=false;
}
return $tot;
}
function calSalarySix($personId,$quitDate){
include_once "../class/clsConnection.php";
include_once "../class/clshissalary.php";
include_once "../class/clsperson.php";
$oC = new Connection();
$oHs = new Hissalary($oC->c);
$oPs = new Person($oC->c);
$oPs->SearchByKey($personId);
$oPs->GetRecord();
$budyear = GetbudYearTh($quitDate);
$cycle =1;
$oHs->RSHissalaryPsBud2($personId,$budyear-1,2,$cycle);
if($oHs->GetRecord()){
$salary1 = ($oHs->salary)*6 ;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-1,1,$cycle);
$oHs->GetRecord();
$salary1 = ($oHs->salary)*6;
}
//echo "H".$salary1 ;
$oHs->RSHissalaryPsBud2($personId,$budyear-2,2,$cycle);
if($oHs->GetRecord()){
$salary2 = ($oHs->salary)*6;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-2,1,$cycle);
$oHs->GetRecord();
$salary2 = ($oHs->salary)*6;
}
$oHs->RSHissalaryPsBud2($personId,$budyear-3,2,$cycle);
if($oHs->GetRecord()){
$salary3 = ($oHs->salary)*6;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-3,1,$cycle);
$oHs->GetRecord();
$salary3 = ($oHs->salary)*6;
}
$oHs->RSHissalaryPsBud2($personId,$budyear-4,2,$cycle);
if($oHs->GetRecord()){
$salary4 = ($oHs->salary)*6;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-4,1,$cycle);
$oHs->GetRecord();
$salary4 = ($oHs->salary)*6;
}
$cycle =2;
$oHs->RSHissalaryPsBud2($personId,$budyear-1,2,$cycle);
if($oHs->GetRecord()){
$salary12 = ($oHs->salary)*6 ;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-1,1,$cycle);
$oHs->GetRecord();
$salary12 = ($oHs->salary)*6;
}
$oHs->RSHissalaryPsBud2($personId,$budyear-2,2,$cycle);
if($oHs->GetRecord()){
$salary22 = ($oHs->salary)*6;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-2,1,$cycle);
$oHs->GetRecord();
$salary22 = ($oHs->salary)*6;
}
$oHs->RSHissalaryPsBud2($personId,$budyear-3,2,$cycle);
if($oHs->GetRecord()){
$salary32 = ($oHs->salary)*6;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-3,1,$cycle);
$oHs->GetRecord();
$salary32 = ($oHs->salary)*6;
}
$oHs->RSHissalaryPsBud2($personId,$budyear-4,2,$cycle);
if($oHs->GetRecord()){
$salary42 = ($oHs->salary)*6;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-4,1,$cycle);
$oHs->GetRecord();
$salary42 = ($oHs->salary)*6;
}
$nummonth = calmonth($quitDate,$budyear);
//echo "nummonth = ".$nummonth;
$lastmonth = 12-$nummonth;
//echo "lastmonth = ".$lastmonth;
//echo "psSlalary = ".$oPs->salary;
$salary = $nummonth * $oPs->salary;
//echo "<BR>salary=".$salary;
if($lastmonth > 6){
$oHs->RSHissalaryPsBud2($personId,$budyear-5,2,2);
if($oHs->GetRecord()){
$salarylast = ($oHs->salary)*6;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-4,1,2);
$oHs->GetRecord();
$salarylast = ($oHs->salary)*6;
}
$oHs->RSHissalaryPsBud2($personId,$budyear-5,2,1);
if($oHs->GetRecord()){
$salarylast = (($oHs->salary)*($lastmonth-6)) + $salarylast;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-4,1,1);
$oHs->GetRecord();
$salarylast = (($oHs->salary)*($lastmonth-6))+ $salarylast;
}
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-5,2,2);
if($oHs->GetRecord()){
$salarylast = ($oHs->salary)*$lastmonth;
}else{
$oHs->RSHissalaryPsBud2($personId,$budyear-4,1,2);
$oHs->GetRecord();
$salarylast = ($oHs->salary)*lastmonth;
}
}
//echo "budYear = ".($budyear-1)."<BR>";
//echo "budYear = ".($budyear-2)."<BR>";
//echo "budYear = ".($budyear-3)."<BR>";
//echo "budYear = ".($budyear-4)."<BR>";
//echo "salary1 = ".$salary1."<BR>";
//echo "salary2 = ".$salary2."<BR>";
//echo "salary3 = ".$salary3."<BR>";
// echo "salary4 = ".$salary4."<BR>";
//echo "salary12 = ".$salary12."<BR>";
//echo "salary22 = ".$salary22."<BR>";
//echo "salary32 = ".$salary32."<BR>";
//echo "salary42 = ".$salary42."<BR>";
//echo "salary = ".$salary."<BR>";
// echo "salarylast = ".$salarylast."<BR>";
$average = $salary1+$salary2+$salary3+$salary4+$salary12+$salary22+$salary32+$salary42+$salary+$salarylast;
$average = floor($average/60);
//echo ">>>".$average;
return $average;
}
function sixtyDate($date)
{
//echo "---->".$date;
$arr1 = explode("-", $date);
$yeartmp = $arr1[0];
//echo "---->".$yeartmp;
$yearsixty = 60 + $yeartmp;
$datesixty = $yearsixty."-".$arr1[1]."-".$arr1[2];
return $datesixty;
}
function sixtyDateWork($date)
{
//echo "---->".$date;
$arr1 = explode("-", $date);
$yeartmp = $arr1[0];
//echo "---->".$yeartmp;
$yearsixty = 60 + $yeartmp;
$datesixty = $yearsixty."-".$arr1[1]."-".$arr1[2];
return $datesixty;
}
function sixtyBudYear($dateB)// yy-mm-dd Thai
{
$datesixty = sixtyDateWork($dateB);
if(GetbudYearTh($datesixty) > GetbudYearTh(getNowDateTh()))
{
$pensionYear = GetbudYearTh($datesixty);
$pensionDate = $pensionYear."-"."10"."-"."1";
}
else
{
$pensionYear = GetbudYearTh(getNowDateTh());
$pensionDate = $pensionYear."-"."10"."-"."1";
}
return "$pensionYear,$pensionDate";
}
function getday($date){
if($date=="1"){
$yy = date('Y')+543;
$mm = date('m');
$dd = date('d');
}else{
list($yy, $mm, $dd) = split('[-]', $date);
}
if($dd=='01') { $dd='1'; }
else if($dd=='02') { $dd='2'; }
else if($dd=='03') { $dd='3'; }
else if($dd=='04') { $dd='4'; }
else if($dd=='05') { $dd='5'; }
else if($dd=='06') { $dd='6'; }
else if($dd=='07') { $dd='7'; }
else if($dd=='08') { $dd='8'; }
else if($dd=='09') { $dd='9'; }
if($mm=='01') { $mm='..'; }
else if($mm=='02') { $mm='..'; }
else if($mm=='03') { $mm='..'; }
else if($mm=='04') { $mm='..'; }
else if($mm=='05') { $mm='..'; }
else if($mm=='06') { $mm='..'; }
else if($mm=='07') { $mm='..'; }
else if($mm=='08') { $mm='..'; }
else if($mm=='09') { $mm='..'; }
else if($mm=='10') { $mm='..'; }
else if($mm=='11') { $mm='..'; }
else if($mm=='12') { $mm='..'; }
return "$dd $mm $yy";
}
?>
|