| Current Path : /home2/wtmwscom/public_html/member/ |
| Current File : /home2/wtmwscom/public_html/member/payout_model.php |
<?php
session_start();
include('../connection.php');
include '../function_lib.php';
if(empty($_SESSION['userid'])){
redirect('./login.php');
die;
}
$provide_help_amount_array = array(2=>1000, 3=>2000, 4=>3000, 5=>5000, 6=>10000, 7=>20000, 8=>30000, 9=>40000, 10=>50000, 11=>100000);
$uid = $_SESSION['userid'];
$query = mysqli_query($connection, "SELECT plan_type FROM user where uid = '$uid'");
$row = mysqli_fetch_object($query);
$amount = tres($_POST['amount']);
$wallet_row = mysqli_fetch_object(mysqli_query($connection, "SELECT SUM(remaining_amount) AS wallet FROM transaction WHERE uid='$uid' AND status='1' AND remaining_amount > '0' AND txn_mode='0' "));
$wallet = !empty($wallet_row->wallet) ? $wallet_row->wallet : 0;
if($amount<=$wallet && $amount == $amount && ($amount % $amount == 0)){
// otp_authenticate("account.php");
$datetime = date('Y-m-d H:i:s');
$total_remaining_amount=0;
$result_income = mysqli_query($connection, "SELECT id, remaining_amount FROM transaction WHERE uid='$uid' AND status='1' AND remaining_amount > '0' AND txn_mode='0' ORDER BY datetime ASC ");
while ($row_income = mysqli_fetch_object($result_income)) {
$income_id = $row_income->id;
$remaining_amount = $row_income->remaining_amount;
$total_remaining_amount += $remaining_amount;
if($total_remaining_amount < $amount){
mysqli_query($connection, "UPDATE transaction SET remaining_amount = '0' WHERE id='$income_id' ");
} else if ($total_remaining_amount == $amount) {
mysqli_query($connection, "UPDATE transaction SET remaining_amount = '0' WHERE id='$income_id' ");
break;
} else if ($total_remaining_amount > $amount) {
$remaining_amount_diff = $total_remaining_amount - $amount ;
mysqli_query($connection, "UPDATE transaction SET remaining_amount = '$remaining_amount_diff' WHERE id='$income_id' ");
break;
}
}
//$service_tax = $amount *0;
//$tds = ($wallet * $master_tds_rate)/100;
$tds = 0;
$service = ($amount * $master_service_rate)/100;
$net_amount = $amount - ($tds + $service);
// mysqli_query($connection, "update user set wallet = wallet - '$amount' where uid = '$uid'");
mysqli_query($connection, "insert into withdraw(uid, amount, tds, service, net_amount, datetime) values('$uid', '$amount', '$tds', '$service', '$net_amount', '".date('Y-m-d H:i:s')."')");
mysqli_query($connection, "INSERT INTO `transaction` (`uid`, `amount`, `txn_type`, `txn_mode`, `datetime`, `status`, `closing_datetime`) VALUES "
. "('$uid', - '$amount', '8', '1', '$datetime', '1', '$datetime');");
$bank_result =mysqli_query($connection,"SELECT recid FROM `bank_details` WHERE uid='$uid' ORDER BY recid Desc LIMIT 1");
$receive_bank_id = mysqli_num_rows($bank_result)==1?mysqli_fetch_object($bank_result)->recid:0;
$is_request_insert = mysqli_query($connection,"INSERT INTO `request_amount` (`uid`, `amount`, `balance`, `datetime`, `bank_id`) VALUES ('$uid','$amount','$amount','".date('Y-m-d H:i:s')."','$receive_bank_id' )");
setMessage('Your withdrawal request completed successfully.', 'alert-success');
redirect('./account.php');
}
else{
setMessage('Request amount must be less than or equal to primary wallet and greater than 3000.', 'alert-error');
redirect('./account.php');
}
?>