getMessage(); } } $ym = $_GET['ym'] ?? ''; $accountId = (int)($_GET['account_id'] ?? 0); $q = trim($_GET['q'] ?? ''); $params = [$uid]; $where = ["i.user_id = ?"]; if ($ym !== '') { $where[] = "i.start_year_month = ?"; $params[] = $ym; } if ($accountId > 0) { $where[] = "i.account_id = ?"; $params[] = $accountId; } if ($q !== '') { $where[] = "(t.merchant_name LIKE ? OR t.description LIKE ? OR a.account_name LIKE ?)"; $like = '%' . $q . '%'; $params[] = $like; $params[] = $like; $params[] = $like; } $sql = " SELECT i.*, a.account_name, a.institution_name, t.transaction_date, t.merchant_name, t.description, COALESCE(SUM(CASE WHEN s.is_billed = 0 THEN s.principal_amount ELSE 0 END), 0) AS remaining_principal, COALESCE(SUM(CASE WHEN s.is_billed = 0 THEN s.interest_amount ELSE 0 END), 0) AS remaining_interest, COALESCE(SUM(CASE WHEN s.is_billed = 0 THEN s.total_amount ELSE 0 END), 0) AS remaining_total, COALESCE(SUM(CASE WHEN s.is_billed = 1 THEN s.total_amount ELSE 0 END), 0) AS billed_total, COALESCE(MIN(CASE WHEN s.is_billed = 0 THEN s.cycle_no ELSE NULL END), 0) AS next_cycle FROM installments i JOIN accounts a ON a.id = i.account_id JOIN transactions t ON t.id = i.transaction_id LEFT JOIN installment_schedules s ON s.installment_id = i.id WHERE " . implode(' AND ', $where) . " GROUP BY i.id, i.user_id, i.transaction_id, i.account_id, i.principal_amount, i.interest_total, i.total_billed_amount, i.installment_months, i.annual_interest_rate, i.start_year_month, i.interest_type, i.current_cycle, i.is_completed, i.prepaid_principal_amount, i.prepaid_interest_amount, i.created_at, i.updated_at, a.account_name, a.institution_name, t.transaction_date, t.merchant_name, t.description ORDER BY i.created_at DESC, i.id DESC "; $stmt = $pdo->prepare($sql); $stmt->execute($params); $installments = $stmt->fetchAll(); $stmt = $pdo->prepare(" SELECT id, account_name, institution_name FROM accounts WHERE user_id = ? AND is_active = 1 AND account_type = 'card' ORDER BY id ASC "); $stmt->execute([$uid]); $cardAccounts = $stmt->fetchAll(); require __DIR__ . '/../app/views/header.php'; ?>
| 회차 | 청구월 | 원금 | 이자 | 합계 | 상태 |
|---|---|---|---|---|---|
| = $s['cycle_no'] ?>회차 | = h($s['bill_year_month']) ?> | = won($s['principal_amount']) ?> | = won($s['interest_amount']) ?> | = won($s['total_amount']) ?> | 청구완료 미청구 |
| 회차 정보가 없습니다. | |||||