# Rate Plan Helper Functions

### function get\_rate\_plan($rate\_plan\_id) {....}

**Supported hooks**

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

```php
 add_filter('before_get_rate_plan', 'before_get_rate_plan_callback_fn', 10, 1);
 
 function before_get_rate_plan_callback_fn ($rate_plan_id) {
   // This filter would be executed before retrieving rate_planfrom database in get_rate_plan helper.
 }
```

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

```php
add_filter('should_get_rate_plan', 'should_get_rate_plan_callback_fn', 10, 1);

 function should_get_rate_plan_callback_fn ($rate_plan_id) {
   // This filter would be executed before retrieving rate_plan details from database in get_rate_plan helper.
 }
```

**Hook name :**  pre.get.rate\_plan\
**Description:** This hook would be executed before retrieving rate\_plan details from database in get\_rate\_plan helper.\
**Usage:**

```php
add_filter('pre.get.rate_plan', 'pre_get_rate_plan_callback_fn', 10, 1);

 function pre_get_rate_plan_callback_fn ($rate_plan_id) {
   // This filter would be executed before retrieving rate_plan details from database in get_rate_plan helper.
 }
```

**Hook name :**  post.get.rate\_plan\
**Description:** This hook would be executed after retrieving rate\_plan details from database in get\_rate\_plan helper.\
**Usage:**

```php
add_filter('post.get.rate_plan', ' post_get_rate_plan_callback_fn', 10, 1);

 function post_get_rate_plan_callback_fn ($rate_plan_id) {
   // This filter would be executed before retrieving rate_plan details from database in get_rate_plan helper.
 }
```

**Usage**

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

// Retrieves rate plan data based on a rate_plan_id.
$rate_plan_data = get_rate_plan($rate_plan_id);
```

**Request Parameters**

| Param           | Type    | Required | Default | Description                                                |
| --------------- | ------- | -------- | ------- | ---------------------------------------------------------- |
| $rate\_plan\_id | integer | yes      | null    | The id of the rate plan corresponds to the rate plan table |

**Response**

```php
// $response array includes following attributes:

Array
(
    [rate_plan_id] => 2
    [rate_plan_name] => Super Rate Plan
    [room_type_id] => 3
    [charge_type_id] => 1
    [description] => 
    [is_deleted] => 
    [number_of_adults_included_for_base_rate] => 4
    [currency_id] => 151
    [base_rate_id] => 2
    [is_selectable] => 1
    [image_group_id] => 8
    [is_shown_in_online_booking_engine] => 1
    [company_id] => 1
    [parent_rate_plan_id] => 
    [policy_code] => 
    [date_time] => 2021-12-10 12:01:01
    [rate_id] => 2
    [base_rate] => 
    [adult_1_rate] => 
    [adult_2_rate] => 
    [adult_3_rate] => 
    [adult_4_rate] => 
    [additional_adult_rate] => 
    [additional_child_rate] => 
    [minimum_length_of_stay] => 
    [maximum_length_of_stay] => 
    [minimum_length_of_stay_arrival] => 
    [maximum_length_of_stay_arrival] => 
    [closed_to_arrival] => 
    [closed_to_departure] => 
    [can_be_sold_online] => 1
)

//if there is no rate plan data for any rate plan id provided in input or any error will return null.
```

### function add\_rate\_plan($rate\_plan) {.....}

#### **Supported hooks**

**Filter name:**  before\_add\_rate\_plan\
**Description:** This filter would be executed before add rate plan into the database in add\_rate\_plan  helper.\
**Usage:**

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

add_filter( ‘before_add_rate_plan’, ‘before_add_rate_plan_callback_fun’, 10, 1 );

function before_add_rate_plan_callback_fun($rate_plan) {
 // code
}
```

**Filter name:**  should\_add\_rate\_plan\
**Description:** This filter would be executed before add rate plan into database in add\_rate\_plan helper.\
**Usage:**

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

add_filter( ‘should_add_rate_plan’, ‘should_add_rate_plan_callback_fun’, 10, 1 );

function should_add_rate_plan_callback_fun($rate_plan) {
    // code
}
```

**hook name:**  pre.add.rate\_plan\
**Description:** This hook would be executed before add rate plan into the database in add\_rate\_plan  helper.\
**Usage:**

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

add_action('pre.add.rate_plan', 'pre_add_rate_plan_callback_fun', 10, 1);

function pre_add_rate_plan_callback_fun($rate_plan) {
    // code
}
```

**hook name:**  post.add.rate\_plan\
**Description:** This hook would be executed after add rate plan into the database in add\_rate\_plan helper.\
**Usage:**

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

