@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / d12da87
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 22:00 UTC

Fix commerce document types and restore discoverable organization workspaces

JVK committed Oct 31, 2026 at 14:34 UTC d12da878bd19526f428fb80523d8533b218bd8e3
19 files changed +266 -31
.github/workflows/quality.yml
+1 -1
@@ -125,7 +125,7 @@ jobs:
125 - name: Real DOM smoke
126 run: |
127 python3 -m http.server 4173 >/tmp/finora-http.log 2>&1 &
128 - npx playwright test 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
128 + npx playwright test 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
129
130 identity-wave5a-database:
131 runs-on: ubuntu-latest
PROJECT_STATE.md
+15
@@ -210,3 +210,18 @@ Owner requests layer-by-layer click/functional testing of all controls and compa
210 - Audit baseline357cfb2: fresh canonical browser suite203/203 PASS(5.9m), server49/49 andGolden PASS. Static inventory734 template occurrences; runtime651 distinct observed controls;76menu targets reached(50rail DOM paths,26direct module preparation). Button sweep221unique onclick expressions in fresh isolated contexts:128CLICK_EXECUTED/93HIDDEN_OR_DISABLED,0JS errors. Confirmation dismissed, all external requests blocked; these are smoke coverage, not semantic success/all-controls acceptance.
211 - Accepted7 current synthetic screenshots support scoped UX findings; real TinyFish run37baeb67 only visited7/8modules and few submenus, with no usable screenshot files returned. Do not inherit its broad headline or claim full live coverage. Comparative report sourced official QuickBooks/Xero/Zoho/Sage/NetSuite pages; not competitor hands-on testing. Artifacts/reproducible scripts/report in docs/audits/2026-10-31. No app code or production financial data changed. Next work: fixtures for93unreached controls, assertions for128clicked operations, real-role/sandbox acceptance, accessibility measurements.
212 - Follow-up actual local clicks after opening About accordion reproduced two real functional placeholders: update-check always alerts latest-version without checking; bug-report only alerts support-active without report workflow. Recorded as P1, not fixed in this audit-only change. No JS error does not mean business success. Proof JSON and accepted screenshot19 retained.
213 +
214 +### 2026-10-31 — Approved remediation and continuous status tracking
215 +- Owner approves continuing audit remediation and explicitly requires goals, in-progress work and remaining work kept current. Current objective: make every reachable control have a verified outcome; do not substitute click/no-JS-error counts for functional acceptance.
216 +- IN PROGRESS: replace About update/report placeholders with truthful tested behavior; extend synthetic real-click scenarios for previously hidden controls. Update check must compare public build fingerprints, bound network/body reads, distinguish newer/unavailable/offline, never auto-reload unsaved work or claim current without evidence. Bug reporting opens existing support draft only, no automatic external message or private-data collection.
217 +- REMAINING: per-role/data-state fixtures for93 baseline unreached controls, assertions beyond128 smoke clicks, production admin/limited-role acceptance, accessibility measurements, and prioritized UX improvements in audit report. Prior audit evidence remains valid only for baseline357cfb2.
218 +- Live status board: docs/EXECUTION_STATUS.md. Keep canonical history here; board summarizes goal/status/evidence/next action without erasing historical limits.
219 +
220 +### 2026-10-31 — Owner-reported commerce types and missing workspaces
221 +- Owner screenshots show purchase types in the sales route and sales types in purchase. Requested correction: context-specific document options and consistent route/form state, preserving existing documents.
222 +- Owner also reports missing organization, requests and organization member/seat/company administration. Investigate Phase A launcher relocation against actual permissions and existing license quotas; restore discoverable supported entry points without bypassing authorization or fabricating absent provisioning features. These regressions take priority over About placeholders; earlier audit work remains open.
223 +- Fresh remote main remains357cfb2. In progress: reproduce both routing problems, inspect licensed launcher and organization manager paths, add meaningful role-aware browser regressions and update docs/EXECUTION_STATUS.md with verified outcomes.
224 +- Diagnosis checkpoint: commercial-rnd.js inserts all sales/purchase options into both forms; onchange can leave original form type inconsistent. Phase A retained advanced workspace implementations in the licensed launcher, but Settings lacks discoverable organization administration and footer controls are tiny/stale after context changes. Existing secure invitations and organization-capacity dashboard are present; the old ELI-3 future hint is stale.
225 +- Production read-only catalog2026-10-31 confirms licenses.max_users/max_companies/modules/organization_id and RPCs admin_set_user_limit/admin_set_company_limit/organization_add_member/organization_create_invitation exist. No customer rows, credentials or financial data read/changed. This proves contracts exist, not successful real invitation or current customer quota values.
226 +- Implementation checkpoint: route-specific sales/purchase options and canonical invoice-kind synchronization; Settings entries for organization users/access/capacity and all workspaces; enterprise launcher picks a permitted task including accounting/treasury-only licenses; footer authority refresh and late-bound manager handler preserve invitation/capacity extensions. No financial engine/record or backend change.
227 +- Two commerce regressions observed RED→GREEN; focused commerce+existing invoice persistence7/7 PASS. Generated combined new scenarios8/8 PASS. First generated run failed because local HTTP server ended after steered user turn (connection refused); excluded, rerun with server lifetime bound to test succeeded. Static contracts updated to follow centralized existing authorization guard, not remove it; all pre-browser commands plus release-safety now PASS, including49server/Golden. Full211browser run ongoing. Independent reviewer agent unavailable due provider usage limit; root reviewing diff directly, no independent-review success claimed.
docs/EXECUTION_STATUS.md new
+27
@@ -0,0 +1,27 @@
1 +# وضعیت اجرای فینورا
2 +
3 +آخرین به‌روزرسانی: ۲۰۲۶-۱۰-۳۱. مرجع تاریخچه و اختیار اجرا: [PROJECT_STATE](../PROJECT_STATE.md).
4 +
5 +## هدف جاری
6 +
7 +کنترل‌های نرم‌افزار در مسیر واقعی کاربر، با نقش و دادهٔ مناسب و نتیجهٔ قابل اثبات کار کنند؛ سپس بهبود UX بر مبنای ممیزی و مقایسهٔ رسمی اجرا شود. تعداد تست یا کلیک، به‌تنهایی معیار پایان نیست.
8 +
9 +|کار|وضعیت|شواهد / اقدام بعدی|
10 +|---|---|---|
11 +|تفکیک نوع سند خرید/فروش|پیاده‌سازی؛ تست جدید source/Pages قبول|فروش: فروش/پیش‌فاکتور/صورت‌وضعیت؛ خرید: خرید؛ regression کامل در حال اجرا|
12 +|سازمان، درخواست‌ها و مدیریت اعضا|پیاده‌سازی؛ تست Pages قبول|ورودی تنظیمات، سازمان در انتخابگر، دعوت/ظرفیت موجود؛ انتشار هنوز انجام نشده|
13 +|اصلاح شرکت|منتشر؛ بازکردن/انصراف واقعی قبول|ذخیرهٔ تغییر شرکت در حساب واقعی از این پذیرش نتیجه نمی‌شود|
14 +|تعیین رمز مدیر کل|منتشر؛ تست مصنوعی موفق|آزمون واقعی پنجره با نقش مدیر کل و حساب کنترل‌شده باقی است|
15 +|منوهای فازA|منتشر؛۲۰۳تست نسخهٔ مربوط موفق|پذیرش همهٔ نقش‌ها و داده‌ها جداست|
16 +|ممیزی کنترل‌ها|گزارش وPR191 آماده|۷۳۴ تعریف،۶۵۱ مشاهده؛۷۶ مقصد منو؛۱۲۸ کلیک/۹۳ پیش‌شرط فراهم‌نشده|
17 +|بررسی آپدیت واقعی|باز؛ پس از اصلاحات فوری جدید|جایگزین پیام ثابت با مقایسهٔ نسخه و خطای صادقانه؛ تست قبل/بعد|
18 +|گزارش باگ واقعی|باز؛ پس از اصلاحات فوری جدید|بازکردن پیش‌نویس پشتیبانی؛ بدون ارسال خودکار یا اطلاعات خصوصی|
19 +|پوشش کنترل‌های پنهان|در حال تکمیل با سناریوهای خرید/فروش و سازمان|شروع از ایجاد سریع، مودال‌ها و تنظیمات؛ نتیجهٔ هر سناریو ثبت شود|
20 +|پذیرش تنظیمات پس از reload/logout|باز|آزمون قبلی فقط بازگشت به بخش و بازگردانی مقدار را ثابت کرد|
21 +|چندنقشی، چندشرکتی و هم‌زمانی|باز|داده و محیط ایزوله؛ کنترل سرور مرجع مجوز|
22 +|فاز مالی جدید۰|ممیزی تکمیل|اصلاحات هسته مالی در شاخه‌های آزمایشی؛ روی Production نصب نشده|
23 +|گرید اسناد، تاریخچه، مغایرت بانکی و onboarding|صف بعد ازپایداری|اولویت و معیارها در docs/audits/2026-10-31/competitor-comparison.md|
24 +
25 +## معیار تحویل نوبت جاری
26 +
27 +تست معنادار شکست‌خورده قبل از رفع، قبولی source/Pages، مجموعهٔ کامل regression و امنیت، PR و انتشار محافظت‌شده، بررسی نسخهٔ عمومی، سپس ثبت دقیق محدودیت‌های باقی‌مانده.
docs/NAVIGATION_RECOVERY_2026-10-31.md new
+31
@@ -0,0 +1,31 @@
1 +# پیگیری اصلاح مسیرهای بازرگانی و سازمان — ۲۰۲۶-۱۰-۳۱
2 +
3 +## هدف و درخواست مالک
4 +
5 +در مسیر فروش فقط انواع سند فروش، و در مسیر خرید فقط انواع خرید موجود باشند. سازمان، درخواست‌ها و مدیریت اعضا/ظرفیت‌ها باید با ورودی روشن و رعایت لایسنس و نقش قابل دسترس باشند. این اصلاحات بر کارهای ممیزی قبلی اولویت دارند؛ آن کارها حذف نشده‌اند.
6 +
7 +## علت‌های تأییدشده
8 +
9 +- `commercial-rnd.js` یک انتخابگر مشترک با گزینه‌های خرید و فروش در هر دو فرم ایجاد می‌کند. تغییر آن می‌تواند فرم مقابل را باز کند و مقدار انتخابگر فرم قبلی را ناسازگار باقی بگذارد.
10 +- فاز A هشت ماژول اصلی را در نوار ثابت نگه داشته و دارایی‌ها، منابع انسانی، اتوماسیون، درخواست‌ها و گروه شرکت‌ها را به انتخابگر «ماژول‌ها» منتقل کرده است. کد آن‌ها حذف نشده؛ مسیر کوچک پایین نوار به‌اندازه کافی قابل کشف نیست.
11 +- مدیریت اعضا و نقش‌های سازمانی در کنترل پایین نوار «دسترسی‌ها» مانده؛ در تنظیمات ورودی مستقیمی ندارد. کنترل‌های پایین نوار باید پس از تغییر نقش/سازمان هم بازبینی شوند.
12 +- دعوت امن کاربر جدید و داشبورد ظرفیت سازمان پیاده‌سازی شده‌اند. متن قدیمی «در ELI-3 اضافه می‌شود» گمراه‌کننده است.
13 +
14 +## تفکیک اختیارات
15 +
16 +|مسیر|کارکرد|
17 +|---|---|
18 +|کاربران و لایسنس‌ها؛ مدیر کل نرم‌افزار|ساخت حساب مرکزی، اصلاح لایسنس و ظرفیت شرکت/کاربر، ماژول‌های مجاز و عملیات رمز مجاز|
19 +|سازمان و دسترسی‌ها؛ مدیر مجاز سازمان|عضویت، دعوت امن، نقش‌ها و دسترسی‌ها، ساختار سازمانی و نمایش ظرفیت|
20 +|شرکت‌ها|مدیریت شرکت‌های مجاز در سقف ظرفیت لایسنس|
21 +|ماژول‌ها|ورود به فضاهای کاری موجود و مجاز؛ بدون اعطای مجوز جدید|
22 +
23 +بررسی خواندنی کاتالوگ Production وجود ستون‌های `max_users`، `max_companies`، `modules` و `organization_id` و توابع تنظیم ظرفیت، افزودن عضو و ایجاد دعوت را تأیید کرد. هیچ سهمیه یا داده مشتری تغییر نکرد. وجود قرارداد سرور، آزمون موفق دعوت در حساب واقعی یا اعلام مقدار سهمیه مشتری نیست.
24 +
25 +## وضعیت اجرا
26 +
27 +اصلاحات پیاده‌سازی شده؛ هنوز منتشر نشده. دو تست خرید/فروش قبل از اصلاح شکست خوردند و سپس قبول شدند. ۸ سناریوی جدید در نسخهٔ ساخته‌شده Pages قبول شدند. بررسی‌های ایستا و ۴۹ تست سروری قبول‌اند؛ regression کامل ۲۱۱ تست در حال اجراست. یک اجرای اولیه Pages به علت خاموش‌شدن سرور محلی شکست خورد؛ اجرای مجدد با سرور همراه آزمون، ۸/۸ قبول شد. تابلوی جاری: [EXECUTION_STATUS](EXECUTION_STATUS.md).
28 +
29 +## باقی‌مانده
30 +
31 +آزمون نقش‌های مدیر سازمان/کاربر محدود، نبود لایسنس ماژول، جابه‌جایی فرم خرید و فروش و نسخهٔ ساخته‌شده Pages؛ سپس regression و انتشار محافظت‌شده. پذیرش واقعی ایجاد دعوت و عملیات مالی از تست مصنوعی نتیجه نمی‌شود.
index.html
+4 -4
@@ -925,8 +925,8 @@ body{background:#f6f9fc}
925 <script src="js/core.js?v=20261025-password-recovery-v1"></script>
926 <script src="js/admin.js?v=20261028-central-password-reset-v1"></script>
927 <script src="js/sync.js?v=20261012-login-read-cancel-v1"></script>
928 -<script src="js/ui.js?v=20261023-phase-a-navigation-v1"></script>
929 -<script src="js/invoices.js?v=20261024-settings-zero-vat-v1"></script>
928 +<script src="js/ui.js?v=20261031-workspace-recovery-v1"></script>
929 +<script src="js/invoices.js?v=20261031-workspace-recovery-v1"></script>
930 <script src="js/print.js?v=20261012-clean-invoice-print-v1"></script>
931 <script src="js/products.js"></script>
932 <script src="js/contacts.js?v=20260928-roles-v3"></script>
@@ -935,7 +935,7 @@ body{background:#f6f9fc}
935 <script src="js/companies.js?v=20261028-company-edit-v1"></script>
936 <script src="js/backup.js?v=20260928-data-v3"></script>
937 <script src="js/words.js"></script>
938 -<script src="js/bootstrap.js?v=20261030-navigation-recovery-v1"></script>
938 +<script src="js/bootstrap.js?v=20261031-workspace-recovery-v1"></script>
939
940 <style>
941 .form-control, textarea, select { direction: rtl; }
@@ -948,7 +948,7 @@ body{background:#f6f9fc}
948 <script src="js/projects.js?v=20260928-projects-v7"></script>
949 <script src="js/invoice-excel-import.js"></script>
950 <script src="js/purchases.js?v=20261011-persian-print-v1"></script>
951 -<script src="js/commercial-rnd.js?v=20261007-commerce-r1"></script>
951 +<script src="js/commercial-rnd.js?v=20261031-workspace-recovery-v1"></script>
952 <script src="js/operations.js?v=20260928-phase3-final"></script>
953 <script src="js/payments.js?v=20260928-phase3-final"></script>
954 <script src="js/accounting.js?v=20260928-accounting-v3"></script>
js/bootstrap.js
+3 -3
@@ -3,10 +3,10 @@
3 // browsers may download in parallel but preserve script execution/dependencies.
4 // Auth starts only once all extensions have finished loading or failed.
5 const FINORA_EXTENSION_SCRIPTS=[
6 - "js/organization-rbac.js?v=20261030-navigation-recovery-v1",
6 + "js/organization-rbac.js?v=20261031-workspace-recovery-v1",
7 "js/organization-invitations.js?v=20260930-eli3-v1",
8 "js/organization-enterprise-ux.js?v=20260930-eli4-v1",
9 - "js/platform-modules.js?v=20261023-phase-a-navigation-v1",
9 + "js/platform-modules.js?v=20261031-workspace-recovery-v1",
10 "js/office-automation.js?v=20260930-c4-v1",
11 "js/request-workflow-d2.js?v=20261001-d2-v1",
12 "js/request-workflow-d3b.js?v=20261001-d3b-v1",
@@ -15,7 +15,7 @@ const FINORA_EXTENSION_SCRIPTS=[
15 "js/office-rbac.js?v=20260930-slice-b-v1",
16 "js/office-mature.js?v=20261001-c7-v2",
17 "js/office-workflow.js?v=20261001-c8-task3-v3",
18 - "js/organization-shell.js?v=20261023-phase-a-navigation-v1",
18 + "js/organization-shell.js?v=20261031-workspace-recovery-v1",
19 "js/taxpayer-print.js?v=20261003-reference-v2"
20 ];
21 const FINORA_EXTENSION_BUNDLE_URL=null;
js/commercial-rnd.js
+8 -5
@@ -8,18 +8,21 @@
8 if(kind){kind.value=type==='pre_invoice'?'pre_invoice':type==='contract_statement'?'contract_statement':'non_formal';if(typeof handleInvoiceKindChange==='function')handleInvoiceKindChange();}
9 };
10 function invoiceTypeControl(current){
11 - return '<div class="form-group finora-invoice-type" style="min-width:220px;margin:0"><label>نوع فاکتور / سند تجاری</label><select class="form-control" onchange="finoraOpenInvoiceType(this.value)">'+
12 - '<option value="sale" '+(current==='sale'?'selected':'')+'>فروش</option>'+
13 - '<option value="purchase" '+(current==='purchase'?'selected':'')+'>خرید</option>'+
11 + // The shell owns purchase/sales navigation; each form offers only its own family.
12 + const options=current==='purchase'?'<option value="purchase">خرید</option>':
13 + '<option value="sale">فروش</option>'+
14 '<option value="pre_invoice">پیش‌فاکتور فروش</option>'+
15 - '<option value="contract_statement">صورت‌وضعیت فروش</option>'+
16 - '</select><small style="color:var(--text-muted)">نوع سند را انتخاب کنید؛ حسابداری هر رویداد به‌صورت خودکار تعیین می‌شود.</small></div>';
15 + '<option value="contract_statement">صورت‌وضعیت فروش</option>';
16 + return '<div class="form-group finora-invoice-type" style="min-width:220px;margin:0"><label>نوع فاکتور / سند تجاری</label><select class="form-control" onchange="finoraOpenInvoiceType(this.value)">'+options+
17 + '</select><small style="color:var(--text-muted)">'+(current==='purchase'?'اسناد خرید از این بخش ثبت می‌شوند.':'نوع سند فروش را انتخاب کنید.')+'</small></div>';
18 }
19 function installUnifiedInvoiceControls(){
20 const saleTitle=$('invoice-form-title');
21 if(saleTitle&&!document.querySelector('#view-invoices .finora-invoice-type')){
22 const host=saleTitle.parentElement?.parentElement;if(host){const box=document.createElement('div');box.innerHTML=invoiceTypeControl('sale');host.insertBefore(box.firstElementChild,host.children[1]||null);}saleTitle.innerText='صدور سند تجاری';
23 }
24 + const saleType=document.querySelector('#view-invoices .finora-invoice-type select'),kind=$('invoice-kind')?.value;
25 + if(saleType)saleType.value=['pre_invoice','contract_statement'].includes(kind)?kind:'sale';
26 const purSel=$('pur-supplier');
27 if(purSel&&!$('pur-quick-supplier')){
28 const a=document.createElement('a');a.id='pur-quick-supplier';a.href='#';a.innerText='+ تأمین‌کننده جدید';a.style.cssText='display:inline-block;margin-bottom:6px';a.onclick=e=>{e.preventDefault();openQuickContactModal('supplier');};purSel.parentElement?.insertBefore(a,purSel);
js/invoices.js
+2
@@ -1,5 +1,7 @@
1 function handleInvoiceKindChange(){
2 const kind=document.getElementById('invoice-kind').value;
3 + const salesType=document.querySelector('#view-invoices .finora-invoice-type select');
4 + if(salesType)salesType.value=['pre_invoice','contract_statement'].includes(kind)?kind:'sale';
5 const vatModeRow=document.getElementById('box-invoice-vat-mode-row');
6 const vatModeSelect=document.getElementById('invoice-vat-mode');
7 if(kind==='non_formal'){
js/organization-rbac.js
+9 -5
@@ -159,9 +159,10 @@ function configurableModules(){
159 if(currentUser?.isOrganizationOwner)return Object.entries(window.FINORA_MODULE_CATALOG||{}).filter(([k,v])=>k!=='core'&&v.implemented).map(([k,v])=>[k,v.title]);
160 return (currentUser?.modulePermissions||[]).filter(p=>p.capabilities?.includes('configure')).map(p=>[p.module_key,(window.FINORA_MODULE_CATALOG||{})[p.module_key]?.title||p.module_key]);
161 }
162 +window.finoraCanOpenOrganizationAccess=function(){return !!currentUser?.organizationId&&(finoraCanManageOrganization()||configurableModules().length>0)};
163 window.showOrganizationAccessManager=async function(){
164 const canManage=finoraCanManageOrganization();
164 - if(!canManage&&!configurableModules().length)return alert('دسترسی مدیریت اعضا یا مجوزهای ماژول را ندارید.');
165 + if(!window.finoraCanOpenOrganizationAccess())return alert('دسترسی مدیریت اعضا یا مجوزهای ماژول را ندارید.');
166 let el=document.getElementById('finora-org-access-modal');if(!el){el=document.createElement('div');el.id='finora-org-access-modal';el.className='modal-backdrop';document.body.appendChild(el)}
167 const members=await orgManagerData(),mods=configurableModules(),roleData=canManage?await roleManagerData():{roles:[],permissions:[],assignments:[]};
168 const roleModules=canManage?roleConfigurableModules():[];
@@ -172,7 +173,7 @@ window.showOrganizationAccessManager=async function(){
173 return '<tr><td>'+esc(m.profile?.full_name||m.profile?.email||m.user_id)+'</td><td>'+esc(m.position_title||'—')+'</td><td>'+esc(m.status)+'</td><td>'+status+' '+recovery+'</td></tr>';
174 }).join('');
175 el.innerHTML='<div class="modal-card" style="max-width:900px"><div style="display:flex;justify-content:space-between;gap:10px"><div><h3>مدیریت دسترسی سازمان</h3><p class="af-hint">'+esc(currentUser.organizationName||'')+' · مجوز تجاری و مجوز عضو مستقل از هم هستند.</p><p id="org-seat-summary" class="af-hint"><strong>'+toPersianDigits(activeCount)+'</strong> کاربر فعال از <strong>'+toPersianDigits(maxUsers)+'</strong> · ظرفیت باقی‌مانده '+toPersianDigits(remaining)+'</p></div><button class="btn btn-secondary btn-inline" onclick="document.getElementById(\'finora-org-access-modal\').classList.remove(\'active\')">بستن</button></div>'+
175 - (canManage?'<div class="card" style="margin-top:14px"><h4>افزودن عضو موجود فینورا</h4><div class="form-row"><div class="form-group"><label>ایمیل</label><input id="org-member-email" class="form-control" type="email"></div><div class="form-group"><label>سمت</label><input id="org-member-position" class="form-control"></div></div><button class="btn btn-primary" onclick="organizationAddMemberFromUi()">افزودن عضو</button><p class="af-hint">دعوت کاربر فاقد حساب در ELI-3 اضافه می‌شود.</p><div class="table-responsive" style="margin-top:12px"><table><thead><tr><th>عضو</th><th>سمت</th><th>وضعیت</th><th>عملیات</th></tr></thead><tbody>'+memberRows+'</tbody></table></div></div>':'')+
176 + (canManage?'<div class="card" style="margin-top:14px"><h4>افزودن عضو موجود فینورا</h4><div class="form-row"><div class="form-group"><label>ایمیل</label><input id="org-member-email" class="form-control" type="email"></div><div class="form-group"><label>سمت</label><input id="org-member-position" class="form-control"></div></div><button class="btn btn-primary" onclick="organizationAddMemberFromUi()">افزودن عضو</button><p class="af-hint">برای کاربر جدید از بخش «دعوت کاربر جدید» در همین پنجره استفاده کنید.</p><div class="table-responsive" style="margin-top:12px"><table><thead><tr><th>عضو</th><th>سمت</th><th>وضعیت</th><th>عملیات</th></tr></thead><tbody>'+memberRows+'</tbody></table></div></div>':'')+
177 (canManage?'<div class="card"><h4>نقش‌های سازمانی</h4><p class="af-hint">نقش‌ها مجوزهای قابل استفاده مجدد هستند؛ مجوز مستقیم هر کاربر همچنان به‌عنوان Override مستقل باقی می‌ماند.</p><div class="form-row"><div class="form-group"><label>کلید نقش سفارشی</label><input id="org-role-key" class="form-control" placeholder="regional_accountant"></div><div class="form-group"><label>عنوان نقش</label><input id="org-role-title" class="form-control" placeholder="حسابدار ناحیه"></div></div><button class="btn btn-primary btn-inline" onclick="organizationCreateRoleFromUi()">ایجاد/به‌روزرسانی نقش</button><hr style="margin:14px 0"><div class="form-row"><div class="form-group"><label>عضو</label><select id="org-role-member" class="form-control">'+members.filter(m=>!m.is_owner&&m.status==='active').map(m=>'<option value="'+esc(m.id)+'">'+esc(m.profile?.full_name||m.profile?.email||m.position_title||m.user_id)+'</option>').join('')+'</select></div><div class="form-group"><label>نقش</label><select id="org-role-assign" class="form-control">'+roleData.roles.filter(r=>r.active).map(r=>'<option value="'+esc(r.id)+'">'+esc(r.title)+(r.is_system?' · پیش‌فرض':'')+'</option>').join('')+'</select></div></div><button class="btn btn-success btn-inline" onclick="organizationAssignRoleFromUi()">تخصیص نقش</button><hr style="margin:14px 0"><div class="form-row"><div class="form-group"><label>نقش</label><select id="org-role-perm-role" class="form-control">'+roleData.roles.filter(r=>r.active).map(r=>'<option value="'+esc(r.id)+'">'+esc(r.title)+'</option>').join('')+'</select></div><div class="form-group"><label>ماژول</label><select id="org-role-perm-module" class="form-control">'+roleModules.map(x=>'<option value="'+esc(x[0])+'">'+esc(x[1])+'</option>').join('')+'</select></div><div class="form-group"><label>سطح محرمانگی</label><select id="org-role-perm-clearance" class="form-control"><option value="0">عادی</option><option value="1">محرمانه</option><option value="2">خیلی محرمانه</option><option value="3">سری</option></select></div></div><div class="form-group"><label>قابلیت‌های نقش</label><div id="org-role-perm-caps" style="display:flex;gap:10px;flex-wrap:wrap">'+[['read','مشاهده'],['create','ایجاد'],['edit','ویرایش'],['delete','حذف'],['approve','تأیید'],['register','ثبت دبیرخانه'],['refer','ارجاع'],['archive','بایگانی'],['configure','مدیریت']].map(x=>'<label><input type="checkbox" value="'+x[0]+'" '+(x[0]==='read'?'checked':'')+'> '+x[1]+'</label>').join('')+'</div></div><button class="btn btn-success btn-inline" onclick="organizationSaveRolePermissionFromUi()">ثبت مجوز نقش</button><div class="table-responsive" style="margin-top:12px"><table><thead><tr><th>نقش</th><th>نوع</th><th>مجوزها</th><th>تخصیص‌ها</th></tr></thead><tbody>'+roleData.roles.map(r=>'<tr><td>'+esc(r.title)+'</td><td>'+(r.is_system?'پیش‌فرض':'سفارشی')+'</td><td>'+roleData.permissions.filter(p=>p.role_id===r.id).map(p=>esc(p.module_key)+' ('+esc((p.capabilities||[]).join(', '))+')').join('<br>')+'</td><td>'+toPersianDigits(roleData.assignments.filter(a=>a.role_id===r.id).length)+'</td></tr>').join('')+'</tbody></table></div></div>':'')+
178 '<div class="card"><h4>مجوز مستقیم کاربر <small style="color:var(--text-muted)">Override پیشرفته</small></h4><div class="form-row"><div class="form-group"><label>عضو</label><select id="org-perm-member" class="form-control">'+members.filter(m=>!m.is_owner&&m.status==='active').map(m=>'<option value="'+esc(m.id)+'">'+esc(m.profile?.full_name||m.profile?.email||m.position_title||m.user_id)+'</option>').join('')+'</select></div><div class="form-group"><label>ماژول</label><select id="org-perm-module" class="form-control">'+mods.map(x=>'<option value="'+esc(x[0])+'">'+esc(x[1])+'</option>').join('')+'</select></div><div class="form-group"><label>دامنه</label><select id="org-perm-scope" class="form-control" onchange="document.getElementById(\'org-perm-scope-id\').disabled=[\'own\',\'organization\'].includes(this.value)"><option value="own">فقط رکوردهای خود</option><option value="unit">واحد</option><option value="branch">شعبه</option><option value="company">شرکت</option><option value="organization">کل سازمان</option></select></div><div class="form-group"><label>شناسه دامنه</label><input id="org-perm-scope-id" class="form-control" disabled></div></div><div class="form-group"><label>قابلیت‌ها</label><div id="org-perm-caps" style="display:flex;gap:10px;flex-wrap:wrap">'+[['read','مشاهده'],['create','ایجاد'],['edit','ویرایش'],['delete','حذف'],['approve','تأیید'],['register','ثبت دبیرخانه'],['refer','ارجاع'],['archive','بایگانی'],['configure','مدیریت ماژول']].map(x=>'<label><input type="checkbox" value="'+x[0]+'" '+(x[0]==='read'?'checked':'')+'> '+x[1]+'</label>').join('')+'</div></div><div class="form-row"><div class="form-group"><label>سطح محرمانگی</label><select id="org-perm-clearance" class="form-control"><option value="0">عادی</option><option value="1">محرمانه</option><option value="2">خیلی محرمانه</option><option value="3">سری</option></select></div></div><button class="btn btn-success" onclick="organizationSavePermissionFromUi()">ثبت/به‌روزرسانی مجوز مستقیم</button></div></div>';
179 el.classList.add('active');
@@ -215,10 +216,13 @@ window.organizationSavePermissionFromUi=async function(){
216 const {error}=await sb.rpc('organization_set_member_permission',{p_organization_id:currentUser.organizationId,p_member_id:member,p_module_key:module,p_capabilities:caps,p_scope_type:scope,p_scope_id:scopeId,p_confidentiality_level:clearance});if(error)return alert('ثبت مجوز انجام نشد: '+error.message);alert('مجوز عضو ثبت شد.');await showOrganizationAccessManager();
217 };
218 function ensureOrgAccessButton(){
218 - const footer=document.querySelector('.app-shell-nav .sidebar-footer');if(!footer||document.getElementById('finora-org-access-btn'))return;
219 - const b=document.createElement('button');b.id='finora-org-access-btn';b.className='shell-logout';b.title='سازمان و دسترسی‌ها';b.textContent='دسترسی‌ها';b.onclick=showOrganizationAccessManager;footer.appendChild(b);
220 - b.style.display=(finoraCanManageOrganization()||configurableModules().length)?'':'none';
219 + const footer=document.querySelector('.app-shell-nav .sidebar-footer');if(!footer)return;
220 + let b=document.getElementById('finora-org-access-btn');
221 + if(!b){b=document.createElement('button');b.id='finora-org-access-btn';b.className='shell-logout';b.title='سازمان و دسترسی‌ها';b.textContent='دسترسی‌ها';footer.appendChild(b)}
222 + b.onclick=()=>window.showOrganizationAccessManager();
223 + b.style.display=window.finoraCanOpenOrganizationAccess()?'':'none';
224 }
225 +window.refreshFinoraOrganizationAccessButton=ensureOrgAccessButton;
226 const baseEnterAppOrg=enterApp;
227 enterApp=async function(authUser){const r=await baseEnterAppOrg(authUser);ensureOrgAccessButton();return r};
228 // Signal only after the full organization module and its account wrapper exist.
js/organization-shell.js
+6 -4
@@ -1,15 +1,17 @@
1 /* Slice B / ELI organization shell controls loaded after platform modules. */
2 (function(){
3 -function canManage(){return !!currentUser&&!!window.finoraCanManageOrganization?.()}
3 window.showFinoraOrganizationSwitcher=function(){
4 const xs=currentUser?.organizations||[];if(xs.length<2)return;
5 let el=document.getElementById('finora-org-switch-modal');if(!el){el=document.createElement('div');el.id='finora-org-switch-modal';el.className='modal-backdrop';document.body.appendChild(el)}
6 el.innerHTML='<div class="modal-card" style="max-width:520px"><h3>انتخاب سازمان فعال</h3><p class="af-hint">اطلاعات، لایسنس و دسترسی‌ها بر اساس سازمان انتخاب‌شده بارگذاری می‌شوند.</p>'+finoraOrganizationSwitcherHtml()+'<div style="margin-top:14px"><button class="btn btn-secondary" onclick="document.getElementById(\'finora-org-switch-modal\').classList.remove(\'active\')">بستن</button></div></div>';el.classList.add('active');
7 };
8 function ensureOrgShell(){
10 - const footer=document.querySelector('.app-shell-nav .sidebar-footer');if(!footer||!currentUser)return;
11 - if((currentUser.organizations||[]).length>1&&!document.getElementById('finora-org-switch-btn')){const b=document.createElement('button');b.id='finora-org-switch-btn';b.className='shell-logout';b.title='تغییر سازمان';b.textContent='سازمان';b.onclick=showFinoraOrganizationSwitcher;footer.appendChild(b)}
12 - if(canManage()&&!document.getElementById('finora-org-access-btn')){const b=document.createElement('button');b.id='finora-org-access-btn';b.className='shell-logout';b.title='سازمان و دسترسی‌ها';b.textContent='دسترسی‌ها';b.onclick=showOrganizationAccessManager;footer.appendChild(b)}
9 + const footer=document.querySelector('.app-shell-nav .sidebar-footer');if(!footer)return;
10 + let b=document.getElementById('finora-org-switch-btn');
11 + const multiple=(currentUser?.organizations||[]).length>1;
12 + if(multiple&&!b){b=document.createElement('button');b.id='finora-org-switch-btn';b.className='shell-logout';b.title='تغییر سازمان';b.textContent='سازمان';b.onclick=()=>window.showFinoraOrganizationSwitcher();footer.appendChild(b)}
13 + if(b)b.style.display=multiple?'':'none';
14 + window.refreshFinoraOrganizationAccessButton?.();
15 }
16 const baseEnter=enterApp;enterApp=async function(authUser){const r=await baseEnter(authUser);ensureOrgShell();return r};
17 const baseRefresh=refreshAllSurfaces;refreshAllSurfaces=function(){const r=baseRefresh();ensureOrgShell();return r};
js/platform-modules.js
+11 -2
@@ -31,9 +31,18 @@ if(typeof renderModulePanel==='function'){const basePanel=renderModulePanel;rend
31 if(typeof openModule==='function'){const baseOpen=openModule;openModule=function(moduleKey,defaultView,defaultTask=''){if(!canModule(moduleKey,defaultTask||'')){alert('این ماژول در لایسنس فعلی فعال نیست.');return showModuleLauncher(true)}return baseOpen(moduleKey,defaultView,defaultTask)}}
32 if(typeof navigateShell==='function'){const baseNav=navigateShell;navigateShell=function(moduleKey,viewId,task='',rerender=true){if(!canModule(moduleKey,task||'')){alert('دسترسی این ماژول در لایسنس فعلی فعال نیست.');return false}return baseNav(moduleKey,viewId,task,rerender)}}
33 if(typeof refreshAllSurfaces==='function'){const baseRefresh=refreshAllSurfaces;refreshAllSurfaces=function(){const r=baseRefresh();applyLicensedUI();if(document.getElementById('view-office')?.classList.contains('active')&&typeof officeRender==='function')officeRender(window.FINORA_OFFICE_TASK||'inbox');if(document.getElementById('view-requests')?.classList.contains('active')&&typeof requestsRender==='function')requestsRender(window.FINORA_REQUEST_TASK||'mine');return r}}
34 -function launcherModules(){const list=[['accounting','accounting','view-accounting-foundation','accounts'],['commerce','commerce','view-invoices',''],['treasury','treasury','view-payments',''],['contracting','projects','view-contracting',''],['inventory','inventory','view-inventory','stock'],['assets','assets','view-assets','asset-register'],['hr_payroll','enterprise','view-enterprise','employees'],['office_automation','office','view-office','inbox'],['requests_workflow','requests','view-requests','new'],['group_consolidation','enterprise','view-enterprise','group'],['analytics','reports','view-reports','']];return list.filter(x=>licensed(x[0])&&canShowShellCommand({module:x[1],view:x[2],task:x[3]}))}
34 +function launcherModules(){
35 + const list=[['accounting','accounting','view-accounting-foundation','accounts'],['commerce','commerce','view-invoices',''],['treasury','treasury','view-payments',''],['contracting','projects','view-contracting',''],['inventory','inventory','view-inventory','stock'],['assets','assets','view-assets','asset-register'],['office_automation','office','view-office','inbox'],['requests_workflow','requests','view-requests','new'],['analytics','reports','view-reports','']];
36 + // Enterprise is a workspace spanning several existing licensed modules. Route to
37 + // its first permitted task, including accounting/treasury-only subscriptions.
38 + const enterprise=[['hr_payroll','employees'],['group_consolidation','group'],['treasury','treasury'],['accounting','costing']]
39 + .map(([key,task])=>[key,'enterprise','view-enterprise',task])
40 + .find(x=>licensed(x[0])&&canShowShellCommand({module:x[1],view:x[2],task:x[3]}));
41 + if(enterprise)list.splice(6,0,enterprise);
42 + return list.filter(x=>licensed(x[0])&&canShowShellCommand({module:x[1],view:x[2],task:x[3]}));
43 +}
44 function ensureLauncher(){let el=document.getElementById('finora-module-launcher');if(el)return el;el=document.createElement('div');el.id='finora-module-launcher';el.className='modal-backdrop';el.innerHTML='<div class="modal-card" style="max-width:860px"><div style="display:flex;justify-content:space-between;gap:12px;align-items:center"><div><h3 style="font-size:20px">ورود به فضای کاری</h3><p style="color:var(--text-muted);font-size:12px;margin-top:5px">فقط ماژول‌های فعال در لایسنس شما نمایش داده می‌شوند.</p></div><button class="btn btn-secondary btn-inline" onclick="closeModuleLauncher()">ادامه در داشبورد</button></div><div id="finora-launcher-grid" style="display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px;margin-top:18px"></div></div>';document.body.appendChild(el);return el}
36 -function showModuleLauncher(force=false){if(!currentUser)return;const choices=launcherModules();if(!force&&choices.length<=1)return;const el=ensureLauncher(),grid=document.getElementById('finora-launcher-grid');grid.innerHTML=choices.map(x=>{const c=MODULE_CATALOG[x[0]];return '<button class="card" style="text-align:right;cursor:pointer;border:1px solid var(--border);padding:16px" onclick="enterLicensedWorkspace(\''+x[1]+'\',\''+x[2]+'\',\''+x[3]+'\')"><div style="font-size:24px">'+c.icon+'</div><strong style="display:block;margin-top:8px">'+c.title+'</strong><small style="color:var(--text-muted)">ورود به ماژول</small></button>'}).join('');el.classList.add('active')}
45 +function showModuleLauncher(force=false){if(!currentUser)return;const choices=launcherModules();if(!force&&choices.length<=1)return;const el=ensureLauncher(),grid=document.getElementById('finora-launcher-grid');grid.innerHTML=choices.map(x=>{const c=MODULE_CATALOG[x[0]];return '<button class="card" style="text-align:right;cursor:pointer;border:1px solid var(--border);padding:16px" onclick="enterLicensedWorkspace(\''+x[1]+'\',\''+x[2]+'\',\''+x[3]+'\')"><div style="font-size:24px">'+c.icon+'</div><strong style="display:block;margin-top:8px">'+(x[1]==='enterprise'?'سازمان · ':'')+c.title+'</strong><small style="color:var(--text-muted)">ورود به ماژول</small></button>'}).join('');el.classList.add('active')}
46 window.showModuleLauncher=showModuleLauncher;window.closeModuleLauncher=()=>document.getElementById('finora-module-launcher')?.classList.remove('active');window.enterLicensedWorkspace=(m,v,t)=>{closeModuleLauncher();navigateShell(m,v,t||'')};
47 function ensureLicensePicker(){const modal=document.querySelector('#modal-admin-license-edit .modal-card');if(!modal||document.getElementById('modal-license-modules'))return;const actions=modal.querySelector('div[style*="margin-top:16px"]'),box=document.createElement('div');box.id='modal-license-modules';box.className='form-group';box.innerHTML='<label>ماژول‌های فعال لایسنس</label><div id="license-module-grid" style="display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px;margin-top:8px"></div><small style="color:var(--text-muted)">«کامل» همه ماژول‌های فعلی و آینده را باز می‌کند. ماژول‌های آتی تا زمان عملیاتی‌شدن قابل فروش نیستند.</small>';modal.insertBefore(box,actions||null)}
48 function renderLicensePicker(uid){ensureLicensePicker();const u=typeof adminUsersCache!=='undefined'?adminUsersCache.find(x=>x.id===uid):null,mods=Array.isArray(u?.lic?.modules)&&u.lic.modules.length?u.lic.modules:['full_suite'],grid=document.getElementById('license-module-grid');if(!grid)return;grid.innerHTML='<label style="grid-column:1/-1"><input type="checkbox" value="full_suite" '+(mods.includes('full_suite')?'checked':'')+' onchange="toggleFullSuiteModules(this)"> <strong>لایسنس کامل ERP</strong></label>'+Object.entries(MODULE_CATALOG).filter(([k])=>k!=='core').map(([k,v])=>'<label style="opacity:'+(v.implemented?1:.5)+'"><input class="license-module-check" type="checkbox" value="'+k+'" '+(mods.includes('full_suite')||mods.includes(k)?'checked':'')+' '+(v.implemented?'':'disabled')+'> '+v.title+(v.implemented?'':' — آتی')+'</label>').join('');toggleFullSuiteModules(grid.querySelector('input[value="full_suite"]'),true)}
js/ui.js
+9 -1
@@ -102,7 +102,7 @@ const FINORA_MODULES={
102 assets:{title:'دارایی ثابت',context:'دارایی، استهلاک و ارزش دفتری',groups:[{title:'اطلاعات پایه',items:[['ثبت دارایی','view-assets','◆','','asset-new']]},{title:'عملیات و دفاتر',items:[['دفتر دارایی‌ها','view-assets','▤','','asset-register'],['استهلاک و سوابق','view-assets','◷','','depreciation']]}]},
103 enterprise:{title:'سازمان',context:'منابع انسانی، حقوق، خزانه، بهای تمام‌شده و کنترل گروه',groups:[{title:'منابع انسانی',items:[['کارکنان','view-enterprise','♙','','employees'],['قرارداد کار و پایان‌کار','view-enterprise','▤','','contracts'],['مرخصی و ذخیره','view-enterprise','◷','','leave'],['حقوق، بیمه و مالیات','view-enterprise','▥','','payroll'],['تعهدات کارکنان','view-enterprise','◌','','benefits']]},{title:'خزانه تکمیلی',items:[['صندوق و تعریف تنخواه','view-enterprise','¤','','treasury'],['عملیات تنخواه و تسویه','view-enterprise','↔','','pettyops']]},{title:'کنترل مدیریت',items:[['بودجه عملکرد و ABC','view-enterprise','◎','','costing'],['گروه، نقدینگی و فی‌مابین','view-enterprise','▦','','group']]},{title:'انطباق',items:[['رجیستری قوانین و استانداردها','view-enterprise','✓','','compliance']]}]},
104 reports:{title:'گزارش‌ها',context:'گزارش‌های حسابداری و مدیریتی',groups:[{title:'مدیریتی',items:[['گزارش‌های عملیاتی','view-reports','▥']]},{title:'حسابداری',items:[['تراز آزمایشی','view-accounting-reports','▥','','trial'],['دفاتر حسابداری','view-accounting-reports','▤','','ledger'],['صورت‌های مالی','view-accounting-reports','◫','','financials'],['جریان وجوه نقد','view-accounting-reports','↕','','cashflow'],['سن مطالبات / بدهی','view-accounting-reports','◷','','aging'],['پروژه / پیمان','view-accounting-reports','▧','','projects']]}]},
105 - settings:{title:'تنظیمات',context:'شرکت، داده، دسترسی و یکپارچه‌سازی',groups:[{title:'حساب و شرکت',items:[['شرکت‌ها','view-settings','▦','','company'],['حساب کاربری و رمز','view-settings','♙','','account'],['پیش‌فرض فاکتور','view-settings','▤','','invoice-defaults']]},{title:'عملیات و داده',items:[['تنظیمات عملیاتی','view-data-center','◌','','ops-settings'],['ورود/خروج داده و پشتیبان','view-data-center','⇅','','data-backup']]},{title:'یکپارچه‌سازی',items:[['اتصالات و API','view-integrations','⇆']]},{title:'سیستم',items:[['درباره فینورا','view-settings','ⓘ','','about'],['کاربران و لایسنس','view-admin','♙','admin']]}]}
105 + settings:{title:'تنظیمات',context:'شرکت، داده، دسترسی و یکپارچه‌سازی',groups:[{title:'حساب و شرکت',items:[['شرکت‌ها','view-settings','▦','','company'],['حساب کاربری و رمز','view-settings','♙','','account'],['پیش‌فرض فاکتور','view-settings','▤','','invoice-defaults']]},{title:'سازمان و فضای کاری',items:[['کاربران، دسترسی‌ها و ظرفیت سازمان','view-settings','♙','organization','organization-access'],['همه ماژول‌ها و فضاهای کاری','view-settings','▦','','module-launcher']]},{title:'عملیات و داده',items:[['تنظیمات عملیاتی','view-data-center','◌','','ops-settings'],['ورود/خروج داده و پشتیبان','view-data-center','⇅','','data-backup']]},{title:'یکپارچه‌سازی',items:[['اتصالات و API','view-integrations','⇆']]},{title:'سیستم',items:[['درباره فینورا','view-settings','ⓘ','','about'],['کاربران و لایسنس','view-admin','♙','admin']]}]}
106 };
107 const FINORA_VIEW_HOME={
108 'view-dashboard':'dashboard','view-journal':'accounting','view-accounting-foundation':'accounting','view-accounting-reports':'accounting','view-currency':'accounting',
@@ -127,6 +127,8 @@ function canShowShellCommand(cmd){
127 }
128 // Admin-only entries are shown based on the verified role of the signed-in user
129 // (server-side RLS/RPC still enforces the real permission).
130 + if(cmd.guard==='organization')return !!window.finoraCanOpenOrganizationAccess?.();
131 + if(cmd.task==='module-launcher'&&typeof window.showModuleLauncher!=='function')return false;
132 if(cmd.guard==='admin')return !!(typeof currentUser!=='undefined'&&currentUser&&currentUser.role==='admin');
133 return true;
134 }
@@ -171,6 +173,12 @@ function openModule(moduleKey,defaultView,defaultTask=''){
173 if(defaultView)navigateShell(moduleKey,defaultView,defaultTask,true);else renderModulePanel(moduleKey,'','');
174 }
175 function navigateShell(moduleKey,viewId,task='',rerender=true){
176 + if(moduleKey==='settings'&&task==='organization-access'){
177 + closeCommandSearch();
178 + if(!window.finoraCanOpenOrganizationAccess?.())return false;
179 + return window.showOrganizationAccessManager();
180 + }
181 + if(moduleKey==='settings'&&task==='module-launcher'){closeCommandSearch();return window.showModuleLauncher?.(true);}
182 if(viewId==='view-journal'&&typeof ensureJournalView==='function')ensureJournalView();
183 if(viewId==='view-enterprise'&&typeof ensureEnterpriseView==='function')ensureEnterpriseView();
184 switchView(viewId);
scripts/commerce-route-types.spec.js new
+48
@@ -0,0 +1,48 @@
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 +async function openCommerce(page,kind='non_formal'){
4 + await page.route(/https:\/\/[^/]*supabase\.co\//,r=>r.abort());
5 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
6 + await page.waitForFunction(()=>window.FinoraStartupStatus?.extensionsReady&&window.FinoraStartupStatus?.authChecked&&!window.FinoraStartupStatus?.failedExtensionCount);
7 + await page.evaluate(async kind=>{
8 + window.alert=()=>{};window.confirm=()=>false;maybeMigrateLegacyData=()=>{};
9 + fetchCurrentUser=async()=>({id:'COMMERCE_QA',fullName:'QA',role:'admin',modules:['full_suite'],subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}});
10 + const rows=[{collection:'companies',id:'CO',data:{name:'شرکت آزمون'}},{collection:'settings',id:'main',data:{default_company_id:'CO',invoice_kind:kind,currency_mode:'rial',user_display_name:'QA',professional_role:'accountant'}}];
11 + sb.from=()=>({select:()=>({order(){return this},async range(){return {data:rows,error:null}}})});
12 + sb.rpc=async()=>({error:null});
13 + await enterApp({id:'COMMERCE_QA'});
14 + },kind);
15 + await expect(page.locator('#auth-screen')).toBeHidden();
16 + await page.locator('.module-tab[data-module="commerce"]').click();
17 + await page.locator('#module-panel-links [data-view="view-invoices"]').click();
18 +}
19 +const sale=page=>page.locator('#view-invoices .finora-invoice-type select');
20 +const purchase=page=>page.locator('#view-purchases .finora-invoice-type select');
21 +test('commerce menu routes offer only matching document families and retain unsaved sale fields',async({page})=>{
22 + await openCommerce(page);
23 + await expect(sale(page).locator('option')).toHaveText(['فروش','پیش‌فاکتور فروش','صورت‌وضعیت فروش']);
24 + await page.locator('#invoice-number').fill('UNSAVED-QA');
25 + await sale(page).selectOption('pre_invoice');
26 + await expect(page.locator('#invoice-kind')).toHaveValue('pre_invoice');
27 + await page.locator('#module-panel-links [data-view="view-purchases"]').click();
28 + await expect(purchase(page).locator('option')).toHaveText(['خرید']);
29 + await expect(purchase(page)).toHaveValue('purchase');
30 + await page.locator('#module-panel-links [data-view="view-invoices"]').click();
31 + await expect(sale(page)).toHaveValue('pre_invoice');
32 + await expect(page.locator('#invoice-number')).toHaveValue('UNSAVED-QA');
33 + await expect(page.locator('#workspace-title')).toHaveText('فاکتور فروش');
34 +});
35 +test('sales document selector reflects restored defaults and existing kind changes',async({page})=>{
36 + await openCommerce(page,'contract_statement');
37 + await expect(sale(page)).toHaveValue('contract_statement');
38 + // Existing edit/default/draft restoration paths all invoke this canonical form handler.
39 + await page.evaluate(()=>{document.getElementById('invoice-kind').value='formal';handleInvoiceKindChange()});
40 + await expect(sale(page)).toHaveValue('sale');
41 + await expect(page.locator('#invoice-kind')).toHaveValue('formal');
42 + await sale(page).selectOption('pre_invoice');
43 + await expect(page.locator('#invoice-kind')).toHaveValue('pre_invoice');
44 + await expect(page.locator('#box-invoice-contract-number')).toBeHidden();
45 + await sale(page).selectOption('contract_statement');
46 + await expect(page.locator('#invoice-kind')).toHaveValue('contract_statement');
47 + await expect(page.locator('#box-invoice-contract-number')).toBeVisible();
48 +});
scripts/commercial-rnd-check.mjs
+1 -1
@@ -16,6 +16,6 @@ ok(commerce.includes("company.accountingTemplate=''")&&commerce.includes("compan
16 ok(html.includes('js/commercial-rnd.js'),'Commerce slice must be loaded.');
17 ok(!html.includes('🧾 فاکتور فروش</button>')&&!html.includes('🛒 فاکتور خرید</button>'),'Invoice form must not duplicate sale/purchase shortcut buttons beside the document heading.');
18 ok(!fs.readFileSync('js/ux-hardening-r2.js','utf8').includes('finora-commerce-toolbar'),'Invoice workspace must not duplicate sale/purchase/pre-invoice workflow buttons above the form.');
19 -ok(['sale','purchase','pre_invoice','contract_statement'].every(v=>commerce.includes('<option value="'+v+'"')),'Unified document selector must contain sale, purchase, sales pre-invoice and sales progress statement.');
19 +ok(['sale','purchase','pre_invoice','contract_statement'].every(v=>commerce.includes('<option value="'+v+'"')),'Context-specific document selectors must retain existing purchase and sales document types.');
20 ok(purchase.includes("jePostSourceRecord('purchase',record)"),'Purchase posting must remain automatic.');
21 console.log('Commercial R&D invariants passed.');
scripts/dom-smoke.spec.js
+3 -2
@@ -120,11 +120,12 @@ test('Phase A visible licensed launcher preserves extra workspaces without addin
120 }
121 await page.evaluate(()=>{switchView('view-dashboard');currentUser.modules=['accounting'];currentUser.commercialModules=['accounting'];applyLicensedModuleUI()});
122 await toggle.click();
123 - await expect(grid.locator('button')).toHaveCount(1);
123 + await expect(grid.locator('button')).toHaveCount(2);
124 + await expect(grid).toContainText('سازمان');
125 await expect(grid).toContainText('حسابداری');
126 for(const label of ['دارایی ثابت','منابع انسانی و حقوق','اتوماسیون اداری','درخواست‌ها و فرایندها','CRM','ناوگان','MRP'])await expect(grid).not.toContainText(label);
127 expect(await page.evaluate(()=>({office:canAccessFinoraModule('office'),workflow:canAccessFinoraModule('requests')}))).toEqual({office:false,workflow:false});
127 - await grid.getByRole('button',{name:/حسابداری/}).click();
128 + await grid.getByRole('button',{name:/حسابداری/}).filter({hasNotText:'سازمان'}).click();
129 await expect(page.locator('#view-accounting-foundation')).toHaveClass(/active/);
130 expect(errors).toEqual([]);
131 });
scripts/enterprise-org-ux-check.mjs
+3 -1
@@ -13,7 +13,9 @@ need(ui,/renderEnterpriseOrganizationTree/i,'typed tree renderer');
13 need(ui,/refreshEnterpriseOrganizationDashboard/i,'capacity dashboard');
14 need(ui,/org-unit-kind/i,'unit kind editor');
15 const shell=fs.readFileSync('js/organization-shell.js','utf8');
16 -need(shell,/finoraCanManageOrganization/i,'core-admin shell gate');
16 +need(shell,/refreshFinoraOrganizationAccessButton/i,'refreshed organization shell gate');
17 +const rbac=fs.readFileSync('js/organization-rbac.js','utf8');
18 +need(rbac,/finoraCanOpenOrganizationAccess[\s\S]*currentUser\?\.organizationId[\s\S]*finoraCanManageOrganization/i,'organization identity and capability gate');
19 const boot=fs.readFileSync('js/bootstrap.js','utf8');
20 need(boot,/organization-enterprise-ux\.js/i,'ELI-4 runtime bootstrap');
21 console.log('ELI-4 enterprise organization UX contract: PASS');
scripts/login-connectivity-check.mjs
+1 -1
@@ -9,7 +9,7 @@ assert(html.includes('id="auth-connectivity-result" aria-live="polite"'),'Diagno
9 assert(html.includes('js/login-connectivity.js?v=20261026-preflight-compare-v5'),'Missing versioned script');
10 assert(html.includes('js/core.js?v=20261025-password-recovery-v1'),'Production login controls must use new cache version');
11 assert(html.indexOf('<script src="js/login-connectivity.js?v=20261026-preflight-compare-v5"')<html.indexOf('<script src="js/core.js?v=20261025-password-recovery-v1"'),'Connectivity handler script must execute before core (not just preload)');
12 -assert(html.includes('js/bootstrap.js?v=20261030-navigation-recovery-v1'),'Parallel bootstrap must also be cache-busted');
12 +assert(html.includes('js/bootstrap.js?v=20261031-workspace-recovery-v1'),'Parallel bootstrap must also be cache-busted');
13 assert(html.includes('id="auth-login-button"')&&html.includes('id="auth-login-status"'),'Login control requires real readiness/progress feedback');
14 assert(core.includes('window.FinoraAppAssetsReady'),'Authenticated workspace must remain gated until all module scripts settle');
15 assert(core.includes('window.FinoraOrganizationContextReady')&&core.includes('organizationAccount'),'Profile and license lookup must wait for the organization account adapter');
scripts/slice-b-rbac-check.mjs
+1 -1
@@ -11,6 +11,6 @@ if(/user_metadata/i.test(sql))throw new Error('authorization must not trust user
11 const org=fs.readFileSync(path.join(root,'js','organization-rbac.js'),'utf8'),office=fs.readFileSync(path.join(root,'js','office-rbac.js'),'utf8'),shell=fs.readFileSync(path.join(root,'js','organization-shell.js'),'utf8'),boot=fs.readFileSync(path.join(root,'js','bootstrap.js'),'utf8');
12 for(const token of ['organizationId','modulePermissions','commercialModules','hasFinoraCapability','p_organization_id:currentUser.organizationId','organization_set_member_permission','organization_add_member'])if(!org.includes(token))throw new Error(`missing organization client invariant: ${token}`);
13 for(const token of ["cap('configure')","cap('create')","cap('register')","cap('refer')",'office_refer_correspondence',"currentUser.organizationId+'/'+currentUser.id+'/'+correspondenceId"])if(!office.includes(token))throw new Error(`missing office capability invariant: ${token}`);
14 -for(const token of ['showFinoraOrganizationSwitcher','finora-org-switch-btn','showOrganizationAccessManager'])if(!shell.includes(token))throw new Error(`missing organization shell invariant: ${token}`);
14 +for(const token of ['showFinoraOrganizationSwitcher','finora-org-switch-btn','refreshFinoraOrganizationAccessButton'])if(!shell.includes(token))throw new Error(`missing organization shell invariant: ${token}`);
15 if(!boot.includes('organization-rbac.js')||!boot.includes('office-rbac.js')||!boot.includes('organization-shell.js'))throw new Error('Slice B extensions are not loaded by bootstrap');
16 console.log(`Slice B tenant/RBAC invariants PASS (${requiredFiles.join(', ')})`);
scripts/workspace-access.spec.js new
+83
@@ -0,0 +1,83 @@
1 +const {test,expect}=require('@playwright/test');
2 +test.setTimeout(15000);
3 +const BASE=process.env.FINORA_TEST_BASE_URL||'http://127.0.0.1:4173/index.html';
4 +async function fixture(page){
5 + await page.route(/https:\/\/[^/]*supabase\.co\//,r=>r.abort());
6 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
7 + await page.waitForFunction(()=>window.FinoraStartupStatus?.extensionsReady&&window.FinoraStartupStatus?.authChecked);
8 + await page.evaluate(()=>{
9 + currentUser={id:'QA_OWNER',role:'user',isOrganizationOwner:true,organizationId:'QA_ORG',organizationName:'سازمان آزمایشی',organizations:[],modules:['full_suite'],commercialModules:['full_suite'],modulePermissions:[],maxUsers:5,maxCompanies:3,subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}};
10 + COLLS.forEach(k=>datastore[k]=[]);saveDatastore=()=>{};
11 + sb.from=table=>({select(){return this},eq(){return this},in(){return this},order(){return this},then(resolve,reject){return Promise.resolve({data:table==='organization_members'?[{id:'QA_MEMBER',user_id:'QA_OWNER',status:'active',is_owner:true}]:[],error:null}).then(resolve,reject)}});
12 + sb.rpc=async(name)=>({data:name==='organization_capacity_summary'?{active_users:1,max_users:5,company_count:1,max_companies:3,modules:['full_suite'],status:'active'}:[],error:null});
13 + document.querySelector('#auth-screen').style.display='none';document.body.classList.remove('shell-panel-collapsed');refreshAllSurfaces();
14 + });
15 +}
16 +test('Settings exposes existing organization members, invitations and capacities',async({page})=>{
17 + await fixture(page);await page.locator('#module-rail [data-module="settings"]').click();
18 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
19 + const modal=page.locator('#finora-org-access-modal.active');
20 + await expect(modal).toBeVisible();await expect(modal.locator('#org-invitation-card')).toContainText('دعوت کاربر جدید');
21 + await expect(modal.locator('#enterprise-org-dashboard')).toContainText('شرکت‌های حقوقی');
22 + await expect(modal.locator('#org-seat-summary')).toContainText('۵');
23 + await modal.getByRole('button',{name:'بستن',exact:true}).click();await expect(modal).toHaveCount(0);
24 +});
25 +test('Settings module chooser reaches organization and requests through real clicks',async({page})=>{
26 + await fixture(page);
27 + for(const [label,view] of [['منابع انسانی و حقوق','view-enterprise'],['درخواست‌ها و فرایندها','view-requests']]){
28 + await page.locator('#module-rail [data-module="settings"]').click();
29 + await page.locator('#module-panel-links [data-task="module-launcher"]').click();
30 + await page.locator('#finora-launcher-grid').getByRole('button',{name:new RegExp(label)}).click();
31 + await expect(page.locator('#'+view)).toHaveClass(/active/);
32 + }
33 +});
34 +test('permission refresh removes organization management entry and stale footer access',async({page})=>{
35 + await fixture(page);await page.locator('#module-rail [data-module="settings"]').click();
36 + await expect(page.locator('#finora-org-access-btn')).toBeVisible();
37 + await page.evaluate(()=>{currentUser.isOrganizationOwner=false;currentUser.modules=['accounting'];currentUser.commercialModules=['accounting'];refreshAllSurfaces()});
38 + await page.locator('#module-rail [data-module="settings"]').click();
39 + await expect(page.locator('#module-panel-links [data-task="organization-access"]')).toHaveCount(0);
40 + await expect(page.locator('#finora-org-access-btn')).toBeHidden();
41 + await page.locator('#module-panel-links [data-task="module-launcher"]').click();
42 + await expect(page.locator('#finora-launcher-grid')).not.toContainText('درخواست‌ها');
43 + await expect(page.locator('#finora-launcher-grid')).not.toContainText('منابع انسانی');
44 + await page.evaluate(()=>{window.__deniedQueries=0;sb.from=()=>{window.__deniedQueries++;throw Error('unexpected')};navigateShell('settings','view-settings','organization-access')});
45 + expect(await page.evaluate(()=>window.__deniedQueries)).toBe(0);
46 +});
47 +test('global admin without organization authority cannot open organization manager',async({page})=>{
48 + await fixture(page);
49 + await page.evaluate(()=>{currentUser.role='admin';currentUser.isOrganizationOwner=false;currentUser.organizationId=null;refreshAllSurfaces();window.__queries=0;sb.from=()=>{window.__queries++;throw Error('unexpected query')};window.alert=()=>{}});
50 + await page.locator('#module-rail [data-module="settings"]').click();
51 + await expect(page.locator('#module-panel-links [data-view="view-admin"]')).toHaveCount(1);
52 + await expect(page.locator('#module-panel-links [data-task="organization-access"]')).toHaveCount(0);
53 + await page.evaluate(()=>showOrganizationAccessManager());
54 + expect(await page.evaluate(()=>window.__queries)).toBe(0);
55 +});
56 +test('delegated organization configure manager retains invitations while module-only manager does not',async({page})=>{
57 + await fixture(page);
58 + await page.evaluate(()=>{currentUser.isOrganizationOwner=false;currentUser.modulePermissions=[{module_key:'core',capabilities:['configure']}];refreshAllSurfaces()});
59 + await page.locator('#module-rail [data-module="settings"]').click();
60 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
61 + await expect(page.locator('#org-invitation-card')).toBeAttached();
62 + await page.locator('#finora-org-access-modal').getByRole('button',{name:'بستن',exact:true}).click();
63 + await page.evaluate(()=>{currentUser.modulePermissions=[{module_key:'office_automation',capabilities:['configure']}];refreshAllSurfaces()});
64 + await page.locator('#module-rail [data-module="settings"]').click();
65 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
66 + await expect(page.locator('#finora-org-access-modal.active')).toBeVisible();
67 + await expect(page.locator('#org-invitation-card')).toHaveCount(0);
68 + await expect(page.locator('#enterprise-org-dashboard')).toHaveCount(0);
69 + await expect(page.locator('#org-member-email')).toHaveCount(0);
70 +});
71 +test('accounting and treasury licenses retain their organization workspace without HR access',async({page})=>{
72 + await fixture(page);
73 + for(const [module,task] of [['accounting','costing'],['treasury','treasury']]){
74 + await page.evaluate(module=>{currentUser.modules=[module];currentUser.commercialModules=[module];refreshAllSurfaces()},module);
75 + await page.locator('#module-rail [data-module="settings"]').click();
76 + await page.locator('#module-panel-links [data-task="module-launcher"]').click();
77 + await page.locator('#finora-launcher-grid').getByRole('button',{name:/سازمان/}).click();
78 + await expect(page.locator('#view-enterprise')).toHaveClass(/active/);
79 + await expect(page.locator('#module-panel-links .module-link.active')).toHaveAttribute('data-task',task);
80 + await expect(page.locator('#module-panel-links [data-task="employees"]')).toHaveCount(0);
81 + await expect(page.locator('#module-panel-links [data-task="group"]')).toHaveCount(0);
82 + }
83 +});