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

header('Content-Type: application/json');

$name  = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');

if ($name === '') {
    echo json_encode(['success' => false, 'message' => 'Name is required.']);
    exit;
}

$stmt = $conn->prepare("INSERT INTO customers (name, email, phone) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $name, $email, $phone);
if ($stmt->execute()) {
    echo json_encode(['success' => true, 'message' => 'Customer added successfully.']);
} else {
    echo json_encode(['success' => false, 'message' => 'Error: ' . $conn->error]);
}
$stmt->close();

    header("Location: pos.php?status=error");
    exit();
?>


