prepare("SELECT * FROM accounts WHERE user_id = ? AND is_active = 1 ORDER BY id"); $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 { $mode = $_POST['mode'] ?? 'create'; if ($mode === 'apply_month') { $ym = $_POST['ym'] ?? date('Y-m'); $count = apply_recurring_transactions_for_month($uid, $ym, true); $msg = $ym . ' 적용 완료: ' . $count . '건 입력'; } else { $stmt = $pdo->prepare(" INSERT INTO recurring_transactions (user_id, account_id, category_id, transaction_type, amount, day_of_month, merchant_name, description, related_account_id, is_active) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 1) "); $stmt->execute([ $uid, (int)$_POST['account_id'], (int)$_POST['category_id'], $_POST['transaction_type'], (float)$_POST['amount'], (int)$_POST['day_of_month'], trim($_POST['merchant_name'] ?? '') ?: null, trim($_POST['description'] ?? '') ?: null, !empty($_POST['related_account_id']) ? (int)$_POST['related_account_id'] : null, ]); redirect('/recurring.php'); } } catch (Throwable $e) { $error = $e->getMessage(); } } $stmt = $pdo->prepare("SELECT rt.*, a.account_name, c.name AS category_name, ra.account_name AS related_name FROM recurring_transactions rt JOIN accounts a ON rt.account_id = a.id JOIN categories c ON rt.category_id = c.id LEFT JOIN accounts ra ON rt.related_account_id = ra.id WHERE rt.user_id = ? ORDER BY rt.day_of_month, rt.id"); $stmt->execute([$uid]); $list = $stmt->fetchAll(); require __DIR__ . '/../app/views/header.php'; ?>

고정지출 / 고정거래

일자 유형 계좌 관련 카테고리 금액 마지막 적용월