<!-- ?php
$categories = $conn->query("SELECT * FROM categories");
$sub_categories = $conn->query("SELECT * FROM sub_categories");
?>
<input type="text" name="item_code" class="form-control mb-3" placeholder="Item Code" value="<?= $item['item_code'] ?? '' ?>" required>
<input type="text" name="sku_number" class="form-control mb-3" placeholder="SKU Number" value="<?= $item['sku_number'] ?? '' ?>" required>
<input type="text" name="name" class="form-control mb-3" placeholder="Item Name" value="<?= $item['name'] ?? '' ?>" required>

<select name="category_id" class="form-control mb-3" required>
    <option value="">Select Category</option>
    <?php while ($cat = $categories->fetch_assoc()): ?>
        <option value="<?= $cat['id'] ?>" <?= ($item['category_id'] ?? '') == $cat['id'] ? 'selected' : '' ?>><?= $cat['name'] ?></option>
    <?php endwhile; ?>
</select>

<select name="sub_category_id" class="form-control mb-3">
    <option value="">Select Sub Category</option>
    <?php while ($sub = $sub_categories->fetch_assoc()): ?>
        <option value="<?= $sub['id'] ?>" <?= ($item['sub_category_id'] ?? '') == $sub['id'] ? 'selected' : '' ?>><?= $sub['name'] ?></option>
    <?php endwhile; ?>
</select>

<input type="number" step="0.01" name="retail_price" class="form-control mb-3" placeholder="Retail Price" value="<?= $item['retail_price'] ?? '' ?>" required>
<label>Cost Price <small class="text-muted">(Default: 0.00)</small></label>
<input type="number" step="0.01" min="0" name="cost_price" class="form-control mb-3" placeholder="Cost Price" value="<?= $item['cost_price'] ?? '0.00' ?>" required>
<small class="text-muted">Enter 0.00 if cost is unknown, or enter the actual cost</small>
<input type="number" name="reorder_quantity" class="form-control mb-3" placeholder="Reorder Quantity" value="<?= $item['reorder_quantity'] ?? 0 ?>">
<input type="number" name="reorder_level" class="form-control mb-3" placeholder="Reorder Level" value="<?= $item['reorder_level'] ?? 0 ?>">
<select name="tax_type" class="form-control mb-3" required>
    <option value="">Select Tax Type</option>
    <?php foreach (["included", "excluded", "nil"] as $type): ?>
        <option value="<?= $type ?>" <?= (isset($item['tax_type']) && $item['tax_type'] == $type) ? 'selected' : '' ?>><?= ucfirst($type) ?></option>
    <?php endforeach; ?>
</select>
<select name="tax_rate_id" class="form-control mb-3">
    <option value="">Select Tax Rate</option>
    <?php while($rate = $tax_rates->fetch_assoc()): ?>
        <option value="<?= $rate['id'] ?>" <?= (isset($item['tax_rate_id']) && $item['tax_rate_id'] == $rate['id']) ? 'selected' : '' ?>>
            <?= $rate['name'] ?> (<?= $rate['rate'] ?>%)
        </option>
    <?php endwhile; ?>
</select> -->
