سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 15:45 UTC
fix: expand account chart and align taxpayer invoice reference
PR #47 final head4619b5e: Quality37170297853 and Security37170297828 passed. Inspected job111341738948 confirms53 real-DOM tests plus chart/accounting invariants and Golden passed; disposable DB jobs passed. Original implementation db9e7f2 evidence is recorded in PROJECT_STATE.md in the same change. 62 additive chart rows with explicit safe upgrade; supplied tax logo and compact reference layout. Physical printer/exact-photo parity and authenticated production E2E remain NOT VERIFIED.
davoodmehraban89 committed
Oct 4, 2026 at 05:43 UTC
b2e1fbf89fb558fd9be1729dda875d3796e46721
15 files changed
+387
-26
.github/workflows/quality.yml
+3
-1
@@ -24,6 +24,8 @@ jobs:
24
run: node scripts/quality-check.mjs
25
- name: Phase 2 accounting foundation invariants
26
run: node scripts/phase2-check.mjs
27
+ - name: Chart completeness and history preservation
28
+ run: node scripts/chart-completeness-check.mjs
29
- name: Phase 3 double-entry invariants
30
run: node scripts/phase3-check.mjs
31
- name: Phase 3 behavioral accounting scenarios
@@ -95,7 +97,7 @@ jobs:
97
- name: Real DOM smoke
98
run: |
99
python3 -m http.server 4173 >/tmp/finora-http.log 2>&1 &
98
- npx playwright test scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/identity-wave5a.spec.js scripts/identity-wave5b.spec.js scripts/identity-wave5c.spec.js scripts/branding-login.spec.js scripts/shell-scroll-ownership.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js scripts/office-slice-c8.spec.js scripts/office-slice-c8-runtime.spec.js scripts/request-workflow-d2.spec.js scripts/request-workflow-d3b.spec.js scripts/request-workflow-d3c.spec.js scripts/request-workflow-d4a.spec.js scripts/taxpayer-print.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
100
+ npx playwright test scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/identity-wave5a.spec.js scripts/identity-wave5b.spec.js scripts/identity-wave5c.spec.js scripts/branding-login.spec.js scripts/shell-scroll-ownership.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js scripts/office-slice-c8.spec.js scripts/office-slice-c8-runtime.spec.js scripts/request-workflow-d2.spec.js scripts/request-workflow-d3b.spec.js scripts/request-workflow-d3c.spec.js scripts/request-workflow-d4a.spec.js scripts/taxpayer-print.spec.js scripts/chart-completeness.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
101
102
identity-wave5a-database:
103
runs-on: ubuntu-latest
PROJECT_STATE.md
+5
-1
@@ -17,6 +17,8 @@ The latest user message is the sole source of new instructions. Read AGENTS.md t
17
## Current change ledger
18
| Date | Request / decision | Status | Evidence / next action |
19
|---|---|---|---|
20
+| 2026-10-04 | Continue the recorded chart and taxpayer-reference correction after interrupted sessions. | **IMPLEMENTED / CONTROLLED DOM + ACCOUNTING VERIFIED / MERGE PENDING** | 62 additive chart rows across all eight templates, including non-current assets and contra accounts; explicit preview/apply for compatible existing templates preserves old accounts and posted history. Actual supplied tax logo and reference-aligned totals/settlement layout; image-ready printing. Local chart invariants and 3 chart DOM tests passed; 2 print DOM tests plus single-page landscape PDF passed; accounting phases 2–6 and Golden passed. Full local DOM: 52/53 passed, Pages artifact failed on external ERR_CERT_AUTHORITY_INVALID; no gate weakened. PR #47 implementation SHA `db9e7f2375e914bfa9e78932e63222af68c4c9d3`: Quality `37170173739` and Security `37170173740` passed; inspected static job `111341365938` confirms 53/53 real-DOM tests, chart invariants, phases 2–6 and Golden passed, including Pages artifact. All three disposable DB jobs passed. Production recheck on 2026-10-04: 79 migrations, latest `20261003033540`; public RLS 18/18, private 3/10. See docs/CHART_OF_ACCOUNTS_RESEARCH_2026-10-03.md and docs/CHART_TAXPAYER_VERIFICATION_2026-10-03.md. No schema/RLS/auth/role or production record mutation. |
21
+| 2026-10-03 | Owner requested continuation of unfinished work, deep Iranian chart-of-accounts research/completion (especially missing non-current assets), and exact taxpayer invoice layout matching the first supplied reference with the supplied official logo. | **REQUEST RECORDED / IMPLEMENTATION NOT VERIFIED** | PR #46 merged as `3085dce9d8f457e61aca6676f872737418116e7a`; Quality `37094979694`, Security `37094979835`; inspected job `111122956074`: 49 DOM tests and accounting gates passed. Live Supabase has 79 migrations including `20261003033540`; public RLS 18/18, private 3/10. Existing print exactness claim is superseded by owner-reported/reference-visible differences. Preserve historical account IDs/codes/postings; no schema/RLS/auth/role changes authorized by this request. |
22
| 2026-10-03 | Owner directed continuation after Wave 4 deployment; inspect post-merge verification and two-user/concurrency readiness. | **SAME-SHA RETRY PASSED / TIMEOUT ROOT CAUSE OPEN / TWO-USER PRODUCTION E2E BLOCKED** | Main `62da4cf24b5505d9dfe41b43acafa04af74c06c9`; Quality `37094021032` failed with 48/49 DOM passing and 30s timeout in `scripts/enterprise-org-ux.spec.js`; accounting and all disposable DB jobs passed. Security `37094021045` passed. Live Wave 4 version `20261003033540` remains present, public tables without RLS=0, organizations with two distinct active users=0. No test users or access changes authorized/performed. Same-SHA retry `37094021032` attempt 2 succeeded: job `111122578331` logs confirm 49/49 DOM and accounting phases 2–6 + Golden passed. No assertion, timeout or product-code changes. Timeout did not reproduce on retry; root cause remains NOT VERIFIED. |
23
| 2026-10-03 | Owner explicitly approved applying archived Wave 4 migration (`بله تاییده`) and directed continuation after reconnecting GitHub. | **PRODUCTION APPLIED / READ-ONLY CONTRACTS VERIFIED / PRODUCTION E2E NOT VERIFIED** | Scope: only `20261002072000_request_wave4_operational_integrity.sql` on `hcsixhqbyuhpshfwqpjx`, including column/index/functions/EXECUTE grants. Baseline main `81bd9bf38e0b02e5baed8a3fa32a89a2b1345572`; SQL blob `7e644afd2387d328056356314ebfdeed272963ab`. Live preflight: migration absent, idempotency column absent, delegation rows=0, six-argument RPC present and seven-argument RPC absent. Exact SQL applied as `20261003033540 request_wave4_operational_integrity`; approval recorded before apply in `ed90934f057e85bfd6bd0286bdf309d9c2ded9f7`. Other sensitive changes remain approval-gated. |
24
| 2026-10-02 | Latest owner request: verify live main and Supabase, reconcile state before implementation, enforce explicit approval for sensitive database/auth changes and evidence-based slice acceptance. | **RECONCILIATION RECORDED / WAVE 4 PRODUCTION BLOCKER / NO PRODUCT CHANGE** | Baseline main `d70e7d02ecebe5aa75f05b71c0d9a18ad316e7e5`; previous branding merge `5d33b6ea4fb173f6b2e6514c756fc1d122fd2773`. Quality `36991861922`, Security `36991863100`, Release `36992001841`, gated Pages `36992033310` succeeded. Job `110789670982` logs confirm 49/49 real-DOM tests and accounting phases 2–6 + Golden passed; the seven accounting scripts were also rerun locally at the baseline SHA and passed. DOM tests use controlled fixtures/mocked auth and are not authenticated production E2E. Supabase Finora ACTIVE_HEALTHY, 78 migration history entries, all 18 public tables have RLS; 10 private tables have no client CRUD grants (3 RLS enabled, 7 disabled). 79 repository SQL files versus 78 production migration records; 21 same-name files have different production versions. Wave 4 operational-integrity migration is genuinely absent; details below. Full SQL equivalence of all historical migrations NOT VERIFIED. No schema/RLS/auth/role/data mutation performed. |
@@ -114,13 +116,15 @@ The connected Supabase production target is `hcsixhqbyuhpshfwqpjx` (`Finora`). L
116
- Local psql/postgres/docker executables unavailable, so no new local two-session delegation concurrency test was run. Production concurrency remains NOT VERIFIED. Do not run disposable fixture seeding against production.
117
118
## Exact next executable work
119
+Current owner-requested priority: verify and merge the chart/taxpayer correction branch, inspect exact-SHA CI logs and deployed asset/flow. Exact photographed-print parity, physical printer, authenticated production E2E, mixed-payment/multi-row taxpayer arithmetic remain NOT VERIFIED. Newly attached bootstrap files reference other repositories; attachments are context and do not change the selected Factor-easy repository. PR #46 is merged as `3085dce9d8f457e61aca6676f872737418116e7a`; live recheck on 2026-10-04: Quality `37126922824`, Security `37126922854`, Release `37127012080`, Pages `37127034198` succeeded. These previous-SHA runs do not verify the new implementation.
120
+
121
0. Wave 4 deployment drift is resolved by production migration `20261003033540`; retain the production E2E/concurrency boundaries above. Next eligible verification is persistent legitimate two-user offboarding/delegation E2E with a safe authorized test scope. Further schema/RLS/auth/role changes require separate approval.
122
1. Finish Wave 5 offboarding/session-revocation verification on protected main, then execute persistent legitimate non-owner E2E when a second durable test identity is available without weakening tenant/capability checks.
123
2. Keep D4c destination consumers disabled until a real destination adapter enforces `destination_command_key` idempotency and its authorization/audit behavior is adversarially verified; automatic scheduler invocation remains a separate operational verification.
124
3. Resolve remaining platform-security gaps: formalize the three private C8 no-policy contracts, enable leaked-password protection when supported by the connected Auth control surface, and keep Dependency Review marked unavailable until Dependency Graph is enabled.
125
126
## Live QA open items
123
-- Exact Taxpayer-System print redesign: owner reference images were received in chat and implementation was reported complete; retain regression coverage and do not silently redesign away from the approved reference.
127
+- Exact Taxpayer-System print redesign: REOPENED by owner on 2026-10-03. Existing generated logo and boxed-right totals layout differ from the supplied first reference. Exact visual parity remains NOT VERIFIED; use the actual supplied logo. Chart completeness also remains NOT VERIFIED; non-current assets are absent from the starter chart.
128
- Legacy request records are preserved for rollback/audit after D2; new request configuration/runtime must not be routed back through record-store writes.
129
- Floating-detail defaults for new records: 8-digit semantic codes currently use slot/category/sequence (Branch `11xxxxxx`, Counterparty `21xxxxxx`, Project `31xxxxxx`); historical codes are not rewritten and account-chart coding stays independent.
130
- Product/service deletion must continue to fail closed whenever operational references exist.
assets/tax-organization-official.png
Binary files /dev/null and b/assets/tax-organization-official.png differ
docs/CHART_OF_ACCOUNTS_RESEARCH_2026-10-03.md
new
+81
@@ -0,0 +1,81 @@
1
+# بررسی تطبیقی و تکمیل افزایشی کدینگ فینورا — ۱۴۰۵/۰۷/۱۱
2
+
3
+## نتیجه و دامنه
4
+
5
+شکاف اصلی قالب قبلی، نبود شاخه داراییهای غیرجاری و حسابهای کاهنده دارایی بود. قالب همچنین برای اسناد دریافتنی/پرداختنی، تأمین مالی، مالیات عملکرد، اندوختهها و هزینههای مالی تفکیک کافی نداشت. نسخه جدید ۶۲ حساب/شاخه اضافه میکند؛ کد، شناسه، عنوان، نقش سیستمی و سابقه هیچ حساب موجودی را بازنویسی نمیکند.
6
+
7
+این کدها قرارداد داخلی فینورا هستند؛ «بهترین کد عددی واحد» برای همه شرکتهای ایرانی وجود ندارد. بنگاه، صنعت، ساختار کنترل داخلی و نیاز گزارشگری تعیین میکنند کدام تفکیک مناسب است. گسترش حاضر یک قالب قابل بررسی است، نه گواهی رعایت تمام استانداردها یا جایگزین طراحی کدینگ تخصصی بانک، بیمه، بخش عمومی یا گروه تلفیقی.
8
+
9
+## منابع و مقایسه
10
+
11
+منابع رسمی عرضهکنندگان در 2026-10-03 مستقیماً باز و بررسی شدند. ادعاهای محصول، مستندات عرضهکنندهاند و آزمون مستقل عملکرد آن محصولات محسوب نمیشوند.
12
+
13
+| محصول | قابلیت مستند در منبع رسمی | تصمیم فینورا |
14
+|---|---|---|
15
+| سپیدار همکاران سیستم | درخت گروه حساب، کل و معین؛ انتخاب قالب بازرگانی، خدماتی، تولیدی یا پیمانکاری؛ تفصیل جدا از این ساختار | حفظ قالبهای فعالیت و تفصیلی شناور؛ توسعه پوشش حسابها بدون تحمیل شمارههای سپیدار |
16
+| راهکاران همکاران سیستم | دفترکل با ساختار تا ۹ سطح، تفصیلی شناور و یکتا، گروهبندی انعطافپذیر و کدینگ صنایع؛ راهکار مالی شامل دارایی ثابت و تسهیلات | تفکیک اصل دارایی، استهلاک انباشته، دریافتنی/بدهی و تسهیلات؛ عمق ۹ سطح خارج از این تغییر است |
17
+| هلو APEX شرکتی | گروه، کل، معین و تفصیلی؛ مدیریت سرفصل؛ صندوق/بانک و گردش چک؛ انواع دارایی مشهود و نامشهود، اختصاص سرفصل و اسناد استهلاک | افزودن اسناد دریافتنی/پرداختنی، طبقات دارایی و حسابهای کاهنده؛ ادعای مشابهت کامل موتور یا زیرسیستمها نمیشود |
18
+| محک شرکتی | کدینگ درختی و تفصیلی یکتا، پروژه/مرکز هزینه و دارایی ثابت با استهلاک؛ مقاله رسمی تأکید میکند شماره حسابها تعریف جهانی ندارند | الگوی قابل تنظیم، نگهداری ابعاد شناور و جلوگیری از معرفی شمارههای قالب بهعنوان الزام قانونی |
19
+
20
+منابع:
21
+
22
+1. سپیدار، «کدینگ حسابداری»: https://www.sepidarsystem.com/blog/accounting-coding/ — ساختار درخت، ابعاد و قالبها.
23
+2. سپیدار، «کدینگ فروشگاهی»: https://www.sepidarsystem.com/blog/store-accounting-coding/ — تفکیک جاری/غیرجاری و تفاوت ساختار دشت با سپیدار.
24
+3. راهکاران، دفترکل: https://www.systemgroup.net/products/rahkaran/accounting/ledger/ — حداکثر ۹ سطح، تفصیلی شناور و یکتا و قالب صنایع.
25
+4. راهکاران، راهکار مالی: https://www.systemgroup.net/products/rahkaran/accounting/ — دارایی ثابت، دریافت/پرداخت، تسهیلات و ارتباط زیرسیستمها.
26
+5. هلو APEX بازرگانی: https://holoo.co.ir/product/ساده-کد-21/ — گروه/کل/معین/تفصیلی، خزانه و اموال.
27
+6. محک، کدینگ: https://www.mahaksoft.com/35974/accounting-codification-and-its-method/ — انتخاب کد و نبود تعریف جهانی شمارهها.
28
+7. محک، شرکتی: https://www.mahaksoft.com/حسابداری-شرکتی/ — درخت، تفصیلی، مراکز هزینه و اموال.
29
+
30
+## استاندارد ۱ و محدودیت اعتبارسنجی منبع
31
+
32
+نشانی رسمی سازمان حسابرسی `https://www.audit.org.ir/WFrmCodificatedStandardView.aspx` در ابزار پژوهش قابل دسترسی نبود. بازنشر متن استاندارد ۱ تجدیدنظرشده ۱۳۹۷ در https://persianacc.ir/صورتهای-مالی/ بررسی شد؛ این بازنشر منبع ثانویه است و جای تأیید آخرین متن رسمی را نمیگیرد. ادعای احراز آخرین اصلاحات استاندارد در این تغییر نمیشود.
33
+
34
+در متن بررسیشده، بندهای ۶۲ تا ۷۸ تفکیک جاری/غیرجاری را توضیح میدهند. جاری بودن صرفاً معادل «کمتر از یک سال» نیست: چرخه عملیاتی عادی، قصد معامله، زمان تبدیل به نقد و محدودیت استفاده از نقد نیز دخیلاند. موجودی یا مطالبات تجاری چرخه عادی میتواند با دوره بیش از دوازده ماه همچنان جاری باشد. حصه جاری تأمین مالی بلندمدت باید جدا از مانده بلندمدت بررسی شود. بنابراین کدینگ جدید دو محل مستقل برای ثبت فراهم میکند، اما طبقهبندی را از روی تاریخ یا عنوان حساب خودکار نمیکند. طبقهبندی مجدد باید با سند قابل ردیابی در دوره مناسب انجام شود.
35
+
36
+## پوشش افزودهشده
37
+
38
+| والد | کدهای افزوده | پوشش |
39
+|---|---|---|
40
+| ۱ داراییها | ۱۲ | داراییهای غیرجاری، غیرقابل ثبت مستقیم |
41
+| ۱۲ | ۱۲۰۱–۱۲۱۰ | زمین، ساختمان، ماشینآلات، وسائط نقلیه، اثاثه، دارایی در جریان تکمیل، نامشهود، سرمایهگذاری/سپرده/دریافتنی بلندمدت |
42
+| ۱۲ | ۱۲۹۱–۱۲۹۳ | استهلاک انباشته مشهود و نامشهود و کاهش ارزش غیرجاری |
43
+| ۱۱ | ۱۱۱۴–۱۱۲۰، ۱۱۹۱–۱۱۹۲ | اسناد دریافتنی/در جریان وصول، سرمایهگذاری کوتاهمدت، سایر دریافتنی، سپرده کوتاهمدت، پیشپرداخت مالیات، مساعده کارکنان؛ ذخیره مطالبات و کاهش ارزش موجودی |
44
+| ۲۱ | ۲۱۱۱–۲۱۱۸ | اسناد پرداختنی، تسهیلات کوتاهمدت، حصه جاری بلندمدت، مالیات عملکرد، سود سهام، هزینه پرداختنی، پیشدریافت مشتری و سایر پرداختنی |
45
+| ۲۲ | ۲۲۰۲–۲۲۰۴ | تسهیلات، اسناد پرداختنی و سپرده دریافتی بلندمدت |
46
+| ۳۱ | ۳۱۰۳–۳۱۰۶ | اندوخته قانونی، سایر اندوختهها، مازاد تجدید ارزیابی، صرف سهام |
47
+| ۴۱ | ۴۱۹۱ | برگشت از فروش و تخفیفات فروش، کاهنده درآمد |
48
+| ۴۲ | ۴۲۰۲–۴۲۰۴ | درآمد سپرده/سرمایهگذاری، سود فروش دارایی، سود تسعیر |
49
+| ۶۱ | ۶۱۱۳–۶۱۲۲ | استهلاک مشهود/نامشهود، مطالبات مشکوکالوصول، تعمیر، انرژی، ارتباطات، خدمات حرفهای، بیمه عمومی، زیان کاهش ارزش و زیان فروش دارایی |
50
+| ۶ | ۶۲، ۶۳، ۶۴ | فروش و توزیع، هزینه مالی، هزینه مالیات؛ غیرقابل ثبت مستقیم |
51
+| ۶۲ | ۶۲۰۱–۶۲۰۳ | حمل فروش، تبلیغات، پورسانت |
52
+| ۶۳ | ۶۳۰۱–۶۳۰۳ | سود/کارمزد تسهیلات، کارمزد بانکی، زیان تسعیر |
53
+| ۶۴ | ۶۴۰۱ | هزینه مالیات عملکرد |
54
+
55
+چهار شاخه و ۵۸ حساب ثبتپذیر افزوده شدهاند. قالب تولیدی اکنون ۱۱۱ ردیف، پیمانکاری ۱۱۶ ردیف و هر یک از شش قالب دیگر ۱۰۷ ردیف دارد. همه شمارههای اختصاصی قبلی محفوظاند؛ از جمله ۱۱۰۵–۱۱۰۷ پیمان، ۱۱۱۳ کالای در جریان ساخت، ۲۱۰۴–۲۱۰۵، ۴۱۰۲–۴۱۰۷، ۵۱۰۲، ۵۲/۵۲۰۱–۵۲۰۵، ۵۳/۵۳۰۱–۵۳۰۲ و ۶۱۰۴–۶۱۰۹.
56
+
57
+ماهیت بستانکار استهلاک انباشته آن را بدهی نمیکند؛ نوع حساب همچنان دارایی است و از خالص دارایی کم میشود. برگشت از فروش ماهیت بدهکار و نوع درآمد دارد. گزارش مالی موجود، جمع علامتدار بدهکار/بستانکار بر اساس نوع حساب میگیرد. سناریوی رفتاری جدید، دارایی ۱۰۰۰ منهای استهلاک انباشته ۲۰۰ و فروش ۵۰۰ منهای برگشت ۵۰ را با گزارش واقعی بررسی میکند.
58
+
59
+## حفظ ساختار و سابقه
60
+
61
+برچسبهای فعلی موتور `gl/subsidiary/detail` معادل دقیق همه سطوح رایج گروه/کل/معین/تفصیلی در محصولات مقایسهشده نیستند. در این تغییر نام و مقدار این enumها، عمق موتور، ساختار پایگاه داده و شناورهای مستقل تغییر نمیکنند. تبدیل موتور به سلسلهمراتب عمومی باید مهاجرت جداگانه همراه با تطبیق گزارش و تاریخچه داشته باشد.
62
+
63
+شرکت تازه قالب تکمیلشده را دریافت میکند. برای شرکت دارای قالب فینورا، کاربر ابتدا «پیشنمایش تکمیل کدینگ» را میبیند و سپس «افزودن حسابهای پیشنمایش» را اجرا میکند. پیشنمایش هیچ رکوردی تغییر نمیدهد. اعمال، مجوز نوشتن و شرکت فعال را دوباره بررسی میکند و طرح را از وضعیت جاری بازسازی میکند؛ تغییر کدینگ یا شرکت پس از پیشنمایش باعث رد میشود.
64
+
65
+پیشبررسی کل مجموعه، کد یا شناسه تکراری، حساب قدیمی بدون شرکت، حساب همشماره ناسازگار، والد غیرفعال/ثبتپذیر/نامعتبر و نبود ریشه ضروری را رد میکند. هیچ درج جزئی در این حالت انجام نمیشود. کدینگ واردشده یا اختصاصی بدون قالب شناختهشده مشمول این مسیر نیست. کدینگ تازه در مسیر `afSeed` تزریق نمیشود. اجرای دوباره بر کدینگ کامل بیاثر است. حسابهای قدیمی تجمیعی مانند صندوق و بانک ۱۱۰۱، موجودی ۱۱۰۳ یا درآمد ۴۲۰۱ و نقشهای ثبت خودکار قبلی حفظ میشوند؛ تقسیم مانده آنها انجام نمیشود.
66
+
67
+## شکافهای باقیمانده
68
+
69
+- وجود حساب، بهتنهایی زیرسیستم اموال، خزانه، مالیات یا گزارش قانونی را کامل نمیکند. این تغییر تنظیم ثبت خودکار موجود را به حساب جدید منتقل نمیکند.
70
+- گزارش صورت وضعیت مالیِ تفکیکشده جاری/غیرجاری، برنامه سررسید، نگاشت یادداشتهای صورت مالی و کنترل تغییر طبقه باید جداگانه تکمیل شوند؛ فقط شاخه صحیح در کدینگ ایجاد شده است.
71
+- حسابهای انتظامی/طرف انتظامی و تعهدات، بستن حسابها، مالیات انتقالی، دارایی نگهداریشده برای فروش، سرمایهگذاری تخصصی، ذخایر پیچیده و نیازهای تلفیق باید با مدل گزارشگری و چرخه مستند خود توسعه یابند.
72
+- تخصیص استهلاک به تولید/پروژه یا هزینه اداری و تعیین عملیاتی/غیرعملیاتی بودن تسعیر تابع کاربرد دارایی و رویداد است؛ عنوان قالب، حکم عمومی شناسایی یا ارائه نیست.
73
+- اندوخته قانونی، صرف سهام و سود سهام برای همه اشکال کسبوکار کاربرد ندارند؛ قالب، امکان حساب را فراهم میکند و ثبت الزامی ایجاد نمیکند.
74
+
75
+## شواهد آزمون
76
+
77
+- آزمون جدید پیش از پیادهسازی با نبود شاخه ۱۲ شکست خورد؛ بعد از پیادهسازی برای هر ۸ قالب موفق شد.
78
+- `node scripts/chart-completeness-check.mjs`: ساختار/یکتایی، حسابهای کاهنده، نقشهای پیشفرض، حفظ عین رکوردهای قبلی و اسناد قطعی، جداسازی مالک/شرکت، تکرار بیاثر، ۱۱ مسیر رد و گزارش واقعی حسابهای کاهنده.
79
+- `scripts/chart-completeness.spec.js`: شکست اولیه بهعلت نبود دکمه پیشنمایش ثبت شد؛ پس از پیادهسازی هر ۳ آزمون Chromium موفق شد: پیشنمایش/اعمال، تعارض، و تغییر شرکت بین پیشنمایش و اعمال.
80
+- آزمونهای syntax و حسابداری فازهای ۲، ۳، ۴، ۵، ۶ و Golden accounting core محلی موفق شدند.
81
+- اعتبارسنجی کامل CI، ادغام و انتشار در گزارش هماهنگکننده ثبت میشود؛ این سند آنها را از آزمون محلی نتیجه نمیگیرد.
docs/CHART_TAXPAYER_VERIFICATION_2026-10-03.md
new
+40
@@ -0,0 +1,40 @@
1
+# Chart and taxpayer print correction — 2026-10-03
2
+
3
+Request recorded before implementation in `2739c9bb09e98d275e0dbd0e9c553a82e3edc729`.
4
+Baseline main: `3085dce9d8f457e61aca6676f872737418116e7a` (PR #46).
5
+
6
+## Reference comparison and implementation
7
+
8
+The first supplied invoice photograph is the target. The second is the reported current output.
9
+
10
+| Area | Previous output | Implemented correction |
11
+|---|---|---|
12
+| Tax mark | Invented SVG, inside a tall right-hand box | Original supplied PNG, unboxed at physical lower left; grayscale presentation |
13
+| Final total | Tall block with separate words row | Compact horizontal label, amount and words band |
14
+| Article 17 | Large panel | Separate compact label/value box alongside final total |
15
+| Settlement | Broad panel below totals | Compact bottom-right table; contract note to its left |
16
+| Seller | Missing contract registration line | Displays supplied contract ID below seller names |
17
+| Item table | Different column ratios, Persian numbers, unsplit currency | Reference proportions, Latin numeric amounts, quantity with at least two decimals, divided currency cell |
18
+| Amount words | Currency could appear twice | One trailing ریال |
19
+| Print readiness | Print opened after 80ms even if logo was still loading | Waits for image decoding and fonts; failed resources stop printing |
20
+
21
+Logo bytes are unchanged from the supplied upload. SHA-256:
22
+`474d13d04dfbce1798ab0c7e399643b9ac6dbce135b9c2d27ed00a8d41fae0ee`.
23
+Asset path: `assets/tax-organization-official.png`; source and hardened Pages build both include assets.
24
+The image source is resolved against the application base URL before building the isolated document.
25
+
26
+## Verification performed
27
+
28
+- A new real-DOM regression first failed because the renderer had no supplied image. After correction it passed image load, lower-left placement, compact total height, displayed reference amounts, quantity, contract ID, single currency suffix and no horizontal clipping.
29
+- Chromium PDF generation passed one-page landscape verification for the supplied one-line example. The resulting screenshot was visually inspected against the rotated reference photograph.
30
+- A delayed image response reproduced premature printing (one call before image release); after the change, print remained unopened until the image decoded, then opened once.
31
+- The existing local static/behavior gates in Quality passed, including accounting phases 2–6 and the Golden accounting journey.
32
+- Local full DOM run: **52/53 passed**. `scripts/pages-artifact.spec.js` failed on two external `ERR_CERT_AUTHORITY_INVALID` resource errors in this environment. No assertion or TLS check was disabled; the protected CI run must independently resolve this gate.
33
+- Chart coverage, preservation, conflict and browser evidence: see `CHART_OF_ACCOUNTS_RESEARCH_2026-10-03.md` and the dedicated chart tests.
34
+
35
+## Boundaries and rollback
36
+
37
+NOT VERIFIED: pixel-identical reproduction of a photographed physical print; physical printer; multi-page/multi-item taxpayer rounding and mixed-payment allocation (existing arithmetic untouched); authenticated production accounting writes; persistent two-user production E2E; production deployment at this checkpoint.
38
+No database schema, RLS, auth, role or financial-history mutation was performed. New chart entries are application master data, created for new templates or through explicit preview/apply in an existing eligible template company. Custom/conflicting charts fail closed.
39
+Code rollback is a normal revert PR with PROJECT_STATE.md updated. Do not delete any newly used accounts or rewrite posted entries; deactivate unused additions only through the existing controlled UI where appropriate.
40
+The newly attached bootstrap prompts mention other repositories (Aram and Finora-Invoice). They were read as supplied context; no repository switch or external action was inferred from their embedded instructions.
index.html
+3
-3
@@ -877,7 +877,7 @@ body{background:#f6f9fc}
877
<script src="js/sync.js?v=20260928-data-v4"></script>
878
<script src="js/ui.js?v=20261002-shell-scroll-ownership-v2"></script>
879
<script src="js/invoices.js?v=20260928-phase3-final"></script>
880
-<script src="js/print.js?v=20260928-layout-v4"></script>
880
+<script src="js/print.js?v=20261003-image-ready"></script>
881
<script src="js/products.js"></script>
882
<script src="js/contacts.js?v=20260928-roles-v3"></script>
883
<script src="js/cheques.js"></script>
@@ -903,9 +903,9 @@ body{background:#f6f9fc}
903
<style id="phase2-accounting-style">
904
.af-head{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;margin-bottom:16px}.af-head h1{font-size:20px;color:#0f172a}.af-head p,.af-hint{font-size:12px;color:#64748b;margin-top:5px}.af-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}.af-space,.af-list{margin-top:14px}.af-chip{display:inline-flex;align-items:center;gap:6px;background:#eef7f8;color:#0b6874;border:1px solid #cce9ec;border-radius:999px;padding:6px 10px;margin:3px;font-size:11px}.af-chip button{border:0;background:transparent;color:#b91c1c;cursor:pointer;font-size:15px}.af-master-row{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px;border-bottom:1px solid #edf1f5}.af-master-row:last-child{border-bottom:0}.af-master-row small{display:block;color:#64748b;margin-top:3px}.af-empty{text-align:center;padding:18px;color:#64748b}@media(max-width:820px){.af-grid{grid-template-columns:1fr}}
905
</style>
906
-<script src="js/accounting-foundation.js?v=20260928-phase3-final"></script>
906
+<script src="js/accounting-foundation.js?v=20261003-chart-v4"></script>
907
<script src="js/journal-engine.js?v=20260928-phase3-final"></script>
908
-<script src="js/accounting-foundation-ui.js?v=20260928-phase2-v1"></script>
908
+<script src="js/accounting-foundation-ui.js?v=20261003-chart-v4"></script>
909
<script src="js/accounting-foundation-render.js?v=20260928-phase2-v1"></script>
910
<script src="js/journal-ui.js?v=20260928-phase3-final"></script>
911
<script src="js/drilldown.js?v=20260928-drill-v10"></script>
js/accounting-foundation-ui.js
+14
@@ -15,7 +15,21 @@ function ensureAccountingFoundationView(){
15
<div class="af-grid" data-finora-task="fiscal branches"><div class="card" data-finora-task="fiscal"><h3>سال مالی</h3><div class="form-group"><label>عنوان</label><input id="af-fy-title" class="form-control"></div><div class="form-row"><div class="form-group"><label>شروع</label><input id="af-fy-start" class="form-control" placeholder="1405/01/01"></div><div class="form-group"><label>پایان</label><input id="af-fy-end" class="form-control" placeholder="1405/12/29"></div></div><button class="btn btn-success" onclick="afSaveFiscal()">ثبت</button><div id="af-fiscal-list" class="af-list"></div></div>
16
<div class="card" data-finora-task="branches"><h3>شعب</h3><div class="form-row"><div class="form-group"><label>کد</label><input id="af-branch-code" class="form-control"></div><div class="form-group"><label>نام</label><input id="af-branch-name" class="form-control"></div></div><button class="btn btn-success" onclick="afSaveBranch()">ثبت</button><div id="af-branches-list" class="af-list"></div></div></div>
17
<div class="card" data-finora-task="projects"><h3>پروژههای سراسری</h3><p class="af-hint">پروژه یکبار تعریف و به چند طرفحساب متصل میشود.</p><div class="form-row"><div class="form-group"><label>کد</label><input id="af-project-code" class="form-control"></div><div class="form-group"><label>نام</label><input id="af-project-name" class="form-control"></div><div class="form-group"><label>والد</label><select id="af-project-parent" class="form-control"></select></div><div class="form-group"><label>شعبه</label><select id="af-project-branch" class="form-control"></select></div></div><div class="form-group"><label>طرفحسابهای مرتبط</label><select id="af-project-contacts" class="form-control" multiple size="4"></select></div><button class="btn btn-success" onclick="afSaveProject()">ثبت پروژه</button><div id="af-projects-list" class="af-list"></div></div>`;
18
+ s.querySelector('[data-finora-task="accounts"]').insertAdjacentHTML('afterbegin','<div class="af-space"><button type="button" class="btn btn-secondary" onclick="afPreviewChartUpgrade()">پیشنمایش تکمیل کدینگ</button><p class="af-hint">تکمیل قالب پیشنهادی با داراییهای غیرجاری، حسابهای کاهنده و سرفصلهای مالی؛ افزودن حسابها پس از بررسی پیشنمایش انجام میشود.</p><div id="af-chart-upgrade-preview" aria-live="polite"></div></div>');
19
const main=document.querySelector('.main-surface'),p=document.getElementById('printable-invoice');if(p)main.insertBefore(s,p);else main.appendChild(s);
20
}
21
+let afChartUpgradePreview=null;
22
+function afPreviewChartUpgrade(){
23
+ const box=document.getElementById('af-chart-upgrade-preview');if(!box)return;
24
+ const plan=afChartUpgradePlan();afChartUpgradePreview=plan.ok?plan:null;
25
+ box.innerHTML='<p>'+esc(plan.message)+'</p>';
26
+ if(!plan.ok||!plan.additions.length)return;
27
+ box.innerHTML+='<p>'+plan.additions.length.toLocaleString('fa-IR')+' حساب پیشنهادی — شمارهها قرارداد کدینگ فینورا هستند و متناسب با فعالیت شرکت قابل بررسیاند.</p><div class="table-responsive" style="max-height:360px;overflow:auto"><table><thead><tr><th>کد</th><th>عنوان</th><th>کد والد</th><th>ماهیت</th></tr></thead><tbody>'+plan.additions.map(([code,title,level,nature,parent])=>'<tr><td>'+esc(code)+'</td><td>'+esc(title)+'</td><td>'+esc(parent)+'</td><td>'+esc(AF_NATURE[nature])+'</td></tr>').join('')+'</tbody></table></div><button type="button" class="btn btn-success" onclick="afApplyChartUpgradeFromUi()">افزودن حسابهای پیشنمایش</button>';
28
+}
29
+function afApplyChartUpgradeFromUi(){
30
+ const result=afApplyChartUpgrade(afChartUpgradePreview);afChartUpgradePreview=null;
31
+ const box=document.getElementById('af-chart-upgrade-preview');if(box)box.innerHTML='<p>'+esc(result.message)+'</p>';
32
+ if(result.ok&&typeof renderAccountingFoundation==='function')renderAccountingFoundation();
33
+}
34
function afParents(){const l=document.getElementById('af-account-level')?.value,p=document.getElementById('af-account-parent');if(!p)return;const n=l==='subsidiary'?'gl':l==='detail'?'subsidiary':'';p.disabled=!n;p.innerHTML='<option value="">— بدون والد —</option>'+getMyAccounts().filter(x=>x.level===n).map(x=>'<option value="'+x.id+'">'+esc(x.code)+' — '+esc(x.title)+'</option>').join('')}
35
document.addEventListener('DOMContentLoaded',ensureAccountingFoundationView);
js/accounting-foundation.js
+47
-2
@@ -26,6 +26,51 @@ const AF_SPECIAL_ACCOUNTS={
26
service:[['4106','درآمد خدمات','detail','credit','41'],['6108','هزینه ارائه خدمات','detail','debit','61']],
27
trading:[['4107','فروش کالا','detail','credit','41'],['5102','خرید و بهای کالای فروشرفته','detail','debit','51']]
28
};
29
+// Finora chart v4: additive operational coverage; numbers are local conventions, not statutory codes.
30
+// Contra accounts retain the underlying account type, independently of their normal balance.
31
+const AF_CHART_ADDITIONS=[
32
+ ['12','داراییهای غیرجاری','subsidiary','debit','1'],
33
+ ['1201','زمین','detail','debit','12'],['1202','ساختمان','detail','debit','12'],['1203','ماشینآلات و تجهیزات','detail','debit','12'],['1204','وسائط نقلیه','detail','debit','12'],['1205','اثاثه و منصوبات','detail','debit','12'],['1206','داراییهای در جریان تکمیل','detail','debit','12'],['1207','داراییهای نامشهود','detail','debit','12'],['1208','سرمایهگذاریهای بلندمدت','detail','debit','12'],['1209','سپردههای بلندمدت','detail','debit','12'],['1210','دریافتنیهای بلندمدت','detail','debit','12'],['1291','استهلاک انباشته داراییهای مشهود','detail','credit','12'],['1292','استهلاک انباشته داراییهای نامشهود','detail','credit','12'],['1293','کاهش ارزش داراییهای غیرجاری','detail','credit','12'],
34
+ ['1114','اسناد دریافتنی','detail','debit','11'],['1115','اسناد در جریان وصول','detail','debit','11'],['1116','سرمایهگذاریهای کوتاهمدت','detail','debit','11'],['1117','سایر دریافتنیها','detail','debit','11'],['1118','سپردههای کوتاهمدت','detail','debit','11'],['1119','پیشپرداخت مالیات عملکرد','detail','debit','11'],['1120','مساعده و وام کوتاهمدت کارکنان','detail','debit','11'],['1191','ذخیره مطالبات مشکوکالوصول','detail','credit','11'],['1192','کاهش ارزش موجودی مواد و کالا','detail','credit','11'],
35
+ ['2111','اسناد پرداختنی','detail','credit','21'],['2112','تسهیلات مالی کوتاهمدت','detail','credit','21'],['2113','حصه جاری تسهیلات مالی بلندمدت','detail','credit','21'],['2114','مالیات عملکرد پرداختنی','detail','credit','21'],['2115','سود سهام پرداختنی','detail','credit','21'],['2116','هزینههای پرداختنی','detail','credit','21'],['2117','پیشدریافت از مشتریان','detail','credit','21'],['2118','سایر پرداختنیها','detail','credit','21'],['2202','تسهیلات مالی بلندمدت','detail','credit','22'],['2203','اسناد پرداختنی بلندمدت','detail','credit','22'],['2204','سپردههای دریافتی بلندمدت','detail','credit','22'],
36
+ ['3103','اندوخته قانونی','detail','credit','31'],['3104','سایر اندوختهها','detail','credit','31'],['3105','مازاد تجدید ارزیابی','detail','credit','31'],['3106','صرف سهام','detail','credit','31'],
37
+ ['4191','برگشت از فروش و تخفیفات فروش','detail','debit','41'],['4202','درآمد سپرده و سرمایهگذاری','detail','credit','42'],['4203','سود فروش داراییهای غیرجاری','detail','credit','42'],['4204','سود تسعیر ارز','detail','credit','42'],
38
+ ['6113','هزینه استهلاک داراییهای مشهود','detail','debit','61'],['6114','هزینه استهلاک داراییهای نامشهود','detail','debit','61'],['6115','هزینه مطالبات مشکوکالوصول','detail','debit','61'],['6116','تعمیر و نگهداری','detail','debit','61'],['6117','آب، برق و گاز','detail','debit','61'],['6118','ارتباطات و اینترنت','detail','debit','61'],['6119','خدمات حرفهای و مشاوره','detail','debit','61'],['6120','بیمه عمومی','detail','debit','61'],['6121','زیان کاهش ارزش داراییها','detail','debit','61'],['6122','زیان فروش داراییهای غیرجاری','detail','debit','61'],
39
+ ['62','هزینههای فروش و توزیع','subsidiary','debit','6'],['6201','حمل و توزیع فروش','detail','debit','62'],['6202','بازاریابی و تبلیغات','detail','debit','62'],['6203','پورسانت فروش','detail','debit','62'],
40
+ ['63','هزینههای مالی','subsidiary','debit','6'],['6301','سود و کارمزد تسهیلات مالی','detail','debit','63'],['6302','کارمزد خدمات بانکی','detail','debit','63'],['6303','زیان تسعیر ارز','detail','debit','63'],
41
+ ['64','هزینه مالیات بر درآمد','subsidiary','debit','6'],['6401','هزینه مالیات عملکرد','detail','debit','64']
42
+];
43
+function afChartUpgradePlan(companyId=afCompanyId()){
44
+ const fail=message=>({ok:false,message,additions:[]}),owner=currentUser?.id,company=getMyCompanies().find(c=>c.id===companyId),type=company?.accountingTemplate?.type;
45
+ if(!owner||!companyId||companyId!==afCompanyId()||!company||!Object.prototype.hasOwnProperty.call(AF_COMPANY_TYPES,type)||company.accountingTemplate.source==='excel')return fail('تکمیل کدینگ فقط برای شرکت فعال با قالب پیشنهادی فینورا در دسترس است؛ کدینگ اختصاصی باید جداگانه بررسی شود.');
46
+ if((datastore.accounts||[]).some(a=>a.ownerUserId===owner&&!a.companyId))return fail('حساب قدیمی بدون شرکت مشخص وجود دارد؛ ابتدا انتساب شرکت بررسی شود.');
47
+ const rows=(datastore.accounts||[]).filter(a=>a.ownerUserId===owner&&a.companyId===companyId),byCode=new Map(),ids=new Set();
48
+ if(!rows.length)return fail('ابتدا قالب کدینگ شرکت را ایجاد کنید.');
49
+ for(const a of rows){if(byCode.has(a.code)||ids.has(a.id)||!a.id)return fail('کد یا شناسه تکراری در کدینگ شرکت وجود دارد.');byCode.set(a.code,a);ids.add(a.id)}
50
+ const specs=new Map([...AF_BASE_ACCOUNTS,...(AF_SPECIAL_ACCOUNTS[type]||[]),...AF_CHART_ADDITIONS].map(r=>[r[0],r])),newCodes=new Set(AF_CHART_ADDITIONS.map(r=>r[0])),validated=new Set(),visiting=new Set(),additions=[];
51
+ function validate(code){
52
+ if(validated.has(code))return true;if(visiting.has(code))return false;visiting.add(code);
53
+ const spec=specs.get(code);if(!spec)return false;const [,title,level,normalBalance,parentCode]=spec;
54
+ if(parentCode&&!validate(parentCode))return false;
55
+ const a=byCode.get(code);
56
+ if(a){const p=parentCode?byCode.get(parentCode):null;if(a.title!==title||a.level!==level||a.normalBalance!==normalBalance||(a.accountType||afAccountTypeForCode(code))!==afAccountTypeForCode(code)||a.active===false||a.postingAllowed!==(level==='detail')||(a.parentId||'')!==(p?.id||'')||(parentCode&&!p))return false;}
57
+ else if(!newCodes.has(code))return false;
58
+ visiting.delete(code);validated.add(code);return true;
59
+ }
60
+ for(const spec of AF_CHART_ADDITIONS){if(!validate(spec[0]))return fail('تعارض کد یا ساختار حساب '+spec[0]+'؛ ابتدا حساب و والدهای آن بررسی شوند. هیچ حسابی اضافه نشد.');if(!byCode.has(spec[0]))additions.push(spec)}
61
+ return {ok:true,ownerUserId:owner,companyId,type,additions,snapshot:JSON.stringify({rows,template:company.accountingTemplate}),message:additions.length?'حسابهای زیر به کدینگ شرکت افزوده میشوند.':'کدینگ پیشنهادی شرکت کامل است.'};
62
+}
63
+function afApplyChartUpgrade(preview){
64
+ if(!requireWrite())return {ok:false,message:'اجازه تغییر کدینگ وجود ندارد.'};
65
+ const plan=afChartUpgradePlan();
66
+ if(!plan.ok)return plan;
67
+ if(!preview?.ok||preview.ownerUserId!==plan.ownerUserId||preview.companyId!==plan.companyId||preview.snapshot!==plan.snapshot)return {ok:false,message:'شرکت یا کدینگ از زمان پیشنمایش تغییر کرده است؛ دوباره پیشنمایش بگیرید.'};
68
+ if(!plan.additions.length)return {ok:true,added:0,message:'کدینگ پیشنهادی شرکت کامل است.'};
69
+ const byCode=new Map(datastore.accounts.filter(a=>a.ownerUserId===plan.ownerUserId&&a.companyId===plan.companyId).map(a=>[a.code,a])),created=[];
70
+ for(const [code,title,level,normalBalance,parentCode] of plan.additions){const a={id:afId('ACC'),ownerUserId:plan.ownerUserId,companyId:plan.companyId,code,title,level,normalBalance,parentId:byCode.get(parentCode)?.id||'',accountType:afAccountTypeForCode(code),systemRole:'',postingAllowed:level==='detail',active:true,template:plan.type,chartVersion:4};created.push(a);byCode.set(code,a)}
71
+ datastore.accounts.push(...created);const company=getMyCompanies().find(c=>c.id===plan.companyId);company.accountingTemplate={...company.accountingTemplate,chartVersion:4,chartUpgradedAt:new Date().toISOString()};saveDatastore();
72
+ return {ok:true,added:created.length,message:created.length.toLocaleString('fa-IR')+' حساب افزوده شد؛ سوابق قبلی حفظ شدند.'};
73
+}
74
function afCompanyId(){const s=getMySettings(),c=getMyCompanies();return s.default_company_id||c[0]?.id||'';}
75
function afOwned(k){const cid=afCompanyId();return(datastore[k]||[]).filter(x=>x.ownerUserId===currentUser?.id&&(!x.companyId||x.companyId===cid));}
76
function getMyFiscalYears(){return afOwned('fiscalYears')} function getMyAccounts(){return afOwned('accounts')}
@@ -88,7 +133,7 @@ function afApplyTemplate(companyId,type){
133
if((datastore.accounts||[]).some(x=>x.ownerUserId===currentUser.id&&x.companyId===companyId)){alert('برای این شرکت کدینگ وجود دارد؛ قالب روی کدینگ موجود اعمال نشد.');return false}
134
const previous=getMySettings().default_company_id;getMySettings().default_company_id=companyId;
135
try{
91
- const rows=[...AF_BASE_ACCOUNTS,...(AF_SPECIAL_ACCOUNTS[type]||[])],byCode={};
136
+ const rows=[...AF_BASE_ACCOUNTS,...(AF_SPECIAL_ACCOUNTS[type]||[]),...AF_CHART_ADDITIONS],byCode={};
137
rows.forEach(r=>{const [code,title,level,normalBalance,parentCode]=r;const a={id:afId('ACC'),ownerUserId:currentUser.id,companyId,code,title,level,parentId:parentCode?(byCode[parentCode]?.id||''):'',normalBalance,accountType:afAccountTypeForCode(code),systemRole:afDefaultSystemRole(code,type),postingAllowed:level==='detail',active:true,template:type};datastore.accounts.push(a);byCode[code]=a});
138
const branch=afCreateDimension(companyId,'BRANCH','شعبه','branch',1,1);
139
const party=afCreateDimension(companyId,'COUNTERPARTY','طرف حساب','contact',1,2);
@@ -99,7 +144,7 @@ function afApplyTemplate(companyId,type){
144
['1102','2101'].forEach(c=>addRule(c,party,'required'));['1101','4101','5101','6101','6102','6103'].forEach(c=>addRule(c,branch,'optional'));
145
if(type==='contracting'){['4301','5301','5302','1105','1106','1107','2104','2105','6109'].forEach(c=>{addRule(c,project,'required');addRule(c,contract,'required')})}
146
if(['service','manufacturing','contracting','professional'].includes(type)){['6101','6102','6103','5101'].forEach(c=>addRule(c,cost,'optional'))}
102
- company.activityType=type;company.accountingTemplate={type,appliedAt:new Date().toISOString(),version:3,complianceVersion:3,jurisdiction:'IR'};saveDatastore();if(typeof jeEnsureDefaultProfiles==='function')jeEnsureDefaultProfiles();return true;
147
+ company.activityType=type;company.accountingTemplate={type,appliedAt:new Date().toISOString(),version:3,chartVersion:4,complianceVersion:3,jurisdiction:'IR'};saveDatastore();if(typeof jeEnsureDefaultProfiles==='function')jeEnsureDefaultProfiles();return true;
148
}finally{getMySettings().default_company_id=previous;saveDatastore()}
149
}
150
function afImportCell(row,names){for(const n of names){if(Object.prototype.hasOwnProperty.call(row,n)&&String(row[n]??'').trim()!=='')return String(row[n]).trim()}return ''}
js/bootstrap.js
+1
-1
@@ -1,2 +1,2 @@
1
function finoraLoadScript(src){return new Promise((resolve,reject)=>{const s=document.createElement('script');s.src=src;s.onload=resolve;s.onerror=()=>reject(new Error('Failed to load '+src));document.head.appendChild(s)})}
2
-window.addEventListener('DOMContentLoaded',async()=>{try{await finoraLoadScript('js/organization-rbac.js?v=20260930-slice-b-v1');await finoraLoadScript('js/organization-invitations.js?v=20260930-eli3-v1');await finoraLoadScript('js/organization-enterprise-ux.js?v=20260930-eli4-v1');await finoraLoadScript('js/platform-modules.js?v=20261001-platform-c6-v1');await finoraLoadScript('js/office-automation.js?v=20260930-c4-v1');await finoraLoadScript('js/request-workflow-d2.js?v=20261001-d2-v1');await finoraLoadScript('js/request-workflow-d3b.js?v=20261001-d3b-v1');await finoraLoadScript('js/request-workflow-d3c.js?v=20261001-d3c-v1');await finoraLoadScript('js/request-workflow-d4a.js?v=20261002-d4a-v1');await finoraLoadScript('js/office-rbac.js?v=20260930-slice-b-v1');await finoraLoadScript('js/office-mature.js?v=20261001-c7-v2');await finoraLoadScript('js/office-workflow.js?v=20261001-c8-task3-v3');await finoraLoadScript('js/organization-shell.js?v=20260930-eli4-v1');await finoraLoadScript('js/taxpayer-print.js?v=20261001-official-v1')}catch(e){console.error('Finora platform extension load failed',e)}if(!currentUser)initAuthSystem();});
2
+window.addEventListener('DOMContentLoaded',async()=>{try{await finoraLoadScript('js/organization-rbac.js?v=20260930-slice-b-v1');await finoraLoadScript('js/organization-invitations.js?v=20260930-eli3-v1');await finoraLoadScript('js/organization-enterprise-ux.js?v=20260930-eli4-v1');await finoraLoadScript('js/platform-modules.js?v=20261001-platform-c6-v1');await finoraLoadScript('js/office-automation.js?v=20260930-c4-v1');await finoraLoadScript('js/request-workflow-d2.js?v=20261001-d2-v1');await finoraLoadScript('js/request-workflow-d3b.js?v=20261001-d3b-v1');await finoraLoadScript('js/request-workflow-d3c.js?v=20261001-d3c-v1');await finoraLoadScript('js/request-workflow-d4a.js?v=20261002-d4a-v1');await finoraLoadScript('js/office-rbac.js?v=20260930-slice-b-v1');await finoraLoadScript('js/office-mature.js?v=20261001-c7-v2');await finoraLoadScript('js/office-workflow.js?v=20261001-c8-task3-v3');await finoraLoadScript('js/organization-shell.js?v=20260930-eli4-v1');await finoraLoadScript('js/taxpayer-print.js?v=20261003-reference-v2')}catch(e){console.error('Finora platform extension load failed',e)}if(!currentUser)initAuthSystem();});
js/print.js
+6
-1
@@ -46,7 +46,12 @@ function printIsolatedDocument(content,spec){
46
if(window.__FINORA_PRINT_TEST_MODE)return frame;
47
const cleanup=()=>{setTimeout(removeIsolatedPrintFrame,0);};
48
frame.contentWindow.addEventListener('afterprint',cleanup,{once:true});
49
- setTimeout(()=>{try{frame.contentWindow.focus();frame.contentWindow.print();setTimeout(cleanup,3000);}catch(err){cleanup();alert('امکان باز کردن پنجره چاپ وجود ندارد. لطفاً دوباره تلاش کنید.');}},80);
49
+ setTimeout(async()=>{try{
50
+ await Promise.all([...doc.images].map(img=>img.decode()));
51
+ if(doc.fonts)await doc.fonts.ready;
52
+ if(!frame.isConnected)return;
53
+ frame.contentWindow.focus();frame.contentWindow.print();setTimeout(cleanup,3000);
54
+ }catch(err){cleanup();alert('تصویر یا منابع چاپ بارگذاری نشد. لطفاً دوباره تلاش کنید.');}},80);
55
return frame;
56
}
57
function stageInvoicePrint(content,spec){
js/taxpayer-print.js
+61
-15
@@ -1,5 +1,5 @@
1
(function(){
2
- function money(v){return Number(v||0).toLocaleString('fa-IR')}
2
+ function money(v){return Number(v||0).toLocaleString('en-US')}
3
function txt(v,fallback='—'){return esc(v===undefined||v===null||v===''?fallback:v)}
4
function words(v){
5
try{
@@ -9,7 +9,8 @@
9
}catch(_){ }
10
return money(v);
11
}
12
- function taxLogo(){return `<div class="tax-org-mark" aria-label="سازمان امور مالیاتی کشور"><svg viewBox="0 0 92 92" xmlns="http://www.w3.org/2000/svg" role="img"><g fill="none" stroke="#111" stroke-width="3.2"><path d="M8 8h26v10H18v16H8zM84 8H58v10h16v16h10zM8 84h26V74H18V58H8zM84 84H58V74h16V58h10z"/><path d="M26 26h40v40H26zM34 34h24v24H34z"/><path d="M8 42h26M58 42h26M42 8v26M42 58v26M50 8v18M50 66v18M8 50h18M66 50h18"/></g><circle cx="46" cy="46" r="7" fill="none" stroke="#111" stroke-width="3"/></svg><div>سازمان امور مالیاتی کشور</div></div>`}
12
+ const taxLogoUrl=new URL('assets/tax-organization-official.png',document.baseURI).href;
13
+ function taxLogo(){return `<div class="tax-org-mark"><img src="${esc(taxLogoUrl)}" alt="سازمان امور مالیاتی کشور"></div>`}
14
window.buildTaxLogo=taxLogo;
15
window.buildElectronicDocPage=function(inv,edoc,seller,contact){
16
inv=inv||{};edoc=edoc||{};seller=seller||{};contact=contact||{};
@@ -28,14 +29,14 @@
29
const total=taxable+rowVat;
30
const ids=(edoc.items&&edoc.items[idx])||{};
31
return `<tr>
31
- <td class="c rowno">${toPersianDigits(idx+1)}</td>
32
+ <td class="c rowno">${idx+1}</td>
33
<td class="c ids"><div>${txt(ids.internalId,'')}</div><div class="id-sep">${txt(ids.officialId,'')}</div></td>
34
<td class="desc">${txt(it.prodName,'')}</td>
35
<td class="c">${txt(it.unit,'عدد')}</td>
35
- <td class="c">${toPersianDigits(it.qty||0)}</td>
36
- <td class="num"><div>${money(it.price)}</div><small>ریال</small></td>
36
+ <td class="c">${Number(it.qty||0).toLocaleString('en-US',{minimumFractionDigits:2,maximumFractionDigits:8})}</td>
37
+ <td class="num unit-price"><div>${money(it.price)}</div><small>ریال</small></td>
38
<td class="num">${money(rowDiscount)}</td>
38
- <td class="c">${toPersianDigits(vatRate)}</td>
39
+ <td class="c">${vatRate}</td>
40
<td class="num">${money(rowVat)}</td>
41
<td class="num strong">${money(total)}</td>
42
</tr>`;
@@ -48,12 +49,50 @@
49
const pattern=edoc.pattern||'فروش کالا / خدمات';
50
return `<div class="invoice-a4-page taxpayer-official-sheet" dir="rtl">
51
<style>
51
- .taxpayer-official-sheet{background:#fff!important;color:#111!important;padding:4mm 5mm!important;font-family:Tahoma,'Vazirmatn FD',Arial,sans-serif!important;font-size:9px;line-height:1.45;position:relative;direction:rtl}
52
- .taxpayer-official-sheet *{box-sizing:border-box}.taxpayer-official-sheet .tax-title{text-align:center;font-size:15px;font-weight:800;margin:0 0 4mm}
53
- .taxpayer-official-sheet .meta{display:grid;grid-template-columns:1fr 1.25fr 1fr;gap:7mm;border-bottom:1px dotted #555;padding-bottom:2mm;margin-bottom:1.5mm;direction:ltr}
54
- .taxpayer-official-sheet .meta-col{direction:rtl}.taxpayer-official-sheet .kv{display:grid;grid-template-columns:1.35fr 1fr;gap:3mm;min-height:7mm;align-items:center}.taxpayer-official-sheet .kv b{font-weight:700}.taxpayer-official-sheet .ltr{direction:ltr;text-align:left;font-family:Tahoma,Arial,sans-serif}
55
- .taxpayer-official-sheet .party-title{font-weight:800;border-bottom:1px dotted #555;padding:1mm 0;text-align:right}.taxpayer-official-sheet .party{display:grid;grid-template-columns:1.1fr 1fr 1fr 1.2fr;gap:2mm 6mm;padding:1.5mm 0 2mm;border-bottom:1px dotted #555}.taxpayer-official-sheet .party span{white-space:nowrap}.taxpayer-official-sheet .party .wide{grid-column:span 2}
56
- .taxpayer-official-sheet .section-label{text-align:right;font-weight:800;padding:1.5mm 0 .8mm}.taxpayer-official-sheet table{width:100%;border-collapse:collapse;table-layout:fixed;direction:rtl;font-size:8.2px}.taxpayer-official-sheet th,.taxpayer-official-sheet td{border:1px solid #333;padding:1.2mm .9mm;vertical-align:middle}.taxpayer-official-sheet th{text-align:center;background:#fff;font-weight:800}.taxpayer-official-sheet .c{text-align:center}.taxpayer-official-sheet .num{text-align:center;direction:ltr}.taxpayer-official-sheet .desc{text-align:right}.taxpayer-official-sheet .strong{font-weight:800}.taxpayer-official-sheet .rowno{width:3.5%}.taxpayer-official-sheet .ids{width:14%}.taxpayer-official-sheet .id-sep{border-top:1px solid #777;margin:1mm -.9mm -1.2mm;padding:1mm .9mm}.taxpayer-official-sheet small{display:block;font-size:7px}.taxpayer-official-sheet .totals td{font-weight:700}.taxpayer-official-sheet .final-grid{display:grid;grid-template-columns:16% 38% 46%;border:1px solid #333;border-top:0;min-height:15mm}.taxpayer-official-sheet .final-grid>div{border-left:1px solid #333;padding:1.4mm}.taxpayer-official-sheet .final-grid>div:last-child{border-left:0}.taxpayer-official-sheet .final-amount{display:grid;grid-template-columns:28% 72%;align-items:center;font-size:9px}.taxpayer-official-sheet .final-amount b{font-size:11px}.taxpayer-official-sheet .settle{width:100%;border-collapse:collapse;font-size:8px}.taxpayer-official-sheet .settle td,.taxpayer-official-sheet .settle th{padding:1mm}.taxpayer-official-sheet .contract-note{padding:2mm 1mm;font-size:9px}.taxpayer-official-sheet .tax-org-mark{width:25mm;text-align:center;font-size:6.5px;line-height:1.2}.taxpayer-official-sheet .tax-org-mark svg{width:22mm;height:22mm;display:block;margin:auto}.taxpayer-official-sheet .bottom{display:flex;align-items:flex-start;justify-content:space-between;margin-top:1mm;direction:ltr}.taxpayer-official-sheet .bottom>*{direction:rtl}.taxpayer-official-sheet .tax-logo-slot{width:30mm;padding-top:1mm}.taxpayer-official-sheet .contract-slot{flex:1;padding:2mm 5mm 0;text-align:center}
52
+ .taxpayer-official-sheet{background:#fff!important;color:#111!important;padding:7mm 5mm!important;font-family:Tahoma,Arial,sans-serif!important;font-size:10px;line-height:1.5;position:relative;direction:rtl}
53
+ .taxpayer-official-sheet *{box-sizing:border-box}
54
+ .taxpayer-official-sheet .tax-title{text-align:center;font-size:15px;font-weight:800;margin:0 0 2mm}
55
+ .taxpayer-official-sheet .meta{display:grid;grid-template-columns:33% 36% 31%;direction:ltr}
56
+ .taxpayer-official-sheet .meta-col{direction:rtl;min-width:0}
57
+ .taxpayer-official-sheet .kv{display:flex;align-items:center;gap:1.5mm;min-height:7.5mm}
58
+ .taxpayer-official-sheet .kv b{font-weight:700}
59
+ .taxpayer-official-sheet .meta-col:first-child .kv{justify-content:space-between;padding-right:5mm}
60
+ .taxpayer-official-sheet .meta-col:not(:first-child) .kv{justify-content:flex-start}
61
+ .taxpayer-official-sheet .ltr{direction:ltr;unicode-bidi:isolate;font-family:Arial,sans-serif;overflow-wrap:anywhere}
62
+ .taxpayer-official-sheet .party-title{display:flex;align-items:center;font-weight:800;padding:1mm 0;text-align:right}
63
+ .taxpayer-official-sheet .party-title:after{content:"";flex:1;border-top:1px dotted #555;margin-right:1mm}
64
+ .taxpayer-official-sheet .party{display:grid;grid-template-columns:25% 29% 22% 24%;gap:1mm 0;padding:0 0 2mm;border-bottom:1px dotted #555}
65
+ .taxpayer-official-sheet .party span{min-width:0}
66
+ .taxpayer-official-sheet .party .wide{grid-column:span 2}
67
+ .taxpayer-official-sheet .seller-contract{grid-column:1/-1;padding-top:2mm}
68
+ .taxpayer-official-sheet .section-label{text-align:right;font-weight:800;padding:2mm 0 .8mm}
69
+ .taxpayer-official-sheet table{width:100%;border-collapse:collapse;table-layout:fixed;direction:rtl;font-size:9px}
70
+ .taxpayer-official-sheet th,.taxpayer-official-sheet td{border:1px solid #333;padding:1mm .6mm;vertical-align:middle;overflow-wrap:anywhere}
71
+ .taxpayer-official-sheet th{text-align:center;background:#eee;font-weight:400}
72
+ .taxpayer-official-sheet .c{text-align:center}
73
+ .taxpayer-official-sheet .num{text-align:center;direction:ltr}
74
+ .taxpayer-official-sheet .desc{text-align:right}
75
+ .taxpayer-official-sheet .id-sep{border-top:1px solid #333;margin:.5mm -.6mm -1mm;padding:.5mm .6mm}
76
+ .taxpayer-official-sheet .unit-price small{border-top:1px solid #333;margin:.5mm -.6mm -1mm;padding:.5mm .6mm}
77
+ .taxpayer-official-sheet small{display:block;font-size:8px}
78
+ .taxpayer-official-sheet .totals td{background:#f3f3f3}
79
+ .taxpayer-official-sheet .after-table{position:relative;min-height:28mm;padding-top:2mm}
80
+ .taxpayer-official-sheet .final-grid{display:flex;gap:1mm;width:79%;margin-right:0;margin-left:auto}
81
+ .taxpayer-official-sheet .final-amount{display:grid;grid-template-columns:16% 23% 61%;width:73%;border:1px solid #333;min-height:9mm}
82
+ .taxpayer-official-sheet .final-amount>*{padding:1mm .6mm;display:flex;align-items:center;justify-content:center;font-weight:400}
83
+ .taxpayer-official-sheet .final-amount>*+*{border-right:1px solid #333}
84
+ .taxpayer-official-sheet .amount-words{font-size:8px;text-align:center}
85
+ .taxpayer-official-sheet .article17{display:grid;grid-template-columns:48% 52%;width:27%;border:1px solid #333;text-align:center;align-items:stretch}
86
+ .taxpayer-official-sheet .article17>*{padding:1mm;display:flex;align-items:center;justify-content:center}
87
+ .taxpayer-official-sheet .article17>*+*{border-right:1px solid #333}
88
+ .taxpayer-official-sheet .tax-logo-slot{position:absolute;left:0;top:2mm;width:24mm}
89
+ .taxpayer-official-sheet .tax-org-mark img{display:block;width:24mm;height:auto;filter:grayscale(1)}
90
+ .taxpayer-official-sheet .bottom{display:flex;direction:rtl;gap:2mm;align-items:flex-start;margin-top:4mm;margin-left:25mm}
91
+ .taxpayer-official-sheet .settlement-slot{width:35%;flex-shrink:0}
92
+ .taxpayer-official-sheet .settle{font-size:8px}
93
+ .taxpayer-official-sheet .settle td,.taxpayer-official-sheet .settle th{padding:.6mm}
94
+ .taxpayer-official-sheet .contract-slot{flex:1;padding-top:1mm;text-align:right}
95
+ .taxpayer-official-sheet .contract-note{font-size:9px}
96
</style>
97
<div class="tax-title">صورتحساب الکترونیکی فروش کالا/خدمات</div>
98
<div class="meta">
@@ -77,6 +116,7 @@
116
<div class="party">
117
<span><b>شماره اقتصادی:</b> ${txt(seller.economic_code||seller.economicCode,'')}</span><span><b>شماره/شناسه ملی:</b> ${txt(seller.national_id||seller.nationalId,'')}</span><span><b>کد شعبه:</b> ${txt(seller.branch_code||seller.branchCode,'0000')}</span><span><b>کد پستی:</b> ${txt(seller.postal_code||seller.postalCode,'')}</span>
118
<span class="wide"><b>نام شخص حقیقی/حقوقی:</b> ${txt(seller.name,'')}</span><span class="wide"><b>نام بنگاه اقتصادی:</b> ${txt(seller.trade_name||seller.business_name||seller.name,'')}</span>
119
+ ${edoc.contractId?`<span class="seller-contract"><b>شناسه یکتای ثبت قرارداد:</b> ${txt(edoc.contractId)}</span>`:''}
120
</div>
121
<div class="party-title">مشخصات خریدار</div>
122
<div class="party">
@@ -84,10 +124,16 @@
124
<span class="wide"><b>نام شخص حقیقی/حقوقی:</b> ${txt(contact.name||inv.contactName,'')}</span><span class="wide"><b>نام بنگاه اقتصادی:</b> ${txt(contact.trade_name||contact.business_name||contact.name||inv.contactName,'')}</span>
125
</div>
126
<div class="section-label">مشخصات کالا / خدمت مورد معامله</div>
87
- <table class="items-table"><thead><tr><th rowspan="2" style="width:3.5%">ردیف</th><th style="width:14%">شناسه کالا/خدمت داخلی</th><th rowspan="2" style="width:23%">شرح کالا/خدمت</th><th rowspan="2" style="width:7%">واحد اندازهگیری</th><th rowspan="2" style="width:6%">تعداد/مقدار</th><th style="width:11%">مبلغ واحد (ریال)</th><th rowspan="2" style="width:9%">مبلغ تخفیف</th><th rowspan="2" style="width:6%">نرخ مالیات بر ارزش افزوده</th><th rowspan="2" style="width:10%">مبلغ مالیات بر ارزش افزوده</th><th rowspan="2" style="width:11%">مبلغ کل کالا/خدمت</th></tr><tr><th>شناسه کالا/خدمت</th><th>نوع ارز</th></tr></thead><tbody>${itemRows||'<tr><td colspan="10" class="c">—</td></tr>'}</tbody>
127
+ <table class="items-table"><thead><tr><th rowspan="2" style="width:1.6%">ردیف</th><th style="width:10.6%">شناسه کالا/خدمت داخلی</th><th rowspan="2" style="width:24.4%">شرح کالا/خدمت</th><th rowspan="2" style="width:5.3%">واحد اندازهگیری</th><th rowspan="2" style="width:8.8%">تعداد/مقدار</th><th style="width:14.2%">مبلغ واحد (ریال)</th><th rowspan="2" style="width:8.8%">مبلغ تخفیف</th><th rowspan="2" style="width:5.3%">نرخ مالیات بر ارزش افزوده</th><th rowspan="2" style="width:9.7%">مبلغ مالیات بر ارزش افزوده</th><th rowspan="2" style="width:11.3%">مبلغ کل کالا/خدمت</th></tr><tr><th>شناسه کالا/خدمت</th><th>نوع ارز</th></tr></thead><tbody>${itemRows||'<tr><td colspan="10" class="c">—</td></tr>'}</tbody>
128
<tfoot class="totals"><tr><td colspan="6" class="desc">جمع کل</td><td class="num">${money(discountTotal)}</td><td></td><td class="num">${money(vatTotal)}</td><td class="num">${money(grandTotal)}</td></tr></tfoot></table>
89
- <div class="final-grid"><div class="tax-logo-slot">${taxLogo()}</div><div><div class="c"><b>مالیات موضوع ماده ۱۷</b></div><div class="c" style="font-size:14px;margin-top:2mm">${money(Number(edoc.article17Tax||0))}</div></div><div><div class="final-amount"><b>مبلغ نهایی</b><b class="num">${money(grandTotal)}</b></div><div style="border-top:1px solid #333;margin-top:1.5mm;padding-top:1.5mm;text-align:center">${txt(words(grandTotal),'')} ریال</div></div></div>
90
- <div class="bottom"><div class="tax-logo-slot"></div><div class="contract-slot">${contract}</div><div style="width:46%"><table class="settle"><tr><th>روش تسویه</th><th>مبلغ پرداختی نقدی بدون احتساب ارزش افزوده</th><th>مبلغ نسیه بدون احتساب ارزش افزوده</th></tr><tr><td class="c">${paymentLabel}</td><td class="num">${money(cashAmount)}</td><td class="num">${money(inv.paymentMethod==='credit'?baseTotal:0)}</td></tr></table></div></div>
129
+ <div class="after-table">
130
+ <div class="tax-logo-slot">${taxLogo()}</div>
131
+ <div class="final-grid">
132
+ <div class="final-amount"><span>مبلغ نهایی</span><span class="num">${money(grandTotal)}</span><span class="amount-words">${txt(words(grandTotal).replace(/(?:\s*ریال)+$/,'').trim())} ریال</span></div>
133
+ <div class="article17"><span>مالیات موضوع ماده 17</span><span class="num">${money(Number(edoc.article17Tax||0))}</span></div>
134
+ </div>
135
+ <div class="bottom"><div class="settlement-slot"><table class="settle"><tr><th>روش تسویه</th><th>مبلغ پرداختی نقدی بدون احتساب ارزش افزوده</th><th>مبلغ نسیه بدون احتساب ارزش افزوده</th></tr><tr><td class="c">${paymentLabel}</td><td class="num">${money(cashAmount)}</td><td class="num">${money(inv.paymentMethod==='credit'?baseTotal:0)}</td></tr></table></div><div class="contract-slot">${contract}</div></div>
136
+ </div>
137
</div>`;
138
};
139
})();
scripts/chart-completeness-check.mjs
new
+54
@@ -0,0 +1,54 @@
1
+import assert from 'node:assert/strict';
2
+import fs from 'node:fs';
3
+import vm from 'node:vm';
4
+const source=fs.readFileSync('js/accounting-foundation.js','utf8');
5
+function fixture(type='trading'){
6
+ const ctx={console,window:{},currentUser:{id:'owner'},settings:{default_company_id:'C1'},companies:[{id:'C1',ownerUserId:'owner'}],datastore:{accounts:[],dimensionTypes:[],accountDimensionRules:[],journalEntries:[{id:'J1',status:'posted',debit:100,credit:100}]},requireWrite:()=>true,alert:()=>{},saveDatastore:()=>{},getMySettings(){return this.settings},getMyCompanies(){return this.companies}};
7
+ vm.createContext(ctx);vm.runInContext(source,ctx);vm.runInContext('getMySettings=()=>settings;getMyCompanies=()=>companies;',ctx);
8
+ assert.equal(vm.runInContext(`afApplyTemplate('C1','${type}')`,ctx),true);return ctx;
9
+}
10
+// Missing noncurrent assets would force fixed assets into the current bucket.
11
+for(const type of ['trading','service','manufacturing','contracting','retail','distribution','nonprofit','professional']){
12
+ const c=fixture(type),rows=c.datastore.accounts,byCode=new Map(rows.map(x=>[x.code,x]));
13
+ assert.ok(byCode.has('12'),`${type}: noncurrent asset branch missing`);
14
+ assert.equal(byCode.get('12').parentId,byCode.get('1').id);
15
+ for(const code of ['1201','1202','1207','1208','1291','1292','1114','2113','2202','3103','4191','6301','6401'])assert.ok(byCode.has(code),`${type}: coverage missing ${code}`);
16
+ assert.equal(byCode.get('1291').accountType,'asset');assert.equal(byCode.get('1291').normalBalance,'credit');
17
+ assert.equal(byCode.get('4191').accountType,'revenue');assert.equal(byCode.get('4191').normalBalance,'debit');
18
+ assert.equal(byCode.size,rows.length,`${type}: duplicate template code`);
19
+ for(const a of rows){assert.equal(a.postingAllowed,a.level==='detail');if(a.parentId){const p=rows.find(x=>x.id===a.parentId);assert.ok(p);assert.equal(p.level,a.level==='detail'?'subsidiary':'gl');}}
20
+ assert.equal(rows.filter(a=>a.systemRole==='cash_default').length,1);
21
+ assert.equal(rows.filter(a=>a.systemRole==='revenue_default').length,1);
22
+ if(type==='contracting')assert.equal(byCode.get('1105').title,'مطالبات حسن انجام کار');
23
+ if(type==='manufacturing')assert.equal(byCode.get('1113').accountType,'asset');
24
+}
25
+function legacy(){const c=fixture();vm.runInContext('datastore.accounts=datastore.accounts.filter(a=>!AF_CHART_ADDITIONS.some(r=>r[0]===a.code));companies[0].accountingTemplate.chartVersion=3;',c);return c;}
26
+function plan(c){return vm.runInContext('afChartUpgradePlan()',c)}
27
+function apply(c,p){c.preview=p;return vm.runInContext('afApplyChartUpgrade(preview)',c)}
28
+const c=legacy();c.datastore.accounts.push({id:'OTHER',ownerUserId:'other',companyId:'C1',code:'1201',title:'Other tenant'});c.datastore.accounts.push({id:'COMPANY2',ownerUserId:'owner',companyId:'C2',code:'12',title:'Other company'});
29
+const old=JSON.stringify(c.datastore),p=plan(c);assert.ok(p.ok);assert.ok(p.additions.length>30);assert.equal(JSON.stringify(c.datastore),old,'preview mutated chart');
30
+const historical=c.datastore.accounts.map(x=>JSON.stringify(x)),entries=JSON.stringify(c.datastore.journalEntries);assert.equal(apply(c,p).ok,true);
31
+assert.deepEqual(c.datastore.accounts.slice(0,historical.length).map(x=>JSON.stringify(x)),historical,'upgrade rewrote historical account');assert.equal(JSON.stringify(c.datastore.journalEntries),entries);
32
+const stable=JSON.stringify(c.datastore);assert.equal(plan(c).additions.length,0);assert.equal(apply(c,plan(c)).ok,true);assert.equal(JSON.stringify(c.datastore),stable,'repeat upgrade mutated rows');
33
+for(const damage of ['conflict','inactive','bad-parent','posting-parent','missing-root','duplicate','unscoped','custom','stale','denied','switch-company']){
34
+ const x=legacy();let preview;
35
+ if(damage==='conflict')x.datastore.accounts.push({id:'COLLISION',ownerUserId:'owner',companyId:'C1',code:'1201',title:'Custom account',level:'detail'});
36
+ if(damage==='inactive')x.datastore.accounts.find(a=>a.code==='1').active=false;
37
+ if(damage==='bad-parent')x.datastore.accounts.find(a=>a.code==='11').parentId='OTHER';
38
+ if(damage==='posting-parent')x.datastore.accounts.find(a=>a.code==='11').postingAllowed=true;
39
+ if(damage==='missing-root')x.datastore.accounts=x.datastore.accounts.filter(a=>a.code!=='1');
40
+ if(damage==='duplicate')x.datastore.accounts.push({...x.datastore.accounts.find(a=>a.code==='1'),id:'DUP'});
41
+ if(damage==='unscoped')x.datastore.accounts.push({id:'LEGACY_UNSCOPED',ownerUserId:'owner',code:'1201'});
42
+ if(damage==='custom')delete x.companies[0].accountingTemplate;
43
+ if(['stale','denied','switch-company'].includes(damage)){preview=plan(x);if(damage==='stale')x.datastore.accounts.find(a=>a.code==='11').title='Changed';if(damage==='denied')x.requireWrite=()=>false;if(damage==='switch-company')x.settings.default_company_id='C2';}
44
+ const before=JSON.stringify(x.datastore);assert.equal(apply(x,preview||plan(x)).ok,false,`${damage}: should reject`);assert.equal(JSON.stringify(x.datastore),before,`${damage}: partial mutation`);
45
+}
46
+const ui=legacy(),previewBox={innerHTML:''};ui.document={addEventListener:()=>{},getElementById:id=>id==='af-chart-upgrade-preview'?previewBox:null};ui.esc=v=>String(v).replaceAll('<','<').replaceAll('>','>');
47
+vm.runInContext(fs.readFileSync('js/accounting-foundation-ui.js','utf8'),ui);
48
+const uiBefore=JSON.stringify(ui.datastore.accounts);vm.runInContext("if(typeof afPreviewChartUpgrade==='function')afPreviewChartUpgrade()",ui);
49
+assert.ok(previewBox.innerHTML.includes('داراییهای غیرجاری'),'upgrade UI must show proposed noncurrent assets before applying');assert.equal(JSON.stringify(ui.datastore.accounts),uiBefore);
50
+vm.runInContext('afApplyChartUpgradeFromUi()',ui);assert.ok(previewBox.innerHTML.includes('سوابق قبلی حفظ شدند'));assert.ok(ui.datastore.accounts.some(a=>a.code==='1201'));
51
+// Real financial reporting must subtract credit-normal assets and debit-normal revenue.
52
+const reporting=fixture(),account=code=>reporting.datastore.accounts.find(a=>a.code===code),voucher={id:'POSTED',date:'1405/01/01',status:'posted'},ledger=[['1202',1000,0],['1291',0,200],['3101',0,800],['1101',500,0],['4107',0,500],['4191',50,0],['1101',0,50]].map(([code,debit,credit],i)=>({id:'L'+i,accountId:account(code).id,account:account(code),debit,credit,voucher}));
53
+reporting.jeLedgerRows=()=>ledger;vm.runInContext(fs.readFileSync('js/phase6-reporting.js','utf8'),reporting);const financial=reporting.window.P6Reports.financials();assert.equal(financial.assets,1250);assert.equal(financial.revenue,450);assert.equal(financial.profit,450);assert.equal(financial.assets,financial.equity+financial.profit);
54
+console.log('Chart completeness: all 8 templates, contra types, safe explicit upgrades, preview UI and rejection boundaries passed.');
scripts/chart-completeness.spec.js
new
+32
@@ -0,0 +1,32 @@
1
+const {test,expect}=require('@playwright/test');
2
+const path=require('node:path');
3
+async function legacyChart(page){
4
+ await page.setContent('<main class="main-surface"></main>');
5
+ await page.addScriptTag({content:`var currentUser={id:'owner'},settings={default_company_id:'C1'},companies=[{id:'C1',name:'نمونه'}],datastore={accounts:[],dimensionTypes:[],accountDimensionRules:[]};function getMySettings(){return settings}function getMyCompanies(){return companies}function requireWrite(){return true}function saveDatastore(){}function esc(v){return String(v).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}`});
6
+ await page.addScriptTag({path:path.resolve('js/accounting-foundation.js')});
7
+ await page.addScriptTag({path:path.resolve('js/accounting-foundation-ui.js')});
8
+ await page.evaluate(()=>{afApplyTemplate('C1','trading');datastore.accounts=datastore.accounts.filter(a=>!AF_CHART_ADDITIONS.some(r=>r[0]===a.code));companies[0].accountingTemplate.chartVersion=3;ensureAccountingFoundationView();window.beforeChart=JSON.stringify(datastore.accounts)});
9
+}
10
+test('chart upgrade previews every addition and changes accounts only on explicit apply',async({page})=>{
11
+ await legacyChart(page);await page.getByRole('button',{name:'پیشنمایش تکمیل کدینگ'}).click();
12
+ await expect(page.locator('#af-chart-upgrade-preview')).toContainText('داراییهای غیرجاری');
13
+ await expect(page.locator('#af-chart-upgrade-preview')).toContainText('استهلاک انباشته');
14
+ expect(await page.evaluate(()=>JSON.stringify(datastore.accounts)===beforeChart)).toBe(true);
15
+ await page.getByRole('button',{name:'افزودن حسابهای پیشنمایش'}).click();
16
+ await expect(page.locator('#af-chart-upgrade-preview')).toContainText('سوابق قبلی حفظ شدند');
17
+ expect(await page.evaluate(()=>datastore.accounts.some(a=>a.code==='1201'))).toBe(true);
18
+ const after=await page.evaluate(()=>JSON.stringify(datastore.accounts));await page.getByRole('button',{name:'پیشنمایش تکمیل کدینگ'}).click();
19
+ await expect(page.locator('#af-chart-upgrade-preview')).toContainText('کامل است');
20
+ expect(await page.evaluate(()=>JSON.stringify(datastore.accounts))).toBe(after);
21
+});
22
+test('conflicting custom account blocks all chart additions and escapes its title',async({page})=>{
23
+ await legacyChart(page);await page.evaluate(()=>{datastore.accounts.push({id:'custom',ownerUserId:'owner',companyId:'C1',code:'1201',title:'<img src=x onerror=alert(1)>',level:'detail'});beforeChart=JSON.stringify(datastore.accounts)});
24
+ await page.getByRole('button',{name:'پیشنمایش تکمیل کدینگ'}).click();await expect(page.locator('#af-chart-upgrade-preview')).toContainText('تعارض');
25
+ await expect(page.getByRole('button',{name:'افزودن حسابهای پیشنمایش'})).toHaveCount(0);
26
+ expect(await page.evaluate(()=>JSON.stringify(datastore.accounts)===beforeChart)).toBe(true);
27
+});
28
+test('switching active company after preview blocks application',async({page})=>{
29
+ await legacyChart(page);await page.getByRole('button',{name:'پیشنمایش تکمیل کدینگ'}).click();
30
+ await page.evaluate(()=>{settings.default_company_id='C2';companies.push({id:'C2'})});await page.getByRole('button',{name:'افزودن حسابهای پیشنمایش'}).click();
31
+ expect(await page.evaluate(()=>JSON.stringify(datastore.accounts)===beforeChart)).toBe(true);await expect(page.getByRole('button',{name:'افزودن حسابهای پیشنمایش'})).toHaveCount(0);
32
+});
scripts/quality-check.mjs
+1
-1
@@ -63,7 +63,7 @@ for(const cssNeedle of ['--shell-rail','--shell-panel','.module-tab.active','.mo
63
if(!index.includes(cssNeedle))throw new Error('Phase 1 responsive shell CSS missing '+cssNeedle);
64
65
for(const coll of ['fiscalYears','accounts','dimensionTypes','dimensionValues','accountDimensionRules','branches','projects','projectLinks'])if(!all['core.js'].includes("'"+coll+"'"))throw new Error('Phase 2 collection missing '+coll);
66
-if(!index.includes('data-module="accounting"')||!index.includes('accounting-foundation.js?v=20260928-phase3-final'))throw new Error('Phase 2 accounting shell integration missing');
66
+if(!index.includes('data-module="accounting"')||!index.includes('accounting-foundation.js?v=20261003-chart-v4'))throw new Error('Phase 2 accounting shell integration missing');
67
68
for(const coll of ['postingProfiles','journalVouchers','journalLines','journalLineDimensions'])if(!all['core.js'].includes("'"+coll+"'")||!all['sync.js'].includes(coll))throw new Error('Phase 3 collection missing '+coll);
69
for(const needle of ['jeValidateLines','jeValidateDimensions','jeCreateDraft','jePost','jeReverse','jeDeleteDraft','jeTrialBalance','sourceVersion'])if(!all['journal-engine.js']?.includes(needle))throw new Error('Phase 3 journal invariant missing '+needle);
scripts/taxpayer-print.spec.js
+39
-1
@@ -15,9 +15,47 @@ test('Taxpayer System print follows the approved official landscape structure',a
15
expect(html).toContain('مشخصات خریدار');
16
expect(html).toContain('شناسه کالا/خدمت داخلی');
17
expect(html).toContain('شناسه کالا/خدمت');
18
- expect(html).toContain('مالیات موضوع ماده ۱۷');
18
+ expect(html).toContain('مالیات موضوع ماده 17');
19
expect(html).toContain('روش تسویه');
20
expect(html).toContain('سازمان امور مالیاتی کشور');
21
expect(html).toContain('205108734859');
22
expect(html).not.toContain('مطابق استاندارد سامانه مودیان');
23
+ await page.setContent(await page.evaluate(html=>buildIsolatedPrintDocument(html,{paper:'A4',orientation:'landscape',widthMm:297,heightMm:210,marginMm:7}),html));
24
+ const logo=page.locator('.tax-logo-slot img');
25
+ await expect(logo).toHaveCount(1);
26
+ await expect(logo).toHaveAttribute('src',/assets\/tax-organization-official.png$/);
27
+ await expect.poll(()=>logo.evaluate(img=>img.complete&&img.naturalWidth>0)).toBe(true);
28
+ const table=await page.locator('.items-table').boundingBox(),mark=await logo.boundingBox(),settle=await page.locator('.settle').boundingBox();
29
+ expect(mark.y).toBeGreaterThanOrEqual(table.y+table.height);
30
+ expect(mark.x+mark.width).toBeLessThan(settle.x);
31
+ expect(await page.locator('.final-grid .tax-logo-slot').count()).toBe(0);
32
+ expect((await page.locator('.final-grid').boundingBox()).height).toBeLessThan(55);
33
+ await expect(page.locator('.items-table tbody tr').first()).toContainText('34,136,903,725');
34
+ await expect(page.locator('.items-table tbody tr').first()).toContainText('1.00');
35
+ await expect(page.locator('.seller-contract')).toContainText('205108734859');
36
+ expect((await page.locator('.amount-words').textContent()).match(/ریال/g)).toHaveLength(1);
37
+ expect(await page.locator('.taxpayer-official-sheet').evaluate(el=>el.scrollWidth<=el.clientWidth)).toBe(true);
38
+ await page.screenshot({path:'test-results/taxpayer-reference.png',fullPage:true});
39
+ const {PDFDocument}=require('pdf-lib');
40
+ const pdf=await PDFDocument.load(await page.pdf({preferCSSPageSize:true}));
41
+ expect(pdf.getPageCount()).toBe(1);
42
+ expect(pdf.getPage(0).getWidth()).toBeGreaterThan(pdf.getPage(0).getHeight());
43
+});
44
+
45
+test('isolated print waits for the supplied image before opening print',async({page})=>{
46
+ await page.goto('http://127.0.0.1:4173/');
47
+ await page.waitForFunction(()=>typeof printIsolatedDocument==='function');
48
+ let release;
49
+ const gate=new Promise(resolve=>release=resolve);
50
+ await page.route('**/assets/tax-organization-official.png?delayed',async route=>{await gate;await route.continue();});
51
+ await page.evaluate(()=>{
52
+ window.printCalls=0;
53
+ const frame=printIsolatedDocument('<img src="http://127.0.0.1:4173/assets/tax-organization-official.png?delayed">',{paper:'A4',orientation:'landscape',widthMm:297,heightMm:210,marginMm:7});
54
+ frame.contentWindow.print=()=>window.printCalls++;
55
+ });
56
+ // Deliberately hold image response beyond the old 80ms print timer.
57
+ await page.waitForTimeout(200);
58
+ expect(await page.evaluate(()=>window.printCalls)).toBe(0);
59
+ release();
60
+ await expect.poll(()=>page.evaluate(()=>window.printCalls)).toBe(1);
61
});