
<meta charset="utf-8">

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

<html>

<head>
  
<?php

include "dbconfig.php";

//include "css_header.php";
include "head.php";
//Get the order data for this order.

$driver_id=$con->real_escape_string($_POST['driver_id']);
$from="";
	$to="";
	
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));
	}
	
$customer_sql = "SELECT bookings.id,bookings.pickup_date,bookings.pickup_address,company_contact.name as passenger,bookings.pickup_post_code,bookings.drop_address,bookings.drop_post_code,
customers.name as company,employees.first_name,
invoices.gross 
FROM bookings
LEFT JOIN customers ON bookings.customer_id=customers.id
LEFT JOIN company_contact on bookings.passenger_id=company_contact.id
LEFT JOIN invoices on bookings.invoice_no=invoices.invoice_no
LEFT JOIN employees on bookings.driver_id=employees.id
where employees.id=$driver_id 
AND bookings.pickup_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 ///////////////////
$driver = 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 $driver['first_name'];?></td></tr>
                     <thead>

                        <tr class="btn-primary">

                           <th>Job ID</th>
                           <th>Pickup Date</th>
                           <th>Company</th>
                           <th>Passenger</th>
                           <th>Pickup From</th>
                           <th>Post Code</th>
                           <th>Drop To</th>
						   <th>Post Code</th>
                           <th>Total Amount</th>

                        </tr>
					
                     </thead>

                     <tfoot>

                        <tr class="btn-primary">
                           <th>Job ID</th>
                           <th>Pickup Date</th>
                           <th>Company</th>
                           <th>Passenger</th>
                           <th>Pickup From</th>
                           <th>Post Code</th>
                           <th>Drop To</th>
						   <th>Post Code</th>
                           <th>Total Amount</th>

                        </tr>
						
                     </tfoot>

                     <tbody >

<?php
$total_amount=0;
while ($job = mysqli_fetch_assoc($result)) {
   $total_amount=$total_amount+number_format($job['gross'],2);
   ?>               
							
                        <td><?php echo $job['id']; ?></td>
                        <td><?php
                           $pickup_date = new DateTime($job['pickup_date']);

                           echo $pickup_date->format("d F, Y")
                           ?></td>
                        <td><?php echo $job['company']; ?></td>
                        <td><?php echo $job['passenger']; ?></td>
						<td><?php echo $job['pickup_address']; ?></td>
                        <td><?php echo $job['pickup_post_code']; ?></td>
						<td><?php echo $job['drop_address']; ?></td>
                        <td><?php echo $job['drop_post_code']; ?></td>
                        
					    <td><?php echo "£".number_format($job['gross'],2); ?></td>
                        </tr>

					

                        <?php
                     }
                     ?>



                     </tbody>
				<tr><td colspan="9" style="text-align:right; font-size:18; color:#F30A0E">Total Amount=<?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>