add_action('post.add.rate_plan', 'post_add_rate_plan_callback_fun', 10, 1);

function post_add_rate_plan_callback_fun($rate_plan) {
    // code
}
```

**Usage**

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

//add a new rate plan in rate_plan table.
$rate_plan_id = add_rate_plan($rate_plan);
```

**Request Parameters**

Parameters in array format includes following attributes:

<table><thead><tr><th width="199">Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>rate_plan_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The rate_plan_name of specific rate_plan.</td></tr><tr><td>room_type_id</td><td>Integer</td><td></td><td>0</td><td>The room_type_id  for specific rate_plan.</td></tr><tr><td>charge_type_id</td><td>Integer</td><td></td><td>0</td><td>The charge_type_id for specific rate_plan.</td></tr><tr><td>description</td><td>Text</td><td></td><td>Null</td><td>The description of specific rate_plan.</td></tr><tr><td>number_of_adults_included_for_base_rate</td><td>Integer</td><td></td><td>4</td><td>The number of adults included for base_rate in a rate plan.</td></tr><tr><td>currency_id</td><td>Integer</td><td></td><td>Null</td><td>The currency_id for specific rate_plan.</td></tr><tr><td>base_rate_id</td><td>Integer</td><td></td><td>Null</td><td>The base_rate_id for specific rate_plan.</td></tr><tr><td>is_selectable</td><td>Integer</td><td></td><td>1</td><td>The is_selectable for specific rate_plan.</td></tr><tr><td>is_shown_in_online_booking_engine</td><td>Integer</td><td></td><td>1</td><td>it's shown in online_booking_engine for a specific rate plan.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for a specific rate plan.</td></tr><tr><td>parent_rate_plan_id</td><td>Integer</td><td></td><td>Null</td><td>The parent_rate_plan_id for specific rate_plan.</td></tr><tr><td>policy_code</td><td>Character</td><td></td><td>Null</td><td>The policy_code for specific rate_plan.</td></tr></tbody></table>

**Response**

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

```php
return $rate_plan_id;
```

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

### function get\_rate\_plans($filter) {.....}

**Supported hooks**

**Filter name:**  before\_get\_rate\_plans\
**Description:** This filter would be executed before retrieving rate\_plan details from database in get\_rate\_plans helper.\
**Usage:**

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

add_filter( ‘before_get_rate_plans’, ‘before_get_rate_plans_callback_fun’, 10, 1 );

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

**Filter name:**  should\_get\_rate\_plans\
**Description:** This filter would be executed before retrieving rate\_plan details from database in get\_rate\_plans helper.\
**Usage:**

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

add_filter( ‘should_get_rate_plans’, ‘should_get_rate_plans_callback_fun’, 10, 1 );

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

**hook name:**  pre.get.rate\_plans\
**Description:** This hook would be executed before retrieving rate\_plan details from database in get\_rate\_plans helper.\
**Usage:**

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

add_action('pre.get.rate_plans', 'pre_get_rate_plans_callback_fun', 10, 1);

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

**hook name:**  post.get.rate\_plans\
**Description:** This hook would be executed after retrieving rate\_plan details from database in get\_rate\_plans helper.\
**Usage:**

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

add_action('post.get.rate_plans', 'post_get_rate_plans_callback_fun', 10, 1);

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

**Usage**

```php
// Retrieves rate_plan data based on a filter array.
$rate_plan_data = get_rate_plans($filter);
```

**Request Parameters**

parameter array filter required for charge details.

| Param            | Type      | Required | Default | Description                              |
| ---------------- | --------- | -------- | ------- | ---------------------------------------- |
| rate\_plan\_name | Character | Yes      | Null    | The description for a specific charge.   |
| company\_id      | Integer   | Yes      | Null    | The booking\_id  for specific charge.    |
| room\_type\_id   | Integer   | Yes      | Null    | The customer\_id  for a specific charge. |

**Response**

```php
// $response array includes following attributes:
// $response['key'] : the key of specific rate_plan
// $response['rate_plan_name'] : the rate_plan_name of specific rate_plan.
// $response['room_type_id'] : the room_type_id for specific rate_plan.
// $response['charge_type_id'] : the charge_type_id for specific rate_plan.
// $response['description'] : the description for specific rate_plan.
// $response['company_id'] : the company_id for specific rate_plan.
// $response['number_of_adults_included_for_base_rate'] : the number_of_adults_included_for_base_rate for specific rate_plan.
// and many more attributes from table rate_plan.

// Successfully response giving you array of rate plan data.

Array
(
    [0] => Array
        (
            [rate_plan_id] => 1
            [rate_plan_name] => simple Rate Plan
            [room_type_id] => 2
            [charge_type_id] => 1
            [description] => 
            [is_deleted] => 0
            [number_of_adults_included_for_base_rate] => 4
            [currency_id] => 151
            [base_rate_id] => 1
            [is_selectable] => 1
            [image_group_id] => 7
            [is_shown_in_online_booking_engine] => 1
            [company_id] => 1
            [parent_rate_plan_id] => 
            [policy_code] => 
            [date_time] => 2021-12-10 12:00:45
        )

)

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

### function update\_rate\_plan($rate\_plan, $rate\_plan\_id) {....}

**Usage**

```php
// update rate_plan data based on rate_plan update data and rate_plan_id.
 update_rate_plan($rate_plan, $rate_plan_id);
