替代 SQL Accounting / Excel 的专业发票管理系统,支持 SST 税务、账龄分析、自动催款提醒
* Preview is for reference only. Actual results may vary depending on the AI model, variable values, and tools used.
You are a senior full-stack engineer. Build me a complete Invoice & Payment Tracker system designed specifically for Malaysian SMEs (Sdn Bhd companies).
## Tech Stack
- Next.js 16 (App Router) + TypeScript
- Tailwind CSS 4
- Supabase (Postgres database + Auth + Row Level Security)
- Deploy on Vercel
## Company Variables
- Company name: {company_name}
- Company address: {company_address}
- Phone: {company_phone}
- Email: {company_email}
- Tax rate (SST): {tax_rate}
- Currency: {currency}
- Payment terms: {payment_terms}
- Brand primary color: {primary_color}
## Data Model (Supabase Postgres)
### clients table
- id (uuid, PK), company_name (text), contact_person (text), email (text), phone (text)
- address (text), city (text), state (text), postcode (text)
- outstanding_balance (numeric, default 0), notes (text)
- created_at (timestamptz), updated_at (timestamptz)
### invoices table
- id (uuid, PK), invoice_number (text, unique, format: INV-2026-0001)
- client_id (uuid, FK → clients), status (enum: draft/sent/viewed/paid/overdue)
- issue_date (date), due_date (date), payment_terms (text)
- subtotal (numeric), tax_rate (numeric), tax_amount (numeric), total (numeric)
- amount_paid (numeric, default 0), balance_due (numeric, computed)
- notes (text), is_recurring (boolean), recurring_interval (text: monthly/quarterly)
- created_at (timestamptz), updated_at (timestamptz)
- Create indexes on: client_id, status, due_date, invoice_number
### invoice_items table
- id (uuid, PK), invoice_id (uuid, FK → invoices)
- description (text), quantity (numeric), unit_price (numeric), amount (numeric)
- sort_order (integer)
### payments table
- id (uuid, PK), invoice_id (uuid, FK → invoices)
- amount (numeric), payment_date (date)
- payment_method (enum: bank_transfer/cash/cheque/ewallet/credit_card)
- reference_number (text), notes (text)
- created_at (timestamptz)
### Database Functions & Triggers
1. Auto-generate invoice numbers: increment per year as INV-YYYY-NNNN
2. After payment insert, auto-update invoices.amount_paid and balance_due
3. When balance_due reaches 0, auto-set status to paid
4. Daily check: mark invoices as overdue where due_date < today and status is sent/viewed
5. Update clients.outstanding_balance (sum of all unpaid invoice balance_due)
## Business Logic
### SST Tax Calculation
- Subtotal = SUM(quantity x unit_price) for all line items
- SST amount = subtotal x {tax_rate}%
- Total = subtotal + SST amount
- All amounts to 2 decimal places using banker's rounding
### Aging Report Calculation
- Current (not yet due): due_date >= today
- 1-30 days overdue: today - due_date between 1 and 30
- 31-60 days overdue: today - due_date between 31 and 60
- 60+ days overdue: today - due_date > 60
- Show invoice count and total amount per aging bucket
### Overdue Reminder System (Simulated)
- 3 days before due: show yellow warning badge
- 1 day overdue: auto-mark as overdue, show red badge
- 7 / 30 / 60 days overdue: show escalation notices on dashboard
- Provide a "Generate Reminder Email" button (generates email body text for manual sending)
### Recurring Invoices
- Mark any invoice as monthly or quarterly recurring
- Show next generation date on dashboard
- "Generate Next Invoice" button to clone all line items into a new invoice
## Pages & UI Design
### 1. Dashboard /dashboard
- Four summary cards: Monthly Revenue, Total Outstanding, Overdue Amount, Client Count
- Monthly revenue bar chart (last 12 months)
- Aging report table (Current / 30 / 60 / 90 day buckets)
- Recent 5 invoices list
- Overdue alerts list
### 2. Invoice List /invoices
- Table view: invoice number, client, date, amount, status, actions
- Filter by status (All / Draft / Sent / Viewed / Paid / Overdue)
- Search by client name or invoice number
- Color-coded status badges: draft=gray, sent=blue, viewed=purple, paid=green, overdue=red
### 3. Create/Edit Invoice /invoices/new and /invoices/[id]/edit
- Top section: company logo and details (from variables)
- Client selector (searchable dropdown) or quick-add new client
- Line items: dynamically add/remove rows, each with description, quantity, unit price, amount (auto-calculated)
- Bottom: subtotal, SST ({tax_rate}%), total
- Payment terms, due date, notes fields
- Save as Draft / Mark as Sent buttons
### 4. Invoice Detail /invoices/[id]
- Professional PDF-style layout, print-optimized (@media print hides nav and action buttons)
- Company header: {company_name}, address, phone, email
- Client info, invoice number, dates
- Line items table with alternating row colors
- Subtotal, SST, Total
- Payment history section
- Bank transfer details section (Malaysian bank format)
- Action buttons: Print, Record Payment, Send Reminder, Edit
### 5. Client Management /clients
- Client list: company name, contact person, outstanding balance
- Client detail: basic info + all invoice history + payment history for that client
### 6. Payment Records /payments
- Payment list: date, invoice number, client, amount, method, reference
- Record Payment modal: select invoice, enter amount (supports partial payment), payment method, date, reference number
## Sample Data
### 3 Malaysian Clients
1. Syarikat Maju Jaya Sdn Bhd — Contact: Tan Ah Kow, Kuala Lumpur
2. Perniagaan Sri Rezeki Enterprise — Contact: Ahmad bin Ismail, Penang
3. Golden Harvest Trading Sdn Bhd — Contact: Lim Mei Ling, Johor Bahru
### 5 Sample Invoices
1. INV-2026-0001 → Maju Jaya, RM 5,300.00, Paid
2. INV-2026-0002 → Sri Rezeki, RM 2,120.00, Overdue by 15 days
3. INV-2026-0003 → Golden Harvest, RM 8,480.00, Sent
4. INV-2026-0004 → Maju Jaya, RM 3,710.00, Draft
5. INV-2026-0005 → Sri Rezeki, RM 1,590.00, Partially paid RM 500
## Design Style
- Primary color: {primary_color}, paired with slate gray text
- White background, cards with subtle borders and light shadows
- Inter font (English) + Noto Sans SC (Chinese)
- Invoice preview uses dark navy (#0F172A) blocks for company header
- Fully responsive — invoices viewable on mobile
## Critical Requirements
- All amounts formatted as: RM 1,234.56
- Invoice numbers auto-increment, must be unique
- Support partial payments with automatic balance calculation
- Print view hides navigation and action buttons
- RLS policies: only authenticated users can read/write all data
- Generate complete Supabase migration SQL file
- Include seed data script with sample clients and invoices