<?php
include("../connect.php"); 
$response = array();
if(isset($_POST['vehicle_id']) && isset($_POST['admin_id']) && isset($_POST['percentage'])&& isset($_POST['percentage2']) && isset($_POST['type'])&& isset($_POST['start_date'])&& isset($_POST['end_date']))
{
	$ver = $_POST['admin_id'];
	$vehicle_id=$_POST['vehicle_id'];
	$start_date=$_POST['start_date'];
	$end_date=$_POST['end_date'];
	$percentage=$_POST['percentage'];
	$percentage2=$_POST['percentage2'];
	$type=$_POST['type'];
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d")." ".date('h:i:sa');
									
		$select_product = mysqli_query($con,"SELECT * FROM `tbl_commission_type` WHERE vehicle_id = '$vehicle_id' ORDER by commission_id desc limit 1");

	if(mysqli_num_rows($select_product)>0)
	{     $row = mysqli_fetch_assoc($select_product); 

		  $commission_id  = $row['commission_id'];
		  $end_dt = date('Y-m-d', strtotime('-1 day', strtotime($start_date)));
		$uq2=mysqli_query($con,"update tbl_commission_type set end_date='$end_dt' where commission_id='$commission_id'"); 
	}
	
		$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']="Required field missing";
}	
echo json_encode($response);
?>