query("SELECT id, full_legal_name FROM clients ORDER BY full_legal_name ASC")->fetchAll(PDO::FETCH_ASSOC);
$care_staff = $db->query("SELECT id, full_name FROM care_staff ORDER BY full_name ASC")->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
$error = "Failed to fetch clients or care staff: " . $e->getMessage();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
if (empty($_POST['client_id']) || empty($_POST['staff_id']) || empty($_POST['service_date'])) {
throw new Exception("Client, Care Staff, and Service Date are required fields.");
}
$db = db();
$sql = "INSERT INTO bookings (
client_id, staff_id, service_date, ndis_line_item,
duration_minutes, service_notes, billing_status
) VALUES (
:client_id, :staff_id, :service_date, :ndis_line_item,
:duration_minutes, :service_notes, :billing_status
)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':client_id', $_POST['client_id'], PDO::PARAM_INT);
$stmt->bindParam(':staff_id', $_POST['staff_id'], PDO::PARAM_INT);
$stmt->bindParam(':service_date', $_POST['service_date']);
$stmt->bindParam(':ndis_line_item', $_POST['ndis_line_item']);
$stmt->bindParam(':duration_minutes', $_POST['duration_minutes'], PDO::PARAM_INT);
$stmt->bindParam(':service_notes', $_POST['service_notes']);
$stmt->bindParam(':billing_status', $_POST['billing_status']);
$stmt->execute();
$message = "Booking successfully added!";
} catch (Exception $e) {
$error = "Error: " . $e->getMessage();
}
}
?>
Log a New Booking