<?php
include("dbconnection.php");
$student_id = $_GET['student_id'];
$cid = $_GET['cid'];
$bill_no = $_GET['bill_no'];
$q2 = "SELECT
    payments.p_id,
    course_type.c_name,
    payments.p_main_amount,
    discount.d_amount,
    payments.p_amount,
    loan_r_details.p_received_amount,
    loan_r_details.p_borrow_amount,
    payments.class_time,
    payments.start_date,
    payments.end_date,
    payments.p_status,
    loan_r_details.bill_no
FROM payments
LEFT JOIN course_type 
       ON course_type.c_id = payments.c_id
LEFT JOIN loan_r_details 
       ON loan_r_details.c_id     = payments.c_id
      AND loan_r_details.s_id     = payments.s_id       -- matches the same student
      AND loan_r_details.bill_no  = '$bill_no'          -- new condition
LEFT JOIN discount 
       ON discount.c_id = payments.c_id
      AND discount.s_id = payments.s_id
WHERE payments.s_id = '$student_id'
  AND payments.c_id = '$cid'";
$r = $con->query($q2); 
// print_r($r);
?>

<!DOCTYPE html>
<html>
<head>
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>پرداخت  </title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="shortcut icon" type="image/png" href="images/J.png">
    <script>
  window.addEventListener("DOMContentLoaded", () => {
    document.addEventListener("keydown", function(event) {
      if (event.key === "Escape") {
        window.location.href = "index.php"; // Directly go to index.php
      }
    });
  });
</script>

    <style type="text/css">
			/* reset */

*
{
	border: 0;
	box-sizing: content-box;
	color: inherit;
	font-family: inherit;
	font-size: inherit;
	font-style: inherit;
	font-weight: inherit;
	line-height: inherit;
	list-style: none;
	margin: 0;
	padding: 0;
	text-decoration: none;
	vertical-align: top;
}

/* content editable */

*[contenteditable] { border-radius: 0.25em; min-width: 1em; outline: 0; }

*[contenteditable] { cursor: pointer; }

