سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 17:00 UTC
fix: preserve opening balances in financial position reports
JVK committed
Nov 29, 2026 at 09:44 UTC
a9a74735f82536690efdd23bcd056b8ac0fd9fef
8 files changed
+233
-8
.github/workflows/quality.yml
+3
-3
@@ -138,12 +138,12 @@ jobs:
138
- name: Real DOM smoke
139
run: |
140
python3 -m http.server 4173 >/tmp/finora-http.log 2>&1 &
141
- npx playwright test scripts/journal-form-pending.spec.js scripts/about-support.spec.js scripts/login-account-errors.spec.js scripts/organization-manager-read-state.spec.js scripts/commerce-route-types.spec.js scripts/workspace-access.spec.js scripts/password-recovery.spec.js scripts/password-admin-ui.spec.js scripts/login-auth-transport.spec.js scripts/login-startup-readiness.spec.js scripts/phase0-startup-performance.spec.js 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/login-connectivity.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/accounting-p0-journal.spec.js scripts/ux-hardening-r2.spec.js scripts/ux-keyboard-f2.spec.js scripts/phase0-dark-theme-contrast.spec.js scripts/phase0-selector-stress.spec.js scripts/phase0-invoice-persistence.spec.js scripts/phase0-modal-dashboard.spec.js scripts/accounting-document-workflow.spec.js scripts/admin-provisioning.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
141
+ npx playwright test scripts/reporting-financial-position.spec.js scripts/journal-form-pending.spec.js scripts/about-support.spec.js scripts/login-account-errors.spec.js scripts/organization-manager-read-state.spec.js scripts/commerce-route-types.spec.js scripts/workspace-access.spec.js scripts/password-recovery.spec.js scripts/password-admin-ui.spec.js scripts/login-auth-transport.spec.js scripts/login-startup-readiness.spec.js scripts/phase0-startup-performance.spec.js 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/login-connectivity.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/accounting-p0-journal.spec.js scripts/ux-hardening-r2.spec.js scripts/ux-keyboard-f2.spec.js scripts/phase0-dark-theme-contrast.spec.js scripts/phase0-selector-stress.spec.js scripts/phase0-invoice-persistence.spec.js scripts/phase0-modal-dashboard.spec.js scripts/accounting-document-workflow.spec.js scripts/admin-provisioning.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
142
143
- - name: About support on generated Pages
143
+ - name: Focused regressions on generated Pages
144
run: |
145
node scripts/build-pages.mjs
146
- FINORA_TEST_BASE_URL=http://127.0.0.1:4173/_site/index.html npx playwright test scripts/journal-form-pending.spec.js scripts/about-support.spec.js --reporter=line --workers=1
146
+ FINORA_TEST_BASE_URL=http://127.0.0.1:4173/_site/index.html npx playwright test scripts/reporting-financial-position.spec.js scripts/journal-form-pending.spec.js scripts/about-support.spec.js --reporter=line --workers=1
147
148
identity-wave5a-database:
149
runs-on: ubuntu-latest
PROJECT_STATE.md
+12
@@ -1,4 +1,5 @@
1
# PROJECT STATE — FINORA 1.0 / FACTOR-EASY (فشردهشده در فاز صفر)
2
+> **Current checkpoint 2026-11-29:** [external-work reconciliation and G01 report repair](docs/audits/FINORA_RECONCILIATION_2026-11-29_FA.md), plus the latest dated entries below. Early phase restrictions and pending checkpoints are historical; newer owner decisions and verified results take precedence. Candidate work is not deployed.
3
> **مرجع اجرایی جاری برای AI و توسعهدهندگان** · مخزن `davoodmehraban89/Factor-easy` · شاخه محافظتشده `main` · تاریخ ۱۴۰۵/۰۷/۲۴.
4
> **تاریخچه کامل بدون حذف یک بایت:** [`docs/archive/PROJECT_STATE_PRE_MASTER_PHASE0_2026-10-16.md`](docs/archive/PROJECT_STATE_PRE_MASTER_PHASE0_2026-10-16.md). Blob SHA پیش/پس از آرشیو: `4e8adb5c82b4c7e5d16f26c94cc904ba5774bca6`، ۲۹۰٬۹۱۳ کاراکتر، ۸۰۹ خط؛ برای جزئیات هر فاز/شناسه PR و تصمیمهای قدیمی به همین سند رجوع شود. آرشیو را بدون درخواست مالک تغییر ندهید.
5
@@ -750,3 +751,14 @@ Next action: run and inspect Quality on the latest PR212 head. If any browser te
751
### 2026-11-25 — FIN-V2 G01-QA checkpoint (#262)
752
- Isolated parent PR261 911e01df2e4d0c29edeb96cee68d91b8053a6263, main dab1a45; all four parent gates PASS. Decision 24abb758ff1cce8a66a9d7e1c230ca93ba2c79d1, test commit 65acbb13118fa7133125cb3d9b22cccb0b7aab24. Only existing Phase6 behavior test and append-only checkpoint files changed. Loads actual journal-engine.js and phase6-reporting.js in VM with synthetic ledger input; asserts draft exclusion, historical reversal and replacement, cutoff, gross debit/credit 490, signed balance and loss 50, and read-only input. Existing scenarios unchanged.
753
- Execution: no local full repo execution; run node scripts/phase6-behavior-check.mjs in existing Quality CI and verify exact final SHA. No claim of PASS until observed. Fixture is a read-model test, not actual posting, real browser/DB or complete report-status UX. Codex-main review; financial #229 remains open and separate. No runtime/SQL/production/merge/release.
754
+
755
+### 2026-11-28 — FIN-G01-R1 — financial position cutoff repair (decision before implementation)
756
+- Owner says continue the comprehensive reconciliation and unfinished work. Root reviewed external recovery PR261 `911e01df2e4d0c29edeb96cee68d91b8053a6263` and report QA PR263 `8d28e56ac8e18ab806e83d8c075376888ab2247b`; selected the latter as the isolated base for `fix/g01-asof-financial-position-20261128`. Main remains `dab1a45fcfc4f12e675cfe055e477138cd3e99fa`. Recovery's exact261 Quality/WP1/WP2/Security passed; exact263 Quality/WP1/Security passed, WP2 not triggered. These candidate results do not close the remaining Issue229 product expected REDs or establish release readiness.
757
+- Source-backed defect: `P6Reports.financials(from,to)` uses period movement for asset/liability/equity balances, dropping opening balances before `from`. Implement a read-only report correction: preserve period trial/revenue/expense/profit; calculate financial position cumulatively through `to`; preserve the API's equity-account balance and separately disclose unclosed income and total equity. Maintain current posted/reversed/company projection, no new ledger or posting path.
758
+- Root owns this bounded report patch and its tests/cache/docs. External C01 financial SQL ownership is unchanged. Acceptance: actual-journal fixture proves opening carry-forward, period/cutoff, reversal, draft/foreign-company exclusion, unclosed versus closed profit and immutable input; real DOM filter interaction on source and generated Pages; relevant existing checks and exact candidate CI. No fiscal-year selector, temporary-document reporting mode, server lifecycle, historical conversion, hosted data, main merge or deployment is included or claimed.
759
+
760
+### 2026-11-29 — FIN-G01-R1 local verification and continuation checkpoint
761
+- Implemented the bounded financial-position cutoff repair in the existing P6 report. Period trial/revenue/expense/profit remain unchanged; asset/liability/equity balances include earlier posted history through the cutoff. Existing `equity` API meaning is preserved; residual unclosed income and total equity are separately returned/displayed. Reversed originals remain in historical reporting; closing transfers do not double-count equity. Source cache tag updated; browser regression runs in both existing source/Pages CI commands.
762
+- Proven RED before implementation: actual-journal Node fixture and real browser filter both returned assets50 instead1150; the old G01 draft-only-date expectation incorrectly erased prior assets120/liabilities170. New expectation preserves zero period movement and the existing balances. GREEN: Phase6/20k rows, chart/Golden and all57 pre-browser/server/safety commands PASS; dedicated source1/1 and generated Pages1/1 PASS; complete canonical Chromium262/262 PASS(7.2m) on Nov29. Three existing Issue229 browser expected-RED sentinels remain product defects. Nov28 interrupted full run is excluded, not a PASS.
763
+- Independent final code review found no blocker; reviewer reran Phase6/chart/Golden and a separate contra-account/liability arithmetic probe. Root inspected the synthetic report screenshot. Runtime blob reviewed: `366fe2586cf8608a025fe0afe4180bcb59e24531`. No SQL, Auth/permissions, journal mutation, historical conversion, main merge or deployment occurred.
764
+- Exact final code/PR SHA and remote CI must be read from the scoped PR ledger; local evidence is not a remote pass. All-seven generated Pages regression PASS(10.4s) before publication. Remaining: draft-first/independent approval #229, identity integration, cheques, draft-inclusive reporting, fiscal-year/legacy-company and pre-closing income-statement semantics, historical conversion and real-account acceptance. Preserve external C01 ownership; continuation prompt and base evidence are in the linked Nov29 report.
docs/EXECUTION_STATUS.md
+8
@@ -1,5 +1,13 @@
1
# وضعیت اجرای فینورا
2
3
+### وضعیت جاری — ۲۰۲۶-۱۱-۲۹
4
+
5
+- **هدف:** ادامهٔ کار روی مبنای آزمودهشده، حفظ اصلاحات محیط بیرونی و تکمیل گزارشهای قابل تطبیق با دفتر؛ مطالب تاریخدار پایین، تاریخچهاند.
6
+- **بررسی انجامشده:** اصلاح بازیابی PR261 (`911e01d`) چهار گیت موفق دارد؛ Quality شامل ۲۶۱ آزمون مرورگر و ۶ Pages است. PR263 (`8d28e56`) آزمون گزارش را افزوده و Quality/WP1/Security موفق دارد؛ WP2 در آن اجرا نشده است. اینها کاندیدای ادغامنشدهاند؛ `main` هنوز `dab1a45` است.
7
+- **اصلاحشده و آزمودهشدهٔ محلی — FIN-G01-R1:** حذف ماندهٔ افتتاحیه از صورت وضعیت مالی هنگام انتخاب «از تاریخ» برطرف شد؛ در نمونهٔ آزمون، دارایی اکنون ۱٬۱۵۰ است و سود دوره ۵۰ میماند. ۵۷ کنترل و اجرای کامل ۲۶۲ آزمون مرورگر موفق؛ تست اختصاصی منبع/Pages و بازبینی مستقل موفق. سه شکست موردانتظار Issue229 همچنان نقص محصول هستند. شاخه `fix/g01-asof-financial-position-20261128` از PR263؛ [گزارش، شواهد و پرامپت ادامه](audits/FINORA_RECONCILIATION_2026-11-29_FA.md). مجموعهٔ کامل Pages نیز ۷/۷ موفق است. مرجع وضعیت CI دقیق، شرح درخواست تغییر است؛ این نتایج محلی به معنی انتشار نیست.
8
+- **باقیمانده:** تصمیم یکپارچهسازی/انتشار با مراجعه به CI درخواست تغییر؛ چرخهٔ سروری ثبت موقت و تأیید مستقل Issue229؛ شمارههای عطف/موقت/قطعی؛ چرخهٔ چک؛ انتخاب اسناد موقت در گزارش؛ دامنهٔ سال مالی و سوابق فاقد شرکت؛ تطبیق و تبدیل تاریخچه؛ آزمون حساب و شبکهٔ واقعی. هیچیک با موفقیت کلی CI تکمیل اعلام نمیشود. مالکیت پیادهسازی C01 در محیط بیرونی محفوظ است.
9
+
10
+
11
### ۲۰۲۶-۱۱-۲۲ — آزمونهای موردانتظار RED برای Issue229
12
- **مبنای محفوظ:** PR228 SHA `ae6a0557d575389853c4545ca99ec57c8015a0e0` چهار گیت موفق (Quality `44986537956`، WP1 `44986538027`، WP2 `44986537948`، Security `44986537938`). مسیرهای آزمودهشده مستقیماً قطعی میکنند و draft-first را اثبات نمیکنند.
13
- **کاندیدای جدید:** افزودن دو تست `test.fail` صریح در اسکریپت Playwright موجود: یک کلیک واقعی خرید که نباید خودش سند قطعی ایجاد کند و باید منبع+سند حسابداری موقت را ذخیره کند؛ و یک کنترل وضعیت سند موقتِ دارای پیوند در فروش و خرید. هدف دریافت **شکست موردانتظار روی assertion مالی** است؛ قبولی کلی CI بهمعنی رفع نقص نیست. اگر خطای setup رخ دهد، باید fixture اصلاح شود و آن را RED مالی ننامیم.
docs/audits/FINORA_RECONCILIATION_2026-11-29_FA.md
new
+41
@@ -0,0 +1,41 @@
1
+# بازبینی ادامهٔ پروژه و اصلاح گزارش مالی — ۲۰۲۶-۱۱-۲۹
2
+
3
+## نتیجهٔ مدیریتی
4
+
5
+کار محیط بیرونی در بازیابی خطا، حفظ ویرایشها و افزودن آزمون گزارش مفید بوده است؛ حفظ میشود. موفقیت این آزمونها بهتنهایی به معنی تکمیل چرخهٔ مالی یا آمادگی انتشار نیست. مبنای این نوبت PR263، با SHA `8d28e56ac8e18ab806e83d8c075376888ab2247b` است؛ `main` پس از بررسی دوباره در ۲۹ نوامبر همچنان `dab1a45fcfc4f12e675cfe055e477138cd3e99fa` است. هیچ تغییر عملیاتی یا انتشار انجام نشده است.
6
+
7
+| بخش | نتیجهٔ بررسی | شاهد ثابت |
8
+|---|---|---|
9
+| بازیابی خطا و جلوگیری از ذخیرهٔ ناخواسته هنگام بازخوانی | اصلاح محدود PR261 حفظ شد؛ بازبینی مستقل در محدودهٔ Diff مانع تازهای پیدا نکرد | SHA `911e01d`؛ [Quality](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45405580355)، [WP1](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45405580359)، [WP2](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45405580328)، [Security](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45405580622) موفق |
10
+| تطبیق گزارش با دفتر | PR263 آزمون مفید افزوده؛ خود محاسبات گزارش را اصلاح نکرده است | SHA `8d28e56`؛ [Quality](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45537093463)، [WP1](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45537093416)، [Security](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45537093414) موفق؛ WP2 روی این SHA اجرا نشده |
11
+| ماتریس نیازمندیها | PR259 سند ردیابی است؛ جایگزین مبنای کد یا اثبات تکمیل نیازها نیست | [نسخهٔ ثابت ماتریس](https://github.com/davoodmehraban89/Factor-easy/blob/088df6f/docs/agent-workflow/FIN_V2_REQUIREMENT_COVERAGE_2026-11-24.md) |
12
+| ثبت موقت و تأیید مستقل | Issue229 باز است؛ سه قرارداد مرورگر و دو شاهد JWT هنوز نقص شناختهشده را ثبت میکنند | سبز بودن workflow نباید به رفع این نقص تعبیر شود |
13
+
14
+## اصلاح واقعی این نوبت — FIN-G01-R1
15
+
16
+صورت وضعیت مالی از گردش بازهٔ انتخابی استفاده میکرد؛ بنابراین ماندهٔ افتتاحیه و گردش قبل از «از تاریخ» حذف میشد. در نمونهٔ مستقل، سرمایهٔ اولیه ۱٬۰۰۰، فروش قبل از دوره ۱۰۰، فروش دوره ۲۰۰، هزینهٔ دوره ۵۰ و برگشت فروش قبلی ۱۰۰ است. سود دوره ۵۰ است، اما دارایی پایان دوره باید **۱٬۱۵۰** باشد؛ نسخهٔ مبنا **۵۰** نمایش میداد.
17
+
18
+اصلاح در همان `P6Reports.financials` انجام شد: سود و زیان و تراز گردش همچنان بازهای هستند؛ دارایی، بدهی و حقوق مالکانه تا تاریخ پایان محاسبه میشوند. ماندهٔ حسابهای حقوق مالکانه در API قبلی حفظ شده و سود/زیان حسابهای بستهنشده و جمع حقوق مالکانه جدا نمایش داده میشوند. بستن حسابهای درآمد/هزینه نباید سود را دوباره بشمارد. در صورت خالی بودن تاریخ پایان، رفتار بدون محدودیت تاریخ حفظ میشود و در عنوان گزارش مشخص است.
19
+
20
+تغییر شامل `phase6-reporting.js`، نسخهٔ فایل در HTML، آزمون محاسبات، آزمون مرورگر و اتصال همان آزمون به CI منبع و Pages است. مسیر ثبت سند، SQL، مجوزها و سوابق مالی تغییر نکردهاند.
21
+
22
+## شواهد و حدود پذیرش
23
+
24
+- شکست پیش از اصلاح در آزمون Node و کلیک واقعی مرورگر مشاهده شد؛ انتظار مالی تغییر نکرد تا آزمون سبز شود.
25
+- آزمون محاسبات با موتور واقعی خواندن دفتر: ماندهٔ افتتاحیه، سود دوره، تاریخ شروع/پایان، برگشت، حذف اسناد موقت و شرکت/مالک دیگر، دورهٔ بدون گردش، بستن حسابها و تغییرنکردن ورودی موفق است. آزمون قبلیِ روز دارای فقط سند موقت تصحیح شد: گردش روز صفر میماند، اما ماندهٔ دارایی/بدهی قبلی نباید صفر شود.
26
+- آزمون ۲۰هزار سطر، Golden Accounting و کدینگ موفق؛ ۵۷ فرمان موجود کنترل ایستا/رفتاری/سرور/ایمنی موفق است.
27
+- آزمون اختصاصی مرورگر منبع ۱/۱ و Pages با CSP سختگیرانه ۱/۱ موفق؛ کلیک منوی گزارش و اعمال سه بازه، مبلغ نمایشی، عدم ذخیره و عدم تغییر دفتر کنترل شد. تصویر دادهٔ مصنوعی توسط مدیر پروژه بازبینی شد. مجموعهٔ کامل Pages (گزارش، حفظ فرم و پشتیبانی) نیز ۷/۷ موفق در ۱۰٫۴ ثانیه است.
28
+- بازبین مستقل روی Diff مانع تازهای نیافت؛ آزمون تکمیلی حسابهای کاهنده و بدهی، دارایی ۱٬۳۲۰ = بدهی ۱۰۰ + حقوق مالکانه ۱٬۲۲۰ را با حفظ ورودی تأیید کرد.
29
+- اجرای کامل مرورگر ۲۸ نوامبر با راهاندازی مجدد محیط پس از ۲۱۴/۲۶۲ قطع شد و نتیجهٔ موفق محسوب نمیشود. اجرای کامل تازهٔ ۲۹ نوامبر **۲۶۲/۲۶۲ موفق در ۷٫۲ دقیقه** است؛ سه قرارداد شکستِ موردانتظار Issue229 همچنان نقص باز محصولاند. نتیجهٔ CI دقیق درخواست تغییر جدا ثبت میشود؛ این عدد شاهد محلی است.
30
+- انتخاب سال مالی، سوابق قدیمی فاقد شرکت، انتخاب «موقت/قطعی/هر دو»، حساب واقعی و صحت دفاتر واقعی با این اصلاح پذیرفته نشدهاند. سود انباشته در اینجا ماندهٔ بستهنشدهٔ حسابهای درآمد/هزینهٔ دفتر بارگذاریشده است، نه ادعای سود سال مالی انتخابشده.
31
+- سود و زیان دوره، مانند قبل، گردش حسابهای درآمد/هزینه در بازه را گزارش میکند؛ اسناد بستن حساب داخل همان بازه نیز در آن اثر دارند. تهیهٔ صورت سود و زیان پیش از بستن حساب و تطبیق افتتاحیه/اختتامیهٔ چند سال، پذیرش جداگانه میخواهد؛ آزمون بستن حساب در این اصلاح فقط جلوگیری از دوبارهشماری حقوق مالکانه را اثبات میکند.
32
+
33
+## نقطهٔ ادامه برای محیط بیرونی
34
+
35
+منشور بلندمدت [V2 ثابت](https://github.com/davoodmehraban89/Factor-easy/blob/85438788324ff507eb7305a78dca214fd118b752/docs/agent-workflow/LONG_TERM_EXECUTION_CHARTER_V2_FA.md) برقرار است. به مبنای قدیمی PR234/250 برنگردید و اصلاح بازیابی PR261 یا اصلاح گزارش حاضر را دوباره نسازید. شاخهٔ این اصلاح `fix/g01-asof-financial-position-20261128` بر PR263 است؛ قبل از انتخاب آن، SHA نهایی و نتیجهٔ CI درخواست تغییر را بخوانید.
36
+
37
+مالکیت C01 و پیادهسازی مالی در محیط بیرونی محفوظ است. اقدام بعدیِ آن مسیر، تکمیل قرارداد منبع+سند موقت اتمیک و قطعیسازی با مجوز مستقل است؛ آزمونهای شکست موردانتظار فقط پس از اصلاح واقعی به PASS معمولی تبدیل شوند. شمارهگذاری، چک، دامنهٔ گزارش، تطبیق تاریخچه و پذیرش واقعی همچنان کارهای بعدیاند. نیازی به تکرار درخواست اتصال بکاپِ صرفنظرشده نیست. تغییرات تاریخی/عملیاتی و انتشار از روی صرفاً سبز بودن این شاخه انجام نشود.
38
+
39
+پرامپت ادامهٔ کوتاه، همراه با منشور بلندمدت:
40
+
41
+> منشور V2 در SHA ثابت بالا و این checkpoint را بخوان. ابتدا HEAD زنده، مالکیت کار و CI را تطبیق بده. اصلاحات بازیابی و گزارشِ پذیرفتهشده را حفظ کن و نقصهای تکمیلشده را دوباره نساز. کارِ مجاز C01 را با استفاده از موتور و آزمونهای موجود ادامه بده؛ برای هر تغییر، درخواست، هدف، آزمون شکست/موفقیت، SHA و کار باقیمانده را در PROJECT_STATE و EXECUTION_STATUS ثبت کن. موفقیت تستِ شناسایی نقص را رفع نقص اعلام نکن. کارهای مستقل را ادامه بده؛ فقط اتصال یا تصمیم واقعاً مفقود را از مالک بخواه. نتیجه را به Codex اصلی برای بازبینی یکپارچه تحویل بده.
index.html
+1
-1
@@ -981,7 +981,7 @@ body{background:#f6f9fc}
981
<script src="js/phase4-contracting.js?v=20260929-phase4-v1"></script>
982
<script src="js/phase5-domain.js?v=20260929-phase5-v1"></script>
983
<script src="js/phase5-enterprise.js?v=20261124-readonly-recovery-v1"></script>
984
-<script src="js/phase6-reporting.js?v=20260929-phase6-v1"></script>
984
+<script src="js/phase6-reporting.js?v=20261128-asof-position-v2"></script>
985
<script src="js/enterprise-iran.js?v=20260930-iran-erp-v1"></script>
986
<script src="js/enterprise-iran-v2.js?v=20260930-iran-erp-v2"></script>
987
<script src="js/selfcheck.js?v=20260928-release-1-0"></script>
js/phase6-reporting.js
+17
-3
@@ -9,7 +9,21 @@
9
}
10
function rollup(from,to){const m=new Map();scoped(from,to).forEach(r=>{const a=r.account||amap().get(r.accountId)||{},x=m.get(r.accountId)||{accountId:r.accountId,code:a.code||'',title:a.title||'',level:a.level||'',accountType:a.accountType||'',systemRole:a.systemRole||'',debit:0,credit:0};x.debit+=n(r.debit);x.credit+=n(r.credit);m.set(r.accountId,x)});return[...m.values()].map(x=>({...x,balance:x.debit-x.credit})).sort((a,b)=>String(a.code).localeCompare(String(b.code),undefined,{numeric:true}))}
11
function classify(a){const explicit=String(a.accountType||'').toLowerCase();if(['revenue','expense','asset','liability','equity'].includes(explicit))return explicit;const s=((a.code||'')+' '+(a.title||'')).toLowerCase();if(/فروش|درآمد/.test(s))return'revenue';if(/هزینه|بهای تمام|خرید/.test(s))return'expense';if(/دریافتنی|دارایی|موجودی|بانک|صندوق/.test(s))return'asset';if(/پرداختنی|بدهی|مالیات پرداختنی/.test(s))return'liability';if(/سرمایه|حقوق صاحبان/.test(s))return'equity';return'other'}
12
- function financials(from,to){const tb=rollup(from,to);let revenue=0,expense=0,assets=0,liabilities=0,equity=0;tb.forEach(x=>{const k=classify(x);if(k==='revenue')revenue+=x.credit-x.debit;else if(k==='expense')expense+=x.debit-x.credit;else if(k==='asset')assets+=x.debit-x.credit;else if(k==='liability')liabilities+=x.credit-x.debit;else if(k==='equity')equity+=x.credit-x.debit});return{trial:tb,revenue,expense,profit:revenue-expense,assets,liabilities,equity}}
12
+ function financials(from,to){
13
+ const tb=rollup(from,to),position=from?rollup('',to):tb;
14
+ let revenue=0,expense=0,assets=0,liabilities=0,equity=0,accumulatedProfit=0;
15
+ // P&L and trial balance are period movements; financial position is as of to.
16
+ tb.forEach(x=>{const k=classify(x);if(k==='revenue')revenue+=x.credit-x.debit;else if(k==='expense')expense+=x.debit-x.credit});
17
+ position.forEach(x=>{
18
+ const k=classify(x);
19
+ if(k==='asset')assets+=x.debit-x.credit;
20
+ else if(k==='liability')liabilities+=x.credit-x.debit;
21
+ else if(k==='equity')equity+=x.credit-x.debit;
22
+ // Residual P&L balances become zero when transferred to equity by closing.
23
+ else if(k==='revenue'||k==='expense')accumulatedProfit+=x.credit-x.debit;
24
+ });
25
+ return{trial:tb,revenue,expense,profit:revenue-expense,assets,liabilities,equity,accumulatedProfit,totalEquity:equity+accumulatedProfit};
26
+ }
27
function aging(asOf){const cutoff=asOf||getJalaliNumeric(),arId=typeof jeReceivableAccount==='function'?jeReceivableAccount()?.id||'':'',apId=typeof jePayableAccount==='function'?jePayableAccount()?.id||'':'',bucket=x=>x<=30?'0-30':x<=60?'31-60':x<=90?'61-90':'90+',out={receivable:{},payable:{}};['receivable','payable'].forEach(k=>['0-30','31-60','61-90','90+'].forEach(b=>out[k][b]=0));const fy=String(cutoff).split('/').map(Number),approx=d=>{const p=String(d||cutoff).split('/').map(Number);return Math.max(0,(fy[0]-p[0])*365+(fy[1]-p[1])*30+(fy[2]-p[2]))};scoped('',cutoff).forEach(r=>{const a=r.account||{},s=(a.code||'')+' '+(a.title||''),b=bucket(approx(dateOf(r)));if((arId&&r.accountId===arId)||(!arId&&/دریافتنی|بدهکاران/.test(s)))out.receivable[b]+=n(r.debit)-n(r.credit);if((apId&&r.accountId===apId)||(!apId&&/پرداختنی|بستانکاران/.test(s)))out.payable[b]+=n(r.credit)-n(r.debit)});return out}
28
function cashFlow(from,to){
29
const cashId=typeof jeCashAccount==='function'?jeCashAccount()?.id||'':'',out={operating:0,investing:0,financing:0,total:0,rows:[]};scoped(from,to).forEach(r=>{const a=r.account||{},s=(a.code||'')+' '+(a.title||'');if((cashId&&r.accountId!==cashId)||(!cashId&&!/بانک|صندوق|نقد/.test(s)))return;const amount=n(r.debit)-n(r.credit),src=String(r.voucher?.sourceType||'');let group=/asset|fixed_asset/.test(src)?'investing':/capital|loan|financ/.test(src)?'financing':'operating';out[group]+=amount;out.total+=amount;out.rows.push({date:dateOf(r),voucher:r.voucher?.number||'',sourceType:src,account:a.title||'',amount,group})});return out
@@ -31,7 +45,7 @@
45
'<div class="grid-kpi" data-finora-task="all trial financials"><div class="kpi-unit"><div><div class="kpi-lbl">جمع بدهکار</div><div class="kpi-val">'+fmt(dr)+'</div></div></div><div class="kpi-unit"><div><div class="kpi-lbl">جمع بستانکار</div><div class="kpi-val">'+fmt(cr)+'</div></div></div><div class="kpi-unit"><div><div class="kpi-lbl">سود/زیان دفتر</div><div class="kpi-val">'+fmt(f.profit)+'</div></div></div><div class="kpi-unit"><div><div class="kpi-lbl">کنترل تراز</div><div class="kpi-val">'+(Math.abs(dr-cr)<.001?'تراز':'نامتوازن')+'</div></div></div></div>'+
46
'<div class="card" data-finora-task="trial"><h3>تراز آزمایشی</h3><div class="table-responsive"><table><thead><tr><th>کد</th><th>حساب</th><th>گردش بدهکار</th><th>گردش بستانکار</th><th>مانده</th></tr></thead><tbody>'+f.trial.map(x=>'<tr><td>'+esc(x.code)+'</td><td>'+esc(x.title)+'</td><td>'+fmt(x.debit)+'</td><td>'+fmt(x.credit)+'</td><td>'+fmt(x.balance)+'</td></tr>').join('')+'</tbody></table></div></div>'+
47
'<div class="card" data-finora-task="ledger"><h3>دفتر کل / معین / تفصیلی و تحلیلی</h3><div class="table-responsive"><table><thead><tr><th>تاریخ</th><th>شماره سند</th><th>حساب</th><th>شرح</th><th>بدهکار</th><th>بستانکار</th></tr></thead><tbody>'+led.map(r=>'<tr><td>'+esc(dateOf(r))+'</td><td><button class="btn btn-secondary btn-inline" onclick="switchView(\'view-journal\')">'+esc(r.voucher?.number||r.voucherId)+'</button></td><td>'+esc((r.account?.code||'')+' — '+(r.account?.title||''))+'</td><td>'+esc(r.description||r.voucher?.description||'')+'</td><td>'+fmt(r.debit)+'</td><td>'+fmt(r.credit)+'</td></tr>').join('')+'</tbody></table></div></div>'+
34
- '<div class="card" data-finora-task="financials"><h3>صورت سود و زیان / وضعیت مالی</h3><div class="table-responsive"><table><tbody><tr><td>درآمد</td><td>'+fmt(f.revenue)+'</td><td>دارایی</td><td>'+fmt(f.assets)+'</td></tr><tr><td>هزینه و بهای تمامشده</td><td>'+fmt(f.expense)+'</td><td>بدهی</td><td>'+fmt(f.liabilities)+'</td></tr><tr><td><strong>سود/زیان</strong></td><td><strong>'+fmt(f.profit)+'</strong></td><td>حقوق مالکانه</td><td>'+fmt(f.equity)+'</td></tr></tbody></table></div></div>'+
48
+ '<div class="card" data-finora-task="financials"><h3>صورت سود و زیان / وضعیت مالی</h3><p>سود و زیان مربوط به بازهٔ انتخابی است؛ وضعیت مالی ماندههای قبل از «از تاریخ» را نیز تا تاریخ پایان در بر میگیرد.</p><div class="table-responsive"><table><thead><tr><th colspan="2">سود و زیان دوره</th><th colspan="2">'+esc(to?'وضعیت مالی تا '+to:'وضعیت مالی (همه تاریخها)')+'</th></tr></thead><tbody><tr><td>درآمد</td><td>'+fmt(f.revenue)+'</td><td>دارایی</td><td>'+fmt(f.assets)+'</td></tr><tr><td>هزینه و بهای تمامشده</td><td>'+fmt(f.expense)+'</td><td>بدهی</td><td>'+fmt(f.liabilities)+'</td></tr><tr><td><strong>سود/زیان</strong></td><td><strong>'+fmt(f.profit)+'</strong></td><td>حقوق مالکانه ثبتشده</td><td>'+fmt(f.equity)+'</td></tr><tr><td colspan="2"></td><td>سود/زیان انباشته حسابهای بستهنشده</td><td>'+fmt(f.accumulatedProfit)+'</td></tr><tr><td colspan="2"></td><td><strong>جمع حقوق مالکانه</strong></td><td><strong>'+fmt(f.totalEquity)+'</strong></td></tr></tbody></table></div></div>'+
49
'<div class="card" data-finora-task="cashflow"><h3>صورت جریان وجوه نقد</h3><div class="table-responsive"><table><tbody><tr><td>عملیاتی</td><td>'+fmt(cf.operating)+'</td></tr><tr><td>سرمایهگذاری</td><td>'+fmt(cf.investing)+'</td></tr><tr><td>تأمین مالی</td><td>'+fmt(cf.financing)+'</td></tr><tr><td><strong>خالص تغییر نقد</strong></td><td><strong>'+fmt(cf.total)+'</strong></td></tr></tbody></table></div></div>'+
50
'<div class="card" data-finora-task="aging"><h3>سن مطالبات / بدهیها</h3><div class="table-responsive"><table><thead><tr><th>نوع</th><th>۰–۳۰</th><th>۳۱–۶۰</th><th>۶۱–۹۰</th><th>۹۰+</th></tr></thead><tbody><tr><td>مطالبات</td><td>'+fmt(a.receivable['0-30'])+'</td><td>'+fmt(a.receivable['31-60'])+'</td><td>'+fmt(a.receivable['61-90'])+'</td><td>'+fmt(a.receivable['90+'])+'</td></tr><tr><td>بدهی</td><td>'+fmt(a.payable['0-30'])+'</td><td>'+fmt(a.payable['31-60'])+'</td><td>'+fmt(a.payable['61-90'])+'</td><td>'+fmt(a.payable['90+'])+'</td></tr></tbody></table></div></div>'+
51
'<div class="card" data-finora-task="projects"><h3>گزارش تجمیعی پروژه و پیمان</h3><div class="table-responsive"><table><thead><tr><th>پروژه</th><th>تعداد پیمان</th><th>ارزش پیمان</th><th>صورتوضعیت قطعی</th><th>سود/زیان پیمان</th></tr></thead><tbody>'+projects.map(x=>'<tr><td>'+esc(x.project.name||x.project.title||x.project.id)+'</td><td>'+x.contracts.toLocaleString('fa-IR')+'</td><td>'+fmt(x.value)+'</td><td>'+fmt(x.statements)+'</td><td>'+fmt(x.profit)+'</td></tr>').join('')+'</tbody></table></div></div>'+
@@ -39,4 +53,4 @@
53
const ae=document.getElementById('p6-account'),de=document.getElementById('p6-dimension');if(ae)ae.value=accountId;if(de)de.value=dimensionValueId;
54
}
55
window.P6Reports={ledger,rollup,financials,aging,cashFlow,projectContractSummary,legacyCutoverPreview,postLegacyInvoice,render};
42
-})();
\ No newline at end of file
56
+})();
scripts/phase6-behavior-check.mjs
+58
-1
@@ -57,7 +57,64 @@ const perfStart=Date.now(),perfRoll=P.rollup('1405/01/01','1405/01/31'),perfFin=
57
check('account balances',reports.rollup().map(x=>[x.accountId,x.balance]),
58
[['AR',120],['AP',-170],['REV',-120],['EXP',170]]);
59
check('draft only date',result('1405/01/04','1405/01/04'),
60
- {revenue:0,expense:0,profit:0,assets:0,liabilities:0,debit:0,credit:0});
60
+ {revenue:0,expense:0,profit:0,assets:120,liabilities:170,debit:0,credit:0});
61
+ check('draft only date has no ledger movement',reports.ledger({from:'1405/01/04',to:'1405/01/04'}).length,0);
62
check('read projection preserves journal input',JSON.stringify(book),before);
63
console.log('G01 actual journal/report reconciliation passed: draft exclusion, reversal, replacement, date range and read-only input.');
64
}
65
+
66
+// Financial position is cumulative at the cutoff; P&L/trial stay period-based.
67
+// This catches loss of opening balances, use of period profit in equity,
68
+// omission of reversed originals, future/draft leakage and double-counted closing.
69
+{
70
+ const ownerUserId='G01_POSITION_OWNER',companyId='G01_POSITION_CO';
71
+ const book={journalVouchers:[],journalLines:[],journalLineDimensions:[]};
72
+ const accounts=[['CASH','asset'],['EQUITY','equity'],['REV','revenue'],['EXP','expense']]
73
+ .map(([id,accountType])=>({id,code:id,title:id,accountType,postingAllowed:true}));
74
+ function add(id,date,status,amount,debitAccount,creditAccount,scope={}){
75
+ const identity={ownerUserId,companyId,...scope};
76
+ book.journalVouchers.push({id,number:id,date,status,...identity,totalDebit:amount,totalCredit:amount});
77
+ book.journalLines.push({id:id+'D',voucherId:id,accountId:debitAccount,debit:amount,credit:0,...identity},
78
+ {id:id+'C',voucherId:id,accountId:creditAccount,debit:0,credit:amount,...identity});
79
+ }
80
+ add('OPEN','1405/01/01','posted',1000,'CASH','EQUITY');
81
+ add('PRIOR','1405/01/15','reversed',100,'CASH','REV');
82
+ add('CURRENT','1405/02/01','posted',200,'CASH','REV');
83
+ add('COST','1405/02/02','posted',50,'EXP','CASH');
84
+ add('REVERSE','1405/02/28','posted',100,'REV','CASH');
85
+ add('FUTURE','1405/03/01','posted',777,'CASH','REV');
86
+ add('DRAFT','1405/02/10','draft',999,'CASH','REV');
87
+ add('OTHER_CO','1405/02/01','posted',5000,'CASH','REV',{companyId:'OTHER_CO'});
88
+ add('OTHER_OWNER','1405/02/01','posted',6000,'CASH','REV',{ownerUserId:'OTHER_OWNER'});
89
+ const actual={window:{},console,datastore:book,currentUser:{id:ownerUserId},afCompanyId:()=>companyId,getMyAccounts:()=>accounts};
90
+ vm.createContext(actual);
91
+ vm.runInContext(fs.readFileSync('js/journal-engine.js','utf8'),actual);
92
+ vm.runInContext(fs.readFileSync('js/phase6-reporting.js','utf8'),actual);
93
+ const reports=actual.window.P6Reports;
94
+ const check=(label,got,want)=>{if(JSON.stringify(got)!==JSON.stringify(want))throw new Error('G01 position '+label+': '+JSON.stringify({got,want}));};
95
+ const result=(from,to)=>{
96
+ const f=reports.financials(from,to);
97
+ return {revenue:f.revenue,expense:f.expense,profit:f.profit,assets:f.assets,liabilities:f.liabilities,
98
+ equity:f.equity,accumulatedProfit:f.accumulatedProfit,totalEquity:f.totalEquity,
99
+ debit:f.trial.reduce((s,x)=>s+x.debit,0),credit:f.trial.reduce((s,x)=>s+x.credit,0)};
100
+ };
101
+ const before=JSON.stringify(book);
102
+ check('opening and prior balances survive period filter',result('1405/02/01','1405/02/28'),
103
+ {revenue:100,expense:50,profit:50,assets:1150,liabilities:0,equity:1000,accumulatedProfit:150,totalEquity:1150,debit:350,credit:350});
104
+ check('inclusive cutoff before reversal',result('1405/02/01','1405/02/01'),
105
+ {revenue:200,expense:0,profit:200,assets:1300,liabilities:0,equity:1000,accumulatedProfit:300,totalEquity:1300,debit:200,credit:200});
106
+ check('empty period retains position',result('1405/02/10','1405/02/10'),
107
+ {revenue:0,expense:0,profit:0,assets:1250,liabilities:0,equity:1000,accumulatedProfit:250,totalEquity:1250,debit:0,credit:0});
108
+ check('period ledger excludes opening future and draft',reports.ledger({from:'1405/02/01',to:'1405/02/28'}).length,6);
109
+ check('unbounded dashboard behavior',result('',''),
110
+ {revenue:977,expense:50,profit:927,assets:1927,liabilities:0,equity:1000,accumulatedProfit:927,totalEquity:1927,debit:2227,credit:2227});
111
+ check('reports are read only',JSON.stringify(book),before);
112
+ // Closing the residual revenue/expense into equity must not count it twice.
113
+ add('CLOSE_REV','1405/02/28','posted',200,'REV','EQUITY');
114
+ add('CLOSE_EXP','1405/02/28','posted',50,'EQUITY','EXP');
115
+ const closedBefore=JSON.stringify(book);
116
+ check('closed earnings counted once',result('1405/02/28','1405/02/28'),
117
+ {revenue:-300,expense:-50,profit:-250,assets:1150,liabilities:0,equity:1150,accumulatedProfit:0,totalEquity:1150,debit:350,credit:350});
118
+ check('closed report remains read only',JSON.stringify(book),closedBefore);
119
+ console.log('G01 financial-position cutoff passed: opening, period profit, reversal, scope, cutoff, closing and unchanged journal input.');
120
+}
scripts/reporting-financial-position.spec.js
new
+93
@@ -0,0 +1,93 @@
1
+const {test,expect}=require('@playwright/test');
2
+const BASE=process.env.FINORA_TEST_BASE_URL||'http://127.0.0.1:4173/index.html';
3
+
4
+// This catches treating a financial-position balance as period movement. All
5
+// journals are synthetic; the actual journal projection, report and UI run.
6
+test('financial report filters retain opening balances and disclose period profit separately',async({page,context})=>{
7
+ const errors=[];
8
+ page.on('pageerror',error=>errors.push(error.message));
9
+ await context.route('**/*',route=>new URL(route.request().url()).origin===new URL(BASE).origin?route.continue():route.abort());
10
+ await page.goto(BASE,{waitUntil:'domcontentloaded'});
11
+ await page.waitForFunction(()=>window.FinoraStartupStatus?.extensionsReady&&window.FinoraStartupStatus?.authChecked);
12
+ await page.evaluate(()=>{
13
+ const ownerUserId='QA_REPORT_OWNER',companyId='QA_REPORT_COMPANY';
14
+ currentUser={id:ownerUserId,role:'admin',organizationId:'QA_REPORT_ORG',isOrganizationOwner:true,organizations:[],modules:['full_suite'],commercialModules:['full_suite'],modulePermissions:[],subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}};
15
+ COLLS.forEach(key=>datastore[key]=[]);
16
+ datastore.companies=[{id:companyId,ownerUserId,name:'شرکت گزارش آزمایشی'}];
17
+ datastore.settings=[{ownerUserId,default_company_id:companyId,currency_mode:'rial',currency_custom:''}];
18
+ datastore.accounts=[
19
+ ['CASH','1101','صندوق','asset','cash_default'],
20
+ ['EQUITY','3101','سرمایه','equity',''],
21
+ ['REV','4101','درآمد','revenue','revenue_default'],
22
+ ['EXP','6101','هزینه','expense','expense_default']
23
+ ].map(([id,code,title,accountType,systemRole])=>({id,code,title,accountType,systemRole,ownerUserId,companyId,active:true,postingAllowed:true}));
24
+ const add=(id,date,status,amount,debitAccount,creditAccount,scope=companyId)=>{
25
+ datastore.journalVouchers.push({id,ownerUserId,companyId:scope,number:id,date,status,totalDebit:amount,totalCredit:amount});
26
+ datastore.journalLines.push(
27
+ {id:id+'D',voucherId:id,ownerUserId,companyId:scope,accountId:debitAccount,debit:amount,credit:0},
28
+ {id:id+'C',voucherId:id,ownerUserId,companyId:scope,accountId:creditAccount,debit:0,credit:amount});
29
+ };
30
+ add('OPENING','1405/01/01','posted',1000,'CASH','EQUITY');
31
+ add('EARLIER_SALE','1405/01/10','reversed',100,'CASH','REV');
32
+ add('CURRENT_SALE','1405/02/01','posted',200,'CASH','REV');
33
+ add('EXPENSE','1405/02/02','posted',50,'EXP','CASH');
34
+ add('REVERSAL','1405/02/03','posted',100,'REV','CASH');
35
+ add('FUTURE','1405/03/01','posted',777,'CASH','REV');
36
+ add('DRAFT','1405/02/10','draft',999,'CASH','REV');
37
+ add('OTHER_COMPANY','1405/02/01','posted',5000,'CASH','REV','QA_OTHER_COMPANY');
38
+ // Intercept the write boundary, not the read/model functions under test.
39
+ window.__reportWrites=0;
40
+ saveDatastore=()=>{window.__reportWrites++};
41
+ sb.rpc=async()=>{window.__reportWrites++;return {data:[],error:null}};
42
+ window.__reportBookBefore=JSON.stringify({vouchers:datastore.journalVouchers,lines:datastore.journalLines,accounts:datastore.accounts});
43
+ document.querySelector('#auth-screen').style.display='none';
44
+ document.body.classList.remove('shell-panel-collapsed');
45
+ applyLicensedModuleUI();
46
+ });
47
+ await page.locator('#module-rail [data-module="reports"]').click();
48
+ await page.locator('#module-panel-links [data-task="financials"]').click();
49
+ const report=page.locator('#p6-reporting-root [data-finora-task="financials"]');
50
+ await expect(report).toBeVisible();
51
+ const valueAfter=label=>report.getByRole('cell',{name:label,exact:true}).locator('xpath=following-sibling::td[1]');
52
+ const filter=async(from,to)=>{
53
+ await page.locator('#p6-from').fill(from);
54
+ await page.locator('#p6-to').fill(to);
55
+ await page.getByRole('button',{name:'اعمال فیلتر',exact:true}).click();
56
+ await expect(page.locator('#p6-from')).toHaveValue(from);
57
+ await expect(page.locator('#p6-to')).toHaveValue(to);
58
+ };
59
+ await filter('1405/02/01','1405/02/28');
60
+ await expect(valueAfter('دارایی')).toHaveText('۱٬۱۵۰');
61
+ await expect(valueAfter('درآمد')).toHaveText('۱۰۰');
62
+ await expect(valueAfter('هزینه و بهای تمامشده')).toHaveText('۵۰');
63
+ await expect(valueAfter('حقوق مالکانه ثبتشده')).toHaveText('۱٬۰۰۰');
64
+ await expect(valueAfter('سود/زیان انباشته حسابهای بستهنشده')).toHaveText('۱۵۰');
65
+ await expect(valueAfter('جمع حقوق مالکانه')).toHaveText('۱٬۱۵۰');
66
+ await expect(report).toContainText('سود و زیان دوره');
67
+ await expect(report).toContainText('وضعیت مالی تا 1405/02/28');
68
+ expect(await page.evaluate(()=>{
69
+ const f=P6Reports.financials('1405/02/01','1405/02/28');
70
+ return {profit:f.profit,equity:f.equity,accumulatedProfit:f.accumulatedProfit,totalEquity:f.totalEquity};
71
+ })).toEqual({profit:50,equity:1000,accumulatedProfit:150,totalEquity:1150});
72
+ // A period with no posted movements still has its brought-forward balance.
73
+ await filter('1405/02/10','1405/02/20');
74
+ await expect(valueAfter('دارایی')).toHaveText('۱٬۱۵۰');
75
+ await expect(valueAfter('درآمد')).toHaveText('۰');
76
+ await expect(valueAfter('هزینه و بهای تمامشده')).toHaveText('۰');
77
+ await expect(valueAfter('سود/زیان انباشته حسابهای بستهنشده')).toHaveText('۱۵۰');
78
+ await expect(valueAfter('جمع حقوق مالکانه')).toHaveText('۱٬۱۵۰');
79
+ // The inclusive cutoff before the reversal retains the earlier sale.
80
+ await filter('1405/02/01','1405/02/02');
81
+ await expect(valueAfter('دارایی')).toHaveText('۱٬۲۵۰');
82
+ await expect(valueAfter('درآمد')).toHaveText('۲۰۰');
83
+ await expect(valueAfter('سود/زیان انباشته حسابهای بستهنشده')).toHaveText('۲۵۰');
84
+ await expect(valueAfter('جمع حقوق مالکانه')).toHaveText('۱٬۲۵۰');
85
+ expect(await page.evaluate(()=>({
86
+ unchanged:window.__reportBookBefore===JSON.stringify({vouchers:datastore.journalVouchers,lines:datastore.journalLines,accounts:datastore.accounts}),
87
+ writes:window.__reportWrites
88
+ }))).toEqual({unchanged:true,writes:0});
89
+ expect(errors).toEqual([]);
90
+ if(new URL(BASE).pathname.includes('/_site/')){
91
+ expect(await page.locator('meta[http-equiv="Content-Security-Policy"]').getAttribute('content')).not.toMatch(/script-src[^;]*'unsafe-inline'/);
92
+ }
93
+});