<?php
include 'db.php';

$id = $_POST['id'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$address = $_POST['address'];
$province = $_POST['province'];
$category_id = $_POST['category_id'] ?: 'NULL';
$is_walk_in = isset($_POST['is_walk_in']) ? 1 : 0;
$active = isset($_POST['active']) ? 1 : 0;
$discount_applied = isset($_POST['discount_applied']) ? 'Y' : 'N';
$discount_rate = floatval($_POST['discount_rate'] ?? 0);

$stmt = $conn->prepare("UPDATE customers SET name=?, phone=?, email=?, address=?, province=?, category_id=?, is_walk_in=?, active=?, discount_applied=?, discount_rate=? WHERE id=?");
$stmt->bind_param("ssssssiiisd", $name, $phone, $email, $address, $province, $category_id, $is_walk_in, $active, $discount_applied, $discount_rate, $id);
$stmt->execute();

header("Location: customer_list.php?success=1");
exit;
