<?php
include "control/activity.php";
$dd = new activity();
@$userKey = $_SESSION['loginKey'];

$amnt = $_REQUEST['amnt'];

if($amnt=="")
{
    print_r(json_encode(array("status" => "failed","remark" => "Field Required")));
}
else{
    $table = "userdetails";
    $condition = " where userKey='$userKey' AND invitation_bonus < $amnt";
    $getBackUser = $dd->check($table,$condition);
    if($getBackUser['status'] == "success"){
    $value = "wallet=wallet+$amnt,invitation_bonus=invitation_bonus+$amnt";
    $condition = " userKey='$userKey'";
    $result = $dd->updateData($table,$value,$condition);
    if($result){
        $date = date("h:i d/m/Y");
        $ref = mt_rand(1111111111,9999999999);
        $table = "funds_request";
        $value = "(`userKey_id`, `request_date`, `request_type`, `amount`, `refrence_number`, `funds_status`, `approved_date`, `avl_balance`, `remark`) 
        SELECT '$userKey','$date','INR','$amnt','$ref','success','$date',wallet,'Balance credit for Refral : $amnt' FROM userdetails WHERE userKey='$userKey'";
        $result = $dd->insertData($table,$value);
        if($result){
            print_r(json_encode(array("status" =>  "success","remark" => "Congratulations balance Receivd : $amnt")));
        }
      }
    }else{
        print_r(json_encode(array("status" =>  "failed","remark" => "Already Excute..!!")));
    }
}


?>