Skip to content

Commit

Permalink
make things work for school-less orders
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgreenthal committed Oct 20, 2023
1 parent f36b797 commit 6433016
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ interface BookingRepository : CrudRepository<Booking, Long> {
nativeQuery = true
)
fun countLowerIdBookingsForSchoolId(schoolId: Long, bookingId: Long): Long

@Query(
"select count(*) from booking where school_id is null and id < ?1",
nativeQuery = true
)
fun countLowerIdBookingsForNoSchool(bookingId: Long): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ class InvoiceCalculator {
@Autowired private lateinit var invoiceLineRepo: InvoiceLineRepository

fun determineInvoiceLabel(booking: Booking): String {
val schoolId = booking.school!!.id!!
val schoolId = booking.school?.id

val bookingsWithLowerId = repo.countLowerIdBookingsForSchoolId(schoolId, booking.id!!)
val bookingsWithLowerId = if (schoolId == null) {
repo.countLowerIdBookingsForNoSchool(booking.id!!)
} else {
repo.countLowerIdBookingsForSchoolId(schoolId, booking.id!!)
}
val thisBookingSequence = bookingsWithLowerId + 1

return "$schoolId-$thisBookingSequence"
val displayableSchoolId = schoolId?.toString() ?: "X"

return "$displayableSchoolId-$thisBookingSequence"
}

// This logic is described in the UI, so when updating it, it should be updated in both places.
Expand Down

0 comments on commit 6433016

Please sign in to comment.