<?php
@session_start();
include "control/activity.php";
$dd = new activity();

$am = $_REQUEST['am'];
$type = $_REQUEST['type'];
$payId = $_REQUEST['payId'];
$userKey = $_REQUEST['userKey'];
$date = date("H:i d/m/Y");


if($type == "approved")
{
    $table = "balance_withdraw";
    $value = "payment_status='success',sending_date='$date'";
    $condition = " withdraw_key='$payId'";
    $result = $dd->updateData($table,$value,$condition);
    if($result){
        $table = "userdetails";
        $value = "twithdraw=twithdraw+$am";
        $condition = " userKey='$userKey'";
        $result = $dd->updateData($table,$value,$condition);
        if($result){
            echo "<script>window.open('withdrawReport.php','_self')</script>";
        }
    }
}



if($type == "rejected")
{
    $table = "balance_withdraw";
    $value = "payment_status='rejected',sending_date='$date'";
    $condition = " withdraw_key='$payId'";
    $result = $dd->updateData($table,$value,$condition);
    if($result){

         $table = "balance_withdraw";
         $condition = " where withdraw_key='$payId'";
         $getRefundsBalance = $dd->single($table,$condition)['amounnt'];


         $table = "userdetails";
         $value = "wallet=wallet+$getRefundsBalance,withdraw_balance=withdraw_balance+$getRefundsBalance";
         $condition = " userKey='$userKey'";
         $result = $dd->updateData($table,$value,$condition);
         if($result)
         {
            echo "<script>window.open('withdrawReport.php','_self')</script>";
         }
    }
}


?>