<?php include("auth.php") ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>Transaction List</title>
    <meta content="" name="description">
    <meta content="" name="keywords">
    <?php include("templates/inc.php"); ?>
    <!-- <script src="scripts/home-notification.js" type="text/javascript" language="javascript"></script> -->
</head>

<body>

    <!-- ======= Header ======= -->
    <?php
    include("templates/header.php");
    ?>

    <!-- End Header -->

    <!-- ======= Sidebar ======= -->
    <?php
    include("templates/sidebar.php");

    ?>
    <!-- End Sidebar-->

    <main id="main" class="main">

        <div class="pagetitle">
            <h1>User Transaction List</h1>
            <nav>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
                    <li class="breadcrumb-item">User Transaction List</li>

                </ol>
            </nav>
            <hr>
        </div><!-- End Page Title -->

        <section class="section">
            <!-- <a href="home-notification.php">
                <button type="button" class="btn btn-primary"><i class="bi bi-plus me-1"></i> Add New Notification</button>
            </a></br></br> -->

            <section class="section">
                <div class="row">
                    <div class="col-lg-12">

                        <div class="card">
                            <div class="card-body table-responsive" id="records">
                                <h5 class="card-title">User Transaction List</h5>
                                <!-- Table with stripped rows -->
                                <table class="table datatable table-striped">
                                    <thead>
                                        <tr>
                                            <th scope="col">Sl</th>
                                            <th scope="col">From</th>
                                            <th scope="col">To</th>
                                            <th scope="col">Amount</th>
                                            <!--<th scope="col">Type</th>-->
                                            <th scope="col">Txn Id</th>
                                            <th scope="col">Remark</th>

                                        </tr>
                                    </thead>

                                    <tbody>
                                        <?php
                                        require "conn.php";

                                        $sl = 1;
                                        
                                        function getUserName($uid)
                                        {
                                        require "conn.php";
                                        $res="";
                                        $sql = "select * from tbl_user where mobile='$uid'";
                                        $rs = mysqli_query($conn, $sql);
                                        $row = mysqli_fetch_assoc($rs);
                                        
                                        if($row['uname'])
                                        $res=$row['uname'];
                                        
                                        return($res);
                                        }
                                           
                                        if(isset($_GET['filter']) && base64_decode($_GET['filter'])=="today")
                                        $sql = "select * from user_payment_history where deleted_at is NULL and DATE(created_at)=CURDATE() order by id desc";
                                        else if(isset($_GET['filter']) && base64_decode($_GET['filter'])=="month")
                                        $sql = "select * from user_payment_history where deleted_at is NULL and MONTH(created_at)=MONTH(CURDATE()) order by id desc";
                                        else
                                        $sql = "select * from user_payment_history where deleted_at is NULL order by id desc";

                                        $rs = mysqli_query($conn, $sql);
                                        while ($row = mysqli_fetch_assoc($rs)) {
                                            echo "<tr>";
                                            echo '<td>' . $sl . '</td>';
                                            echo '<td>' . getUserName($row['uid']) . ' (' . $row['uid'] . ')</td>';
                                            echo '<td>' . getUserName($row['pay_to']) . ' (' . $row['pay_to'] . ')</td>';
                                            echo '<td>' . $row['amount'] . '</td>';
                                            // echo '<td>' . $row['payment_type'] . '</td>';
                                            echo '<td>' . $row['transaction_id'] . '</td>';
                                              echo '<td>' . $row['title'] . '</td>';

                                            // echo '<td><a href="home-notification.php?action=' . base64_encode("Edit") . '&id=' . base64_encode($row['id']) . '" class="btn btn-primary"><i class="bi bi-pencil"></i></a>
                                            // <button id=' . $row['id'] . ' class="btn btn-danger delete"><i class="bi bi-trash"></i></button></td>';
                                            // echo "</tr>";
                                            $sl++;
                                        }
                                        ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

            </section>

    </main><!-- End #main -->

    <!-- ======= Footer ======= -->
    <?php
    include("templates/footer.php");
    ?>
    <!-- End Footer -->


    <?php include("templates/vendors.php"); ?>

</body>

</html>