@davoodmehraban89 / Aram-2 Mirror · read-only
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 03:00 UTC

source-data-cleanup
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
tsx 157 lines 4.45 KB
Raw
1 import { useCallback, useEffect, useState } from 'react'
2 import { api, ApiError } from '../api/client'
3 import { faNumber } from '../lib/format'
4
5 interface Props {
6 yearId: number
7 refreshKey: number
8 }
9
10 interface NoteRow {
11 note_id: number
12 note_number: string
13 title: string
14 statement: string
15 section: string
16 }
17
18 interface MappingRow {
19 mapping_id: number
20 account_code: string
21 target_note_id: number
22 mapping_type: string
23 }
24
25 export default function NotesManager({ yearId, refreshKey }: Props) {
26 const [notes, setNotes] = useState<NoteRow[]>([])
27 const [mappings, setMappings] = useState<MappingRow[]>([])
28 const [edits, setEdits] = useState<Record<number, string>>({})
29 const [error, setError] = useState<string | null>(null)
30 const [message, setMessage] = useState<string | null>(null)
31
32 const load = useCallback(async () => {
33 try {
34 const [n, m] = await Promise.all([api.listNotes(yearId), api.listMappings(yearId)])
35 setNotes(n.notes)
36 setMappings(m.mappings)
37 } catch (err) {
38 setError(err instanceof ApiError ? err.message : String(err))
39 }
40 }, [yearId])
41
42 useEffect(() => {
43 void load()
44 }, [load, refreshKey])
45
46 async function act(fn: () => Promise<unknown>, ok: string) {
47 setError(null)
48 setMessage(null)
49 try {
50 await fn()
51 setMessage(ok)
52 await load()
53 } catch (err) {
54 setError(err instanceof ApiError ? err.message : String(err))
55 }
56 }
57
58 const noteNumber = (id: number) => notes.find((n) => n.note_id === id)?.note_number ?? String(id)
59
60 return (
61 <section className="card">
62 <h2>مدیریت یادداشت‌ها و نگاشت‌ها</h2>
63 {message && <p className="ok">{message}</p>}
64 {error && <p className="error">{error}</p>}
65
66 <h3>یادداشت‌ها ({faNumber(notes.length)})</h3>
67 <table>
68 <thead>
69 <tr>
70 <th>شماره</th>
71 <th>عنوان</th>
72 <th>صورت/بخش</th>
73 <th>عملیات</th>
74 </tr>
75 </thead>
76 <tbody>
77 {notes.map((n) => (
78 <tr key={n.note_id}>
79 <td className="mono">{n.note_number}</td>
80 <td>
81 <input
82 value={edits[n.note_id] ?? n.title}
83 onChange={(e) => setEdits((s) => ({ ...s, [n.note_id]: e.target.value }))}
84 />
85 </td>
86 <td className="muted">
87 {n.statement}/{n.section}
88 </td>
89 <td>
90 <button
91 type="button"
92 onClick={() =>
93 act(
94 () => api.updateNote(yearId, n.note_id, { title: edits[n.note_id] ?? n.title }),
95 'عنوان یادداشت به‌روز شد.',
96 )
97 }
98 >
99 ذخیره
100 </button>{' '}
101 <button
102 type="button"
103 onClick={() => act(() => api.deleteNote(yearId, n.note_id), 'یادداشت حذف شد.')}
104 >
105 حذف
106 </button>
107 </td>
108 </tr>
109 ))}
110 {notes.length === 0 && (
111 <tr>
112 <td colSpan={4} className="muted">
113 یادداشتی وجود ندارد.
114 </td>
115 </tr>
116 )}
117 </tbody>
118 </table>
119
120 <h3>نگاشت‌ها ({faNumber(mappings.length)})</h3>
121 <table>
122 <thead>
123 <tr>
124 <th>کد حساب</th>
125 <th>یادداشت مقصد</th>
126 <th>نوع</th>
127 <th>عملیات</th>
128 </tr>
129 </thead>
130 <tbody>
131 {mappings.map((m) => (
132 <tr key={m.mapping_id}>
133 <td className="mono">{m.account_code}</td>
134 <td>{noteNumber(m.target_note_id)}</td>
135 <td className="muted">{m.mapping_type}</td>
136 <td>
137 <button
138 type="button"
139 onClick={() => act(() => api.deleteMapping(yearId, m.mapping_id), 'نگاشت حذف شد.')}
140 >
141 حذف
142 </button>
143 </td>
144 </tr>
145 ))}
146 {mappings.length === 0 && (
147 <tr>
148 <td colSpan={4} className="muted">
149 نگاشتی وجود ندارد.
150 </td>
151 </tr>
152 )}
153 </tbody>
154 </table>
155 </section>
156 )
157 }