Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 06:45 UTC
arena/094f314c-aram
add-index-html-10623938925177053894
arena/094f314c-aram
chatgpt-phase1b2-autopilot
codex/adr-future-connectors-pi-v1
codex/aram-account-note-source-trace-20261031
codex/aram-actions-node24-maintenance-20261031
codex/aram-analyst-review-workbook-20261031
codex/aram-bs-candidate-statement-20261031
codex/aram-cash-flow-direct-candidate-20261031
codex/aram-clean-reference-year-integrity-20261030
codex/aram-cross-statement-controls-20261031
codex/aram-equity-changes-candidate-20261031
codex/aram-five-statement-cli-20261031
codex/aram-five-statement-integration-20261031
codex/aram-five-statement-orchestrator-20261031
codex/aram-gate3-coverage-target-guard-20261030
codex/aram-gate3-hidden-xlsx-guard-20261030
codex/aram-gate3-integration-validation-20261030
codex/aram-gate3-mapping-change-preview-20261030
codex/aram-gate3-stale-note-guard-20261030
codex/aram-income-statement-candidate-20261031
codex/aram-manifest-referential-integrity-20261031
codex/aram-mapping-source-parser-20261101
codex/aram-multidimensional-mapping-20261101
codex/aram-multistatement-mapping-20261031
codex/aram-pipeline-manifest-schema-20261031
codex/aram-readonly-mapping-coverage-20261031
codex/aram-reconciliation-review-gate-20261031
codex/aram-same-flush-fiscal-lock-20261030
codex/aram-synthetic-windows-demo-20261031
codex/aram-trial-balance-diagnostic-20261031
codex/aram-windows-background-detail-search-20261031
codex/aram-windows-detail-review-20261031
codex/aram-windows-five-statement-pilot-20261031
codex/aram-windows-statement-figures-20261031
codex/gate-2a-pilot-workbook
codex/gate-2a-pilot-workbook-6864754244772568979
codex/gate3-authenticated-principal-boundary-20261030
codex/gate3-authored-draft-staging-20261030
codex/gate3-carry-forward-preview-20261023
codex/gate3-draft-staging-audit-20261030
codex/gate3-mapping-batch-freshness-20261030
codex/gate3-mapping-batch-review-20261030
codex/gate3-mapping-core
codex/gate3-mapping-coverage-20261023
codex/gate3-mapping-excel-20261023
codex/gate3-note-mapping-review-20261023
codex/gate3-signed-year-scope-20261030
codex/gate3-unapproved-proposal-storage-20261030
codex/payvast-mapping-discovery-20261023
codex/phase-2a-backend-foundation
codex/phase-2b-post-merge-record
codex/phase-2b-source-registration
codex/phase-2b-source-registration-12955190277775369594
codex/post-gate2a-control-reconciliation
codex/post-pr18-acceptance-record
codex/project-control-foundation
codex/t1-repo-hygiene-20261023
codex/t2-ci-hardening-20261023
codex/t3-explicit-migrations-20261023
codex/t6a-readonly-diagnostics-20261023
codex/v1-01-safety-gate-hardening
codex/v1-year-isolation-followup-20261023
codex/windows-native-pilot-shell-20261030
docs/aram-master-control-plan-20261111
docs/aram-roadmap-dashboard-20261030
docs/financial-statement-reconciliation-1402-1404-20261110
feat/gate3-governed-mapping-20261101
feat/gate3-package9-1-security-20261103
feat/gate3-package9-isolated-20261103
fix/password-unicode-validation-20261111
governance/aram-5-1-3-controls-20261030
governance/role-based-operating-model
jules-1168663913887856558-73b8a885
jules-gate-2b-mapping-workflow-foundation-4137724387867065330
phase-1b1-audit-report-7365389436990903239
phase-2a-backend-foundation-10237597358138521261
phase1b2-postmerge-metadata-fix
refactor/drg-parent-year-id-15088443704684163304
source-data-cleanup
| 1 | /* Aram Pilot Workbench — mobile-first, vanilla JS, RTL, no external deps. */ |
| 2 | "use strict"; |
| 3 | |
| 4 | const API = "/api/v1/pilot"; |
| 5 | const S = { |
| 6 | meta: null, data: null, tab: "dashboard", |
| 7 | filter: "all", search: "", noteSearch: "", |
| 8 | statementView: "BS", expanded: new Set(), |
| 9 | }; |
| 10 | |
| 11 | const $ = (s) => document.querySelector(s); |
| 12 | const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ( |
| 13 | { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c] |
| 14 | )); |
| 15 | function fmt(v) { |
| 16 | if (v === null || v === undefined || v === "") return "—"; |
| 17 | let s = String(v); const neg = s.startsWith("-"); if (neg) s = s.slice(1); |
| 18 | let [i, d] = s.split("."); i = i.replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
| 19 | if (d) d = d.replace(/0+$/, ""); |
| 20 | return (neg ? "−" : "") + i + (d ? "." + d : ""); |
| 21 | } |
| 22 | const isNeg = (v) => String(v ?? "").startsWith("-"); |
| 23 | const numCell = (v) => `<td class="num${isNeg(v) ? " neg" : ""}">${fmt(v)}</td>`; |
| 24 | const STATUS_FA = { |
| 25 | INCOMPLETE: "ناقص — پیشنویس کاری", |
| 26 | COMPLETE_DRAFT: "کامل — نگاشتها در انتظار تأیید", |
| 27 | COMPLETE_APPROVED: "کامل — همهٔ نگاشتها تأییدشده", |
| 28 | }; |
| 29 | const APPROVAL_FA = { Draft: "پیشنویس", Reviewed: "بررسیشده", Approved: "تأییدشده" }; |
| 30 | |
| 31 | let toastTimer = null; |
| 32 | function toast(msg, kind = "") { |
| 33 | const el = $("#toast"); el.textContent = msg; el.className = `toast ${kind}`; |
| 34 | clearTimeout(toastTimer); toastTimer = setTimeout(() => el.classList.add("hidden"), 4200); |
| 35 | } |
| 36 | async function api(path, opts = {}) { |
| 37 | const res = await fetch(API + path, opts); |
| 38 | let body = null; try { body = await res.json(); } catch { /* non-JSON */ } |
| 39 | if (!res.ok) { |
| 40 | const d = body?.detail; |
| 41 | const err = new Error(typeof d === "string" ? d : d?.message || `خطای سرور (${res.status})`); |
| 42 | err.issues = d?.issues; err.status = res.status; throw err; |
| 43 | } |
| 44 | return body; |
| 45 | } |
| 46 | const actor = () => ($("#actor-input").value || "").trim(); |
| 47 | const sid = () => S.data.session.id; |
| 48 | function applyPayload(payload) { S.data = payload; renderAll(); } |
| 49 | |
| 50 | /* ---------------- bottom sheet ---------------- */ |
| 51 | function openSheet(title, html, onMount) { |
| 52 | $("#sheet-title").textContent = title; |
| 53 | $("#sheet-body").innerHTML = html; |
| 54 | $("#sheet").classList.remove("hidden"); |
| 55 | $("#sheet-backdrop").classList.remove("hidden"); |
| 56 | document.body.style.overflow = "hidden"; |
| 57 | if (onMount) onMount(); |
| 58 | } |
| 59 | function closeSheet() { |
| 60 | $("#sheet").classList.add("hidden"); |
| 61 | $("#sheet-backdrop").classList.add("hidden"); |
| 62 | document.body.style.overflow = ""; |
| 63 | } |
| 64 | |
| 65 | /* ---------------- landing ---------------- */ |
| 66 | function renderPolicy() { |
| 67 | const m = S.meta, items = []; |
| 68 | for (const st of m.rendered_statements) |
| 69 | for (const [sec, sign] of Object.entries(m.section_policy[st])) |
| 70 | items.push(`<div class="policy-item"><b>${esc(m.statement_labels_fa[st])}</b> / ${esc(m.section_labels_fa[sec] || sec)} <span class="mono">${sign > 0 ? "+" : "−"}</span></div>`); |
| 71 | for (const st of m.deferred_statements) |
| 72 | items.push(`<div class="policy-item muted">${esc(m.statement_labels_fa[st])} — نسخهٔ بعدی</div>`); |
| 73 | $("#policy-grid").innerHTML = items.join(""); |
| 74 | } |
| 75 | function showIssues(err) { |
| 76 | const panel = $("#issues-panel"); |
| 77 | if (!err.issues?.length) { toast(err.message, "error"); return; } |
| 78 | $("#issues-message").textContent = err.message; |
| 79 | $("#issues-table tbody").innerHTML = err.issues.map((i) => |
| 80 | `<tr><td>${esc(i.sheet)}</td><td class="num">${i.row}</td><td class="mono">${esc(i.field)}</td><td class="mono">${esc(i.code)}</td><td>${esc(i.message)}</td></tr>`).join(""); |
| 81 | panel.classList.remove("hidden"); |
| 82 | panel.scrollIntoView({ behavior: "smooth", block: "start" }); |
| 83 | } |
| 84 | async function uploadFile(file) { |
| 85 | $("#issues-panel").classList.add("hidden"); |
| 86 | $("#upload-progress").classList.remove("hidden"); $("#upload-btn").disabled = true; |
| 87 | try { |
| 88 | const form = new FormData(); form.append("file", file); |
| 89 | enterWorkspace(await api("/sessions", { method: "POST", body: form })); |
| 90 | toast("فایل پذیرفته شد؛ پیشبررسی بدون خطا بود.", "success"); |
| 91 | } catch (err) { showIssues(err); } |
| 92 | finally { $("#upload-progress").classList.add("hidden"); $("#upload-btn").disabled = false; $("#file-input").value = ""; } |
| 93 | } |
| 94 | async function startDemo() { |
| 95 | $("#issues-panel").classList.add("hidden"); $("#demo-btn").disabled = true; |
| 96 | try { |
| 97 | enterWorkspace(await api("/demo", { method: "POST" })); |
| 98 | toast("دموی ساختگی آماده شد؛ دو حساب نگاشتنشده منتظر شما هستند.", "success"); |
| 99 | } catch (err) { toast(err.message, "error"); } |
| 100 | finally { $("#demo-btn").disabled = false; } |
| 101 | } |
| 102 | |
| 103 | /* ---------------- workspace ---------------- */ |
| 104 | function enterWorkspace(payload) { |
| 105 | S.data = payload; S.tab = "dashboard"; S.filter = "all"; S.search = ""; |
| 106 | S.noteSearch = ""; S.expanded = new Set(); |
| 107 | $("#view-landing").classList.add("hidden"); |
| 108 | $("#view-workspace").classList.remove("hidden"); |
| 109 | $("#tabbar").classList.remove("hidden"); |
| 110 | $("#new-session-btn").classList.remove("hidden"); |
| 111 | $("#engine-version").textContent = payload.report.engine_version; |
| 112 | renderAll(); window.scrollTo({ top: 0 }); |
| 113 | } |
| 114 | function leaveWorkspace() { |
| 115 | S.data = null; |
| 116 | $("#view-workspace").classList.add("hidden"); |
| 117 | $("#view-landing").classList.remove("hidden"); |
| 118 | $("#tabbar").classList.add("hidden"); |
| 119 | $("#new-session-btn").classList.add("hidden"); |
| 120 | } |
| 121 | function renderAll() { |
| 122 | const { report, session } = S.data, c = report.company; |
| 123 | const sourceChip = session.source === "demo" |
| 124 | ? `<span class="chip demo">دموی ساختگی</span>` |
| 125 | : `<span class="chip mono">${esc(session.filename)}</span>`; |
| 126 | $("#session-info").innerHTML = `<div class="session-meta"> |
| 127 | <span class="company-name">${esc(c.name)}</span> |
| 128 | <span class="chip">کد ${esc(c.code)}</span> |
| 129 | <span class="chip">سال ${c.fiscal_year}</span> |
| 130 | <span class="chip">${esc(c.unit || "واحد نامشخص")}</span>${sourceChip}</div>`; |
| 131 | $("#status-chip").innerHTML = `<span class="status-chip status-${report.status.label}">${STATUS_FA[report.status.label]}</span>`; |
| 132 | const ex = report.coverage.exception_count, badge = $("#mapping-badge"); |
| 133 | badge.textContent = ex; badge.className = `badge${ex === 0 ? " zero" : ""}`; |
| 134 | document.querySelectorAll(".tabbar .tab").forEach((t) => t.classList.toggle("active", t.dataset.tab === S.tab)); |
| 135 | document.querySelectorAll(".tab-panel").forEach((p) => p.classList.add("hidden")); |
| 136 | $(`#tab-${S.tab}`).classList.remove("hidden"); |
| 137 | ({ dashboard: renderDashboard, accounts: renderAccounts, notes: renderNotes, statements: renderStatements, more: renderMore })[S.tab](); |
| 138 | } |
| 139 | |
| 140 | /* ---------------- dashboard ---------------- */ |
| 141 | function renderDashboard() { |
| 142 | const { report } = S.data, t = report.totals, cov = report.coverage; |
| 143 | const pct = cov.total_accounts ? Math.round((cov.mapped_accounts / cov.total_accounts) * 100) : 0; |
| 144 | const totalCard = (label, v, hl = false) => |
| 145 | `<div class="total-card${hl ? " highlight" : ""}"><div class="label">${label}</div><div class="value${isNeg(v) ? " neg" : ""}">${fmt(v)}</div></div>`; |
| 146 | const exceptions = report.exceptions.length ? ` |
| 147 | <div class="card" style="margin-top:14px"> |
| 148 | <h3 style="margin-top:0">صف استثنا (${report.exceptions.length})</h3> |
| 149 | <div class="item-list">${report.exceptions.map((e) => ` |
| 150 | <div class="item-card"> |
| 151 | <div class="item-top"> |
| 152 | <div><div class="item-title">${esc(e.account_name)}</div><div class="item-code mono">${esc(e.account_code)} · سطر منبع ${e.source_row}</div></div> |
| 153 | <span class="item-amount${isNeg(e.closing) ? " neg" : ""}">${fmt(e.closing)}</span> |
| 154 | </div> |
| 155 | <div class="item-sub"><span class="approval-chip approval-none">${esc(e.code)}</span> ${esc(e.details)}</div> |
| 156 | <div class="item-actions"><button class="btn small primary" data-action="resolve-exception" data-code="${esc(e.account_code)}">رسیدگی و نگاشت</button></div> |
| 157 | </div>`).join("")}</div> |
| 158 | </div>` : `<div class="card" style="margin-top:14px"><b style="color:var(--green)">✓ هیچ استثنایی باقی نمانده است.</b></div>`; |
| 159 | $("#tab-dashboard").innerHTML = ` |
| 160 | <div class="grid checks-grid">${report.checks.map((ch) => ` |
| 161 | <div class="check-card ${ch.passed ? "pass" : "fail"}"> |
| 162 | <div class="check-name">${esc(ch.name_fa)}</div> |
| 163 | <div class="check-state">${ch.passed ? "✓ قبول" : "✗ رد"}</div> |
| 164 | ${ch.amount !== null ? `<div class="check-amount">${fmt(ch.amount)}</div>` : ""} |
| 165 | <div class="check-details">${esc(ch.details)}</div> |
| 166 | </div>`).join("")}</div> |
| 167 | <div class="card"><b>پوشش نگاشت:</b> ${cov.mapped_accounts} از ${cov.total_accounts} حساب (${pct}٪) |
| 168 | <div class="coverage-bar-wrap" style="margin-top:8px"><div class="coverage-bar" style="width:${pct}%"></div></div></div> |
| 169 | <div class="grid totals-grid"> |
| 170 | ${totalCard("جمع داراییها", t.assets)}${totalCard("جمع بدهیها", t.liabilities)} |
| 171 | ${totalCard("حقوق مالکانه", t.equity)}${totalCard("درآمدها", t.revenue)} |
| 172 | ${totalCard("هزینهها", t.expenses)}${totalCard("سود (زیان) دوره", t.profit, true)} |
| 173 | </div>${exceptions}`; |
| 174 | } |
| 175 | |
| 176 | /* ---------------- accounts ---------------- */ |
| 177 | function mappingSummary(a) { |
| 178 | if (a.conflict) return `<span class="approval-chip approval-none">تعارض نگاشت</span>`; |
| 179 | if (!a.mapping) return `<span class="approval-chip approval-none">بدون نگاشت</span>`; |
| 180 | const m = a.mapping; |
| 181 | const note = S.data.notes.find((n) => n.statement === m.statement && n.section === m.section && n.note_number === m.note_number && n.subnote_code === m.subnote_code); |
| 182 | const label = note ? `${note.note_number} — ${note.note_title}` : m.note_number; |
| 183 | return `<span class="mono">${esc(m.statement)}/${esc(m.section)}</span> · ${esc(label)} <span class="approval-chip approval-${esc(m.approval_status)}">${APPROVAL_FA[m.approval_status] || m.approval_status}</span>`; |
| 184 | } |
| 185 | function filteredAccounts() { |
| 186 | const q = S.search.trim(); |
| 187 | return S.data.accounts.filter((a) => { |
| 188 | if (S.filter === "unmapped" && a.mapping) return false; |
| 189 | if (S.filter === "unapproved" && a.mapping?.approval_status === "Approved") return false; |
| 190 | if (S.filter === "conflict" && !a.conflict) return false; |
| 191 | if (q && !(a.code.includes(q) || a.name.includes(q))) return false; |
| 192 | return true; |
| 193 | }); |
| 194 | } |
| 195 | function accountCard(a) { |
| 196 | return `<div class="item-card"> |
| 197 | <div class="item-top"> |
| 198 | <div><div class="item-title">${esc(a.name)}</div><div class="item-code mono">${esc(a.code)} · کل ${esc(a.general_code)} · سطر ${a.source_row}</div></div> |
| 199 | <span class="item-amount${isNeg(a.closing) ? " neg" : ""}">${fmt(a.closing)}</span> |
| 200 | </div> |
| 201 | <div class="item-sub">${mappingSummary(a)}</div> |
| 202 | <div class="item-actions"> |
| 203 | <button class="btn small primary" data-action="map-account" data-code="${esc(a.code)}">${a.mapping ? "ویرایش نگاشت" : "تعیین مقصد"}</button> |
| 204 | <button class="btn small" data-action="edit-account" data-code="${esc(a.code)}">ویرایش حساب</button> |
| 205 | <button class="btn small" data-action="rename-account" data-code="${esc(a.code)}">تغییر کد</button> |
| 206 | <button class="btn small danger" data-action="delete-account" data-code="${esc(a.code)}">حذف</button> |
| 207 | </div> |
| 208 | </div>`; |
| 209 | } |
| 210 | function updateAccList() { |
| 211 | const list = $("#acc-list"); if (!list) return; |
| 212 | const rows = filteredAccounts().map(accountCard).join(""); |
| 213 | list.innerHTML = rows || `<div class="card muted">حسابی با این فیلتر یافت نشد.</div>`; |
| 214 | } |
| 215 | function renderAccounts() { |
| 216 | $("#tab-accounts").innerHTML = ` |
| 217 | <div class="table-toolbar"> |
| 218 | <input type="search" id="acc-search" placeholder="جستجوی کد یا نام…" value="${esc(S.search)}"> |
| 219 | <select id="acc-filter"> |
| 220 | <option value="all">همه</option><option value="unmapped">بدون نگاشت</option> |
| 221 | <option value="unapproved">تأییدنشده</option><option value="conflict">تعارض</option> |
| 222 | </select> |
| 223 | <button class="btn accent small" data-action="add-account">+ حساب جدید</button> |
| 224 | </div> |
| 225 | <p class="muted">${S.data.accounts.length} حساب · مانده بدهکار-مثبت · هر تغییر در ردّ ممیزی ثبت میشود</p> |
| 226 | <div class="item-list" id="acc-list"></div>`; |
| 227 | $("#acc-filter").value = S.filter; |
| 228 | $("#acc-search").oninput = (e) => { S.search = e.target.value; updateAccList(); }; |
| 229 | $("#acc-filter").onchange = (e) => { S.filter = e.target.value; updateAccList(); }; |
| 230 | updateAccList(); |
| 231 | } |
| 232 | |
| 233 | /* ---------------- account forms ---------------- */ |
| 234 | function accountFormHtml(a) { |
| 235 | const v = a || { full_code: "", name: "", general_code: "", general_name: "", opening: "0", debit: "0", credit: "0", subsidiary_code: "", subsidiary_name: "", row_status: "Draft" }; |
| 236 | const codeField = a |
| 237 | ? `<div class="form-field full"><span>کد حساب (ثابت)</span><input value="${esc(v.full_code)}" disabled></div>` |
| 238 | : `<div class="form-field full"><span>کد کامل حساب *</span><input id="f-code" value="${esc(v.full_code)}" placeholder="مثلاً 1201"></div>`; |
| 239 | return `<div class="form-grid"> |
| 240 | ${codeField} |
| 241 | <div class="form-field full"><span>نام حساب *</span><input id="f-name" value="${esc(v.name)}"></div> |
| 242 | <div class="form-field"><span>کد حساب کل *</span><input id="f-gencode" value="${esc(v.general_code)}"></div> |
| 243 | <div class="form-field"><span>نام حساب کل *</span><input id="f-genname" value="${esc(v.general_name)}"></div> |
| 244 | <div class="form-field"><span>کد معین (اختیاری)</span><input id="f-subcode" value="${esc(v.subsidiary_code)}"></div> |
| 245 | <div class="form-field"><span>نام معین (اختیاری)</span><input id="f-subname" value="${esc(v.subsidiary_name)}"></div> |
| 246 | <div class="form-field"><span>مانده ابتدای دوره</span><input id="f-opening" inputmode="decimal" value="${esc(v.opening)}"></div> |
| 247 | <div class="form-field"><span>گردش بدهکار</span><input id="f-debit" inputmode="decimal" value="${esc(v.debit)}"></div> |
| 248 | <div class="form-field"><span>گردش بستانکار</span><input id="f-credit" inputmode="decimal" value="${esc(v.credit)}"></div> |
| 249 | <div class="form-field"><span>وضعیت سطر</span><select id="f-rowstatus"> |
| 250 | <option value="Draft">Draft</option><option value="Reviewed">Reviewed</option><option value="Approved">Approved</option> |
| 251 | </select></div> |
| 252 | <div class="form-field full"><span>مانده پایان دوره (محاسبهشده)</span><div class="computed-box">بدهکار+ = <b id="f-closing">—</b></div></div> |
| 253 | </div> |
| 254 | <p class="form-hint">مانده پایان دوره از «ابتدای دوره + بدهکار − بستانکار» محاسبه میشود؛ هیچ مبلغی حدس زده نمیشود.</p> |
| 255 | <div class="form-actions"> |
| 256 | <button class="btn primary" data-action="submit-account" data-code="${a ? esc(a.code) : ""}">${a ? "ذخیره تغییرات" : "افزودن حساب"}</button> |
| 257 | <button class="btn ghost" data-action="close-sheet">انصراف</button> |
| 258 | </div>`; |
| 259 | } |
| 260 | function wireAccountForm(a) { |
| 261 | $("#f-rowstatus").value = a?.row_status || "Draft"; |
| 262 | const calc = () => { |
| 263 | const o = parseFloat($("#f-opening").value) || 0, d = parseFloat($("#f-debit").value) || 0, c = parseFloat($("#f-credit").value) || 0; |
| 264 | $("#f-closing").textContent = fmt(String(o + d - c)); |
| 265 | }; |
| 266 | ["f-opening", "f-debit", "f-credit"].forEach((id) => $("#" + id).addEventListener("input", calc)); |
| 267 | calc(); |
| 268 | } |
| 269 | async function submitAccount(code) { |
| 270 | const body = { |
| 271 | name: $("#f-name").value, general_code: $("#f-gencode").value, general_name: $("#f-genname").value, |
| 272 | opening: $("#f-opening").value || "0", debit: $("#f-debit").value || "0", credit: $("#f-credit").value || "0", |
| 273 | row_status: $("#f-rowstatus").value, subsidiary_code: $("#f-subcode").value, subsidiary_name: $("#f-subname").value, |
| 274 | actor: actor(), |
| 275 | }; |
| 276 | try { |
| 277 | if (code) applyPayload(await api(`/sessions/${sid()}/accounts/${encodeURIComponent(code)}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) })); |
| 278 | else { body.full_code = $("#f-code").value; applyPayload(await api(`/sessions/${sid()}/accounts`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) })); } |
| 279 | closeSheet(); toast(code ? "حساب ویرایش شد." : "حساب جدید افزوده شد؛ اکنون مقصدش را تعیین کنید.", "success"); |
| 280 | } catch (err) { toast(err.message, "error"); } |
| 281 | } |
| 282 | function openRename(a) { |
| 283 | openSheet("تغییر کد حساب", `<div class="form-grid"> |
| 284 | <div class="form-field full"><span>کد فعلی</span><input value="${esc(a.code)}" disabled></div> |
| 285 | <div class="form-field full"><span>کد جدید *</span><input id="f-newcode" placeholder="کد جدید"></div> |
| 286 | </div><p class="form-hint">نگاشت این حساب بهصورت خودکار به کد جدید منتقل میشود.</p> |
| 287 | <div class="form-actions"><button class="btn primary" data-action="submit-rename" data-code="${esc(a.code)}">تغییر کد</button> |
| 288 | <button class="btn ghost" data-action="close-sheet">انصراف</button></div>`); |
| 289 | } |
| 290 | async function submitRename(code) { |
| 291 | try { |
| 292 | applyPayload(await api(`/sessions/${sid()}/accounts/${encodeURIComponent(code)}/rename`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ new_code: $("#f-newcode").value, actor: actor() }) })); |
| 293 | closeSheet(); toast("کد حساب تغییر کرد و نگاشت منتقل شد.", "success"); |
| 294 | } catch (err) { toast(err.message, "error"); } |
| 295 | } |
| 296 | async function deleteAccount(code) { |
| 297 | if (!confirm(`حساب ${code} و نگاشت آن حذف شود؟`)) return; |
| 298 | try { |
| 299 | applyPayload(await api(`/sessions/${sid()}/accounts/${encodeURIComponent(code)}?actor=${encodeURIComponent(actor())}`, { method: "DELETE" })); |
| 300 | toast("حساب حذف شد.", "success"); |
| 301 | } catch (err) { toast(err.message, "error"); } |
| 302 | } |
| 303 | |
| 304 | /* ---------------- mapping form ---------------- */ |
| 305 | function noteOptions(statement, section) { |
| 306 | return S.data.notes.filter((n) => n.statement === statement && n.section === section); |
| 307 | } |
| 308 | function openMapping(a) { |
| 309 | const m = a.mapping || {}; |
| 310 | const statements = [...S.meta.rendered_statements, ...S.meta.deferred_statements]; |
| 311 | openSheet(`نگاشت حساب ${a.code}`, `<div class="form-grid"> |
| 312 | <div class="form-field full"><span>حساب</span><input value="${esc(a.code)} — ${esc(a.name)}" disabled></div> |
| 313 | <div class="form-field"><span>صورت مالی</span><select id="m-statement">${statements.map((st) => `<option value="${st}">${esc(S.meta.statement_labels_fa[st])} (${st})</option>`).join("")}</select></div> |
| 314 | <div class="form-field"><span>بخش</span><select id="m-section"></select></div> |
| 315 | <div class="form-field full"><span>یادداشت / زیریادداشت</span><select id="m-note"></select></div> |
| 316 | <div class="form-field"><span>وضعیت تأیید</span><select id="m-approval"> |
| 317 | <option value="Draft">Draft</option><option value="Reviewed">Reviewed</option><option value="Approved">Approved</option> |
| 318 | </select></div> |
| 319 | <div class="form-field"><span>نام بازبین</span><input id="m-reviewer" value="${esc(m.reviewer || actor())}" placeholder="برای Reviewed/Approved الزامی"></div> |
| 320 | </div> |
| 321 | <div class="form-actions"> |
| 322 | <button class="btn primary" data-action="submit-mapping" data-code="${esc(a.code)}">ثبت نگاشت</button> |
| 323 | ${a.mapping ? `<button class="btn danger" data-action="clear-mapping" data-code="${esc(a.code)}">حذف نگاشت</button>` : ""} |
| 324 | <button class="btn ghost" data-action="close-sheet">انصراف</button> |
| 325 | </div>`, () => { |
| 326 | const stSel = $("#m-statement"), secSel = $("#m-section"), noteSel = $("#m-note"); |
| 327 | stSel.value = m.statement || "BS"; |
| 328 | const fillSections = () => { |
| 329 | const st = stSel.value; |
| 330 | const sections = S.meta.section_policy[st] ? Object.keys(S.meta.section_policy[st]) |
| 331 | : [...new Set(S.data.notes.filter((n) => n.statement === st).map((n) => n.section))]; |
| 332 | secSel.innerHTML = sections.map((sec) => `<option value="${esc(sec)}">${esc(S.meta.section_labels_fa[sec] || sec)}</option>`).join(""); |
| 333 | if (m.section && sections.includes(m.section)) secSel.value = m.section; |
| 334 | fillNotes(); |
| 335 | }; |
| 336 | const fillNotes = () => { |
| 337 | const opts = noteOptions(stSel.value, secSel.value); |
| 338 | noteSel.innerHTML = opts.length ? opts.map((n) => { |
| 339 | const val = `${n.note_number}|${n.subnote_code}`; |
| 340 | const label = `${n.note_number} — ${n.note_title}${n.subnote_code ? ` / ${n.subnote_code} ${n.subnote_title}` : ""}`; |
| 341 | return `<option value="${esc(val)}">${esc(label)}</option>`; |
| 342 | }).join("") : `<option value="">— یادداشتی تعریف نشده؛ ابتدا از زبانهٔ یادداشتها اضافه کنید —</option>`; |
| 343 | const cur = `${m.note_number}|${m.subnote_code || ""}`; |
| 344 | if ([...noteSel.options].some((o) => o.value === cur)) noteSel.value = cur; |
| 345 | }; |
| 346 | stSel.onchange = fillSections; secSel.onchange = fillNotes; fillSections(); |
| 347 | $("#m-approval").value = m.approval_status || "Draft"; |
| 348 | }); |
| 349 | } |
| 350 | async function submitMapping(code) { |
| 351 | const noteVal = $("#m-note").value; |
| 352 | if (!noteVal) { toast("برای این بخش یادداشتی نیست؛ ابتدا یادداشت اضافه کنید.", "error"); return; } |
| 353 | const [note_number, subnote_code] = noteVal.split("|"); |
| 354 | const approval_status = $("#m-approval").value, reviewer = $("#m-reviewer").value.trim(); |
| 355 | if (approval_status !== "Draft" && !reviewer) { toast("برای Reviewed/Approved نام بازبین الزامی است.", "error"); return; } |
| 356 | try { |
| 357 | applyPayload(await api(`/sessions/${sid()}/mappings/${encodeURIComponent(code)}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ statement: $("#m-statement").value, section: $("#m-section").value, note_number, subnote_code: subnote_code || "", approval_status, reviewer, actor: actor() }) })); |
| 358 | closeSheet(); toast(`نگاشت حساب ${code} ثبت شد.`, "success"); |
| 359 | } catch (err) { toast(err.message, "error"); } |
| 360 | } |
| 361 | async function clearMapping(code) { |
| 362 | try { |
| 363 | applyPayload(await api(`/sessions/${sid()}/mappings/${encodeURIComponent(code)}?actor=${encodeURIComponent(actor())}`, { method: "DELETE" })); |
| 364 | closeSheet(); toast("نگاشت حذف شد.", "success"); |
| 365 | } catch (err) { toast(err.message, "error"); } |
| 366 | } |
| 367 | |
| 368 | /* ---------------- notes ---------------- */ |
| 369 | function updateNoteList() { |
| 370 | const list = $("#note-list"); if (!list) return; |
| 371 | const q = S.noteSearch.trim(); |
| 372 | const notes = S.data.notes.filter((n) => !q || n.note_number.includes(q) || n.note_title.includes(q) || n.section.includes(q)); |
| 373 | const groups = {}; |
| 374 | for (const n of notes) { const k = `${n.statement}|${n.section}`; (groups[k] = groups[k] || []).push(n); } |
| 375 | const usedKeys = new Set(S.data.accounts.filter((a) => a.mapping).map((a) => `${a.mapping.statement}|${a.mapping.section}|${a.mapping.note_number}|${a.mapping.subnote_code}`)); |
| 376 | let html = ""; |
| 377 | const order = Object.keys(groups).sort(); |
| 378 | if (!order.length) html = `<div class="card muted">یادداشتی یافت نشد.</div>`; |
| 379 | for (const k of order) { |
| 380 | const [st, sec] = k.split("|"); |
| 381 | html += `<div class="section-label">${esc(S.meta.statement_labels_fa[st] || st)} / ${esc(S.meta.section_labels_fa[sec] || sec)}</div><div class="item-list">`; |
| 382 | for (const n of groups[k].sort((a, b) => a.note_number.localeCompare(b.note_number) || a.subnote_code.localeCompare(b.subnote_code))) { |
| 383 | const key = `${n.statement}|${n.section}|${n.note_number}|${n.subnote_code}`; |
| 384 | const inUse = usedKeys.has(key); |
| 385 | html += `<div class="item-card"> |
| 386 | <div class="item-top"> |
| 387 | <div><div class="item-title">${esc(n.note_title)}${n.subnote_code ? ` <span class="muted">/ ${esc(n.subnote_code)} ${esc(n.subnote_title)}</span>` : ""}</div> |
| 388 | <div class="item-code mono">یادداشت ${esc(n.note_number)}${n.subnote_code ? ` · زیریادداشت ${esc(n.subnote_code)}` : ""}</div></div> |
| 389 | ${inUse ? `<span class="approval-chip approval-Approved">در استفاده</span>` : `<span class="approval-chip">آزاد</span>`} |
| 390 | </div> |
| 391 | <div class="item-actions"> |
| 392 | <button class="btn small" data-action="edit-note" data-key="${esc(key)}">ویرایش عنوان</button> |
| 393 | <button class="btn small danger" data-action="delete-note" data-key="${esc(key)}" ${inUse ? 'title="ابتدا نگاشتهای متصل را جابهجا کنید"' : ""}>حذف</button> |
| 394 | </div> |
| 395 | </div>`; |
| 396 | } |
| 397 | html += `</div>`; |
| 398 | } |
| 399 | list.innerHTML = html; |
| 400 | } |
| 401 | function renderNotes() { |
| 402 | $("#tab-notes").innerHTML = `<div class="table-toolbar"> |
| 403 | <input type="search" id="note-search" placeholder="جستجوی یادداشت…" value="${esc(S.noteSearch)}"> |
| 404 | <button class="btn accent small" data-action="add-note">+ یادداشت جدید</button> |
| 405 | </div><p class="muted">${S.data.notes.length} یادداشت/زیریادداشت · مقصدهای نگاشت از اینجا تعریف میشوند</p> |
| 406 | <div id="note-list"></div>`; |
| 407 | $("#note-search").oninput = (e) => { S.noteSearch = e.target.value; updateNoteList(); }; |
| 408 | updateNoteList(); |
| 409 | } |
| 410 | function noteFormHtml(n) { |
| 411 | const statements = [...S.meta.rendered_statements, ...S.meta.deferred_statements]; |
| 412 | const v = n || { statement: "BS", section: "Assets", note_number: "", note_title: "", subnote_code: "", subnote_title: "" }; |
| 413 | const keyLocked = !!n; |
| 414 | return `<div class="form-grid"> |
| 415 | <div class="form-field"><span>صورت مالی</span><select id="n-statement" ${keyLocked ? "disabled" : ""}>${statements.map((st) => `<option value="${st}">${esc(S.meta.statement_labels_fa[st])} (${st})</option>`).join("")}</select></div> |
| 416 | <div class="form-field"><span>بخش *</span><input id="n-section" value="${esc(v.section)}" ${keyLocked ? "disabled" : ""} placeholder="Assets / Liabilities / …"></div> |
| 417 | <div class="form-field"><span>شماره یادداشت *</span><input id="n-number" value="${esc(v.note_number)}" ${keyLocked ? "disabled" : ""}></div> |
| 418 | <div class="form-field"><span>کد زیریادداشت (اختیاری)</span><input id="n-subcode" value="${esc(v.subnote_code)}" ${keyLocked ? "disabled" : ""}></div> |
| 419 | <div class="form-field full"><span>عنوان یادداشت *</span><input id="n-title" value="${esc(v.note_title)}"></div> |
| 420 | <div class="form-field full"><span>عنوان زیریادداشت</span><input id="n-subtitle" value="${esc(v.subnote_title)}"></div> |
| 421 | </div> |
| 422 | ${keyLocked ? `<p class="form-hint">کلید یادداشت ثابت است؛ فقط عنوانها ویرایش میشوند.</p>` : `<p class="form-hint">برای زیریادداشت، کد و عنوان آن را پر کنید. بخشهای استاندارد: Assets، Liabilities، Equity، Revenue، Expenses.</p>`} |
| 423 | <div class="form-actions"> |
| 424 | <button class="btn primary" data-action="submit-note" data-key="${n ? esc(`${n.statement}|${n.section}|${n.note_number}|${n.subnote_code}`) : ""}">${n ? "ذخیره عنوان" : "افزودن یادداشت"}</button> |
| 425 | <button class="btn ghost" data-action="close-sheet">انصراف</button> |
| 426 | </div>`; |
| 427 | } |
| 428 | async function submitNote(key) { |
| 429 | const body = { |
| 430 | statement: $("#n-statement").value, section: $("#n-section").value, |
| 431 | note_number: $("#n-number").value, note_title: $("#n-title").value, |
| 432 | subnote_code: $("#n-subcode").value, subnote_title: $("#n-subtitle").value, actor: actor(), |
| 433 | }; |
| 434 | try { |
| 435 | if (key) { const [st, sec, num, sub] = key.split("|"); Object.assign(body, { statement: st, section: sec, note_number: num, subnote_code: sub }); } |
| 436 | applyPayload(await api(`/sessions/${sid()}/notes`, { method: key ? "PUT" : "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) })); |
| 437 | closeSheet(); toast(key ? "عنوان یادداشت ویرایش شد." : "یادداشت جدید افزوده شد.", "success"); |
| 438 | } catch (err) { toast(err.message, "error"); } |
| 439 | } |
| 440 | async function deleteNote(key) { |
| 441 | const [statement, section, note_number, subnote_code] = key.split("|"); |
| 442 | if (!confirm("این یادداشت حذف شود؟")) return; |
| 443 | try { |
| 444 | const params = new URLSearchParams({ statement, section, note_number, subnote_code, actor: actor() }); |
| 445 | applyPayload(await api(`/sessions/${sid()}/notes?${params}`, { method: "DELETE" })); |
| 446 | toast("یادداشت حذف شد.", "success"); |
| 447 | } catch (err) { toast(err.message, "error"); } |
| 448 | } |
| 449 | |
| 450 | /* ---------------- statements ---------------- */ |
| 451 | function renderStatements() { |
| 452 | const code = S.statementView; |
| 453 | const { report } = S.data, st = report.statements[code], c = report.company; |
| 454 | const sections = st.sections.map((sec) => ` |
| 455 | <div class="statement-section"> |
| 456 | <div class="section-head"><span>${esc(sec.label_fa)}</span><span class="note-total${isNeg(sec.total) ? " neg" : ""}">${fmt(sec.total)}</span></div> |
| 457 | ${sec.lines.map((line) => { |
| 458 | const key = `${code}|${sec.name}|${line.note_number}|${line.subnote_code}`; |
| 459 | const open = S.expanded.has(key); |
| 460 | const title = `${line.note_title}${line.subnote_code ? ` / ${line.subnote_code} ${line.subnote_title}` : ""}`; |
| 461 | return `<div class="note-line" data-action="toggle-line" data-key="${esc(key)}"> |
| 462 | <span class="note-title"><span class="note-number">${esc(line.note_number)}</span>${esc(title)} <span class="muted">${open ? "▾" : "◂"} ${line.accounts.length} حساب</span></span> |
| 463 | <span class="note-total${isNeg(line.total) ? " neg" : ""}">${fmt(line.total)}</span></div> |
| 464 | ${open ? `<div class="drill"><div class="table-wrap"><table> |
| 465 | <thead><tr><th>کد</th><th>حساب</th><th class="num">مانده دفتر</th><th class="num">نمایشی</th><th>سطر</th><th>تأیید</th></tr></thead> |
| 466 | <tbody>${line.accounts.map((a) => `<tr><td class="mono">${esc(a.code)}</td><td>${esc(a.name)}</td>${numCell(a.closing)}${numCell(a.display)}<td class="num">${a.source_row}</td><td><span class="approval-chip approval-${esc(a.approval_status)}">${APPROVAL_FA[a.approval_status] || a.approval_status}</span></td></tr>`).join("")}</tbody> |
| 467 | </table></div></div>` : ""}`; |
| 468 | }).join("") || `<div class="note-line muted">رقمی در این بخش منظور نشده است.</div>`} |
| 469 | </div>`).join(""); |
| 470 | const grand = code === "BS" |
| 471 | ? `<div class="statement-total"><span>جمع داراییها</span><span class="note-total">${fmt(report.totals.assets)}</span></div> |
| 472 | <div class="statement-total"><span>جمع بدهیها و حقوق مالکانه</span><span class="note-total">${fmt(report.totals.liabilities_and_equity)}</span></div>` |
| 473 | : `<div class="statement-total"><span>سود (زیان) دوره</span><span class="note-total${isNeg(report.totals.profit) ? " neg" : ""}">${fmt(report.totals.profit)}</span></div>`; |
| 474 | $("#tab-statements").innerHTML = ` |
| 475 | <div class="statement-tools"> |
| 476 | <div class="segmented"> |
| 477 | <button data-action="view-statement" data-code="BS" class="${code === "BS" ? "active" : ""}">ترازنامه</button> |
| 478 | <button data-action="view-statement" data-code="IS" class="${code === "IS" ? "active" : ""}">سود و زیان</button> |
| 479 | </div> |
| 480 | <button class="btn small ghost" data-action="print">🖨 چاپ</button> |
| 481 | </div> |
| 482 | <div class="statement-paper"> |
| 483 | <div class="statement-head"><h2>${esc(st.label_fa)}</h2> |
| 484 | <div class="sub">${esc(c.name)} — سال مالی ${c.fiscal_year} — به ${esc(c.unit || "واحد نامشخص")}</div> |
| 485 | <span class="draft-watermark">${STATUS_FA[report.status.label]} · پیشنویس کاری، نه صورت مالی رسمی</span></div> |
| 486 | ${sections}${grand} |
| 487 | ${code === "BS" ? `<p class="muted">سود دوره (${fmt(report.totals.profit)}) از طریق معادلهٔ حسابداری در حقوق مالکانه کنترل میشود.</p>` : ""} |
| 488 | </div>`; |
| 489 | } |
| 490 | |
| 491 | /* ---------------- more / audit / export ---------------- */ |
| 492 | function renderMore() { |
| 493 | const { report, session, audit_trail: trail } = S.data, c = report.company; |
| 494 | const prov = (k, v, mono = false) => `<div class="prov-item"><div class="k">${k}</div><div class="v${mono ? " mono" : ""}">${esc(v)}</div></div>`; |
| 495 | $("#tab-more").innerHTML = ` |
| 496 | <div class="card" style="margin-bottom:14px"> |
| 497 | <h3 style="margin-top:0">شرکت و سال مالی</h3> |
| 498 | <div class="provenance-grid"> |
| 499 | ${prov("نام", c.name)}${prov("کد", c.code, true)}${prov("سال مالی", c.fiscal_year)} |
| 500 | ${prov("واحد", c.unit || "—")}${prov("ارز", c.currency || "—")} |
| 501 | </div> |
| 502 | <button class="btn block" data-action="edit-company">ویرایش اطلاعات شرکت</button> |
| 503 | </div> |
| 504 | <div class="card" style="margin-bottom:14px"> |
| 505 | <h3 style="margin-top:0">خروجی و ذخیره</h3> |
| 506 | <div class="action-stack"> |
| 507 | <a class="btn primary block" href="${API}/sessions/${session.id}/export.xlsx" download>⬇ دانلود گزارش اکسل (صورتها + کنترلها + ردّ ممیزی)</a> |
| 508 | <a class="btn accent block" href="${API}/sessions/${session.id}/workspace.xlsx" download>💾 ذخیرهٔ کارگاه (قابل آپلود مجدد برای ادامهٔ کار)</a> |
| 509 | <button class="btn danger block" data-action="delete-session">حذف جلسه از حافظه</button> |
| 510 | </div> |
| 511 | <p class="muted">جلسهها فقط در حافظهٔ سرور هستند؛ «ذخیرهٔ کارگاه» را دانلود کنید و بعداً دوباره آپلود کنید تا کار ادامه یابد.</p> |
| 512 | </div> |
| 513 | <div class="card" style="margin-bottom:14px"> |
| 514 | <h3 style="margin-top:0">شناسنامه</h3> |
| 515 | <div class="provenance-grid"> |
| 516 | ${prov("SHA-256 فایل ورودی", report.source_sha256, true)} |
| 517 | ${prov("زمان ایجاد (UTC)", session.created_at, true)} |
| 518 | ${prov("منبع", session.source === "demo" ? "دموی ساختگی" : `فایل ${session.filename}`)} |
| 519 | ${prov("نسخهٔ موتور", report.engine_version, true)} |
| 520 | </div> |
| 521 | </div> |
| 522 | <div class="card"> |
| 523 | <h3 style="margin-top:0">ردّ ممیزی (${trail.length})</h3> |
| 524 | ${trail.length ? `<div class="table-wrap"><table> |
| 525 | <thead><tr><th>زمان</th><th>کاربر</th><th>حساب</th><th>اقدام</th><th>قبل</th><th>بعد</th></tr></thead> |
| 526 | <tbody>${trail.map((e) => `<tr><td class="mono">${esc(e.at)}</td><td>${esc(e.actor)}</td><td class="mono">${esc(e.account_code)}</td><td>${esc(e.action)}</td><td class="mono">${esc(e.before)}</td><td class="mono">${esc(e.after)}</td></tr>`).join("")}</tbody> |
| 527 | </table></div>` : `<p class="muted">هنوز تغییری ثبت نشده است.</p>`} |
| 528 | </div>`; |
| 529 | } |
| 530 | function openCompany() { |
| 531 | const c = S.data.report.company; |
| 532 | openSheet("ویرایش شرکت", `<div class="form-grid"> |
| 533 | <div class="form-field full"><span>نام شرکت *</span><input id="c-name" value="${esc(c.name)}"></div> |
| 534 | <div class="form-field"><span>کد شرکت *</span><input id="c-code" value="${esc(c.code)}"></div> |
| 535 | <div class="form-field"><span>سال مالی *</span><input id="c-year" inputmode="numeric" value="${c.fiscal_year}"></div> |
| 536 | <div class="form-field"><span>واحد پول</span><input id="c-unit" value="${esc(c.unit)}"></div> |
| 537 | <div class="form-field"><span>ارز</span><input id="c-currency" value="${esc(c.currency)}"></div> |
| 538 | <div class="form-field full"><span>تهیهکننده</span><input id="c-prepared" value="${esc(c.prepared_by)}"></div> |
| 539 | </div> |
| 540 | <div class="form-actions"><button class="btn primary" data-action="submit-company">ذخیره</button> |
| 541 | <button class="btn ghost" data-action="close-sheet">انصراف</button></div>`); |
| 542 | } |
| 543 | async function submitCompany() { |
| 544 | try { |
| 545 | applyPayload(await api(`/sessions/${sid()}/company`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: $("#c-name").value, code: $("#c-code").value, fiscal_year: parseInt($("#c-year").value, 10), unit: $("#c-unit").value, currency: $("#c-currency").value, prepared_by: $("#c-prepared").value, actor: actor() }) })); |
| 546 | closeSheet(); toast("اطلاعات شرکت ویرایش شد.", "success"); |
| 547 | } catch (err) { toast(err.message, "error"); } |
| 548 | } |
| 549 | async function deleteSession() { |
| 550 | if (!confirm("جلسه از حافظهٔ سرور حذف شود؟ فایلهای دانلودشده باقی میمانند.")) return; |
| 551 | try { await api(`/sessions/${sid()}`, { method: "DELETE" }); leaveWorkspace(); toast("جلسه حذف شد.", "success"); } |
| 552 | catch (err) { toast(err.message, "error"); } |
| 553 | } |
| 554 | |
| 555 | /* ---------------- events ---------------- */ |
| 556 | document.addEventListener("click", (e) => { |
| 557 | const el = e.target.closest("[data-action]"); |
| 558 | if (!el) return; |
| 559 | const { action, code, key } = el.dataset; |
| 560 | const findAcc = (c) => S.data.accounts.find((a) => a.code === c); |
| 561 | if (action === "close-sheet") closeSheet(); |
| 562 | else if (action === "add-account") { openSheet("افزودن حساب جدید", accountFormHtml(null), () => wireAccountForm(null)); } |
| 563 | else if (action === "edit-account") { const a = findAcc(code); openSheet(`ویرایش حساب ${code}`, accountFormHtml(a), () => wireAccountForm(a)); } |
| 564 | else if (action === "submit-account") submitAccount(code); |
| 565 | else if (action === "rename-account") openRename(findAcc(code)); |
| 566 | else if (action === "submit-rename") submitRename(code); |
| 567 | else if (action === "delete-account") deleteAccount(code); |
| 568 | else if (action === "map-account") openMapping(findAcc(code)); |
| 569 | else if (action === "submit-mapping") submitMapping(code); |
| 570 | else if (action === "clear-mapping") clearMapping(code); |
| 571 | else if (action === "resolve-exception") { S.tab = "accounts"; renderAll(); openMapping(findAcc(code)); } |
| 572 | else if (action === "add-note") openSheet("افزودن یادداشت جدید", noteFormHtml(null), () => { $("#n-statement").value = "BS"; }); |
| 573 | else if (action === "edit-note") { const n = S.data.notes.find((x) => `${x.statement}|${x.section}|${x.note_number}|${x.subnote_code}` === key); openSheet("ویرایش یادداشت", noteFormHtml(n), () => { $("#n-statement").value = n.statement; }); } |
| 574 | else if (action === "submit-note") submitNote(key); |
| 575 | else if (action === "delete-note") deleteNote(key); |
| 576 | else if (action === "view-statement") { S.statementView = code; renderStatements(); } |
| 577 | else if (action === "toggle-line") { S.expanded.has(key) ? S.expanded.delete(key) : S.expanded.add(key); renderStatements(); } |
| 578 | else if (action === "print") window.print(); |
| 579 | else if (action === "edit-company") openCompany(); |
| 580 | else if (action === "submit-company") submitCompany(); |
| 581 | else if (action === "delete-session") deleteSession(); |
| 582 | }); |
| 583 | |
| 584 | document.addEventListener("DOMContentLoaded", async () => { |
| 585 | $("#actor-input").value = localStorage.getItem("aram-actor") || ""; |
| 586 | $("#actor-input").addEventListener("input", (e) => localStorage.setItem("aram-actor", e.target.value)); |
| 587 | $("#upload-btn").addEventListener("click", () => $("#file-input").click()); |
| 588 | $("#file-input").addEventListener("change", (e) => { if (e.target.files[0]) uploadFile(e.target.files[0]); }); |
| 589 | $("#demo-btn").addEventListener("click", startDemo); |
| 590 | $("#new-session-btn").addEventListener("click", leaveWorkspace); |
| 591 | $("#sheet-close").addEventListener("click", closeSheet); |
| 592 | $("#sheet-backdrop").addEventListener("click", closeSheet); |
| 593 | $("#tabbar").addEventListener("click", (e) => { |
| 594 | const tab = e.target.closest(".tab"); |
| 595 | if (!tab || !S.data) return; |
| 596 | S.tab = tab.dataset.tab; renderAll(); window.scrollTo({ top: 0 }); |
| 597 | }); |
| 598 | try { S.meta = await api("/meta"); renderPolicy(); } |
| 599 | catch (err) { toast("بارگذاری اطلاعات موتور ناموفق بود: " + err.message, "error"); } |
| 600 | }); |