<?php include '_session_login.php' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
	<link rel="stylesheet" href="css/style.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<title></title>
<style type="text/css">
@media print{
.print_text {
	line-height: 1.0em;
	font-size:16px;
	font-family: "AngsanaUPC";
}
}
select {
	text-align: center;
	text-align-last: center;
  border:none;
}
option {
	text-align: left;
}
</style>

<style>
#p2{
	font-size:0.8em;
}
.p2{
	font-size:0.8em;
}
table {
  border-collapse: collapse;
}
select {
  border: 0 !important;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: url('dropdown_arrow.png') no-repeat;
  background-position: 0px 0px;
  text-indent: 0px;
  text-overflow: "";
  color: black;
	text-align:center;
}
.td {
	border: 1px solid black;
	padding: -1px;
	line-height: 0.9em;
}
@media print {
  @page {
		margin: 0;
	}
  body {
		margin: 0.6cm;
	}
}
</style>
<style type="text/css" media="print">
.inputprint{
    display:none;
}
@page { size: landscape; }
body{
	line-height: 7pt;
}
</style>

<style>
.div {
    width: 40%;
    padding: 15px;
    border: 15px solid green;
    margin: 15px;
}
</style>

</head>
<body>
<?php
    $ACT_NO = $_REQUEST['ACT_NO'];
    $_month_name = array("01"=>"มกราคม",  "02"=>"กุมภาพันธ์",  "03"=>"มีนาคม",
    	 "04"=>"เมษายน",  "05"=>"พฤษภาคม",  "06"=>"มิถุนายน",
    	 "07"=>"กรกฎาคม",  "08"=>"สิงหาคม",  "09"=>"กันยายน",
    	 "10"=>"ตุลาคม", "11"=>"พฤศจิกายน",  "12"=>"ธันวาคม");
    $m = date('m');
    $MM = $_month_name[$m];
    include '_connect.php';
    function convert($number){
    $txtnum1 = array('ศูนย์','หนึ่ง','สอง','สาม','สี่','ห้า','หก','เจ็ด','แปด','เก้า','สิบ');
    $txtnum2 = array('','สิบ','ร้อย','พัน','หมื่น','แสน','ล้าน','สิบ','ร้อย','พัน','หมื่น','แสน','ล้าน');
    $number = str_replace(",","",$number);
    $number = str_replace(" ","",$number);
    $number = str_replace("บาท","",$number);
    $number = explode(".",$number);
    if(sizeof($number)>2){
    return '';
    exit;
    }
    $strlen = strlen($number[0]);
    $convert = '';
    for($i=0;$i<$strlen;$i++){
    	$n = substr($number[0], $i,1);
    	if($n!=0){
    		if($i==($strlen-1) AND $n==1){ $convert .= 'เอ็ด'; }
    		elseif($i==($strlen-2) AND $n==2){  $convert .= 'ยี่'; }
    		elseif($i==($strlen-2) AND $n==1){ $convert .= ''; }
    		else{ $convert .= $txtnum1[$n]; }
    		$convert .= $txtnum2[$strlen-$i-1];
    	}
    }
    $convert .= 'บาท';
    if($number[1]=='0' OR $number[1]=='00' OR
    $number[1]==''){
    $convert .= 'ถ้วน';
    }else{
    $strlen = strlen($number[1]);
    for($i=0;$i<$strlen;$i++){
    $n = substr($number[1], $i,1);
    	if($n!=0){
    	if($i==($strlen-1) AND $n==1){$convert
    	.= 'เอ็ด';}
    	elseif($i==($strlen-2) AND
    	$n==2){$convert .= 'ยี่';}
    	elseif($i==($strlen-2) AND
    	$n==1){$convert .= '';}
    	else{ $convert .= $txtnum1[$n];}
    	$convert .= $txtnum2[$strlen-$i-1];
    	}
    }
    $convert .= 'สตางค์';
    }
    return $convert;
    }
		$sql = "SELECT * FROM [CONFIG].[dbo].[ACT_RECEIPT] WHERE ACT_NO = '$ACT_NO'";
    // echo "$sql";
    $select=$conn->prepare($sql);
    $select->execute();
    $fetch=$select->fetch();
    if ($fetch['ACT_DATE1'] != '') {
      $ACT_DATE11 = substr($fetch['ACT_DATE1'],0,4)+543; $ACT_DATE12 = substr($fetch['ACT_DATE1'],5,2); $ACT_DATE13 = substr($fetch['ACT_DATE1'],8,2);
      $ACT_DATE1 = $ACT_DATE13."/".$ACT_DATE12."/".$ACT_DATE11;
    } else {
      $ACT_DATE1 = '';
    }
    if ($fetch['ACT_DATE2'] != '') {
      $ACT_DATE21 = substr($fetch['ACT_DATE2'],0,4)+543; $ACT_DATE22 = substr($fetch['ACT_DATE2'],5,2); $ACT_DATE23 = substr($fetch['ACT_DATE2'],8,2);
      $ACT_DATE2 = $ACT_DATE23."/".$ACT_DATE22."/".$ACT_DATE21;
    } else {
      $ACT_DATE2 = '';
    }
    if ($fetch['SUM_PAPER'] != '') {
      $SUM_PAPER = $fetch['SUM_PAPER'];
    }
    else {
      $SUM_PAPER = '0';
    }
    if ($fetch['SUM_PANCIL'] != '') {
      $SUM_PANCIL = $fetch['SUM_PANCIL'];
    }
    else {
      $SUM_PANCIL = '0';
    }
    $SUMPRICEX1 = number_format(($fetch['REG_PRICE']+$SUM_PAPER)+$SUM_PANCIL,2);
