<?php
include("../connect.php"); 
$response = array();
if(isset($_POST['vehicle_type']) && isset($_POST['admin_id'])&& isset($_POST['start_date'])&& isset($_POST['end_date'])&& isset($_POST['percentage'])&& isset($_POST['percentage2'])&& isset($_POST['type'])&& isset($_POST['company_id']))
{
	$ver = $_POST['admin_id'];
	$c_name=$_POST['vehicle_type'];
	$company_id=$_POST['company_id'];
	$start_date=$_POST['start_date'];
	$end_date=$_POST['end_date'];
	$type=$_POST['type'];
	$percentage2=$_POST['percentage2'];
	$percentage=$_POST['percentage'];
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d")." ".date('h:i:sa');
	$res_product_stock = mysqli_query($con,"SELECT vehicle_type FROM  tbl_vehicle_master where vehicle_type='$c_name' and admin_id='$ver'  and company_id='$company_id'");
	if(mysqli_num_rows($res_product_stock)<=0)
	{									
		$query = mysqli_query($con,"INSERT INTO `tbl_vehicle_master`(`admin_id`,`vehicle_type`,`company_id`,`status`,`insert_datetime`)VALUES('$ver','$c_name','$company_id','Active','$cdate')");	
		$vehicle_id = mysqli_insert_id($con);

		$query = mysqli_query($con,"INSERT INTO `tbl_commission_type`(`admin_id`,`vehicle_id`,`type`,`percentage`,`percentage2`,`start_date`,`end_date`,`insert_datetime`)VALUES('$ver','$vehicle_id','$type','$percentage','$percentage2','$start_date','$end_date','$cdate')");	
		
		$response['success']='1';
		$response['details']="Insert Successful";			
	}
	else
	{
		$response['success']='0';
		$response['details']="Vehicle already exists";
	}
}
else
{
	$response['success']='0';
	$response['details']="Required field missing";
}	
echo json_encode($response);
?>