206 lines
8.1 KiB
PHP
206 lines
8.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../app/lib/auth.php';
|
|
require_once __DIR__ . '/../app/lib/db.php';
|
|
require_once __DIR__ . '/../app/lib/helpers.php';
|
|
require_once __DIR__ . '/../app/lib/loan_service.php';
|
|
|
|
check_auth();
|
|
|
|
$pdo = db();
|
|
$uid = user_id();
|
|
$id = (int)($_GET['id'] ?? 0);
|
|
$error = '';
|
|
$msg = '';
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT *
|
|
FROM loans
|
|
WHERE id = ? AND user_id = ?
|
|
");
|
|
$stmt->execute([$id, $uid]);
|
|
$loan = $stmt->fetch();
|
|
|
|
if (!$loan) {
|
|
exit('대출 정보를 찾을 수 없습니다.');
|
|
}
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT * FROM accounts
|
|
WHERE user_id = ?
|
|
AND is_active = 1
|
|
AND account_type IN ('bank','cash','other')
|
|
ORDER BY id ASC
|
|
");
|
|
$stmt->execute([$uid]);
|
|
$accounts = $stmt->fetchAll();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
try {
|
|
$scheduleId = (int)($_POST['schedule_id'] ?? 0);
|
|
$accountId = !empty($_POST['account_id']) ? (int)$_POST['account_id'] : null;
|
|
$paymentDate = $_POST['payment_date'] ?? date('Y-m-d');
|
|
$description = trim($_POST['description'] ?? '') ?: null;
|
|
|
|
pay_loan_schedule($uid, $scheduleId, $accountId, $paymentDate, $description);
|
|
$msg = '상환 처리되었습니다.';
|
|
} catch (Throwable $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT
|
|
ls.*,
|
|
lp.payment_date,
|
|
lp.description AS payment_description,
|
|
lp.is_auto_generated,
|
|
lp.payment_type
|
|
FROM loan_schedules ls
|
|
LEFT JOIN loan_payments lp
|
|
ON lp.loan_schedule_id = ls.id
|
|
WHERE ls.loan_id = ?
|
|
ORDER BY ls.cycle_no ASC
|
|
");
|
|
$stmt->execute([$id]);
|
|
$schedules = $stmt->fetchAll();
|
|
|
|
$summary = get_loan_remaining_summary($id);
|
|
|
|
require __DIR__ . '/../app/views/header.php';
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="mb-0">대출 상세</h2>
|
|
<div class="d-flex gap-2">
|
|
<?php if ($loan['status'] === 'active'): ?>
|
|
<a href="/loan_prepay.php?id=<?= $loan['id'] ?>" class="btn btn-outline-danger">중도상환</a>
|
|
<?php endif; ?>
|
|
<a href="/loans.php" class="btn btn-outline-secondary">목록</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?= h($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($msg): ?>
|
|
<div class="alert alert-success"><?= h($msg) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card finance-card mb-4">
|
|
<div class="card-body">
|
|
<div class="eyebrow"><?= h($loan['lender_name'] ?: '-') ?></div>
|
|
<div class="card-title-lg"><?= h($loan['loan_name']) ?></div>
|
|
|
|
<div class="row g-3 mt-2">
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-label">원금</div>
|
|
<div class="stat-value"><?= won($loan['principal_amount']) ?></div>
|
|
</div>
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-label">연이자율</div>
|
|
<div class="stat-value"><?= h((string)$loan['annual_interest_rate']) ?>%</div>
|
|
</div>
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-label">거치기간</div>
|
|
<div class="stat-value"><?= h((string)$loan['grace_period_months']) ?>개월</div>
|
|
</div>
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-label">상환기간</div>
|
|
<div class="stat-value"><?= h((string)$loan['repayment_months']) ?>개월</div>
|
|
</div>
|
|
|
|
<div class="col-6 col-md-4">
|
|
<div class="stat-label">남은 원금</div>
|
|
<div class="stat-value"><?= won($summary['remaining_principal']) ?></div>
|
|
</div>
|
|
<div class="col-6 col-md-4">
|
|
<div class="stat-label">남은 이자</div>
|
|
<div class="stat-value text-danger"><?= won($summary['remaining_interest']) ?></div>
|
|
</div>
|
|
<div class="col-6 col-md-4">
|
|
<div class="stat-label">남은 총액</div>
|
|
<div class="stat-value"><?= won($summary['remaining_total']) ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card finance-card">
|
|
<div class="card-body mobile-scroll">
|
|
<table class="table align-middle mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>회차</th>
|
|
<th>납부일</th>
|
|
<th>구간</th>
|
|
<th class="text-end">기초원금</th>
|
|
<th class="text-end">원금</th>
|
|
<th class="text-end">이자</th>
|
|
<th class="text-end">합계</th>
|
|
<th class="text-end">기말원금</th>
|
|
<th>상태</th>
|
|
<th>처리</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($schedules as $s): ?>
|
|
<tr>
|
|
<td><?= $s['cycle_no'] ?></td>
|
|
<td><?= h($s['due_date']) ?></td>
|
|
<td><?= $s['payment_phase'] === 'grace' ? '거치' : '상환' ?></td>
|
|
<td class="text-end"><?= won($s['opening_principal']) ?></td>
|
|
<td class="text-end"><?= won($s['scheduled_principal']) ?></td>
|
|
<td class="text-end text-danger"><?= won($s['scheduled_interest']) ?></td>
|
|
<td class="text-end fw-bold"><?= won($s['scheduled_total']) ?></td>
|
|
<td class="text-end"><?= won($s['closing_principal']) ?></td>
|
|
<td>
|
|
<?php if ((int)$s['is_paid'] === 1): ?>
|
|
<?php if ((int)($s['is_auto_generated'] ?? 0) === 1): ?>
|
|
<span class="badge text-bg-info">자동반영</span>
|
|
<?php else: ?>
|
|
<span class="badge text-bg-success">납부완료</span>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($s['payment_date'])): ?>
|
|
<div class="small text-secondary mt-1"><?= h($s['payment_date']) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($s['payment_description'])): ?>
|
|
<div class="small text-secondary"><?= h($s['payment_description']) ?></div>
|
|
<?php endif; ?>
|
|
<?php else: ?>
|
|
<span class="badge text-bg-secondary">예정</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<?php if ((int)$s['is_paid'] === 0): ?>
|
|
<form method="post" class="d-flex flex-column gap-2">
|
|
<input type="hidden" name="schedule_id" value="<?= $s['id'] ?>">
|
|
<select name="account_id" class="form-select form-select-sm">
|
|
<option value="">출금계좌</option>
|
|
<?php foreach ($accounts as $acc): ?>
|
|
<option value="<?= $acc['id'] ?>"><?= h($acc['account_name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<input type="date" name="payment_date" class="form-control form-control-sm" value="<?= date('Y-m-d') ?>">
|
|
<button class="btn btn-sm btn-primary">상환처리</button>
|
|
</form>
|
|
<?php else: ?>
|
|
-
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
|
|
<?php if (!$schedules): ?>
|
|
<tr>
|
|
<td colspan="10" class="text-center text-secondary py-5">스케줄이 없습니다.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require __DIR__ . '/../app/views/footer.php'; ?>
|