Sync active room stays when booking expected dates change
All checks were successful
build-and-deploy / build-deploy (push) Successful in 37s

This commit is contained in:
androidlover5842
2026-02-08 18:01:36 +05:30
parent 924bf2c614
commit 189fdb33de
5 changed files with 39 additions and 3 deletions

View File

@@ -511,6 +511,7 @@ class BookingFlow(
room = room,
fromAt = checkInAt,
toAt = null,
plannedCheckoutAt = booking.expectedCheckoutAt,
rateSource = parseRateSource(stay.rateSource),
nightlyRate = stay.nightlyRate,
ratePlanCode = stay.ratePlanCode,
@@ -579,6 +580,7 @@ class BookingFlow(
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid date range")
}
validateRoomStayBoundsForExpectedDatesUpdate(booking, expectedIn, expectedOut)
syncActiveRoomStaysWithBookingExpectedDates(booking, expectedIn, expectedOut)
booking.updatedAt = OffsetDateTime.now()
bookingRepo.save(booking)
@@ -637,6 +639,32 @@ class BookingFlow(
}
}
private fun syncActiveRoomStaysWithBookingExpectedDates(
booking: com.android.trisolarisserver.models.booking.Booking,
expectedIn: OffsetDateTime?,
expectedOut: OffsetDateTime?
) {
val bookingId = booking.id ?: return
if (expectedIn == null && expectedOut == null) return
val activeStays = roomStayRepo.findActiveByBookingId(bookingId)
if (activeStays.isEmpty()) return
var changed = false
activeStays.forEach { stay ->
if (booking.status == BookingStatus.OPEN && expectedIn != null && stay.fromAt != expectedIn) {
stay.fromAt = expectedIn
changed = true
}
if (expectedOut != null && stay.plannedCheckoutAt != expectedOut) {
stay.plannedCheckoutAt = expectedOut
changed = true
}
}
if (changed) {
roomStayRepo.saveAll(activeStays)
}
}
@PostMapping("/{bookingId}/billing-policy")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Transactional

View File

@@ -69,7 +69,7 @@ class RoomStays(
roomTypeName = roomType.name,
fromAt = stay.fromAt.toString(),
checkinAt = booking.checkinAt?.toString(),
expectedCheckoutAt = booking.expectedCheckoutAt?.toString(),
expectedCheckoutAt = (stay.plannedCheckoutAt ?: booking.expectedCheckoutAt)?.toString(),
nightlyRate = stay.nightlyRate
)
}

View File

@@ -33,6 +33,9 @@ class RoomStay(
@Column(name = "to_at", columnDefinition = "timestamptz")
var toAt: OffsetDateTime? = null, // null = active
@Column(name = "planned_checkout_at", columnDefinition = "timestamptz")
var plannedCheckoutAt: OffsetDateTime? = null,
@Column(name = "is_voided", nullable = false)
var isVoided: Boolean = false,

View File

@@ -48,7 +48,7 @@ interface RoomStayRepo : JpaRepository<RoomStay, UUID> {
@Query("""
select rs.room.id as roomId,
rs.fromAt as fromAt,
b.expectedCheckoutAt as expectedCheckoutAt
coalesce(rs.plannedCheckoutAt, b.expectedCheckoutAt) as expectedCheckoutAt
from RoomStay rs
join rs.booking b
where rs.property.id = :propertyId