diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/incidents/IncidentComponents.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/incidents/IncidentComponents.jsx index 2b89bfe..da8fa27 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/incidents/IncidentComponents.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/incidents/IncidentComponents.jsx @@ -37,5 +37,5 @@ export function useIncidentChange(load, contextKey) { const ask=value=>{if(!load.busy&&!load.needsRefresh)setPending({...value,stage:"confirm"});}; const close=()=>{if(!load.busy&&!guard.current)setPending(null);}; const confirm=async()=>{if(pending.stage!=="confirm"){close();return;}if(guard.current)return;guard.current=true;try{const result=await load.run(pending.id,pending.action,pending.payload);setPending(p=>p?{...p,stage:result.ok?"success":"failure",error:result.error}:null);}finally{guard.current=false;}}; - return [pending&&,ask]; + return [pending&&,ask]; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/settlements/settlementModel.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/settlements/settlementModel.js index c4ee631..ce728ce 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/settlements/settlementModel.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/settlements/settlementModel.js @@ -11,6 +11,8 @@ export const knownMoney=value=>typeof value==="number"&&Number.isFinite(value)&& export function actualVnTime(value,now=new Date()) { const at=typeof value==="string"&&/^\d{4}-\d{2}-\d{2}T.*Z$/.test(value)&&Number.isFinite(Date.parse(value))?new Date(value).toISOString():parseVnDeadline(value);if(Date.parse(at)>now.getTime())throw new Error("Thời gian thực tế không được ở tương lai.");return at; } +/** D42/D47: khoản hoàn khách chọn nhận tiền mặt — quản lý duyệt & giao ở "Hoàn tiền mặt tại quầy", nhân viên chi. */ +export const isCashRefund = (r) => r?.method === "CASH" || r?.bankName === "CASH"; export function transferProof(item,payload,now=new Date()) { if(!item||item.status!=="PENDING"||!knownMoney(item.amount)||item.amount<=0)throw new Error("Khoản hoàn chưa có số tiền hợp lệ hoặc không còn chờ xử lý."); if(!item.customer)throw new Error("Thiếu tên khách trên hợp đồng."); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/pendingTaskCounts.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/pendingTaskCounts.js index 182faf1..786196f 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/pendingTaskCounts.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/utils/pendingTaskCounts.js @@ -1,4 +1,4 @@ -import { isReturnSettlementReady } from "../settlements/settlementModel.js"; +import { isCashRefund, isReturnSettlementReady } from "../settlements/settlementModel.js"; // Derive badges from the same work queues as each page; never store a second counter. export function pendingTaskCounts(ops, role, me) { @@ -58,7 +58,7 @@ export function pendingTaskCounts(ops, role, me) { const managerCashRefunds = count(ops.cash_refunds, r => r.status === "WAITING_APPROVAL"); // Xung đột đặt kho: hệ thống tự đề xuất đổi ô cho khách; quản lý chỉ cần xử lý khi không còn ô tương đương (NONE). const unitConflicts = count(ops.unit_conflicts, c => c.status === "OPEN" && c.option === "NONE"); - const depositRefunds = count(ops.deposit_refunds, r => r.status === "PENDING"); + const depositRefunds = count(ops.deposit_refunds, r => r.status === "PENDING" && !isCashRefund(r)); const refunds = count(ops.refunds, r => r.status === "PENDING"); // #7 (12/11): navbar quản lý = Tổng quan · Danh sách kho · Hợp đồng & quá hạn · Hoàn tiền · Báo cáo. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx index ad82a64..a458bfc 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx @@ -29,6 +29,6 @@ export function useWorkflowChange(load) { // opts (chữ theo Figma từng màn): { successTitle, failTitle, confirmLabel, doneLabel, onDone } const ask = (action, payload, title, summary, opts = {}) => { setError(""); setForbidden(false); setPending({ action, payload, title, summary, opts }); }; const closeResult = () => { const done = result?.onDone; setResult(null); done?.(); }; - const dialog = pending ? setPending(null)} onReload={() => { setPending(null); load.reload(); }} onConfirm={async () => { if(guard.current)return;guard.current=true;let out;try{out=await load.run(pending.action, pending.payload);}finally{guard.current=false;} if (out.ok) { setPending(null); setResult({ title: pending.opts.successTitle || "Đã lưu kết quả", label: pending.opts.doneLabel || "Về hồ sơ", onDone: pending.opts.onDone }); } else { setForbidden(out.code === "FORBIDDEN"); setError(out.error); } }} /> : result ? : null; + const dialog = pending ? setPending(null)} onReload={() => { setPending(null); load.reload(); }} onConfirm={async () => { if(guard.current)return;guard.current=true;let out;try{out=await load.run(pending.action, pending.payload);}finally{guard.current=false;} if (out.ok) { setPending(null); setResult({ title: pending.opts.successTitle || "Đã lưu kết quả", label: pending.opts.doneLabel || "Về hồ sơ", onDone: pending.opts.onDone }); } else { setForbidden(out.code === "FORBIDDEN"); setError(out.error); } }} /> : result ? : null; return [dialog, ask]; } 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 c8b117b..2f92bf8 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 @@ -52,9 +52,9 @@ function SettledCase({ ops, contract }) { {refund && (

Khoản hoàn {refund.id}

-

Mã hồ sơ nội bộ · {refund.method === "CASH" ? "Tiền mặt tại quầy" : `Chuyển khoản ${refund.bankName || ""}`} · {amountLabel(refund.amount)}

-

{refund.status === "PAID" ? `Đã hoàn · mã giao dịch ngân hàng ${refund.transactionRef || "chưa có"}` : "Đang chờ hoàn: nhập mã giao dịch ngân hàng sau khi chuyển tiền."}

-
Mở khoản hoàn
+

{refund.method === "CASH" ? "Tiền mặt tại quầy" : `Chuyển khoản ${refund.bankName || ""}`} · {amountLabel(refund.amount)}

+

{refund.status === "PAID" ? (refund.method === "CASH" ? "Đã chi tiền mặt cho khách" : `Đã hoàn · mã giao dịch ngân hàng ${refund.transactionRef || "chưa có"}`) : refund.method === "CASH" ? "Đang chờ chi: duyệt và giao nhân viên ở mục Hoàn tiền mặt tại quầy." : "Đang chờ hoàn: nhập mã giao dịch ngân hàng sau khi chuyển tiền."}

+
Mở khoản hoàn
)} @@ -113,6 +113,9 @@ export function ContractListPage({ query }) { const settlementReady = source === "local" || supportsReturnPolicy(ops); const [returning, setReturning] = useState(false); const visibleContracts = ops.contracts.filter((c) => c.state !== "RETURNED" || isReturnSettlementReady(ops, c)); + // Hợp đồng đã có hồ sơ trả kho chỉ hiện ở "Hồ sơ trả kho" phía trên, không lặp lại ở danh sách Hợp đồng. + const returnContracts = new Set((ops.returns || []).map((r) => r.contract)); + const listedContracts = visibleContracts.filter((c) => !returnContracts.has(c.id)); const sel = query.get("id") ? visibleContracts.find((c) => c.id === query.get("id")) : null; const [note, setNote] = useState(""); const detailRef = useRef(null); @@ -123,7 +126,7 @@ export function ContractListPage({ query }) {

Hợp đồng

-
{visibleContracts.map(c=>{const [label,tone]=CONTRACT_STATE(c);return {c.state==="OVERDUE"&&Xử lý quá hạn}{c.state==="RETURNED"?"Duyệt đối soát":"Xem hồ sơ"}}>

{c.state==="RETURNED"?"Biên bản đã gửi · khấu trừ tối đa bằng cọc":"Theo dõi hạn thuê và lịch sử liên hệ khách"}

;})}
+
{!listedContracts.length&&}{listedContracts.map(c=>{const [label,tone]=CONTRACT_STATE(c);return {c.state==="OVERDUE"&&Xử lý quá hạn}{c.state==="RETURNED"?"Duyệt đối soát":"Xem hồ sơ"}}>

{c.state==="RETURNED"?"Biên bản đã gửi · khấu trừ tối đa bằng cọc":"Theo dõi hạn thuê và lịch sử liên hệ khách"}

;})}
{query.get("id")&&!sel&&} {sel && (
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx index 82e07e2..9e50245 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx @@ -11,13 +11,13 @@ import { Button, DetailList, Empty, Field, LinkButton, Notice, PageHeader, Tag } import { useWorkflowData } from "../../facility-operations/workflows/useWorkflowData.js"; import { useWorkflowChange, WorkflowState } from "../../facility-operations/workflows/WorkflowComponents.jsx"; import { useOps } from "../../facility-operations/state/FacilityOperationsProvider.jsx"; -import { transferProof, knownMoney } from "../../facility-operations/settlements/settlementModel.js"; +import { isCashRefund, transferProof, knownMoney } from "../../facility-operations/settlements/settlementModel.js"; import { SettlementTable } from "../../facility-operations/settlements/SettlementComponents.jsx"; import { settlementFromRefund } from "../../facility-operations/settlements/settlementModel.js"; import { amountLabel,timeLabel } from "../../facility-operations/damage/DamageComponents.jsx"; import { vnDateTimeInput } from "../../facility-operations/damage/damageModel.js"; import "../../../shared/styles/customer-detail.css"; -import { go } from "../../../app/router.js"; +import { go, qs } from "../../../app/router.js"; function TransferForm({item,load,ask}) { const hasBank = Boolean(item.bankName && item.bankName !== "CASH" && item.accountNumber); @@ -164,6 +164,8 @@ export function DepositRefundPage({query=new URLSearchParams(),embedded=false}) const base=useWorkflowData("depositRefunds"),{ops,source,run,saving,needsRefresh}=useOps(),[selected,setSelected]=useState(query.get("id")||""); const load=source==="local"?{...base,data:ops.deposit_refunds||[],loading:false,error:"",busy:saving,needsRefresh,demo:true,run:(action,payload)=>run(action,payload)}:base; const [dialog,ask]=useWorkflowChange(load),item=load.data?.find(r=>r.id===selected); + // D42/D47: hoàn cọc tiền mặt nằm ở mục "Hoàn tiền mặt tại quầy" (quản lý duyệt & giao, nhân viên chi) — không lặp ở đây. + const transfers=(load.data||[]).filter(r=>!isCashRefund(r)); const Wrap=embedded?"section":"main"; - return {embedded?

{item?`Hoàn cọc ${item.contractId} · ${item.customer}`:"Hoàn cọc sau trả kho"}

:<>

SafeSpace / Quản lý cơ sở / Hoàn tiền

}{!selected?
{(load.data||[]).map(r=>

{r.customer} · Kho {r.unit}

{r.contractId} · {amountLabel(r.amount)}

{r.status==="PAID"?"Đã hoàn":r.status==="PENDING"?"Chờ hoàn":r.status==="NO_REFUND"?"Không còn khoản hoàn":"Chưa rõ trạng thái"}
)}{!load.data?.length&&}
:!item?:<>
{item.status==="PENDING"&&knownMoney(item.amount)&&item.amount>0?:{item.status==="PAID"?`Đã ghi nhận ${item.method==="CASH"?"chi tiền mặt":"chuyển tiền"} lúc ${timeLabel(item.paidAt)}.`:knownMoney(item.amount)&&item.amount===0?"Không còn khoản hoàn; không tạo giao dịch chuyển tiền.":"Chưa có đủ dữ liệu khoản hoàn để thao tác."}}
}
{dialog}
; + return {embedded?

{item?`Hoàn cọc ${item.contractId} · ${item.customer}`:"Hoàn cọc sau trả kho"}

:<>

SafeSpace / Quản lý cơ sở / Hoàn tiền

}{!selected?
{transfers.map(r=>

{r.customer} · Kho {r.unit}

{r.contractId} · {amountLabel(r.amount)}

{r.status==="PAID"?"Đã hoàn":r.status==="PENDING"?"Chờ hoàn":r.status==="NO_REFUND"?"Không còn khoản hoàn":"Chưa rõ trạng thái"}
)}{!transfers.length&&}
:!item?:<>
{item.status==="PENDING"&&knownMoney(item.amount)&&item.amount>0&&isCashRefund(item)?Khách chọn nhận tiền mặt tại quầy. Duyệt và giao nhân viên chi ở mục Hoàn tiền mặt tại quầy; nhân viên xác nhận khi đã chi cho khách. Mở Hoàn tiền mặt tại quầy:item.status==="PENDING"&&knownMoney(item.amount)&&item.amount>0?:{item.status==="PAID"?`Đã ghi nhận ${item.method==="CASH"?"chi tiền mặt":"chuyển tiền"} lúc ${timeLabel(item.paidAt)}.`:knownMoney(item.amount)&&item.amount===0?"Không còn khoản hoàn; không tạo giao dịch chuyển tiền.":"Chưa có đủ dữ liệu khoản hoàn để thao tác."}}
}
{dialog}
; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/refundCenterModel.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/refundCenterModel.js index 72c51b7..9ff65f7 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/refundCenterModel.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/refundCenterModel.js @@ -1,3 +1,5 @@ +import { isCashRefund } from "../../facility-operations/settlements/settlementModel.js"; + // Mục "Hoàn tiền" của Quản lý (#7 · 12/11): ba loại hoàn tiền lọc trong cùng một trang. export const REFUND_KINDS = [["", "Tất cả"], ["cancel", "Đơn huỷ"], ["deposit", "Hoàn cọc trả kho"], ["cash", "Tiền mặt tại quầy"]]; export const refundKindOf = (k) => (REFUND_KINDS.some(([key]) => key === k) ? k : ""); @@ -5,7 +7,8 @@ export function refundPendingCounts(ops) { const n = (list, test) => (list || []).filter(test).length; return { cancel: n(ops?.refunds, (r) => r.status === "PENDING"), - deposit: n(ops?.deposit_refunds, (r) => r.status === "PENDING"), + // Hoàn cọc tiền mặt đã nằm ở mục tiền mặt tại quầy: không đếm hai lần. + deposit: n(ops?.deposit_refunds, (r) => r.status === "PENDING" && !isCashRefund(r)), cash: n(ops?.cash_refunds, (r) => r.status === "WAITING_APPROVAL"), }; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/ChangeFlowDialog.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/ChangeFlowDialog.jsx index 1b3555c..9744beb 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/ChangeFlowDialog.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/ChangeFlowDialog.jsx @@ -13,7 +13,7 @@ export function useChangeFlow() { const t=changeFlowTexts({action,scope,...texts}); try { if(confirm&&!(await step({kind:"confirm",danger,title:t.confirmTitle,rows:[["Thao tác",action],["Phạm vi",scope],["Nội dung",content]]})))return {ok:false,cancelled:true}; - if(!alive.current)return {ok:false,cancelled:true};setState({kind:"saving",title:"Đang lưu thay đổi",text:"Vui lòng chờ máy chủ xác nhận."}); + if(!alive.current)return {ok:false,cancelled:true};setState({kind:"saving",title:"Đang lưu thay đổi",text:"Vui lòng chờ trong giây lát."}); const result=await perform(()=>alive.current); if(!alive.current)return {ok:false,cancelled:true};setState(null); if(result===false)return {ok:false,cancelled:true}; diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/UI.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/UI.jsx index 9a6f689..94efc88 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/UI.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/UI.jsx @@ -10,6 +10,7 @@ * - PageHeader: Tiêu đề trang chuẩn mực. */ import React, { useEffect, useId, useRef } from "react"; +import { createPortal } from "react-dom"; import { href } from "../../app/router.js"; const paths = { @@ -217,7 +218,7 @@ export function Modal({ title, children, onClose, size = "sm", label, tone, plac } }; }, []); - return ( + const overlay = (
e.target === e.currentTarget && modalStack[modalStack.length - 1] === ref.current && closeRef.current?.()}>

{title}

@@ -225,6 +226,8 @@ export function Modal({ title, children, onClose, size = "sm", label, tone, plac
); + // Gắn popup thẳng vào : khối cha có hiệu ứng (transform) không còn giam nền mờ trong khung trang, popup phủ kín cả thanh đầu trang (D54). + return typeof document !== "undefined" && document.body?.nodeType === 1 ? createPortal(overlay, document.body) : overlay; } export function Dialog({ title, message, actionLabel = "Đã hiểu", onClose }) { diff --git a/progress.md b/progress.md index 84cc57e..990f6c9 100644 --- a/progress.md +++ b/progress.md @@ -2200,3 +2200,4 @@ - Email: đặt lại mật khẩu — lỗi "Mật khẩu mới phải khác mật khẩu hiện tại" trước đây bị FE hiểu là sai mã và đẩy về bước nhập mã; nay hiện ngay dưới ô mật khẩu. Thư hợp đồng sửa câu QR/PIN cho đúng D51 (xem được ngay, mở cửa từ 00:00 ngày bắt đầu). Rà hàng đợi email (hợp đồng, xác nhận đã nhận tiền, nhắc gia hạn, quá hạn, OTP): không thấy lỗi khác. - Kiểm chứng: FE `npm test` 231/231 (TZ Asia/Ho_Chi_Minh), test:business 15/15, test:workflows 12/12, test:render 178 route PASS, check:structure PASS, build PASS; xem thanh đầu trang và chân trang bằng Chrome trên `dev:mock`. **Chưa build/chạy `dotnet test`** (môi trường AI không tải được .NET SDK) — cần CI hoặc máy thành viên. Chưa thử PayOS thật. - Bổ sung cùng ngày: ô quá hạn mà khách đã gửi trả kho bị hiện hai việc ở "Kiểm tra trả kho" của nhân viên ("Đồ quá hạn · Cần xử lý đồ trong kho" và lịch kiểm tra trả kho), vì hồ sơ quá hạn chỉ đóng khi chốt hoàn cọc. `GetOverdueCasesAsync` nay ẩn hồ sơ chưa lập biên bản của hợp đồng `RETURN_PENDING` (hồ sơ đã có biên bản vẫn giữ); thêm test `GetOverdueCasesAsync_HidesCaseAfterCustomerRequestsReturn`. Chưa chạy `dotnet test`. +- Bổ sung cùng ngày (khu Quản lý): hợp đồng đã có hồ sơ trả kho không còn lặp ở danh sách "Hợp đồng" (chỉ hiện ở "Hồ sơ trả kho"). Hoàn cọc khách chọn tiền mặt không còn lặp ở "Hoàn cọc sau trả kho" và không đếm hai lần trên số "Hoàn tiền"; mở khoản này chỉ hướng sang mục "Hoàn tiền mặt tại quầy" (quản lý duyệt & giao, nhân viên chi — D42/D47), không còn ô "Mã phiếu chi" cho quản lý. Popup gắn thẳng vào `` để nền mờ phủ kín cả thanh đầu trang (trước đây bị giam trong khối có hiệu ứng `transform` ở trang Hoàn tiền); bỏ chữ "Máy chủ đã xác nhận kết quả" trong popup thành công. FE `npm test` 231/231, test:render 178 route, test:workflows, test:business, check:structure, build PASS; xem popup bằng Chrome trên `dev:mock`.