<?php
include "head.php";
include "dbconfig.php";
//include "css_header.php";
//Get the order data for this order.
$sql="SELECT * from transactions WHERE source_id=255";
$res=mysqli_query($con,$sql);
$p_sql="
SELECT * from passbook";
$p_res=mysqli_query($con,$p_sql);
$passbook=mysqli_fetch_assoc($p_res);
$current_balance=$passbook['current_bal'];
$d_sql="
SELECT id,name,SUM(balance) as total from creditors WHERE source_id=255";
$d_res=mysqli_query($con,$d_sql);
$passbook=mysqli_fetch_assoc($d_res);
$debtor_balance=$passbook['total'];

$cd_sql="SELECT id,name from customers where id=255";
$cd_res=mysqli_query($con,$cd_sql);
$debt_name=mysqli_fetch_assoc($cd_res);
$debtor_name=$debt_name['name'];

?>

<!docpayment_type html>
<html>
<head>
<head>
   
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.11/js/dataTables.bootstrap.min.js"></script>
<script payment_type="text/javascript">
	$(document).ready(function() {
    $('#example').DataTable();
} );
</script>
<meta charset="utf-8">
<title>Debtor Statement</title>
</head>

<body>
<div class="row">
    	<div class="col-sm-12" style="background-color:#F2F746">
        	<h1 style="" class="text-black text-center"> Statement of <?php echo $debtor_name;?></h1>
            
        </div>
    </div>
<div class="container">
	<div class="row">
    	<div class="col-md-12">
        <br>
<p style="font-size:26px; font-family:serif; color:#12A2CD;"> 
<?php if($debtor_balance<0){ echo 'Total Amount Recievable £'.number_format(-$debtor_balance,2);}
else{ echo 'Total Amount Payable £'.number_format($debtor_balance,2);}?>
</p>

<table id="example" class="table table-striped table-bordered warning" cellspacing="0" width="100%">
        <thead>
            <tr style="font-size:26px; font-family:serif;">
                   <th style="width:25%">Date</th>
                <th style="width:25%">Details</th>
                <th class="success" style="width:25%">Money In</th>
               <th style="width:25%">Money Out</th>

                
            </tr>
        </thead>
        <tfoot>
            <tr style="font-size:26px; font-family:serif">
            	
                 <th style="width:25%">Date</th>
                <th style="width:25%">Account</th>
                <th style="width:25%">Money In</th>
               <th style="width:25%">Money Out</th>

                
            </tr>
        </tfoot>
        <tbody >
        						<?php
                                    while($statement=mysqli_fetch_assoc($res))
									{
														
									?>
            <tr style="font-size:26px; font-family:serif;"  class="warning">
            
            <?php $date=date("Y-m-d",strtotime($statement['transaction_date']));?>
            
                <td    style="width:100px;"><?php echo $date;?></td>
               
                 
 				<td    style="width:100px;">
 					<?php 
					$money_in=0;
					$money_out=0;
					
 						if($statement['transaction_type'] == 'cr')
						{
 							//echo $clients[$statement['source_id']];
							$money_in=$statement['amount'];
 						}
 						else
 						{
 							//echo $candidates[$statement['source_id']];
							$money_out=$statement['amount'];
 						}?>
 				</td>
                <td class="success"    style="width:100px;"><?php echo $money_in;?></td>
                <td    style="width:100px;"><?php echo $money_out;?></td>
                
            </tr>
            
            
			<?php						
				}
								
				?>
            
            </tbody>
    </table>
    </div>
    </div>
    </div>
    
</body>
</html>