Skip to content

Commit 5357bf8

Browse files
Merge branch 'dev' into inventory
2 parents 7311e12 + c767869 commit 5357bf8

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

frontend/src/pages/Pos/TransactionHistory.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,23 @@ function TransactionHistory() {
390390
items.forEach((item, i) => { refundAmount += (refundQtys[i] || 0) * (item.price || 0); });
391391

392392
const oldTotal = parseInt((refundModal.total || '').toString().replace(/[^0-9]/g, '')) || 0;
393+
const pointsDiscount = Number(refundModal.pointsDiscount || 0);
394+
const noCashCollectedByPoints = oldTotal === 0 && pointsDiscount > 0;
395+
if (noCashCollectedByPoints) {
396+
refundAmount = 0;
397+
}
398+
393399
const newTotal = Math.max(0, oldTotal - refundAmount);
394400
const totalRefundedAmount = Number(refundModal.refundedAmount || 0) + refundAmount;
395401

402+
const refundNoteMessage = noCashCollectedByPoints
403+
? `Hoàn trả 0đ (đơn đã dùng điểm về 0đ) lúc ${new Date().toLocaleString('vi-VN', { hour: '2-digit', minute: '2-digit', day: '2-digit', month: '2-digit', year: 'numeric' })}`
404+
: `Hoàn trả ${refundAmount.toLocaleString()}đ lúc ${new Date().toLocaleString('vi-VN', { hour: '2-digit', minute: '2-digit', day: '2-digit', month: '2-digit', year: 'numeric' })}`;
405+
406+
const refundSuccessMessage = noCashCollectedByPoints
407+
? 'Đã hoàn trả hàng thành công (đơn 0đ do dùng điểm nên không hoàn tiền)!'
408+
: 'Đã hoàn trả thành công!';
409+
396410
const updatedTransaction = {
397411
...refundModal,
398412
cart: newItems,
@@ -401,15 +415,15 @@ function TransactionHistory() {
401415
quantity: `${newItems.reduce((s, it) => s + (it.qty || it.quantity || 1), 0)} món`,
402416
status: newItems.length === 0 ? 'Đã hoàn trả' : 'Hoàn thành',
403417
refundedAmount: totalRefundedAmount,
404-
refundNote: `Hoàn trả ${refundAmount.toLocaleString()}đ lúc ${new Date().toLocaleString('vi-VN', { hour: '2-digit', minute: '2-digit', day: '2-digit', month: '2-digit', year: 'numeric' })}`,
418+
refundNote: refundNoteMessage,
405419
};
406420

407421
const updatedTransactions = transactions.map(t => t.id === refundModal.id ? updatedTransaction : t);
408422
setTransactions(updatedTransactions);
409423
localStorage.setItem('transactions', JSON.stringify(updatedTransactions));
410424
setSelectedTransaction(prev => (prev?.id === updatedTransaction.id ? updatedTransaction : prev));
411425
setRefundModal(null);
412-
showNotificationModal('Đã hoàn trả thành công!');
426+
showNotificationModal(refundSuccessMessage);
413427
};
414428

415429
const saveCustomerInfo = () => {
@@ -653,6 +667,7 @@ function TransactionHistory() {
653667
>
654668
<option value="all">Tất cả trạng thái</option>
655669
<option value="Hoàn thành">Hoàn thành</option>
670+
<option value="Đã hoàn trả">Đã hoàn trả</option>
656671
<option value="Chờ thanh toán">Chờ thanh toán (Đơn treo)</option>
657672
</select>
658673

0 commit comments

Comments
 (0)