?>
<page size="A4">
<div class="div">
<form class="" name="frm" method="post" action="" target="_blank" id="form-search" >
<table border="0" width="100%" class="print_text" id="my-text">
  <tr>
    <td></td>
    <td align="right"> <label id="p2">เลขที่ <?php echo $fetch['ACT_NO']; ?></label>&nbsp; &nbsp;</td>
  </tr>
  <tr>
    <td width="15%">
      <img src="dist/img/logo_1.png" alt="" width="100%" height="auto">
    </td>
    <td><center><p>
        <b><?php echo $fetch['CROP_NAME']; ?></b><br><br>
        <b>ใบรับรองแทนใบเสร็จรับเงิน</b>
    </p></center></td>
  </tr>
  <tr>
    <td ></td>
  </tr>
</table><br><br>
<table border="0" width="100%" class="print_text">
  <tr>
    <td><label id="p2">&nbsp; ผู้รับเงินจากบริษัท</label></td>
    <td><label id="p2" style="color:#1E90FF;"><?php echo $fetch['COMPANY']; ?> </label></td>
  </tr>
</table>
 <br>
<table border="1" width="100%" class="print_text">
  <tr>
    <td align="center" width="10%"><label id="p2"><b>ลำดับ</b></label></td>
    <td align="center" width="50%"><label id="p2"><b>รายละเอียดรายจ่าย</b></label></td>
    <td align="center" width="10%"><label id="p2"><b>จำนวนเงิน</b></label></td>
    <td align="center" width="10%"><label id="p2"><b>หมายเหตุ</b></label></td>
  </tr>
  <tr>
    <td align="center"><label id="p2" style="color:#1E90FF;">1.</label></td>
    <td><label id="p2" style="color:#1E90FF;">&nbsp; ค่า พ.ร.บ. <?php //echo $fetch['REG_PRICE']; ?></label></td>
    <td align="right"><label id="p2" style="color:#1E90FF;"><?php echo number_format($fetch['REG_PRICE'],2); ?></label>&nbsp;</td>
    <td><label id="p2" style="color:#1E90FF;">&nbsp; </label></td>
  </tr>
  <tr>
    <td align="center"><label id="p2" style="color:#1E90FF;">2.</label></td>
    <td><label id="p2" style="color:red;">&nbsp; หัก ค่านายหน้า <?php //echo $fetch['tsp_registrar1']; ?> </label></td>
    <td align="right"><label id="p2"  style="color:red;">-<?php echo number_format($fetch['SUM_BROKER'],2); ?></label>&nbsp;</td>
    <td><label id="p2"></label></td>
  </tr>
  <tr>
    <td align="center"><label id="p2" style="color:#1E90FF;">3.</label></td>
    <td><label id="p2" style="color:#1E90FF;">&nbsp; บวกค่ากระดาษ <?php //echo $fetch['tsp_registrar']; ?> </label></td>
    <td align="right"><label id="p2"  style="color:#1E90FF;"><?php echo number_format($SUM_PAPER,2); ?></label>&nbsp;</td>
    <td><label id="p2"></label></td>
  </tr>
  <tr>
    <td align="center" width="10%"><label id="p2"><b></b></label> <br> </td>
    <td><label id="p2" style="color:#1E90FF;">&nbsp; บวกค่าเครื่องเขียน<?php //echo $fetch['tsp_registrar']; ?> </label></td>
    <td align="right"><label id="p2"  style="color:#1E90FF;"><?php echo number_format($SUM_PANCIL,2); ?></label>&nbsp;</td>
    <td align="center" width="10%"><label id="p2"><b></b></label> <br> </td>
  </tr>
	<tr>
		<td align="center"><label id="p2" style="color:#1E90FF;"></label></td>
		<td><label id="p2" style="color:#1E90FF;">&nbsp;  <?php //echo $fetch['CT_NO']; ?> </label></td>
		<td><label id="p2"></label></td>
		<td><label id="p2"></label></td>
	</tr>
  <tr>
    <td align="center"></td>
    <td><label id="p2" style="color:#1E90FF;">&nbsp;  <?php //echo $fetch['BRAND_NAME']; ?> </label> </td>
    <td><label id="p2"></label></td>
    <td><label id="p2"></label></td>
  </tr>
	<tr>
		<td align="center"></td>
		<td><label id="p2" style="color:#1E90FF;">&nbsp;  <?php //echo $fetch['SERIAL_NO']; ?> </label></td>
		<td><label id="p2"></label></td>
		<td><label id="p2"></label></td>
	</tr>
  <tr>
    <td align="center"></td>
    <td><label id="p2" style="color:#1E90FF;">&nbsp;  <?php// echo $fetch['PSERIAL_NO']; ?> </label></td>
    <td><label id="p2"></label></td>
    <td><label id="p2"></label></td>
  </tr>
