From 4fef5556cae364dc09953073f74b0a1efb6b6042 Mon Sep 17 00:00:00 2001 From: taekyoungc Date: Thu, 25 Jun 2026 14:59:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=85=84=20=ED=8C=90=EB=A7=A4=ED=98=84?= =?UTF-8?q?=ED=99=A9=20=EC=97=91=EC=85=80=20=EC=B5=9C=EC=83=81=EB=8B=A8?= =?UTF-8?q?=EC=97=90=20=EC=A7=80=EC=97=AD/=EB=B2=94=EC=9C=84=C2=B7?= =?UTF-8?q?=EB=8B=A8=EC=9C=84=C2=B7=EC=B6=9C=EB=A0=A5=EC=9D=BC=20=EC=A0=9C?= =?UTF-8?q?=EB=AA=A9=20=EB=B8=94=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - export_excel_2003_xml 에 헤더 위 제목행(topRows) 옵션 추가(하위호환) - 년판매 export: '시도 구군 / 범위', '(단위 : 매/원)', '연도 판매현황 · 대행소', '출력일' 표기 Co-Authored-By: Claude Opus 4.8 --- app/Controllers/Admin/SalesReport.php | 27 ++++++++++++++++++++++++++- app/Helpers/export_helper.php | 12 +++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/Controllers/Admin/SalesReport.php b/app/Controllers/Admin/SalesReport.php index 5ab5460..6b40dda 100644 --- a/app/Controllers/Admin/SalesReport.php +++ b/app/Controllers/Admin/SalesReport.php @@ -1284,6 +1284,30 @@ class SalesReport extends BaseController if ($export) { $headers = array_merge(['품목', '구분'], array_map(static fn (array $c): string => (string) ($c['label'] ?? ''), $built['colSpec'])); + $colCount = count($headers); + + // 최상단 제목 블록: (지역/범위) ……… (단위 : 매/원) / (제목) ……… 출력일 + $region = trim( + (string) ($lgRow->lg_sido ?? '') . ' ' . (string) ($lgRow->lg_gugun ?? '') + ); + if ($region === '') { + $region = $lgName; + } + $makeTopRow = static function (string $left, string $right) use ($colCount): array { + $row = array_fill(0, max($colCount, 1), ''); + $row[0] = $left; + if ($right !== '') { + $row[max($colCount - 1, 0)] = $right; + } + + return $row; + }; + $topRows = [ + $makeTopRow($region . ' / ' . $gugunLabel, '(단위 : 매/원)'), + $makeTopRow($year . '년 판매현황 · 대행소: ' . $agencyLabel, '출력일: ' . date('Y-m-d')), + array_fill(0, max($colCount, 1), ''), // 구분용 빈 줄 + ]; + $exportRows = []; foreach ($built['itemBlocks'] as $block) { foreach ($block['lines'] as $li) { @@ -1306,7 +1330,8 @@ class SalesReport extends BaseController '년판매현황_' . $year . '_' . $exportStamp, $year . '년판매', $headers, - $exportRows + $exportRows, + $topRows ); } diff --git a/app/Helpers/export_helper.php b/app/Helpers/export_helper.php index bc4eddb..e6af3a4 100644 --- a/app/Helpers/export_helper.php +++ b/app/Helpers/export_helper.php @@ -76,8 +76,9 @@ if (! function_exists('export_excel_2003_xml')) { * @param string $sheetName 시트 이름(Excel 제한: 길이·일부 문자) * @param string[] $headers 컬럼 헤더 * @param array $rows 데이터 행(각 행은 배열, 값은 문자열로 출력) + * @param array $topRows 헤더 위에 추가할 제목/부제 행(각 행은 배열). 비우면 없음. */ - function export_excel_2003_xml(string $filename, string $sheetName, array $headers, array $rows): void + function export_excel_2003_xml(string $filename, string $sheetName, array $headers, array $rows, array $topRows = []): void { $filename = preg_replace('/\.[^.]+$/u', '', $filename) . '.xls'; @@ -97,6 +98,15 @@ if (! function_exists('export_excel_2003_xml')) { $parts[] = ''; $parts[] = ''; + // 상단 제목/부제 행(있을 때만) + foreach ($topRows as $topRow) { + $parts[] = ''; + foreach (array_values((array) $topRow) as $cell) { + $parts[] = '' . $esc($cell) . ''; + } + $parts[] = ''; + } + $parts[] = ''; foreach ($headers as $h) { $parts[] = '' . $esc($h) . '';