Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ Theo yêu cầu nhóm, dùng src/app, src/features/<role>/<feature>, src/shared,
- Thời hạn hoàn: 3–5 ngày làm việc, chuyển khoản thủ công sau khi trừ phí. Hệ thống ghi trạng thái hoàn khi Quản lý xác nhận ở M07.
- Thay thế: quy định "phí hủy 10% tiền thuê" trong BACKEND-TODO (H1) và CANCEL_FEE_RATE (appReducer.js) không còn áp dụng; phải đổi theo D27. Chưa triển khai code.

## D28 — 2026-10-23: Đồng bộ Figma 23/10 (huỷ/hoàn tiền D27 và hộp thoại kết quả)

- Figma được cập nhật theo D27: luồng đặt chỗ hiện tiền cọc (thuê + cọc 1 tháng = tổng ban đầu); huỷ trước ngày bắt đầu thuê: phí 10% tiền cọc, hoàn 100% tiền thuê và 90% cọc; B02 phí quá hạn 5% giá thuê tháng mỗi ngày trễ. Code giữ số liệu từ backend, chỉ đổi chữ và bố cục theo Figma.
- C14 đặt nút "Xem đơn / Huỷ đơn" trên từng dòng; C14b/C14c hiện "Đã huỷ · Đang hoàn tiền" (`refundStatus` PENDING) và "Đã huỷ · Đã hoàn tiền" (COMPLETED).
- Mọi thao tác ghi của nhân viên và các thao tác phân bổ, phân công, duyệt/từ chối gia hạn của quản lý đi qua: xác nhận → thành công (03a) hoặc thất bại (03b) theo Figma 779:*, 847:*, 885:*. Admin và Vận hành KD dùng chung `shared/components/ChangeFlowDialog.jsx`. Sau thành công, trang quay về danh sách đúng theo nút trên Figma thay vì trang kết quả `staff/done`.
- M08 hoàn tiền đơn huỷ là trang riêng `#/manager/refunds` nằm dưới tab "Hợp đồng & quá hạn" (Figma đặt cùng tab). Chỉ hoàn bằng chuyển khoản vì khách đã trả qua PayOS; bắt buộc nhập mã giao dịch.

## D28 — Kiểm thử giao diện C12/C12b/C13 bằng Playwright

Expand Down
30 changes: 30 additions & 0 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,33 @@ Trạng thái triển khai D27 (22/10/2026):
- Giao diện: `cancelPreviewOf` (appReducer.js) tính 10% tiền cọc; C14a hiển thị phí và số hoàn theo đó. Còn thiếu: nút xác nhận hoàn cho đơn đã huỷ ở màn M07.
- Đường cũ `POST /api/manager/contracts/{id}/refund` giờ gọi chung `FacilityOpsService.ConfirmRefundAsync` (D27); đã bỏ `ManagerService.ConfirmRefundAsync` (trước đây đặt trạng thái `ENDED` không hợp lệ). Id phải là mã hiển thị `HĐ-…` như `/api/ops`; tài khoản ADMIN không có cơ sở được phân công nên nhận 403.
- F12 · RESERVED → OCCUPIED: `UnitStartActivation` (chạy cùng worker mỗi phút) chuyển ô đang giữ chỗ sang đang thuê khi hợp đồng ACTIVE/EXPIRING đến `StartDate` (giờ Việt Nam), ghi `unit_status_histories`. Nhận chìa khóa vẫn không đổi trạng thái ô (D26). Chuyển RESERVED/OCCUPIED bằng tay vẫn bị chặn ở `UnitStatusRules`.

## M08 — Hoàn tiền đơn huỷ trên giao diện quản lý (F40, 23/10/2026)

Giao diện `#/manager/refunds` (Figma M08 828:10212, M08a 828:10262) đọc danh sách từ `GET /api/ops/board` và gọi
`POST /api/ops/reservations/{id}/refund` (đã có, D27). Backend cần bổ sung:

