<?php
    if(isset($_POST['delete'])){
        $id = $_POST['delete_payment'];

        $all_payment = "DELETE FROM payment WHERE payment_id=$id";

        if($db->query($all_payment) == TRUE){
            echo "<script>alert('Student Payment Deleted')</script>";
        }else{
            echo "<script>alert('Student Payment not deleted')</script>";
        }

    }

?>
            <!-- Recent Sales Start -->
            <div class="container-fluid pt-4 px-4">
                <div class="bg-secondary text-center rounded p-4">
                    <div class="d-flex align-items-center justify-content-between mb-4">
                        <h6 class="mb-0">All Payment</h6>
                        
                    </div>
                    <div class="table-responsive">
                        <table class="table text-start align-middle table-bordered table-hover mb-0">
                            <thead>
                                <tr class="text-white">
                                    <th scope="col"><input class="form-check-input" type="checkbox"></th>
                                    <!-- <th scope="col">S/N</th> -->
                                    <th scope="col">payment type</th>
                                    <!-- <th scope="col">prove of payment</th> -->
                                    <th scope="col">Payment from</th>
                                    <th scope="col">Action</th>
                                    <th scope="col">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $all_payment = mysqli_query($db, "SELECT * FROM payment");

                                // fetch all payment 
                                if(mysqli_fetch_array($all_payment)){

                                    // use foreach to echo all datas
                                    foreach($all_payment as $payment){

                                ?>
                                <tr>
                                    <td><input class="form-check-input" type="checkbox"></td>
                                    <!-- <td><?php echo $payment['payment_id']; ?></td> -->
                                    <td><?php echo $payment['pay']; ?></td>
                                    <!-- <td><?php echo $payment['paymentfiles']; ?></td> -->
                                    <td><?php echo $payment['sname']; ?></td>
                                    <td><a class="btn btn-sm btn-success" href="index.php?env=edit_payment&payment_id=<?php echo $payment['payment_id']; ?>">Edit</a></td>
                                    <td>
                                        <form method="POST">
                                            <input type='hidden' name='delete_payment' value='<?php echo $payment['payment_id'] ?>'>
                                            <input type='submit'class='btn btn-sm btn-danger' name='delete' value='Delete'>
                                        </form>
                                   
                                    </td>
                                </tr>

                                <?php
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <!-- Recent Sales End -->

            <!-- Footer Start -->
            <?php include("inc/footer.php"); ?>