<?php
/**
 * userDebit.php -- Debit User's Account
 */

include '../inc/config.inc.php'; // Configuration

ob_start();
session_start();

//date_default_timezone_set('Africa/Lagos');

error_reporting(E_ALL);
ini_set('display_errors', 1);

if ( !isset($_SESSION['admin']) || $_SESSION["loggedin"] !== true || trim($_SESSION['admin']) == '' ){
	//header('Location: ' . $BASE_URL . 'wp-admin/');
    header('Location: ' . $BASE_URL . 'signin');
	exit;
}

if ( isset($_GET['id']) ){
    $user_id = intval($_GET['id']);
    // Users
    $users = $db_con->prepare("SELECT id, fullname, currency FROM users WHERE id='$user_id'");
    $users->execute();
    $user = $users->fetch(PDO::FETCH_ASSOC);

    // Get Total Balance
    $userTB = $db_con->prepare("SELECT * FROM user_total_balance WHERE user_id='".$user['id']."'");
    $userTB->execute(); $tb = $userTB->fetch(PDO::FETCH_ASSOC);

    // Get Total Earning
    $userTE = $db_con->prepare("SELECT * FROM user_total_earning WHERE user_id='".$user['id']."'");
    $userTE->execute(); $te = $userTE->fetch(PDO::FETCH_ASSOC);

    // Get Active Deposit
    $userAD = $db_con->prepare("SELECT * FROM user_active_deposit WHERE user_id='".$user['id']."'");
    $userAD->execute(); $ad = $userAD->fetch(PDO::FETCH_ASSOC);

    // Get Total Deposit
    $userTD = $db_con->prepare("SELECT * FROM user_total_deposit WHERE user_id='".$user['id']."'");
    $userTD->execute(); $td = $userTD->fetch(PDO::FETCH_ASSOC);

    // Get Total Withdrawal
    $userTW = $db_con->prepare("SELECT * FROM user_total_withdrawal WHERE user_id='".$user['id']."'");
    $userTW->execute(); $tw = $userTW->fetch(PDO::FETCH_ASSOC);

    // Get Last Deposit
    $userLD = $db_con->prepare("SELECT * FROM user_last_deposit WHERE user_id='".$user['id']."'");
    $userLD->execute(); $ld = $userLD->fetch(PDO::FETCH_ASSOC);

    // Get Last Withdrawal
    $userLW = $db_con->prepare("SELECT * FROM user_last_withdrawal WHERE user_id='".$user['id']."'");
    $userLW->execute(); $lw = $userLW->fetch(PDO::FETCH_ASSOC);

    // Get Pending Withdraw
    $userPW = $db_con->prepare("SELECT * FROM user_pending_withdraw WHERE user_id='".$user['id']."'");
    $userPW->execute(); $pw = $userPW->fetch(PDO::FETCH_ASSOC);

    // Get Profit Lost
    $userPL = $db_con->prepare("SELECT * FROM user_profit_lost WHERE user_id='".$user['id']."'");
    $userPL->execute(); $pl = $userPL->fetch(PDO::FETCH_ASSOC);

?>

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Debit funds - Alert Signals Nation</title>
    <!-- Favicon -->

    <link rel="shortcut icon" href="../../img/Signals-Alert-3.png" />
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- Typography CSS -->
    <link rel="stylesheet" href="css/typography.css">
    <!-- Style CSS -->
    <link rel="stylesheet" href="css/style.css">
    <!-- Responsive CSS -->
    <link rel="stylesheet" href="css/responsive.css">

    <script src="../plugins/sweetalerts/promise-polyfill.js"></script>
    <link href="../plugins/sweetalerts/sweetalert.css" rel="stylesheet" type="text/css" />

    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" rel="stylesheet" />
    <style>
        /*------ Google Font Style ------ */
        body {font-family:'Roboto'!important;}
    </style>
    
</head>
<body class="sidebar-main-active right-column-fixed">
    <!-- loader Start -->
    <div id="loading">
        <div id="loading-center">
        </div>
    </div>
    <!-- loader END -->
    <!-- Wrapper Start -->
    <div class="wrapper">
        <!-- Sidebar  -->
        <?php include 'navbar.php' ?>
        <!-- Page Content  -->
        <div id="content-page" class="content-page">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-12 col-lg-12">
                        <div class="iq-card">
                            <div class="iq-card-header d-flex justify-content-between">
                                <div class="iq-header-title">
                                    <h4 class="card-title" style="font-family: 'Roboto'!important;">Debit</h4>
                                </div>
                            </div>
                            <div class="iq-card-body">
                                <div class="row">
                                    <div class="col-sm-3">
                                        <div class="nav flex-column nav-pills text-center" id="v-pills-tab" role="tablist" aria-orientation="vertical">
                                            <!--<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Total balance</a>-->
                                            <a class="nav-link active" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="true">Total Earning</a>
                                            <!--<a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Active Deposit</a>
                                            <a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Total Deposit</a>
                                            <a class="nav-link" id="v-pills-s-tab" data-toggle="pill" href="#v-pills-s" role="tab" aria-controls="v-pills-s" aria-selected="false">Total Withdrawal</a>
                                            <a class="nav-link" id="v-pills-se-tab" data-toggle="pill" href="#v-pills-se" role="tab" aria-controls="v-pills-se" aria-selected="false">Last Deposit</a>
                                            <a class="nav-link" id="v-pills-set-tab" data-toggle="pill" href="#v-pills-set" role="tab" aria-controls="v-pills-set" aria-selected="false">Last Withdrawal</a>
                                            <a class="nav-link" id="v-pills-sett-tab" data-toggle="pill" href="#v-pills-sett" role="tab" aria-controls="v-pills-sett" aria-selected="false">Pending Withdraw</a>-->
                                            <a class="nav-link" id="v-pills-sett-tab" data-toggle="pill" href="#v-pills-pl" role="tab" aria-controls="v-pills-pl" aria-selected="false">Profit Lost</a>
                                        </div>
                                    </div>
                                    <div class="col-sm-9">
                                        <div class="tab-content mt-0" id="v-pills-tabContent">
                                            <!--<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $tb['amount']; ?>" placeholder="2000">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance </label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $tb['current_balance']; ?>" placeholder="2000" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $tb['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $tb['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updateTB" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updateTB']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $tb['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_total_balance SET amount='$amount', current_balance='$current_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Total Balance');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>-->

                                            <div class="tab-pane fade show active" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount (<?= $user['currency']; ?>)</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $te['amount']; ?>">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance (<?= $user['currency']; ?>)</label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $te['current_balance']; ?>" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $te['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $te['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updateTE" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updateTE']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $te['current_balance'];
                                                    //$new_balance = $current_balance - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    //$update = $db_con->prepare("UPDATE user_total_earning SET amount='$new_balance', current_balance='$new_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");
                                                    $update = $db_con->prepare("UPDATE user_total_earning SET amount=amount-'$current_balance', current_balance=current_balance-'$amount', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Total Earning');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>

                                            <!--<div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $ad['amount']; ?>" placeholder="2000">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance </label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $ad['current_balance']; ?>" placeholder="2000" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $ad['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $ad['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updateAD" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updateAD']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $ad['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_active_deposit SET amount='$amount', current_balance='$current_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Active Deposit');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>

                                            <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $td['amount']; ?>" placeholder="2000">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance </label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $td['current_balance']; ?>" placeholder="2000" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $td['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $td['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updateTD" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updateTD']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $td['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_total_deposit SET amount='$amount', current_balance='$current_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Total Deposit');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>

                                            <div class="tab-pane fade" id="v-pills-s" role="tabpanel" aria-labelledby="v-pills-s-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $tw['amount']; ?>" placeholder="2000">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance </label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $tw['current_balance']; ?>" placeholder="2000" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $tw['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $tw['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updateTW" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updateTW']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $tw['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_total_withdrawal SET amount='$amount', current_balance='$current_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Total Withdrawal');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>

                                            <div class="tab-pane fade" id="v-pills-se" role="tabpanel" aria-labelledby="v-pills-se-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $ld['amount']; ?>" placeholder="2000">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance </label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $ld['current_balance']; ?>" placeholder="2000" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $ld['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $ld['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updateLD" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updateLD']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $ld['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_last_deposit SET amount='$amount', current_balance='$current_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Last Deposit');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>

                                            <div class="tab-pane fade" id="v-pills-set" role="tabpanel" aria-labelledby="v-pills-set-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $lw['amount']; ?>" placeholder="2000">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance </label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $lw['current_balance']; ?>" placeholder="2000" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $lw['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $lw['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updateLW" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updateLW']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $lw['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_last_withdrawal SET amount='$amount', current_balance='$current_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Last Withdrawal');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>

                                            <div class="tab-pane fade" id="v-pills-sett" role="tabpanel" aria-labelledby="v-pills-sett-tab">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $pw['amount']; ?>" placeholder="2000">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance </label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $pw['current_balance']; ?>" placeholder="2000" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $pw['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $pw['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updatePW" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updatePW']) ){

                                                    $amount = $_POST['amount'];
                                                    $current_balance = $pw['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_pending_withdraw SET amount='$amount', current_balance='$current_balance', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    if ( $update->execute() ){
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Pending Withdraw');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>-->

                                            <div class="tab-pane fade" id="v-pills-pl" role="tabpanel" aria-labelledby="v-pills-pl">
                                                <form method="post" action="">
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Amount (<?= $user['currency']; ?>)</label>
                                                        <input type="text" class="form-control" name="amount" value="<?= $pl['amount']; ?>">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputText1">Current balance (<?= $user['currency']; ?>)</label>
                                                        <input type="text" class="form-control" name="current_balance" value="<?= $pl['current_balance']; ?>" disabled="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleInputdate">Debit Date</label>
                                                        <input type="date" class="form-control" name="debit_date" value="<?= $pl['debit_date']; ?>" placeholder="2019-12-18">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="exampleFormControlTextarea1">Description</label>
                                                        <textarea class="form-control" name="description" rows="5"><?= $pl['description']; ?></textarea>
                                                    </div>
                                                    <button type="submit" name="updatePL" class="btn btn-primary">Submit</button>
                                                </form>
                                                <?php
                                                if ( isset($_POST['updatePL']) ){

                                                    $amount = $_POST['amount'];
                                                    //$current_balance = $pl['current_balance'] - $amount;
                                                    $total_balance = $tb['current_balance'] - $amount;
                                                    $debit_date = $_POST['debit_date'];
                                                    $description = $_POST['description'];
                                                
                                                    $update = $db_con->prepare("UPDATE user_profit_lost SET amount='$amount', current_balance='$amount', debit_date='$debit_date', description='$description' WHERE user_id='".$user['id']."'");

                                                    //$updateTB = $db_con->prepare("UPDATE user_total_balance SET amount=amount-'$amount', current_balance=current_balance-'$rel_amount' WHERE user_id='$user_id'");
                                                    $updateTB = $db_con->prepare("UPDATE user_total_balance SET amount='$total_balance', current_balance='$total_balance' WHERE user_id='$user_id'");

                                                    if ( $update->execute() ){
                                                        $updateTB->execute();
                                                ?>
                                                        <script>
                                                            setTimeout(function(){
                                                                noticePop('Profit Lost');
                                                            }, 2000);
                                                        </script>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Wrapper END -->
    <!-- Footer -->
    <?php include 'footer.php' ?>
    <!-- color-customizer END -->
    <!-- Optional JavaScript -->
    <script src="../plugins/jquery-3.1.1.min.js"></script>
    <script src="../plugins/sweetalerts/sweetalert2.min.js"></script>
    <script src="https://unpkg.com/@popperjs/core@2/dist/umd/popper.js"></script>

    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="js/jquery.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- Appear JavaScript -->
    <script src="js/jquery.appear.js"></script>
    <!-- Countdown JavaScript -->
    <script src="js/countdown.min.js"></script>
    <!-- Counterup JavaScript -->
    <script src="js/waypoints.min.js"></script>
    <script src="js/jquery.counterup.min.js"></script>
    <!-- Wow JavaScript -->
    <script src="js/wow.min.js"></script>
    <!-- Apexcharts JavaScript -->
    <script src="js/apexcharts.js"></script>
    <!-- Slick JavaScript -->
    <script src="js/slick.min.js"></script>
    <!-- Select2 JavaScript -->
    <script src="js/select2.min.js"></script>
    <!-- Owl Carousel JavaScript -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- Magnific Popup JavaScript -->
    <script src="js/jquery.magnific-popup.min.js"></script>
    <!-- Smooth Scrollbar JavaScript -->
    <script src="js/smooth-scrollbar.js"></script>
    <!-- lottie JavaScript -->
    <script src="js/lottie.js"></script>
    <!-- am core JavaScript -->
    <script src="js/core.js"></script>
    <!-- am charts JavaScript -->
    <script src="js/charts.js"></script>
    <!-- am animated JavaScript -->
    <script src="js/animated.js"></script>
    <!-- am kelly JavaScript -->
    <script src="js/kelly.js"></script>
    <!-- am maps JavaScript -->
    <script src="js/maps.js"></script>
    <!-- am worldLow JavaScript -->
    <script src="js/worldLow.js"></script>
    <!-- Style Customizer -->
    <script src="js/style-customizer.js"></script>
    <!-- Chart Custom JavaScript -->
    <script src="js/chart-custom.js"></script>
    <!-- Custom JavaScript -->
    <script src="js/custom.js"></script>

    <script>
        function noticePop( value ){
            swal({
                html: '<span style="font-size:18px!important;">Successfully updated "'+ `${value}` +'" <br>for <b><?= $user['fullname']; ?></b> </span>',
                type: 'success',
                timer: 4000,
                showConfirmButton: false,
                allowOutsideClick: false,
                allowEscapeKey: false,
            }).then(function(){
                window.location.href = 'userDebit?id=<?= $user['id']; ?>';
            });
        }
    </script>

</body>
</html>

<?php
}
?>