
<?php
echo 'not allowed'; die;
include 'get_user_info.php';

//  set default time format
date_default_timezone_set('Asia/Kolkata');      
$date=date("Y-m-d H:i:s");      //  for 24 hour

$id=$_REQUEST['take_user_id_wallet'];
$amount=$_REQUEST['take_amount'];
$main_id=$_REQUEST['take_user_id_wallet'];

//date_default_timezone_set('Asia/Kolkata');      
//$date=date("Y-m-d h:i:s");   //  for 12 hour
//$date=date("Y-m-d H:i");      //  for 24 hour
$transaction_id=get_unique_transaction_id();
$admin_total_balace=get_admin_total_balance();  //  to get admin total wallet balance
if($id=='B00001')
{
    $query ="insert into admin_wallet_details(wallet_user_id,receiver_amount,cr_dr,closer_amount,wallet_transaction_id,wallet_remarks,wallet_date)
        values('$id','$amount','cr','$admin_total_balace'+'$amount','$transaction_id','Add money to wallet','$date');";
}
$query .="insert into wallet(receiver_id,balance,sender_id,source,transaction_date,transaction_id,remarks,pending)
        values('$id','$amount','$main_id','admin','$date','$transaction_id','add wallet money','1'); ";
$query .="update wallet_balance set total_balance=total_balance+'$amount' where balance_user_id='$id' ";
$connection=mysqli_multi_query($conn,$query);
if($connection)
{
    
    echo '<script> alert("Amount added successfully"); window.location="add_money.php"; </script>';
}
else
{
    echo 'Not add';
}

function get_unique_transaction_id(){
       include 'include/db.php';
       $qr2="select MAX(transaction_id) from wallet LIMIT 1";
        $con2=mysqli_query($conn,$qr2);
        if(mysqli_num_rows($con2)>0)
        {
        	while($rw=mysqli_fetch_array($con2))
        	{
        		 $xyz=$rw['MAX(transaction_id)'];
        		 $aa=substr($xyz,2);
        		 $old_unique_id=intval($aa);  //  convert string to int
        	}
        	for ($num = $old_unique_id; $num <= $old_unique_id+1; $num++)
            $net_val=sprintf("%'.06d", $num);
            return 'WT'.$net_val;
        }
   }

?>