8
When requesting a vehicle reservation, the system inserts the scheduled departure and return time code (we prefer to work with fixed codes instead of schedules in order to facilitate programming). What happens is that when the reservation is made at times ahead (for example, I am booking in the morning an hour in the afternoon) the system allows another reservation that goes "over" the previous reservation.
For example, if I book from 9:00 to 10:00, mine select
does not display this interval after confirmation, but if someone reserves from 8:00 to 11:00 on the same day he will let record. With the select
below I do not display the booked schedules, any idea how to do the validation?
SELECT H.* FROM HORARIOS H
WHERE NOT EXISTS (
SELECT * FROM RESERVAS R
WHERE H.COD BETWEEN R.COD_HORA_SAIDA AND
R.COD_HORA_PREVISTA-1 AND
R.COD_VEICULO = :codveiculo AND
DATE_FORMAT(DATA_SAIDA, \'%d-%m-%Y\') = :codcalendario AND
r.ativa = 1)
ORDER BY H.COD
Below is an example of the situation that occurs:
I couldn’t understand what your problem is. Can you explain it better please?
– Jorge B.
For example, I enter in the "reservations" table my reservation, for example, from 14:00 to 16:00. The system blocks the display of this interval, so no one can reserve this same time. But if someone wants to book from 13:00 (time that is free) until 17:00 (time also free) will manage, going over the previous reservation.
– Diego
So if someone wants to book from 1:00 to 5:00, they shouldn’t be able to book either, right?
– Jorge B.
How do you save that time code in the bank, @Diego? I wonder why, perhaps, if a second table were created, which would function as a list, and stored the hours that the car would remain, something like (following its example)
[14 15 16]
, could be easy to measure, and yourCONTAINS
function by checking the saved record for the record to be saved.– Gustavo Cinque
Another question, if it was selected from 13h to 15h, and if there was already a record of 14h to 16h, should not be allowed?
– Gustavo Cinque
@George B. exactly, if he wanted from 1:00 to 2:00 he could, but from 1:00 to 5:00 should be blocked.
– Diego
@Gustavocinque I have a schedule, every half hour. In every system I treat the hours with the code. You mean instead of recording an intermission, recording all the time he gets "out"? Type, time reservation code 1 to 5 record entire interval (1,2,3,4,5) in the bank?
– Diego
Yes, that’s right. So you could compare the two lists, if they contain the same elements. But you would still save the input and output columns, this second table would be for validation of this part of the system.
– Gustavo Cinque
This would be a bank solution, you could implement the same idea programmatically.
– Gustavo Cinque
@Gustavocinque I’m trying to build something with PHP, but really this is complicated.
– Diego