<?php
$title = 'Deposit 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_deposits = $basicFunctn->selectAllDlt($basicFunctn->transaction_tb);
?>

<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-responsive">
                                            <table class="table table-bordered table-hover table-sm">
                                                <thead>
                                                    <tr>
                                                        <th>S/N</th>
                                                        <th>Transaction ID</th>
                                                        <th>Email</th>
                                                        <th>Investment</th>
                                                        <th>Plan</th>
                                                        <th>Coin</th>
                                                        <th>Amount&nbsp;($)</th>
                                                        <th>Interest&nbsp;($) </th>
                                                        <th>Status</th>
                                                        <th>Day On</th>
                                                        <th>Date Created</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php 
                                                    $i = 1;
                                                    foreach ($all_deposits as $e) {
                                                        $investment = $basicFunctn->getDataDlt($e['investment_type_id'], $basicFunctn->investment_plan_tb);
                                                        $coin = $basicFunctn->getDataDlt($e['coin_type_id'], $basicFunctn->currencies_tb);
                                                        $package = $basicFunctn->getDataDlt($e['plan_id'], $basicFunctn->package_tb);
                                                        $the_user = $basicFunctn->getDataDlt($e['user_id'], $basicFunctn->user_tb);
                                                        if($e['status'] == 'pending'){
                                                            $class = 'status-pending';
                                                        }elseif ($e['status'] == 'confirmed') {
                                                            $class = 'status-confirmed';
                                                        }elseif ($e['status'] == 'completed') {
                                                            $class = 'status-done';
                                                        }
                                                        $date_trans = $basicFunctn->date_transform($e['date_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 $investment['name']; ?></td>
                                                        <td><?php print $package['name']; ?></td>
                                                        <td><?php print $coin['name']; ?></td>
                                                        <td><?php print $e['amt_in_usd']; ?></td>
                                                        <td><?php print round($e['interest_in_usd'],3); ?></td>
                                                        <td><?php print $e['status']; ?></td>
                                                        <td><?php print $date_trans; ?></td>
                                                        <td><?php print $e['created_at']; ?></td>
                                                    </tr>
                                                    <?php $i++;} ?>

                                                    <!-- <tr style="color:blue;">
                                                        <td>'.$i.'</td>
                                                        <td>'.$row['transactionid'].'</td>
                                                        <td>'.$row['email'].'</td>
                                                        <td>'.$row['email'].'</td>
                                                        <td>'.$row['email'].'</td>
                                                        <td>'.$row['email'].'</td>
                                                        <td>'.$row['amount'].'</td>
                                                        <td>'.$row['interest'].'</td>
                                                        <td>'.$row['status'].'</td>
                                                        <td>'.$dayOn.'</td>
                                                        <td>'.$row['datereg'].'</td>
                                                    </tr>
                                                    <tr style="color:purple;">
                                                        <td>'.$i.'</td>
                                                        <td>'.$row['transactionid'].'</td>
                                                        <td>'.$row['email'].'</td>
                                                        <td>'.$row['email'].'</td>
                                                        <td>'.$row['email'].'</td>
                                                        <td>'.$row['amount'].'</td>
                                                        <td>'.$row['interest'].'</td>
                                                        <td>'.$row['status'].'</td>
                                                        <td>'.$dayOn.'</td>
                                                        <td>'.$row['plan'].'</td>
                                                        <td>'.$row['datereg'].'</td>
                                                    </tr> -->
                                                </tbody>
                                            </table>


                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Modal START-->
                <div class="modal fade zoomInUp" id="paid_txn_modal">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4>Confirm Withdrawal?</h4>
                            </div>
                            <form class="paid_txn_form">
                                <div class="modal-body">
                                    <p class="">By confirming this, you acknowledge to have sent payments for this withdrawal. <br> User will see that this payment has been sent.</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 paid_txn_btn" data-dismiss="modal">Continue</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Modal START-->
                <div class="modal fade zoomInUp" id="pending_txn_modal">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4>Unconfirm Withdrawal?</h4>
                            </div>
                            <form class="pending_txn_form">
                                <div class="modal-body">
                                    <p class="">By clicking continue, this withdrawal will be made pending. <br> User will see that payments have not been sent for this withdrawal.</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 pending_txn_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 Withdrawal?</h4>
                            </div>
                            <form class="delete_txn_form">
                                <div class="modal-body">
                                    <p class="text-danger">By clicking continue, this withdrawal will be deleted permanently. <br> User won't be able to view this withdrawal.</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>
        $('.paid_txn_modal').click(function(e) {
            e.preventDefault();
            append_id('withdraw_paid_id', '.paid_txn_form', '#paid_txn_modal', this)
            $('#paid_txn_modal').modal('toggle');
        });
        $('.pending_txn_modal').click(function(e) {
            e.preventDefault();
            append_id('withdraw_pending_id', '.pending_txn_form', '#pending_txn_modal', this)
            $('#pending_txn_modal').modal('toggle');
        });
        $('.delete_txn_modal').click(function(e) {
            e.preventDefault();
            append_id('withdraw_delete_id', '.delete_txn_form', '#delete_txn_modal', this)
            $('#delete_txn_modal').modal('toggle');
        });


        $('.paid_txn_btn').click(async function(e) {
            e.preventDefault();
            let paid_txn_form = $('.paid_txn_form').serializeArray();
            let form_data = set_form_data(paid_txn_form);
            // console.log(paid_txn_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            throwSweetalert(returned, 'pay-interest', 1);
        });
        $('.pending_txn_btn').click(async function(e) {
            e.preventDefault();
            let pending_txn_form = $('.pending_txn_form').serializeArray();
            let form_data = set_form_data(pending_txn_form);
            // console.log(pending_txn_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'pay-interest', 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, 'pay-interest', 1);
        });
    </script>