<?php
		  	
			  include "../dbconfig.php";
			  //print_r($_POST);
			  $x=0;
			  $booking_id=0;
			  $count=0;
			    $nett=$con->real_escape_string($_POST['nett']);
				$date=$con->real_escape_string($_POST['date']);
				$vat_p=$con->real_escape_string($_POST['vat_p']);
				$vat=$con->real_escape_string($_POST['vat']);
				
				$date=$con->real_escape_string($_POST['date']);
				$date = str_replace("/","-",$date);
	  $date = date("Y-m-d", strtotime($date));
				
				$gross=$con->real_escape_string($_POST['gross']);
				$company_id=$con->real_escape_string($_POST['company_id']);
				
			 $sql="INSERT INTO invoices (date,customer_id,nett,vat,gross,status) VALUES('".$date."','".$company_id."','".$nett."','".$vat."','".$gross."','2')"; 
			//echo $sql;
			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 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';
			 
		  ?>
