<?php
$title = 'Wallet Top ups';
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_investments = $basicFunctn->selectAllDlt($basicFunctn->transaction_tb);
$all_investments = $basicFunctn->selectWhereDlt($basicFunctn->wallet_tb,'description','my_deposit');
?>

<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="card-block">
                                        <div class="table-overflow table-responsive">
                                            <table id="dt-opt" class="table table-lg table-hover">
                                                <thead>
                                                    <tr>
                                                        <th>S/N</th>
                                                        <th>Name</th>
                                                        <th>Txn ID</th>
                                                        <th>Deposit&nbsp;($)</th>
                                                        <th>Status</th>
                                                        <th>Created</th>
                                                        <th></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    $i = 1;
                                                    foreach ($all_investments as $e) {
                                                        $the_user = $basicFunctn->getDataDlt($e['user_id'], $basicFunctn->user_tb);
                                                        $user_detail = $basicFunctn->selectWhereDlt($basicFunctn->user_details, 'user_unique_id', $e['user_id'])[0];
                                                        $full_name = explode('++', $the_user['full_name']);
                                                        $first_name = $full_name[0];
                                                        $last_name = $full_name[1];
                                                    ?>
                                                        <tr>
                                                            <td><?php print $i; ?></td>
                                                            <td>
                                                                <div class="list-info mrg-top-10">
                                                                    <!-- <img class="thumb-img" src="assets/images/avatars/thumb-1.jpg" alt=""> -->
                                                                    <img class="thumb-img" src="../../user/assets/uploads/profile/<?php print $user_detail['passport']; ?>" alt="">
                                                                    <div class="info">
                                                                        <span class="title text-capitalize"><?php print $first_name . ' ' . $last_name; ?></span>
                                                                        <span class="sub-title"><?php print $the_user['email']; ?></span>
                                                                    </div>
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="relative mrg-top-15">
                                                                    <span class="text-info"><?php print $e['unique_id']; ?></span>
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="mrg-top-15">
                                                                    <span class="text-warning"><?php print $e['amt_in_usd']; ?></span>
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="relative mrg-top-15">

                                                                    <?php if ($e['status'] == 'pending') { ?>
                                                                        <span class="status warning"> </span>
                                                                    <?php } elseif ($e['status'] == 'confirmed') { ?>
                                                                        <span class="status success"> </span>
                                                                    <?php } elseif ($e['status'] == 'completed') { ?> <span class="status danger"> </span>
                                                                    <?php } ?>

                                                                    <span class="pdd-left-10 text-capitalize"><b><?php print $e['status']; ?></b></span>
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="mrg-top-15">
                                                                    <span><?php print $e['created_at']; ?></span>
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="mrg-top-10 text-center">
                                                                    <button class="btn btn-icon btn-flat btn-rounded dropdown-toggle" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                                        <i class="ti-more-alt"></i>
                                                                    </button>
                                                                    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                                        <a href="user-wallet?user=<?php print $e['user_id']; ?>" class="dropdown-item cursor-pointer ">User wallet </a>
                                                                        <?php if ($e['status'] == 'pending') { ?>
                                                                            <a id="<?php print $e['unique_id']; ?>" class="dropdown-item cursor-pointer confirm_modal">Confirm Deposit</a>
                                                                        <?php } elseif ($e['status'] == 'confirmed') { ?>
                                                                            <a id="<?php print $e['unique_id']; ?>" class="dropdown-item cursor-pointer unconfirm_modal">Unconfirm Deposit</a>
                                                                        <?php } ?>
                                                                        <a id="<?php print $e['unique_id']; ?>" class="dropdown-item cursor-pointer delete_txn_modal">Delete Txn</a>
                                                                    </div>
                                                                </div>
                                                            </td>
                                                    <?php $i++;
                                                    } ?>
                                                    <!-- <tr>
                                                        <td>1</td>
                                                        <td>
                                                            <div class="list-info mrg-top-10">
                                                                <img class="thumb-img" src="assets/images/avatars/thumb-4.jpg" alt="">
                                                                <div class="info">
                                                                    <span class="title">Samuel Field</span>
                                                                    <span class="sub-title">ID 861</span>
                                                                </div>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="relative mrg-top-15">
                                                                <span class="status away"> </span>
                                                                <span class="pdd-left-20">Trade Pendding</span>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-15">
                                                                <span class="text-info"><b>#33667</b></span>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-15">
                                                                <span>8 May 2017</span>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-15">
                                                                <span>8 May 2017</span>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-15">
                                                                <span>8 May 2017</span>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-15">
                                                                <span>8 May 2017</span>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-15">
                                                                <span>8 May 2017</span>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-15">
                                                                <b class="text-dark font-size-16">$168.00</b>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="mrg-top-10 text-center">
                                                                <button class="btn btn-icon btn-flat btn-rounded dropdown-toggle">
                                                                    <i class="ti-more-alt"></i>
                                                                </button>
                                                            </div>
                                                        </td>
                                                    </tr> -->
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        <div class="modal fade zoomInUp" id="confirm-modal">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4>Confirm Deposit?</h4>
                    </div>
                    <form class="confirm_txn_form">
                    <!-- <input type="hidden" name="user_id" value="<?php //print $_GET['user'] ?>"> -->
                        <div class="modal-body">
                            <p class="">By confirming this, you acknowledge to have recieved payment for this deposit. <br> User can now use the fund for purchases.</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>
        <div class="modal fade zoomInUp" id="unconfirm_modal">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4>Unconfirm Deposit?</h4>
                    </div>
                    <form class="unconfirm_form">
                    <!-- <input type="hidden" name="user_id" value="<?php //print $_GET['user'] ?>"> -->
                        <div class="modal-body">
                            <p class="">By clicking continue, this deposit will be made pending.</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>
        <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 Deposit?</h4>
                    </div>
                    <form class="delete_txn_form">
                    <!-- <input type="hidden" name="user_id" value="<?php //print $_GET['user'] ?>"> -->
                        <div class="modal-body">
                            <p class="text-danger">By clicking continue, this deposit 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('wallet_confirm_deposit_id', '.confirm_txn_form', '#confirm-modal', this)
                $('#confirm-modal').modal('toggle');
            });
            $('.unconfirm_modal').click(function(e) {
                e.preventDefault();
                append_id('wallet_unconfirm_txn_id', '.unconfirm_form', '#unconfirm_modal', this)
                $('#unconfirm_modal').modal('toggle');
            });
            $('.delete_txn_modal').click(function(e) {
                e.preventDefault();
                append_id('wallet_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 data = $('.confirm_txn_form').serializeArray();
            let form_data = set_form_data(data);
            let returned = await ajaxRequest('ajax.php', form_data);
                throwSweetalert(returned, 'wallet-fundings', 1);
        });
        $('.unconfirm_btn').click(async function(e) {
            e.preventDefault();
            let data = $('.unconfirm_form').serializeArray();
            let form_data = set_form_data(data);
            // console.log(data);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
                throwSweetalert(returned, 'wallet-fundings', 1);
        });
        $('.delete_txn_btn').click(async function(e) {
            e.preventDefault();
            let data = $('.delete_txn_form').serializeArray();
            let form_data = set_form_data(data);
            // console.log(delete_txn_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
                throwSweetalert(returned, 'wallet-fundings', 1);
        });
    </script>