<?php
$title = 'Investments';
// require_once('../admin/lib/table-traits.php'); 
// require_once('../admin/lib/basic-function.php'); 
// require_once('../admin/lib/user-functions.php'); 
require_once('header-links.php');

$current_pg = 4;

$all_investments = $basicFunctn->selectWhereDlt($user->transaction_tb, 'user_id', $user_logged['unique_id']);
// $full_name = explode('++', $user_logged['full_name']);
// $first_name = $full_name[0];
// $last_name = $full_name[1];
// $date_joined = explode(',', $user_logged['created_at']);

// print_r($all_investments);
// die();



?>

<body>
    <!-- BEGIN LOADER -->
    <div id="load_screen">
        <div class="loader">
            <div class="loader-content">
                <div class="spinner-grow align-self-center"></div>
            </div>
        </div>
    </div>
    <!--  END LOADER -->

    <!--  BEGIN NAVBAR  -->
    <?php require_once('header.php'); ?>
    <!--  END NAVBAR  -->

    <!--  BEGIN MAIN CONTAINER  -->
    <div class="main-container" id="container">

        <div class="overlay"></div>
        <div class="search-overlay"></div>

        <!--  BEGIN SIDEBAR  -->
        <?php require_once('sidebar.php'); ?>
        <!--  END SIDEBAR  -->

        <!--  BEGIN CONTENT AREA  -->
        <div id="content" class="main-content">
            <div class="layout-px-spacing">

                <div class="row layout-spacing">

                    <!-- Content -->
                    <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 layout-top-spacing">

                        <!-- <div class="user-profile layout-spacing"> -->
                        <div class="widget-content widget-content-area">
                            <div class="table-responsive">
                                <table class="table table-hover mb-4">
                                    <thead>
                                        <tr>
                                            <th>S/N</th>
                                            <th>Transaction Id</th>
                                            <th>Investment</th>
                                            <th>Currency</th>
                                            <th>Package</th>
                                            <th>Amount($)</th>
                                            <th>Coin Equiv.</th>
                                            <th class="text-center">Status</th>
                                            <th>Interest($)</th>
                                            <th>Date Created</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php  
                                     if(count($all_investments)>0){ 
                                    $i = 1;
                                    foreach ($all_investments 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);
                                        ?>
                                        <tr>
                                            <td><?php print $i; ?></td>
                                            <td><?php print $e['unique_id']; ?></td>
                                            <td><?php print $investment['name']; ?></td>
                                            <td><?php print $coin['name']; ?></td>
                                            <td><?php print $package['name']; ?></td>
                                            <td><?php print $e['amt_in_usd']; ?></td>
                                            <td><?php print $e['amt_in_currency']; ?> (<?php print $coin['symbol']; ?>)</td>
                                            <td class="text-center text-capitalize">
                                                <?php if($e['status'] == 'pending'){ ?>
                                                    <span class="text-warning">
                                                        <?php print $e['status']; ?>
                                                    </span>
                                                <?php }elseif($e['status'] == 'confirmed'){ ?>
                                                    <span class="text-success">
                                                        <?php print $e['status']; ?>
                                                    </span>
                                                <?php }elseif($e['status'] == 'completed'){ ?>
                                                    <span class="text-danger">
                                                        <?php print $e['status']; ?>
                                                    </span>
                                                <?php } ?>
                                            </td>
                                            <td><?php print round($e['interest_in_usd'],3); ?></td>
                                            <td><?php print $e['created_at']; ?></td>
                                        </tr>
                                    <?php $i++; }
                                         } else{ ?>
                                         <tr> 
                                             <td class="text-center" colspan="10"> No Records Found </td> 
                                         </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!-- </div> -->

                    </div>

                </div>
            </div>
            <?php require_once('footer.php'); ?>
        </div>
        <!--  END CONTENT AREA  -->
    </div>
    <?php require_once('footer-links.php'); ?>
    <script>
        $('.edit_user_btn').click(async function(e) {
            e.preventDefault();
            let edit_user_form = $('.edit_user_form').serializeArray();
            let form_data = set_form_data(edit_user_form);
            // console.log(edit_user_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'profile', 1);
        });
    </script>