Skip to content
Advertisement

Booking Time slot, with Equipment Stock query, in Laravel

Here’s an interesting one for you all. I’ve found myself in a implementation conundrum.

I’m developing a booking app in Laravel that allows people to book rooms and equipment for spaces at specific times. The amount of equipment available is limited, so the amount of stock has to be queried in tandem with the time slots associated with the booking.

I thought I’d solved the problem by iterating through the ‘other bookings’ that occur at the same time and count up the items that are currently in use -> then check that against what’s available in stock.

For 90% of my tests this was working fine but have just managed to find a bug that won’t allow me to do this.

JavaScript

I then used individual if statements to redirect if the count wound up larger than the amount in the stock.

An example of the bug in action is:

2 drum kits in stock. Make one booking for 1-2pm… then another in the same room for 2-3pm. Both requiring a drumkit.

If I then try and make a booking in a different space from 1-3pm, the count is already 2, even if one set of drums is free again (If that makes sense).

I’m really stumped. I can’t envisage if I need to:

  • Continue with ‘counting’, but produce something that deducts 1 for each item that is in the same room as another (?).
  • Whether I should scrap counting completely and write individual queries for each equipment item… and how I would even do that!

Any help would be much obliged.

Advertisement

Answer

Although the method in my previous answer looked promising… it started to make unfixable counting errors as the stock amount and adjacent bookings scaled up.

I had a rethink and devised a better solution. Users will only be able to book at a minimum 30 minute slots anyway.

So using a do/while loop, for every 30 minute increment of users chosen time slot, it’ll do a stock check.

I’m sure it isn’t great to be hammering the server but at least there’s a fixed amount of time it will be queried during a booking.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement