命 理
奇
奇 門
Kỳ Môn Phối Bát Tự · Bản Mệnh — Đại Vận — Lưu Niên — Lưu Nguyệt

立 命 · LẬP BẢN MỆNH CỤC (theo giờ sinh)

Lưu ý: mốc tiết khí trong công cụ này dùng ngày dương xấp xỉ (đủ chính xác cho phần lớn trường hợp), không thay thế lịch vạn niên chuẩn khi giờ sinh nằm sát ranh giới đổi tiết.

奇門 Nhập ngày giờ rồi bấm LẬP BÀN để khởi cục.
`; } function exportToWord(){ const html = buildReportHTML(); if (!html){ alert('Hãy Lập Bản Mệnh Cục trước khi xuất file.'); return; } const blob = new Blob(['\ufeff', html], { type: 'application/msword' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); const b = state.b; const fname = `Luan_KyMon_${b.__d}-${b.__m}-${b.__y}.doc`; a.href = url; a.download = fname; document.body.appendChild(a); a.click(); document.body.removeChild(a); setTimeout(()=>URL.revokeObjectURL(url), 3000); } /* ============================================================ 15. UI WIRING ============================================================ */ const opts = {dunType:'time', boardType:'zhuan', gender:'nam', nguyenMethod:'trinhuan'}; document.querySelectorAll('#optToggles .toggle').forEach(btn=>{ btn.addEventListener('click', ()=>{ const optKey = btn.dataset.opt; const val = btn.dataset.val; document.querySelectorAll(`#optToggles .toggle[data-opt="${optKey}"]`).forEach(b=>b.classList.remove('on')); btn.classList.add('on'); if (optKey==='dunType') opts.dunType = val; if (optKey==='board') opts.boardType = val; if (optKey==='nguyenMethod') opts.nguyenMethod = val; if (optKey==='gender'){ opts.gender = val; if (state.b){ state.daiVanCur = null; document.getElementById('daivanDetailBox')?.remove(); renderDaiVan(state.b, opts.gender); applyHighlights(); renderTongHop(); } } }); }); document.getElementById('btnNow').addEventListener('click',()=>{ const now = new Date(); document.getElementById('yy').value = now.getFullYear(); document.getElementById('mo').value = now.getMonth()+1; document.getElementById('dd').value = now.getDate(); document.getElementById('hh').value = now.getHours(); document.getElementById('mi').value = now.getMinutes(); }); document.getElementById('btnGo').addEventListener('click', ()=>{ const y = parseInt(document.getElementById('yy').value); const m = parseInt(document.getElementById('mo').value); const d = parseInt(document.getElementById('dd').value); const h = parseInt(document.getElementById('hh').value); const mi = parseInt(document.getElementById('mi').value); const tz = parseInt(document.getElementById('tz').value); document.getElementById('empty').style.display='none'; document.getElementById('result').style.display='block'; document.getElementById('pillars').innerHTML = renderPillars( computeBan({y,m,d,h,mi,tz, dunType:opts.dunType, boardType:opts.boardType, nguyenMethod:'trinhuan'}) ); if (opts.nguyenMethod === 'both'){ document.getElementById('singleView').style.display = 'none'; document.getElementById('dualView').style.display = 'block'; const b = renderDualView(y,m,d,h,mi,tz); setupMenhLy(b, y,m,d,h,mi,tz); } else { document.getElementById('singleView').style.display = 'block'; document.getElementById('dualView').style.display = 'none'; const b = computeBan({y,m,d,h,mi,tz, dunType:opts.dunType, boardType:opts.boardType, nguyenMethod:opts.nguyenMethod}); b.__y=y; b.__m=m; b.__d=d; b.__h=h; b.__mi=mi; b.__tz=tz; document.getElementById('meta').innerHTML = renderMeta(b); document.getElementById('board').innerHTML = renderBoard(b); document.getElementById('legend').innerHTML = renderLegend(b); document.getElementById('interpret').innerHTML = renderInterpret(b); setupMenhLy(b, y,m,d,h,mi,tz); } document.getElementById('result').scrollIntoView({behavior:'smooth', block:'start'}); }); function setupMenhLy(b, y,m,d,h,mi,tz){ b.__y=y; b.__m=m; b.__d=d; b.__h=h; b.__mi=mi; b.__tz=tz; state.b = b; state.daiVanCur = null; state.luuNienCur = null; state.luuNguyetCur = null; document.getElementById('daivanDetailBox')?.remove(); document.getElementById('menhchuBox').innerHTML = renderMenhChu(b); renderDaiVan(b, opts.gender); document.getElementById('luuNienBox').innerHTML = ''; document.getElementById('luuNguyetBox').innerHTML = ''; document.getElementById('tonghopBox').innerHTML = ''; applyHighlights(); } function renderDualView(y,m,d,h,mi,tz){ const bTN = computeBan({y,m,d,h,mi,tz, dunType:opts.dunType, boardType:opts.boardType, nguyenMethod:'trinhuan'}); const bSB = computeBan({y,m,d,h,mi,tz, dunType:opts.dunType, boardType:opts.boardType, nguyenMethod:'saibo'}); const diff = (bTN.juNum!==bSB.juNum || bTN.isYang!==bSB.isYang); document.getElementById('dualNote').innerHTML = diff ? `

