From e0136bd006e59f002fc836d0afb328add15da0c8 Mon Sep 17 00:00:00 2001 From: Vector Date: Sun, 25 Oct 2026 09:28:37 +0700 Subject: [PATCH] =?UTF-8?q?fix(fe):=20s=E1=BB=ADa=20l=E1=BB=97i=20C11,=20C?= =?UTF-8?q?14a,=20S04,=20S09,=20M07?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SafeSpace-Customer-UI/BACKEND-TODO.md | 5 +- .../src/app/data/appSeed.js | 8 ++-- .../src/app/state/appReducer.js | 7 ++- .../customer/payments/PaymentListPage.jsx | 47 +++++++++++++------ .../reservations/ReservationListPage.jsx | 42 ++++++++++++----- .../api/facilityOperationsApi.js | 3 +- .../state/FacilityOperationsProvider.jsx | 9 ++-- .../state/facilityOperationsReducer.js | 2 +- .../utils/opsConfirmation.js | 18 +++++-- .../manager/contracts/ContractListPage.jsx | 29 +++++++++--- .../refunds/CancellationRefundPage.jsx | 7 +-- .../staff/payments/FeeCollectionPage.jsx | 3 +- .../payments/PaymentConfirmationPage.jsx | 11 +++-- .../staff/returns/ReturnInspectionPage.jsx | 37 +++++++++++---- .../src/shared/utils/policy.js | 15 ++++++ progress.md | 19 ++++++++ 16 files changed, 195 insertions(+), 67 deletions(-) create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/utils/policy.js 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 ( ); @@ -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() { {(LEDGER_STATUS[l.status] || [l.status])[0]} {payable.length > 0 && ( - {l.payable && l.status === "UNPAID" && } + {canPay(l) && } )} @@ -131,7 +139,11 @@ export default function PaymentListPage() { ) : fees.length > 0 ? ( <>

{[...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…"}
@@ -78,11 +95,12 @@ function CancelDialog({ r, onDone, onClose }) { setReason(e.target.value)} /> - {paid &&

Bạn được hoàn 100% tiền thuê và 90% 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.

} + {paid && !blocked &&

{CANCEL_REFUND_NOTE}

} + {blocked && {blocked}} {error && {error}}
- +
); @@ -125,7 +143,7 @@ export default function ReservationListPage() {
Xem đơn - {!done && canCancel(data, r) && ( + {canCancel(data, r) && ( )}
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js index 13357b8..3bcb48d 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js @@ -67,7 +67,8 @@ export const OPS_ACTIONS = { ALLOCATE: ({ id, unit }) => ["POST", `/api/ops/allocations/${enc(id)}`, { unitCode: unit }], ASSIGN: ({ id, staff }) => ["PUT", `/api/ops/assignments/${enc(id)}`, { staffId: staff }], REMIND: ({ id, note }) => ["POST", `/api/ops/contracts/${enc(id)}/reminders`, { note: note || "" }], - CONFIRM_REFUND: ({ id }) => ["POST", `/api/ops/contracts/${enc(id)}/refund`], + // M07a · Ghi chú gửi kèm; backend hiện chưa đọc body (BACKEND-TODO: lưu ghi chú xác nhận trả kho) + CONFIRM_REFUND: ({ id, note }) => ["POST", `/api/ops/contracts/${enc(id)}/refund`, { note: String(note || "").trim() || null }], // M08 · D27: xác nhận đã chuyển khoản hoàn cho đơn khách huỷ (backend chưa nhận phương thức / mã giao dịch → gửi kèm để lưu sau) CONFIRM_RESERVATION_REFUND: ({ id, method, transaction_ref }) => ["POST", `/api/ops/reservations/${enc(id)}/refund`, { method: method || "BANK_TRANSFER", transactionRef: String(transaction_ref || "").trim() || null }], // M02b / M02c · CreateStorageUnitRequest / UpdateStorageUnitRequest (OpsDtos.cs). Backend chưa nhận loại kho + cỡ theo tên: diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx index bd5a238..fbebc37 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx @@ -27,6 +27,7 @@ function readOps() { const UNSUPPORTED = { UPDATE_UNIT_STATUS: "Máy chủ chưa hỗ trợ đổi trạng thái ô kho. Cập nhật backend có PUT /api/staff/units/{mã}/status rồi thử lại.", + CONFIRM_FEE_COLLECTION: "Máy chủ chưa hỗ trợ ghi nhận thu phí tại quầy (POST /api/ops/fees/{mã}/confirm). Chưa lưu khoản thu này; không thu thêm tiền của khách.", }; // Nhật ký / thông báo trong ca chỉ giữ ở trình duyệt (backend chưa có API thông báo) @@ -103,13 +104,14 @@ export function OpsProvider({ children, notify, mode = "local", onApiError, role async (type, payload, message) => { if (source === "api" && type !== "MARK_READ") { try { - await callAction(type, payload); + const res = await callAction(type, payload); await reload(); if (message) { commit(appendLog(ref.current, message, null)); notify?.(message); } - return { ok: true }; + // Giữ số liệu backend trả về (vd. số tiền hoàn cọc thực tế) để màn kết quả hiển thị đúng + return { ok: true, ...(res && typeof res === "object" && !Array.isArray(res) ? res : {}) }; } catch (e) { onApiError?.(e); // Route chưa có trên backend: ASP.NET trả 404/405 không kèm nội dung → báo rõ thay vì "Không tìm thấy dữ liệu." @@ -169,7 +171,8 @@ export function OpsProvider({ children, notify, mode = "local", onApiError, role await showOutcome({ kind: "failure", ...failure, detail: result.error && result.error !== failure.text ? result.error : "" }); return { ...result, shown: true }; } - if (spec.success) await showOutcome({ kind: "success", ...spec.success }); + const success = typeof spec.success === "function" ? spec.success(result) : spec.success; + if (success) await showOutcome({ kind: "success", ...success }); return result; } finally { activeAction.current = false; diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/facilityOperationsReducer.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/facilityOperationsReducer.js index 7199361..96746a8 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/facilityOperationsReducer.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/facilityOperationsReducer.js @@ -184,7 +184,7 @@ const ACTIONS = { contracts: patch(state.contracts, id, () => ({ state: "CLOSED", due: debt ? `Đã trả kho · Còn nợ ${money(debt)}` : `Hoàn cọc ${money(refund)} sau khi trừ khoản còn nợ` })), units: r ? patchUnit(state.units, r.unit, () => ({ status: "EMPTY", tenant: null, end: null })) : state.units, }; - return { state: addLog(next, now, `Đã xác nhận hoàn cọc ${money(refund)} · ${id}`, "manager/contracts", "MANAGER"), result: { id, refund } }; + return { state: addLog(next, now, `Đã xác nhận hoàn cọc ${money(refund)} · ${id}`, "manager/contracts", "MANAGER"), result: { id, refund, debt } }; }, // S09f · Nhân viên xác nhận đã thu phí phát sinh / công nợ tại quầy diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/opsConfirmation.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/opsConfirmation.js index 5276574..6d2ce13 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/opsConfirmation.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/opsConfirmation.js @@ -12,7 +12,8 @@ export function settleReturn(ret, contract) { return { refund: Math.max(0, deposit - owed), debt: Math.max(0, owed - deposit), owed }; } const GENERIC_FAIL = "Chưa ghi nhận thay đổi. Giữ nội dung đã nhập để kiểm tra và thử lại."; -const FEE_KEYS = [["damage_fee", "Hư hỏng"], ["cleaning_fee", "Vệ sinh"], ["overdue_fee", "Quá hạn"]]; +// Phí quá hạn do backend tự tính khi xác nhận trả kho, không có trong biên bản S04 +const FEE_KEYS = [["damage_fee", "Hư hỏng"], ["cleaning_fee", "Vệ sinh"]]; export function opsConfirmation(type, payload, ops) { const find = key => (ops[key] || []).find(x => x.id === payload.id); @@ -149,10 +150,21 @@ export function opsConfirmation(type, payload, ops) { case "CONFIRM_REFUND": { const c = find("contracts"); const ret = (ops.returns || []).find((x) => x.contract === payload.id); - const { refund, debt } = settleReturn(ret, c); + const estimate = settleReturn(ret, c); return { confirm: false, - success: { title: `Đã xác nhận trả kho${debt ? ` · Còn nợ ${money(debt)}` : ""}`, text: `Hợp đồng ${payload.id} đã hoàn tất trả kho.${refund ? ` Hoàn cọc ${money(refund)} sau khi trừ các khoản phải thu (D27).` : ""}`, action: "Đã hiểu" }, + // Ưu tiên số hoàn cọc backend tính (RefundPolicy: trả sớm, phí quá hạn tự tính…); không có thì dùng ước tính phía giao diện + success: (result = {}) => { + const fromServer = typeof result.refund === "number"; + const refund = fromServer ? result.refund : estimate.refund; + const knownDebt = typeof result.debt === "number"; + const debt = knownDebt ? result.debt : fromServer ? 0 : estimate.debt; + return { + title: `Đã xác nhận trả kho${debt ? ` · Còn nợ ${money(debt)}` : ""}`, + text: `Hợp đồng ${payload.id} đã hoàn tất trả kho.${refund ? ` Hoàn cọc ${money(refund)} sau khi trừ các khoản phải thu (D27).` : " Không có tiền cọc được hoàn."}${fromServer && !knownDebt ? " Khoản còn nợ (nếu có) tiếp tục được theo dõi tại danh sách hợp đồng." : ""}`, + action: "Đã hiểu", + }; + }, failure: { title: "Không xác nhận trả kho được", text: GENERIC_FAIL }, }; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx index 791bfd7..d0ed566 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx @@ -4,6 +4,7 @@ import { dateLabel, dateTimeLabel, daysBetween, money, today } from "../../../sh import { go, qs } from "../../../app/router.js"; import { useOps } from "../../facility-operations/state/FacilityOperationsProvider.jsx"; import { PageHeaderBlock } from "../components/PageHeaderBlock.jsx"; +import { settleReturn } from "../../facility-operations/utils/opsConfirmation.js"; export const CONTRACT_STATE = (c) => c.state === "OVERDUE" @@ -18,8 +19,10 @@ export const CONTRACT_STATE = (c) => function ReturnConfirmDialog({ contract, ret, onClose, onConfirm }) { const [note, setNote] = useState(""); const [busy, setBusy] = useState(false); - const fees = Number(ret?.report?.cleaning_fee || 0) + Number(ret?.report?.damage_fee || 0) + Number(ret?.report?.overdue_fee || 0); const unpaid = Number(ret?.unpaid ?? contract.amount ?? 0); + // Ước tính khấu trừ cọc (D27); số chính thức do backend tính khi xác nhận (gồm phí quá hạn tự tính, trả sớm…) + const { owed, refund, debt } = settleReturn(ret, contract); + const deposit = Number(ret?.deposit || 0); return (

{[contract.customer, `Kho ${contract.unit}`, ret?.appointment ? `trả kho ${dateLabel(ret.appointment)}` : null].filter(Boolean).join(" · ")}

@@ -29,16 +32,26 @@ function ReturnConfirmDialog({ contract, ret, onClose, onConfirm }) { {[["damage_fee", "Phí hư hỏng"], ["cleaning_fee", "Phí vệ sinh"], ["overdue_fee", "Phí quá hạn"]].filter(([k]) => Number(ret?.report?.[k]) > 0).map(([k, label]) => (
{label} (biên bản S04)
{money(Number(ret.report[k]))}
))} -
Tổng còn phải thu
{money(unpaid + fees)}
+
Tổng còn phải thu
{money(owed)}
+ {deposit > 0 && ( + <> +
Tiền cọc đang giữ
{money(deposit)}
+
Trừ vào cọc (dự kiến)
− {money(Math.min(deposit, owed))}
+
+
{debt > 0 ? "Còn nợ sau khi trừ cọc (dự kiến)" : "Hoàn cọc cho khách (dự kiến)"}
+
0 ? "tone-red" : "tone-green"}`}>{money(debt > 0 ? debt : refund)}
+
+ + )}
setNote(e.target.value)} /> -

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 }) {
Đã thanh toán qua PayOS
{money(refund.paid)}
-
Phí huỷ (10% tiền cọc)
{refund.fee ? `− ${money(refund.fee)}` : money(0)}
+
{CANCEL_FEE_LABEL}
{refund.fee ? `− ${money(refund.fee)}` : money(0)}
Số tiền hoàn
{money(refund.amount)}
@@ -104,7 +105,7 @@ export function CancellationRefundPage() {
Đã thanh toán (tiền thuê + cọc)
{money(next.paid)}
Tiền thuê
{money(next.rent)}
Tiền cọc
{money(next.deposit)}
-
Phí huỷ (10% tiền cọc)
{money(next.fee)}
+
{CANCEL_FEE_LABEL}
{money(next.fee)}
Hoàn cho khách
{money(next.amount)}
)} diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/FeeCollectionPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/FeeCollectionPage.jsx index 147ba3c..3aa09c7 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/FeeCollectionPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/FeeCollectionPage.jsx @@ -19,6 +19,7 @@ export function FeeCollectionPage({ query }) { ); const paid = f.status !== "PENDING"; + const items = Array.isArray(f.items) ? f.items : []; const submit = async () => { const r = await run("CONFIRM_FEE_COLLECTION", { id: f.id }, `Đã thu ${money(f.amount)} · ${f.contract}`); if (r.ok) go("staff/reconcile"); @@ -34,7 +35,7 @@ export function FeeCollectionPage({ query }) {

{f.contract} · {f.customer} · Kho {f.unit}

-

{f.items.map(([label, amount]) => `${label}: ${money(amount)}`).join(" · ")}. Tổng cần thu: {money(f.amount)}.

+

{items.map(([label, amount]) => `${label}: ${money(amount)}`).join(" · ")}{items.length ? ". " : ""}Tổng cần thu: {money(f.amount)}.

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 }) {
{FEES.map(([k, label]) => ( - set(k, e.target.value)} /> + set(k, e.target.value)} /> ))}
+ +

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.