Remove the five-step wizard, keep one large anchored calendar with year/month grids, and surface existing guarantor and remark in the detail drawer. Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
318 lines
18 KiB
PHP
318 lines
18 KiB
PHP
<?php
|
||
requireLogin();
|
||
$id = (int)($_GET['id'] ?? 0);
|
||
$stmt = $pdo->prepare('SELECT a.*, d.name AS dir_name FROM archives a JOIN directories d ON a.directory_id=d.id WHERE a.id=:id');
|
||
$stmt->execute([':id' => $id]);
|
||
$a = $stmt->fetch();
|
||
if (!$a) {
|
||
flash('error', '档案不存在');
|
||
header('Location: index.php');
|
||
exit;
|
||
}
|
||
$planAll = loadRepaymentPlans();
|
||
$planCfg = getArchiveRepaymentPlan($planAll, $id);
|
||
$repaymentPlans = $planCfg['plans'] ?? [];
|
||
$financeAll = loadFinanceConfigs();
|
||
$financeCfg = getArchiveFinanceConfig($financeAll, $id);
|
||
$status = archiveStatusWithConfig($a['end_date'], $financeCfg);
|
||
$detailKind = normalizeArchiveKind($a['archive_kind'] ?? '');
|
||
$interestPayable = calcCurrentInterest($a, $financeCfg, $repaymentPlans);
|
||
$settlementInterestPayable = $detailKind === ARCHIVE_KIND_BANK_LOAN
|
||
? calcSettlementPeriodInterest($a, $financeCfg, $repaymentPlans, date('Y-m-d'))
|
||
: 0.0;
|
||
usort($repaymentPlans, function ($x, $y) {
|
||
return strcmp((string)($x['due_date'] ?? ''), (string)($y['due_date'] ?? ''));
|
||
});
|
||
$files = $pdo->prepare('SELECT * FROM files WHERE archive_id=:a ORDER BY id DESC');
|
||
$files->execute([':a' => $id]);
|
||
$fileRows = $files->fetchAll();
|
||
|
||
/* ---------- 呈现数据(仅视觉层,不改业务语义) ---------- */
|
||
// fmtMoney/statusPillCls 在 index.php 后部才定义(本 view 在 1904 行即被 require 并 exit),此处做 guarded 兜底
|
||
if (!function_exists('fmtMoney')) {
|
||
function fmtMoney(?float $v): string
|
||
{
|
||
return $v === null ? '—' : number_format($v, 2, '.', ',');
|
||
}
|
||
}
|
||
if (!function_exists('statusPillCls')) {
|
||
function statusPillCls(string $s): string
|
||
{
|
||
return ['履行中' => 'ok', '逾期中' => 'over', '待更新' => 'pending', '已完成' => 'done'][$s] ?? 'pending';
|
||
}
|
||
}
|
||
$isDrawer = !empty($_GET['drawer']);
|
||
$dtab = (string)($_GET['dtab'] ?? 'summary');
|
||
if (!in_array($dtab, ['summary', 'plan', 'files'], true)) {
|
||
$dtab = 'summary';
|
||
}
|
||
$isAdmin = isAdmin();
|
||
$detailDirs = fetchDirectories($pdo);
|
||
$detailPathMap = dirPathMap($detailDirs);
|
||
$archivePath = (string)($detailPathMap[(int)$a['directory_id']] ?? $a['dir_name']);
|
||
$kindLabel = archiveKindLabel($detailKind);
|
||
$statusCls = statusPillCls($status);
|
||
$instLabel = $detailKind === ARCHIVE_KIND_EXTERNAL_GUARANTEE ? '债权人' : '贷款机构';
|
||
$creditLimit = $a['credit_limit'] !== null ? (float)$a['credit_limit'] : null;
|
||
$remaining = $a['remaining_limit'] !== null ? (float)$a['remaining_limit'] : null;
|
||
$paidPct = ($creditLimit !== null && $creditLimit > 0 && $remaining !== null)
|
||
? (int)round(($creditLimit - $remaining) / $creditLimit * 100)
|
||
: null;
|
||
$rateTxt = $a['annual_rate'] === null ? '—' : number_format((float)$a['annual_rate'], 2) . '%';
|
||
$interestMode = (string)($financeCfg['interest_mode'] ?? 'monthly');
|
||
$settleRule = (string)($financeCfg['settlement_rule'] ?? '');
|
||
$settleDay = (string)($financeCfg['settlement_day'] ?? '');
|
||
$modeTxt = $interestMode === 'quarterly' ? '按季计息' : ($interestMode === 'bullet' ? '到期一次性付清' : '按月计息');
|
||
if ($settleRule === 'maturity_once') {
|
||
$settleFullTxt = '到期一次性付息';
|
||
} elseif ($settleRule === 'quarterly_day') {
|
||
$settleFullTxt = $modeTxt . '(每季 ' . $settleDay . ' 日结息)';
|
||
} else {
|
||
$settleFullTxt = $modeTxt . '(结息日 ' . $settleDay . ' 日)';
|
||
}
|
||
$overdueTxt = '上浮 ' . rtrim(rtrim(number_format((float)$financeCfg['overdue_float_pct'], 2, '.', ''), '0'), '.') . '%';
|
||
$detailRemark = trim((string)($financeCfg['remark'] ?? ''));
|
||
$fileCount = count($fileRows);
|
||
|
||
$fileIco = function (string $ext): string {
|
||
$ext = strtolower($ext);
|
||
if ($ext === 'pdf') {
|
||
return 'PDF';
|
||
}
|
||
if (in_array($ext, ['xls', 'xlsx', 'csv', 'et'], true)) {
|
||
return 'XLS';
|
||
}
|
||
if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'], true)) {
|
||
return 'IMG';
|
||
}
|
||
return 'FILE';
|
||
};
|
||
|
||
$fileSizeTxt = function ($bytes): string {
|
||
$kb = ((int)$bytes) / 1024;
|
||
return $kb >= 1024 ? number_format($kb / 1024, 1) . ' MB' : number_format($kb, 1) . ' KB';
|
||
};
|
||
|
||
$renderHero = function () use ($remaining, $creditLimit, $paidPct, $rateTxt) {
|
||
?>
|
||
<div class="hero-amount" <?= ($remaining !== null && (float)$remaining === 0.0) ? 'data-zero' : '' ?>>
|
||
<div>
|
||
<div class="ha-label">剩余额度</div>
|
||
<div class="ha-value num"><?= e(fmtMoney($remaining)) ?></div>
|
||
</div>
|
||
<div class="ha-side">授信额度 <b class="num"><?= e(fmtMoney($creditLimit)) ?></b><br>已还 <b class="num"><?= $paidPct === null ? '—' : $paidPct . '%' ?></b> · 年利率 <b class="num"><?= e($rateTxt) ?></b></div>
|
||
</div>
|
||
<?php
|
||
};
|
||
|
||
$renderTimeline = function () use ($planCfg, $repaymentPlans) {
|
||
if (!($planCfg['enabled'] ?? false)) {
|
||
echo '<div class="empty">该档案未启用分期还款计划</div>';
|
||
return;
|
||
}
|
||
if (!$repaymentPlans) {
|
||
echo '<div class="empty">暂无分期还款计划</div>';
|
||
return;
|
||
}
|
||
$stateMap = [
|
||
'paid' => ['paid', 'ok', '已还'],
|
||
'delayed' => ['', 'done', '已延期'],
|
||
'overdue' => ['over', 'over', '逾期'],
|
||
'pending' => ['due', 'due', '未还'],
|
||
];
|
||
echo '<div class="timeline">';
|
||
foreach ($repaymentPlans as $p) {
|
||
$st = (string)($p['status'] ?? 'pending');
|
||
[$tl, $pillCls, $pillTxt] = $stateMap[$st] ?? $stateMap['pending'];
|
||
?>
|
||
<div class="plan-row" <?= $tl !== '' ? 'data-tl="' . $tl . '"' : '' ?>>
|
||
<span class="plan-kind"><?= e((string)($p['kind'] ?? '还款')) ?></span>
|
||
<span class="plan-date num"><?= e((string)$p['due_date']) ?></span>
|
||
<span class="pill pill--<?= $pillCls ?>"><?= $pillTxt ?></span>
|
||
<span class="plan-amt num"><?= e(fmtMoney((float)($p['amount'] ?? 0))) ?></span>
|
||
</div>
|
||
<?php
|
||
}
|
||
echo '</div>';
|
||
};
|
||
|
||
$renderFiles = function () use ($fileRows, $fileIco, $fileSizeTxt, $isAdmin) {
|
||
if (!$fileRows) {
|
||
echo '<div class="empty">暂无附件</div>';
|
||
return;
|
||
}
|
||
foreach ($fileRows as $f) {
|
||
$fid = (int)$f['id'];
|
||
$ext = (string)$f['file_ext'];
|
||
?>
|
||
<div class="file-row" style="flex-wrap:wrap;">
|
||
<span class="file-ico"><?= e($fileIco($ext)) ?></span>
|
||
<div style="min-width:0; flex:1;">
|
||
<div class="file-name"><?= e((string)$f['original_name']) ?></div>
|
||
<div class="file-meta num"><?= e($fileSizeTxt($f['file_size'])) ?></div>
|
||
</div>
|
||
<div class="file-act">
|
||
<?php if (canPreview($ext)): ?>
|
||
<form method="get" action="index.php" target="_blank" style="display:inline; margin:0;">
|
||
<input type="hidden" name="action" value="preview_file">
|
||
<input type="hidden" name="id" value="<?= $fid ?>">
|
||
<button type="submit">预览</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
<form method="get" action="index.php" style="display:inline; margin:0;">
|
||
<input type="hidden" name="action" value="download_file">
|
||
<input type="hidden" name="id" value="<?= $fid ?>">
|
||
<button type="submit">下载</button>
|
||
</form>
|
||
</div>
|
||
<?php if ($isAdmin): ?>
|
||
<div class="file-act" style="flex-basis:100%; justify-content:flex-end; margin:2px 0 0;">
|
||
<form method="post" action="index.php?action=rename_file" style="display:inline-flex; align-items:center; gap:4px; margin:0;">
|
||
<input type="hidden" name="file_id" value="<?= $fid ?>">
|
||
<input name="new_name" value="<?= e((string)pathinfo((string)$f['original_name'], PATHINFO_FILENAME)) ?>" placeholder="新文件名" required aria-label="新文件名" style="width:96px; height:24px; font-size:11.5px; padding:0 6px;">
|
||
<button type="submit">重命名</button>
|
||
</form>
|
||
<form method="get" action="index.php" style="display:inline; margin:0;" onsubmit="return confirm('确认删除?')">
|
||
<input type="hidden" name="action" value="delete_file">
|
||
<input type="hidden" name="id" value="<?= $fid ?>">
|
||
<button type="submit">删除</button>
|
||
</form>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php
|
||
}
|
||
};
|
||
|
||
$renderUpload = function () use ($id) {
|
||
?>
|
||
<form method="post" action="index.php?action=upload_file" enctype="multipart/form-data" style="margin:4px 0 0;">
|
||
<input type="hidden" name="archive_id" value="<?= $id ?>">
|
||
<input type="file" name="files[]" multiple required style="width:100%; margin-bottom:8px;">
|
||
<button type="submit" class="btn btn--plain" style="width:100%;">+ 上传附件</button>
|
||
</form>
|
||
<?php
|
||
};
|
||
|
||
$renderReminder = function (bool $flat) {
|
||
?>
|
||
<div class="setting-row" <?= $flat ? 'style="border-top:0; padding-top:0;"' : '' ?>>
|
||
<div>到期与还款提醒<div class="hint">到期前 30 / 7 天推送至经办人</div></div>
|
||
<button type="button" class="switch" role="switch" aria-checked="true" disabled aria-label="到期与还款提醒(系统默认开启)"></button>
|
||
</div>
|
||
<?php
|
||
};
|
||
|
||
/* ============================================================
|
||
抽屉模式:只输出 drawerInner 等价片段(fusion.js fetch 注入)
|
||
============================================================ */
|
||
if ($isDrawer):
|
||
?>
|
||
<div class="drawer-grip" data-grip><span></span></div>
|
||
<button type="button" class="drawer-close" data-close-drawer aria-label="关闭">✕</button>
|
||
<div class="drawer-head" data-grip>
|
||
<div class="drawer-eyebrow"><?= e($kindLabel) ?> · <span class="num">#<?= $id ?></span></div>
|
||
<div class="drawer-title"><?= e((string)$a['borrower']) ?></div>
|
||
<div class="drawer-sub"><?= e($archivePath) ?> · 附件 <?= $fileCount ?> 个 <span class="pill pill--<?= $statusCls ?>"><?= e($status) ?></span></div>
|
||
</div>
|
||
<div class="drawer-body">
|
||
<div class="seg drawer-tabs" role="tablist" aria-label="详情标签">
|
||
<button type="button" role="tab" data-dtab="summary" <?= $dtab === 'summary' ? 'data-active' : '' ?>>概要</button>
|
||
<button type="button" role="tab" data-dtab="plan" <?= $dtab === 'plan' ? 'data-active' : '' ?>>还款计划</button>
|
||
<button type="button" role="tab" data-dtab="files" <?= $dtab === 'files' ? 'data-active' : '' ?>>附件</button>
|
||
</div>
|
||
<?php if ($dtab === 'summary'): ?>
|
||
<?php $renderHero(); ?>
|
||
<div class="field-grid">
|
||
<div class="field"><label><?= $instLabel ?></label><div class="val"><?= e(trim((string)$a['loan_institution']) !== '' ? (string)$a['loan_institution'] : '—') ?></div></div>
|
||
<div class="field"><label>业务类型</label><div class="val"><?= e($kindLabel) ?></div></div>
|
||
<div class="field"><label>到期日</label><div class="val num"><?= e((string)$a['end_date'] !== '' ? (string)$a['end_date'] : '—') ?></div></div>
|
||
<div class="field"><label>结息方式</label><div class="val"><?= e($modeTxt) ?></div></div>
|
||
<div class="field"><label>当前应付利息</label><div class="val num" style="color:var(--gold);"><?= e(fmtMoney($interestPayable)) ?></div></div>
|
||
<div class="field"><label>归档路径</label><div class="val" style="font-size:12.5px;"><?= e($archivePath) ?></div></div>
|
||
<div class="field"><label>担保人</label><div class="val"><?= e(trim((string)$a['guarantor']) !== '' ? (string)$a['guarantor'] : '—') ?></div></div>
|
||
<div class="field field--full"><label>备注</label><div class="val val--note"><?= e($detailRemark !== '' ? $detailRemark : '—') ?></div></div>
|
||
</div>
|
||
<div class="section-title">提醒设置</div>
|
||
<?php $renderReminder(false); ?>
|
||
<?php elseif ($dtab === 'plan'): ?>
|
||
<div class="section-title" style="margin-top:0;">分期还款计划</div>
|
||
<?php $renderTimeline(); ?>
|
||
<div class="section-title">登记还款</div>
|
||
<a class="btn btn--plain" style="width:100%;" href="index.php?action=tasks&tab=plan">登记还款请前往任务中心 →</a>
|
||
<?php else: ?>
|
||
<div class="section-title" style="margin-top:0;">附件(<?= $fileCount ?>)</div>
|
||
<?php $renderFiles(); ?>
|
||
<?php if ($isAdmin): ?><?php $renderUpload(); ?><?php endif; ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="drawer-foot">
|
||
<a class="btn btn--primary" style="flex:1;" href="index.php?action=archive_detail&id=<?= $id ?>">全页详情</a>
|
||
<button type="button" class="btn btn--plain" data-close-drawer style="flex:1;">关闭</button>
|
||
</div>
|
||
<?php
|
||
exit;
|
||
endif;
|
||
|
||
/* ============================================================
|
||
全页模式(样板 detailPage)
|
||
============================================================ */
|
||
pageHeader($me); ?>
|
||
<div class="crumbs">
|
||
<form method="get" action="index.php" style="display:inline; margin:0;"><button type="submit">‹ 档案库</button></form>
|
||
<span>/</span><span><?= e((string)$a['name']) ?></span>
|
||
</div>
|
||
<div class="page-head">
|
||
<div>
|
||
<h1 class="page-title"><?= e((string)$a['borrower']) ?></h1>
|
||
<div class="page-sub"><?= e($kindLabel) ?> · <span class="num">#<?= $id ?></span> · <?= e($archivePath) ?> <span class="pill pill--<?= $statusCls ?>"><?= e($status) ?></span></div>
|
||
</div>
|
||
<div style="display:flex; gap:10px;">
|
||
<a class="btn btn--plain" href="index.php?action=export&mode=selected&format=xlsx&kind=all&ids=<?= $id ?>">导出</a>
|
||
<?php if ($isAdmin): ?><a class="btn btn--primary" href="index.php?action=archive_form&id=<?= $id ?>">编辑档案</a><?php endif; ?>
|
||
</div>
|
||
</div>
|
||
<div class="detail-grid">
|
||
<div>
|
||
<?php $renderHero(); ?>
|
||
<div class="section-title" style="margin-top:0;">概要</div>
|
||
<div class="field-grid">
|
||
<div class="field"><label><?= $instLabel ?></label><div class="val"><?= e((string)$a['loan_institution']) ?></div></div>
|
||
<div class="field"><label>业务类型</label><div class="val"><?= e($kindLabel) ?></div></div>
|
||
<div class="field"><label>起始日 / 到期日</label><div class="val num"><?= e((string)$a['start_date']) ?> — <?= e((string)$a['end_date']) ?></div></div>
|
||
<div class="field"><label>结息方式</label><div class="val"><?= e($settleFullTxt) ?></div></div>
|
||
<div class="field"><label>当前应付利息</label><div class="val num" style="color:var(--gold);"><?= e(fmtMoney($interestPayable)) ?></div></div>
|
||
<?php if ($detailKind === ARCHIVE_KIND_BANK_LOAN): ?>
|
||
<div class="field"><label>结息日应付利息</label><div class="val num"><?= e(fmtMoney($settlementInterestPayable)) ?></div><div class="file-meta">本结息周期整段</div></div>
|
||
<?php endif; ?>
|
||
<div class="field"><label>逾期利率上浮</label><div class="val num"><?= e($overdueTxt) ?></div></div>
|
||
<div class="field"><label>担保人</label><div class="val"><?= e(trim((string)$a['guarantor']) !== '' ? (string)$a['guarantor'] : '—') ?></div></div>
|
||
<div class="field"><label>担保类型</label><div class="val"><?= e(trim((string)$a['guarantee_type']) !== '' ? (string)$a['guarantee_type'] : '—') ?></div></div>
|
||
</div>
|
||
<div class="field field--full" style="margin-top:16px;"><label>备注</label><div class="val val--note"><?= e($detailRemark !== '' ? $detailRemark : '—') ?></div></div>
|
||
<div class="section-title">还款计划</div>
|
||
<?php $renderTimeline(); ?>
|
||
<?php if ($isAdmin): ?><div class="field-hint" style="margin-top:4px;">还款计划状态和延期调整请在“编辑档案”页面操作。</div><?php endif; ?>
|
||
</div>
|
||
<div>
|
||
<div class="side-panel">
|
||
<div class="section-title" style="margin:0 0 12px;">附件(<?= $fileCount ?>)</div>
|
||
<?php $renderFiles(); ?>
|
||
<?php if ($isAdmin): ?><?php $renderUpload(); ?><?php endif; ?>
|
||
<div class="section-title">提醒</div>
|
||
<?php $renderReminder(true); ?>
|
||
<?php if ($isAdmin): ?>
|
||
<div class="section-title">危险操作</div>
|
||
<form method="get" action="index.php" style="margin:0;">
|
||
<input type="hidden" name="action" value="request_delete_archive">
|
||
<input type="hidden" name="id" value="<?= $id ?>">
|
||
<button type="button" class="hold-btn" data-hold-delete="1" aria-label="按住以申请删除">
|
||
<span class="fill" aria-hidden="true"></span><span class="lbl">按住申请删除(双管理员审批)</span>
|
||
</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php pageFooter(); exit;
|