سامانه صدور فاکتور و حسابداری
fix/wave2-request-input-integrity
audit-remediation-wave3-4-20261002
audit-remediation-wave3-verify-20261002
audit-remediation-wave4-20261002
audit-remediation-wave4b-20261002
audit-remediation-wave5a-identity-20261002
audit-remediation-wave5b-offboarding-20261002
audit-remediation-wave5c-authorization-20261002
audit-security-intent-review-20261002
audit/finora-financial-core-20261115
audit/finora-master-prompt-phase0-20261016
audit/finora-stage3-legacy-source-readonly-20261023
audit/full-controls-20261030
audit/owner-live-state-reconcile-20261012
audit/owner-review-20261007
audit/phase1-live-permissions-readonly-20261013
audit/reconcile-live-state-20261006
audit/reconcile-state-20261002
audit/wp0-hardening-baseline-20261102
branding-login-favicon-20261002
c8-workflow-task1
c8-workflow-task2
c8-workflow-task3
chore/wave0-pages-gate-closeout
claude-code-plugins-setup
design/finora-c01-authoritative-source-draft-20261124
docs-wave4b-verified-20261002
docs/active-company-invoice-release-evidence-20261014
docs/agent-operating-model-20261114
docs/chart-taxpayer-release-evidence-20261004
docs/cloud-only-agent-orchestration-20261115
docs/confirm-finora-product-charter-20261115
docs/continuation-20261030
docs/d4a-verified
docs/external-work-review-20261121
docs/finora-audit-continuity-20261014
docs/finora-backup-merge-evidence-20261014
docs/finora-ci-reconciliation-20261122
docs/finora-codex-master-prompt
docs/finora-eight-phase-plan-20261011
docs/finora-f002-live-buyer-filter-verified-20261015
docs/finora-license-race-release-evidence-20261014
docs/finora-license-rollout-acceptance-20261015
docs/finora-phase0-repeat-and-pages-nav-verified-20261015
docs/finora-phase0-repeat-evidence-20261015
docs/finora-selectors-release-and-fixture-qa-20261015
docs/finora-stagea-pr240-ci-triage-20261123
docs/finora-test-license-live-pass-20261015
docs/finora-v2-m01-coverage-20261124
docs/handoff-charter-v2-20261124
docs/invoice-product-search-release-20261011
docs/invoice-workspace-release-20261007
docs/phase-status-20261031
docs/phase0-acceptance-release-evidence-20261012
docs/phase0-admin-provision-release-evidence-20261012
docs/phase0-core-bundle-owner-login-open-20261013
docs/phase0-duplicate-js-release-20261016
docs/phase0-f001-auth-rest-shared-timeout-20261013
docs/phase0-f001-owner-login-observed-20261013
docs/phase0-f001-second-device-fail-40s-20261013
docs/phase0-f003-release-verification-20261011
docs/phase0-f004-print-release-evidence-20261012
docs/phase0-f004-watermark-release-evidence-20261012
docs/phase0-f005-large-selector-release-20261012
docs/phase0-f005-release-evidence-20261012
docs/phase0-f006-dark-release-evidence-20261012
docs/phase0-f008-final-pr-closure-evidence-20261012
docs/phase0-f008-reconcile-stale-prs-20261012
docs/phase0-f107-production-evidence-20261012
docs/phase0-kavenegar-otp-preflight-release-20261012
docs/phase0-login-release-evidence-20261012
docs/phase0-login-rest-bootstrap-stage-release-20261012
docs/phase0-owner-app-assets-bundle-release-20261013
docs/phase0-owner-login-csp-release-20261012
docs/phase0-reconcile-postmerge-evidence-20261012
docs/phase0-site-probe-release-evidence-20261012
docs/phase0-startup-release-evidence-20261012
docs/phase3-treasury-release-evidence-20261014
docs/pilot-posted-correction-release-evidence-20261014
docs/pilot-purchase-correction-release-evidence-20261014
docs/print-persian-release-verification-20261011
docs/qa-ci-triage-218-20261122
docs/real-account-qa-20261030
docs/release-state-20261007
docs/seamless-amendment-release-20261014
docs/seamless-document-correction-release-20261014
docs/settings-login-release-20261025
docs/stripe-qa-deployment-evidence-20261011
docs/ux-f2-release-evidence-20261011
docs/ux-f2-release-verification-20261011
docs/wave0-closeout
docs/wave2-closeout
exec-phase1-architecture
exec-phase1-implementation
exec-phase1-qa
exec-phase1-security-release
exec-phase1-ux
feat/accounting-document-draft-approval-20261011
feat/accounting-document-release-candidate-20261011
feat/active-company-strict-isolation-20261014
feat/admin-provisioning-reconciled-20261011
feat/admin-secure-user-provisioning-20261011
feat/admin-user-provisioning-merged-20261011
feat/d4a-request-work-queue
feat/document-lifecycle-atf-20261118
feat/document-lifecycle-temp-permanent-atef
feat/draft-first-attachment-lifecycle-216
feat/finora-offline-encrypted-backup-20261014
feat/finora-phase-a-navigation-20261023
feat/finora-stripe-sandbox-edge-gate
feat/immutable-attachment-temporary-vouchers
feat/iran-accounting-design-audit
feat/journal-document-lifecycle-20261118
feat/journal-rpc-repository-adapter-20261117
feat/office-c7-fulltext-ocr-provenance
feat/password-recovery-admin-reset-20261025
feat/pilot-expense-income-inplace-amendment-20261014
feat/pilot-journal-invoice-correction-20261014
feat/pilot-purchase-correction-20261014
feat/pilot-treasury-unallocated-correction-20261014
feat/retain-document-editor-after-save-20261014
feat/seamless-financial-document-correction-20261014
feat/slice-b-tenant-rbac
feat/stripe-sandbox-invoice-probe
feature/accounting-core-p0
feature/accounting-product-guidance
feature/admin-identity-phone-auth
feature/commercial-rnd
feature/finora-phase1a-supabase-cli-20261016
feature/finora-stage2-manual-canary-20261017
feature/finora-stage3-commercial-payload-20261023
feature/finora-stage3-enforce-invoice-rpc-20261023
feature/finora-stage3-enforce-purchase-red-20261023
feature/invoice-workspace-cleanup
feature/phase0-kavenegar-otp-preflight-20261012
feature/ux-commerce-settings-r2
fix-shell-scroll-live-cache-20261002
fix-shell-scrollbar-explicit-ownership-20261002
fix-shell-scrollbar-ownership-20261002
fix-shell-scrollbar-right-edge-20261002
fix/about-bug-report-20261114
fix/active-company-invoice-scope-20261014
fix/active-company-isolation-reconcile-20261014
fix/admin-central-password-reset-20261028
fix/auth-network-diagnostics
fix/chart-taxpayer-reference-20261003
fix/combobox-enter-reliability
fix/combobox-live-search
fix/combobox-production-cache
fix/combobox-release-asset-v2
fix/company-edit-action-20261028
fix/company-edit-pilot-delete-20261014
fix/company-form-action-state-20261014
fix/company-form-action-state-rebased-20261014
fix/contact-operational-balance-20261111
fix/dark-theme-contrast
fix/financial-lifecycle-recovery-20261124
fix/finora-accounting-test-organization-readiness-20261015
fix/finora-b01-safe-org-switch-20261124
fix/finora-b02-sync-recovery-20261124
fix/finora-b03-conflict-review-20261124
fix/finora-org-license-bootstrap-race-20261014
fix/finora-stage3-posted-source-immutable-20261023
fix/finora-v2-b03-r2-qa-20261124
fix/finora-v2-b03-r3-readonly-20261124
fix/g01-asof-financial-position-20261128
fix/invoice-product-search-rehydrate-20261011
fix/invoice-search-cache-bust
fix/issue229-linked-draft-status-20261122
fix/login-assets-retry-20261014
fix/login-inert-startup-20261110
fix/login-member-access-20261101
fix/login-resilience-20261017
fix/login-short-viewport-20261028
fix/login-startup-readiness-20261024
fix/navigation-utilities-placement-20261105
fix/office-c7-source-ref-binding
fix/office-c7-source-ref-binding-v2
fix/owner-login-network-20261026
fix/password-recovery-invalid-cancel-20261026
fix/payment-amount-format-20261111
fix/phase0-admin-provision-seat-bootstrap-20261012
fix/phase0-auth-bundled-assets-for-unstable-isp-20261013
fix/phase0-auth-handler-binding-stalled-session-20261012
fix/phase0-login-context-stage-visibility-20261012
fix/phase0-login-single-local-bundle-20261013
fix/phase0-login-site-probe-clarity-20261012
fix/phase0-login-ui-ready-20261012
fix/phase0-modal-dashboard-drill-20261011
fix/phase0-pages-blocking-core-bundles-20261013
fix/phase0-print-no-draft-watermark-20261012
fix/phase0-startup-parallel-asset-load-20261012
fix/phase3-behavioral-verification
fix/preserve-pending-edits-20261121
fix/print-persian-digit-consistency-20261011
fix/recovery-login-startup-20261027
fix/report-opening-balance-release-20261130
fix/settings-checkbox-persistence-20261024
fix/taxpayer-arithmetic-20261004
fix/ux-keyboard-search-f2-20261011
fix/wave2-request-input-integrity
hardening/c01-source-draft-20261129
hardening/global-draft-conversion-20261113
hardening/wp1-ledger-integrity-20261102
integration/finora-execution-20261124
integration/issue229-ui-qa-20261122
integration/wp1-ledger-core-20261115
integration/wp2-manual-journal-rpc-20261116
main
ops-heartbeat-v2-20261002
ops-progress-heartbeat-rule-20261002
ops/wave4-production-20261003
plan/financial-core-phase1-approval-20261016
qa/attachment-allocator-two-session-20261122
qa/draft-first-save-red-evidence-20261122
qa/finora-autopost-retry-identity-red-20261122
qa/finora-identity-rpc-security-tripwire-20261122
qa/finora-issue223-manual-kardex-browser-red-20261123
qa/finora-issue223-stock-real-jwt-20261123
qa/finora-issue238-inventory-count-browser-red-20261123
qa/finora-issue238-save-browser-red-20261122
qa/finora-login-cors-header-preflight-20261025
qa/finora-phase0-saved-session-repeat-20261015
qa/finora-phase5-posted-insert-jwt-red-20261123
qa/finora-stage3-ui-jwt-autopost-20261023
qa/finora-v2-g01-report-reconciliation-20261125
qa/free-supabase-local-wp2-20261116
qa/issue229-approval-boundary-jwt-20261122
qa/issue229-sale-save-linked-draft-red-20261122
qa/phase0-acceptance-start-20261012
qa/phase0-f005-account-project-contract-stress-20261012
qa/phase0-f005-selector-stress-20261012
qa/phase0-f006-dark-contrast-20261012
qa/post-wave4-verification-20261003
qa/posted-source-immutable-jwt-20261122
qa/pr219-wp1-disposable-dburl-proof-20261123
qa/purchase-source-jwt-20261122
qa/real-settings-acceptance-20261025
qa/recovery-mail-acceptance-20261026
qa/source-autopost-jwt-atomicity-20261122
qa/wave0-negative-gate-proof
qa/wp2-auth-tenant-e2e-20261117
qa/wp2-authorized-journal-write-20261122
qa/wp2-financial-paths-reconciliation-20261122
qa/wp3-financial-tenant-isolation-20261117
remediation/wave0-liveqa-wave1
remediation/wave2-request-integrity
staging/finora-stage22-free-20261022
state-scroll-verified-20261002
state-wave4b-production-20261002
state-wave5a-production-20261002
test/finora-accounting-boot-readiness-20261015
test/finora-f0-02-production-selectors-20261015
test/finora-pages-commerce-event-wiring-20261015
test/finora-pages-invoice-selectors-readonly-20261015
test/finora-stage3-jwt-source-post-20261023
test/phase0-invoice-fixture-bootstrap-20261016
test/phase0-invoice-persistence-20261011
test/phase0-pages-delayed-dispatcher-20261016
ux-scroll-ownership-20261002
work/finora-stage3-enforce-purchase-green-20261023
work/finora-stage3-enforce-sale-green-20261023
work/finora-stage3-payload-green-20261023
| 1 | /* Iran enterprise v2 — payroll, employee obligations, petty-cash posting, ABC/budget and group controls. */ |
| 2 | var enterpriseRenderV1=window.enterpriseRenderV1||window.enterpriseRender;window.enterpriseRenderV1=enterpriseRenderV1; |
| 3 | var IR_V2=window.IR_V2||{salaryTax1405:'IR-TAX-SALARY-1405',social:'IR-SSI-28',unemployment:'IR-UNEMPLOYMENT-5',vat1405:'IR-VAT-1405'}; |
| 4 | function entV2Rows(k,all=false){const cid=entCid();return entRows(k).filter(x=>all||x.companyId===cid)} |
| 5 | function entV2Num(v){const n=Number(String(v??'').replace(/,/g,''));return Number.isFinite(n)?Math.round(n):0} |
| 6 | function entV2Audit(action,entity,id,after){datastore.enterpriseAudit.push({id:entId('EA'),ownerUserId:currentUser.id,companyId:entCid(),action,entity,entityId:id,after:after||null,at:new Date().toISOString()})} |
| 7 | function entSalaryTax1405(x){x=Math.max(0,entV2Num(x));const b=[[400000000,0],[800000000,.10],[1000000000,.15],[1200000000,.20],[1400000000,.25],[Infinity,.30]];let p=0,t=0;for(const [c,r] of b){const q=Math.min(x,c);if(q>p)t+=(q-p)*r;if(x<=c)break;p=c}return Math.round(t)} |
| 8 | function entEnsureFinancialAccounts(){const cid=entCid(),co=getMyCompanies().find(x=>x.id===cid);if(!cid||!co?.accountingTemplate)return;const specs=[['1109','تنخواهگردان','debit','11','asset'],['1110','حسابهای فیمابین دریافتنی','debit','11','asset'],['2106','حقوق و دستمزد پرداختنی','credit','21','liability'],['2107','بیمه پرداختنی','credit','21','liability'],['2108','مالیات حقوق پرداختنی','credit','21','liability'],['2109','ذخیره مزایای پایان خدمت کارکنان','credit','21','liability'],['2110','حسابهای فیمابین پرداختنی','credit','21','liability'],['2111','تعهد مرخصی استفادهنشده','credit','21','liability'],['6110','هزینه بیمه سهم کارفرما','debit','61','expense'],['6111','هزینه مزایای پایان خدمت کارکنان','debit','61','expense'],['6112','هزینه مرخصی کارکنان','debit','61','expense']];const by=Object.fromEntries(getMyAccounts().map(a=>[a.code,a]));let ch=false;for(const [code,title,normalBalance,parentCode,accountType] of specs){if(by[code])continue;const p=by[parentCode];if(!p)continue;const a={id:afId('ACC'),ownerUserId:currentUser.id,companyId:cid,code,title,level:'detail',parentId:p.id,normalBalance,accountType,postingAllowed:true,active:true,template:'iran-enterprise-v2'};datastore.accounts.push(a);by[code]=a;ch=true}if(ch)saveDatastore()} |
| 9 | function entV2Acc(code){return getMyAccounts().find(a=>a.code===code&&a.active!==false&&a.postingAllowed)||null} |
| 10 | function entServiceYears(start,end){const p=s=>String(s||'').replace(/-/g,'/').split('/').map(Number);const a=p(start),b=p(end||getJalaliNumeric());if(a.length<3||b.length<3||a.some(Number.isNaN)||b.some(Number.isNaN))return 0;return Math.max(0,(b[0]-a[0])+(b[1]-a[1])/12+(b[2]-a[2])/365)} |
| 11 | enterpriseEndServiceEstimate=function(c){return Math.max(0,Math.round(Number(c.lastMonthlyWage||0)*entServiceYears(c.startDate,c.endDate)))}; |
| 12 | function entSavePayrollLine(){if(!requireWrite())return;const period=document.getElementById('ent2-pay-period')?.value.trim(),employeeId=document.getElementById('ent2-pay-employee')?.value,gross=entV2Num(document.getElementById('ent2-pay-gross')?.value),insuranceBase=entV2Num(document.getElementById('ent2-pay-ins')?.value),taxable=entV2Num(document.getElementById('ent2-pay-taxable')?.value);if(!period||!employeeId||gross<=0||insuranceBase<0||taxable<0)return alert('اطلاعات حقوق معتبر نیست.');let run=entV2Rows('payrollRuns').find(x=>x.period===period&&x.status==='draft');if(!run){run={id:entId('PR'),ownerUserId:currentUser.id,companyId:entCid(),period,status:'draft',ruleVersions:{salaryTax:IR_V2.salaryTax1405,social:IR_V2.social,unemployment:IR_V2.unemployment},createdAt:new Date().toISOString()};datastore.payrollRuns.push(run)}if(entV2Rows('payrollLines').some(x=>x.runId===run.id&&x.employeeId===employeeId))return alert('این کارکن در این دوره قبلاً ثبت شده است.');const employeeInsurance=Math.round(insuranceBase*.07),employerInsurance=Math.round(insuranceBase*.23),tax=period.startsWith('1405/')?entSalaryTax1405(taxable):0,net=gross-employeeInsurance-tax;if(net<0)return alert('خالص پرداختنی منفی است.');const r={id:entId('PL'),ownerUserId:currentUser.id,companyId:entCid(),runId:run.id,employeeId,gross,insuranceBase,taxable,employeeInsurance,employerInsurance,tax,net,ruleVersions:run.ruleVersions};datastore.payrollLines.push(r);entV2Audit('create','payrollLine',r.id,r);saveDatastore();enterpriseRender('payroll')} |
| 13 | function entPostPayroll(id){if(!requireWrite())return;const run=entV2Rows('payrollRuns').find(x=>x.id===id&&x.status==='draft'),ls=entV2Rows('payrollLines').filter(x=>x.runId===id);if(!run||!ls.length)return alert('دوره حقوق معتبر نیست.');entEnsureFinancialAccounts();const wage=entV2Acc('6101')||jeExpenseAccount(),insExp=entV2Acc('6110'),pay=entV2Acc('2106'),insPay=entV2Acc('2107'),taxPay=entV2Acc('2108');if(!wage||!insExp||!pay||!insPay||!taxPay)return alert('کدینگ حقوق، بیمه و مالیات کامل نیست.');const gross=ls.reduce((s,x)=>s+x.gross,0),er=ls.reduce((s,x)=>s+x.employerInsurance,0),ee=ls.reduce((s,x)=>s+x.employeeInsurance,0),tax=ls.reduce((s,x)=>s+x.tax,0),net=ls.reduce((s,x)=>s+x.net,0);try{const v=jeCreateDraft({date:run.period+'/29',description:'حقوق و دستمزد '+run.period,sourceType:'payroll_run',sourceId:run.id,lines:[{accountId:wage.id,debit:gross,credit:0,description:'حقوق ناخالص',dimensions:[]},{accountId:insExp.id,debit:er,credit:0,description:'بیمه سهم کارفرما',dimensions:[]},{accountId:pay.id,debit:0,credit:net,description:'خالص پرداختنی',dimensions:[]},{accountId:insPay.id,debit:0,credit:ee+er,description:'بیمه پرداختنی',dimensions:[]},{accountId:taxPay.id,debit:0,credit:tax,description:'مالیات حقوق پرداختنی',dimensions:[]}]});jePost(v.id);Object.assign(run,{status:'posted',accountingStatus:'posted',journalVoucherId:v.id,postedAt:new Date().toISOString()});entV2Audit('post','payrollRun',run.id,{journalVoucherId:v.id});saveDatastore();enterpriseRender('payroll')}catch(e){alert(e.message)}} |
| 14 | function entAccrueBenefit(){if(!requireWrite())return;const employeeId=document.getElementById('ent2-ben-employee')?.value,kind=document.getElementById('ent2-ben-kind')?.value,period=document.getElementById('ent2-ben-period')?.value.trim(),amount=entV2Num(document.getElementById('ent2-ben-amount')?.value),basis=document.getElementById('ent2-ben-basis')?.value.trim();if(!employeeId||!period||amount<=0||!basis)return alert('کارکن، دوره، مبلغ و مبنای برآورد الزامی است.');entEnsureFinancialAccounts();const exp=entV2Acc(kind==='end_service'?'6111':'6112'),liab=entV2Acc(kind==='end_service'?'2109':'2111');if(!exp||!liab)return alert('کدینگ تعهدات کارکنان کامل نیست.');const r={id:entId('BEN'),ownerUserId:currentUser.id,companyId:entCid(),employeeId,kind,period,amount,basis,status:'draft',ruleVersion:kind==='end_service'?'IR-LABOR-24':'IR-LABOR-66/71'};datastore.employeeBenefitAccruals.push(r);try{const v=jeCreateDraft({date:period+'/29',description:(kind==='end_service'?'برآورد مزایای پایان خدمت':'برآورد تعهد مرخصی')+' '+period,sourceType:'employee_benefit_accrual',sourceId:r.id,lines:[{accountId:exp.id,debit:amount,credit:0,description:basis,dimensions:[]},{accountId:liab.id,debit:0,credit:amount,description:basis,dimensions:[]}]});jePost(v.id);Object.assign(r,{status:'posted',accountingStatus:'posted',journalVoucherId:v.id,postedAt:new Date().toISOString()});entV2Audit('post','employeeBenefitAccrual',r.id,r);saveDatastore();enterpriseRender('benefits')}catch(e){datastore.employeeBenefitAccruals=datastore.employeeBenefitAccruals.filter(x=>x.id!==r.id);saveDatastore();alert(e.message)}} |
| 15 | function entPettyBalance(id){return entV2Rows('pettyCashTransactions').filter(x=>x.fundId===id&&x.status==='posted').reduce((s,x)=>s+(x.kind==='issue'?x.amount:-x.amount),0)} |
| 16 | function entPostPetty(){if(!requireWrite())return;const fundId=document.getElementById('ent2-pt-fund')?.value,kind=document.getElementById('ent2-pt-kind')?.value,amount=entV2Num(document.getElementById('ent2-pt-amount')?.value),date=document.getElementById('ent2-pt-date')?.value.trim()||getJalaliNumeric(),description=document.getElementById('ent2-pt-desc')?.value.trim(),fund=entV2Rows('pettyCashFunds').find(x=>x.id===fundId);if(!fund||amount<=0||!description)return alert('تنخواه، مبلغ و شرح الزامی است.');const bal=entPettyBalance(fundId);if(kind!=='issue'&&amount>bal)return alert('مانده تنخواه کافی نیست.');if(kind==='issue'&&bal+amount>Number(fund.approvedLimit||0))return alert('سقف مصوب تنخواه رعایت نشده است.');entEnsureFinancialAccounts();const cash=jeCashAccount(),petty=entV2Acc('1109'),expense=jeExpenseAccount();if(!cash||!petty||(kind==='expense'&&!expense))return alert('کدینگ صندوق/تنخواه/هزینه کامل نیست.');const r={id:entId('PT'),ownerUserId:currentUser.id,companyId:entCid(),fundId,kind,amount,date,description,status:'draft'};datastore.pettyCashTransactions.push(r);const lines=kind==='issue'?[{accountId:petty.id,debit:amount,credit:0,description,dimensions:[]},{accountId:cash.id,debit:0,credit:amount,description,dimensions:[]}]:kind==='expense'?[{accountId:expense.id,debit:amount,credit:0,description,dimensions:[]},{accountId:petty.id,debit:0,credit:amount,description,dimensions:[]}]:[{accountId:cash.id,debit:amount,credit:0,description,dimensions:[]},{accountId:petty.id,debit:0,credit:amount,description,dimensions:[]}];try{const v=jeCreateDraft({date,description:'تنخواه — '+description,sourceType:'petty_cash',sourceId:r.id,lines});jePost(v.id);Object.assign(r,{status:'posted',accountingStatus:'posted',journalVoucherId:v.id,postedAt:new Date().toISOString()});entV2Audit('post','pettyCashTransaction',r.id,r);saveDatastore();enterpriseRender('pettyops')}catch(e){datastore.pettyCashTransactions=datastore.pettyCashTransactions.filter(x=>x.id!==r.id);saveDatastore();alert(e.message)}} |
| 17 | function entSaveBudget(){if(!requireWrite())return;const period=document.getElementById('ent2-b-period')?.value.trim(),amount=entV2Num(document.getElementById('ent2-b-amount')?.value),measure=document.getElementById('ent2-b-measure')?.value.trim(),target=Number(document.getElementById('ent2-b-target')?.value||0);if(!period||amount<0)return alert('بودجه معتبر نیست.');const r={id:entId('BDG'),ownerUserId:currentUser.id,companyId:entCid(),period,amount,measure,target,method:measure?'performance':'financial',status:'approved'};datastore.budgets.push(r);entV2Audit('create','budget',r.id,r);saveDatastore();enterpriseRender('costing')} |
| 18 | function entSaveDriver(){if(!requireWrite())return;const name=document.getElementById('ent2-d-name')?.value.trim(),unit=document.getElementById('ent2-d-unit')?.value.trim(),poolCost=entV2Num(document.getElementById('ent2-d-cost')?.value),totalQty=Number(document.getElementById('ent2-d-total')?.value||0);if(!name||!unit||poolCost<0||totalQty<=0)return alert('محرک هزینه معتبر نیست.');datastore.costDrivers.push({id:entId('DRV'),ownerUserId:currentUser.id,companyId:entCid(),name,unit,poolCost,totalQty,status:'active'});saveDatastore();enterpriseRender('costing')} |
| 19 | function entAllocateABC(){if(!requireWrite())return;const driverId=document.getElementById('ent2-a-driver')?.value,objectName=document.getElementById('ent2-a-object')?.value.trim(),qty=Number(document.getElementById('ent2-a-qty')?.value||0),d=entV2Rows('costDrivers').find(x=>x.id===driverId);if(!d||!objectName||qty<0||qty>d.totalQty)return alert('تخصیص معتبر نیست.');datastore.costAllocations.push({id:entId('ALC'),ownerUserId:currentUser.id,companyId:entCid(),driverId,objectName,driverQty:qty,allocatedAmount:Math.round(d.poolCost*qty/d.totalQty),method:'ABC'});saveDatastore();enterpriseRender('costing')} |
| 20 | function entSaveIntercompany(){if(!requireWrite())return;const fromCompanyId=document.getElementById('ent2-ic-from')?.value,toCompanyId=document.getElementById('ent2-ic-to')?.value,amount=entV2Num(document.getElementById('ent2-ic-amount')?.value),reference=document.getElementById('ent2-ic-ref')?.value.trim(),date=document.getElementById('ent2-ic-date')?.value.trim()||getJalaliNumeric();if(!fromCompanyId||!toCompanyId||fromCompanyId===toCompanyId||amount<=0||!reference)return alert('فیمابین معتبر نیست.');const r={id:entId('IC'),ownerUserId:currentUser.id,companyId:entCid(),fromCompanyId,toCompanyId,amount,reference,date,status:'open'};datastore.intercompanyTransactions.push(r);entV2Audit('create','intercompanyTransaction',r.id,r);saveDatastore();enterpriseRender('group')} |
| 21 | function entMatchIntercompany(id){if(!requireWrite())return;const a=entV2Rows('intercompanyTransactions',true).find(x=>x.id===id&&x.status==='open');if(!a)return;const b=entV2Rows('intercompanyTransactions',true).find(x=>x.id!==a.id&&x.status==='open'&&x.fromCompanyId===a.toCompanyId&&x.toCompanyId===a.fromCompanyId&&x.amount===a.amount&&x.reference===a.reference);if(!b)return alert('رکورد متقابل پیدا نشد.');a.status=b.status='matched';a.matchedWith=b.id;b.matchedWith=a.id;saveDatastore();enterpriseRender('group')} |
| 22 | function entGroupRows(){const cs=getMyCompanies(),vs=(datastore.journalVouchers||[]).filter(v=>v.ownerUserId===currentUser?.id&&['posted','reversed'].includes(v.status)),ls=(datastore.journalLines||[]).filter(l=>l.ownerUserId===currentUser?.id);return cs.map(c=>{const vids=new Set(vs.filter(v=>v.companyId===c.id).map(v=>v.id)),acc=(datastore.accounts||[]).filter(a=>a.ownerUserId===currentUser?.id&&a.companyId===c.id),cashIds=new Set(acc.filter(a=>a.systemRole==='cash_default'||String(a.title||'').includes('صندوق')||String(a.title||'').includes('بانک')).map(a=>a.id)),cash=ls.filter(l=>vids.has(l.voucherId)&&cashIds.has(l.accountId)).reduce((s,l)=>s+Number(l.debit||0)-Number(l.credit||0),0),open=entV2Rows('intercompanyTransactions',true).filter(x=>x.status==='open'&&(x.fromCompanyId===c.id||x.toCompanyId===c.id)).reduce((s,x)=>s+x.amount,0);return{c,vouchers:vids.size,cash,open}})} |
| 23 | function entRenderV2(task){const r=ensureEnterpriseView(),emps=entV2Rows('employees'),eo='<option value="">— کارکن —</option>'+emps.map(x=>'<option value="'+esc(x.id)+'">'+esc(x.personnelNo+' · '+x.fullName)+'</option>').join(''),runs=entV2Rows('payrollRuns'),funds=entV2Rows('pettyCashFunds'),drivers=entV2Rows('costDrivers'),companies=getMyCompanies(),ics=entV2Rows('intercompanyTransactions',true),group=entGroupRows();let h=''; |
| 24 | if(task==='payroll')h='<div class="card"><h2>حقوق، بیمه و مالیات حقوق</h2><p class="af-hint">قواعد ۱۴۰۵ نسخهدار؛ ۷٪ سهم کارکن و ۲۳٪ هزینه کارفرما برای کارکن مشمول استاندارد. موارد خاص باید با پرونده بیمه کنترل شود.</p><div class="form-row"><input id="ent2-pay-period" class="form-control" value="'+esc(String(getJalaliNumeric()).slice(0,7))+'"><select id="ent2-pay-employee" class="form-control">'+eo+'</select><input id="ent2-pay-gross" class="form-control" placeholder="حقوق ناخالص"><input id="ent2-pay-ins" class="form-control" placeholder="مبنای بیمه"><input id="ent2-pay-taxable" class="form-control" placeholder="مشمول مالیات"></div><button class="btn" onclick="entSavePayrollLine()">افزودن ردیف</button></div><div class="card"><table><tbody>'+runs.map(x=>{const l=entV2Rows('payrollLines').filter(y=>y.runId===x.id);return'<tr><td>'+esc(x.period)+'</td><td>'+esc(x.status)+'</td><td>'+entMoney(l.reduce((s,y)=>s+y.gross,0))+'</td><td>'+(x.status==='draft'?'<button class="btn btn-inline" onclick="entPostPayroll(\''+x.id+'\')">ثبت قطعی و سند</button>':'سند '+esc(x.journalVoucherId||''))+'</td></tr>'}).join('')+'</tbody></table></div>'; |
| 25 | if(task==='benefits')h='<div class="card"><h2>تعهدات کارکنان</h2><p class="af-hint">پایانکار قانون کار با مزایای بازنشستگی استاندارد ۳۳ یکسان فرض نمیشود.</p><div class="form-row"><select id="ent2-ben-employee" class="form-control">'+eo+'</select><select id="ent2-ben-kind" class="form-control"><option value="end_service">مزایای پایان خدمت</option><option value="leave">تعهد مرخصی</option></select><input id="ent2-ben-period" class="form-control" value="'+esc(String(getJalaliNumeric()).slice(0,7))+'"><input id="ent2-ben-amount" class="form-control" placeholder="مبلغ"><input id="ent2-ben-basis" class="form-control" placeholder="مبنای برآورد"></div><button class="btn" onclick="entAccrueBenefit()">ثبت تعهد و سند</button></div>'; |
| 26 | if(task==='pettyops')h='<div class="card"><h2>عملیات تنخواه</h2><div class="form-row"><select id="ent2-pt-fund" class="form-control">'+funds.map(x=>'<option value="'+esc(x.id)+'">'+esc(x.title)+' — مانده '+entMoney(entPettyBalance(x.id))+'</option>').join('')+'</select><select id="ent2-pt-kind" class="form-control"><option value="issue">پرداخت وجه</option><option value="expense">ثبت هزینه</option><option value="return">برگشت وجه</option></select><input id="ent2-pt-amount" class="form-control" placeholder="مبلغ"><input id="ent2-pt-date" class="form-control" value="'+esc(getJalaliNumeric())+'"><input id="ent2-pt-desc" class="form-control" placeholder="شرح/مدرک"></div><button class="btn" onclick="entPostPetty()">ثبت قطعی و سند</button></div>'; |
| 27 | if(task==='costing')h='<div class="card"><h2>بودجهریزی عملکرد</h2><div class="form-row"><input id="ent2-b-period" class="form-control" placeholder="دوره"><input id="ent2-b-amount" class="form-control" placeholder="بودجه"><input id="ent2-b-measure" class="form-control" placeholder="شاخص عملکرد"><input id="ent2-b-target" class="form-control" placeholder="هدف"></div><button class="btn" onclick="entSaveBudget()">ثبت بودجه</button></div><div class="card"><h2>ABC — محرک هزینه</h2><div class="form-row"><input id="ent2-d-name" class="form-control" placeholder="محرک"><input id="ent2-d-unit" class="form-control" placeholder="واحد"><input id="ent2-d-cost" class="form-control" placeholder="هزینه مخزن"><input id="ent2-d-total" class="form-control" placeholder="مقدار کل"></div><button class="btn" onclick="entSaveDriver()">ثبت محرک</button><div class="form-row"><select id="ent2-a-driver" class="form-control">'+drivers.map(x=>'<option value="'+esc(x.id)+'">'+esc(x.name)+'</option>').join('')+'</select><input id="ent2-a-object" class="form-control" placeholder="موضوع هزینه"><input id="ent2-a-qty" class="form-control" placeholder="مصرف محرک"></div><button class="btn" onclick="entAllocateABC()">تخصیص ABC</button></div>'; |
| 28 | if(task==='group')h='<div class="card"><h2>کنترل مدیریتی گروه</h2><table><tbody>'+group.map(x=>'<tr><td>'+esc(x.c.name)+'</td><td>اسناد '+x.vouchers+'</td><td>نقد '+entMoney(x.cash)+'</td><td>فیمابین باز '+entMoney(x.open)+'</td></tr>').join('')+'</tbody></table><p class="af-hint">این کنترل مدیریتی است، نه صورت مالی تلفیقی استاندارد ۳۹؛ تلفیق قانونی به mapping، حذف درونگروهی، NCI، یکنواختی رویه/دوره و ترجمه ارز نیاز دارد.</p></div><div class="card"><h2>فیمابین</h2><div class="form-row"><select id="ent2-ic-from" class="form-control">'+companies.map(x=>'<option value="'+esc(x.id)+'">'+esc(x.name)+'</option>').join('')+'</select><select id="ent2-ic-to" class="form-control">'+companies.map(x=>'<option value="'+esc(x.id)+'">'+esc(x.name)+'</option>').join('')+'</select><input id="ent2-ic-amount" class="form-control" placeholder="مبلغ"><input id="ent2-ic-date" class="form-control" value="'+esc(getJalaliNumeric())+'"><input id="ent2-ic-ref" class="form-control" placeholder="مرجع مشترک"></div><button class="btn" onclick="entSaveIntercompany()">ثبت</button><table><tbody>'+ics.map(x=>'<tr><td>'+esc(x.reference)+'</td><td>'+entMoney(x.amount)+'</td><td>'+esc(x.status)+'</td><td>'+(x.status==='open'?'<button class="btn btn-inline" onclick="entMatchIntercompany(\''+x.id+'\')">تطبیق</button>':'—')+'</td></tr>').join('')+'</tbody></table></div>'; |
| 29 | r.innerHTML='<div class="af-head"><div><h1>ERP سازمانی ایران</h1><p>کنترلهای مالی و عملیاتی سازمان</p></div></div>'+h |
| 30 | } |
| 31 | window.enterpriseRender=function(task='employees'){return ['payroll','benefits','pettyops','costing','group'].includes(task)?entRenderV2(task):enterpriseRenderV1(task)}; |