<?php
ob_start();
error_reporting(0);
include("connect.php");
session_start(); 
$ver = $_SESSION["admin_id"];
if(!isset($_SESSION["admin_id"])){
   header('location:http://www.btcover.appexperts.net');
}
date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
	$cdate1  = date("H:i:s");

$da  = date("Y-m-d H:i:s");
$transaction_id=$_POST['transaction_id'];
$ver = $_SESSION["manager_id"];

	$policy_no=$_POST['policy_no'];
	$uniqe_id=$_POST['unique_id'];
	$agent_id=$_POST['agent_id'];
	
	$received_amt=$_POST['received_amt'];
	$difference_amt=$_POST['difference_amt'];
	$status='Complete';
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
	$ctime=date('h:i:sa');
	$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',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`, `transaction_date`, `transaction_time`, `status`) VALUES ('$agent_id','$difference_amt','$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',update_datetime='$cdate' where unique_id='$unique_id' and status = 'Pending' "); 


		$response['success']='1';
		$response['details']="Insert Successful";			
	}
 header('Location:agent-pending-work.php'); 
?>