<?php 
ob_start();
include "head.php";?>
    <?php
	//include "dbfunction.php";
	include "dbconfig.php";
  $invoice_no =$_GET['invoice_no'];
  $sql="SELECT bookings.pickup_date,bookings.id AS booking_id,bookings.comments, bookings.parking,bookings.driver_id, bookings.drop_address,bookings.drop_post_code, bookings.waiting_charges,bookings.fare,bookings.total_fare,bookings.waiting_time, bookings.hours,bookings.mins,bookings.other,sum(bookings.total_fare) as Total,
customers.id AS customer_id, customers.name AS customer_name,customers.address1,customers.post_code,customers.city, customers.mobile, payment_type.name AS payment_type, employees.first_name AS driver, vehicles.make as vehicle, company_contact.name as company_contact,
invoices.invoice_no,invoices.nett,invoices.vat,invoices.gross,invoices.date as invoice_date
FROM 
bookings
LEFT JOIN invoices ON bookings.invoice_no=invoices.invoice_no
LEFT JOIN customers ON bookings.customer_id = customers.id 
LEFT JOIN payment_type ON bookings.payment_type = payment_type.id 
LEFT JOIN employees ON bookings.driver_id = employees.id 
LEFT JOIN vehicles ON bookings.vehicle_id = vehicles.id 
LEFT JOIN company_contact ON customers.id = company_contact.customer_id 
WHERE invoices.invoice_no=$invoice_no
GROUP BY bookings.id
";
// $customer_id=$_GET['company_id'];
//WHERE customers.id=$customer_id GROUP BY bookings.id
$res=mysqli_query($con,$sql);
$rowcount=mysqli_num_rows($res);
$client=mysqli_query($con,$sql);
$invoice=mysqli_fetch_assoc($client)
?>
    
<style>table{ table-layout:fixed; } table td{ word-wrap:break-word; width:30px; }</style>
</head>

