Files
teatea-pension/.trellis/tasks/archive/2026-07/07-09-ai-fee-frontend/design.md

4.3 KiB

AI Presentation And Fee Workspace Design

Scope

This task keeps the current AI product surface and adds one new frontend-only fee workspace. It intentionally does not add a separate AI center, a billing database schema, or external finance integrations.

AI Boundary

The visible AI workflow remains split across the existing layers:

  • modules/ai/server/analysis.ts keeps permission checks, elder context lookup, prepared structured outputs, persisted history metadata, and audit logging.
  • modules/ai/components/ElderAiAnalysisDialog.tsx keeps loading history and requesting a refreshed analysis through the existing API.
  • modules/dashboard/components/DashboardHome.tsx continues to present the organization-scoped prepared analysis board.
  • modules/ai/components/KnowledgeManagementClient.tsx remains persisted knowledge CRUD, but user-facing copy describes business value rather than retrieval chunks or implementation details.

No external model provider is called by the visible analysis path. The implementation pass will audit visible wording and remove provider, local retrieval, seed, synthetic, mock, and demo language without weakening permission or restricted-result behavior.

Fee Workspace Boundary

Create a new modules/billing/ frontend domain:

  • types.ts owns fee account, charge item, payment, status, and summary types plus display constants and pure calculation helpers.
  • lib/presentation-data.ts owns the initial organization fee ledger used by the workspace.
  • components/BillingWorkspaceClient.tsx owns all browser-session interactions.

Create routes:

  • app/(app)/app/billing/page.tsx
  • app/(app)/app/[organizationSlug]/billing/page.tsx

The server route performs the normal authentication and organization checks, gates the page with admission:manage, and passes the initial ledger into the client component. No API route or database table is added.

Navigation

Add 费用管理 to the operations group after 床位房间. Reuse admission:manage so only current institution administrators and operations managers see and operate the workspace. Add a Lucide wallet/receipt icon through the existing sidebar icon map.

Fee Data Model

Each resident statement contains:

  • statement id, resident identity, room/bed label, billing period, due date
  • charge items with category, description, quantity, unit price, and amount
  • payment records with amount, method, time, reference, operator, and note
  • invoice state and receipt count

Totals and status are derived from charge and payment records:

  • paid: outstanding amount is zero
  • partial: at least one payment exists and an outstanding amount remains
  • pending: no payment and not past due
  • overdue: outstanding amount remains after the due date

All currency is represented as integer cents internally and formatted as CNY for display.

Interactions

The fee workspace provides:

  • overview metrics for current receivables, collected amount, outstanding amount, and overdue households
  • resident/statement search and status filtering
  • statement detail dialog with itemized charges and payment history
  • charge registration dialog that appends a new item and recalculates totals
  • payment registration dialog with amount and method validation, then local statement/status updates
  • receipt and invoice actions that update the current browser-session record and return credible product feedback

Controls must not be decorative. Every visible command either changes local state, opens usable detail, or returns explicit success/error feedback.

Responsive Layout

  • Use the existing max-w-7xl, operational header, metric cards, table, badge, select, input, button, and dialog patterns.
  • Keep tables horizontally scrollable with explicit minimum widths.
  • Stack toolbar controls and dialog form fields at narrow widths.
  • Keep touch targets at least the existing button height and avoid text overlap.

Compatibility And Rollback

  • Existing AI API and database contracts remain unchanged.
  • No migration or production data backfill is required.
  • Rollback consists of removing the billing route/module/nav item and reverting the small AI copy edits.
  • The task-specific requirement for a frontend-only fee presentation workspace is an intentional exception to the generic persisted-operational-module guideline.