From tcindie:
No, I don't think that functionality has been written yet.

I agree it definitely should be included. If you're willing to work on it to get that implemented, that'd be appreciated. Basically all you should have to do is duplicate one of the conditional action predicates, and have it fire an action if the status is changed to 'Cancelled'.

While you're at it, it might be worth changing the existing function that decreases availability to handle both increasing and decreasing as most of the logic is already complete, it would simply need a flag to determine if you are increasing or decreasing availabilities, and in the event you are increasing them, they should only be increased if the dates are far enough into the future to not be affected by the variable that is set for when to zero out availability (equal to and older than: yesterday, today, or tomorrow).

The functions that need to be updated for this are in the hotel_booking.module

hotel_booking_reduce_availability() should probably change to something like hotel_booking_alter_availability()

and the predicate(s) needed to fire the action should be added to hotel_booking_ca_predicate()

Here's an idea of how the hotel_booking_reduce_availability function might be changed to handle this:

<?php

// Existing reduce availability function:
function hotel_booking_reduce_availability($order) {
  watchdog('hotel booking', "Processing booking(s)");
  if (is_array($order->products)) {
    foreach ($order->products as $key => $product){
      if ($product->data['module'] = 'hotel_booking'){
        $nid = $product->nid;
        $nights = $product->data['nights'];
        if (is_array($nights)) {
          foreach ($nights as $night) {
            watchdog('hotel booking',t('Room type: @model availability reduced for !night', array('@model' => $product->model, '!night' => $night)));
            db_query("UPDATE {hotel_availability_calendars} SET avail_quantity = avail_quantity - 1 WHERE rtid = %d AND caldate = '%s'", $nid, $night);
          }
        }
      }
    }
  }
}


// Should become something like this:
function hotel_booking_alter_availability($order, $method = 'reduce') {
  switch($method) {
    case 'reduce':
      watchdog('hotel booking', "Processing booking(s)");
      if (is_array($order->products)) {
        foreach ($order->products as $key => $product){
          if ($product->data['module'] = 'hotel_booking'){
            $nid = $product->nid;
            $nights = $product->data['nights'];
            if (is_array($nights)) {
              foreach ($nights as $night) {
                watchdog('hotel booking',t('Room type: @model availability reduced for !night', array('@model' => $product->model, '!night' => $night)));
                db_query("UPDATE {hotel_availability_calendars} SET avail_quantity = avail_quantity - 1 WHERE rtid = %d AND caldate = '%s'", $nid, $night);
              }
            }
          }
        }
      }
    break;
    case 'increase':
      watchdog('hotel booking', "Processing canceled booking(s)");
      if (is_array($order->products)) {
        foreach ($order->products as $key => $product){
          if ($product->data['module'] = 'hotel_booking'){
            $nid = $product->nid;
            $nights = $product->data['nights'];
            if (is_array($nights)) {
              foreach ($nights as $night) {
		if (_non_zeroed_date($night)) {
                  watchdog('hotel booking',t('Room type: @model availability increased for !night', array('@model' => $product->model, '!night' => $night)));
                  db_query("UPDATE {hotel_availability_calendars} SET avail_quantity = avail_quantity + 1 WHERE rtid = %d AND caldate = '%s'", $nid, $night);
                }
              }
            }
          }
        }
      }
    break;
  }
}


// A new function _non_zeroed_date($date) referred to in the example here would be required to determine if the passed date value were a date that's not yet been zeroed out.
CommentFileSizeAuthor
#2 uc_hotel-631934.patch9.03 KBshushu
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shushu’s picture

In the current hotel_booking_ca_predicate() hotel_booking_checkout_complete is disabled (status 0) and hotel_booking_payment_received is enabled (status 1).
What is the reason for that ?
Does hotel_booking_checkout_complete is just junk ?

shushu’s picture

Status: Active » Needs review
FileSize
9.03 KB

Patch includes:
- hotel_booking_alter_availability() instead of hotel_booking_reduce_availability()
- _non_zeroed_date() and its helper _expiration_date()
- Since _expiration_date() code was taken from hotel_calendars.module, I didn't want to duplicate code so I changed hotel_calendars.module as well.
- Needed additions to the action and predicate

Please review,
Shushu

willvincent’s picture

> In the current hotel_booking_ca_predicate() hotel_booking_checkout_complete is disabled (status 0) and hotel_booking_payment_received is enabled (status 1).
> What is the reason for that ?
> Does hotel_booking_checkout_complete is just junk ?

This creates the two predicates that allow the end user to choose if they want to decrease availability when status is changed to checkout complete, or when the payment received trigger fires. If they are both enabled, the number available will be decreased twice, which is why only one is enabled by default.

willvincent’s picture

Status: Needs review » Fixed

Committed to CVS

I made a couple small changes to a couple of the function names, so they live in the hotel_booking namespace, rather than just _function_name()

Also, fixed the db table name in the cron portion of the patch.

willvincent’s picture

Status: Fixed » Closed (fixed)
lancemannlee’s picture

Please can anyone help show me how to increase the number of nights as the 14 nights default is not ok for the project i'm working on. OR if there was a way to include a Check Out field.

larowlan’s picture