query("SELECT id, full_legal_name FROM participants ORDER BY full_legal_name ASC")->fetchAll(PDO::FETCH_ASSOC);
$workers = $db->query("SELECT id, full_name FROM support_workers ORDER BY full_name ASC")->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
$error = "Failed to fetch participants or workers: " . $e->getMessage();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
if (empty($_POST['participant_id']) || empty($_POST['worker_id']) || empty($_POST['service_date'])) {
throw new Exception("Participant, Worker, and Service Date are required fields.");
}
$db = db();
$sql = "INSERT INTO service_logs (
participant_id, worker_id, service_date, ndis_line_item,
duration_minutes, service_notes, billing_status
) VALUES (
:participant_id, :worker_id, :service_date, :ndis_line_item,
:duration_minutes, :service_notes, :billing_status
)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':participant_id', $_POST['participant_id'], PDO::PARAM_INT);
$stmt->bindParam(':worker_id', $_POST['worker_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 = "Service log successfully added!";
} catch (Exception $e) {
$error = "Error: " . $e->getMessage();
}
}
?>
Log a New Service