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

	$agent_id = $_REQUEST['agent_id'];
	$cdate11=$_REQUEST['cdate1'];
	$cdate22=$_REQUEST['cdate2'];
	$cdate1=date("Y-m-d", strtotime($cdate11) );
	$cdate2=date("Y-m-d", strtotime($cdate22) );
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
	$ctime = date('h:i:s');
	$cdate1 = isset($cdate1) ? $cdate1 : $cdate;
	$cdate2 = isset($cdate2) ? $cdate2 : $cdate;

	$select_premium = mysqli_query($con,"select * from tbl_customer_premium,tbl_policy_master where tbl_customer_premium.agent_id='$agent_id' and tbl_customer_premium.transaction_date>='$cdate1' and tbl_customer_premium.transaction_date<='$cdate2' and tbl_customer_premium.policy_no=tbl_policy_master.policy_no ORDER by transaction_id");

	$amount=0;
	if(mysqli_num_rows($select_premium)>0)
	{    
		while($fetch_details=mysqli_fetch_assoc($select_premium))
		{
			
		$vehicle_id=$fetch_details['vehicle_id'];
		$premium=$fetch_details['agent_received_amt'];
		$policy_date=$fetch_details['transaction_date'];
			
		$query = mysqli_query($con,"SELECT * from tbl_commission_type where tbl_commission_type.vehicle_id='$vehicle_id' order by tbl_commission_type.commission_id");
		
			if(mysqli_num_rows($query)>1)
			{
				while($fetch_percentage=mysqli_fetch_assoc($query)){
					
				 	$percentage=$fetch_percentage['percentage'];
					$start_date=$fetch_percentage['start_date'];
					$end_date=$fetch_percentage['end_date'];	
					if(strtotime($start_date) <= strtotime($policy_date) && strtotime($end_date) >= strtotime($policy_date)){
						 $amt = $premium * ((float)$percentage/100);
						 break;
					}
				}	
			}
			else
			{
				
				$fetch_percentage= mysqli_fetch_assoc($query);
				 $percentage=$fetch_percentage['percentage'];
				 $amt = $premium * ((float)$percentage/100);
			}
			 $amount=(float)$amount+(float)$amt;
			 $premium;
		
		}
	}

?>
<input class="form-control form-white" placeholder="Commission To Be Paid" id="paid" type="text" value="<?php echo number_format($amount,2,'.','');?>" name="to_be_paid" />
