diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md
index 890c0af..1a7931d 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md
@@ -376,7 +376,10 @@ theo loại kho + diện tích (D17: cỡ M 15 m², cỡ L 30 m²) và từ ch
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ợ.
+- `POST /api/ops/returns/{id}/inspection` (`OpsReturnInspectionRequest`): nhận thêm `damageFee`, `cleaningFee`, `cleaningRequired`, `feeReason`; lưu vào `ReturnInspection.DamageFee` / `CleaningFee` / `CleaningRequired` (cột đã có, `ConfirmRefundAsync` đang đọc) và ghi khoản `DAMAGE_FEE` / `CLEANING_FEE` trạng thái `PENDING` để M07 trừ cọc theo D27, phần thiếu thành công nợ.
+ - Cập nhật 25/10: S04 **bỏ ô nhập phí quá hạn** vì `ConfirmRefundAsync` đã tự tính phí quá hạn theo số ngày trễ (chính sách `OVERDUE`); nhập tay sẽ tính trùng. Giao diện không gửi `overdueFee` nữa.
+ - `OpsReturnReportDto` trong `GET /api/ops/board` trả thêm `damageFee`, `cleaningFee`, `cleaningRequired`, `feeReason`. Khi chưa có, S04 hiện "Máy chủ chưa lưu phí phát sinh…" và M07 không có dòng phí.
+- `POST /api/ops/contracts/{id}/refund` (M07a): giao diện gửi body `{ note }` (ghi chú khi xác nhận trả kho); endpoint hiện bỏ qua body — cần lưu vào activity log. Phản hồi `{ refund }` đang được dùng để hiện số hoàn cọc thực tế.
- 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`.
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/data/appSeed.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/data/appSeed.js
index bbd581b..24a81d2 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/data/appSeed.js
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/data/appSeed.js
@@ -42,7 +42,9 @@ const at = (iso, time) => `${iso}T${time}:00`;
export function createSeedData(t = today()) {
const b015End = addDays(t, 5);
const b015Start = addMonths(b015End, -3);
- const a102End = addMonths(t, 3);
+ // Đơn/hợp đồng A-102 bắt đầu từ ngày mai: đơn đã thanh toán chỉ huỷ được trước ngày bắt đầu thuê (C14a)
+ const a102Start = addDays(t, 1);
+ const a102End = addMonths(a102Start, 3);
return {
user: {
user_id: 101,
@@ -61,7 +63,7 @@ export function createSeedData(t = today()) {
offer_key: "normal-M",
size_label: "Cỡ M · 15 m²",
months: 3,
- start_date: t,
+ start_date: a102Start,
end_date: a102End,
monthly_rate: 1150000,
deposit: 1150000,
@@ -99,7 +101,7 @@ export function createSeedData(t = today()) {
size_m2: 15,
location: "Tầng 1 · Dãy A",
months: 3,
- start_date: t,
+ start_date: a102Start,
end_date: a102End,
monthly_rate: 1150000,
deposit: 1150000,
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js
index ba2bac8..6c71d28 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js
@@ -9,6 +9,7 @@ import {
timeoutLabel,
} from "../../shared/utils/format.js";
import { TICKET_TOPICS, ticketTitle } from "../../shared/utils/status.js";
+import { CANCEL_DEPOSIT_FEE_RATE, CANCEL_POLICY_NAME } from "../../shared/utils/policy.js";
export class DomainError extends Error {
constructor(message, code = "INVALID") {
@@ -70,13 +71,11 @@ const hasPending = (state, contract_id) => ({
});
// C14a · Ước tính hoàn tiền khi huỷ đơn đã thanh toán trước ngày bắt đầu thuê (chế độ trình duyệt).
-// Chính sách D27: phí huỷ cố định 10% tiền cọc; hoàn 100% tiền thuê + 90% tiền cọc.
-// Chế độ API lấy từ GET /api/reservations/{id}/cancel-preview.
-export const CANCEL_DEPOSIT_FEE_RATE = 0.1;
+// Chính sách D27 (shared/utils/policy.js). Chế độ API lấy từ GET /api/reservations/{id}/cancel-preview.
export function cancelPreviewOf(r) {
const paid = r.initial_total || 0;
const fee = Math.round((r.deposit || 0) * CANCEL_DEPOSIT_FEE_RATE);
- return { paid, fee, refund: Math.max(0, paid - fee), policy: "Huỷ trước ngày bắt đầu: phí 10% tiền cọc" };
+ return { paid, fee, refund: Math.max(0, paid - fee), policy: CANCEL_POLICY_NAME };
}
const handlers = {
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/payments/PaymentListPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/payments/PaymentListPage.jsx
index efe1830..4212a5a 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/payments/PaymentListPage.jsx
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/payments/PaymentListPage.jsx
@@ -7,7 +7,8 @@ import { facilityOf } from "../../../app/state/appSelectors.js";
import { useApp } from "../../../app/state/AppProvider.jsx";
// C11fc · Chọn trả phí phát sinh tại quầy → C11fcp. Không làm giảm công nợ cho tới khi nhân viên xác nhận đã thu (S09f).
-function CounterDialog({ rows, contract, facilityName, onClose }) {
+// Backend chưa có API lưu lựa chọn này (BACKEND-TODO S09f) → chỉ ghi trên thiết bị, thông báo nói rõ điều đó.
+function CounterDialog({ rows, contract, facilityName, savedOnServer, onClose }) {
const { dispatch } = useApp();
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
@@ -25,7 +26,10 @@ function CounterDialog({ rows, contract, facilityName, onClose }) {
return (
-
{contractLabel} còn phải thu {money(total)}. Nhân viên sẽ cập nhật khi nhận đủ tiền; chọn phương thức chưa làm giảm công nợ.
+
+ {contractLabel} còn phải thu {money(total)}. Đến quầy {facilityName || "cơ sở"} để thanh toán; nhân viên cập nhật khi nhận đủ tiền. Chọn phương thức chưa làm giảm công nợ.
+ {!savedOnServer && " Lựa chọn này chỉ lưu trên thiết bị của bạn; bạn vẫn có thể thanh toán qua mã QR."}
+
);
@@ -50,13 +54,17 @@ function CounterDialog({ rows, contract, facilityName, onClose }) {
// C11 — Thanh toán & lịch hẹn. Khoản gia hạn đã duyệt có nút "Thanh toán" mở QR PayOS (C11q), trả xong → C11b.
// C11f / C11fb / C11fq: phí phát sinh trả kho trả qua PayOS hoặc tại quầy (C11fc → C11fcp).
export default function PaymentListPage() {
- const { data } = useApp();
+ const { data, mode } = useApp();
const [paying, setPaying] = useState(null);
const [paid, setPaid] = useState(null);
- const [counter, setCounter] = useState(false);
+ const [counter, setCounter] = useState(null); // contract_id đang chọn trả phí tại quầy
const fees = data.ledger.filter((l) => l.fee && ["UNPAID", "AT_COUNTER"].includes(l.status));
const appointments = [...data.appointments].sort((a, b) => a.date.localeCompare(b.date));
- const payable = data.ledger.filter((l) => l.payable && l.status === "UNPAID");
+ // Phí đã chọn "tại quầy" vẫn trả được qua QR nếu khách đổi ý (khoản chưa thu trên hệ thống)
+ const canPay = (l) => l.payable && (l.status === "UNPAID" || (l.fee && l.status === "AT_COUNTER"));
+ const payable = data.ledger.filter(canPay);
+ // Phí chưa thu theo từng hợp đồng: mỗi hợp đồng một nút "tại quầy", không gộp phí của nhiều hợp đồng
+ const unpaidFeeContracts = [...new Set(fees.filter((l) => l.status === "UNPAID").map((l) => l.contract_id))];
const contractOfRow = (l) => data.contracts.find((c) => c.contract_id === l.contract_id);
const subtitle = (l) => {
const c = contractOfRow(l);
@@ -109,7 +117,7 @@ export default function PaymentListPage() {
{[...new Set(fees.map((l) => l.detail).filter(Boolean))].join(" ")} Thanh toán qua PayOS hoặc tại quầy; khoản còn nợ vẫn được theo dõi sau khi trả kho.
- {fees.some((l) => l.status === "UNPAID") && }
+ {unpaidFeeContracts.map((id) => (
+
+ ))}
>
) : (
payable.length > 0 && (
@@ -151,14 +163,19 @@ export default function PaymentListPage() {
onClose={() => setPaying(null)}
/>
)}
- {counter && (
- l.status === "UNPAID")}
- contract={contractOfRow(fees[0]) ? { ...contractOfRow(fees[0]), customer: data.user?.full_name } : { contract_id: fees[0]?.contract_id, customer: data.user?.full_name }}
- facilityName={(() => { const c = contractOfRow(fees[0]); return c ? facilityOf(data, c.facility_id, c.facility_name)?.name : null; })()}
- onClose={() => setCounter(false)}
- />
- )}
+ {counter && (() => {
+ const rows = fees.filter((l) => l.status === "UNPAID" && l.contract_id === counter);
+ const c = contractOfRow({ contract_id: counter });
+ return (
+ setCounter(null)}
+ />
+ );
+ })()}
);
}
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/reservations/ReservationListPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/reservations/ReservationListPage.jsx
index 4e84b36..0b83ba0 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/reservations/ReservationListPage.jsx
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/reservations/ReservationListPage.jsx
@@ -1,18 +1,24 @@
import React, { useEffect, useState } from "react";
import { EmptyInline } from "../../../shared/components/Inline.jsx";
import { Button, Field, LinkButton, Modal, Notice, PageHeader } from "../../../shared/components/UI.jsx";
-import { dateLabel, money, shortCode } from "../../../shared/utils/format.js";
+import { dateLabel, money, shortCode, today } from "../../../shared/utils/format.js";
+import { CANCEL_FEE_LABEL, CANCEL_POLICY_HINT, CANCEL_REFUND_NOTE } from "../../../shared/utils/policy.js";
import { shortName } from "../../../shared/hooks/useBrowserEvents.js";
import { RESERVATION_STATUS } from "../../../shared/utils/status.js";
import { facilityOf, sortedReservations } from "../../../app/state/appSelectors.js";
import { useApp } from "../../../app/state/AppProvider.jsx";
-// Đơn khách tự huỷ được: chờ thanh toán, hoặc đã thanh toán nhưng chưa nhận kho (cùng quy tắc backend:
-// ReservationService.CancelReservationAsync nhận PENDING_PAYMENT / CONFIRMED)
-export function canCancel(data, r) {
- if (r.api_status) return ["PENDING_PAYMENT", "CONFIRMED", "PAID"].includes(r.api_status) && r.status !== "CANCELLED";
+// Đơn khách tự huỷ được — cùng quy tắc backend ReservationService.CancelReservationAsync:
+// PENDING_PAYMENT / PENDING_AT_FACILITY (chưa thu tiền) huỷ lúc nào cũng được;
+// CONFIRMED (đã thanh toán) chỉ huỷ trước ngày bắt đầu thuê, từ ngày bắt đầu dùng quy trình trả kho.
+const CANCELLABLE_API = ["PENDING_PAYMENT", "PENDING_AT_FACILITY", "CONFIRMED"];
+const beforeStart = (r) => !r.start_date || today() < r.start_date;
+export function canCancel(data, r, now = today()) {
+ if (r.status === "CANCELLED") return false;
+ const started = r.start_date && now >= r.start_date;
+ if (r.api_status) return CANCELLABLE_API.includes(r.api_status) && !(r.api_status === "CONFIRMED" && started);
if (r.status === "PENDING_PAYMENT") return true;
- if (r.status !== "CONFIRMED") return false;
+ if (r.status !== "CONFIRMED" || started) return false;
return !data.contracts.some((c) => c.reservation_id === r.reservation_id && c.handed_over);
}
@@ -24,7 +30,6 @@ function statusCell(r) {
if (isRefunded(r)) return Đã huỷ · Đã hoàn tiền;
return RESERVATION_STATUS[r.status][0];
}
-export const CANCEL_POLICY_HINT = "Huỷ trước ngày bắt đầu thuê: phí huỷ 10% tiền cọc, hoàn 100% tiền thuê và 90% cọc. Từ ngày bắt đầu thuê, sử dụng quy trình trả kho.";
// C14a — Hộp thoại huỷ đơn & hoàn tiền
function CancelDialog({ r, onDone, onClose }) {
@@ -33,12 +38,24 @@ function CancelDialog({ r, onDone, onClose }) {
const [reason, setReason] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
+ // Backend từ chối xem trước (vd. đã đến ngày bắt đầu thuê) → hiện lý do, không cho bấm huỷ
+ const [blocked, setBlocked] = useState("");
const paid = r.status === "CONFIRMED";
const f = facilityOf(data, r.facility_id, r.facility_name);
useEffect(() => {
let alive = true;
- if (paid) services?.cancelPreview(r).then((res) => alive && setPreview(res.ok ? res.preview : false));
+ if (paid && !beforeStart(r)) setBlocked("Đã đến ngày bắt đầu thuê nên không huỷ đặt chỗ được. Vui lòng đăng ký trả kho để được xử lý hoàn cọc theo chính sách.");
+ else if (paid)
+ services?.cancelPreview(r).then((res) => {
+ if (!alive) return;
+ if (res.ok) setPreview(res.preview);
+ else if (res.unsupported) setPreview(false);
+ else {
+ setPreview(false);
+ setBlocked(res.error || "Không tính được số tiền hoàn. Vui lòng thử lại sau.");
+ }
+ });
return () => {
alive = false;
};
@@ -63,7 +80,7 @@ function CancelDialog({ r, onDone, onClose }) {
Đã thanh toán (tiền thuê {r.months} tháng + cọc)
{money(preview?.paid ?? r.initial_total)}
-
Phí huỷ (10% tiền cọc)
+
{CANCEL_FEE_LABEL}
{preview ? `− ${money(preview.fee)}` : preview === false ? "Theo chính sách hiện hành" : "Đang tính…"}
Xác nhận trả kho sẽ kết thúc hợp đồng. Khoản chưa thanh toán vẫn được giữ để tiếp tục thu hồi.
+
Xác nhận trả kho sẽ kết thúc hợp đồng. Số hoàn cọc chính thức do hệ thống tính theo chính sách (gồm phí quá hạn theo số ngày trễ); khoản còn nợ vẫn được giữ để tiếp tục thu hồi.
-
+
);
@@ -107,14 +120,16 @@ export function ContractListPage({ query }) {
ret={ops.returns.find((x) => x.contract === sel.id)}
onClose={() => setReturning(false)}
onConfirm={async (note) => {
- setReturning(false);
- await run("CONFIRM_REFUND", { id: sel.id, note }, "Đã xác nhận trả kho");
+ // Giữ hộp thoại (và ghi chú) khi lưu thất bại để quản lý kiểm tra rồi thử lại
+ const res = await run("CONFIRM_REFUND", { id: sel.id, note }, "Đã xác nhận trả kho");
+ if (res.ok) setReturning(false);
+ return res.ok;
}}
/>
)}
{/* Figma M07: lối vào M08 hoàn tiền đơn huỷ */}
Hoàn tiền đơn huỷ{(ops.refunds || []).some((r) => r.status === "PENDING") ? ` (${ops.refunds.filter((r) => r.status === "PENDING").length})` : ""}
- {sel.reminders.length > 0 && (
+ {(sel.reminders || []).length > 0 && (
{sel.reminders.map((r, i) =>
{dateTimeLabel(r.at)}{r.text}
)}
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/CancellationRefundPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/CancellationRefundPage.jsx
index 96845c5..8d777cd 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/CancellationRefundPage.jsx
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/CancellationRefundPage.jsx
@@ -3,13 +3,14 @@ import { Button, Field, LinkButton, Modal, Notice } from "../../../shared/compon
import { dateLabel, dateTimeLabel, money } from "../../../shared/utils/format.js";
import { useOps } from "../../facility-operations/state/FacilityOperationsProvider.jsx";
import { PageHeaderBlock } from "../components/PageHeaderBlock.jsx";
+import { CANCEL_FEE_LABEL, CANCEL_REFUND_SHORT } from "../../../shared/utils/policy.js";
// Figma M08 / M08a / M08a2 / M08-kết thúc / M07e: hoàn tiền đơn khách huỷ trước ngày bắt đầu thuê (D27).
// Quản lý chuyển khoản thủ công ngoài hệ thống rồi xác nhận ở đây; thao tác không tự chuyển tiền.
// Khách trả qua PayOS nên chỉ hoàn bằng chuyển khoản (Figma M08a ẩn lựa chọn tiền mặt)
const METHODS = [["BANK_TRANSFER", "Chuyển khoản thủ công về tài khoản khách đã thanh toán"]];
const shortId = (id) => id.replace(/^SS-\d{8}-/, "SS-");
-const amountLabel = (r) => (r.fee ? `${money(r.amount)} (100% tiền thuê + 90% cọc)` : money(r.amount));
+const amountLabel = (r) => (r.fee ? `${money(r.amount)} (${CANCEL_REFUND_SHORT})` : money(r.amount));
function RefundDialog({ refund, onClose, onDone }) {
const { run } = useOps();
@@ -32,7 +33,7 @@ function RefundDialog({ refund, onClose, onDone }) {
Phương thức: Tiền mặt tại quầy. Khoản thu này thanh toán công nợ hiện có; trạng thái hợp đồng đã kết thúc được giữ nguyên.{f.due ? ` Hạn thanh toán: ${dateLabel(f.due)}.` : ""}
{paid ?
Đã thu đủ {money(f.amount)}.
: }
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/PaymentConfirmationPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/PaymentConfirmationPage.jsx
index 2007aba..6c35cee 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/PaymentConfirmationPage.jsx
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/PaymentConfirmationPage.jsx
@@ -6,14 +6,15 @@ import { PAYMENT_STATE } from "../../facility-operations/state/facilityOperation
import { useOps } from "../../facility-operations/state/FacilityOperationsProvider.jsx";
import { Facts } from "../../facility-operations/components/FacilityOperationsComponents.jsx";
+// Backend (OpsPaymentDto) chưa trả tách tiền thuê / cọc → ước tính theo D-cọc = 1 tháng thuê, đánh dấu estimated
export function paymentParts(p) {
- if (p.rent != null && p.deposit != null) return { months: p.months || null, rent: Number(p.rent), deposit: Number(p.deposit) };
+ if (p.rent != null && p.deposit != null) return { months: p.months || null, rent: Number(p.rent), deposit: Number(p.deposit), estimated: false };
const [y1, m1, d1] = String(p.start || "").split("-").map(Number);
const [y2, m2, d2] = String(p.end || "").split("-").map(Number);
const months = y1 && y2 ? Math.max(1, (y2 - y1) * 12 + (m2 - m1) - (d2 < d1 ? 1 : 0)) : null;
- if (!months) return { months: null, rent: null, deposit: null };
+ if (!months) return { months: null, rent: null, deposit: null, estimated: true };
const monthly = Math.round(p.amount / (months + 1));
- return { months, rent: p.amount - monthly, deposit: monthly };
+ return { months, rent: p.amount - monthly, deposit: monthly, estimated: true };
}
export const HOLD_HOURS = 24;
@@ -52,12 +53,12 @@ export function PaymentConfirmationPage({ query }) {
["Số tiền cần thu", {money(p.amount)}],
["Hình thức thu", "Tiền mặt / chuyển khoản tại quầy"],
["Giữ chỗ đến", holdUntil ? dateTimeLabel(holdUntil) : "—"],
- ["Gồm", parts.months ? `Thuê ${parts.months} tháng ${money(parts.rent)} + cọc ${money(parts.deposit)}` : p.offer],
+ ["Gồm", parts.months ? `Thuê ${parts.months} tháng ${money(parts.rent)} + cọc ${money(parts.deposit)}${parts.estimated ? " (ước tính, cọc bằng 1 tháng thuê)" : ""}` : p.offer],
]}
/>
{done ? (
- {PAYMENT_STATE[p.status][0]}{p.note ? `: ${p.note}` : ""}.
+ {(PAYMENT_STATE[p.status] || [`Trạng thái ${p.status}`])[0]}{p.note ? `: ${p.note}` : ""}.
) : (
<>
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/returns/ReturnInspectionPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/returns/ReturnInspectionPage.jsx
index 54c77e9..6b8a326 100644
--- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/returns/ReturnInspectionPage.jsx
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/returns/ReturnInspectionPage.jsx
@@ -5,16 +5,17 @@ import { dateTimeLabel, money } from "../../../shared/utils/format.js";
import { go, href } from "../../../app/router.js";
import { useOps } from "../../facility-operations/state/FacilityOperationsProvider.jsx";
-const FEES = [["damage_fee", "Phí hư hỏng"], ["cleaning_fee", "Phí vệ sinh"], ["overdue_fee", "Phí quá hạn"]];
+// Phí quá hạn không nhập tay: backend tự tính theo số ngày trễ khi quản lý xác nhận trả kho (ConfirmRefundAsync)
+const FEES = [["damage_fee", "Phí hư hỏng"], ["cleaning_fee", "Phí vệ sinh"]];
const toNumber = (v) => Number(String(v ?? "").replace(/[^\d-]/g, "") || 0);
export const PROPOSALS = ["Chờ vệ sinh / kiểm tra trước khi cho thuê lại", "Sẵn sàng cho thuê lại", "Cần bảo trì trước khi cho thuê lại"];
export function ReturnInspectionPage({ query }) {
- const { ops, run } = useOps();
+ const { ops, run, source } = useOps();
const list = ops.returns.filter((r) => r.status === "SCHEDULED");
const r = query.get("id") ? ops.returns.find((x) => x.id === query.get("id")) : list[0] || ops.returns[0];
- const [form, setForm] = useState({ items: "Đã chuyển hết đồ khỏi kho", walls: "Không ghi nhận hư hỏng mới", keys: "Đã nhận lại 01 chìa khóa", proposal: PROPOSALS[0], damage_fee: "0", cleaning_fee: "0", overdue_fee: "0", fee_reason: "" });
+ const [form, setForm] = useState({ items: "Đã chuyển hết đồ khỏi kho", walls: "Không ghi nhận hư hỏng mới", keys: "Đã nhận lại 01 chìa khóa", proposal: PROPOSALS[0], damage_fee: "0", cleaning_fee: "0", cleaning_required: false, fee_reason: "" });
const [err, setErr] = useState("");
if (!r)
return (
@@ -33,13 +34,18 @@ export function ReturnInspectionPage({ query }) {
const fees = Object.fromEntries(FEES.map(([k]) => [k, toNumber(form[k])]));
if (Object.values(fees).some((v) => !Number.isFinite(v) || v < 0)) return setErr("Phí phát sinh phải là số tiền không âm.");
if (Object.values(fees).some((v) => v > 0) && !form.fee_reason.trim()) return setErr("Nhập lý do thu phí.");
- const out = await run("SUBMIT_RETURN", { id: r.id, report: { ...form, ...fees, fee_reason: form.fee_reason.trim() } }, "Đã gửi biên bản trả kho cho quản lý");
+ const report = { ...form, ...fees, cleaning_required: Boolean(form.cleaning_required), fee_reason: form.fee_reason.trim() };
+ const out = await run("SUBMIT_RETURN", { id: r.id, report }, "Đã gửi biên bản trả kho cho quản lý");
if (!out.ok) return setErr(out.shown || out.cancelled ? "" : out.error);
go("staff/return");
};
const submitted = r.status === "SUBMITTED";
- const report = submitted ? { ...form, ...r.report } : form;
+ // Biên bản đã gửi: chỉ hiện phí máy chủ trả về, không lấy lại số đang gõ trên form
+ const feesSaved = submitted && FEES.some(([k]) => r.report?.[k] != null);
+ const report = submitted ? { ...form, ...Object.fromEntries(FEES.map(([k]) => [k, "0"])), cleaning_required: false, fee_reason: "", ...r.report } : form;
const feeTotal = FEES.reduce((sum, [k]) => sum + (toNumber(report[k]) || 0), 0);
+ const deposit = Number(r.deposit) || 0;
+ const owed = (Number(r.unpaid) || 0) + feeTotal;
return (
← Danh sách trả kho
@@ -64,13 +70,21 @@ export function ReturnInspectionPage({ query }) {
Phí quá hạn do hệ thống tự tính theo số ngày trễ hạn khi quản lý xác nhận trả kho, không nhập tại đây.
set("fee_reason", e.target.value)} />
+ {submitted && !feesSaved && source === "api" && (
+ Máy chủ chưa lưu phí phát sinh của biên bản này. Báo quản lý cơ sở kiểm tra lại phí trước khi xác nhận trả kho.
+ )}
{err && {err}}
{submitted ? Đã gửi biên bản lúc {dateTimeLabel(r.submitted_at)}. Chờ quản lý xác nhận trả kho. : }
@@ -82,8 +96,15 @@ export function ReturnInspectionPage({ query }) {
{label} đề xuất: {money(toNumber(report[k]))}
))}
-
Tổng khoản phải thu: {money(r.unpaid + feeTotal)}
-
Nhân viên ghi nhận tình trạng và phí. Quản lý xác nhận trả kho tại M07; khoản chưa thanh toán tiếp tục được theo dõi.
+
Tổng khoản phải thu: {money(owed)}
+ {deposit > 0 && (
+
+ Tiền cọc đang giữ: {money(deposit)}
+
+ {owed > deposit ? `Phần vượt cọc thành công nợ: ${money(owed - deposit)}` : `Dự kiến hoàn cọc: ${money(deposit - owed)}`}
+
+ )}
+
Nhân viên ghi nhận tình trạng và phí. Quản lý xác nhận trả kho tại M07; số hoàn cọc chính thức do hệ thống tính theo chính sách khi xác nhận, khoản chưa thanh toán tiếp tục được theo dõi.
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/utils/policy.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/utils/policy.js
new file mode 100644
index 0000000..d4befe8
--- /dev/null
+++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/utils/policy.js
@@ -0,0 +1,15 @@
+// Chính sách huỷ đơn / hoàn tiền dùng chung cho C14a (khách), M07 và M08 (quản lý).
+// Khi nhóm chốt bảng chính sách mới (DECISIONS.md), chỉ sửa ở file này.
+// Số tiền thực tế luôn ưu tiên lấy từ backend (cancel-preview, board); các giá trị dưới đây chỉ dùng để hiển thị
+// nhãn và tính dự phòng khi chạy không backend.
+
+// D27: phí huỷ cố định = 10% tiền cọc; hoàn 100% tiền thuê + phần cọc còn lại
+export const CANCEL_DEPOSIT_FEE_RATE = 0.1;
+
+const pct = (x) => `${Math.round(x * 100)}%`;
+
+export const CANCEL_FEE_LABEL = `Phí huỷ (${pct(CANCEL_DEPOSIT_FEE_RATE)} tiền cọc)`;
+export const CANCEL_REFUND_SHORT = `100% tiền thuê + ${pct(1 - CANCEL_DEPOSIT_FEE_RATE)} cọc`;
+export const CANCEL_POLICY_NAME = `Huỷ trước ngày bắt đầu: phí ${pct(CANCEL_DEPOSIT_FEE_RATE)} tiền cọc`;
+export const CANCEL_POLICY_HINT = `Huỷ trước ngày bắt đầu thuê: phí huỷ ${pct(CANCEL_DEPOSIT_FEE_RATE)} tiền cọc, hoàn 100% tiền thuê và ${pct(1 - CANCEL_DEPOSIT_FEE_RATE)} cọc. Từ ngày bắt đầu thuê, sử dụng quy trình trả kho.`;
+export const CANCEL_REFUND_NOTE = `Bạn được hoàn 100% tiền thuê và ${pct(1 - CANCEL_DEPOSIT_FEE_RATE)} tiền cọc trong 3–5 ngày làm việc. Quản lý cơ sở chuyển khoản thủ công và cập nhật trạng thái hoàn tiền.`;
diff --git a/progress.md b/progress.md
index f63f0b5..829e814 100644
--- a/progress.md
+++ b/progress.md
@@ -1,3 +1,22 @@
+## 2026-10-25 — Sửa lỗi FE các màn C11, C14a, S04, S09, M07 (kế hoạch 25–31/10, phần Thắng)
+
+- **Bản gốc:** `main` c5aa79a (đã gộp PR #29). Chỉ sửa frontend; không sửa backend, DB, migration.
+- **C14a:** `canCancel` khớp `ReservationService.CancelReservationAsync` (PENDING_PAYMENT / PENDING_AT_FACILITY / CONFIRMED, bỏ PAID);
+ đơn đã thanh toán không huỷ được từ ngày bắt đầu thuê; lỗi `cancel-preview` hiện lý do và khoá nút huỷ; huỷ một đơn không còn ẩn nút huỷ đơn khác.
+- **Chính sách huỷ/hoàn:** gom chữ và tỷ lệ về `src/shared/utils/policy.js` (C14a, M08, reducer) — chốt chính sách mới chỉ sửa một file.
+- **C11:** nút "Thanh toán phí tại quầy" tách theo từng hợp đồng (trước gộp phí nhiều hợp đồng vào HĐ đầu tiên);
+ chế độ API báo rõ lựa chọn chỉ lưu trên thiết bị (backend chưa có API); phí đã chọn "tại quầy" vẫn trả được qua QR.
+- **S04:** bỏ ô phí quá hạn (BE tự tính khi xác nhận, tránh tính trùng); thêm "Kho cần vệ sinh" (`cleaningRequired`);
+ hiện tiền cọc và dự kiến hoàn/công nợ; biên bản đã gửi chỉ hiện phí máy chủ trả về, báo lỗi nếu máy chủ chưa lưu phí.
+- **S09:** trạng thái lạ không làm crash; S09f không crash khi thiếu `items`; "Gồm" ghi rõ là ước tính; thông báo cụ thể khi BE chưa có `/api/ops/fees/{id}/confirm`.
+- **M07:** hộp thoại xác nhận trả kho hiện tiền cọc, trừ cọc, hoàn/còn nợ dự kiến; gửi kèm ghi chú; giữ hộp thoại khi lưu lỗi;
+ màn kết quả dùng số `refund` backend trả về thay vì số ước tính phía giao diện; chặn crash khi thiếu `reminders`.
+- **Seed:** đơn/hợp đồng A-102 (SS-0142) bắt đầu từ ngày mai để vẫn có đơn huỷ được theo quy tắc mới (test render C14 cần nút "Huỷ đơn").
+- **Kiểm chứng (local, không backend):** `check:structure` PASS; `npm test` 81/81; `test:business` 9/9; `test:render` 97 route PASS; `build` PASS;
+ Chromium chạy tay C11, C14a, S09, luồng S04 có phí → M07a xác nhận (còn nợ 510.000 đ khớp hai bên).
+- **Chưa kiểm chứng:** chưa chạy .NET/SQL Server/PayOS thật. Phần còn chờ backend ghi ở `BACKEND-TODO.md` mục "Phí phát sinh khi trả kho và công nợ" và "M08":
+ lưu phí S04, `POST /api/payments/{id}/payos`, API chọn trả tại quầy, `feeCollections` + `/api/ops/fees/{id}/confirm`, `refunds` trên board, lưu ghi chú M07a.
+
## 2026-10-15 — F31: Frontend vận hành KD, không sửa backend/database
- Bản gốc: SSFRMS(1).zip mới; API: operations-api(3).md; thiết kế B01–B05 section 436:13803.