<?php include 'header-link.php'; ?>

<?php
 $sql = "SELECT balance_history.id, student.username, student.number, balance_history.gateway,balance_history.taka,balance_history.name,balance_history.number,balance_history.status FROM balance_history 
 left join student on balance_history.userid = student.userid
 ORDER BY FIELD(balance_history.status, 'Pending', 'Accepted', 'Rejected') ASC";
$result = $con->query($sql);
$sl=0;

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['delete_id'])) {
$delete_id = $_POST['delete_id'];
$delete_sql = "DELETE FROM balance_history WHERE id = ?";
$stmt = $con->prepare($delete_sql);
$stmt->bind_param("i", $delete_id);
$stmt->execute();
header("Location: add-balance-auto.php"); 
exit();
}
?>


<main>
    <section>
        <div class="container mt-2 pb-5">
            <div class="row justify-content-center">
                <div class="col-md-6">
                    <div class="card custom-card">
                        <div class="card-body">
                            <div class="text-center">
                                <i class="profile-icon fa-solid fa-bolt-auto"></i>
                            </div>

                            <h6 class="card-title text-center my-3"> Add Balance Auto (<?php echo $addBalAuto; ?>) </h6>
                           
                            

                            <input type="text" class="form-control mb-4" id="searchInput" placeholder="Search User..." onkeyup="filterOffers()">


                            <div class="offer-list" id="offerList">
                                <?php if ($result->num_rows > 0): ?>
                                <?php while($row = $result->fetch_assoc()): ?>
                                    <div class="offer-card mb-5 p-3" data-sim="<?php echo $offer['offer_sim']; ?>">
                                        <div class="row">
                                            <div class="col">
                                                <small class="fw-bold">A/C Name: <?php echo $row['username']; ?></small><br>
                                                <small>A/C Contact: <?php echo $row['number']; ?></small><br>
                                                <small> Status : <?php echo $row['status']; ?></small>
                                            </div>
                                            <div class="col text-end">
                                                <small> Gateway: <?php echo $row['gateway']; ?> </small><br>
                                                <small  class="fw-bold">Taka: <?php echo $row['taka']; ?> </small><br>
                                                <small> Name : <?php echo $row['name']; ?></small><br>
                                                <small> Mob No. : <?php echo $row['number']; ?></small>
                                            </div>
                                        </div>
                                        <div class="d-grid text-center">
                                        <a class="btn custom-button mx-3" href="edit-bal-request.php?id=<?php echo $row['id']; ?>"> <i
                                        class="font fa-solid fa-eye"></i> View </a>  
                                        </div>
                                    </div>
                                <?php endwhile; ?>
                                <?php else: ?>
									<small>No records found.</small>
									<?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
<script>
function filterOffers() {
    const searchInput = document.getElementById('searchInput').value.toLowerCase();
    const offerCards = document.querySelectorAll('.offer-card');

    offerCards.forEach(card => {
        const cardText = card.textContent.toLowerCase();
        
        if (cardText.includes(searchInput)) {
            card.style.display = ''; // Show the card
        } else {
            card.style.display = 'none'; // Hide the card
        }
    });
}
</script>


</body>
</html>