```

**Supported hooks**

**Filter name:**  before\_update\_rate\_plan\
**Description:** This filter would be executed before update rate\_plan into the database in update\_rate\_plan helper.\
**Usage:**

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

add_filter( ‘before_update_rate_plan’, ‘before_update_rate_plan_callback_fun’, 10, 1 );

function before_update_rate_plan_callback_fun($rate_plan, $rate_plan_id) {
 // code
}
```

**Filter name:**  should\_update\_rate\_plan\
**Description:** This filter would be executed before update rate\_plan into database in update\_rate\_plan helper.\
**Usage:**

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

add_filter( ‘should_update_rate_plan’, ‘should_update_rate_plan_callback_fun’, 10, 1 );

function should_update_rate_plan_callback_fun($rate_plan, $rate_plan_id) {
    // code
}
```

**hook name:**  pre.update.rate\_plan\
**Description:** This hook would be executed before update rate\_plan into the database in update\_rate\_plan helper.\
**Usage:**

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

add_action('pre.update.rate_plan', 'pre_update_rate_plan_callback_fun', 10, 1);

function pre_update_rate_plan_callback_fun($rate_plan, $rate_plan_id) {
    // code
}
```

**hook name:**  post.update.rate\_plan\
**Description:** This hook would be executed after update rate\_plan into the database in update\_rate\_plan helper.\
**Usage:**

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

add_action('post.update.rate_plan', 'post_update_rate_plan_callback_fun', 10, 1);

function post_update_rate_plan_callback_fun($rate_plan, $rate_plan_id) {
    // code
}
```

**Request Parameters**

Request required rate\_plan\_id and  array format data includes following attributes:

<table><thead><tr><th width="199">Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>rate_plan_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The primary key of rate plan table for specific rate plan.</td></tr><tr><td>rate_plan_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The rate_plan_name of specific rate_plan.</td></tr><tr><td>room_type_id</td><td>Integer</td><td></td><td>0</td><td>The room_type_id  for specific rate_plan.</td></tr><tr><td>charge_type_id</td><td>Integer</td><td></td><td>0</td><td>The charge_type_id for specific rate_plan.</td></tr><tr><td>description</td><td>Text</td><td></td><td>Null</td><td>The description of specific rate_plan.</td></tr><tr><td>number_of_adults_included_for_base_rate</td><td>Integer</td><td></td><td>4</td><td>The number of adults included for base_rate in a rate plan.</td></tr><tr><td>currency_id</td><td>Integer</td><td></td><td>Null</td><td>The currency_id for specific rate_plan.</td></tr><tr><td>base_rate_id</td><td>Integer</td><td></td><td>Null</td><td>The base_rate_id for specific rate_plan.</td></tr><tr><td>is_selectable</td><td>Integer</td><td></td><td>1</td><td>The is_selectable for specific rate_plan.</td></tr><tr><td>is_shown_in_online_booking_engine</td><td>Integer</td><td></td><td>1</td><td>it's shown in online_booking_engine for a specific rate plan.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for a specific rate plan.</td></tr><tr><td>parent_rate_plan_id</td><td>Integer</td><td></td><td>Null</td><td>The parent_rate_plan_id for specific rate_plan.</td></tr><tr><td>policy_code</td><td>Character</td><td></td><td>Null</td><td>The policy_code for specific rate_plan.</td></tr></tbody></table>

**Response**

```
Response return mixed Either true or null if rate plan data is updated then true else null.
```

### **function delete\_rate\_plan(**$rate\_plan\_i&#x64;**) {.....}**

**Usage**

```php
// delete a rate plan data from the rate plan table. it's a soft delete process only status will change data still existing in the backend database.

 delete_rate_plan($rate_plan_id);
```

**Request Parameters**

| Param           | Type    | Required | Default | Description                                                 |
| --------------- | ------- | -------- | ------- | ----------------------------------------------------------- |
| $rate\_plan\_id | integer | yes      | null    | The id of the rate plan  corresponds to the rate plan table |

**Response**

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