<?php
header('Content-Type: application/json');
include '../db.php';

try {
    // Fetch active discounts
    $stmt = $conn->prepare("SELECT * FROM discounts WHERE is_active = 1 ORDER BY discount_name");
    $stmt->execute();
    $result = $stmt->get_result();
    
    $discounts = [];
    while ($row = $result->fetch_assoc()) {
        $discounts[] = $row;
    }
    
    echo json_encode([
        'success' => true,
        'discounts' => $discounts
    ]);
    
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => 'Error fetching discounts: ' . $e->getMessage()
    ]);
}
?>
