/* ============================================================================= * B08_Quantity_Milestone_Table.ts * 거리이정표 표(PLAN 244-1 · 244-13) 짜기 — 화면 없음(PLAN 302-3). * 화면(`B08_Quantity_UI_Milestone`) · 인쇄 미리보기(`B09_Draft_Print_Quantity`)가 같은 함수를 씀. * * 열 = 기준점 있음 = 2차포장 · 1차포장 (· 포장) · 비포장 + 계 포장 · 비포장 · 합계 / 없음 = 포장 · 비포장 · 합계 * 줄 = TS 짝(`…_Milestone_Calc.computeMilestone`) · 목적지 = 글(화면은 고름 표 ▾ 를 덧붙임) * ========================================================================== */ import type { DataColumn, DataTableOptions } from "@ui/ui_template_data_table"; import { computeMilestone, type Dest, type MilestoneData, type MilestoneTableRow, } from "./B08_Quantity_Milestone_Calc"; export const DEST_TEXT: Record = { start: "시점", mid: "중점" }; const KM = { kind: "number", decimals: 3, trim: true, width: 72 } as const; const ROAD = ["도로 구분 (km)"]; const SUM = ["계 (km)"]; /** 표 열(244-13) — 2차포장 열 = 기준점 있을 때만 · 기준점 없음 = 포장(2차 + 1차 + 포장) · 비포장 · 합계 · * 기준점 있음 = 거침 안 한 거래처 「포장」 값이 있으면 포장 열도 */ export function milestoneColumns(withBase: boolean, anyPaved: boolean): DataColumn[] { const roads: DataColumn[] = withBase ? [ { key: "s2", label: "2차포장", group: ROAD, ...KM }, { key: "s1", label: "1차포장", group: ROAD, ...KM }, ...(anyPaved ? [{ key: "pv", label: "포장", group: ROAD, ...KM }] : []), { key: "un", label: "비포장", group: ROAD, ...KM }, { key: "paved", label: "포장", group: SUM, ...KM }, { key: "unpaved", label: "비포장", group: SUM, ...KM }, ] : [ { key: "paved", label: "포장", group: ROAD, ...KM }, { key: "un", label: "비포장", group: ROAD, ...KM }, ]; return [ { key: "item", label: "항목", width: 134 }, { key: "company", label: "거래처 이름", width: 120 }, { key: "dest", label: "목적지", width: 72 }, ...roads, { key: "total", label: "합계", group: SUM, ...KM, width: 108 }, { key: "note", label: "비고", width: 160 }, ]; } /** 표 한 벌 — options(열 · 줄 · 이름) · rows = 짝 계산 줄(경로 id · 줄 차례 · km) · mode = 열 꼴 표 */ export function milestoneTable( data: MilestoneData, midDefaultM: number | null, ): { options: DataTableOptions; rows: MilestoneTableRow[]; mode: string } { const rows = computeMilestone(data, midDefaultM); const withBase = data.bases.length > 0; const anyPaved = rows.some((r) => r.pv > 0); return { options: { columns: milestoneColumns(withBase, anyPaved), rows: rows.map((r) => ({ ...r, dest: DEST_TEXT[r.dest] })), caption: "거리이정표", empty: "", }, rows, mode: `${withBase}:${anyPaved}`, }; }