
<?php
if($system_status==1){
	$form_name="";
	$date_start=$date_start;
	$date_end=$date_end;
}
if($system_status==2){
	$form_name="(หลังกำหนด)";
	$date_start=$date_start2;
	$date_end=$date_end2;
}
	
	
?>	 
 <center><h2><strong>ลงทะเบียน <?=$form_name?> ภาคเรียนที่ <?=$semester?> ปีการศึกษา <?=$academicYear?> </strong> </h2>
  <p><?php  echo "กำหนดชำระเงินภายในวันที่ ".thai2($date_start). " - ".thai2($date_end);   ?></p></center>
<style>
	li{
		list-style-type:none;
	}
</style>
<?php
//global $connect;		
			//ดึงข้อมูลนักศึกษา 
				$result_std2018_student=select("std2018_student,prefix,studentstatuscode","where std2018_student.studentCode='$studentCode' AND std2018_student.prefixID=prefix.prefix_id AND std2018_student.studentStatusCode=studentstatuscode.studentStatusCode");
					$prefix_name=$result_std2018_student['prefix_name'];
					$firstname=$result_std2018_student['firstname'];
					$surname=$result_std2018_student['surname'];
					$studentCode=$result_std2018_student['studentCode'];
					$studentStatusCode=$result_std2018_student['studentStatusCode'];
					$gpax=$result_std2018_student["gpax"];
					$tel=$result_std2018_student["tel"];
					$StatusName=$result_std2018_student["StatusName"];
					$tel=$result_std2018_student["tel"];
					$groupName=$result_std2018_student["groupName"];
					$minorNameTH=$result_std2018_student["minorNameTh"];
					$gpax=$result_std2018_student["gpax"];
					$idcard_student=$result_std2018_student["idcard"];	
//ดึงข้อมูลกลุ่มเรียน	
				$result_std2018=select("std2018_studentgroup","where groupCode='$groupCode'");
					$grade=$result_std2018['grade'];
					$groupCode=$result_std2018['groupCode'];
					$groupName=$result_std2018['groupName'];
					$teacherFirstname=$result_std2018['teacherFirstname'];
					$teacherLastname=$result_std2018['teacherLastname'];	
//------- ดึงข้อมูลค่าหน่วยกิต และค่าธรรมเนียมการศึกษา ------
				$num_regis_group=num_record("regis_group","where groupCode='$groupCode'  AND academicYear='$academicYear' AND semester='$semester'  AND status='1'");
				//echo $result;
				$result_regis_group=select("regis_group","where groupCode='$groupCode'  AND academicYear='$academicYear' AND semester='$semester' ");
					$credit=$result_regis_group["credit"];
					$cost_credit=$result_regis_group["cost_credit"];
					$cost_value=$result_regis_group["cost_value"];
					$total_value=$cost_credit+$cost_value;
					include("pages/convert.php"); 
					//$convert_number= convert($total_value); 

?>
		
	<div class="card bg-light text-dark">
    			<div class="card-body">
					<div class="row">
		  <div class="col-sm-3"><div align="center">
	

		  <img src="<?=$link_img_student?><?=$studentCode?>.jpg" width="100" alt="" width="100" class="rounded"> 
		  </div></div>
		  <div class="col-sm-9">
				  <ui>
				    <li>รหัสประจำตัวนักศึกษา : <b><?php echo"$studentCode"; ?></b></li> 
			  		<li>ชื่อ นามสกุล : <b><?php echo"$prefix_name$firstname    $surname"; ?></b></li>
					<li>GPA : <b><?php echo"$gpax"; ?></b></li>  
				  <li>สาขางาน : <b><?php echo"$minorNameTH"; ?></b></li>
				   <li>กลุ่ม : <b><?php echo"$groupName"; ?></b></li>
					 <li>ครูที่ปรึกษา : <b><?php if($teacherFirstname!=""){ echo"ครู$teacherFirstname   $teacherLastname"; }?></b></li>  
				  <li>สถานะภาพ : <b><?php echo"$StatusName"; ?></b></li>
 
			  </ui><br>
	</div></div></div>
