# Tax Helper Functions

### function add\_tax($tax) {.....}

#### **Supported hooks**

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

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

add_filter( ‘before_add_tax’, ‘before_add_tax_callback_fun’, 10, 1 );

function before_add_tax_callback_fun($tax) {
 // code
}
```

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

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

add_filter( ‘should_add_tax’, ‘should_add_tax_callback_fun’, 10, 1 );

function should_add_tax_callback_fun($tax) {
    // code
}

```

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

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

add_action('pre.add.tax', 'pre_add_tax_callback_fun', 10, 1);

function pre_add_tax_callback_fun($tax) {
    // code
}
```

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

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

add_action('post.add.tax', 'post_add_tax_callback_fun', 10, 1);

function post_add_tax_callback_fun($tax) {
    // code
}
```

**Usage**

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

// add a new tax in tax table.
$tax_id = add_tax($tax);
```

**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>tax_type</td><td>Character</td><td>Yes</td><td>Null</td><td>The tax_type of specific tax.</td></tr><tr><td>tax_rate</td><td>Decimal Integer</td><td></td><td>0</td><td>the tax_rate for specific tax.</td></tr><tr><td>is_percentage</td><td>Integer</td><td>Yes</td><td>1</td><td>The is_percentage is conformed tax in percentage or not for specific tax.</td></tr><tr><td>is_brackets_active</td><td>Integer</td><td>Yes</td><td>Null</td><td>The is_brackets_active  if active then create price bracket data for specific tax.</td></tr><tr><td>is_tax_inclusive</td><td>Integer</td><td></td><td>0</td><td>The is_tax_inclusive for specific tax.</td></tr><tr><td>start_range</td><td>Integer</td><td></td><td>Null</td><td>The start_range for specific tax price_bracket.</td></tr><tr><td>end_range</td><td>Integer</td><td></td><td>Null</td><td>The end_range  for specific tax price_bracket.</td></tr><tr><td>tax_rate_price_bracket</td><td>Integer</td><td></td><td>0</td><td>The tax_rate  for specific tax price_bracket.</td></tr><tr><td>is_percentage_price_bracket</td><td>Integer</td><td></td><td>1</td><td>The is_percentage  for specific tax price_bracket.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific tax.</td></tr></tbody></table>

**Response**

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

```

```php
return $tax_id;
```

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

### function get\_tax($tax\_type\_id) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_tax’, ‘before_get_tax_callback_fun’, 10, 1 );

function before_get_tax_callback_fun($tax_type_id) {
 // code
}
```

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

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

add_filter( ‘should_get_tax’, ‘should_get_tax_callback_fun’, 10, 1 );

function should_get_tax_callback_fun($tax_type_id) {
    // code
}
```

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

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

add_action('pre.get.tax', 'pre_get_tax_callback_fun', 10, 1);

function pre_get_tax_callback_fun($tax_type_id) {
    // code
}
```

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

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

add_action('post.get.tax', 'post_get_tax_callback_fun', 10, 1);

function post_get_tax_callback_fun($tax_type_id) {
    // code
}
```

**Usage**

```php
// Retrieves tax data based on a tax_type_id.
$tax_data = get_tax($tax_type_id);
```

**Request Parameters**

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

**Response**

```php
// $response array includes following attributes:
// $response['tax_type'] : the tax_type of specific tax.
// $response['tax_rate'] : the tax_rate for specific tax .
// $response['is_percentage'] : the is_percentage for specific tax.
// $response['company_id'] : the company_id for specific tax.
// $response['is_brackets_active'] : the is_brackets_active for specific tax.
// $response['is_tax_inclusive'] : the is_tax_inclusive for specific tax.
// $response['start_range'] : the start_range for specific tax price_bracket.
// $response['end_range'] : the end_range for specific tax price_bracket.
// $response['tax_rate_price_bracket'] : the tax_rate for specific tax price_bracket.
// $response['is_percentage_price_bracket'] : the is_percentage for specific tax price_bracket.
// and many more attributes for table tax and join with tax_price_bracket table.

// Successfully response giving you array of tax data.

Array
(
    [tax_type] => gst
    [tax_rate] => 12.000
    [company_id] => 1
    [tax_type_id] => 2
    [is_deleted] => 0
    [is_percentage] => 1
    [is_brackets_active] => 1
    [is_tax_inclusive] => 0
    [start_range] => 12
    [end_range] => 19
    [price_tax_rate] => 1
    [price_percentage] => 1
)
// if there is no tax data for any tax id provided in input or any error will return null. 
```

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

