Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

feat: add phase 4 operations controls and enterprise rtl ui

Davood Mehraban committed Oct 5, 2026 at 16:47 UTC 4d282f8ff68c4d0f27fb7f800ecb460780c2bbfd
13 files changed +21 -4
src/app/globals.css
+1 -1
@@ -1 +1 @@
1 -*{box-sizing:border-box}body{margin:0;background:#f4f7f8;color:#14252b;font-family:Tahoma,Arial,sans-serif}header{height:72px;background:#fff;border-bottom:1px solid #dce5e8;display:flex;align-items:center;justify-content:space-between;padding:0 32px}header strong{font-size:22px}header span{color:#60737a}nav{display:flex;gap:10px;padding:12px 32px;background:#fff;border-bottom:1px solid #e2e9eb}nav a{color:#264b56;text-decoration:none;padding:8px 12px;border-radius:8px}nav a:focus-visible{outline:3px solid currentColor;outline-offset:2px}main{max-width:1180px;margin:auto;padding:32px}.hero{background:#173d48;color:white;padding:30px;border-radius:18px}.hero h1{margin:6px 0 8px;font-size:34px}.eyebrow{margin:0;opacity:.78}.grid{display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin:22px 0}.grid article,.panel{background:white;border:1px solid #dce5e8;border-radius:14px;padding:20px}.grid article{display:grid;gap:9px}.grid b{font-size:30px;font-variant-numeric:tabular-nums}.grid small{color:#64777d}.panel{margin:14px 0}.panel h2{margin-top:0}@media(max-width:760px){.grid{grid-template-columns:1fr 1fr}nav{overflow:auto}main{padding:18px}}@media(max-width:460px){.grid{grid-template-columns:1fr}}
\ No newline at end of file
1 +:root{font-family:Tahoma,Arial,sans-serif;background:#f4f6f8;color:#17212b}*{box-sizing:border-box}body{margin:0}.shell{min-height:100vh;display:grid;grid-template-columns:240px 1fr}aside{background:#101923;color:#eef4f7;padding:24px 16px}.brand{font-size:22px;font-weight:800;margin-bottom:30px}nav{display:grid;gap:7px}nav a{color:#c9d3dc;text-decoration:none;padding:11px 12px;border-radius:8px}nav a:first-child,nav a:hover{background:#243342;color:white}.workspace{min-width:0}header{height:64px;background:white;border-bottom:1px solid #dde3e8;display:flex;align-items:center;justify-content:space-between;padding:0 28px}.health{font-size:13px;border:1px solid #cfd8df;padding:7px 10px;border-radius:20px}main{padding:28px;max-width:1400px;margin:auto}.hero{display:flex;justify-content:space-between;gap:24px;align-items:center;margin-bottom:24px}.hero h1{margin:4px 0;font-size:28px}.hero p{margin:5px 0;color:#5b6874}.eyebrow{font-size:11px;letter-spacing:1.4px}.danger{background:#8d1b24;color:white;border:0;border-radius:8px;padding:12px 16px;font-weight:700}.cards{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-bottom:14px}.cards article,.panel{background:white;border:1px solid #dde3e8;border-radius:10px;padding:18px}.cards span{display:block;color:#65727d;font-size:13px;margin-bottom:10px}.cards strong{font-size:21px}.grid{display:grid;grid-template-columns:2fr 1fr;gap:14px;margin-bottom:14px}.panel h2{font-size:16px;margin:0 0 16px}table{width:100%;border-collapse:collapse}th,td{text-align:right;padding:12px;border-bottom:1px solid #edf0f2;font-size:13px}.status{list-style:none;padding:0;margin:0}.status li{display:flex;justify-content:space-between;padding:12px 0;border-bottom:1px solid #edf0f2}.status span{font-size:12px}.alert{display:flex;justify-content:space-between;gap:20px;background:#fff7e8;border:1px solid #ead7ad;padding:14px;border-radius:8px}.alert span{color:#665b48}@media(max-width:900px){.shell{grid-template-columns:1fr}aside{display:none}.cards{grid-template-columns:1fr 1fr}.grid{grid-template-columns:1fr}}@media(max-width:560px){main{padding:16px}.cards{grid-template-columns:1fr}.hero{align-items:flex-start;flex-direction:column}.alert{flex-direction:column}}
src/app/layout.tsx
+3 -2
@@ -1,2 +1,3 @@
1 -import './globals.css';
2 -export default function RootLayout({children}:{children:React.ReactNode}){return <html lang="fa" dir="rtl"><body><header><strong>TreasuryFlow</strong><span>?????????? ? ?????? ?????</span></header><nav aria-label="?????? ????"><a href="#dispatch">????? ?????</a><a href="#statements">???????? ????</a><a href="#reconcile">?????</a><a href="#exceptions">?????????</a></nav>{children}</body></html>}
1 +import './globals.css';
2 +const nav=['داشبورد عملیات','پرداخت‌ها','تأییدها','بانک و تطبیق','هشدارها','گزارش‌ها','مرکز سلامت','رویدادهای حسابرسی'];
3 +export default function RootLayout({children}:{children:React.ReactNode}){return <html lang="fa" dir="rtl"><body><div className="shell"><aside aria-label="ناوبری اصلی"><div className="brand">TreasuryFlow</div><nav>{nav.map(x=><a key={x} href={'#'+x}>{x}</a>)}</nav></aside><div className="workspace"><header><strong>مرکز عملیات خزانه‌داری</strong><span className="health">سامانه پایدار</span></header>{children}</div></div></body></html>}
src/app/page.tsx
+2 -1
@@ -1 +1,2 @@
1 -const cards=[['????? ?????','?','????? ?????'],['????????','?','?? ?????? ????'],['????? ??????','?','?????? ?????????'],['??????? ?????','?','???? ???']];export default function Home(){return <main><section className="hero"><p className="eyebrow">???? ?????? ?????</p><h1>???? ? ???????????</h1><p>????? ??? ? ??????????? ????????? ?????? ???????? ? ????? ?????????.</p></section><section className="grid" aria-label="????? ??????">{cards.map(([t,n,s])=><article key={t}><span>{t}</span><b>{n}</b><small>{s}</small></article>)}</section><section className="panel" id="dispatch"><h2>?? ????? ?? ????</h2><p>????? ?????? ???? ??????? ?????? ?????? ????? ??????? ? ???????? ?? ????? ???? ??????.</p></section><section className="panel" id="reconcile"><h2>????? ?????</h2><p>????? ???? ?? ???? ????? ???? ? ???? ????? ??????? ????????? ???? ???? ????? ?????? ????? ????????.</p></section><section className="panel" id="exceptions"><h2>????????? ? ?????????</h2><p>UNKNOWN? ????? ???? ?????? ????? ??????? ? ????? ????? ?? ?? ????? ????? ??? ???????.</p></section></main>}
1 +const cards=[['پرداخت‌های امروز','۱۲۴'],['در انتظار تأیید','۱۸'],['نیازمند بررسی','۳'],['مبلغ تسویه‌شده','۸۴٬۵۰۰٬۰۰۰٬۰۰۰ ریال']];
2 +export default function Home(){return <main><section className="hero"><div><p className="eyebrow">OPERATIONS CONTROL CENTER</p><h1>داشبورد عملیات خزانه‌داری</h1><p>نمای یکپارچه پرداخت‌ها، تطبیق بانکی، سلامت سرویس‌ها و رخدادهای نیازمند اقدام.</p></div><button className="danger">توقف اضطراری ارسال</button></section><section className="cards" aria-label="شاخص‌های عملیاتی">{cards.map(([k,v])=><article key={k}><span>{k}</span><strong>{v}</strong></article>)}</section><section className="grid"><article className="panel"><h2>صف‌های نیازمند اقدام</h2><table><thead><tr><th>وضعیت</th><th>تعداد</th><th>اقدام</th></tr></thead><tbody><tr><td>UNKNOWN</td><td>۲</td><td>بررسی نتیجه بانک</td></tr><tr><td>نیازمند تطبیق</td><td>۳</td><td>بازبینی مغایرت</td></tr><tr><td>در انتظار تأیید</td><td>۱۸</td><td>صف Checker</td></tr></tbody></table></article><article className="panel"><h2>مرکز سلامت</h2><ul className="status"><li><b>هسته خزانه‌داری</b><span>سالم</span></li><li><b>موتور تطبیق</b><span>سالم</span></li><li><b>درگاه بانکی آزمایشی</b><span>سالم</span></li></ul></article></section><section className="panel"><h2>هشدارهای عملیاتی</h2><div className="alert"><strong>۲ پرداخت با نتیجه نامشخص</strong><span>ارسال مجدد خودکار غیرفعال است؛ بررسی دستی الزامی است.</span></div></section></main>}
src/domain/operations/alerts.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest'; import {deriveAlerts} from './alerts';
2 +describe('operational alerts',()=>{it('derives deterministic unique alerts',()=>{const a=deriveAlerts({unknown:2,needsReview:1,health:'DEGRADED',queueDepth:101});expect(a.map(x=>x.code)).toEqual(['BANK_HEALTH_DEGRADED','UNKNOWN_PAYMENTS','RECONCILIATION_REVIEW','QUEUE_BACKLOG']);expect(new Set(a.map(x=>x.code)).size).toBe(a.length)});it('returns none when healthy',()=>expect(deriveAlerts({unknown:0,needsReview:0,health:'HEALTHY',queueDepth:3})).toEqual([]))});
src/domain/operations/alerts.ts new
+1
@@ -0,0 +1 @@
1 +export type Alert={code:string;severity:'HIGH'|'MEDIUM';message:string}; export function deriveAlerts(x:{unknown:number;needsReview:number;health:string;queueDepth:number}):Alert[]{const a:Alert[]=[];if(x.health!=='HEALTHY')a.push({code:'BANK_HEALTH_DEGRADED',severity:'HIGH',message:'Bank adapter health is degraded'});if(x.unknown>0)a.push({code:'UNKNOWN_PAYMENTS',severity:'HIGH',message:`${x.unknown} payments have unknown outcome`});if(x.needsReview>0)a.push({code:'RECONCILIATION_REVIEW',severity:'MEDIUM',message:`${x.needsReview} items need review`});if(x.queueDepth>=100)a.push({code:'QUEUE_BACKLOG',severity:'MEDIUM',message:`Queue depth ${x.queueDepth}`});return a}
src/domain/operations/audit-explorer.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest'; import {filterAudit} from './audit-explorer';
2 +describe('audit explorer',()=>{const e=[{tenantId:'t1',seq:2,actor:'u2',action:'APPROVE',entity:'p1',at:20},{tenantId:'t2',seq:1,actor:'u1',action:'CREATE',entity:'p2',at:10},{tenantId:'t1',seq:1,actor:'u1',action:'CREATE',entity:'p1',at:10}];it('never leaks tenants and preserves sequence',()=>expect(filterAudit('t1',e,{}).map(x=>x.seq)).toEqual([1,2]));it('filters actor/action/entity/time',()=>expect(filterAudit('t1',e,{actor:'u2',action:'APPROVE',entity:'p1',from:15,to:25})).toHaveLength(1))});
src/domain/operations/audit-explorer.ts new
+1
@@ -0,0 +1 @@
1 +export type AuditItem={tenantId:string;seq:number;actor:string;action:string;entity:string;at:number}; export type AuditFilter={actor?:string;action?:string;entity?:string;from?:number;to?:number}; export function filterAudit(t:string,e:AuditItem[],f:AuditFilter){return e.filter(x=>x.tenantId===t&&(!f.actor||x.actor===f.actor)&&(!f.action||x.action===f.action)&&(!f.entity||x.entity===f.entity)&&(f.from===undefined||x.at>=f.from)&&(f.to===undefined||x.at<=f.to)).sort((a,b)=>a.seq-b.seq)}
src/domain/operations/dashboard.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest'; import {dashboard} from './dashboard';
2 +describe('operations dashboard',()=>{it('aggregates tenant queues only',()=>{const r=dashboard('t1',[{tenantId:'t1',state:'UNKNOWN',amountIrr:100},{tenantId:'t1',state:'SETTLED',amountIrr:200},{tenantId:'t2',state:'UNKNOWN',amountIrr:999}]);expect(r).toEqual({total:2,totalIrr:300,unknown:1,settled:1,needsReview:0})})});
src/domain/operations/dashboard.ts new
+1
@@ -0,0 +1 @@
1 +export type OperationalPayment={tenantId:string;state:string;amountIrr:number}; export function dashboard(tenantId:string,rows:OperationalPayment[]){const own=rows.filter(x=>x.tenantId===tenantId);return{total:own.length,totalIrr:own.reduce((s,x)=>s+x.amountIrr,0),unknown:own.filter(x=>x.state==='UNKNOWN').length,settled:own.filter(x=>x.state==='SETTLED').length,needsReview:own.filter(x=>x.state==='NEEDS_REVIEW').length}}
src/domain/operations/health.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest'; import {evaluateHealth,EmergencyStop} from './health';
2 +describe('health and emergency stop',()=>{it('marks stale signal degraded',()=>expect(evaluateHealth({lastSeenMs:1000,nowMs:7001,maxAgeMs:5000})).toBe('DEGRADED'));it('blocks dispatch while stop enabled and is reversible',()=>{const s=new EmergencyStop();expect(s.canDispatch()).toBe(true);s.enable('admin','incident');expect(s.canDispatch()).toBe(false);s.disable('admin','resolved');expect(s.canDispatch()).toBe(true);expect(s.events).toHaveLength(2)})});
src/domain/operations/health.ts new
+1
@@ -0,0 +1 @@
1 +export type Health='HEALTHY'|'DEGRADED'; export function evaluateHealth(x:{lastSeenMs:number;nowMs:number;maxAgeMs:number}):Health{return x.nowMs-x.lastSeenMs>x.maxAgeMs?'DEGRADED':'HEALTHY'}; export class EmergencyStop{private enabled=false;readonly events:{action:'ENABLE'|'DISABLE';actor:string;reason:string}[]=[];enable(actor:string,reason:string){if(!actor||!reason)throw new Error('actor/reason required');this.enabled=true;this.events.push({action:'ENABLE',actor,reason})}disable(actor:string,reason:string){if(!actor||!reason)throw new Error('actor/reason required');this.enabled=false;this.events.push({action:'DISABLE',actor,reason})}canDispatch(){return !this.enabled}}
src/domain/operations/reports.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest'; import {report,toCsv} from './reports';
2 +describe('reports and exports',()=>{const rows=[{tenantId:'t1',reference:'R1',state:'SETTLED',amountIrr:1000},{tenantId:'t1',reference:'R2',state:'UNKNOWN',amountIrr:2500},{tenantId:'t2',reference:'SECRET',state:'SETTLED',amountIrr:9}];it('totals tenant data',()=>expect(report('t1',rows)).toEqual({count:2,totalIrr:3500,settledIrr:1000}));it('exports stable integer IRR without tenant leak',()=>{const csv=toCsv('t1',rows);expect(csv).toContain('R1,SETTLED,1000');expect(csv).not.toContain('SECRET');expect(csv.split('\n')[0]).toBe('reference,state,amountIrr')})});
src/domain/operations/reports.ts new
+1
@@ -0,0 +1 @@
1 +export type ReportRow={tenantId:string;reference:string;state:string;amountIrr:number}; export function report(t:string,rows:ReportRow[]){const r=rows.filter(x=>x.tenantId===t);return{count:r.length,totalIrr:r.reduce((s,x)=>s+x.amountIrr,0),settledIrr:r.filter(x=>x.state==='SETTLED').reduce((s,x)=>s+x.amountIrr,0)}} export function toCsv(t:string,rows:ReportRow[]){const own=rows.filter(x=>x.tenantId===t);return ['reference,state,amountIrr',...own.map(x=>`${x.reference},${x.state},${x.amountIrr}`)].join('\n')}