</table>
<table border="1" width="100%" class="print_text" id="my-text">
  <tr>
    <br>
    <td align="center" width="50%" colspan="2"> <label id="p2" style="color:#1E90FF;"> <?php echo "(" .convert($SUMPRICEX1).")"; ?></label> </td>
    <td align="center" width="10%"><label id="p2">รวมทั้งสิ้น</label></td>
    <td align="right" width="10%"><label id="p2" style="color:#1E90FF;"><?php echo $SUMPRICEX1; ?></label> &nbsp;</td>
    <td align="center" width="10%"><label id="p2"></label></td>
  </tr>
</table>
<br>
<table border="0" width="100%" class="print_text" id="my-text">
  <tr>
    <td colspan="4">
      <label id="p2">ข้าพเจ้า &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font style="color:#1E90FF;"><?php echo $fetch['PAYER']; ?></font>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
      <label id="p2">(ผู้เบิกจ่าย) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ตำแหน่ง &nbsp;&nbsp;&nbsp;&nbsp; <?php echo $fetch['REG_POSITION']; ?></label> <!-- <input type="text" name="" class="width-dynamic"  id="p2" style="border:none; font-family:Angsana New;" value="ตำแหน่ง..">  --> <br>
      <label id="p2">ขอรับรองว่า รายจ่ายข้างต้นไม่อาจเรียกเก็บใบเสร็จรับเงินจากผู้รับได้ และข้าพเจ้าได้จ่ายไปในงานของทาง</label>
      <br>
      <label id="p2"><?php echo $fetch['CROP_NAME']; ?> โดยแท้ ตั้งแต่วันที่ &nbsp;&nbsp;&nbsp; <?php echo $ACT_DATE1; ?></label>&nbsp;&nbsp;&nbsp;
      <label id="p2"> ถึงวันที่ &nbsp;&nbsp;&nbsp; <?php echo $ACT_DATE2; ?></label>
    </td>
  </tr>
</table>
<table border="0" width="100%" class="print_text" id="my-text">
  <tr>
    <td  width="60%"></td>
    <td align="center"><br><br>
      <!-- <div id="tag7"></div> -->

			<label id="p2">ลงชื่อ</label> .................................... <label id="p2">(ผู้เบิกจ่าย)</label><br>
      <label id="p2"><?php echo "(".$fetch['PAYER'].")"; ?></label> <br><br>
      <label id="p2">ลงชื่อ</label> .................................... <label id="p2">(ผู้อนุมัติ)</label><br>
      <label id="p2">(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)</label>
    </td>
  </tr>
</table>
<br>
<!-- <input type="hidden" name="sss1" id="sss1" value="180.00"> -->
</form>
<!-- </page>
<div style='page-break-after: always'></div> -->
</div>
<br><br><br><br>

<script language="JavaScript">
function startCalc(){
	interval = setInterval("calc()",1);
}
function chk(){
	var a1 = parseFloat(document.frm.a1.value.replace(/,/g, ''));
	var a2 = parseFloat(document.frm.a2.value.replace(/,/g, ''));
	var a3 = parseFloat(document.frm.a3.value.replace(/,/g, ''));
	result1 = (a1 * 1) + (a2 * 1) + (a3 * 1);
	if (isNaN(result1)) { document.frm.a1sum.value = ""; }
	else {
    document.frm.a1sum.value = result1.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  }
	result2 = (a2 * 1) + (a3 * 1);
	document.frm.sss1.value = result2.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
	}
	function stopCalc(){
		clearInterval(interval);
	}
</script>

<script>
 	function autofill(){
 		var tagc = $("#tag").val();
 		$.ajax({
 			url : '_autofill_1.php',
 			data : 'tagc='+tagc
 		}).success(function(data){
 			var json = data,
 			obj = JSON.parse(json);
 			$("#tag1").val(obj.id1);
      $("#tag2").val(obj.id2);
      $("#tag3").val(obj.id3);
      $("#tag4").val(obj.id4);
      $("#tag5").val(obj.id5);
      $("#tag6").val(obj.id6);
      $("#tag7").html('<img src="img/'+obj.id7+'" width="40%">')
			$("#tag8").val(obj.id8);
 		});

    var tagco = $("#auto").val();
    $.ajax({
      url : '_autocomplete_1.php',
      data : 'tagco='+tagco
    }).success(function(data){
      var json = data,
      obj = JSON.parse(json);
      $("#cop1").val(obj.cop1);
			$("#cop2").val(obj.cop2);
			$("#cop3").val(obj.cop3);
			$("#cop4").val(obj.cop4);
			$("#cop5").val(obj.cop5);
    });
 	}
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js'>
</script><script  src="script.js"></script>
<script>
// function myFunction() {
//   window.print();
// }
// function() {
  // window.print();
	// window.exit();
// }
</script>

</body>
</html>