*[contenteditable]:hover, *[contenteditable]:focus, td:hover *[contenteditable], td:focus *[contenteditable], img.hover { background: #DEF; box-shadow: 0 0 1em 0.5em #DEF; }

span[contenteditable] { display: inline-block; }

/* heading */

h1 { font: bold 100% sans-serif;  text-transform: uppercase; }

/* table */

table { font-size: 75%; table-layout: fixed; width: 100%; }
table { border-collapse: separate; border-spacing: 2px; }
th, td { border-width: 1px; padding: 0.5em; position: relative; text-align: left; }
th, td { border-style: solid; }
th { background:#1a80ed; border-color: #BBB; }
td { border-color: rgb(0, 0, 0); }

/* page */

html { font: 19px/1 'Open Sans', sans-serif; overflow: auto; padding: 0.5in; }
html { background: #999; cursor: default; }

body { box-sizing: border-box; height: 15in; margin: 0 auto; overflow: hidden; padding: 0.5in; width: 8.5in; }
body { background-image: url("assets/images/");  background-size: 820px 1100px;  background-repeat: no-repeat; border-radius: 1px; box-shadow: 0 0 1in -0.25in rgba(0, 0, 0, 0.5); }

/* header */

header { margin: 0 0 3em; }
header:after { clear: both; content: ""; display: table; }

header h1 { background: #000; border-radius: 0.25em; color: #FFF; margin: 0 0 1em; padding: 0.5em 0; }
header address { float: left; font-size: 75%; font-style: normal; line-height: 1.25; margin: 0 1em 1em 0; }
header address p { margin: 0 0 0.25em; }
header span, header img { display: block; float: right; }
header span { margin: 0 0 1em 1em; max-height: 25%; max-width: 60%; position: relative; }
header img { max-height: 100%; max-width: 100%; }
header input { cursor: pointer; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; height: 100%; left: 0; opacity: 0; position: absolute; top: 0; width: 100%; }

/* article */

article, article address, table.meta, table.inventory { margin: 0 0 3em; }
article:after { clear: both; content: ""; display: table; }
article h1 { clip: rect(0 0 0 0); position: absolute; }

article address { float: left; font-size: 125%; font-weight: bold; }

/* table meta & balance */

table.meta, table.balance { float: right; width: 36%; }
table.meta:after, table.balance:after { clear: both; content: ""; display: table; }

/* table meta */

table.meta th { width: 40%; }
table.meta td { width: 60%; }

/* table items */

table.inventory { clear: both; width: 100%; }
table.inventory th { font-weight: bold; text-align: center; }

table.inventory td:nth-child(1) { width: 26%; }
table.inventory td:nth-child(2) { width: 38%; }
table.inventory td:nth-child(3) { text-align: right; width: 12%; }
table.inventory td:nth-child(4) { text-align: right; width: 12%; }
table.inventory td:nth-child(5) { text-align: right; width: 12%; }

/* table balance */

table.balance th, table.balance td { width: 50%; }
table.balance td { text-align: right; }

/* aside */

aside h1 { border: none; border-width: 0 0 1px; margin: 0 0 1em; }
aside h1 { border-color: #999; border-bottom-style: solid; }

/* javascript */

.add, .cut
{
	border-width: 1px;
	display: block;
	font-size: .8rem;
	padding: 0.25em 0.5em;	
	float: left;
	text-align: center;
	width: 0.6em;
}

.add, .cut
{
	background: #9AF;
	box-shadow: 0 1px 2px rgba(0,0,0,0.2);
	background-image: -moz-linear-gradient(#00ADEE 5%, #0078A5 100%);
	background-image: -webkit-linear-gradient(#00ADEE 5%, #0078A5 100%);
	border-radius: 0.5em;
	border-color: #0076A3;
	color: #FFF;
	cursor: pointer;
	font-weight: bold;
	text-shadow: 0 -1px 2px rgba(0,0,0,0.333);
}



.add { margin: -2.5em 0 0; }

.add:hover { background: #00ADEE; }

.cut { opacity: 0; position: absolute; top: 0; left: -1.5em; }
.cut { -webkit-transition: opacity 100ms ease-in; }

tr:hover .cut { opacity: 1; }

#parent {
    list-style: none;
    width: 50%;
    height: 20px;
    margin: 5px;
    padding: 0;
    white-space: nowrap;
    font-weight:bold;
}

#parent > li {
    display: inline-block;
    width: 20%;
    height: 100%;
    
   
}



@media print {
	* { -webkit-print-color-adjust: exact; }
	html { background: none; padding: 72px; }
	body { box-shadow: none; margin: 0; }
	span:empty { display: none; }
	.add, .cut { display: none; }
}

@page { margin: 0; }


		</style>
<body>

<div class="limiter">
		<div class="container-table100" dir="rtl">
        <img src="images/bill.jpg"  width="100%" height="230px"/>
			<div class="row">


<ul id="parent" style="text-align:center;">

<!-- Centered Customer Info Section -->
<div style="text-align: center; margin: 30px -50px; font-weight: bold; font-size: 16px;" dir="rtl">
    <div style="display: inline-block; margin: 0 90px;">
        <span>اسم محصل: </span>
        <span>
            <?php
            $student_id = $_GET['student_id'];
            $student_name = "SELECT s_name FROM student WHERE s_id = ".$student_id;
            $student = $con->query($student_name);
            while($row = $student->fetch_array(MYSQLI_ASSOC)) {
                echo $row["s_name"];
            }
            ?>
        </span>
    </div>

    <div style="display: inline-block; margin: 0 -20px;">
        <span>نمبر ایدی: </span>
        <span>
            <?php
            echo $student_id = $_GET["student_id"];
            
            ?>
        </span>
    </div>
    <div style="display: inline-block; margin: 0 50px;">
        <span>بل نمبر: </span>
        <span>
            <?php
            $bill = $_GET["bill_no"];
            $qurey_bill = "SELECT bill_no FROM loan_r_details WHERE bill_no = ".$bill;
            $result_bill = $con->query($qurey_bill);
            while($row = $result_bill->fetch_array(MYSQLI_ASSOC)) {
                echo $row["bill_no"];
            }
            ?>
        </span>
    </div>

    

    <div style="display: inline-block; margin: 0 50px;">
        <span>تاریخ: </span>
        <span>
            <?php
            $qurey_date = "SELECT p_date FROM loan_r_details WHERE bill_no = ".$bill;
            $result_date = $con->query($qurey_date);
            while($row = $result_date->fetch_array(MYSQLI_ASSOC)) {
                echo $row["p_date"];
            }
            ?>
        </span>
    </div>
</div>

</ul>

</div>
<br><br>

				<div class="table100">
					<table dir="rtl">
                    
						<thead>
							<tr class="table100-head">
                            <th class="column1" style="width: 20px;">نمبر</th>
								<th class="column1" style="width: 50px;">صنف</th>
                                <th class="column1" style="width: 100px;">تایم</th>
                                <th class="column2">مبلغ فیس</th>
                                <th class="column2">تاریخ ثبت نام</th>
                                <th class="column2">تاریخ ختم ثبت</th>
								
                              

							</tr>
						</thead>
						<tbody>
								<tr>
						
                            	<?php
while($row=$r->fetch_array(MYSQLI_ASSOC))
{

	
	echo "<td>".$row["c_name"]."</td>";
    echo "<td>".$row["class_time"]."</td>";
    echo "<td>".$row["p_amount"]."</td>";
    echo "<td>".$row["start_date"]."</td>";
    echo "<td>".$row["end_date"]."</td>";

    
   
	echo "</tr>";
}
								?>
								</tr>
							
						</tbody>
                        <script>
    var tables = document.getElementsByTagName('tbody');
    var table = tables[tables.length -1];
    var rows = table.rows;
    for(var i = 0, td; i < rows.length; i++){
        td = document.createElement('td');
     td.appendChild(document.createTextNode(i + 1));
        rows[i].insertBefore(td, rows[i].firstChild);
    }
</script>
					</table>
       <br>
             <table>
                    <thead>
                        <tr class="table100-head">                 
                            
                            <th class="column2">پرداخت</th>
                            <th class="column3">باقی</th>
                        

                        </tr> 
                    </thead>
                    <tbody>
                            <tr>
                    <?php

                    $bill = $_GET["bill_no"];
                    $sql = "SELECT *  FROM loan_r_details WHERE bill_no = '$bill'";
                    $result = $con->query($sql);
                    while($row=$result->fetch_array(MYSQLI_ASSOC))
{ 
                                         
                       
                        echo "<td>".$row["p_received_amount"]."</td>";
                        echo "<td>".$row["p_borrow_amount"]."</td>";
                        echo "<tr>";
                        
                    }
                    ?>
                      
                            </tr>
                          
                
                    </tbody>
                </table>
                
                <br>
                <div style="font-weight:bold;" class="row">
                
                         <div class="form-group">    
                             <ul><li>
                            <div class="col-md-12">
                         
                        </div>
                        </li></ul>
                            </div>
                            <br>
                            <div class="form-group">
                                <ul>    <li>
                            <div class="col-md-12">
                          
                        </div>
                        </li></ul>
                            </div>
                            
</div>
<br>
                    <button id="printpagebutton" class="btn btn-danger" onclick="printpage()" style="
  @media print {
  #printPageButton {
    display: none;
  }
}">PRINT</button>
  
<script type="text/javascript">
    function printpage() {
        //Get the print button and put it into a variable
        var printButton = document.getElementById("printpagebutton");
        //Set the print button visibility to 'hidden' 
        printButton.style.visibility = 'hidden';
        //Print the page content
        window.print()
        //Set the print button to 'visible' again 
        //[Delete this line if you want it to stay hidden after printing]
        printButton.style.visibility = 'visible';
    }
</script>
<button class="btn btn-primary" id="back"  onclick="goBack()"></button>

<script>
function goBack() {
  window.location.href = 'view_student.php';
 


}
</script>
</body>
</html>


