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
25 changes: 25 additions & 0 deletions DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,28 @@ Bổ sung @playwright/test trong devDependencies để kiểm thao tác biểu m
- **Gia hạn (D50 #23):** chữ hiển thị không còn "chờ quản lý duyệt" / "cơ sở duyệt và chốt giá"; dùng "chờ xác nhận" / "đã được xác nhận".
- **Màn khách hàng:** dưới họ tên trên thanh đầu trang hiện vai trò "Khách hàng" (giống thẻ vai trò của nhân viên, quản lý, admin).
- **Hotline ở chân trang** hiện chữ thường cùng màu các dòng khác, không còn là liên kết `tel:`. Số hotline giữ theo D50.

## D64 — 18/11/2026: Xác nhận hoàn tiền không cần mã giao dịch; trả kho chỉ chọn ngày — Đã chốt

> Người dùng (Thắng) chốt ngày 18/11/2026, Figma đã sửa trước (M-ĐS-CHỐT chuyển khoản + bản tiền mặt, M08a/M08a2, D30-15). Thay ý "nhập mã giao dịch ngân hàng" ở mục 21 (D50), dòng "Chuyển khoản: quản lý … nhập mã giao dịch" và các dòng D27/D32 yêu cầu mã giao dịch, thời điểm chuyển cho bước xác nhận hoàn.

- Khách điền thông tin nhận hoàn (chuyển khoản: ngân hàng, số tài khoản, chủ tài khoản; hoặc tiền mặt tại quầy). Quản lý thấy đủ thông tin đó và **chỉ bấm xác nhận**: "Xác nhận đã chuyển khoản" hoặc "Xác nhận đã trả tiền mặt". **Không nhập mã giao dịch, không nhập thời gian chuyển**; máy chủ ghi thời điểm xác nhận làm ngày hoàn.
- Áp dụng cho hoàn cọc sau trả kho và hoàn tiền đơn huỷ (M08). Vẫn giữ: xác nhận một lần (409 khi bấm lặp), khoá phương thức theo lựa chọn khách, kiểm tra tài khoản nhận đủ thông tin.
- API giữ nguyên trường `transactionRef`/`transferredAt` nhưng **không bắt buộc**; có gửi mã (dữ liệu cũ) thì vẫn kiểm tra ≤ 100 ký tự và không trùng. Khách không còn thấy dòng "Mã giao dịch" ở theo dõi khoản hoàn.
- Trả kho: khách chỉ chọn **ngày** mong muốn trả kho, không chọn giờ hay buổi sáng/chiều (giữ đúng mục 9 / D59).

## D65 — 18/11/2026: Mốc "Sắp hết hạn" còn 10 ngày — Đã chốt

> Người dùng (Thắng) chốt ngày 18/11/2026. Thay mốc 30 ngày của D11 (và mốc 14 ngày của Công cụ demo / bảng kho quản lý).

- Hợp đồng chỉ chuyển "Sắp hết hạn" (EXPIRING) khi còn **≤ 10 ngày** tới ngày kết thúc; còn hơn 10 ngày là "Đang thuê". Áp dụng thống nhất cho khách (Kho của tôi, tổng quan), quản lý, Công cụ demo và tiến trình quét hằng ngày.
- Tiến trình quét hằng ngày đưa hợp đồng EXPIRING còn hơn 10 ngày (đánh theo mốc cũ hoặc vừa gia hạn) về lại ACTIVE. Email nhắc gia hạn giữ nguyên mốc 3 ngày.

## D66 — 18/11/2026: Mỗi cơ sở một nhân viên — bỏ giao việc; quản lý tự xác nhận đã trả tiền mặt — Đã chốt

> Người dùng (Thắng) chốt ngày 18/11/2026, chọn phương án (a). Thay phần "quản lý duyệt chi tiền mặt và giao nhân viên, nhân viên tick 4 mục và chi" của D42/D44, phần "quản lý phân công nhân viên xử lý đồ quá hạn" và trang M06 Phân công công việc.

- Mỗi cơ sở mặc định 1 nhân viên; **không có thao tác giao việc** nào cho nhân viên.
- **Hoàn tiền mặt tại quầy:** bỏ bước "Duyệt & giao" và ô chọn nhân viên. Khoản tiền mặt chờ khách đến nhận ngay khi được tạo; khi khách nhận đủ tiền, **quản lý bấm "Xác nhận đã trả tiền mặt"** (Figma M-ĐS-CHỐT · tiền mặt), không nhập mã giao dịch. Hạn nhận 30 ngày tính từ lúc tạo khoản (khoản cũ đã duyệt vẫn tính từ lần duyệt). Nhân viên chỉ còn gọi nhắc khách ở ngày 10, 20, 25.
- **Xử lý đồ quá hạn từ ngày 20:** bỏ bước quản lý phân công; hồ sơ hiện thẳng ở "Công việc xử lý đồ quá hạn" của nhân viên cơ sở.
- Bỏ trang M06 "Phân công công việc" (đã ẩn khỏi menu từ #7). Yêu cầu hỗ trợ giữ cách hiện tại: nhân viên của cơ sở thấy và nhận xử lý, không cần giao.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Mã việc khớp kế hoạch "SafeSpace — Kế hoạch hoàn thiện cập n
| T04 | Khách chọn trả gia hạn tại quầy; nhân viên xác nhận thu | `POST /api/renewals/{id}/counter-payment`; board `counterRenewals[]` + `POST /api/ops/counter-renewals/actions` `{action:"COLLECT_RENEWAL"}` (xem `APPROVED-FE-API-GAPS.md`) | Đạt | P1 |
| T05 | Biên bản trả kho lưu phí và ảnh | `POST /api/ops/returns/{id}/inspection` nhận thêm `damageFee`, `cleaningRequired`, `feeReason`, `photos[]` (ảnh kho trống bắt buộc); lưu `ReturnInspection.DamageFee/CleaningFee/CleaningRequired`. Vệ sinh = 10% cọc cố định, không nhập tay | Ngọc Mai | P0 |
| T06 | Quyết toán trả kho: tổng khấu trừ ≤ `DepositAmount`; bỏ `Debt`; không để khoản `DAMAGE_FEE`/`OVERDUE_FEE` nào ở trạng thái chờ thu sau quyết toán | `RefundPolicy.Calculate`, `ConfirmRefundAsync`, `RefundPolicyTests` | Ngọc Mai | P0 |
| T07 | Hoàn cọc hai bước: M07 chốt → `REFUND` `PENDING`; màn hoàn cọc ghi `transactionRef` → `PAID`. Ô cần vệ sinh giữ `MAINTENANCE` | `POST /api/ops/contracts/{id}/refund` (chỉ chốt số), `GET /api/ops/deposit-refunds`, `POST /api/ops/deposit-refunds/actions` `{action:"CONFIRM_DEPOSIT_REFUND", id, transactionRef}` | Ngọc Mai | P0 |
| T07 | Hoàn cọc hai bước: M07 chốt → `REFUND` `PENDING`; màn hoàn cọc bấm xác nhận → `PAID` (D64 18/11: `transactionRef`, `transferredAt` không bắt buộc). Ô cần vệ sinh giữ `MAINTENANCE` | `POST /api/ops/contracts/{id}/refund` (chỉ chốt số), `GET /api/ops/deposit-refunds`, `POST /api/ops/deposit-refunds/actions` `{action:"CONFIRM_DEPOSIT_REFUND", id, transactionRef}` | Ngọc Mai | P0 |
| T08 | Tài khoản nhận hoàn chính chủ khi huỷ đơn và khi gửi trả kho: `bankName`, `accountNumber` (6–19 chữ số), `accountHolder` (trùng tên hợp đồng) | `POST /api/reservations/{id}/cancel`, `POST /api/contracts/{id}/move-out` | Ngọc Mai | P1 |
| T09 | Phí quá hạn = `DepositAmount × rate × số ngày trễ`, tối đa `DepositAmount`; dừng khi gửi trả kho. Thêm `CalculationType` `DEPOSIT_PERCENT_PER_DAY` cho chính sách `OVERDUE` (mặc định 5) | `RefundPolicy.OverdueFeeFor`, seed/B02, test | Tiến | P0 |
| T11 | Job quá hạn mỗi ngày: EXPIRING/OVERDUE, tạo `OverdueCase`, cộng phí theo ngày không trùng, mốc nhắc ngày 10–14, việc xử lý đồ ngày 20 | Worker mới (giống `ExpiredCashHoldWorker`) | Tiến | P1 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export function startMockApi(
return send(200, page(rows));
}
// Lượt 6 · #45 #54: công cụ demo ngày & giá
const running = (c) => { const t = dateOnly(new Date()); if (c.status !== "ACTIVE") return c.status; if (c.endDate <= t) return "OVERDUE"; return (new Date(c.endDate) - new Date(t)) / 864e5 <= 14 ? "EXPIRING" : "ACTIVE"; };
const running = (c) => { const t = dateOnly(new Date()); if (c.status !== "ACTIVE") return c.status; if (c.endDate <= t) return "OVERDUE"; return (new Date(c.endDate) - new Date(t)) / 864e5 <= 10 ? "EXPIRING" : "ACTIVE"; };
const overdueDays = (c) => { const t = dateOnly(new Date()); return c.status === "ACTIVE" && c.endDate <= t ? Math.round((new Date(t) - new Date(c.endDate)) / 864e5) : 0; };
const demoDto = (c) => { const u = unit(c.unitId); return { contractId: c.contractId, contractCode: `HĐ-${c.startDate.slice(0, 4)}-${String(c.contractId).padStart(4, "0")}`, customerName: S.users.find((x) => x.userId === c.customerId)?.fullName, unitNumber: u.unitNumber, facilityName: fac(u.facilityId)?.name, startDate: c.startDate, endDate: c.endDate, agreedMonthlyRate: c.agreedMonthlyRate ?? c.monthlyRate ?? 0, depositAmount: c.depositAmount ?? 0, status: running(c), overdueDays: overdueDays(c), payments: S.payments.filter((p) => p.contractId === c.contractId).map((p) => ({ paymentId: p.paymentId, paymentType: p.paymentType, status: p.status, amount: p.amount, paidAt: p.paidAt ? dbTime(p.paidAt) : null, dueDate: p.dueDate || null })) }; };
// D57 · Chỉnh giá theo cơ sở (demo): giá 4 loại kho của một cơ sở
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ async function route(path){await page.goto('http://127.0.0.1:5173/#/'+path);awai
// Nút xác nhận / nút đóng thông báo thành công theo chữ Figma từng màn (useWorkflowChange opts), nên bấm theo vị trí.
async function confirm(){await page.locator('.modal--confirm:not(.modal--success):not(.modal--failure)').getByRole('button').last().click();await page.locator('.modal--success').getByRole('button').first().click();}
// Thời gian chuyển phải sau lúc duyệt đối soát và không ở tương lai: lấy đúng mốc hiện tại (max của ô).
async function transferNow(){const at=page.getByLabel(/Thời gian chuyển/);await at.fill(await at.getAttribute('max'));}
const passed=[];
await login('manager01','Manager@123');await route('manager/refunds');
const han=page.locator('.record-card').filter({hasText:'Phạm Gia Hân'});await han.getByRole('button',{name:'Xem yêu cầu hoàn tiền'}).click();assert.match(await page.getByRole('dialog').innerText(),/2.166.000/);await page.getByRole('button',{name:'Đóng chi tiết',exact:true}).click();
await han.getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();await page.getByRole('dialog').getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();assert.match(await page.getByRole('dialog').innerText(),/Nhập mã giao dịch/);await page.getByLabel('Mã giao dịch hoàn tiền').fill('QA-REF-0139');await transferNow();await page.getByLabel('Đã chuyển đúng số tiền vào đúng tài khoản nhận hoàn').check();await page.getByRole('dialog').getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();await page.locator('.modal--success').getByRole('button',{name:'Về yêu cầu hoàn',exact:true}).click();await page.waitForTimeout(200);assert.equal(await han.getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).count(),0);passed.push('Đúng khách / bắt buộc mã giao dịch, thời gian chuyển, xác nhận chính chủ / không xác nhận hoàn hai lần');
await route('manager/deposit-refunds');await page.getByRole('button',{name:'Xem khoản hoàn'}).click();await page.getByLabel(/Mã giao dịch/).fill('QA-DEPOSIT-0098');await transferNow();await page.getByLabel('Tôi đã chuyển đúng số tiền vào đúng tài khoản nhận').check();await page.getByRole('button',{name:'Ghi nhận đã chuyển tiền'}).click();await confirm();assert.equal(await page.getByRole('button',{name:'Ghi nhận đã chuyển tiền'}).count(),0);passed.push('Hoàn cọc độc lập và chặn xác nhận lại');
await han.getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();assert.match(await page.getByRole('dialog').innerText(),/Không cần nhập mã giao dịch/);await page.getByRole('dialog').getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();await page.locator('.modal--success').getByRole('button',{name:'Về yêu cầu hoàn',exact:true}).click();await page.waitForTimeout(200);assert.equal(await han.getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).count(),0);passed.push('D64: M08 chỉ bấm xác nhận, không nhập mã giao dịch / không xác nhận hoàn hai lần');
await route('manager/deposit-refunds');await page.getByRole('button',{name:'Xem khoản hoàn'}).click();assert.match(await page.locator('main').innerText(),/Số tài khoản/);await page.getByRole('button',{name:'Xác nhận đã chuyển khoản'}).click();await confirm();assert.equal(await page.getByRole('button',{name:'Xác nhận đã chuyển khoản'}).count(),0);passed.push('D64: hoàn cọc chỉ bấm xác nhận đã chuyển khoản, chặn xác nhận lại');
await login('customer01','Customer@123');await route('refunds');assert.match(await page.locator('main').innerText(),/Đã hoàn · 662\.500 đ/);passed.push('Khách nhìn thấy kết quả hoàn cọc sau khi quản lý xác nhận');await route('inquiries/HT-0091');await page.getByRole('button',{name:'Kiểm tra & gửi phản hồi'}).click();assert.match(await page.locator('main').innerText(),/Vui lòng nhập nội dung/);await page.getByLabel('Nội dung phản hồi').fill('Tôi cần kho cho 10 thùng đồ trong 3 tháng.');await page.getByRole('button',{name:'Kiểm tra & gửi phản hồi'}).click();await confirm();passed.push('Phản hồi khách: dữ liệu trống và gửi thành công');
await login('staff01','Staff@123');await route('staff/inquiries');await page.getByRole('button',{name:'Xem yêu cầu',exact:true}).click();assert.match(await page.locator('main').innerText(),/Tôi cần kho cho 10 thùng đồ/);passed.push('Nhân viên nhận đúng phản hồi của khách qua dữ liệu demo chung');
await route('staff/renewal-payments');await page.getByRole('button',{name:'Xác nhận đã thu',exact:true}).click();await confirm();assert.equal(await page.getByRole('button',{name:'Xác nhận đã thu',exact:true}).count(),0);passed.push('Thu gia hạn tại quầy một lần');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { defaultRentalPolicy } from "../../features/facility-operations/workflow
import { isReturnFee, NO_RETURN_COLLECTION, visitDateError } from "../../shared/utils/returnPolicy.js";
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
import { customerNotifications } from "../../features/customer/notifications/customerNotifications.js";
import { noticeKey } from "../../shared/utils/notices.js";
import { submitCancellation, submitReturnRequest } from "../../shared/api/refundRequestApi.js";
import { readPhotoData, verifyPhotoFile } from "../../shared/utils/refundRequest.js";
import { submitRenewalWithConsent } from "../../shared/api/renewalConsentApi.js";
Expand Down Expand Up @@ -394,13 +395,18 @@ function ApiProvider({ children }) {
updateOverlay(o => {
const byId = new Map(events.map(event => [event.id, event]));
const ids = new Set(o.notifications.map(notice => notice.id));
const incoming = events.filter(event => !ids.has(event.id));
// Thông báo quá hạn: thời điểm của sự kiện là 00:00 nên bị xếp dưới các thông báo khác trong ngày và khách không thấy.
// Lần đầu phát hiện và mỗi lần số ngày quá hạn đổi → đưa lên đầu chuông, chưa đọc (cùng nhịp với email quá hạn).
const stamp = new Date().toISOString();
const isOverdue = id => typeof id === "string" && id.startsWith("SERVER-OVERDUE-");
const dismissed = new Set(o.dismissedNotices || []);
const incoming = events.filter(event => !ids.has(event.id) && !dismissed.has(noticeKey(event))).map(event => isOverdue(event.id) ? { ...event, created_at: stamp } : event);
let updated = false;
const existing = o.notifications.map(notice => {
const event = typeof notice.id === "string" && notice.id.startsWith("SERVER-OVERDUE-") ? byId.get(notice.id) : null;
const event = isOverdue(notice.id) ? byId.get(notice.id) : null;
if (!event || event.detail === notice.detail) return notice;
updated = true;
return { ...notice, detail: event.detail };
return { ...notice, detail: event.detail, created_at: stamp, read: false };
});
return incoming.length || updated ? { ...o, notifications: [...incoming, ...existing] } : o;
});
Expand Down Expand Up @@ -585,6 +591,7 @@ function ApiProvider({ children }) {
...o,
returns: next.returns,
notifications: next.notifications,
dismissedNotices: next.dismissedNotices || o.dismissedNotices || [],
activities: next.activities,
appointments: [...next.appointments.filter((a) => !prev.appointments.some((x) => x.appointment_id === a.appointment_id)), ...o.appointments],
name: next.user?.full_name !== prev.user?.full_name ? next.user.full_name : o.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* - Thanh toán: PAY_ORDER, ADD_PAYMENT, REFUND_SETTLEMENT
* - Hỗ trợ: CREATE_TICKET, REPLY_TICKET
*/
import { noticeKey } from "../../shared/utils/notices.js";
import { requireRentalPolicy } from "../../shared/utils/rentalPolicy.js";
import { storedRefundChoice, validateRefundChoice } from "../../shared/utils/refundRequest.js";
import { isReturnFee, NO_RETURN_COLLECTION, visitDateError } from "../../shared/utils/returnPolicy.js";
Expand Down Expand Up @@ -483,12 +484,16 @@ const handlers = {
return { state: { ...state, user: { ...state.user, password: p.next } }, result: {} };
},

// Đã đọc thì xoá khỏi chuông (18/11); nhớ khoá để thông báo sinh từ máy chủ không quay lại.
MARK_READ(state, p) {
const all = !p.ids;
const read = state.notifications.filter((n) => all || p.ids.includes(n.id));
const keys = read.map(noticeKey).filter(Boolean);
return {
state: {
...state,
notifications: state.notifications.map((n) => (all || p.ids.includes(n.id) ? { ...n, read: true } : n)),
notifications: state.notifications.filter((n) => !(all || p.ids.includes(n.id))),
dismissedNotices: [...keys, ...(state.dismissedNotices || []).filter((k) => !keys.includes(k))].slice(0, 500),
},
result: {},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ export const facilityOf = (data, id, name) =>
};
export const contractOf = (data, id) => data.contracts.find((c) => c.contract_id === id);

// Trạng thái hợp đồng suy ra theo ngày (ACTIVE → EXPIRING trong 30 ngày → OVERDUE)
// Trạng thái hợp đồng suy ra theo ngày (ACTIVE → EXPIRING khi còn ≤ 10 ngày, D65 → OVERDUE)
export const EXPIRING_DAYS = 10;
export function contractStatus(c, now = new Date()) {
if (c.status === "ENDED") return "ENDED";
const left = daysBetween(localDate(now), c.end_date);
if (left < 0) return "OVERDUE";
if (left <= 30) return "EXPIRING";
if (left <= EXPIRING_DAYS) return "EXPIRING";
return "ACTIVE";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function expectedState(start, end, today) {
if (!start || !end) return null;
if (start > today) return "Chưa tới ngày thuê";
if (end <= today) return `Quá hạn ${Math.round((Date.parse(today) - Date.parse(end)) / 86400000)} ngày`;
return Math.round((Date.parse(end) - Date.parse(today)) / 86400000) <= 14 ? "Sắp hết hạn" : "Đang thuê";
return Math.round((Date.parse(end) - Date.parse(today)) / 86400000) <= 10 ? "Sắp hết hạn" : "Đang thuê";
}

export function contractFormError({ start, end, rate }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const SYSTEM_ENFORCED_POLICIES = [
{
key: 'expiring',
label: 'Thông báo sắp hết hạn hợp đồng',
value: '30 ngày trước khi hết hạn',
reference: 'D11 · OverdueProcessor',
value: '10 ngày trước khi hết hạn',
reference: 'D65 · OverdueProcessor',
description: 'Hệ thống tự động rà soát hàng ngày và gửi thông báo nhắc gia hạn đến khách hàng.',
},
{
Expand Down
Loading
Loading