<?php
	session_start();
	if($_SESSION['mid'])
	{
		$userid=$_SESSION['mid'];
		$fdate=$_SESSION['fd'];
	    $tdate=$_SESSION['td'];
		$sum=$_SESSION['sm'];
	}
	else
	{
		header('location:../login.php');
	}
?>
<?php
	include'connection.php';
	date_default_timezone_get("asia/kolkata");
	$date=date("Y-m-d");
	$time=date("h:i:s A");
	$oldbalq="select * from wallet where Userid=$userid order by Id desc";
	$resultoldbal=mysqli_query($con,$oldbalq);
	$dataoldbal=mysqli_fetch_array($resultoldbal);
	$oldbal=$dataoldbal['Balance'];
	$newbal=$oldbal+$sum;
	
	$insertq="insert into wallet(Userid,Openingbalance,Credit,Remarks,Balance,Date,Time,Transactiontype)
	values('$userid','$oldbal','$sum','Add Commision For $fdate to $tdate','$newbal','$date','$time','Commission_Success')";
	if(mysqli_query($con,$insertq))
	{
		$updateq="update commwallet set Active='1' where Userid='$userid' and Date>='$fdate' and Date<='$tdate'";
		mysqli_query($con,$updateq);
		$quUpdateBal="update masterdis set Balance='$newbal' where Userid='$userid'";
		mysqli_query($con,$quUpdateBal);
		header('location:withdraw_commision.php');
	}
	

?>