prepare(" SELECT s.installment_id FROM installment_schedules s JOIN installments i ON i.id = s.installment_id WHERE s.id = ? AND i.user_id = ? "); $stmt->execute([$scheduleId, $uid]); $row = $stmt->fetch(); if (!$row) { throw new RuntimeException('회차를 찾을 수 없습니다.'); } $stmt = $pdo->prepare(" UPDATE installment_schedules s JOIN installments i ON i.id = s.installment_id SET s.is_billed = 1, s.billed_at = NOW() WHERE s.id = ? AND i.user_id = ? "); $stmt->execute([$scheduleId, $uid]); recalculate_installment_status((int)$row['installment_id']); $msg = '청구완료 처리되었습니다.'; } if ($mode === 'mark_unbilled') { $scheduleId = (int)($_POST['schedule_id'] ?? 0); $stmt = $pdo->prepare(" SELECT s.installment_id FROM installment_schedules s JOIN installments i ON i.id = s.installment_id WHERE s.id = ? AND i.user_id = ? "); $stmt->execute([$scheduleId, $uid]); $row = $stmt->fetch(); if (!$row) { throw new RuntimeException('회차를 찾을 수 없습니다.'); } $stmt = $pdo->prepare(" UPDATE installment_schedules s JOIN installments i ON i.id = s.installment_id SET s.is_billed = 0, s.billed_at = NULL WHERE s.id = ? AND i.user_id = ? "); $stmt->execute([$scheduleId, $uid]); recalculate_installment_status((int)$row['installment_id']); $msg = '청구완료 취소되었습니다.'; } if ($mode === 'mark_month_all_billed' || $mode === 'mark_month_all_unbilled') { $targetYm = trim($_POST['target_ym'] ?? ''); if ($targetYm === '') { throw new RuntimeException('대상 월이 없습니다.'); } $wantBilled = ($mode === 'mark_month_all_billed'); $fromState = $wantBilled ? 0 : 1; $params = [$uid, $targetYm]; $sql = " SELECT s.id, s.installment_id FROM installment_schedules s JOIN installments i ON i.id = s.installment_id JOIN transactions t ON t.id = i.transaction_id WHERE i.user_id = ? AND s.bill_year_month = ? AND s.is_billed = ? "; $params[] = $fromState; if ($accountId > 0) { $sql .= " AND i.account_id = ? "; $params[] = $accountId; } if ($q !== '') { $sql .= " AND (t.merchant_name LIKE ? OR t.description LIKE ?) "; $like = '%' . $q . '%'; $params[] = $like; $params[] = $like; } $stmt = $pdo->prepare($sql); $stmt->execute($params); $rows = $stmt->fetchAll(); if ($rows) { $scheduleIds = array_column($rows, 'id'); $installmentIds = array_values(array_unique(array_column($rows, 'installment_id'))); $placeholders = implode(',', array_fill(0, count($scheduleIds), '?')); if ($wantBilled) { $stmt = $pdo->prepare(" UPDATE installment_schedules SET is_billed = 1, billed_at = NOW() WHERE id IN ($placeholders) "); } else { $stmt = $pdo->prepare(" UPDATE installment_schedules SET is_billed = 0, billed_at = NULL WHERE id IN ($placeholders) "); } $stmt->execute($scheduleIds); foreach ($installmentIds as $iid) { recalculate_installment_status((int)$iid); } } $msg = $wantBilled ? $targetYm . ' 조회건 전체 청구완료 처리되었습니다.' : $targetYm . ' 조회건 전체 취소되었습니다.'; } } catch (Throwable $e) { $error = $e->getMessage(); } } $params = [$uid, $ym]; $where = [ "i.user_id = ?", "s.bill_year_month = ?" ]; 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 s.id AS schedule_id, s.installment_id, s.cycle_no, s.bill_year_month, s.principal_amount, s.interest_amount, s.total_amount, s.is_billed, s.billed_at, i.installment_months, i.annual_interest_rate, a.account_name, a.institution_name, t.merchant_name, t.description FROM installment_schedules s JOIN installments i ON i.id = s.installment_id JOIN accounts a ON a.id = i.account_id JOIN transactions t ON t.id = i.transaction_id WHERE " . implode(' AND ', $where) . " ORDER BY s.is_billed ASC, a.account_name ASC, s.cycle_no ASC, s.id ASC "; $stmt = $pdo->prepare($sql); $stmt->execute($params); $list = $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(); $summaryStmt = $pdo->prepare(" SELECT COALESCE(SUM(CASE WHEN s.is_billed=0 THEN s.principal_amount ELSE 0 END),0) AS unbilled_principal, COALESCE(SUM(CASE WHEN s.is_billed=0 THEN s.interest_amount ELSE 0 END),0) AS unbilled_interest, COALESCE(SUM(CASE WHEN s.is_billed=0 THEN s.total_amount ELSE 0 END),0) AS unbilled_total, COALESCE(SUM(CASE WHEN s.is_billed=1 THEN s.total_amount ELSE 0 END),0) AS billed_total FROM installment_schedules s JOIN installments i ON i.id = s.installment_id JOIN transactions t ON t.id = i.transaction_id JOIN accounts a ON a.id = i.account_id WHERE " . implode(' AND ', $where)); $summaryStmt->execute($params); $summary = $summaryStmt->fetch(); require __DIR__ . '/../app/views/header.php'; ?>
| 카드 | 사용처 | 회차 | 청구월 | 원금 | 이자 | 합계 | 상태 | 관리 |
|---|---|---|---|---|---|---|---|---|
|
= h($row['account_name']) ?>
= h($row['institution_name']) ?>
|
= h($row['merchant_name'] ?: '-') ?>
= h($row['description'] ?: '-') ?>
연이자율 = numf($row['annual_interest_rate'], 2) ?>%
|
= intvalf($row['cycle_no']) ?> / = intvalf($row['installment_months']) ?> | = h($row['bill_year_month']) ?> | = won($row['principal_amount']) ?> | = won($row['interest_amount']) ?> | = won($row['total_amount']) ?> |
청구완료
= h(date('Y-m-d H:i', strtotime($row['billed_at']))) ?>
미청구
|
|
| 조회 결과가 없습니다. | ||||||||