<?php
$title = 'Withdrawal History';
require_once('header-links.php');
// require_once('../lib/basic-function.php');
// require_once('../lib/user-functions.php');
// require_once('../lib/investment-plan-functions.php');
// require_once('../lib/package-functions.php');
// require_once('../lib/currency-functions.php');
$all_interest = $basicFunctn->selectWhereDlt($basicFunctn->withdrawal_tb,'category','INTEREST');
$all_bonus = $basicFunctn->selectWhereDlt($basicFunctn->withdrawal_tb,'category','BONUS');
?>

<body>
    <div class="app">
        <div class="layout">
            <?php require_once('sidebar.php'); ?>

            <!-- Page Container START -->
            <div class="page-container">
                <?php require_once('header.php'); ?>

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="page-title">
                            <h4><?php print $title; ?></h4>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="padding-20">
                                        <h4 class="card-title no-mrg-btm"></h4>
                                    </div>
                                    <div class="tab-primary">
                                        <ul class="nav nav-tabs" role="tablist">
                                            <li class="nav-item">
                                                <a href="#cashout-interest" class="nav-link active" role="tab" data-toggle="tab">Interest Withdrawal</a>
                                            </li>
                                            <li class="nav-item">
                                                <a href="#cashout-bonus" class="nav-link" role="tab" data-toggle="tab">Bonus Withdrawal</a>
                                            </li>
                                        </ul>
                                        <div class="tab-content">
                                            <div role="tabpanel" class="tab-pane fade in active" id="cashout-interest">
                                                <div class="pdd-horizon-15 pdd-vertical-20">
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <div class="table-overflow">
                                                                <table class="table table-bordered table-hover table-sm">
                                                                    <thead>
                                                                        <tr>
                                                                            <th>S/N</th>
                                                                            <th>TRANSACTION ID</th>
                                                                            <th>EMAIL</th>
                                                                            <th>AMOUNT ($)</th>
                                                                            <th>STATUS</th>
                                                                            <th>DATE-CREATED</th>
                                                                        </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                    <?php 
                                                                    $i=1;
                                                                    foreach ($all_interest as $e) { 
                                                                    $the_user = $basicFunctn->getDataDlt($e['user_id'], $basicFunctn->user_tb);
                                                                    if($e['status'] == 'PENDING'){
                                                                        $class = 'status-pending';
                                                                    }elseif ($e['status'] == 'PAID') {
                                                                        $class = 'status-confirmed';
                                                                    }
                                                                    ?>
                                                                        <tr class="<?php print $class; ?>">
                                                                            <td><?php print $i; ?></td>
                                                                            <td><?php print $e['unique_id']; ?></td>
                                                                            <td><?php print $the_user['email']; ?></td>
                                                                            <td><?php print $e['amt_in_usd']; ?></td>
                                                                            <td><?php print $e['status']; ?></td>
                                                                            <td><?php print $e['created_at']; ?></td>
                                                                        </tr>
                                                                    <?php $i++;} ?>
                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div role="tabpanel" class="tab-pane fade" id="cashout-bonus">
                                                <div class="pdd-horizon-15 pdd-vertical-20">
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <div class="table-overflow">
                                                                <table class="table table-bordered table-hover table-sm">
                                                                    <thead>
                                                                        <tr>
                                                                            <th>S/N</th>
                                                                            <th>TRANSACTION ID</th>
                                                                            <th>EMAIL</th>
                                                                            <th>AMOUNT ($)</th>
                                                                            <th>STATUS</th>
                                                                            <th>DATE-CREATED</th>
                                                                        </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                    <?php 
                                                                    $i=1;
                                                                    foreach ($all_bonus as $e) { 
                                                                    $the_user = $basicFunctn->getDataDlt($e['user_id'], $basicFunctn->user_tb);
                                                                    if($e['status'] == 'PENDING'){
                                                                        $class = 'status-pending';
                                                                    }elseif ($e['status'] == 'PAID') {
                                                                        $class = 'status-confirmed';
                                                                    }
                                                                    ?>
                                                                        <tr class="<?php print $class; ?>">
                                                                            <td><?php print $i; ?></td>
                                                                            <td><?php print $e['unique_id']; ?></td>
                                                                            <td><?php print $the_user['email']; ?></td>
                                                                            <td><?php print $e['amt_in_usd']; ?></td>
                                                                            <td><?php print $e['status']; ?></td>
                                                                            <td><?php print $e['created_at']; ?></td>
                                                                        </tr>
                                                                    <?php $i++;} ?>
                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- Modal START-->
                                            <div class="modal fade zoomInUp" id="confirm-modal">
                                                <div class="modal-dialog" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h4>Confirm Transaction?</h4>
                                                        </div>
                                                        <form class="confirm_txn_form">
                                                            <div class="modal-body">
                                                                <p class="">By confirming this, you acknowledge to have recieved payment for this deposit. <br> Interest will begin to be added to this transaction.</p>
                                                            </div>
                                                        </form>
                                                        <div class="modal-footer no-border">
                                                            <div class="text-right">
                                                                <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                                                <button class="btn btn-primary btn-sm confirm_txn_btn" data-dismiss="modal">Continue</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- Modal START-->
                                            <div class="modal fade zoomInUp" id="end_txn_modal">
                                                <div class="modal-dialog" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h4>End Transaction?</h4>
                                                        </div>
                                                        <form class="end_txn_form">
                                                            <div class="modal-body">
                                                                <p class="">By clicking continue, you acknowledge this transaction has completed its duration. <br> Interest will no longer be added to this transaction.</p>
                                                            </div>
                                                        </form>
                                                        <div class="modal-footer no-border">
                                                            <div class="text-right">
                                                                <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                                                <button class="btn btn-primary btn-sm end_txn_btn" data-dismiss="modal">Continue</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- Modal START-->
                                            <div class="modal fade zoomInUp" id="unconfirm_modal">
                                                <div class="modal-dialog" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h4>Unconfirm Transaction?</h4>
                                                        </div>
                                                        <form class="unconfirm_form">
                                                            <div class="modal-body">
                                                                <p class="">By clicking continue, this transaction will be made pending. <br> Interest will no longer be added to this transaction.</p>
                                                            </div>
                                                        </form>
                                                        <div class="modal-footer no-border">
                                                            <div class="text-right">
                                                                <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                                                <button class="btn btn-primary btn-sm unconfirm_btn" data-dismiss="modal">Continue</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- Modal START-->
                                            <div class="modal fade zoomInUp" id="delete_txn_modal">
                                                <div class="modal-dialog" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h4>Delete Transaction?</h4>
                                                        </div>
                                                        <form class="delete_txn_form">
                                                            <div class="modal-body">
                                                                <p class="text-danger">By clicking continue, this transaction will be deleted permanently. <br> Users won't be able to view this transaction.</p>
                                                            </div>
                                                        </form>
                                                        <div class="modal-footer no-border">
                                                            <div class="text-right">
                                                                <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                                                <button class="btn btn-primary btn-sm delete_txn_btn" data-dismiss="modal">Continue</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- Content Wrapper END -->
                                            <?php require_once('footer.php'); ?>
                                            <!-- Footer END -->

                                        </div>
                                        <!-- Page Container END -->

                                    </div>
                                </div>

                                <?php require_once('footer-links.php'); ?>
                                <script>
                                    $('.confirm_modal').click(function(e) {
                                        e.preventDefault();
                                        append_id('confirm_deposit_id', '.confirm_txn_form', '#confirm-modal', this)
                                        $('#confirm-modal').modal('toggle');
                                    });
                                    $('.end_txn_modal').click(function(e) {
                                        e.preventDefault();
                                        append_id('end_txn_id', '.end_txn_form', '#end_txn_modal', this)
                                        $('#end_txn_modal').modal('toggle');
                                    });
                                    $('.unconfirm_modal').click(function(e) {
                                        e.preventDefault();
                                        append_id('unconfirm_txn_id', '.unconfirm_form', '#unconfirm_modal', this)
                                        $('#unconfirm_modal').modal('toggle');
                                    });
                                    $('.delete_txn_modal').click(function(e) {
                                        e.preventDefault();
                                        append_id('delete_txn_id', '.delete_txn_form', '#delete_txn_modal', this)
                                        $('#delete_txn_modal').modal('toggle');
                                    });


                                    $('.confirm_txn_btn').click(async function(e) {
                                        e.preventDefault();
                                        let confirm_txn_form = $('.confirm_txn_form').serializeArray();
                                        let form_data = set_form_data(confirm_txn_form);
                                        let returned = await ajaxRequest('ajax.php', form_data);
                                        throwSweetalert(returned, 'transactions', 1);
                                    });
                                    $('.end_txn_btn').click(async function(e) {
                                        e.preventDefault();
                                        let end_txn_form = $('.end_txn_form').serializeArray();
                                        let form_data = set_form_data(end_txn_form);
                                        // console.log(end_txn_form);return;
                                        let returned = await ajaxRequest('ajax.php', form_data);
                                        // console.log(returned);return;
                                        throwSweetalert(returned, 'transactions', 1);
                                    });
                                    $('.unconfirm_btn').click(async function(e) {
                                        e.preventDefault();
                                        let unconfirm_form = $('.unconfirm_form').serializeArray();
                                        let form_data = set_form_data(unconfirm_form);
                                        // console.log(unconfirm_form);return;
                                        let returned = await ajaxRequest('ajax.php', form_data);
                                        // console.log(returned);return;
                                        throwSweetalert(returned, 'transactions', 1);
                                    });
                                    $('.delete_txn_btn').click(async function(e) {
                                        e.preventDefault();
                                        let delete_txn_form = $('.delete_txn_form').serializeArray();
                                        let form_data = set_form_data(delete_txn_form);
                                        // console.log(delete_txn_form);return;
                                        let returned = await ajaxRequest('ajax.php', form_data);
                                        // console.log(returned);return;
                                        throwSweetalert(returned, 'transactions', 1);
                                    });
                                </script>