Warning
xekhofunctions are currently aligned with cloud, but this repo still overlaps withwebapp-menuin some feature areas. ReadTECH_AUDIT.mdbefore changing deploy ownership or consolidating features across repos.
Hệ thống quản lý bán hàng (POS) và màn hình bếp (KDS) cho quán ăn Xe Khô Chữa Lành, được xây dựng trên nền tảng Firebase.
- ✅ Quản lý bàn và đơn hàng realtime
- ✅ Gọi món, chỉnh sửa, thanh toán
- ✅ Tích hợp AI chatbot (Vertex AI)
- ✅ Quản lý kho, nhập hàng, báo cáo doanh thu
- ✅ Hỗ trợ nhiều role: admin, staff, kitchen
- ✅ Notification realtime từ bếp
- ✅ Màn hình bếp hiển thị đơn hàng realtime
- ✅ Cập nhật trạng thái món: Nhận → Đang làm → Xong → Đã mang ra
- ✅ Báo chậm khi cần thêm thời gian
- ✅ Thông báo đẩy qua Telegram, FCM Web Push
- ✅ Urgency indicator theo thời gian chờ
- ✅ Chỉ hiển thị món của bàn đang mở
- Vanilla JavaScript - No framework, pure JS
- Firebase SDK v11 - Auth, Firestore, Functions, Messaging
- CSS3 - Responsive design
- Firebase Firestore - NoSQL database
- Firebase Cloud Functions v2 - Serverless backend (Node.js)
- Firebase Hosting - Static hosting
- Firebase Auth - User authentication
- Vertex AI - AI chatbot, OCR, image generation
- Telegram Bot API - Kitchen notifications
- FCM (Firebase Cloud Messaging) - Web push notifications
- Zalo OA - (Planned) Zalo Official Account integration
xekho/
├── index.html # POS main UI
├── kitchen.html # Kitchen Display UI
├── app.js # POS application logic
├── db.js # Firebase/Firestore wrapper
├── store.js # State management
├── style.css # Main styles
├── ai-*.js # AI chatbot modules
├── firebase-messaging-sw.js # Service Worker for FCM
├── firestore.rules # Firestore security rules
├── firebase.json # Firebase config
├── functions/
│ ├── index.js # Cloud Functions (triggers, HTTP endpoints)
│ ├── vertexAi.js # Vertex AI integration
│ ├── geminiTools.js # Gemini function calling tools
│ └── firestoreMegaTools.js # Firestore utilities
├── KDS_PLAN.md # Kitchen Display System plan
├── CHATBOT_GUIDE.md # AI chatbot guide
├── KITCHEN_GUIDE.md # Kitchen staff guide
├── DEPLOYMENT_GUIDE.md # Deployment instructions
└── TESTING_CHECKLIST.md # Testing checklist
- Node.js 20+ (for Firebase Functions)
- Firebase CLI:
npm install -g firebase-tools - Git
git clone https://github.com/longnick/xekho.git
cd xekho
npm install
cd functions
npm install
cd ..# Login to Firebase
firebase login
# Select your Firebase project
firebase use --add
# Chọn project: pos-v2-909ff
# Alias: default
# Get Firebase config
# Copy config từ Firebase Console > Project Settings > Your apps
# Paste vào db.js (firebaseConfig object)Tạo file functions/.env.pos-v2-909ff:
# Vertex AI
VERTEX_PROJECT_ID=pos-v2-909ff
VERTEX_LOCATION=asia-southeast1
VERTEX_TEXT_MODEL=gemini-2.0-flash-exp
VERTEX_IMAGE_MODEL=imagen-3.0-generate-001
# Telegram Bot
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_chat_id
KITCHEN_NEW_ORDER_TELEGRAM_CHAT_ID=your_kitchen_chat_id
# Zalo OA (Optional - not yet implemented)
ZALO_OA_ACCESS_TOKEN=your_zalo_token
ZALO_GROUP_ID=your_zalo_group_id
# Service Account
VERTEX_SERVICE_ACCOUNT_JSON={"type":"service_account",...}# Set secrets for Cloud Functions
firebase functions:secrets:set VERTEX_SERVICE_ACCOUNT_JSON
firebase functions:secrets:set TELEGRAM_BOT_TOKEN
firebase functions:secrets:set ZALO_OA_ACCESS_TOKEN# Start Firebase emulators
firebase emulators:start
# Access:
# - Hosting: http://localhost:5000
# - Functions: http://localhost:5001
# - Firestore: http://localhost:8080# Simple HTTP server
npm start
# hoặc
node server.js
# Access: http://localhost:3000{
uid: string,
email: string,
role: 'admin' | 'staff' | 'kitchen',
displayName: string,
fcmTokens: string[], // FCM device tokens
pushPermission: string,
createdAt: timestamp
}{
id: string,
name: string,
status: 'available' | 'occupied' | 'reserved',
currentOrderId: string | null,
updatedAt: timestamp
}{
id: string,
tableId: string,
tableName: string,
items: [{
id: string,
name: string,
price: number,
qty: number,
note: string,
kitchenStatus: 'pending' | 'received' | 'cooking' | 'ready' | 'served',
kitchenSentAt: timestamp,
kitchenUpdatedAt: timestamp,
servedAt: timestamp
}],
status: 'open' | 'paid' | 'cancelled',
total: number,
createdAt: timestamp,
updatedAt: timestamp
}{
id: string,
type: 'new_order' | 'ready' | 'delay',
orderId: string,
tableId: string,
tableName: string,
items: array,
message: string,
read: boolean,
telegramSent: boolean,
pushSent: boolean,
zaloSent: boolean, // Planned
createdAt: timestamp
}Xem file firestore.rules để biết chi tiết. Các role:
- admin: Full access
- staff: Read/write orders, tables
- kitchen: Read orders, update kitchen status, read/write kitchen_notifications
firebase deploy --only firestore:rulescd functions
npm run build # nếu có TypeScript
cd ..
firebase deploy --only functionsfirebase deploy --only hostingfirebase deployProduction URLs:
1. Staff gọi món trên POS
↓
2. Order được tạo/update trong Firestore
↓
3. POS tự động tạo kitchen_notification document
↓
4. Cloud Function trigger: onKitchenNotificationCreated
↓
5. Gửi notification qua:
- Telegram Bot (kitchen chat)
- FCM Push (devices có role kitchen/admin)
- Zalo OA (planned, chưa implement)
↓
6. Kitchen Display nhận realtime update
↓
7. Bếp cập nhật trạng thái món
↓
8. POS nhận notification realtime
pending → received → cooking → ready → served
(Nhận) (Đang làm) (Xong) (Đã mang ra)
- ✅ Full access to all features
- ✅ User management
- ✅ Settings, reports, inventory
- ✅ Kitchen display access
- ✅ Manage tables and orders
- ✅ Call orders, payment
- ✅ View inventory
- ❌ Cannot access admin settings
- ✅ View kitchen display
- ✅ Update kitchen status
- ✅ Receive notifications
- ❌ Cannot access POS or admin features
Xem file TESTING_CHECKLIST.md để biết chi tiết test cases.
- Login as staff → Gọi món
- Login as kitchen → Xem màn hình bếp
- Cập nhật trạng thái món
- Kiểm tra notification trên POS
- KITCHEN_GUIDE.md - Hướng dẫn sử dụng cho nhân viên bếp
- DEPLOYMENT_GUIDE.md - Hướng dẫn deploy chi tiết
- TESTING_CHECKLIST.md - Checklist test đầy đủ
- KDS_PLAN.md - Kitchen Display System plan (978 dòng)
- CHATBOT_GUIDE.md - AI chatbot guide
- Kiểm tra user role = 'kitchen' hoặc 'admin'
- Kiểm tra FCM token đã được register
- Kiểm tra browser notification permission
- Xem logs trong Firebase Console > Functions
- Kiểm tra Firestore listeners đang active
- Kiểm tra network connection
- Hard refresh (Ctrl+Shift+R)
- Xem logs:
firebase functions:log - Kiểm tra environment variables/secrets
- Kiểm tra Firestore rules
- GitHub Issues: https://github.com/longnick/xekho/issues
- Email: support@xekho.com (nếu có)
Private project - All rights reserved
Version: 1.0.0
Last Updated: 2026-05-05
Firebase Project: pos-v2-909ff