<?php 
include 'layout.php'; include 'db.php';
include 'auth.php';  

require_right('View Taxes');


?>
<div class="page-wrapper">
    <div class="content">
        <div class="page-header">
            <div class="page-title">
                <h4>Tax Rates</h4>
                <h6>Manage your tax rates</h6>
            </div>
            <div class="page-btn">
                <a href="add_tax_rate.php" class="btn btn-added"><i class="fa fa-plus"></i> Add Tax Rate</a>
            </div>
        </div>

        <div class="card">
            <div class="table-responsive">
                <table class="table datatable">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Rate (%)</th>
                            <th class="text-end">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $result = $conn->query("SELECT * FROM tax_rates ORDER BY id DESC");
                        while ($row = $result->fetch_assoc()):
                        ?>
                        <tr>
                            <td><?= $row['id'] ?></td>
                            <td><?= htmlspecialchars($row['name']) ?></td>
                            <td><?= $row['rate'] ?></td>
                            <td class="text-end">
                                <a href="edit_tax_rate.php?id=<?= $row['id'] ?>" class="btn btn-sm btn-outline-warning"><i class="fa fa-edit"></i></a>
                                <a href="delete_tax_rate.php?id=<?= $row['id'] ?>" onclick="return confirm('Delete this tax rate?')" class="btn btn-sm btn-outline-danger"><i class="fa fa-trash"></i></a>
                            </td>
                        </tr>
                        <?php endwhile; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
