<?php
include("../connect.php"); 
$response = array();
if(isset($_POST['transaction_id']) && isset($_POST['policy_no']) && isset($_POST['manager_id']) && isset($_POST['received_amt']))
{
	$ver = $_POST['manager_id'];
	$policy_no=$_POST['policy_no'];
	$new_policy_no=$_POST['new_policy_no'];
	$unique_id=$_POST['unique_id'];
	$agent_id=$_POST['agent_id'];
	$transaction_id=$_POST['transaction_id'];
	$received_amt=$_POST['received_amt'];
	$difference_amt=$_POST['difference_amt'];
	$status=$_POST['status'];
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
	$ctime=date('h:i:sa');

	if($new_policy_no==''){
		$new_policy_no = $policy_no;
	}

	$res_product_stock = mysqli_query($con,"SELECT transaction_id FROM  tbl_customer_premium where manager_id='$ver' and policy_no='$policy_no' and status='Pending' and transaction_id='$transaction_id'");

	if(mysqli_num_rows($res_product_stock)>0)
	{	
		$uq2=mysqli_query($con,"update tbl_customer_premium set status='$status' ,policy_no='$new_policy_no',agent_received_amt='$received_amt',complete_date='$cdate',complete_time='$ctime' where transaction_id='$transaction_id'"); 

		$query = mysqli_query($con,"INSERT INTO `tbl_agent_commission`(`agent_id`, `credit_amt`, `policy_no`, `transaction_date`, `transaction_time`, `status`) VALUES ('$agent_id','$difference_amt','$new_policy_no','$cdate','$ctime','Pending')");	

		$uq3=mysqli_query($con,"update tbl_policy_master set status='Renewed',update_datetime='$cdate' where unique_id='$unique_id' and status = 'Renewal Pending' "); 

		$uq4=mysqli_query($con,"update tbl_policy_master set status='Active',policy_no='$new_policy_no',update_datetime='$cdate' where unique_id='$unique_id' and status = 'Pending' "); 


		$response['success']='1';
		$response['details']="Insert Successful";			
	}
	else
	{
		$response['success']='0';
		$response['details']="Policy No Not exists";
	}
}
else
{
	$response['success']='0';
	$response['details']="Required field missing";
}	
echo json_encode($response);
?>