简体   繁体   中英

Logical error in the query of the booking system

I got a glitch in my logic from the reservation system. I have a room I can rent.

My database has the following test entries for the reservation: 在此处输入图像描述

Now someone wants to book the room from 15.06 - 17.06 but the 17.06 is already booked.

I thought of something like

SELECT * FROM reservation WHERE resDate >= "2020-06-15" AND depDate <= "2020-06-17"

and my query with Doctrine looks like

        return $this->createQueryBuilder('s')
            ->where('s.resDate >= :startdate')
            ->andWhere('s.depDate <= :enddate')
            ->setParameter('startdate', $startdate)
            ->setParameter('enddate', $enddate)
            ->getQuery()
            ->getOneOrNullResult()
            ;

Somehow I can't find a corresponding logic where the query tells me that it hasn't found an entry and that the entered period is free. What am I doing wrong?

Your booking starts from 17th so it is still free to book from 15th to 17th.

Therefore your logic should be to just query the database with 1 day less that is 16th as checkout will be done on 17th.

Usually when booking happens for 15th to 17th it means the guest has paid for 15th, 16th and 17th and will be checking out on 18th morning. That is why you see 3 nights and 5 nights stay in hotel reservations. But in your case as you are explaining it. It seems like you are counting same day in 2 places.

Either way you have to change the way the customer is trying to book the room in first place otherwise the crude fix won't work well and it will create other confusions later on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM