query('SELECT * FROM archives ORDER BY id DESC')->fetchAll(); $financeAll = loadFinanceConfigs(); $planAll = loadRepaymentPlans(); $quickStats = qqBuildPayableInterestData($rowsAll, $financeAll, $planAll); $instRows = $quickStats['instRows']; $planRows = $quickStats['planRows']; $planTotal = (float)($quickStats['planTotal'] ?? 0); if ($exportFormat === 'xlsx' && class_exists('\PhpOffice\PhpSpreadsheet\Spreadsheet') && class_exists('\PhpOffice\PhpSpreadsheet\Writer\Xlsx')) { $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $sheet1 = $spreadsheet->getActiveSheet(); $sheet1->setTitle('机构利息汇总'); $sheet1->fromArray(['机构', '笔数(履行+逾期)', '当前应付利息', '结息日', '结息日应付利息'], null, 'A1'); $sheet1->fromArray(array_map(fn($x) => [$x['loan_institution'], $x['loan_count'], amount((float)$x['current_interest']), (string)($x['settlement_date'] ?? ''), amount((float)$x['settlement_interest'])], $instRows), null, 'A2'); foreach (range('A', 'E') as $col) { $sheet1->getColumnDimension($col)->setWidth(24); } $sheet2 = $spreadsheet->createSheet(); $sheet2->setTitle('当月还款计划'); $sheet2->fromArray(['机构', '档案名称', '借款主体', '到期日', '金额', '状态'], null, 'A1'); $sheet2->fromArray(array_map(fn($x) => [$x['loan_institution'], $x['archive_name'], $x['borrower'], $x['due_date'], amount((float)$x['amount']), $x['status']], $planRows), null, 'A2'); $sheet2->setCellValue('A' . (count($planRows) + 3), '合计'); $sheet2->setCellValue('E' . (count($planRows) + 3), amount($planTotal)); foreach (range('A', 'F') as $col) { $sheet2->getColumnDimension($col)->setWidth(22); } header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="' . rawurlencode('应付本息查询_' . date('Y-m-d') . '.xlsx') . '"'); (new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet))->save('php://output'); exit; } /* 视觉层辅助在 index.php 尾部(本组页面 require 点之后)定义,这里做呈现级兜底 */ if (!function_exists('fmtMoney')) { function fmtMoney(?float $v): string { return $v === null ? '—' : number_format($v, 2, '.', ','); } } pageHeader($me); ?>

统计查询

便捷统计 · 四个口径
总金额 应付本息 对外担保 历史还款
当月计划 笔 · 合计 元 导出 xlsx
机构应付利息统计
$r): $sumCur += (float)$r['current_interest']; $sumSettle += (float)$r['settlement_interest']; ?>
贷款机构在保笔数当前应付利息结息日结息日应付利息
合计 (int)$x['loan_count'], $instRows)) ?> —
暂无履行中或逾期中的银行贷款
当月还款计划()
'due', 'overdue' => 'over', 'delayed' => 'done', 'paid' => 'ok'][$pst] ?? 'due'; $pillTxt = ['pending' => '未还', 'overdue' => '逾期', 'delayed' => '已延期', 'paid' => '已还款'][$pst] ?? '未还'; ?>
·
当月无还款计划