- `GET /api/ops/board` trả thêm mảng `refunds` cho cơ sở của quản lý (đơn `CANCELLED` có khoản `REFUND`). Khi chưa có, trang hiện "Chưa có đơn huỷ cần hoàn tiền."
- Body của `POST /api/ops/reservations/{id}/refund`: nhận và lưu `method` (`BANK_TRANSFER`) và `transactionRef` (mã giao dịch quản lý nhập). Hiện endpoint bỏ qua body.

```jsonc
// GET /api/ops/board → refunds[] (camelCase; giao diện tự đổi sang snake_case)
{ "id": "SS-20260918-0151", "customer": "Nguyễn Hoàng Yến", "cancelledAt": "2026-10-22T08:40:00",
"rent": 3450000, "deposit": 1150000, "paid": 4600000, "fee": 115000, "amount": 4485000,
"status": "PENDING", "paidAt": null, "transactionRef": null } // status: PENDING | PAID
```

## M02b / M02c — Thêm và sửa ô kho (F40)

`POST /api/manager/units` và `PUT /api/manager/units/{id}` đã có nhưng `CreateUnitAsync` luôn lấy loại kho đầu tiên và bỏ qua loại/cỡ.
Giao diện gửi `{ unitNumber, locationDescription, unitTypeCode: "normal" | "climate", area: 15 | 30 }`; backend cần chọn `UnitType`
theo loại kho + diện tích (D17: cỡ M 15 m², cỡ L 30 m²) và từ chối đổi loại/cỡ khi ô đang có khách thuê.

## Phí phát sinh khi trả kho và công nợ (F40: S04, S09f, C11f)

Giao diện đã làm theo Figma; backend cần bổ sung:

- `POST /api/ops/returns/{id}/inspection` (`OpsReturnInspectionRequest`): nhận thêm `damageFee`, `cleaningFee`, `overdueFee`, `feeReason`; ghi các khoản `DAMAGE_FEE` / `CLEANING_FEE` / `OVERDUE_FEE` trạng thái `PENDING` để M07 trừ cọc theo D27 và phần thiếu thành công nợ.
- Khách trả phí qua PayOS: `POST /api/payments/{paymentId}/payos` cho khoản phí `PENDING` (cùng endpoint giao diện đang dùng cho gia hạn; hiện backend chưa có nên popup báo "tạm gián đoạn").
- Khách chọn trả tại quầy (C11fc): API ghi nhận lựa chọn, ví dụ `POST /api/payments/{paymentId}/at-facility`. Giao diện tạm lưu trong trình duyệt (`overlay.feesAtCounter`).
- Nhân viên thu tại quầy (S09f): `GET /api/ops/board` trả `feeCollections[]` `{ id, contract, customer, unit, items: [[nhãn, số tiền]], amount, due, status, requestedAt }` và `POST /api/ops/fees/{id}/confirm` chuyển các khoản sang `PAID`.
2 changes: 2 additions & 0 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
| Quản lý cơ sở / Tổng quan — ManagerDashboardPage | `src/features/manager/dashboard/ManagerDashboardPage.jsx` |
| Quản lý cơ sở / Gia hạn — RenewalApprovalPage | `src/features/manager/renewals/RenewalApprovalPage.jsx` |
| Quản lý cơ sở / Báo cáo — FacilityReportPage | `src/features/manager/reports/FacilityReportPage.jsx` |
| Quản lý cơ sở / Hoàn tiền đơn huỷ — CancellationRefundPage | `src/features/manager/refunds/CancellationRefundPage.jsx` |
| Quản lý cơ sở / Kết quả — ManagerResultPage | `src/features/manager/results/ManagerResultPage.jsx` |
| Quản lý cơ sở / Quản lý ô kho — UnitManagementPage | `src/features/manager/units/UnitManagementPage.jsx` |
| Nhân viên / Tổng quan — StaffDashboardPage | `src/features/staff/dashboard/StaffDashboardPage.jsx` |
Expand All @@ -79,6 +80,7 @@
| Kho thuê / gia hạn / trả kho | `#/units`, `#/units/:id/renew`, `#/units/:id/return` |
| Nhân viên thu tiền / xác minh / nhận chìa khóa | `#/staff/reconcile`, `#/staff/verify`, `#/staff/keys` (alias cũ: `#/staff/handover`) |
| Quản lý ô / phân bổ / gia hạn | `#/manager/units`, `#/manager/allocate`, `#/manager/renewals` |
| Hoàn tiền đơn huỷ (M08) | `#/manager/refunds` |
| Vận hành kinh doanh / quản trị | `#/business`, `#/admin` |

