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

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

Synced Dec 4, 16:45 UTC

dependabot/pip/backend/pytest-cov-gte-6.0-and-lt-8
add-index-html-10623938925177053894 arena/094f314c-aram arena/2d4eda07-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 dependabot/github_actions/actions/checkout-7 dependabot/github_actions/actions/setup-node-6 dependabot/github_actions/actions/setup-python-7 dependabot/github_actions/actions/upload-artifact-7 dependabot/npm_and_yarn/frontend/eslint-plugin-react-hooks-7.1.1 dependabot/npm_and_yarn/frontend/vite-8.4.0 dependabot/npm_and_yarn/frontend/vitest-5.1.2 dependabot/pip/backend/mypy-gte-1.13-and-lt-3 dependabot/pip/backend/pytest-cov-gte-6.0-and-lt-8 dependabot/pip/backend/setuptools-gte-75-and-lt-85 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 186 lines 5.55 KB
Raw
1 import { useCallback, useEffect, useState } from 'react'
2 import { api, ApiError } from '../api/client'
3 import type { NoteRole } from '../api/types'
4 import { faNumber } from '../lib/format'
5
6 interface Props {
7 yearId: number
8 refreshKey: number
9 }
10
11 interface NoteRow {
12 note_id: number
13 note_number: string
14 title: string
15 statement: string
16 section: string
17 role: NoteRole | null
18 }
19
20 const ROLE_LABELS: Record<string, string> = {
21 '': '—',
22 cash: 'نقد (کنترل C-10)',
23 retained_earnings: 'سود انباشته (کنترل C-08)',
24 }
25
26 interface MappingRow {
27 mapping_id: number
28 account_code: string
29 target_note_id: number
30 mapping_type: string
31 }
32
33 export default function NotesManager({ yearId, refreshKey }: Props) {
34 const [notes, setNotes] = useState<NoteRow[]>([])
35 const [mappings, setMappings] = useState<MappingRow[]>([])
36 const [edits, setEdits] = useState<Record<number, string>>({})
37 const [roles, setRoles] = useState<Record<number, string>>({})
38 const [error, setError] = useState<string | null>(null)
39 const [message, setMessage] = useState<string | null>(null)
40
41 const load = useCallback(async () => {
42 try {
43 const [n, m] = await Promise.all([api.listNotes(yearId), api.listMappings(yearId)])
44 setNotes(n.notes)
45 setMappings(m.mappings)
46 } catch (err) {
47 setError(err instanceof ApiError ? err.message : String(err))
48 }
49 }, [yearId])
50
51 useEffect(() => {
52 void load()
53 }, [load, refreshKey])
54
55 async function act(fn: () => Promise<unknown>, ok: string) {
56 setError(null)
57 setMessage(null)
58 try {
59 await fn()
60 setMessage(ok)
61 await load()
62 } catch (err) {
63 setError(err instanceof ApiError ? err.message : String(err))
64 }
65 }
66
67 const noteNumber = (id: number) => notes.find((n) => n.note_id === id)?.note_number ?? String(id)
68
69 return (
70 <section className="card">
71 <h2>مدیریت یادداشت‌ها و نگاشت‌ها</h2>
72 {message && <p className="ok">{message}</p>}
73 {error && <p className="error">{error}</p>}
74
75 <h3>یادداشت‌ها ({faNumber(notes.length)})</h3>
76 <table>
77 <thead>
78 <tr>
79 <th>شماره</th>
80 <th>عنوان</th>
81 <th>صورت/بخش</th>
82 <th>نقش کنترلی</th>
83 <th>عملیات</th>
84 </tr>
85 </thead>
86 <tbody>
87 {notes.map((n) => (
88 <tr key={n.note_id}>
89 <td className="mono">{n.note_number}</td>
90 <td>
91 <input
92 value={edits[n.note_id] ?? n.title}
93 onChange={(e) => setEdits((s) => ({ ...s, [n.note_id]: e.target.value }))}
94 />
95 </td>
96 <td className="muted">
97 {n.statement}/{n.section}
98 </td>
99 <td>
100 <select
101 aria-label={`نقش کنترلی یادداشت ${n.note_number}`}
102 value={roles[n.note_id] ?? n.role ?? ''}
103 onChange={(e) => setRoles((s) => ({ ...s, [n.note_id]: e.target.value }))}
104 >
105 {Object.entries(ROLE_LABELS).map(([value, label]) => (
106 <option key={value} value={value}>
107 {label}
108 </option>
109 ))}
110 </select>
111 </td>
112 <td>
113 <button
114 type="button"
115 onClick={() =>
116 act(
117 () => {
118 const role = roles[n.note_id] ?? n.role ?? ''
119 return api.updateNote(yearId, n.note_id, {
120 title: edits[n.note_id] ?? n.title,
121 ...(role ? { role: role as NoteRole } : {}),
122 })
123 },
124 'یادداشت به‌روز شد.',
125 )
126 }
127 >
128 ذخیره
129 </button>{' '}
130 <button
131 type="button"
132 onClick={() => act(() => api.deleteNote(yearId, n.note_id), 'یادداشت حذف شد.')}
133 >
134 حذف
135 </button>
136 </td>
137 </tr>
138 ))}
139 {notes.length === 0 && (
140 <tr>
141 <td colSpan={5} className="muted">
142 یادداشتی وجود ندارد.
143 </td>
144 </tr>
145 )}
146 </tbody>
147 </table>
148
149 <h3>نگاشت‌ها ({faNumber(mappings.length)})</h3>
150 <table>
151 <thead>
152 <tr>
153 <th>کد حساب</th>
154 <th>یادداشت مقصد</th>
155 <th>نوع</th>
156 <th>عملیات</th>
157 </tr>
158 </thead>
159 <tbody>
160 {mappings.map((m) => (
161 <tr key={m.mapping_id}>
162 <td className="mono">{m.account_code}</td>
163 <td>{noteNumber(m.target_note_id)}</td>
164 <td className="muted">{m.mapping_type}</td>
165 <td>
166 <button
167 type="button"
168 onClick={() => act(() => api.deleteMapping(yearId, m.mapping_id), 'نگاشت حذف شد.')}
169 >
170 حذف
171 </button>
172 </td>
173 </tr>
174 ))}
175 {mappings.length === 0 && (
176 <tr>
177 <td colSpan={4} className="muted">
178 نگاشتی وجود ندارد.
179 </td>
180 </tr>
181 )}
182 </tbody>
183 </table>
184 </section>
185 )
186 }