<?php
include 'db.php';
include 'auth.php';
require_right('Create Taxes');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $rate = (float) $_POST['rate'];

    $stmt = $conn->prepare("INSERT INTO tax_rates (name, rate) VALUES (?, ?)");
    $stmt->bind_param("sd", $name, $rate);
    $stmt->execute();

    header("Location: tax_rate_list.php");
    exit;
}

include 'layout.php';
?>
<div class="page-wrapper">
    <div class="content">
        <div class="page-header"><div class="page-title"><h4>Add Tax Rate</h4></div></div>
        <form method="POST">
            <input type="text" name="name" class="form-control mb-3" placeholder="Tax Name" required>
            <input type="number" step="0.01" name="rate" class="form-control mb-3" placeholder="Rate %" required>
            <div class="text-end">
                <button type="submit" class="btn btn-primary">Save Tax Rate</button>
            </div>
        </form>
    </div>
</div>