## Ví dụ lần theo code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ export function createSeedData(t = today()) {
payable: true,
period: { from: b015End, to: addMonths(b015End, 3), months: 3 },
},
// C11f · Phí phát sinh theo biên bản trả kho, khách trả qua PayOS hoặc tại quầy (S09f)
{
ref: "SS-0086-FEE",
kind: "FEE",
label: "Phí phát sinh trả kho B-015",
contract_id: "HĐ-2026-0086",
reservation_id: "SS-20260615-0086",
amount: 450000,
status: "UNPAID",
payable: true,
fee: true,
detail: "Theo biên bản trả kho B-015: phí vệ sinh 150.000 đ, phí hư hỏng ổ khóa 300.000 đ.",
},
],
appointments: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,13 @@ function ApiProvider({ children }) {
const out = runLocal(type, p);
return out.error ? fail(out.error.message, out.error.code) : { ok: true, ...out.result };
}
// C11fc: backend chưa có API chọn trả phí tại quầy → ghi trong trình duyệt; nhân viên thu ở S09f
case "CHOOSE_FEE_AT_COUNTER": {
const rows = d.ledger.filter((l) => p.refs.includes(l.ref) && l.fee && ["UNPAID", "AT_COUNTER"].includes(l.status));
if (!rows.length) return fail("Không còn khoản phí cần thanh toán.", "NOT_FOUND");
updateOverlay((o) => ({ ...o, feesAtCounter: { ...(o.feesAtCounter || {}), ...Object.fromEntries(rows.map((l) => [l.api_id, Date.now()])) } }));
return { ok: true, refs: rows.map((l) => l.ref) };
}
default:
return fail(`Thao tác không được hỗ trợ: ${type}`, "UNKNOWN");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ const handlers = {

// PayOS báo đã thanh toán (webhook ở backend; chế độ trình duyệt tự gọi để mô phỏng).
// reservation_id → đơn đặt chỗ đã trả tiền thuê + cọc; ref → khoản gia hạn ở C11.
// C11fc → C11fcp: khách chọn trả phí phát sinh tại quầy; công nợ chỉ giảm khi nhân viên xác nhận đã thu (S09f)
CHOOSE_FEE_AT_COUNTER(state, { refs }) {
const rows = state.ledger.filter((l) => refs.includes(l.ref) && l.fee && ["UNPAID", "AT_COUNTER"].includes(l.status));
if (!rows.length) fail("Không còn khoản phí cần thanh toán.", "NOT_FOUND");
return { state: { ...state, ledger: state.ledger.map((l) => (rows.includes(l) ? { ...l, status: "AT_COUNTER" } : l)) }, result: { refs: rows.map((l) => l.ref) } };
},
PAYOS_PAID(state, p, ctx) {
if (p.ref) {
const l = state.ledger.find((x) => x.ref === p.ref);
Expand All @@ -197,6 +203,10 @@ const handlers = {
ledger: state.ledger.map((x) => (x.ref === l.ref ? { ...x, status: "RECONCILED", payable: false } : x)),
contracts: state.contracts.map((x) => (c && x.contract_id === c.contract_id && l.period?.to ? { ...x, end_date: l.period.to, status: "ACTIVE" } : x)),
};
if (l.fee) {
next = notify(next, "Đã thanh toán phí phát sinh", `${l.label} · ${l.amount.toLocaleString("vi-VN")} đ.`, "payments", ctx.now);
return { state: log(next, `Đã thanh toán ${l.label.toLowerCase()} qua QR`, "green", ctx.now), result: { ref: l.ref } };
}
next = notify(next, "Đã thanh toán gia hạn", `Kho ${l.unit_number || c?.unit_number || ""} · gia hạn đến ${l.period?.to ? dateLabel(l.period.to) : "kỳ mới"}.`, "payments", ctx.now);
next = log(next, `Đã thanh toán gia hạn ${l.unit_number || ""} qua QR`, "green", ctx.now);
return { state: next, result: { ref: l.ref } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import React, { useMemo, useState } from "react";
import { adminApi } from "../api/adminApi.js";
import { Button, Modal, Notice } from "../../../shared/components/UI.jsx";
import { ROLE_SCOPE, roleLabel, sortRoles } from "../../../shared/utils/roles.js";
import { useChangeFlow } from "../../../shared/components/ChangeFlowDialog.jsx";
import { useApp } from "../../../app/state/AppProvider.jsx";
import { useLoad } from "../utils/adminUtils.js";

Expand Down Expand Up @@ -51,6 +52,7 @@ export default function PermissionListPage() {
const [changes, setChanges] = useState({});
// Trạng thái hiển thị modal xác nhận lưu thay đổi
const [confirm, setConfirm] = useState(false);
const [flowEl, runChange] = useChangeFlow();
// Trạng thái đang gửi request lưu lên backend
const [saving, setSaving] = useState(false);
// Danh sách các lỗi nếu có request gán/thu hồi quyền thất bại
Expand Down Expand Up @@ -123,27 +125,33 @@ export default function PermissionListPage() {
* 4. Thu thập các lỗi (nếu có) để hiển thị cho Admin.
* 5. Tải lại dữ liệu mới từ backend và thông báo qua toast.
*/
// Figma 885:10589–10613: xác nhận (kèm danh sách thay đổi) → đã lưu / không lưu được
const save = async () => {
setConfirm(false);
setSaving(true);
const failed = [];

for (const [k, on] of pending) {
const [rid, pid] = k.split(":").map(Number);
try {
if (on) await adminApi.assignPermission(rid, pid);
else await adminApi.revokePermission(rid, pid);
} catch (e) {
onApiError(e);
failed.push(`${roleLabel(roleOf(rid)?.roleName)} · ${permOf(pid)?.permissionName}: ${e.message}`);
}
}

await runChange({
action: "Lưu cấu hình quyền", scope: "Các vai trò trong hệ thống", confirm: false,
perform: async () => {
for (const [k, on] of pending) {
const [rid, pid] = k.split(":").map(Number);
try {
if (on) await adminApi.assignPermission(rid, pid);
else await adminApi.revokePermission(rid, pid);
} catch (e) {
onApiError(e);
failed.push(`${roleLabel(roleOf(rid)?.roleName)} · ${permOf(pid)?.permissionName}: ${e.message}`);
}
}
if (failed.length === pending.length) throw new Error(failed[0]);
return true;
},
});
setSaving(false);
setErrors(failed);
setChanges({});
await res.reload();
notify(failed.length ? `Đã lưu, ${failed.length} thay đổi không thành công.` : "Đã lưu cấu hình quyền.", failed.length ? "error" : "success");
if (failed.length && failed.length < pending.length) notify(`Đã lưu, ${failed.length} thay đổi không thành công.`, "error");
};

return (
Expand Down Expand Up @@ -254,7 +262,8 @@ export default function PermissionListPage() {

{/* MODAL XÁC NHẬN ÁP DỤNG THAY ĐỔI */}
{confirm && (
<Modal title="Áp dụng thay đổi quyền?" onClose={() => setConfirm(false)} size="md">
<Modal title="Lưu cấu hình quyền?" onClose={() => setConfirm(false)} size="md">
<p className="modal__text">Kiểm tra thông tin trước khi xác nhận. Chọn Quay lại để giữ nguyên dữ liệu.</p>
{/* Liệt kê từng thay đổi cụ thể */}
<ul className="change-list">
{pending.map(([k, on]) => {
Expand All @@ -273,12 +282,14 @@ export default function PermissionListPage() {
)}

{/* Các nút hành động trong Modal */}
<p className="hint">Chỉ lưu thay đổi sau khi bạn bấm Xác nhận.</p>
<div className="modal__actions">
<Button onClick={save}>Áp dụng</Button>
<Button variant="outline" onClick={() => setConfirm(false)}>Xem lại</Button>
<Button variant="outline" onClick={() => setConfirm(false)}>Quay lại</Button>
<Button onClick={save}>Xác nhận</Button>
</div>
</Modal>
)}
{flowEl}
</main>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Button, Field, Modal, Notice } from "../../../shared/components/UI.jsx"
import { isEmail, isPhone, today } from "../../../shared/utils/format.js";
import { FACILITY_ROLES, roleLabel, sortRoles } from "../../../shared/utils/roles.js";
import { go } from "../../../app/router.js";
import { useChangeFlow } from "../../../shared/components/ChangeFlowDialog.jsx";
import { useApp } from "../../../app/state/AppProvider.jsx";
import { tempPassword, useLoad, usernameFrom } from "../utils/adminUtils.js";

Expand Down Expand Up @@ -88,6 +89,7 @@ export default function CreateUserPage() {
// null: chưa tạo thành công, chưa hiện Modal.
// Có dữ liệu: hiện Modal thông tin đăng nhập.
const [done, setDone] = useState(null);
const [flowEl, runChange] = useChangeFlow();


/*
Expand Down Expand Up @@ -210,31 +212,27 @@ export default function CreateUserPage() {
// Biến lưu thông tin tài khoản được backend tạo.
let created;

try {

/*
* GỌI API TẠO TÀI KHOẢN
*
* Dữ liệu gửi đi:
* - username: tên đăng nhập.
* - password: mật khẩu tạm thời.
* - fullName: họ tên.
* - email: chuyển chữ thường.
* - phone: loại bỏ khoảng trắng, dấu . và -.
* - initialRoleId: ID vai trò được chọn.
* - status: tài khoản được tạo ở trạng thái ACTIVE.
*/

created = await adminApi.createUser({
username: form.username.trim(),
password: form.password,
fullName: form.fullName.trim(),
email: form.email.trim().toLowerCase(),
phone: form.phone.replace(/[\s.-]/g, "") || null,
initialRoleId: Number(form.roleId),
status: "ACTIVE",
});
// Figma 885:10555–10579: hỏi xác nhận trước khi tạo; lỗi hiện hộp thoại "Không tạo tài khoản được".
// Thành công vẫn dùng hộp thoại riêng bên dưới để hiện tên đăng nhập và mật khẩu tạm một lần.
const outcome = await runChange({
action: "Tạo tài khoản", scope: "Tài khoản mới", content: "Thông tin, vai trò và cơ sở đã chọn", showSuccess: false,
perform: async () => {
created = await adminApi.createUser({
username: form.username.trim(),
password: form.password,
fullName: form.fullName.trim(),
email: form.email.trim().toLowerCase(),
phone: form.phone.replace(/[\s.-]/g, "") || null,
initialRoleId: Number(form.roleId),
status: "ACTIVE",
});
return created;
},
});
if (outcome.cancelled) return setBusy(false);

try {
if (outcome.error) throw outcome.error;
} catch (err) {

// Xử lý lỗi API, ví dụ phiên đăng nhập hết hạn.
Expand Down Expand Up @@ -471,6 +469,7 @@ export default function CreateUserPage() {
{/* MODAL SAU KHI TẠO TÀI KHOẢN THÀNH CÔNG
Chỉ xuất hiện khi done khác null.
Khi đóng Modal sẽ chuyển sang trang chi tiết User. */}
{flowEl}
{done && (
<Modal title="Đã tạo tài khoản" onClose={() => go(`admin/users/${done.user.userId}`)}>

Expand Down
Loading