feat: unify wallet with real payment methods, full transaction transparency, pay-session-from-wallet

Address wallet feedback: use the clinic's real payment infrastructure,
redesign the tab to match the admin panel, and make every wallet movement
fully auditable.

Backend:
- WalletTransaction: add createdBy (acting user) + createdByName, payment_method,
  reference, status; toArray exposes them (migration Version20260716083939).
- WalletService (Settlement): balance/charge/withdraw + settleSessionFromWallet,
  records actor/method/reason; insufficient balance throws ERR_WALLET_INSUFFICIENT.
- PatientController: charge/withdraw delegate to WalletService and accept
  payment_method/reference; PATCH /session/{uuid} with payment_method=wallet
  debits the patient's final share from the wallet (reference=session:{uuid}).
- docs/api/patient.md updated.

Frontend:
- Wallet modal redesigned to panel style (no gradient); payment method now uses
  the clinic's real bank accounts + POS devices (usePaymentMethods) plus cash.
- Wallet tab: panel balance card + DataTable ledger with columns مبلغ/نوع/روش/
  دلیل/ثبت‌کننده/تاریخ/ساعت/وضعیت + همه/واریزی/برداشت filters.
- Session card «تکمیل پرداخت» opens a payment-method chooser incl. کیف پول.

Tests: backend transparency + session-from-wallet (success/insufficient/cash);
frontend modal (real methods, toman→rials) + wallet tab + settle chooser.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-16 12:22:37 +03:30
co-authored by Claude Opus 4.8
parent 22474653b5
commit ef97b2b249
12 changed files with 598 additions and 187 deletions
+15 -3
View File
@@ -168,8 +168,8 @@ describe('PatientDetailPage (پرونده تب‌دار)', () => {
expect(screen.getByRole('button', { name: 'همه' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'واریزی' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'برداشت' })).toBeInTheDocument();
// تراکنش credit اولیه دیده می‌شود
expect(screen.getByText('شارژ')).toBeInTheDocument();
// تراکنش credit اولیه دیده می‌شود (سطر جدول async لود می‌شود)
expect(await screen.findByText('شارژ')).toBeInTheDocument();
});
it('filters out the credit transaction when the برداشت filter is selected', async () => {
@@ -193,7 +193,19 @@ describe('PatientDetailPage (پرونده تب‌دار)', () => {
expect(await screen.findByRole('button', { name: 'برداشت از کیف پول' })).toBeInTheDocument();
fireEvent.change(screen.getByPlaceholderText('مبلغ دلخواه (تومان)'), { target: { value: '50000' } });
fireEvent.click(screen.getByRole('button', { name: 'ثبت تراکنش' }));
await waitFor(() => expect(post).toHaveBeenCalledWith('/api/v1/patient/r1/wallet/charge', { amount_rials: 500000 }));
await waitFor(() => expect(post).toHaveBeenCalledWith('/api/v1/patient/r1/wallet/charge', { amount_rials: 500000, payment_method: 'cash' }));
});
it('settles a session from the wallet via the payment-method chooser', async () => {
const patch = api.patch as ReturnType<typeof vi.fn>;
patch.mockResolvedValue({ success: true, data: {} });
renderDetail();
await loaded();
// تب سرویس‌ها پیش‌فرض است؛ کارت پرداخت‌نشده → «تکمیل پرداخت»
fireEvent.click(await screen.findByText('تکمیل پرداخت'));
expect(await screen.findByText('روش پرداخت مراجعه')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'کیف پول بیمار' }));
await waitFor(() => expect(patch).toHaveBeenCalledWith('/api/v1/session/s1', { payment_method: 'wallet' }));
});
it('renders the messages tab with a send box', async () => {