<body>
<form method="post" action="create_reciept.php"> 
<div class="panel panel-primary col-md-10 col-md-offset-1" style="margin-top:20px;">
<div class="panel-heading">Sales Invoice</div>
  <div class="panel-body">
                          
                      <div class="col-md-12">
                      	<div class="col-md-3">
                                    <p><b> Limo Chauffeurs Ltd. </b></p>
                                        <p>12 Lampton Park Road, </p><p>Hounslow,</p>
                                             TW3 4HS</p>
                                    </div>
                          <div class="col-md-3">
                                        <p>Phone: +44 (0)7808939220<br>
                                            Email : info@limochauffeurs.com</p>
                                    </div>
                           <div class="col-md-3">
                           <p><b>Invoice To</b></p>
                                <p>
                                    <?php echo $invoice['customer_name'];?></p>
                                    <input type="hidden" name="customer_name" value="<?php echo $invoice['customer_name'];?>"/>
                                    <p>
                                    <?php 
									if($invoice['address1']==""){
										echo $invoice['address1'];
										}
										else
										{
									echo $invoice['address1'];
                                    }?></p>
                                    <input type="hidden" name="company_address1" value="<?php echo $invoice['address1'];?>"/>
                                    <p>
                                    <?php 
									if($invoice['city']==""){
										echo $invoice['city'];
										}
										else
										{
									echo $invoice['city'];
                                    }?>
                                    <input type="hidden" name="company_city" value="<?php echo $invoice['city'];?>"/>
                                    </p>
                                    <p>
									<?php 
									if($invoice['post_code']==""){
										echo $invoice['post_code'];
										}
										else
										{
									echo $invoice['post_code'];
									
                                    }?>
                                    <input type="hidden" name="company_post_code" value="<?php echo $invoice['post_code'];?>"/>
                                </p>
                            </div>
                            <div class="col-md-3 inv-label">
                        <p>Invoice No: <?php echo $invoice['invoice_no'];?> <br>
                        <input type="hidden" name="invoice_no" value="<?php echo $invoice['invoice_no'];?>"/>
                                            Date : <?php echo $invoice['invoice_date'];?></p>
                                  <input type="hidden" name="invoice_date" value="<?php echo $invoice['invoice_date'];?>"/>
                                </div>
                       </div>
                                               
                      
                     
                        
                       <table  style="font-family:Montserrat; font-size:13px;" id="invoice_table" class="table table-responsive list_jobs table-hover table-bordered table-striped table-info" cellspacing="0" border="1">

        <thead>
			
            <tr class="btn-primary" style="padding:10px;">
                           <th>Job ID</th>
                           <th>Pickup Date</th>
                           <th>Pickup Time</th>
                           <th>Passenger</th>
                           <th>Pickup From</th>
                           
                           <th>Drop To</th>
                            <th>Driver</th>
                           <th>Waiting Time</th>
                           <th style="text-align:right;">Waiting Charges</th>
                           <th style="text-align:right;">Parking</th>
                           <th style="text-align:right;">Fare</th>
                           <th style="text-align:right;">other</th>
                           <th style="text-align:right;">Total Fare</th>
                          
            </tr>

        </thead>

        <tfoot>

            <tr class="btn-primary">
                          <th>Job ID</th>
                           <th>Pickup Date</th>
                           <th>Pickup Time</th>
                           <th>Passenger</th>
                           <th>Pickup From</th>
                           
                           <th>Drop To</th>
                            <th>Driver</th>
                            <th>Waiting Time</th>
                            <th style="text-align:right;">Waiting Charges</th>
                           <th style="text-align:right;">Parking</th>
                           <th style="text-align:right;">Fare</th>
                           <th style="text-align:right;">other</th>
                           <th style="text-align:right;">Total Fare</th>

        </tfoot>

        <tbody>
        

        <?php

                while($job=mysqli_fetch_assoc($res))

                  {
					  //echo $job['payment_type'];
					  //exit;
					 ?>
                           <td><input name="booking_id[]" type="hidden" value="<?php echo $job['booking_id'];?>"><label><?php echo $job['booking_id'];?></label></td>
                           <td><input name="booking_date[]" type="hidden" value="<?php echo date("d/m/y", strtotime($job['pickup_date']));?>"><label><?php echo date("d/m/y", strtotime($job['pickup_date']));?></label></td>
                           
                           <td>
                            <input name="hours[]" type="hidden" value="<?php echo $job['hours'];?>">
                              <input name="mins[]" type="hidden" value="<?php echo $job['mins'];?>">
                               <label><?php echo $job['hours'].":".$job['mins'];?></label>
                           </td>
                           
                           <input type="hidden" name="customer_id" value="<?php echo $job['customer_id'];?>"/>
                           <td><input name="company_contact[]" type="hidden" value="<?php echo $job['company_contact'];?>"><label><?php echo $job['company_contact'];?></label></td>
                            <!-- Pickup Address -->
                           <td>
                             <input name="address1[]" type="hidden" value="<?php echo $job['address1'];?>">
                              <input name="city[]" type="hidden" value="<?php echo $job['city'];?>">
                               <input name="post_code[]" type="hidden" value="<?php echo $job['post_code'];?>">
                               
                              <label><?php echo $job['address1'].",".$job['city'].",".$job['post_code'];?></label>
                           </td>
                            <!-- Drop Address --> 
                           <td>
                             <input name="drop_address[]" type="hidden" value="<?php echo $job['drop_address'];?>">
                               <input name="drop_post_code[]" type="hidden" value="<?php echo $job['drop_post_code'];?>">
                               
                              <label><?php echo $job['drop_address'].",".$job['drop_post_code'];?></label>
                           </td>
                           <?php $booking_id=$job['booking_id'];?>
                           <td><input name="driver[]" type="hidden" value="<?php echo $job['driver'];?>"><label><?php echo $job['driver'];?></label></td>
                        
                          <td><input name="waiting_time[]" type="hidden" value="<?php echo $job['waiting_time'];?>"><label><?php echo $job['waiting_time'];?></label></td>
                          
                          <td style="text-align:right;"><input name="waiting_charges[]" type="hidden" value="<?php echo $job['waiting_charges'];?>"><label><?php echo "£".$job['waiting_charges'];?></label></td>
                          <td style="text-align:right;"><input name="parking[]" type="hidden" value="<?php echo $job['parking'];?>"><label><?php echo "£".$job['parking'];?></label></td>
                          <td style="text-align:right;"><input name="fare[]" type="hidden" value="<?php echo $job['fare'];?>"><label><?php echo "£".$job['fare'];?></label></td>
                          <td style="text-align:right;"><input name="other[]" type="hidden" value="<?php echo $job['other'];?>"><label><?php echo "£".$job['other'];?></label></td>
                          <td style="text-align:right;"><input name="total_fare[]" type="hidden" value="<?php echo $job['total_fare'];?>"><label><?php echo "£".$job['total_fare'];?></label></td>
                        
                                    <input type="hidden" id="selected_booking">
										</td>
       
                          
                 
              </tr>
   <?php } ?>
   		 </tbody>
			   </table>

  </div>
  
                            <div class="col-md-8 col-xs-7 payment-method">
                                <h4>Additional Notes:</h4>
                                  <p><?php echo $invoice['comments'];?></p>
                                <br>
                                <center>
                                <div class="col-md-4">
                       <i class="fa fa-print"></i>&nbsp;<a href="<?php echo "print_invoice.php?invoice_no=".$invoice_no;?>?" onclick="this.href+=new Date().getTime();return true;" class="btn btn-warning btn-sm" value="Print Invoice"/>Print Invoice</a>
                            <h5> Please only print if necessary, think about envoirnment</h5>
                      
                       </div>
                                <h3 class="inv-label itatic">Thank you for your business</h3>
                                </center>
                            </div>
                          <div class="col-md-4 col-xs-5 invoice-block pull-right">
                                <ul class="unstyled amounts">
                                    <li>Nett : <?php echo "£".$invoice['nett'];?></li>
                                    <li>VAT @ 20% : <?php echo "£".$invoice['vat'];?></li>
                                    <li class="grand-total">Gross Total : <?php echo "£".$invoice['gross'];?></li>
                                    <input name="gross" type="hidden" value="<?php echo $invoice['gross'];?>">
                                </ul>
                            </div>
                        
</div>
</form>


</body>
</html>
