取代 StoreHub/Square POS,专为马来西亚零售店打造的库存管理与收银系统
* 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 developer. Help me build a complete **Inventory & POS System** step by step using the Vibe Coding approach.
## Project Overview
Store name: {store_name}
Store type: {store_type}
Estimated products: {num_products}
Tax rate (SST): {tax_rate}
Currency: {currency}
Brand primary color: {primary_color}
## Tech Stack
- Frontend: Next.js 16 (App Router) + Tailwind CSS 4
- Backend/Database: Supabase (PostgreSQL + Auth + RLS + Realtime)
- Deployment: Vercel
- Barcode scanning: Browser Camera API or quagga2 library
- Receipt printing: Browser window.print() + thermal receipt CSS layout
## Data Model (Supabase Tables)
### products
- id (uuid, PK), sku (text, unique), name_zh (text), name_en (text)
- category_id (uuid, FK → categories), barcode (text, unique, nullable)
- cost_price (numeric), selling_price (numeric), image_url (text)
- stock_quantity (integer, default 0), low_stock_threshold (integer, default 5)
- is_active (boolean, default true), created_at, updated_at
### categories
- id (uuid, PK), name_zh (text), name_en (text), sort_order (integer)
### sales
- id (uuid, PK), sale_number (text, unique, format: INV-20260409-001)
- subtotal (numeric), discount_amount (numeric), tax_amount (numeric)
- total (numeric), payment_method (enum: cash/card/ewallet)
- status (enum: completed/voided/refunded)
- location_id (uuid, FK → locations, nullable)
- cashier_id (uuid, FK → auth.users), created_at
### sale_items
- id (uuid, PK), sale_id (uuid, FK → sales)
- product_id (uuid, FK → products), quantity (integer)
- unit_price (numeric), discount_percent (numeric, default 0)
- line_total (numeric), created_at
### stock_movements
- id (uuid, PK), product_id (uuid, FK → products)
- movement_type (enum: purchase_in/sale_out/adjustment/transfer)
- quantity (integer, positive = stock in, negative = stock out)
- reference_id (uuid, nullable, links to sale_id or purchase_order_id)
- notes (text), created_at, created_by (uuid)
### purchase_orders
- id (uuid, PK), po_number (text, unique)
- supplier_id (uuid, FK → suppliers)
- status (enum: draft/ordered/received/cancelled)
- total_amount (numeric), notes (text), ordered_at, received_at
### purchase_order_items
- id (uuid, PK), purchase_order_id (uuid, FK), product_id (uuid, FK)
- quantity (integer), unit_cost (numeric), received_quantity (integer, default 0)
### suppliers
- id (uuid, PK), name (text), contact_person (text)
- phone (text), email (text), address (text)
- last_order_date (date, nullable), notes (text)
### locations (multi-location support)
- id (uuid, PK), name (text), address (text), is_active (boolean)
## Core Business Logic
### 1. POS Checkout Flow
- Search products by name or scan barcode to add to cart
- Support per-item discount (percentage) and whole-order discount
- Auto-calculate subtotal, discount, SST ({tax_rate}), and grand total
- SST formula: tax = (subtotal - discount) x tax_rate
- Select payment method: Cash (auto-calculate change), Card, E-wallet (TNG/GrabPay/DuitNow)
- On checkout, auto-deduct stock via Supabase Database Function + Trigger
- Generate receipt (58mm/80mm thermal format) with store name, item details, SST registration number, total
### 2. Automatic Stock Deduction (Database Trigger)
```sql
-- Triggered on sale_items INSERT
CREATE FUNCTION deduct_stock() RETURNS trigger AS $$
BEGIN
UPDATE products SET stock_quantity = stock_quantity - NEW.quantity
WHERE id = NEW.product_id;
INSERT INTO stock_movements (product_id, movement_type, quantity, reference_id)
VALUES (NEW.product_id, 'sale_out', -NEW.quantity, NEW.sale_id);
RETURN NEW;
END; $$ LANGUAGE plpgsql;
```
### 3. Low Stock Alerts
- Query: stock_quantity <= low_stock_threshold AND is_active = true
- Red alert banner at top of dashboard showing count of low-stock products
- Click to view low-stock list, with quick action to create purchase order
### 4. Profit Calculation
- Per-item profit = selling_price - cost_price
- Gross margin = (selling_price - cost_price) / selling_price x 100%
- Reports show daily/weekly/monthly total revenue, total cost, gross profit
## UI/UX Design Specs
### POS Terminal (Tablet-optimized, 1024px+)
- Left 60%: Product grid (large tap targets, product images, prices) + top search bar + category filters
- Right 40%: Cart list + subtotal/tax/total + payment buttons
- Large fonts (product name 16px+, prices 20px+) for easy touch interaction
- Payment modal: select method → confirm → print receipt
### Admin Dashboard (Desktop)
- Sidebar navigation: Dashboard, Products, Inventory, Sales, Purchasing, Suppliers, Reports, Settings
- Dashboard: today's revenue, order count, gross profit, low stock alerts
- Products: data table + search + filters + bulk actions
- Reports: date range picker + bar charts + detail tables
### Localization
- UI language: Chinese primary, English secondary (bilingual toggle)
- Currency format: {currency} 1,234.00
- Date format: 2026-04-09 / 09/04/2026
## Sample Data ({store_name} — Phone Accessories Shop)
### Categories
Phone Cases, Chargers, Cables, Earphones, Screen Protectors, Other Accessories
### Sample Products
| SKU | Chinese Name | English Name | Cost | Price | Stock | Low Threshold |
|-----|-------------|--------------|------|-------|-------|---------------|
| ACC-001 | iPhone 15 透明手机壳 | iPhone 15 Clear Case | 5.00 | 19.90 | 50 | 10 |
| CHG-001 | 20W USB-C 快充头 | 20W USB-C Charger | 12.00 | 39.90 | 30 | 5 |
| CBL-001 | 1m USB-C 数据线 | 1m USB-C Cable | 3.00 | 15.90 | 100 | 15 |
| EAR-001 | 蓝牙耳机 A1 | Bluetooth Earbuds A1 | 25.00 | 79.90 | 20 | 5 |
| SPF-001 | iPhone 15 钢化膜 | iPhone 15 Screen Protector | 2.00 | 12.90 | 80 | 20 |
### Sample Suppliers
| Supplier | Contact | Products Supplied |
|----------|---------|-------------------|
| 深圳优品科技 | Manager Chen | Phone cases, Screen protectors |
| KL Digital Supply | Ahmad | Chargers, Cables |
## RLS Security Policies
- products/categories: anon can SELECT (POS needs read access)
- sales/sale_items: authenticated can INSERT/SELECT
- All write operations restricted to authenticated users with email in admin allowlist
- stock_movements: auto-inserted via trigger, admin can query
## Page Routes
- / — Login page
- /pos — POS terminal
- /dashboard — Admin dashboard
- /products — Product management
- /inventory — Inventory management
- /sales — Sales history
- /reports — Sales reports
- /suppliers — Supplier management
- /purchase-orders — Purchase order management
- /settings — System settings
Start with the database schema and Supabase configuration, then build the POS terminal interface, and finally complete the admin management modules. Provide complete, runnable code for each step.