<?php
session_name('mini_admin_session');
session_start();
error_reporting(0);
include('includes/dbconnection.php');
require_once('vendor/autoload.php'); // Include mPDF

use Mpdf\Mpdf;

use Dotenv\Dotenv;

// Load environment variables
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

$school_name = $_ENV['SCHOOL_NAME'];
$school_address = $_ENV['SCHOOL_ADDRESS'];
$logo =$_ENV['WEBSITE_LOGO'];
$prefix =$_ENV['Admission_prefix'];


?>
<div class="card-body">
  <?php
  $eid2=$_POST['edit_id'];
  $ret2=mysqli_query($con,"select * from  payment where id='$eid2'");
  while ($row=mysqli_fetch_array($ret2))
  {
    ?> 
<style>
	.flex{
		display: inline-flex;
		width: 100%;
	}
	.w-50{
		width: 100%;
	}

	.text-right{
		text-align:right;
	}
    
	table.wborder{
		width: 100%;
		border-collapse: collapse;
	}
	table.wborder>tbody>tr, table.wborder>tbody>tr>td{
		border:1px solid;
	}
	p{
		margin:unset;
	}

</style>
<div class="text-center">
<img src =<?=$logo?> alt = "logo" height="70" width ="70"><br>
<b><?=$school_name?></b><br>
<?=$school_address?>
</div>
	<hr>
    <div class="row">
		<div class="col-md-6">
            <p>Student Name: <b><?php  echo $row['studentName'];?></b></p>
			<p>Receipt No: <strong>R0000<?php echo $row['id'];?></strong></p>

			<p>Class: <b><?php  echo $row['class'];?> <?php  echo $row['section'];?></b></p>
		</div>
        <div class="col-md-6">
			<p>Payment Date: <b><?php  echo $row['payment_date'];?></b></p>
            <p>Payment For: <b><?php  echo $row['pay_for'];?></b></p>
			<p>Payment Status: <b>Paid</b></p>
			
		</div>
</div>
<hr>
<hr>
<div>
	<p class="text-center"><b>Payment Summary</b></p>
	<table class="wborder">
		<tr>
			<td>
				<p class ="text-center"><b>Fee Details</b></p>
				<hr>
				<table>
					<?php 
				$cfees = $con->query("SELECT * FROM payment where id = '$eid2'");
				$ftotal = 0;
				while ($row = $cfees->fetch_assoc()) {
					$ftotal += $row['amount'];
				?>
				
                <tr>
					<td>Recieved from <b><?php echo $row['studentName'] ?></b> the sum of <b><?php echo number_format($row['amount'])?></b> 
                Being paid for  <b><?php echo $row['pay_for'] ?></b> <b><?php echo $row['Term'] ?></b> <b><?php echo $row['session'] ?></b> academic session 
            </td>
				</tr>
				</table>
			</td>			
			<td width="50%">
			<p class = "text-center"><b>Payment Details</b></p>
				<table width="100%" class="wborder">
                    
					<tr>
						<td width="50%">Date</td>
						<td width="50%" class='text-right'>Amount</td>
					</tr>
					<tr>
						<td><b><?php echo $row['payment_date'] ?></b></td>
						<td class='text-right'><b><?php echo number_format($row['amount']) ?></b></td>
					</tr>
					
					<tr>
						<th>Total</th>
						<th class='text-right'><b><?php echo number_format($ftotal) ?></b></th>
					</tr>
				</table>
				<table width="100%">
					
					<tr>
						<td>Total Paid</td>
						<td class='text-right'><b><?php echo number_format($ftotal) ?></b></td>
					</tr>

				</table>
			</td>			
		</tr>
	</table>
	
            
    <div class = "text-center">
		
    <hr>
    <strong>&copy; <?=$school_name ?></strong>
    <hr>
                </div>
</div>
    <?php 
  } }?>
</div>