
<meta charset="utf-8">

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

<html>

<?php 

include "head.php";
include "dbconfig.php";

?>
  
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<style>
table#invoices tbody  tr {
    cursor : pointer;
}
#jobs_modal .modal-dialog
{
  width: 90%;
}
 </style>
 

<body style="font-family:Montserrat; font-size:13px;"> 
<div class="col-md-12 well" style="text-align:center;">
<center>
<label style="font-size:30px;"> Driver Statement
</label>
 <form name="invoice_filter" action="report_driver_jobs.php" method="post">
    <input type="hidden" name="filter_search" value="yes">
    

        <center>
              <div class="form-group col-md-3">
                        <select name="driver_id" id="customer" class="form-control">
			       	   	 <option style="padding:10px; background-color:#E7D91E; color:#F9F0F1; cursor:pointer;" value="">Select a Driver </option>
                               <?php
							   
							        $customers_sql="SELECT * from employees order by first_name ASC";
									$t_result=mysqli_query($con,$customers_sql);
									while($customer=mysqli_fetch_assoc($t_result))
									{
									
									?>
	<option style="padding:20px; background-color:#2977C9; color:#F9F0F1; cursor:pointer;" value="<?php echo $customer['id']; ?>">
	   <?php echo $customer['first_name']; ?>
    </option>
						<?php
						
						}
						?>
			       	   </select>
			       	   </div>
        <div class="col-md-2">
         <div class="form-group">
                      
 <input type="text" name="from" class="from form-control" placeholder="Date From" id="from">
             
         </div>
        </div>
       <div class="col-md-2">
         <div class="form-group">
                      
 <input type="text"  name="to" class="to form-control" placeholder="Date To" id="to">
             
         </div>
        </div>
 
       
</center>
<div class="col-md-1">
<input type="submit" id="filter_invoice" class="btn btn-sm btn-info pull-left" value="Search Jobs"/>
</div>

      </form>
      </center>
</div>	  
	  <?php
	  $sql='';
