# Booking Helper Functions

### function get\_booking($booking\_id) {...}

#### **Supported hooks**

**Filter name:**  before\_get\_booking\
**Description:** This filter would be executed before retrieving booking from database in get\_booking helper.\
**Usage:**

```php
 add_filter('before_get_booking', 'before_get_booking_callback_fn', 10, 1);
 
 function before_get_booking_callback_fn ($booking_id) {
   // This filter would be executed before retrieving booking from database in get_booking helper.
 }
```

**Filter name:**  should\_get\_booking\
**Description:** This filter would be executed before retrieving booking from database in get\_booking helper.\
**Usage:**

```php
add_filter('should_get_booking', 'should_get_booking_callback_fn', 10, 1);

 function should_get_booking_callback_fn ($booking_id) {
   // This filter would be executed before retrieving booking from database in get_booking helper.
 }
```

**Hook name :**  pre.get.booking\
**Description:** This hook would be executed before retrieving booking from database in get\_booking helper.\
**Usage:**

```php
add_filter('pre.get.booking', 'pre_get_booking_callback_fn', 10, 1);

 function pre_get_booking_callback_fn ($booking_id) {
   // This filter would be executed before retrieving booking from database in get_booking helper.
 }
```

**Hook name :**  post.get.booking\
**Description:** This hook would be executed after retrieving booking from database in get\_booking helper.\
**Usage:**

```php
add_filter('post.get.booking', ' post_get_booking_callback_fn', 10, 1);

 function post_get_booking_callback_fn ($booking_id) {
   // This filter would be executed before retrieving booking from database in get_booking helper.
 }
```

**Usage**

```php
// for use booking helper you need to add this helper on controller or
// you can autoload this helper.
$this->load->helper('includes/booking');

// Retrieves booking data based on a booking_id.
$booking_data = get_booking($booking_id);
```

**Request Parameters**

<table><thead><tr><th>Param</th><th>Type</th><th width="150">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>$booking_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>Booking ID is the primary key for the booking table.</td></tr></tbody></table>

**Response**

```php
// $response array includes following attributes:
// $response['rate'] : the rate (integer) of specific booking.
// $response['adult_count'] : the adult_count (integer) for specific booking (must required).
// $response['children_count'] : the children_count (integer) for specific booking.
// $response['company_id'] : the company_id (integer) for specific booking.
// $response['state'] : the state (integer) for specific booking (must required).
// $response['booking_notes'] : the booking_notes for specific booking.
// $response['booking_customer_id'] : the booking_customer_id (integer) for specific booking.
// $response['booked_by'] : the booked_by for specific booking.
// $response['balance'] : the balance (integer) for specific booking.
// $response['use_rate_plan'] : the use_rate_plan (integer) for specific booking (must required).
// $response['rate_plan_id'] : the rate_plan_id (integer) for specific booking.
// $response['charge_type_id'] : the charge_type_id (integer) for specific booking.
// $response['source'] : the source for specific booking.
// $response['is_ota_booking'] : the is_ota_booking (integer) for specific booking.
// $response['pay_period'] : the pay_period (integer) for specific booking.
// $response['room_type_id'] : the room_type_id (integer) for specific booking block.
// and many more attributes from table booking and join with booking block and customer table.

// Successfully response giving you array of booking data.
Array
(
    [booking_id] => 26
    [rate] => 40
    [adult_count] => 2
    [children_count] => 1
    [state] => 0
    [booking_notes] => 0
    [company_id] => 1
    [booking_customer_id] => 
    [booked_by] => 0
    [balance] => 10
    [balance_without_forecast] => 0
    [invoice_hash] => xxxxxxxxxxxxxxxxxxxxxx
    [use_rate_plan] => 1
    [rate_plan_id] => 1
    [color] => transparent
    [housekeeping_notes] => 
    [charge_type_id] => 0
    [guest_review] => 
    [is_deleted] => 0
    [source] => 0
    [is_ota_booking] => 0
    [pay_period] => 0
    [revenue] => 0
    [add_daily_charge] => 0
    [residual_rate] => 
    [is_invoice_auto_sent] => 0
    [name] => comapny 1
    [address] => 
    [phone] => 
    [city] => 
    [region] => 
    [country] => India
    [website] => 
    [email] => test@minical.io
    [fax] => 
    [selling_date] => 2022-01-27
    [nightly_audit_charge_id] => 
    [time_zone] => Pacific/Midway
)

// If there is no booking data for any booking id provided in input or any error will return null. 
```

### function add\_booking($booking) {...}

#### **Supported hooks**

**Filter name:**  before\_add\_booking\
**Description:** This filter would be executed before add booking into database in get\_booking helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_add_booking’, ‘before_add_booking_callback_fun’, 10, 1 );

function before_add_booking_callback_fun($booking) {
    // code
}
```

**Filter name:**  should\_add\_booking\
Description: This filter would be executed before add booking into database in get\_booking helper.\
Usage:

```php
// The filter callback function is based on the filter.

