<?php 
include('authentication.php');
include('includes/header.php');
include('includes/topbar.php');
include('includes/sidebar.php');
?>


<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Ledger</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active">Ledger</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">


                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">Ledger List</h3>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                            <table id="example1" class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>S No.</th>
                                        <th>Key</th>
                                        <th>Points</th>
                                        <th>Qr Code</th>
                                        <th>Created At</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                        $i = 1;
                        $ref = "Redeem History/".$_GET['id'];
                        $fetchdata = $database->getReference($ref)->getValue();
                        if($fetchdata>0){
                            foreach ($fetchdata as $key => $row) {
                                ?>
                                    <tr>
                                        <td><?=$i?></td>
                                        <td><?=$key?></td>
                                        <td><?php if($row['add'] == 1){
                                            echo "+".$row['point'];
                                        }else{
                                            echo "-".$row['point'];
                                        }?></td>
                                         <td><?=$row['qr_code']?></td>
                                        <td><?php echo date('d/m/Y', $row['created_at']/1000); ?></td>
                                    </tr>
                                    <?php
                                $i++;
                            }
                        }else{

                        }
                      
                      ?>
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <th>S No.</th>
                                        <th>Key</th>
                                        <th>Points</th>
                                        <th>Qr Code</th>
                                        <th>Created At</th>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                        <!-- /.card-body -->
                    </div>
                    <!-- /.card -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
</div>


<?php
include('includes/script.php');
?>
<script>
$(document).ready(function() {
    $('.delete_btn').click(function(e) {
        e.preventDefault();
        var id = $(this).closest('tr').find('.id').text();
        console.log(id);
        $('#delete_id').val(id);
        $('#modal-danger').modal('show');

    });
});
</script>
<?php
include('includes/footer.php');
?>