if(isset($_POST['from'])&&isset($_POST['to']))
{
$from=$_POST['from'];
$to=$_POST['to'];
$driver_id=$_POST['driver_id'];


if($from==''){
	$from='2017-01-01';}
	if($to==''){
	$to='2019-01-01';}
	
$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'
order by employees.id DESC";

?>

<?php
$driver_res=mysqli_query($con,$sql);
$driver_result=mysqli_fetch_assoc($driver_res);
$res=mysqli_query($con,$sql);

//echo $sql;
?>
       <div class="container-fluid" style="font-size:18px; margin-left:5px; margin-bottom:10px;background-color:#A9E3F1; padding:5px;">
<label><h2>Statement of <?php echo $driver_result['first_name'];?></h2></label>
       <table id="customers" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                     <thead>

                        <tr class="btn-primary">

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

                        </tr>
					
                     </thead>

                     <tfoot>

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

                        </tr>
						
                     </tfoot>

                     <tbody >

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

                           echo $pickup_date->format("d F, Y")
                           ?></td>
                        <td><?php echo $driver_data['passenger']."<br> Company-".$driver_data['company']; ?></td>
						<td><?php echo $driver_data['pickup_address']."<br>".$driver_data['pickup_post_code']; ?></td>
						<td><?php echo $driver_data['drop_address']."<br>".$driver_data['drop_post_code']; ?></td>
                        
					    <td><?php echo "£".number_format($driver_data['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>
      </div>
<div class="modal fade bd-example-modal-lg custom-class" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="jobs_modal">

</div><!-- /.modal -->
</form>
<?php }
?>
<?php

 if(isset($_POST['selected_invoice']))
			{
		
		/*	
			echo "<pre>";
  				 print_r($_POST);
			echo "</pre>";
		*/	
		$bookingIds = $_POST;
		
		$count=count($_POST['selected_invoice']);
		
		for ($i=0;$i<$count;$i++){
			$counter=1+$i;
			$index = array_search($_POST['selected_invoice'][$i] ,$bookingIds['invoice_no']);
			//echo "index=".$index;
		$status=$con->real_escape_string($_POST['status']);
		$date=$con->real_escape_string($_POST['date']);
		$invoice_no=$bookingIds['invoice_no'][$index];
		
		$update_booking="UPDATE invoices SET
					  status=$status,
					  pay_date='$date'
				  
					  WHERE invoice_no=$invoice_no";
					  //echo $update_booking;
					  if (!mysqli_query($con,$update_booking)) {
							echo $update_booking;
							die('update 3 INTO Bookings -Error: ' . mysqli_error($con));
							exit;
						 }
		}
	}
?>
<?php
if(isset($_POST['print_invoices']))
{
$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'
order by employees.id DESC";

include "pdf_demo/fpdf.php";
class PDF extends FPDF
{
function Header()
{
	$this->SetY(5);  
    $this->SetFont('Arial', 'B', 20); 
    $this->SetFillColor(0,0,125); 
    $this->SetTextColor(225); 
    $this->Cell(0, 10, "Driver Statement", 0, 0, 'L', true); 
	
    $this->SetTextColor(0);
    $this->SetFont('Arial', '', 12); 
	$this->Ln(10);
	$this->Cell(100, 10, "Limo Chauffers Ltd.,",0,1);
	$this->SetY(20);
	$this->Cell(100, 10, "12 Lampton Park Road,",0,1);
    $this->SetY(25);;
	$this->Cell(100, 10, "Hounslow,",0,1);
    $this->SetY(30);
	$this->Cell(100, 10, "Middlesex",0,1);
	$this->SetY(35);
	$this->Cell(100, 10, "TW3 4HS ",0,1);
	 $this->SetY(40);
	$this->Cell(100, 10, "United Kingdom ",0,1); 

	$this->SetXY(115,15);   
    $this->SetTextColor(0); 
 	$this->SetFont('Arial', '', 10); 
	$this->Cell(100, 10, "Phone: (0)2082304594",0,1);
	$this->Ln(8);
	$this->SetXY(115,20);   
	$this->Cell(100, 10, "Mobile:(0)7808939220,",0,1);
	$this->Ln(8);
	$this->SetXY(115,25);
	$this->Cell(100, 10, "Email: info@limochauffeurs.com",0,1);
	$this->Ln(3);
	$this->SetXY(115,30);
	
	$this->Cell(100, 10, "Website: www.limochauffeurs.com");
	$this->SetFont('Arial', 'B', 11); 
	$this->Ln(3);
	$this->SetXY(115,35);
	
	$this->Cell(100, 10, "VAT No: 1234569898");
	// Set up the Invoice To Data
}
 //footer
 function Footer() { 
    $this->SetFont('Arial', '', 10); 
    $this->SetTextColor(0); 
    $this->SetY(-15);
	$this->Cell(0, 20, "Limo Chauffeurs Ltd", 'T', 1, 'C');
    
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 
	
	//$this->Image('footer.JPG',0,750,620,50); 
}
}
	  
	  $pdf=new PDF();
	  define('£',chr(163));
	  //Add first page
	  $pdf->AddPage('L');
	  $pdf->SetFont( 'Arial', '', 20 );
	 $y_axis_initial = 50;

$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(10);

		$pdf->Cell(20, 6, 'Sr.No.', 1, 0, 'L', 1);
        $pdf->Cell(30, 6, 'Pickup Date', 1, 0, 'L', 1);
		$pdf->Cell(60, 6, 'Passenger.', 1, 0, 'L', 1);
		$pdf->Cell(60, 6, 'Pickup From', 1, 0, 'R', 1);
        
        $pdf->Cell(60, 6, 'Drop To', 1, 0, 'L', 1);
		$pdf->Cell(30, 6, 'Total Amount', 1, 0, 'L', 1);
		

$row_height = 6;
$y_axis = 50;
$y_axis = $y_axis + $row_height;
//echo $sql;
//exit;
$report=mysqli_query($con,$sql);

//initialize counter
$i = 0;

//Set maximum rows per page
$max = 25;

//Set Row Height

 $No = 0;
while($row = mysqli_fetch_array($report))
{
    
	//If the current row is the last one, create new page and print column title
    if ($i == $max)
    {
        $pdf->AddPage('L');

        //print column titles for the current page
        $pdf->SetY($y_axis_initial);
        $pdf->SetX(25);
		$pdf->Cell(20, 6, 'Sr.No.', 1, 0, 'L', 1);
        $pdf->Cell(30, 6, 'Pickup Date', 1, 0, 'L', 1);
		$pdf->Cell(60, 6, 'Passenger.', 1, 0, 'L', 1);
		$pdf->Cell(60, 6, 'Pickup From', 1, 0, 'R', 1);
        
        $pdf->Cell(60, 6, 'Drop To', 1, 0, 'L', 1);
		$pdf->Cell(30, 6, 'Total Amount', 1, 0, 'L', 1);
        

        //Go to next row
        $y_axis = $y_axis + $row_height;

        //Set $i variable to 0 (first row)
        $i = 0;
    }
	    
    $No = $No +1;
	$pickup_date = $row['pickup_date'];
	$pickup_date =date("d/m/Y",strtotime($pickup_date));
	$passenger = $row['passenger'];
    $company = $row['company'];
    $pickup_address = $row['pickup_address'];
    $pickup_post_code = $row['pickup_post_code'];
    $drop_address = $row['drop_address'];
    $drop_post_code = $row['drop_post_code'];
    $gross = number_format($row['gross'],2);
	
    $pdf->SetY($y_axis);
    $pdf->SetX(10);
	$pdf->Cell(20, 6, $No, 1, 0, 'L', 1);
	$pdf->Cell(30, 6, $pickup_date, 1, 0, 'L', 1);
    $pdf->Cell(60, 6, $passenger, 1, 0, 'L', 1);
	$pdf->Cell(60, 6, $pickup_address.", ".$pickup_post_code , 1, 0, 'R', 1);
		$pdf->Cell(60, 6, $drop_address.", ".$drop_post_code , 1, 0, 'R', 1);

    $pdf->Cell(30, 6, £.$gross, 1, 0, 'R', 1);
    

    //Go to next row
    $y_axis = $y_axis + $row_height;
    $i = $i + 1;
	
	$total_gross =number_format($total_gross+$gross,2);
}
$pdf->SetFillColor(0,0,255);
$pdf->SetTextColor(255,255,255);
$pdf->SetFont( 'Arial', '', 15);
$pdf->SetXY(210,$y_axis);
$pdf->Cell(30, 6, "Totals", 1, 0, 'R', 1);

$pdf->SetXY(240,$y_axis);
$pdf->Cell(30, 6, £.$total_gross, 1, 0, 'R', 1);

//Create file
$file_name="Driver-Booking-Report-on ".date("d-m-Y").".pdf";
ob_clean();

$pdf->Output($file_name,'D');

}
?>
<script>
/* data string to send for printing report
 $('#print_invoices').click(function(){
	 
 var query = $('#query_value').val();
 
 
			  	
                var dataString = 'query=' + query;
               alert(dataString);
				
                $.ajax({
                    type: "POST",
                    url: "ajax/generate_invoice_report.php",
                    data: dataString,
                    success: function(data) {
                    // alert(data);
					 //console.log(data); 
					 
                }
            });
	   
	        
});
*/

</script>


<script type="text/jscript">
$('.date').datepicker({
	
    	onSelect: function() {
			
                $( ".date" ).datepicker( "option", "dateFormat","yy-mm-dd");
		
        }
        });
$('.from').datepicker({
	
    	onSelect: function() {
			
                $( ".from" ).datepicker( "option", "dateFormat","yy-mm-dd");
		
        }
        });
$('.to').datepicker({
	
    	onSelect: function() {
			
                $( ".to" ).datepicker( "option", "dateFormat","yy-mm-dd");
		
        }
        });
		
		
$(".invoices").find('td[data-id]').on('click', function () {
	
	////alert("Demo");
	var selected_col=$(this).attr('col-id');
	
	if(selected_col=='6')
	{
			var invoice_no=$(this).attr('data-id');
			var dataString = 'invoice_no='+invoice_no;
			 //alert(dataString);
			 var url11 = '"ajax/list_invoice_jobs.php?'+new Date().getTime();
			  $.ajax({
				  type: "POST",
			  url: url11,
			  data: dataString,
			  success: function(data) {
				  //alert(data);
				  $('#jobs_modal').html(data);
				  
				  $('#jobs_modal').modal('show');
				  }
			  });
	}
});
</script>

</body>
</html>