A
A
arcticworker2019-12-04 22:15:05
1C-Bitrix
arcticworker, 2019-12-04 22:15:05

How to implement a booking system for a hotel?

Conventionally, the hotel has a list of rooms (number1, number2, number3, etc.), some rooms have types (Type1, Type2).
When booking, I plan to create records, for example:
11/03/2019 Room1 Type2 Occupied
11/06/2019 Room2 Type2 Occupied
11/08/2019 Room1 Type1 Occupied
11/11/2019 Room3 ------ Occupied
, etc.
But then I don’t really understand how to find out which numbers are free for a given date range, for example, find out the free numbers from 11/01/2019 to 11/15/2019.
From the ideas there are the following:
№1
1) take all the rooms
2) take all the bookings for one date (11/01/2019)
3) compare the two lists received earlier and exclude the rooms booked for this date, thus I will get free rooms
4) do this algorithm for each day for the interval from the query i.e. from 11/01/2019 to 11/15/2019
No. 2
Initially store data in a different form, for all numbers of all types for each day there should be a record of the form
11/01/2019 Number 1 Type 1 Free
or
11/01/2019 Number 1 Type 1 Busy
Then I make a request at the interval from 01.11. 2019 to 11/15/2019 and the status is free.
This option seems redundant to me and I don’t really understand when to decide on the generation of such records, i.e. once a year to create for the whole year ahead? And when adding a new number or type, these records must be generated for it.
What other options exist for solving the reservation problem? Also interested in comments on the proposed options.
I will implement it in php for Bitrix.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton R., 2019-12-04
@anton_reut

I'm here a little bit of our coding for the night looking:

<?php

// Желаемые даты
$date_arrive = '01.01.2000'; 
$date_depart = '03.01.2000';

// Создаем массив "дней".
$booking = range(strtotime($date_arrive) / 86400, strtotime($date_depart)  / 86400);

// Диапазон дат из базы когда номер забронирован (не доступен).
$closed = range(strtotime('02.01.2000') / 86400, strtotime('05.01.2000')  / 86400);

// Изначально статус "свободен".
$status = 1;

foreach($closed as $c){
  // Если находит пересечение дат то статус "занят, бронь невозможна".
  if(in_array($c, $booking)){
  $status = 0;
  }
}

echo $status;

But here it is still necessary to provide for a search of periods from the database when the number is busy, I did not write this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question