<?php  
session_start();
require_once '../../includes/conn.php';
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/table_data_center_with_border_black.css">
</head>
<body>

<div class="container" style="width:100%;">
 <br>
 <center>
<?php
				   $pq=mysqli_query($con,"select * from stuff left join `user` on user.userid=stuff.userid where stuff.userid='".$_SESSION['id']."'");
				   while($pqrow=mysqli_fetch_array($pq)){
				?>
			    <span style="font-size:21;font-weight:bold;">
			  <?php echo $pqrow['business_name']; ?><br>
				 </span> 
				   <?php }?>
  <span style="font-size:20;">        
Student Statement Report ( Single ) <br>
</span> 
<span style="font-size:19;"> 
			
			<?php
				   $CustId = $_POST['CustId'];
				   $pq=mysqli_query($con,"select distinct customer_id,client_name,client_contact from orders  WHERE customer_id = '$CustId' ");
				   while($pqrow=mysqli_fetch_array($pq)){
				?>
				
			      Student Id :  <?php echo $pqrow['customer_id']; ?> , 
			      Name :  <?php echo $pqrow['client_name']; ?>,
			      Phone :  <?php echo $pqrow['client_contact']; ?>
				  
				   <?php }?>
				   
	
<br>
Date : <?php echo date("M d, Y") ;?> | 
Time   : <?php date_default_timezone_set("Asia/Dhaka"); echo  date("h:i:sa");?>  
		  </span> </center>  
<br>

<?php  
if($_POST) {
    
	$CustId = $_POST['CustId'];
	
	$sql = "SELECT * FROM orders_details 
	Left JOIN stuff ON stuff.userid = orders_details.user_id
	WHERE orders_details.customer_id= '$CustId' 
	order by orders_details.id desc";
	$query = $con->query($sql);
	$countOrder = $query->num_rows;
	

	$table = '
	<table border="1" class="table table-bordered" style="width:100%;">
       
		
		<tr>
			<th>SL </th>
			<th>Date </th>
            <th>Invoice </th>			
			<th>Pre.Due</th>			 
			<th>Collection</th> 
			<th>Rec. Dues </th>
			<th>Coll. By </th>
			<th>Causes </th>
		</tr>
		
		<tr>';
		
		$sl=0;
		$TodayTotal = 0;
		$TotalCollection = 0;
				
		while ($result = $query->fetch_assoc()) {
			$table .= '<tr>
			    <td><center>'.++$sl.'</center></td>
				<td><center>'.date("M d,Y", strtotime($result['order_date'])).'</center></td>
				<td><center>'.$result['custom_invoice'].'</center></td>
				<td><center>'.$result['pre_due'].'</center></td>
				<td><center>'.$result['paid'].'</center></td>				
				<td><center>'.$result['recent_due'].'</center></td>
				<td><center>'.$result['stuff_name'].'</center></td>
				<td><center>'.$result['cuses'].'</center></td>
			</tr>';	
			
			$TodayTotal+= $result['today_total'];
			$TotalCollection+= $result['paid'];
			
		}
		$table .= '
		</tr>
        
		<tr>
			<td colspan="10" style="text-align:right; "><center><b>
  			     
			  Total Collection = '.$TotalCollection.' 
			
			</b></center></td>
						
		</tr>
		
	</table>
	';	

	echo $table;

}

?>
 
</body>
</html>