**Supported hooks**

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

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

add_filter( ‘before_get_taxes’, ‘before_get_taxes_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_taxes’, ‘should_get_taxes_callback_fun’, 10, 1 );

function should_get_taxes_callback_fun($filter) {
    // code
}

```

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

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

add_action('pre.get.taxes', 'pre_get_taxes_callback_fun', 10, 1);

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

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

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

add_action('post.get.taxes', 'post_get_taxes_callback_fun', 10, 1);

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

**Usage**

```php

// Retrieves tax data based on a filter array.
$tax_data = get_taxes($filter);
```

**Request Parameters**

parameter array filter required for tax details.

| Param         | Type      | Required | Default | Description                                                        |
| ------------- | --------- | -------- | ------- | ------------------------------------------------------------------ |
| tax\_type     | Character | Yes      | Null    | The tax type for a specific tax table.                             |
| company\_id   | Integer   | Yes      | Null    | The company\_id  for specific tax.                                 |
| tax\_type\_id | Integer   | yes      | Null    | The tax\_type\_id  primary key of tax type table for specific tax. |

**Response**

```php
// $response array includes following attributes:
// $response['tax_type'] : the tax_type of specific tax.
// $response['tax_rate'] : the tax_rate for specific tax .
// $response['is_percentage'] : the is_percentage for specific tax.
// $response['company_id'] : the company_id for specific tax.
// $response['is_brackets_active'] : the is_brackets_active for specific tax.
// $response['is_tax_inclusive'] : the is_tax_inclusive for specific tax.
// $response['start_range'] : the start_range for specific tax price_bracket.
// $response['end_range'] : the end_range for specific tax price_bracket.
// $response['tax_rate_price_bracket'] : the tax_rate for specific tax price_bracket.
// $response['is_percentage_price_bracket'] : the is_percentage for specific tax price_bracket.
// and many more attributes for table tax and join with tax_price_bracket table.

// Successfully response giving you array of tax data.

Array
(
    [tax_type] => gst
    [tax_rate] => 12.000
    [company_id] => 1
    [tax_type_id] => 2
    [is_deleted] => 0
    [is_percentage] => 1
    [is_brackets_active] => 1
    [is_tax_inclusive] => 0
    [start_range] => 12
    [end_range] => 19
    [price_tax_rate] => 1
    [price_percentage] => 1
)

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

### function update\_tax($tax, $tax\_type\_id) {....}

**Usage**

```php
//update tax data based on a update data and tax_type_id.
 update_tax($tax, $tax_type_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_tax’, ‘before_update_tax_callback_fun’, 10, 1 );

function before_update_tax_callback_fun($tax, $tax_type_id) {
 // code
}
```

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

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

add_filter( ‘should_update_tax’, ‘should_update_tax_callback_fun’, 10, 1 );

function should_update_tax_callback_fun($tax, $tax_type_id) {
    // code
}

```

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

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

add_action('pre.update.tax', 'pre_update_tax_callback_fun', 10, 1);

function pre_update_tax_callback_fun($tax, $tax_type_id) {
    // code
}
```

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

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

add_action('post.update.tax', 'post_update_tax_callback_fun', 10, 1);

function post_update_tax_callback_fun($tax, $tax_type_id) {
    // code
}
```

**Request Parameters**

Request required tax\_type\_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>tax_type_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The tax type id  primary key or tax_type table. </td></tr><tr><td>tax_type</td><td>Character</td><td>Yes</td><td>Null</td><td>The tax_type of specific tax.</td></tr><tr><td>tax_rate</td><td>Decimal Integer</td><td></td><td>0</td><td>the tax_rate for specific tax.</td></tr><tr><td>is_percentage</td><td>Integer</td><td>Yes</td><td>1</td><td>The is_percentage is conformed tax in percentage or not for specific tax.</td></tr><tr><td>is_brackets_active</td><td>Integer</td><td>Yes</td><td>Null</td><td>The is_brackets_active  if active then create price bracket data for specific tax.</td></tr><tr><td>is_tax_inclusive</td><td>Integer</td><td></td><td>0</td><td>The is_tax_inclusive for specific tax.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific tax.</td></tr></tbody></table>

**Response**

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

### **function delete\_**&#x74;a&#x78;**(**$tax\_type\_i&#x64;**) {.....}**

**Usage**

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

 delete_tax($tax_type_id);
```

**Request Parameters**

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

**Response**

```
Response return mixed Either true or null if tax 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/tax-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.
