<?php
		  	
			  include "../dbconfig.php";
			  
			  $x=0;
			  $booking_id=0;
			  $count=0;
			    $nett=$con->real_escape_string($_POST['nett']);
				
				$date=$con->real_escape_string($_POST['date']);
				$date = str_replace("/","-",$date);
	  $date = date("Y-m-d", strtotime($date));
				$percentage=$con->real_escape_string($_POST['percentage']);
				$percentage_amount=$con->real_escape_string($_POST['percentage_amount']);
				$commission=$con->real_escape_string($_POST['commission']);
				$gross=$con->real_escape_string($_POST['gross']);
				$driver_id=$con->real_escape_string($_POST['driver_id']);
				
			 $sql="INSERT INTO driver_invoices (date,driver_id,nett,percentage,percentage_amount,commission,gross,status) VALUES('".$date."','".$driver_id."','".$nett."','".$percentage."','".$percentage_amount."','".$commission."','".$gross."','2')"; 
			if (!mysqli_query($con,$sql)) {echo $sql."Error is ". mysqli_error($con);}
			$invoice_no = $con->insert_id;
			
			$sql='';
			    $count=count($_POST['booking_id']);
			    for ($x = 0; $x < $count; $x++) {
				$booking_id=$con->real_escape_string($_POST['booking_id'][$x]);
				
				$date=date("Y-m-d");
				
				$sql="INSERT INTO driver_invoice_details (booking_id,invoice_no) VALUES(".$booking_id.",".$invoice_no.")";
			    if (!mysqli_query($con,$sql)) {echo $sql."Error is ". mysqli_error($con);}
				
				}//for loop",
			 	echo 'success';
			 
		  ?>
