@@ -392,12 +392,19 @@ function TransactionHistory() {
392392 const oldTotal = parseInt ( ( refundModal . total || '' ) . toString ( ) . replace ( / [ ^ 0 - 9 ] / g, '' ) ) || 0 ;
393393 const pointsDiscount = Number ( refundModal . pointsDiscount || 0 ) ;
394394 const noCashCollectedByPoints = oldTotal === 0 && pointsDiscount > 0 ;
395+
396+ const customerPaidAmount = Number ( refundModal . customerMoney || 0 ) ;
397+ const alreadyRefundedAmount = Number ( refundModal . refundedAmount || 0 ) ;
398+ const remainingRefundableAmount = Math . max ( 0 , customerPaidAmount - alreadyRefundedAmount ) ;
399+
395400 if ( noCashCollectedByPoints ) {
396401 refundAmount = 0 ;
402+ } else {
403+ refundAmount = Math . min ( refundAmount , remainingRefundableAmount ) ;
397404 }
398405
399406 const newTotal = Math . max ( 0 , oldTotal - refundAmount ) ;
400- const totalRefundedAmount = Number ( refundModal . refundedAmount || 0 ) + refundAmount ;
407+ const totalRefundedAmount = alreadyRefundedAmount + refundAmount ;
401408
402409 const refundNoteMessage = noCashCollectedByPoints
403410 ? `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' } ) } `
@@ -1339,15 +1346,20 @@ function TransactionHistory() {
13391346 { /* Tóm tắt số tiền hoàn trả */ }
13401347 { ( ( ) => {
13411348 const items = refundModal . cart || refundModal . items || [ ] ;
1342- const amt = items . reduce ( ( s , item , i ) => s + ( refundQtys [ i ] || 0 ) * ( item . price || 0 ) , 0 ) ;
1343- return amt > 0 ? (
1349+ const rawRefundAmount = items . reduce ( ( s , item , i ) => s + ( refundQtys [ i ] || 0 ) * ( item . price || 0 ) , 0 ) ;
1350+ const customerPaidAmount = Number ( refundModal . customerMoney || 0 ) ;
1351+ const alreadyRefundedAmount = Number ( refundModal . refundedAmount || 0 ) ;
1352+ const remainingRefundableAmount = Math . max ( 0 , customerPaidAmount - alreadyRefundedAmount ) ;
1353+ const previewRefundAmount = Math . min ( rawRefundAmount , remainingRefundableAmount ) ;
1354+
1355+ return previewRefundAmount > 0 ? (
13441356 < div style = { {
13451357 padding : "10px 14px" , marginBottom : "16px" ,
13461358 background : "#fff3cd" , borderRadius : "8px" , border : "1px solid #ffc107" ,
13471359 fontSize : "14px" , display : "flex" , justifyContent : "space-between"
13481360 } } >
13491361 < span > Số tiền cần hoàn lại cho khách:</ span >
1350- < strong style = { { color : "#e67e22" } } > { amt . toLocaleString ( ) } đ</ strong >
1362+ < strong style = { { color : "#e67e22" } } > { previewRefundAmount . toLocaleString ( ) } đ</ strong >
13511363 </ div >
13521364 ) : null ;
13531365 } ) ( ) }
0 commit comments