prepare("SELECT * FROM transactions WHERE id = ? AND user_id = ?"); $stmt->execute([$id, $uid]); $item = $stmt->fetch(); if (!$item) { exit('거래를 찾을 수 없습니다.'); } $stmt = $pdo->prepare(" SELECT * FROM accounts WHERE user_id = ? AND is_active = 1 ORDER BY FIELD(account_type, 'bank', 'card', 'cash', 'other'), id ASC "); $stmt->execute([$uid]); $accounts = $stmt->fetchAll(); $stmt = $pdo->prepare(" SELECT * FROM categories WHERE user_id = ? AND is_active = 1 ORDER BY category_type, sort_order, id "); $stmt->execute([$uid]); $categories = $stmt->fetchAll(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { $payload = build_transaction_payload_from_input($_POST, $uid); update_transaction($id, $uid, $payload); redirect('/transactions.php'); } catch (Throwable $e) { $error = $e->getMessage(); } } $accountsJson = []; foreach ($accounts as $acc) { $accountsJson[] = [ 'id' => (int)$acc['id'], 'name' => $acc['account_name'], 'type' => $acc['account_type'], 'card_kind' => $acc['card_kind'] ?? null, 'billing_day' => $acc['billing_day'] ?? null, 'payment_day' => $acc['payment_day'] ?? null, 'use_credit_grace_period' => !empty($acc['use_credit_grace_period']) ? 1 : 0, ]; } require __DIR__ . '/../app/views/header.php'; ?>