0

Consider a hotel which has multiple room types (e.g. single, double, twin, family), and multiple rooms. Each room can be a combination of room types (e.g. one particular room can be a double/twin room).

The problem I'm facing is how to determine availability of rooms based on what is booked already. Consider a hotel with 2 rooms:

  • Single / Double
  • Double / Family

We have a basic availability of:

  • Single: 1
  • Double: 2
  • Family: 1

(yes, it seems like there are four rooms, but so long as the availability > 1, it can be assigned, that's the premise I'm working on right now)

In this way, I can sell any combination of rooms, and only when a room availability counter hits zero will it affect the other rooms. E.g. I can sell a double room, and still keep the option of single or family room available. Only when another room is sold will everything close off.

So far, so good.

Except when I come up with a multiple S/D rooms (e.g. two or more) and sell them separately (e.g. a single, then a double) the counter doesn't reach 0 (so I can't use that as a trigger to close off other rooms) but I've sold the maximum number of physical rooms the hotel has anyway.

Clearly there's some fault in my approach to how I'm determining what's available, and I'd appreciate any pointers if this issue has been resolved before (as pseudo-code for now, I'll translate to MySQL/PHP once I've got my head around it).

Thanks

2
  • Are you saying that you're just decrementing the counter corresponding to what the customer is asking for? When you sell a S/D room to a customer asking for a D room, you need to decrement the counters for both S and D.
    – svk
    Jan 15, 2014 at 15:11
  • Now I am, yes. I've realised that's the only way to go. I've almost got the SQL working using the grouping functions, but stuck there on in...
    – JamShady
    Jan 16, 2014 at 13:53

1 Answer 1

0

I managed to resolve this eventually through SQL.

My reservations table holds a room_type_id, and a room_id. Depending on whether a room is assigned, I either join the pivot table and then room_types table, or the room_types table directly using the room_type_id. And then I just SUM() 1 for each tuple which thankfully returns the right amount when you group by room_type.id in the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.