import { state } from '../../core/state'; import { openSwDashboardDetail, openSwUsageDetail } from '../../components/Modal/DashboardDetailModal'; import { normalizeDate } from '../../core/utils'; import { ASSET_SCHEMA } from '../../core/schema'; export function renderSwDashboard(container: HTMLElement) { let extQty = 0, extUsed = 0, extExp = 0, extTotal = 0; let intQty = 0, intUsed = 0, intExp = 0, intTotal = 0; let extCost2026 = 0; let intCost2026 = 0; // 통합 SW 데이터 const allSw = [...state.masterData.swExternal, ...state.masterData.swInternal]; allSw.forEach(sw => { const assigned = state.masterData.swUsers.filter(u => u.sw_id === sw.id).length; const qty = typeof sw[ASSET_SCHEMA.ASSET_COUNT.key] === 'number' ? sw[ASSET_SCHEMA.ASSET_COUNT.key] : parseInt(sw[ASSET_SCHEMA.ASSET_COUNT.key]||'0', 10); const priceStr = sw[ASSET_SCHEMA.PURCHASE_AMOUNT.key] ? String(sw[ASSET_SCHEMA.PURCHASE_AMOUNT.key]).replace(/,/g, '') : '0'; const price = parseInt(priceStr, 10) || 0; if (sw.asset_type === '외부SW' || sw.type === '외부SW') { extQty += qty; extUsed += assigned; extTotal++; if (isSWExpiring(sw)) extExp++; if (sw[ASSET_SCHEMA.PURCHASE_DATE.key]?.startsWith('2026')) extCost2026 += price; } else { intQty += qty; intUsed += assigned; intTotal++; if (sw[ASSET_SCHEMA.PURCHASE_DATE.key]?.startsWith('2026')) intCost2026 += price; } }); const extPer = extQty > 0 ? Math.round((extUsed/extQty)*100) : 0; const intPer = intQty > 0 ? Math.round((intUsed/intQty)*100) : 0; container.innerHTML = `