
<meta charset="utf-8">

<title>List of Orders</title>
<!doctype html>

<html>

<head>
  
<?php
include "head.php";
include "dbconfig.php";
    $from="";
	$to="";
	$customer_id=$_POST['customer_id'];
	if (!empty($_POST['from']))
	{
	  $from=$con->real_escape_string($_POST['from']);
	  $from = str_replace("/","-",$from);
	  $from = date("Y-m-d", strtotime($from));
	}
	if (!empty($_POST['to']))
	{
	  $to=$con->real_escape_string($_POST['to']);
	  $to = str_replace("/","-",$to);
	  $to = date("Y-m-d", strtotime($to));
	}
//print_r($_POST);
//include "head.php";


$customer_id=$con->real_escape_string($_POST['customer_id']);

$customer_sql = "SELECT payments_recieved.date,payments_recieved.amount,payments_recieved.comments, customers.name FROM payments_recieved
JOIN customers on payments_recieved.customer_id=customers.id
WHERE customers.id=$customer_id AND payments_recieved.date BETWEEN '$from' AND '$to'";
//echo $customer_sql;
//exit;
$result = mysqli_query($con, $customer_sql);
$result1 = mysqli_query($con, $customer_sql);
/////////// we extract the variable for writing customer name ///////////////////
$customer = mysqli_fetch_assoc($result1)
?>
<style>
table#invoices tbody  tr {
    cursor : pointer;
}
 </style>
 </head>

<body style="font-family:Montserrat; font-size:13px;">

               
      <div class="col-md-12" style="margin-top:50px;">
      
         <table id="customers" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<tr><td colspan="9" style="text-align:center; font-size:25; color:#F30A0E">Statement of <?php echo $customer['name'];?></td></tr>
                     <thead>

                        <tr class="btn-primary">

                           <th>Date</th>
                           <th>Amount</th>
                            <th>Comments</th>
                        </tr>
					
                     </thead>
                     <tfoot>

                        <tr class="btn-primary">
                          <th>Date</th>
                           <th>Amount</th>
                           <th>Comments</th>

                        </tr>
						
                     </tfoot>

                     <tbody >

<?php
$total_amount=0;
while ($job = mysqli_fetch_assoc($result)) {
   
   ?>               
<tr>
                        
                        <td><?php
                           $pickup_date = new DateTime($job['date']);

                           echo $pickup_date->format("d F, Y")
                           ?></td>
                        <td><?php echo "£".number_format($job['amount'],2); ?></td>
						 <td><?php echo $job['comments']; ?></td>
                        </tr>



                        <?php
   						$total_amount=$total_amount+ $job['amount'];
						//echo $total_amount;
                     }
                     ?>



                     </tbody>
<tr><td colspan="9" style="text-align:right; font-size:18; color:#F30A0E">Total Amount Recieved=<?php echo "£".number_format($total_amount,2);?></td></tr>

                  </table>

    </div>


<script type="text/javascript">

  $(document).ready(function() {
    $('#customers').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5',
			'print'
			        ]
    } );
} );

</script>


</body>
</html>