# TDK Finance Manager – hướng dẫn deploy bản snapshot

Gói này là **source code** (không gồm `vendor/`, `node_modules/`, `.env`, file upload, log).
Giao diện đã được build sẵn trong `public/build/`.

## Cài lên server

```bash
# 1. Giải nén vào thư mục web, rồi:
composer install --no-dev --optimize-autoloader
cp .env.example .env        # hoặc dùng .env sẵn có của server
php artisan key:generate    # chỉ khi .env mới
php artisan storage:link

# 2. Cập nhật database (an toàn: chỉ thêm cột/bảng mới)
php artisan migrate --force

# 3. Xoá cache
php artisan optimize:clear
php artisan config:cache && php artisan route:cache && php artisan view:cache
```

**Không** được có file `public/hot` trên server (file đó trỏ giao diện về Vite dev server).

## Lịch chạy tự động

Cron mỗi phút (đã cần cho bot Telegram nhắc nợ):

```
* * * * * cd /duong-dan/toi/du-an && php artisan schedule:run >> /dev/null 2>&1
```

Mới thêm: `tdk:reconcile-wallets --notify` chạy 08:00 mỗi ngày, chỉ nhắn Telegram khi số dư ví lệch sổ cái.

## Lệnh tiện ích

| Lệnh | Tác dụng |
|---|---|
| `php artisan tdk:reconcile-wallets` | Đối soát số dư ví với sổ cái (chỉ đọc) |
| `php artisan tdk:fix-expense-rounding` | Xem trước dòng chi tiêu bị cắt 0,01; thêm `--apply` để sửa (có lưu bản sao) |

## Migration mới trong bản này

Tất cả chỉ thêm bảng/cột, không xoá dữ liệu. Nên sao lưu DB trước khi chạy `migrate`.

- `2026_11_13_100000_add_partner_expense_id_to_customer_expenses_table` – liên kết chi tiêu khách ↔ đối tác (tự nối dữ liệu cũ)
- `2026_11_13_100100_create_cid_status_logs_table` – lịch sử trạng thái CID
- `2026_11_14_100000_add_found_by_admin_id_to_users_table` – nhân viên tìm ra khách
- `2026_11_14_110000_create_commission_rates_and_lines_tables` – hoa hồng
- `2026_11_14_120000_create_member_requests_table` – yêu cầu duyệt
- `2026_11_14_130000_create_allowance_tables` – phụ cấp
- `2026_11_14_140000_add_review_fields_to_other_expenses_table`
- `2026_11_15_100000_add_partner_id_to_member_requests_table`
- `2026_11_16_100000_add_tool_link_to_other_expenses_table`
- `2026_11_16_110000_add_currency_to_member_requests_table`
- `2026_11_16_120000_add_payment_proof_to_member_requests_table`
- `2026_11_16_130000_create_notifications_table` – chuông thông báo

MySQL trên server nên đặt `max_allowed_packet=64M` (ảnh chứng từ thanh toán).

## Kiểm tra sau deploy

1. Đăng nhập admin → Hệ thống → **Đối soát ví**: phải báo "Tất cả số dư ví khớp sổ cái".
2. Tổng quan → **Lợi nhuận**: kiểm tra số CID thiếu chi phí đối tác.
3. `php artisan test` (cần database `testing` riêng).