⚠ Hai phương pháp cho Cục Số khác nhau ở ngày giờ này:

Trí Nhuận pháp: ${bTN.isYang?'Dương':'Âm'} Độn Cục ${bTN.juNum} (${['Thượng','Trung','Hạ'][bTN.nguyen]} nguyên)

Sài Bổ pháp (ước tính): ${bSB.isYang?'Dương':'Âm'} Độn Cục ${bSB.juNum} (${['Thượng','Trung','Hạ'][bSB.nguyen]} nguyên)

Vì Cục Số khác nhau, cách sắp Lục Nghi Tam Kỳ trên hai bàn dưới đây sẽ khác hẳn nhau. Sài Bổ pháp ở đây là bản ước tính theo ngày dương lịch xấp xỉ của tiết khí — sát ranh giới Nguyên có thể lệch so với phần mềm dùng giờ tiết khí thiên văn chính xác.

` : `

Ở ngày giờ này, hai phương pháp cho cùng một Cục Số (${bTN.isYang?'Dương':'Âm'} Độn Cục ${bTN.juNum}) — hai bàn dưới đây sẽ giống hệt nhau. Sự khác biệt giữa hai phương pháp chỉ lộ rõ ở những ngày nằm gần ranh giới đổi Nguyên.

`; document.getElementById('dualGrid').innerHTML = [ {label:'甲 · Trí Nhuận pháp (bảng cố định 60 Giáp Tý)', b:bTN}, {label:'拆 · Sài Bổ pháp — ước tính (liên tục theo ngày)', b:bSB} ].map(item=>`

${item.label}

${renderMeta(item.b)}
${renderBoard(item.b)}
${renderLegend(item.b)}
`).join(''); return bTN; // dùng làm bản chính cho Đại Vận / Lưu Niên / Lưu Nguyệt } document.getElementById('btnExportWord').addEventListener('click', exportToWord); document.getElementById('btnLuuNien').addEventListener('click', ()=>{ if (!state.b){ alert('Hãy lập Bản Mệnh Cục trước.'); return; } const year = parseInt(document.getElementById('lnYear').value); renderLuuNien(state.b, year); }); document.getElementById('btnLuuNguyet').addEventListener('click', ()=>{ if (!state.luuNienCur){ alert('Hãy xem Lưu Niên trước để chọn đúng năm.'); return; } const month = parseInt(document.getElementById('lnMonth').value); const day = parseInt(document.getElementById('lnDay').value) || 15; renderLuuNguyet(state.b, state.luuNienCur.year, month, day); });