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

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

Synced Dec 4, 16:45 UTC

dependabot/github_actions/actions/setup-node-6
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 129 lines 3.98 KB
Raw
1 import { useCallback, useEffect, useState } from 'react'
2 import { api, ApiError } from '../api/client'
3 import type { DrillDownResult, Statement } from '../api/types'
4 import { faNumber, formatRial } from '../lib/format'
5 import DrillDown from './DrillDown'
6
7 interface Props {
8 yearId: number
9 refreshKey: number
10 }
11
12 export default function StatementView({ yearId, refreshKey }: Props) {
13 const [statements, setStatements] = useState<Statement[]>([])
14 const [active, setActive] = useState<string>('BS')
15 const [busy, setBusy] = useState(false)
16 const [error, setError] = useState<string | null>(null)
17 const [unmapped, setUnmapped] = useState<string[]>([])
18 const [drill, setDrill] = useState<DrillDownResult | null>(null)
19
20 const load = useCallback(async () => {
21 try {
22 const res = await api.listStatements(yearId)
23 setStatements(res.statements)
24 } catch (err) {
25 setError(err instanceof ApiError ? err.message : String(err))
26 }
27 }, [yearId])
28
29 useEffect(() => {
30 void load()
31 }, [load, refreshKey])
32
33 async function build() {
34 setBusy(true)
35 setError(null)
36 try {
37 const res = await api.buildStatements(yearId)
38 setUnmapped(res.unmapped_accounts)
39 await load()
40 } catch (err) {
41 setError(err instanceof ApiError ? err.message : String(err))
42 } finally {
43 setBusy(false)
44 }
45 }
46
47 async function openDrill(lineId: number) {
48 setError(null)
49 try {
50 setDrill(await api.drillDown(lineId))
51 } catch (err) {
52 setError(err instanceof ApiError ? err.message : String(err))
53 }
54 }
55
56 const current = statements.find((s) => s.type === active)
57
58 return (
59 <section className="card">
60 <h2>صورت‌های مالی</h2>
61 <div className="row">
62 <button type="button" onClick={build} disabled={busy}>
63 {busy ? 'در حال ساخت…' : 'ساخت صورت‌های مالی'}
64 </button>
65 <button type="button" onClick={() => void api.downloadStatements(yearId, 'xlsx')} disabled={busy}>
66 خروجی اکسل
67 </button>
68 <button type="button" onClick={() => void api.downloadStatements(yearId, 'json')} disabled={busy}>
69 خروجی JSON
70 </button>
71 <div className="tabs">
72 {['BS', 'IS', 'CF', 'EQ'].map((t) => (
73 <button
74 key={t}
75 type="button"
76 className={active === t ? 'tab active' : 'tab'}
77 onClick={() => setActive(t)}
78 >
79 {t}
80 </button>
81 ))}
82 </div>
83 </div>
84
85 {unmapped.length > 0 && (
86 <p className="error">حساب‌های نگاشت‌نشده: {unmapped.join('، ')}</p>
87 )}
88 {error && <p className="error">{error}</p>}
89
90 {current ? (
91 <table>
92 <thead>
93 <tr>
94 <th>ردیف</th>
95 <th>شرح</th>
96 <th>مبلغ (ریال)</th>
97 <th>ریشه‌یابی</th>
98 </tr>
99 </thead>
100 <tbody>
101 {current.lines.map((line) => (
102 <tr key={line.id}>
103 <td className="num">{faNumber(line.line_order)}</td>
104 <td>{line.label}</td>
105 <td className="num">{formatRial(line.mapped_total)}</td>
106 <td>
107 <button type="button" onClick={() => void openDrill(line.id)}>
108 مشاهدهٔ منبع
109 </button>
110 </td>
111 </tr>
112 ))}
113 {current.lines.length === 0 && (
114 <tr>
115 <td colSpan={4} className="muted">
116 این صورت هنوز ساخته نشده است.
117 </td>
118 </tr>
119 )}
120 </tbody>
121 </table>
122 ) : (
123 <p className="muted">صورتی برای نمایش وجود ندارد؛ ابتدا «ساخت صورت‌های مالی» را بزنید.</p>
124 )}
125
126 {drill && <DrillDown result={drill} onClose={() => setDrill(null)} />}
127 </section>
128 )
129 }