I would like to make a view displaying how many nights are booked in a particular month. I thought that just counting the number of days that are 'unavailable' in a month would do it, but I cannot find the field where room X at date Y is set to unavailable.
It is not the booking status field anyway, that field is switched to 1 as soon as a booking is confirmed, but such a booking can consist of any number of days. So which field should I use?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

LeDucDuBleuet’s picture

I would also like to know the best approach to provide such a report for occupancy rate?

Any hint would be greatly appreciated, thank you.

plopesc’s picture

Version: 7.x-1.1 » 7.x-1.x-dev

Hello,
Here is a brief example of how you can extract this kind of information.
You should implement something like this in a custom module.

$unit_id = 'your_unit_id';
$start_date = new Datetime ('your_start_date');
$end_date = new Datetime ('your_end_date');

$json_events  = array();
$rc = new UnitCalendar($unit->unit_id, $unit->default_state);

$events = $rc->getEvents($start_date, $end_date);

foreach ($events as $event) {
  if ($event->id == ROOMS_AVAILABLE) {
    print 'Rooms was not occupied from ' . $event->start_date->format('Y/m/d') . ' to ' . $event->end_date->format('Y/m/d');
  }
}

Hope this helps.

TheoRichel’s picture

Thank you very much. I am sure this is very useful, but alas I am not a programmer and wouldnt know what to do with this.

LeDucDuBleuet’s picture

Status: Active » Fixed
FileSize
12.93 KB

I created a view to report the occupancy rate using PHP so you need to have the module https://www.drupal.org/project/views_php enabled. The code is pretty simple and it should work by simply importing the view in your system but your mileage may vary. Contact me privately if you need my services to adapt it to your needs.

I tried to make the view as generic as possible, I hope this helps!

LeDucDuBleuet’s picture

Status: Fixed » Needs work

I am marking this issue as "Needs work" because the view needs adjusting before it can work on a specific site.

LeDucDuBleuet’s picture

FileSize
10.25 KB

Here is an updated view which will show the units occupancy rate for the last 365 days and will import cleanly in a system with a basic rooms installation. The previous one was using a content type specific to our system, sorry to have miss this...

TheoRichel’s picture

Thanks very much LeDucDuBleuet, your view works wonderful

dorys’s picture

This is a great View. I am just wondering if there is anyway to add a date filter so instead of

$start_date = new Datetime ('now - 364 days');
$end_date = new Datetime ('now');

both start date and end date are filterable?