<?php
	include'connection.php';
	$id=$_GET['id'];
	date_default_timezone_set("asia/Kolkata");
	$date= Date("Y-m-d");
	
	$query="select * from recharge where Id=$id";
	$result=mysqli_query($con,$query);
	$data=mysqli_fetch_array($result);
	
	$userid=$data['Userid'];
	
	$debitamount=$data['Debitamount'];
	$ewalletid=$data['Ewalletid'];
	
	$query1="select * from wallet where Userid=$userid order by Id desc";
	$result1=mysqli_query($con,$query1);
	$data1=mysqli_fetch_array($result1);
	$oldbal=$data1['Balance'];
	$newbal=$oldbal-$debitamount;
	
	$query2="insert into wallet(Userid,Openingbalance,Debit,Balance,Date,Time,Transactiontype,Paynrechid,Operator,Mobile,Amount,Status)
	values('$userid','$oldbal','$debitamount','$newbal','$date','$time','Recharge-Resuccess','$id','$oper','$mobile','$amount','SUCCESS')";
	
	if(mysqli_query($con,$query2))
	{
		$query3="select * from wallet where Userid='$userid' order by Id desc";
		$result3=mysqli_query($con,$query3);
		$data3=mysqli_fetch_array($result3);
		$cewalletid=$data3['Id'];
		
		$query4="update recharge set Creditewalletid='$cewalletid', Balance='$newbal', Status='SUCCESS' where Id='$id' ";
		mysqli_query($con, $query4);
		$query12="update retailer set Balance='$newbal' where Userid='$userid'";
		mysqli_query($con,$query12);
		header('location:admin_recharge_history.php');
	}

?>