<? include ("sess.php");
//
include("lib.php");		  include ("config.php");   
if($pay_pay !=""){
//
$sql_up="update bookborow set status_borrow=3 where member_id='$pay_pay' and status_borrow=2 ";//echo $sql_up ; exit();
mysql_query($sql_up);
//
if($sql_up){echo"<script>alert('ระบบได้รับเรื่องการชำระเงินเงินเรียบร้อยแล้ว')</script>"; }

?>
<script>
self.opener.document.form1.id_sent.value = "<?=$pay_pay;?>";
self.opener.document.form1.submit();
window.close(); 
</script>
 <? } ?>
<!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" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>ค้นหาข้อมูลนักศึกษา</title>
<style type="text/css">
<!--
body {
	background-image: url(images/bg.png);
}
.style3 {
	font-family: "Microsoft Sans Serif";
	font-size: 14px;
	font-weight: bold;
	color: #FF0000;
}
-->
</style>

</head>
<body>
<table width="588" border="0" align="center">
  <tr>
    <td width="582" height="92"><fieldset>
    <table width="580" border="0">
          <?
		  $sql="select * from tbl_member where id='$pay' "  ;
		//  echo $sql ; exit();
		  $re=mysql_query($sql);
		  $num=mysql_num_rows($re);
		$data1=mysql_fetch_array($re);
		  ?>
          <tr>
            <td width="570" class="inputtext"><span class="style3">รายละเอียดยอดค้างชำระ :</span> <? echo "$data1[intro]$data1[name] ";?></td>
          </tr>

          <tr>
            <td><div align="right">
              <table width="580" border="0" align="center">
                <tr>
                  <td width="56" class="menuclick"><div align="center">รหัส</div></td>
                  <td width="130" class="menuclick"><div align="center">ชื่อหนังสือ</div></td>
                  <td width="124" class="menuclick"><div align="center">ประเภทหนังสือ</div></td>
                  <td width="74" class="menuclick"><div align="center">วันยืม</div></td>
                  <td width="70" class="menuclick"><div align="center">วันคืน</div></td>
                  <td width="100" class="menuclick"><div align="center">วันล่าช้า/ค่าปรับ</div></td>
                </tr>
                         <?
		  $sql="select * from bookborow where  member_id='$pay'  and ( status_borrow=1 or status_borrow=2)  "  ;
		//  echo $sql ; exit();
		  $re=mysql_query($sql);
		  $num=mysql_num_rows($re);

				 function DateDiff($strDate1,$strDate2)
	 {
				return (strtotime($strDate2) - strtotime($strDate1))/  ( 60 * 60 * 24 );  // 1 day = 60*60*24
	 }
	 	  $d_d=date("d-m-Y");
				while ($data=mysql_fetch_array($re)){
				$sql_book=mysql_query("select * from tbl_book where id='$data[book_id]' ");
			//	echo $sql_book ; exit();
				$data_book=mysql_fetch_array($sql_book);
								$sql_type=mysql_query("select * from type_book where id='$data_book[book_type]' ");
								$data_type=mysql_fetch_array($sql_type); 
									$date2= DateDiff("$data[date_sent]","$d_d"); //echo $date2;
		if($date2 > 0 ){
		$num_cal=$date2;
		$date_cal_=$date2 * 5;
		//echo $date_cal_;
		$total_cal+=$date2 * 5;
		}
								?>
                <tr>
                  <td class="inputtext"><div align="center">
                    <?=$data_book[no_id];?>
                  </div></td>
                  <td class="inputtext"><div align="center">
                    <?=$data_book[book_name];?>
                  </div></td>
                  <td class="inputtext"><div align="left">
                    <?=$data_type[name];?>
                  </div></td>
                  <td class="inputtext"><?=$data[date_borrow];?></td>
                  <td class="inputtext"><?=$data[date_sent];?></td>
                  <td class="inputtext">
                    <div align="right">
                      <?=$num_cal?>
                    วัน 
                      <?=$date_cal_?>
&nbsp;บาท</div></td>
                </tr><? }?>
              </table>

            </div></td>
          </tr>
          <tr>
            <td height="38"><div align="right" class="inputtext">ยอดค้างชำระทั้ั่งหมด <?=$total_cal?> บาท&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="<? echo"pay.php?pay_pay=$pay&pay=$pay";?>"><span class="menuclick">&nbsp;แจ้งการชำระเงิน&nbsp;</span></a></div></td>
          </tr>
      </table>
   
            </fieldset>    </td>
  </tr>
  <tr>
    <td height="24"><div align="center">

    </div></td>
  </tr>
</table>

<input name="btnButton" type="button" class="style3" onClick="JavaScript:window.print();" value="พิมพ์รายละเอียด" />

</body>
</html>
