Add pending amount to booking list
All checks were successful
build-and-deploy / build-deploy (push) Successful in 39s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 39s
This commit is contained in:
@@ -157,6 +157,9 @@ class BookingFlow(
|
||||
Role.HOUSEKEEPING,
|
||||
Role.FINANCE
|
||||
)
|
||||
val property = propertyRepo.findById(propertyId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
|
||||
}
|
||||
val statuses = parseStatuses(status)
|
||||
val bookings = if (statuses.isEmpty()) {
|
||||
bookingRepo.findByPropertyIdOrderByCreatedAtDesc(propertyId)
|
||||
@@ -171,8 +174,27 @@ class BookingFlow(
|
||||
.groupBy { it.bookingId }
|
||||
.mapValues { (_, rows) -> rows.map { it.roomNumber }.distinct().sorted() }
|
||||
}
|
||||
val staysByBooking = if (bookingIds.isEmpty()) {
|
||||
emptyMap()
|
||||
} else {
|
||||
roomStayRepo.findByBookingIdIn(bookingIds).groupBy { it.booking.id!! }
|
||||
}
|
||||
val paymentsByBooking = if (bookingIds.isEmpty()) {
|
||||
emptyMap()
|
||||
} else {
|
||||
paymentRepo.sumAmountByBookingIds(bookingIds)
|
||||
.associate { it.bookingId to it.total }
|
||||
}
|
||||
return bookings.map { booking ->
|
||||
val guest = booking.primaryGuest
|
||||
val stays = staysByBooking[booking.id].orEmpty()
|
||||
val expectedPay = if (stays.isEmpty()) {
|
||||
null
|
||||
} else {
|
||||
computeExpectedPay(stays, property.timezone)
|
||||
}
|
||||
val collected = paymentsByBooking[booking.id] ?: 0L
|
||||
val pending = expectedPay?.let { it - collected }
|
||||
BookingListItem(
|
||||
id = booking.id!!,
|
||||
status = booking.status.name,
|
||||
@@ -191,7 +213,8 @@ class BookingFlow(
|
||||
femaleCount = booking.femaleCount,
|
||||
totalGuestCount = booking.totalGuestCount,
|
||||
expectedGuestCount = booking.expectedGuestCount,
|
||||
notes = booking.notes
|
||||
notes = booking.notes,
|
||||
pending = pending
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,8 @@ data class BookingListItem(
|
||||
val femaleCount: Int?,
|
||||
val totalGuestCount: Int?,
|
||||
val expectedGuestCount: Int?,
|
||||
val notes: String?
|
||||
val notes: String?,
|
||||
val pending: Long? = null
|
||||
)
|
||||
|
||||
data class BookingDetailResponse(
|
||||
|
||||
Reference in New Issue
Block a user