<?php 
include '../config.php';

$member_id = $_POST['member_id'];
$amount = $_POST['amount'];

$date_transection = $date;


$msql = "SELECT * FROM member_wallet WHERE member_id='$member_id' ";
$mquery = mysqli_query($conn, $msql);
if ($mrow = mysqli_fetch_array($mquery)) {
	$mbalance = $mrow['member_wallet_balance'];
}

$balance = $mbalance - $amount;

if ($balance >= '0') {

	$usql = "UPDATE member_wallet SET member_wallet_balance='$balance' WHERE member_id='$member_id'";
		if(mysqli_query($conn,$usql)){
			$num = rand(10000,100000);
			$pre = "WDR";

			$trans = $pre.$num.$member_id;

			$msql = "INSERT INTO wallet_transaction(transaction_id, transaction_amount, member_id, transaction_update_date, transaction_type) VALUES ('$trans','$amount','$member_id','$date_transection','WithdrawAmt')";
			if (mysqli_query($conn, $msql)) {
				$response=["status"=>'success',"newbalance"=>$balance,"transaction_id"=>$trans,"status"=>'Processing'];
			}
		}else {
			$response=["status"=>'Failure']; 
		}

}else {
	$response=["status"=>'Low Wallet Balance']; 
}
echo json_encode($response);

?>
