feat: 맞춤 집계표 엑셀 다운로드 추가
- 조회 폼에 '엑셀저장' 버튼(현재 컬럼·필터·제목·집계방식 그대로 반영) - Excel 2003 XML로 제목·기간·품목구분 머리행 + 선택 컬럼 + 합계행 출력 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3556,6 +3556,38 @@ class SalesReport extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
// 엑셀 다운로드 — 현재 컬럼·필터·제목 그대로
|
||||
if ((string) ($this->request->getGet('export') ?? '') === '1') {
|
||||
$headers = array_map(static fn ($k) => self::CUSTOM_REPORT_COLUMNS[$k]['label'], $selected);
|
||||
$exportRows = [];
|
||||
foreach ($rows as $row) {
|
||||
$line = [];
|
||||
foreach ($selected as $key) {
|
||||
$isNum = (self::CUSTOM_REPORT_COLUMNS[$key]['type'] ?? '') === 'num';
|
||||
$line[] = $isNum ? number_format((int) ($row[$key] ?? 0)) : (string) ($row[$key] ?? '');
|
||||
}
|
||||
$exportRows[] = $line;
|
||||
}
|
||||
// 합계 행
|
||||
$totalLine = [];
|
||||
foreach ($selected as $i => $key) {
|
||||
$isNum = (self::CUSTOM_REPORT_COLUMNS[$key]['type'] ?? '') === 'num';
|
||||
if ($i === 0) {
|
||||
$totalLine[] = '합계';
|
||||
} else {
|
||||
$totalLine[] = $isNum ? number_format((int) ($totals[$key] ?? 0)) : '';
|
||||
}
|
||||
}
|
||||
$exportRows[] = $totalLine;
|
||||
|
||||
$fileTitle = $title !== '' ? $title : '맞춤집계표';
|
||||
$topRows = [
|
||||
[$fileTitle],
|
||||
['조회기간: ' . $startDate . ' ~ ' . $endDate . ' / 품목구분: ' . $this->customReportCategoryLabel($category)],
|
||||
];
|
||||
export_excel_2003_xml($fileTitle . '_' . $startDate . '_' . $endDate, mb_substr($fileTitle, 0, 31), $headers, $exportRows, $topRows);
|
||||
}
|
||||
|
||||
return $this->renderWorkPage('맞춤 집계표', 'admin/sales_report/custom_report', [
|
||||
'columnCatalog' => self::CUSTOM_REPORT_COLUMNS,
|
||||
'selected' => $selected,
|
||||
|
||||
@@ -32,6 +32,7 @@ $nf = static fn ($n): string => number_format((int) $n);
|
||||
<section class="p-3 bg-white border-b border-gray-200 no-print">
|
||||
<form method="get" action="<?= mgmt_url('reports/custom') ?>" id="custom-report-form" class="space-y-3">
|
||||
<input type="hidden" name="applied" value="1"/>
|
||||
<input type="hidden" name="export" id="cr-export" value="0"/>
|
||||
<div class="flex flex-wrap items-end gap-3 text-sm">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-gray-600 mb-1">표 제목</label>
|
||||
@@ -60,7 +61,8 @@ $nf = static fn ($n): string => number_format((int) $n);
|
||||
<option value="summary" <?= $mode === 'summary' ? 'selected' : '' ?>>품목별 집계</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="bg-btn-search text-white px-4 py-1.5 rounded-sm text-sm shadow hover:opacity-90">조회</button>
|
||||
<button type="submit" onclick="document.getElementById('cr-export').value='0'" class="bg-btn-search text-white px-4 py-1.5 rounded-sm text-sm shadow hover:opacity-90">조회</button>
|
||||
<button type="submit" onclick="document.getElementById('cr-export').value='1'" class="border border-btn-excel-border text-btn-excel-text px-4 py-1.5 rounded-sm text-sm hover:bg-green-50 transition">엑셀저장</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user