</div>
<br>
<div class="row">
  <div class="col-sm-12">
	

<?php
if($num_regis_group==0){
	echo " <div class=\"alert alert-danger\"><center>  <strong> กลุ่มเรียนนี้ ไม่มีข้อมูลการลงทะเบียน</strong> ติดต่องานทะเบียนฯ $tel_regis </center></div>";
	exit();
}	  
if($studentStatusCode!=="03"){
	echo " <div class=\"alert alert-danger\"><center> นักศึกษา <strong>พ้นสภาพ</strong> ไม่สามารถลงทะเบียนได้ ติดต่องานทะเบียนฯ $tel_regis  <br>(กรณีที่ GPA กว่า $lowGPA  นักศึกษาจะไม่สามารถลงทะเบียนได้) </center></div>";
	
}
else
{			
		$num_regis_payment_log=num_record("regis_payment_log","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode' AND GroupCode='$groupCode' ");
		if($num_regis_payment_log!=0){
			$result_regis_payment_log=select("regis_payment_log","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode' AND GroupCode='$groupCode' ");
			$cost_total8=$result_regis_payment_log["cost_total"];	
			$PaymentDate8=$result_regis_payment_log["PaymentDate"];	
			$cost_total88=number_format($cost_total8);
			$PaymentDate8=thai9($PaymentDate8);
			echo " <div class=\"alert alert-success\"><center>  <strong> ชำระเงินค่าลงทะเบียนเรียบร้อยแล้ว</strong><br> (จำนวนเงินที่ชำระ <b>$cost_total88</b> บาท เมื่อวันที่ $PaymentDate8)  </center></div>";	
		}
?>			
</div>
</div>							
<div class="row">
  <div class="col-sm-6">
<center>รายวิชาที่ลงทะเบียน</center>
<?php
//ดึงข้อมูลแผนการเรียน
$sqlx="Select * From std2018_curi_plan where academicYear='$academicYear' AND semester='$semester' AND GroupCode='$groupCode' order by subjectCode ASC";
$db_queryx=mysqli_query($connect,$sqlx);
$num_rowsx=mysqli_num_rows($db_queryx); /* นับ Reccord ที่พบ */
//echo "มีจำนวน <b>$num_rowsx</b> รายวิชา";
if($num_rowsx==0){
	echo "<strong>Warning!</strong> ไม่มีแผนการเรียน.";
}
else
{
	?>
        
    <table class="table table-hover table-striped table-condensed table-sm table-bordered">
    <thead>
      <tr>
        <th><center>#</center></th> 
        <th><center>รหัสวิชา</center></th>
		  <th>ชื่อรายวิชา</th>
		<th><center>หน่วยกิต</center></th>	
      </tr>
    </thead>
    <tbody>
<?php
$ax=0;
 $total_creditx=0;
while($ax < $num_rowsx)
{
	$resultx = mysqli_fetch_array($db_queryx);
	$subjectCodex=$resultx['subjectCode'];
	$subjectNameThx=$resultx['subjectNameTh'];
	$creditx=$resultx['credit'];
		//นับจำนวนหน่วยกิต
	$total_creditx=$total_creditx+$creditx;


	
	?>	
      <tr>
       <td><center><?php echo $ax+1;?></center></td> 
        <td><center><?=$subjectCodex?></center></td>
        <td><?=$subjectNameThx?></td>
        <td><center><?=$creditx?></center></td>
      </tr>
<?php
		$ax++;
}
	
?>
	<tr>
		<td colspan="3"><center><b>รวมหน่วยกิต</b></center></td>
		<td><center><b><?php echo $total_creditx?></b></center></td>
		
	</tr>	
    </tbody>
  </table>
		
		

		<br>
<?php
}
	  ?>
</div>
  <div class="col-sm-6">
<!-- เริ่มค่าธรรมเนียม -->
<center>รายการค่าธรรมเนียม</center>	  
<?php
//ดึงข้อมูลค่าธรรมเนียม
$sql2="Select * From cost_groups_item_list,cost_item where cost_groups_item_list.academicYear='$academicYear' AND cost_groups_item_list.semester='$semester' AND cost_groups_item_list.groupCode='$groupCode'  AND cost_groups_item_list.cost_item_id=cost_item.cost_item_id   order by cost_groups_item_list.id ASC";
$db_query2=mysqli_query($connect,$sql2);
$num_rows2=mysqli_num_rows($db_query2); /* นับ Reccord ที่พบ */
if($num_rows2==0){
	echo "<div class=\"alert alert-warning\"><strong>Warning!</strong> ยังไม่ได้เพิ่มค่าธรรมเนียม.</div>";
	
}
else
{


?>

    <table class="table table-hover table-striped table-condensed table-sm table-bordered">
    <thead>
      <tr>
        <th><center>#</center></th>
        <th colspan="2">รายละเอียดค่าธรรมเนียม</th>
        </tr>
    </thead>
    <tbody>
		      <tr>
        <td><center><?php echo "1";?>.</center></td>
        <td>ค่าลงทะเบียนรายวิชา  จำนวน <?=$credit?> หน่วยกิต</td>
        <td style="text-align: right"><?php echo number_format($cost_credit);?> บาท</td>
        
      </tr>
	<?php
	
$a2=0;
$cost_total2=$cost_credit;	
$no2=2;	
while($a2 < $num_rows2)
{
	$result2 = mysqli_fetch_array($db_query2);
	$item_id2=$result2['id'];
	$cost_item_id2=$result2['cost_item_id'];
	$cost_subject2=$result2['cost_subject'];
	$cost_var2=$result2['cost_var'];


;
	//นับจำนวนนักศึกษาในกลุ่มเรียน
	$num_student=num_record("std2018_student","where groupCode='$groupCode' AND studentStatusCode='03'");
	//echo $num_student;
	
	//เช็คว่าเลือกกลุ่มเรียนนี้แล้วหรือยัง
	$num_regis_group=num_record("regis_group","where academicYear='$academicYear' AND semester='$semester' AND groupCode='$groupCode' ");

	//ตรวจสอบ option ของรายการค่าธรรมเนียม
	$result_cost_item_list=select("cost_item_list","where cost_item_id='$cost_item_id2'");
	$option=$result_cost_item_list["option"];

	//echo "$cost_item_id2 $option<br>";
	
	
	
	if($option==0){	
	?>	
		
      <tr>
        <td><center><?php echo $no2;?>.</center></td>
        <td><?=$cost_subject2?></td>
        <td style="text-align: right"><?php echo number_format($cost_var2);?> บาท</td>  
      </tr>
	<?php 
	$cost_total2=$cost_total2+$cost_var2;
	}else{
		//ตรวจว่าเลือกค่าธรรมเนียมนี้หรือไม่
		$num_student_select_option=num_record("student_select_option","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode' AND cost_item_id='$cost_item_id2'");
		//echo $num_student_select_option;
		if($num_student_select_option!=0){
			?>
      <tr>
        <td><center><?php echo $no2;?>.</center></td>
        <td><?=$cost_subject2?></td>
        <td style="text-align: right"><?php echo number_format($cost_var2);?> บาท</td>  
      </tr>
<?php			
	$cost_total2=$cost_total2+$cost_var2;
		}
	} 
	
	?>
<?php	
	$no2++;
	$a2++;
}
$convert_number= convert($cost_total2); 
//ปรับปรุงยอดเงินที่ต้องชำระ
		//update("regis_student_log","cost_total='$cost_total2'","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode'")
	?>
	<tr>
 		<td colspan="2"><center><b>รวมเงินที่ต้องชำระ&nbsp;&nbsp;&nbsp;(<?=$convert_number?>)</b></center></td>
		<td style="text-align: right"><b><?php echo number_format($cost_total2); ?> บาท</b></td>
		</tr>	
    </tbody>
</table>

<?php 
}
?>	  

<!-- สิ้นสุดค่าธรรมเนียม -->	
	</div>
</div>
<?php
//if($num_regis_payment_log==0){	
	
?>
<div class="row">	
  <div class="col-sm-12">
  <div class="card">
    <div class="card-body">	  
<?php
	//--------- ดึงค่าข้อมูล ธนาคาร ----------------------------
$result_payment=select("regis_payment","where payment_id ='1'");
$taxid=$result_payment["taxid"];
$suffix=$result_payment["suffix"];
$due_date=$result_payment["due_date"];
$compcode=$result_payment["compcode"];
$bank_name=$result_payment["bank_name"];
	
?>	
<div class="alert alert-warning">		

<?php	
if($payment_type==1){
	$topHead="วิธีการชำระเงินค่าลงทะเบียนเรียน";
	$comment1="** ชำระเงินผ่าน Mobile Banking โดยสแกน QR Code ในใบแจ้งชำระเงินฯ  หรือ";
	$comment2="** ชำระเงินได้ที่ $bank_name ทุกสาขาทั่วประเทศ ";
	$comment3="** กรณีที่ไม่สามารถชำระเงินตามที่วิทยาลัยฯ กำหนด ให้ติดต่อ งานการเงิน ก่อนสิ้นสุดวันที่ชำระเงิน";
}
if($payment_type==2){
	$topHead="วิธีการชำระเงินค่าลงทะเบียนเรียน";
	$comment1="** ชำระเงินผ่าน Mobile Banking โดยสแกน QR Code ในใบแจ้งชำระเงินฯ ";
	$comment2="** กรณีที่ไม่สามารถชำระเงินตามที่วิทยาลัยฯ กำหนด ให้ติดต่อ งานการเงิน ก่อนสิ้นสุดวันที่ชำระเงิน";
	$comment3="";
}
if($payment_type==3){
	$topHead="วิธีการชำระเงินค่าลงทะเบียนเรียน";
	$comment1="** ชำระเงินได้ที่ $bank_name ทุกสาขาทั่วประเทศ ";
	$comment2="** กรณีที่ไม่สามารถชำระเงินตามที่วิทยาลัยฯ กำหนด ให้ติดต่อ งานการเงิน ก่อนสิ้นสุดวันที่ชำระเงิน";
	$comment3="";
}
if($payment_type==4){
	$topHead="วิธีการลงทะเบียนหลังกำหนด";
	$comment1="ดาวน์โหลด แบบฟอร์มคำร้องขอลงทะเบียนหลังกำหนด";
	$comment2="** กรณีที่ไม่สามารถชำระเงินตามที่วิทยาลัยฯ กำหนด ให้ติดต่อ งานการเงิน ก่อนสิ้นสุดวันที่ชำระเงิน";
	$comment3="";
}	
?>	
	<b><?=$topHead?></b>
		<ui>
			<li><?=$comment1?></li>
			<li><?=$comment2?></li>
			<li><?=$comment3?></li>
			<li><?php  echo "ชำระเงินภายในวันที่ ".thai2($date_start). " - ".thai2($date_end);   ?> เท่านั้น </li>
		
		</ui>
</div>	
<br>		
<center>
	<a href="pages/pdf-StudentInvoice.php?studentCode=<?php echo 
base64_encode(base64_encode($studentCode)); ?>" target="_blank" class="btn btn-outline-primary" role="button"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> ใบแจ้งการชำระเงินค่าลงทะเบียนเรียน</a>
</center>
	</div>	
</div>	
	</div>	
</div>		  
<?php
	//}
}
?>