add_filter( ‘should_add_booking’, ‘example_callback_fun’, 10, 1 );

function example_callback_fun($booking) {
    // code
}

```

**hook name:**  pre.add.booking\
**Description:** This hook would be executed before add booking into the database in get\_booking helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.add.booking', 'pre_add_booking_callback_fun', 10, 1);

function pre_add_booking_callback_fun($booking) {
    // code
}
```

**hook name:**  post.add.booking\
**Description:** This hook would be executed after add booking into the database in get\_booking helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.add.booking', 'post_add_boking_callback_fun', 10, 1);

function post_add_boking_callback_fun($booking) {
    // code
}
```

**Usage**

```php
// Create a new booking that will also add booking details in booking, booking block and create a new invoice for booking.
 $booking_id = add_booking($booking);
```

**Request Parameters**

Parameters in array format includes following attributes:

| Param                   | Type       | Required | Default | Description                                                                                    |
| ----------------------- | ---------- | -------- | ------- | ---------------------------------------------------------------------------------------------- |
| room\_id                | Integer    | Yes      | Null    | The room\_id for specific booking block.                                                       |
| check\_in\_date         | Date\_time | Yes      | date    | The check\_in\_date for specific booking block.(must required date in gmdate() format)         |
| check\_out\_date        | Date\_time | Yes      | date    | the check\_out\_date for specific booking block(must required date in gmdate() format)         |
| room\_type\_id          | Integer    | Yes      | Null    | The room\_type\_id  for specific booking block.                                                |
| rate                    | Integer    |          |         | The rate of specific booking.                                                                  |
| adult\_count            | Integer    | Yes      | Null    | The adult\_count for specific booking (must require).                                          |
| children\_count         | Integer    |          | Null    | The children\_count  for specific booking.                                                     |
| company\_id             | Integer    | Yes      | Null    | The company for specific booking(must require).                                                |
| state                   | Integer    | Yes      | 0       | The state  for specific booking.                                                               |
| booking\_notes          | Text       |          | Null    | The booking\_notes for specific booking.                                                       |
| booking\_customer\_id   | Integer    | Yes      | Null    | The booking\_customer\_id it's the customer id from the customer table for a specific booking. |
| balance                 | Integer    |          | 0.00    | The balance for the specific booking.                                                          |
| use\_rate\_plan         | Integer    | Yes      | 0       | The use\_rate\_plan for specific booking (must require).                                       |
| rate\_plan\_id          | Integer    | Yes      | 0       | The rate\_plan\_id it's id from the rate plan table for specific booking.                      |
| charge\_type\_id        | Integer    |          | 0       | The charge\_type\_id for specific booking.                                                     |
| source                  | Integer    |          | 0       | The source of booking for specific booking.                                                    |
| is\_ota\_booking        | Integer    |          | 0       | The is\_ota\_booking conforms for specific booking.                                            |
| pay\_period             | Integer    |          | 0       | The pay\_period for specific booking.                                                          |
| room\_type\_id          | Integer    | Yes      | 0       | The room\_type\_id for specific booking block.                                                 |
| booking\_type           | Integer    |          | 0       | The booking\_type for hook function.                                                           |
| booking\_from           | Integer    |          | 0       | The booking\_from for hook function.                                                           |
| housekeeping\_notes     | Text       |          | Null    | The housekeeping\_notes for specific booking.                                                  |
| revenue                 | Integer    |          | 0       | The revenue for specific booking.                                                              |
| add\_daily\_charge      | Integer    |          | 0       | The add\_daily\_charge for specific booking.                                                   |
| residual\_rate          | Integer    |          | 0       | The residual\_rate for specific booking.                                                       |
| is\_invoice\_auto\_sent | Integer    |          | 0       | The is\_invoice\_auto\_sent for specific booking.                                              |

**Response**

```
Response includes the following attributes:
if data have been added successfully it would return the key of specific booking id.
```

```php
return $booking_id; 
```

```
if data does not add it will return null.
```

### function get\_bookings($filter) {.....}

**Supported hooks**

**Filter name:**  before\_get\_bookings\
**Description:** This filter would be executed before retrieving booking details from database in get\_bookings helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_get_bookings’, ‘before_get_bookings_callback_fun’, 10, 1 );

function before_get_bookings_callback_fun($filter) {
 // code
}
```

**Filter name:**  should\_get\_bookings\
**Description:** This filter would be executed before retrieving booking details from database in get\_bookings helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_get_bookings’, ‘should_get_bookings_callback_fun’, 10, 1 );

function should_get_bookings_callback_fun($filter) {
    // code
}
```

**hook name:**  pre.get.bookings\
**Description:** This hook would be executed before retrieving booking details from database in get\_bookings helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.get.bookings', 'pre_get_bookings_callback_fun', 10, 1);

function pre_get_bookings_callback_fun($filter) {
    // code
}
```

