> For the complete documentation index, see [llms.txt](https://docs.minical.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.minical.io/coming-soon/access-minical-data-using-helpers/charge-helper-functions.md).

# Charge Helper Functions

### function add\_charge($charge) {.....}

#### **Supported hooks**

**Filter name:**  before\_add\_charge\
**Description:** This filter would be executed before add charge into the database in add\_charge  helper.\
**Usage:**

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

add_filter( ‘before_add_charge’, ‘before_add_charge_callback_fun’, 10, 1 );

function before_add_charge_callback_fun($charge) {
 // code
}
```

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

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

add_filter( ‘should_add_charge’, ‘should_add_charge_callback_fun’, 10, 1 );

function should_add_charge_callback_fun($charge) {
    // code
}

```

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

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

add_action('pre.add.charge', 'pre_add_charge_callback_fun', 10, 1);

function pre_add_charge_callback_fun($charge) {
    // code
}
```

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

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

add_action('post.add.charge', 'post_add_charge_callback_fun', 10, 1);

function post_add_charge_callback_fun($charge) {
    // code
}
```

**Usage**

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

// add a new charge in charge table.
$charge_id = add_charge($charge);
```

**Request Parameters**

Parameters in array format includes following attributes:

<table><thead><tr><th>Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>description</td><td>Character</td><td>Yes</td><td>Null</td><td>The description of a specific charge.</td></tr><tr><td>date_time</td><td>Date_time</td><td></td><td>Date</td><td>The date_time for specific charge( must provide date in gmdate() format).</td></tr><tr><td>booking_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The booking_id (integer) for a specific charge.</td></tr><tr><td>amount</td><td>Decimal Integer</td><td>Yes</td><td>0</td><td>The amount for a specific charge.</td></tr><tr><td>charge_type_id</td><td>Integer</td><td></td><td>0</td><td>The charge_type_id for a specific charge.</td></tr><tr><td>selling_date</td><td>Date</td><td>Yes</td><td>Date</td><td>The selling_date for specific charge ( must provide date in gmdate() format).</td></tr><tr><td>user_id</td><td>Integer</td><td></td><td>Null</td><td>The user_id for a specific charge.</td></tr><tr><td>customer_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The customer_id for a specific charge.</td></tr><tr><td>pay_period</td><td>Integer</td><td></td><td>1</td><td>The pay_period for specific charge.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific charge.</td></tr><tr><td>quantity</td><td>Integer</td><td>Yes</td><td>0</td><td>The quantity for a specific charge.</td></tr><tr><td>folio_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The folio_id for a specific charge.</td></tr><tr><td>is_extra_pos</td><td>Integer</td><td>Yes</td><td>1</td><td>The is_extra_pos if active then charge add as  POS for a specific charge.</td></tr></tbody></table>

**Response**

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

```php
return $charge_id;
```

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

### function get\_charge($charge\_id) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_charge’, ‘before_get_charge_callback_fun’, 10, 1 );

function before_get_charge_callback_fun($charge_id) {
 // code
}
```

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

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

add_filter( ‘should_get_charge’, ‘should_get_charge_callback_fun’, 10, 1 );

function should_get_charge_callback_fun($charge_id) {
    // code
}
```

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

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

add_action('pre.get.charge', 'pre_get_charge_callback_fun', 10, 1);

function pre_get_charge_callback_fun($charge_id) {
    // code
}
```

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

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

add_action('post.get.charge', 'post_get_charge_callback_fun', 10, 1);

function post_get_charge_callback_fun($charge_id) {
    // code
}
```

**Usage**

```php
// Retrieves charge data based on a charge_id.
$charge_data = get_charge($charge_id);
```

**Request Parameters**

| Param       | Type    | Required | Default | Description                                                  |
| ----------- | ------- | -------- | ------- | ------------------------------------------------------------ |
| $charge\_id | Integer | Yes      | Null    | The primary id of the charge corresponds to the charge table |

**Response**

```php
// $response array includes following attributes:
// $response['description'] : the description of specific charge.
// $response['date_time'] : the date_time  for specific charge.
// $response['booking_id'] : the booking_id  for specific charge.
// $response['amount'] : the amount for specific charge.
// $response['charge_type_id'] : the charge_type_id for specific charge.
// $response['selling_date'] : the selling_date  for specific charge.
// $response['is_night_audit_charge'] : the is_night_audit_charge  for specific charge.
// and many more attributes for table charge.

// Successfully response giving you array of charge data.

Array
(
    [charge_id] => 1
    [description] => mobile charger
    [date_time] => 
    [booking_id] => 1
    [amount] => 25.00
    [is_deleted] => 0
    [charge_type_id] => 1
    [selling_date] => 2021-12-10
    [user_id] => 1
    [customer_id] => 1
    [pay_period] => 
    [is_night_audit_charge] => 0
)

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

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

**Supported hooks**

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

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

add_filter( ‘before_get_charges’, ‘before_get_charges_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_charges’, ‘should_get_charges_callback_fun’, 10, 1 );

function should_get_charges_callback_fun($filter) {
    // code
}

```

**hook name:**  pre.get.charges\
**Description:** This hook would be executed before retrieving charge details from database in get\_charges helper.\
**Usage:**

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

add_action('pre.get.charges', 'pre_get_charges_callback_fun', 10, 1);

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

**hook name:**  post.get.charges\
**Description:** This hook would be executed after retrieving charge details from database in get\_charges helper.\
**Usage:**

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

add_action('post.get.charges', 'post_get_charges_callback_fun', 10, 1);

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

**Usage**

```php
// Retrieves charge data based on a filter array.
$charge_data = get_charges($filter);
```

**Request Parameters**

parameter array filter required for charge details.

| Param            | Type      | Required | Default | Description                                 |
| ---------------- | --------- | -------- | ------- | ------------------------------------------- |
| description      | Character | Yes      | Null    | The description for a specific charge.      |
| booking\_id      | Integer   | Yes      | Null    | The booking\_id  for specific charge.       |
| customer\_id     | Integer   | Yes      | Null    | The customer\_id  for a specific charge.    |
| charge\_type\_id | Integer   | Yes      | Null    | The charge\_type\_id for a specific charge. |
| user\_id         | Integer   | Yes      | Null    | The user\_id for a specific charge          |

**Response**

```php
// $response array includes following attributes:
// $data['description'] : the description of specific charge.
// $data['date_time'] : the date_time  for specific charge.
// $data['booking_id'] : the booking_id  for specific charge.
// $data['amount'] : the amount for specific charge.
// $data['charge_type_id'] : the charge_type_id for specific charge.
// $data['selling_date'] : the selling_date  for specific charge .
// $data['is_night_audit_charge'] : the is_night_audit_charge  for specific charge.
// and many more attributes for charge table and join with customer,booking,user_profiles tables.

// Successfully response giving you array of charge data.
Array
(
    [0] => Array
        (
            [charge_id] => 1
            [description] => mobile charger
            [date_time] => 
            [booking_id] => 1
            [amount] => 25.00
            [is_deleted] => 0
            [charge_type_id] => 1
            [selling_date] => 2021-12-10
            [user_id] => 1
            [customer_id] => 1
            [pay_period] => 0
            [is_night_audit_charge] => 0
            [customer_name] => test user
            [address] => 
            [city] => 
            [region] => 
            [country] => 
            [postal_code] => 
            [phone] => 
            [fax] => 
            [email] => test1@gmail.com
            [company_id] => 1
            [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] => 
            [id] => 1
            [name] => Room Charge
            [is_room_charge_type] => 1
            [is_default_room_charge_type] => 1
            [is_tax_exempt] => 0
            [current_company_id] => 1
            [first_name] => support
            [last_name] => minical
            [language] => english
            [language_id] => 1
            [rate] => 10
            [adult_count] => 1
            [children_count] => 0
            [state] => 5
            [booking_notes] => 
            [booking_customer_id] => 1
            [booked_by] => 
            [balance] => 140
            [balance_without_forecast] => 140
            [invoice_hash] => xxxxxxxxxxxxxxxxxxxxxxxx
            [use_rate_plan] => 0
            [rate_plan_id] => 
            [color] => 
            [housekeeping_notes] => 
            [guest_review] => 
            [source] => 0
            [is_ota_booking] => 0
            [revenue] => 0
            [add_daily_charge] => 1
            [residual_rate] => 0
            [is_invoice_auto_sent] => 0
            [charge_type_name] => Room Charge
            [folio_id] => 0
            [user_name] => support minical
        )
)

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

### function update\_charge($charge, $charge\_id) {....}

**Usage**

```php
// update charge data based on charge update data and charge_id.
 update_charge($charge, $charge_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_charge’, ‘before_update_charge_callback_fun’, 10, 1 );

function before_update_charge_callback_fun($charge, $charge_id) {
 // code
}
```

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

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

add_filter( ‘should_update_charge’, ‘should_update_charge_callback_fun’, 10, 1 );

function should_update_charge_callback_fun($charge, $charge_id) {
    // code
}

```

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

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

add_action('pre.update.charge', 'pre_update_charge_callback_fun', 10, 1);

function pre_update_charge_callback_fun($charge, $charge_id) {
    // code
}
```

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

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

add_action('post.update.charge', 'post_update_charge_callback_fun', 10, 1);

function post_update_charge_callback_fun($charge, $charge_id) {
    // code
}
```

**Request Parameters**

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

<table><thead><tr><th>Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>charge_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The primary key id of charge table for a specific charge.</td></tr><tr><td>description</td><td>Character</td><td>Yes</td><td>Null</td><td>The description of a specific charge.</td></tr><tr><td>date_time</td><td>Date_time</td><td></td><td>Date</td><td>The date_time for specific charge( must provide date in gmdate() format).</td></tr><tr><td>booking_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The booking_id (integer) for a specific charge.</td></tr><tr><td>amount</td><td>Decimal Integer</td><td>Yes</td><td>0</td><td>The amount for a specific charge.</td></tr><tr><td>charge_type_id</td><td>Integer</td><td></td><td>0</td><td>The charge_type_id for a specific charge.</td></tr><tr><td>selling_date</td><td>Date</td><td>Yes</td><td>Date</td><td>The selling_date for specific charge ( must provide date in gmdate() format).</td></tr><tr><td>user_id</td><td>Integer</td><td></td><td>Null</td><td>The user_id for a specific charge.</td></tr><tr><td>customer_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The customer_id for a specific charge.</td></tr><tr><td>pay_period</td><td>Integer</td><td></td><td>1</td><td>The pay_period for specific charge.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific charge.</td></tr><tr><td>is_night_audit_charge</td><td>Integer</td><td></td><td>0</td><td>The is_night_audit_charge <br>for a specific charge</td></tr><tr><td>folio_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The folio_id for a specific charge.</td></tr></tbody></table>

**Response**

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

### **function delete\_**&#x63;harg&#x65;**(**$charge\_i&#x64;**) {.....}**

**Usage**

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

 delete_charge($charge_id);
```

**Request Parameters**

| Param       | Type    | Required | Default | Description                                                  |
| ----------- | ------- | -------- | ------- | ------------------------------------------------------------ |
| $charge\_id | Integer | Yes      | Null    | The primary id of the charge corresponds to the charge table |

**Response**

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