**hook name:**  post.get.bookings\
**Description:** This hook would be executed after retrieving payment details from database in get\_payments helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.get.bookings', 'post_get_bookings_callback_fun', 10, 1);

function post_get_bookings_callback_fun($filter) {
    // code
}
```

**Usage**

```php
// Retrieves booking data based on a filter array.
$booking_data = get_bookings($filter);
```

**Request Parameters**

parameter array filter required for booking details.

| Param        | Type    | Required | Default | Description                                                     |
| ------------ | ------- | -------- | ------- | --------------------------------------------------------------- |
| company\_id  | Integer | Yes      | Null    | The company id for a specific booking.                          |
| booking\_id  | Integer | Yes      | Null    | The primary key id of the booking table for a specific booking. |
| customer\_id | Integer | Yes      | Null    | The customer\_id  for a specific booking.                       |
| room\_id     | Integer | Yes      | Null    | The room\_id for a specific booking.                            |

**Response**

```php
// Successfully response giving you array of payment data.

Array
(
    [0] => Array
        (
            [booking_id] => 1
            [rate] => 10
            [adult_count] => 1
            [children_count] => 0
            [state] => 5
            [booking_notes] => 
            [company_id] => 1
            [booking_customer_id] => 1
            [booked_by] => 
            [balance] => 140
            [balance_without_forecast] => 140
            [invoice_hash] => xxxxxxxxxxxxxxxxxxxxxxxxxx
            [use_rate_plan] => 0
            [rate_plan_id] => 
            [color] => 
            [housekeeping_notes] => 
            [charge_type_id] => 1
            [guest_review] => 
            [is_deleted] => 0
            [source] => 0
            [is_ota_booking] => 0
            [pay_period] => 0
            [revenue] => 0
            [add_daily_charge] => 1
            [residual_rate] => 0
            [is_invoice_auto_sent] => 0
            [room_id] => 11
            [room_type_id] => 2
            [check_in_date] => 2021-12-10 00:00:00
            [check_out_date] => 2021-12-11 00:00:00
            [booking_room_history_id] => 1
            [customer_id] => 1
            [customer_name] => test user
            [address] => 
            [city] => 
            [region] => 
            [country] => 
            [postal_code] => 
            [phone] => 
            [fax] => 
            [email] => test1@gmail.com
            [customer_notes] => 
            [customer_type] => PERSON
            [cc_number] => 
            [cc_expiry_month] => 
            [cc_expiry_year] => 
            [stripe_customer_id] => 
            [customer_type_id] => 1
            [address2] => 
            [phone2] => 
            [cc_tokenex_token] => 
            [cc_cvc_encrypted] => 
        )

    [1] => Array
        (
            [booking_id] => 2
            [rate] => 20
            [adult_count] => 1
            [children_count] => 0
            [state] => 5
            [booking_notes] => 
            [company_id] => 1
            [booking_customer_id] => 2
            [booked_by] => 
            [balance] => 0
            [balance_without_forecast] => 0
            [invoice_hash] => xxxxxxxxxxxxxxxxxxxxxx
            [use_rate_plan] => 1
            [rate_plan_id] => 6
            [color] => 
            [housekeeping_notes] => 
            [charge_type_id] => 
            [guest_review] => 
            [is_deleted] => 0
            [source] => 0
            [is_ota_booking] => 0
            [pay_period] => 0
            [revenue] => 0
            [add_daily_charge] => 1
            [residual_rate] => 0
            [is_invoice_auto_sent] => 0
            [room_id] => 14
            [room_type_id] => 2
            [check_in_date] => 2021-12-17 00:00:00
            [check_out_date] => 2021-12-18 00:00:00
            [booking_room_history_id] => 2
            [customer_id] => 2
            [customer_name] => honey
            [address] => 
            [city] => 
            [region] => 
            [country] => 
            [postal_code] => 
            [phone] => 
            [fax] => 
            [email] => honey@gmail.com
            [customer_notes] => 
            [customer_type] => PERSON
            [cc_number] => 
            [cc_expiry_month] => 
            [cc_expiry_year] => 
            [stripe_customer_id] => 
            [customer_type_id] => 1
            [address2] => 
            [phone2] => 
            [cc_tokenex_token] => 
            [cc_cvc_encrypted] => 
        )
)

// if there is no booking data for filter provided in input or any error will return null.           
```

### function delete\_booking($booking\_id) {.....}

**Usage**

```php
// delete a booking data from booking table. it's a soft delete process only status will change data still existing in back end database.

 delete_booking($booking_id); 
```

**Request Parameters**

| Param        | Type    | Required | Description                                             |
| ------------ | ------- | -------- | ------------------------------------------------------- |
| $booking\_id | integer | yes      | The id of the booking corresponds to the booking table. |

**Response**

```
Response return mixed Either true or null if booking data is deleted then true 
else null.
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.minical.io/coming-soon/access-minical-data-using-helpers/booking-helper-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
