# Introduction

## Welcome to miniCal Documentation

This space contains information about the extension and others feature by miniCal. You'll find extension tutorials with examples, overbooking explanations, custom data management, and extension integration best practices examples.

### miniCal Marketplace

Explore the extension of miniCal on [miniCal Marketplace](http://marketplace.minical.io/).

### Contact Us <a href="#contact-us" id="contact-us"></a>

If you have additional questions, our integrations team is happy to help:

* Message us on [discord](< https://discord.gg/a7B7RXZ3w5>)
* Email us at: <support@minical.io>

If you would like to provide feedback on any part of this documentation, please email us at: <support@minical.io>


# miniCal Hosted Service

How to signup for hosted service

### How to signup for hosted service

You can start your business at the miniCal Hosted service.

we will walk you through step by step.

**Register with miniCal**

* go to miniCal hosted service at <https://app.minical.io/auth/register>, Fill up all the details and get register with us.

![register form](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2Fv0ddyxySlraWrJlrCxOR%2Fimage%20\(34\).png?alt=media\&token=37e4f5d2-15e2-41ac-93de-eef915eeea32)

* In the second form fill-up your company details.&#x20;

![property form](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2F2iZhwySVqi7QyxUpE1qm%2Fimage%20\(35\).png?alt=media\&token=aa9ef94d-7484-4f09-9611-1f0b923c7c5f)

now you can explore our hosted service.


# Configure Feature Settings

### Configure minical property using Feature settings

miniCal has several feature settings, you can enable or disable this setting according to your need.

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FmXenQ41jHiklxWmkn0Rc%2Fimage%20\(36\).png?alt=media\&token=e21fe995-b6af-474e-a287-5e756f192501)


# Install Extensions

### How to install or uninstall an extension

On the extensions page, you will find all extension tabs this page contains all the extensions available on miniCal.

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FoEIsiWdCTkAAGxYcHZHt%2Fimage%20\(38\).png?alt=media\&token=fd2419c8-bce0-44bc-8bbf-f2b9f8a2daaf)

you can simply install or uninstall any extension you want.

### How to active an extension

After installing an extension, you can easily activate or deactivate it by the toggle button. You can mark an extension as a favorite.

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2F1D4vin3V76uFM45HtOwW%2Fimage%20\(39\).png?alt=media\&token=a890245d-a647-4ca6-8826-47631a91dae9)


# Create Multiple Properties

[Multi Property Management](https://marketplace.minical.io/product/multi-property-management/) you can use this extenstion to manage multiple properties on miniCal whether it's a hotel, car rental or anything.

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FSUz8ZcPYr1cBXZk5qDlu%2Fimage%20\(37\).png?alt=media\&token=d110cc84-a9c0-416b-8eed-76cf1f18d312)


# Local Installation

### Follow this step to install miniCal locally.

* Fork the repository miniCal [git-repo](https://github.com/minical/minical) or clone it locally.
* Install the stable version of PHP 7.2.0 or higher, MySQL 5.0.4, and OS-specific dependency tools.
* Create a MySql database with any name.
* Do the basic [configuration updates](https://github.com/minical/minical/wiki/configuration) on the public->build.json file.
* Create a new file named ".env" by copying the .env.example file which is located in the root.
* Update database credentials and project URL in .env file, for more details check the [.env example](https://github.com/minical/minical/wiki/.env-example).
* Run the "composer install" command on your project.
* Make your-server.com point to /public directory of miniCal installation.
* Install miniCal by going to `http://localhost/minical/public/install.php` in your browser and creating an admin account.

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FGzdrXVTbZM7UKiWyWN8q%2Fimage%20\(41\)\(3\).jpg?alt=media\&token=e7d6f2b2-4200-444f-b0e9-d3fa7df46368)

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FAFQMnJgWikShNes3U183%2Fimage.png?alt=media\&token=fece5507-6058-425a-b145-df56b36d5b47)

* That's it. You are done! Visit miniCal at `http://localhost/minical/public`


# ENV Set-Up

#### Environment Variables

Environment variables allow developers to extract sensitive credentials from their source code and to use different configuration variables based on their working environment. Here is an example of a .env file.

```
# database connection 

DATABASE_HOST = 'ENTER YOUR DATABSE HOST NAME'
DATABASE_USER = 'ENTER YOUR DATABSE USER NAME'
DATABASE_PASS = 'ENTER YOUR DATABSE PASSWORD'
DATABASE_NAME = 'ENTER YOUR DATABSE NAME'


# Set it to 'production' or 'development'
ENVIRONMENT = 'development'

# PATH to minical/public folder (for example, http://localhost/minical/public)
PROJECT_URL = 'http://localhost/minical/public'

# PATH to minical/api folder (for example, http://localhost/minical/api)
API_URL = 'http://localhost/minical/api'

# AWS info

AWS_ACCESS_KEY = 'ENTER YOUR AWS ACCESS KEY HERE'
AWS_SECRET_KEY = 'ENTER YOUR AWS SECRET KEY HERE'
AWS_S3_BUCKET = 'ENTER YOUR AWS S3 BUCKET NAME'


# smtp email info

SMTP_USER = 'ENTER YOUR SMTP USER HERE'
SMTP_PASS = 'ENTER YOUR SMTP PASS HERE'


# Capthcha info

RECAPTCHA_SITE_KEY = 'ENTER YOUR RECAPTCHA SITE KEY HERE'
RECAPTCHA_SECRET_KE.Y = 'ENTER YOUR RECAPTCHA SECRET KEY HERE'
```


# Configuration Settings

Guide to all available configuration settings(build.json Configuration).

Project settings are always configured by using a JSON configuration file in the project->public directory named build.json. This file contains a JSON object.

**build.json example for Hotel**

```json
{
  "name": "Hotel",
  "version": "1.0.0",
  "dependencies": {
    "online_booking_engine" : "1.0.0",
    "advance_deposit_report" : "1.0.0"
  },
  "settings": {
      "unit_name":{
         "singular": "room", 
         "plural" : "rooms" 
         },
      "unit_type_name" :  {
         "singular":"room type",
         "plural": "room types"
         },
         "hourly_booking_enabled" : true,
         "display_tooltip" : true
   }
}
```

**build.json example Hostel**

```json
{
   "name": "Hostel",
   "version": "1.0.0",
   "dependencies": {
      "online_booking_engine" : "1.0.0",
      "todays_panel" : "1.0.0",
      "invoice_email" : "1.0.0"      
   },
   "settings": {
      "unit_name":{ 
         "singular": "bed", 
         "plural" : "beds" 
         },
      "unit_type_name" : {
         "singular":"room type",
         "plural": "room types"
         },
      "display_tooltip" : true,
      "hourly_booking_enabled" : true,
      "allow_free_bookings" : true,
      "force_room_selection" : true      
   }
}
```

**build.json example for Vacation Rental**

```json
{
   "name": "Vacation Rental",
   "version": "1.0.0",
   "dependencies": {
      "online_booking_engine" : "1.0.0",
      "todays_panel" : "1.0.0",
      "invoice_email" : "1.0.0"      
   },
   "settings": {
      "unit_name":{ 
         "singular": "room",
         "plural" : "rooms" 
        },
      "unit_type_name" :  {
         "singular":"room type",
         "plural": "room types"
      },   
      "display_tooltip" : true,
      "hourly_booking_enabled" : true,
      "allow_free_bookings" : true,
      "force_room_selection" : true      
   }
}
```

**build.json example for Apartment**

```json
{
   "name": "Apartment",
   "version": "1.0.0",
   "dependencies": {
      "todays_panel" : "1.0.0",
      "advance_deposit_report" : "1.0.0",
      "invoice_email" : "1.0.0"
   },
   "settings": {
      "unit_name":{ 
         "singular": "unit", 
         "plural" : "units" 
         },
      "unit_type_name" :  {
         "singular":"unit type",
         "plural": "unit types"
      },
      "send_invoice_email_automatically" : true,
      "display_tooltip" : true,
      "is_total_balance_include_forecast" : true
   }
}
```

**build.json example for Car Rental**

```json
{
   "name": "Car Rental",
   "version": "1.0.0",
   "description": "",
   "dependencies": {
     "online_booking_engine" : "1.0.0",
   },
   "settings": {
      "unit_name":{ 
         "singular": "vehicle", 
         "plural" : "vehicles" 
         },
      "unit_type_name" :  {
         "singular":"vehicle type",
         "plural": "vehicle types"
         }
      },
      "allow_free_bookings" : false,
      "force_room_selection" : true,
      "is_total_balance_include_forecast" : true,
      "hourly_booking_enabled" : true      
   }   
}
```

**build.json for example** **Office Space**

```json
{
   "name": "Office Space",
   "version": "1.0.0",
   "dependencies": {
      "online_booking_engine" : "1.0.0",
      "advance_deposit_report" : "1.0.0",
      "automated_night_audit" : "1.0.0"
   },
   "settings": {
      "unit_name":{
         "singular": "room", 
         "plural" : "rooms" 
         },
      "unit_type_name" :  {
         "singular":"room type",
         "plural": "room types"
         },
         "hourly_booking_enabled" : true,
         "display_tooltip" : true
    }
  }
```

#### Here is a detailed description of each key.

**Name**

The name key holds the value of the property type. your business type will be the property type.

```json
name: "hotel"
```

**Version**

The version is broken down into 4 points e.g 1.2.3.4 We use MAJOR.MINOR.FEATURE.PATCH to describe the version numbers.

```json
version: "1.0.0"
```

**Dependencies**

This key has a JSON array of extensions that comes with this particular package. This JSON array has an extension name as a key and it's the version as value.

```json
"dependencies": {
"online_booking_engine": "1.0.0"
}
```

**Settings**

This key has a JSON array of feature settings. This JSON array has feature name as key and true or false as value for activating or deactivating a particular feature, handling this application's default features settings. below we have provided a table of feature settings attribute.jso

```json
"settings": {
      "unit_name":{
         "singular": "room", 
         "plural" : "rooms" 
         },
      "unit_type_name" :  {
         "singular":"room type",
         "plural": "room types"
         },
         "hourly_booking_enabled" : true,
         "display_tooltip" : true
   }
```


# Common Installations Errors

Common errors  during local installation

On this page, you find the common errors that occur during the local installations of miniCal.

### <mark style="color:blue;">**Q)**</mark><mark style="color:blue;">.</mark> Database installation is stuck?

<img src="https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FvxqYu8aYh3dcoHw3O311%2Fimage.png?alt=media&amp;token=eeb1a5ad-7cde-499d-ba21-ca7f668d1854" alt="" data-size="original">

<mark style="color:blue;">**Ans.**</mark> If you are using **Apache serve** then do these configurations.

1. &#x20;check if the rewrite module is enabled.
2. &#x20;set apache2.conf AllowOverride All to your Directory

```
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
```

If you are using **Nginx** then do these configurations. Check this link for more details <https://github.com/minical/minical/blob/master/docker/nginx.conf>.

```
        fastcgi_buffers 8 16k;       # default is 8 4k|8k
        fastcgi_buffer_size 32k;     # default is 4k|8k
        fastcgi_connect_timeout 60s; # default is 60s
        fastcgi_send_timeout 300s;   # default is 60s
        fastcgi_read_timeout 300s;   # default is 60s
```

```
location / {
        rewrite ^/api/(.*)$ /api/index.php?/$1 last;
        rewrite ^/public/(.*)$ /public/index.php?/$1 last;
        try_files $uri $uri/ /index.php?/$request_uri;
    }
```

### <mark style="color:blue;">**Q).**</mark>**&#x20;H**ow to publish in apache 'api' point in the virtual host if "minical/public" and "minical/api" in the same directory?

<mark style="color:blue;">**Ans.**</mark>  For virtual host configuration, you can create two separate virtual hosts for Apache, something like this:

```
<VirtualHost *:80>
    DocumentRoot /var/www/html/minical/app/api/
    ServerName api.your-server.com
    CustomLog /usr/local/apache/logs/minical.io.access combined
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html/minical/app/public/
    ServerName app.your-server.com
    CustomLog /usr/local/apache/logs/minical.io.access combined
</VirtualHost>
```

### <mark style="color:blue;">**Q).**</mark> How to add extensions on local setup?

<mark style="color:blue;">**Ans.**</mark> You can download a few Open source extensions here <https://docs.minical.io/build-an-extension/open-source-extensions> Put them in your local extensions directory located at "/minical/public/application/extensions/".

### <mark style="color:blue;">**Q).**</mark> SMTP settings and AWS keys are mandatory before DB installation?

<mark style="color:blue;">**Ans.**</mark> No, these are not mandatory.


# Contribute to miniCal Core

### Contribute

Any contribution for a new feature or an improvement will be appreciated.

**To make a contribution:**

1. Fork the repository and edit.
2. Submit the pull request, please provide a comprehensive description of PR as a commit message.
3. Any pull request that the reviewers don't find useful to miniCal will be rejected. We recommend you to talk to us first before working on a PR. Also, please ensure your code is following [Codeigniter Style Guide](https://codeigniter.com/userguide3/general/styleguide.html).

### How to develop an extension

Do you have an idea of an extension that might be a great addon to the miniCal community?

Follow [Extension development guide](/build-an-extension/build-your-first-extension).


# Build Your First Extension

Let's create a booking list extension. For any new extension, you have to know the directory structure first.

Building your first miniCal extension? Use the [**Boilerplate Extension**](https://github.com/minical/minical-extension-boilerplate) to set up a new extension in a minute.

The [**Boilerplate Extension**](https://github.com/minical/minical-extension-boilerplate) allows you to quickly setup a foundation for new minical extension. \
The Boilerplate includes a few demo pages that showcase how you can retrieve data from the miniCal database, how you can store custom data in the Posts table (similar to wordpress), and how you can store extension-specific settings and options in the options table (Similar to wordpress).\
Here's how the Boilerplate extension looks once installed:

![booking list page](https://camo.githubusercontent.com/53b7965cd5a09ee9793ddf8f42e07a453132aba574f2f885771e2a8a95e49eae/68747470733a2f2f692e696d6775722e636f6d2f6c56354839726e2e706e67)

#### Extension Directory Structure

This is the directory structure that miniCal follows for an extension, under the extensions folder create a minical-extension-boilerplate folder. You can download the boilerplate extension here [Extension Boilerplate](https://github.com/minical/minical-extension-boilerplate).

{% code title="directory structure" %}

```
|->public
     |->application
	    |->extensions
		  |->minical-extension-boilerplate
			 |->assets
                              |->js
                              |->css
			 |->config
                              |->autoload.php
                              |->config.php
                              |->menu.php
                              |->route.php
			 |->controllers
                         |->helpers
                         |->hooks
                              |->actions.php
                              |->filters.php
                         |->language
                         |->libraries
			 |->models
	                 |->view
                         |->composer.json
```

{% endcode %}

**For more real examples, explore our popular open-source extensions:**

1. [Online Booking Engine](https://github.com/minical/online-booking-engine)
2. [Booking Confirmation Email](https://github.com/minical/booking-confirmation-email)
3. [Channex Integration](https://github.com/minical/channex_integration)
4. [Stripe Payment Gateway](https://github.com/minical/stripe-integration)
5. [Boilerplate Extension](https://github.com/minical/minical-extension-boilerplate)


# Controllers

We’ll start by creating a controller inside minical-extension-boilerplate->controllers. In this example, there is a variable $module\_name its module name or folder name in this case it's minical-extension-boilerplate. \_Construct(), initialize all the dependencies such as models, libraries, helpers. now moving forward in any controller's method load the JS or CSS file related to that particular section. Here is the detail about how you can add custom data into the database [Broken mention](broken://pages/4n8NvyIW7Yx4OAdH3krh).

{% code title="show\_booking.php" %}

```php
<?php 
class Show_booking extends MY_Controller
{
    public $module_name;
	function __construct()
	{
        parent::__construct();

        $this->module_name = $this->router->fetch_module();
        $this->load->model('../extensions/'.$this->module_name.'/models/Bookings_model');
        $this->load->library('../extensions/'.$this->module_name.'/libraries/GreetingEmail');
     
	}
	
    /**
    * This function will display the list of the last 20 bookings.
    * load the template of the booking page
    */  
    function show_latest_bookings(){

        $data['bookings'] = $this->Bookings_model->get_bookings();
        $files = get_asstes_files($this->module_assets_files, $this->module_name, $this->controller_name, $this->function_name);

        $data['menu_on'] = TRUE;
        $data['selected_menu'] = 'bookings';
        $data['main_content'] = '../extensions/'.$this->module_name.'/views/booking';

        // library function call
        // $this->greetingemail->send_greeting_email();

        // action call
        // do_action('action name', variable);
        // do_action('add.booking.created', $data);  // this is a core action
        // do_action('my-custom-action', $data);   //this is a custom action 

        // filter call
        // apply_filter('filter name', variable);
        // apply_filter('my-custom-action', $data);

        // helpers function call
        // check if funtion exists or not
        // if(function_exists('custom_helper')){
        //   custom_helper($data);
        // }

        $this->template->load('bootstrapped_template', null , $data['main_content'], $data);
    }

    /**
    * This function will display the list of the last 20 customers.
    * load the template of customer page
    */  
    function show_customer_list()
    {
        $data['customers'] = $this->Bookings_model->get_customer_list();
        $files = get_asstes_files($this->module_assets_files, $this->module_name, $this->controller_name, $this->function_name);
        $data['menu_on'] = TRUE;
        $data['main_content'] = '../extensions/'.$this->module_name.'/views/customer_list';
        $this->template->load('bootstrapped_template', null , $data['main_content'], $data);
    } 
}
```

{% endcode %}


# Assets

This folder has two subfolders CSS and js, As clear by its name all the js files (.js extension) or third-party files will reside here. And all CSS files custom or third-party will reside here.

```
---->asset
    |---->js
    |---->css
```

Here is the JS file

```javascript
//file name booking_list.js
$(document).ready(function () {
    $('#booling_list').DataTable();
    $('#customer_list').DataTable();
});
j
```

CSS file

```css
/* File name extension.css */
.nav-color{
    background-color: #337ab7 !important;
}
```


# Config

This folder has four files each file has its different work.

* autoload.php
* config.php
* menu.php
* route.php

**autoload.php:** This file load all the asset dependency in the controller. Make a config array and add all files to it, config array has a "file" key that has JS file location as value and a "location" key that has an array of locations("controller\_name/method\_name") as value(where this JS file going to load). Here is the detailed description of the [**autoload file**](https://github.com/minical/minical/wiki/Autoload-file).

{% code title="autoload.php" %}

```php
<?PHP 
//load js file on controller function
$config['js-files'] = array(
    array(
        "file" => 'https://nightly.datatables.net/js/jquery.dataTables.js',
        "location" => array(
            "show_booking/show_latest_bookings",
            "show_booking/show_customer_list",      
            "custom_data/get_post_data",
            "option_data/get_option_data",
        ),
    ), 
    array(
        "file" => 'assets/js/booking_list.js',
        "location" => array(
            "show_booking/show_latest_bookings",
            "show_booking/show_customer_list", 
        ),
    ),
    array(
        "file" => 'assets/js/post_custom_data.js',
        "location" => array(
            "custom_data/get_post_data",
        ),
    ),
    array(
        "file" => 'assets/js/option_data.js',
        "location" => array(
            "option_data/get_option_data",
        ),
    )
);

//load css file for controller function
$config['css-files'] = array(
    array(
        "file" => 'assets/css/extension.css',
        "location" => array(
            "show_booking/show_latest_bookings",
            "show_booking/show_customer_list",
            "custom_data/get_post_data",
            "option_data/get_option_data",
            "sample_controller/index",
            "sample_controller/show_info_page",
        ),
    ),
    array(
        "file" => 'https://nightly.datatables.net/css/jquery.dataTables.css',
        "location" => array(
            "show_booking/show_latest_bookings",
            "show_booking/show_customer_list",
            "custom_data/get_post_data",
            "option_data/get_option_data",
         ),
    ),
);

//load helpers file 
$extension_helper = array(
    'booking_list_helper'
  );
```

{% endcode %}

**config.php:** This file has the config array containing the extension details such as name, description, or any information about it. 'is\_default\_active' key has 1 or 0. Here is the detailed description of the [**config file**](https://github.com/minical/minical/wiki/Config-file).

{% code title="config.php" %}

```php
<?php 

$config = array(
        "name" => "Minical Extension Boilerplate",
        "description" => "It is a sample boilerplate extension it contains the basic structure of a typical extension. It will show you the list of bookings.",
        "is_default_active" => 1,
        "version" => "1.0.0", // version of extension
        "logo" => "", // extension's log image
        "view_link" => "sample_page", // view icon link
        "setting_link" => "sample_page", // setting icon link
        "categories" => array("payment_process"), // category of extension
        "marketplace_product_link" => ""
    
    );
```

{% endcode %}

**menu.php:** This file has menu-related details such as the extension's menu label, position on the menu bar, and route link. In this array, the 'location' key has a value such as PRIMARY, SECONDARY, and THIRD. 'label' key has menu label, 'link' key has URL link.

{% code title="menu.php" %}

```php
<?php 
$module_menu = array(
	array(
		'label' => 'Bookings List',
		'location' => 'PRIMARY',
		'link' => 'bookings_list'
	)
);
```

{% endcode %}

**route.php:** This has an array of extension routes, the route will be defined as the same ci route. Here is the detailed description of the [**route file**](https://github.com/minical/minical/wiki/Route-File).

{% code title="route.php" %}

```php
<?php

//sample page
    $extension_route['sample_page'] = 'sample_controller/index';

//list route    
    $extension_route['bookings_list'] = 'show_booking/show_latest_bookings';
    $extension_route['customer_list'] = 'show_booking/show_customer_list';

//post route
    $extension_route['post_data'] = 'custom_data/get_post_data';
    $extension_route['add_custom_data'] = 'custom_data/add_custom_data';
    $extension_route['edit_custom_data/(:any)'] = 'custom_data/edit_custom_data/$1';
    $extension_route['update_custom_data'] = 'custom_data/update_custom_data';
    $extension_route['delete_custom_data/(:any)'] = 'custom_data/delete_custom_data/$1';

//option route
    $extension_route['option_data'] = 'option_data/get_option_data';
    $extension_route['add_option_data'] = 'option_data/add_option_data';
    $extension_route['edit_option_data'] = 'option_data/edit_option_data';
    $extension_route['update_option_data'] = 'option_data/update_option_data';
    $extension_route['delete_option_data'] = 'option_data/delete_option_data';

//info route
    $extension_route['info_page'] = 'sample_controller/show_info_page';
```

{% endcode %}


# language

Language folder contains subfolders of languages, each language subfolder will contain an index.php file, this file will have an array of words.

```
language
      |->english
             |->index.php
      |->korean
             |->index.php
      |->portuguese 
             |->index.php

```

$lang array key will have the like \[extension\_folder\_name]\[keyword] and for value translation of the keyword. Here is an example for English.&#x20;

File location (language/english/index.php)

{% code title="index.php" %}

```php
<?php

$lang['minical-extension-boilerplate']['booking list'] = 'Booking List';
$lang['minical-extension-boilerplate']['booking_id'] = 'Booking ID';
$lang['minical-extension-boilerplate']['room_number'] = 'Room Number';
$lang['minical-extension-boilerplate']['check_in_date'] = 'Check-In Date';
$lang['minical-extension-boilerplate']['check_out_date'] = 'Check-Out Date';
$lang['minical-extension-boilerplate']['customer_name'] = 'Customer Name';
$lang['minical-extension-boilerplate']['no_bookings_found'] = 'No Booking Found';
?>
```

{% endcode %}

Below is an example for Portuguese. File location (language/portuguese/index.php)

{% code title="index.php" %}

```php
<?php

$lang['minical-extension-boilerplate']['booking list'] = 'lista de reservas';
$lang['minical-extension-boilerplate']['booking_id'] = 'ID de reserva';
$lang['minical-extension-boilerplate']['room_number'] = 'Número do quarto';
$lang['minical-extension-boilerplate']['check_in_date'] = 'Data de Check-In';
$lang['minical-extension-boilerplate']['check_out_date'] = 'Data de Check-Out';
$lang['minical-extension-boilerplate']['customer_name'] = 'Nome do Cliente';
$lang['minical-extension-boilerplate']['no_bookings_found'] = 'Nenhuma reserva encontrada';
?>
```

{% endcode %}

Below is an example for Korean. File location (language/korean/index.php)

{% code title="index.php" %}

```php
<?php

$lang['minical-extension-boilerplate']['booking list'] = '예약 목록';
$lang['minical-extension-boilerplate']['booking_id'] = '예약 ID';
$lang['minical-extension-boilerplate']['room_number'] = '방 번호';
$lang['minical-extension-boilerplate']['check_in_date'] = '체크인 날짜';
$lang['minical-extension-boilerplate']['check_out_date'] = '체크 아웃 날짜';
$lang['minical-extension-boilerplate']['customer_name'] = '고객 이름';
$lang['minical-extension-boilerplate']['no_bookings_found'] = '예약을 찾을 수 없습니다';
?>
```

{% endcode %}

#### How to display keywords

For displaying any keyword in extension, keyword should be concatenated with extension folder name with '/' for example 'minical-extension-boilerplate/name' pass this string to l() function like l('minical-extension-boilerplate/name', true) Below other example has given for it.

```php
<?php echo l('minical-extension-boilerplate/booking_id', true);?>

<?php echo l('minical-extension-boilerplate/room_number', true);?>
```


# Models

This folder contains model files, all the database-related queries will go on these files.

{% code title="bookings\_model.php" %}

```php
<?php
class Bookings_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    /**
    * This function will return the result-set array of bookings.
    * @return Array $result array of bookings.
    */  
    function get_bookings()
    {
        $company_id = $this->session->userdata('current_company_id');
        
         $sql_query ="SELECT b.rate,b.booking_id,bb.room_id,bb.check_in_date, bb.check_out_date, r.room_name, c.customer_name, c.email
                from booking b, booking_block bb, room r, customer c
                where b.booking_id=bb.booking_id 
                and bb.room_id=r.room_id
                and b.booking_customer_id=c.customer_id
                and b.company_id=$company_id order by b.booking_id DESC LIMIT 20" ;
        
        $booking_data = $this->db->query($sql_query);    
            if ($this->db->_error_message()) 
            {
                show_error($this->db->_error_message());
            }
         $result = $booking_data->result_array();       
        
        return $result;
    }
   
      /**
    * This function will return the result-set array of customers.
    * @return Array $result array of customers.
    */  
    function get_customer_list()
    {
        $company_id = $this->session->userdata('current_company_id');
        $query = "SELECT customer_name, email, address,phone FROM customer where company_id = $company_id order by customer_id DESC LIMIT 20";
        $customer = $this->db->query($query);    
        if ($this->db->_error_message()) 
        {
            show_error($this->db->_error_message());
        }
        
        $result = $customer->result_array();       
        return $result;
    }  
}
```

{% endcode %}


# View

A view is simply a web page, or a page fragment, like a header, footer, sidebar, etc. Views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy. Views are never called directly, they must be loaded by a controller.

{% code title="booking.php" %}

```php
<!-- page heading -->
<div class="app-page-title">
	<div class="page-title-wrapper">
		<div class="page-title-heading">
			<div class="page-title-icon">
				<i class="pe-7s-diskette text-success"></i>
			</div>
			<div><?php echo l('minical-extension-boilerplate/booking list'); ?>

		</div>
	<div class="app-page-title">
    <div class="page-title-wrapper">
        <div class="page-title-heading">
            <div class="page-title-icon">
                <i class="pe-7s-diskette text-success"></i>
            </div>
            <div><?php echo l('minical-extension-boilerplate/Bolierplate Extenstion'); ?>

            </div>
        </div>
    </div>
</div>

<!-- page nav bar if you have too many pages then add them in nav -->
<div class="topnav nav-color mb-3">
    <ul>
        <li><a class="<?php if($this->uri->segment(1) == 'sample_page') echo 'active'; ?>"
                href="<?php echo base_url().'sample_page'?>"><?php echo l('minical-extension-boilerplate/Blank Page', true); ?></a>
        </li>
        <li><a class="<?php if($this->uri->segment(1) == 'bookings_list') echo 'active'; ?>"
                href="<?php echo base_url().'bookings_list'?>"><?php echo l('minical-extension-boilerplate/Booking list', true); ?></a>
        </li>
        <li><a class="<?php if($this->uri->segment(1) == 'customer_list') echo 'active'; ?>"
                href="<?php echo base_url().'customer_list'?>"><?php echo l('minical-extension-boilerplate/Customer List', true); ?></a>
        </li>
        <li><a class="<?php if($this->uri->segment(1) == 'post_data') echo 'active'; ?>"
                href="<?php echo base_url().'post_data'?>"><?php echo l('minical-extension-boilerplate/Post Custom data', true); ?></a>
        </li>
        <li><a class="<?php if($this->uri->segment(1) == 'option_data') echo 'active'; ?>"
                href="<?php echo base_url().'option_data'?>"><?php echo l('minical-extension-boilerplate/Options Custom data', true); ?></a>
        </li>
        <li><a class="<?php if($this->uri->segment(1) == 'info_page') echo 'active'; ?>"
                href="<?php echo base_url().'info_page'?>"><?php echo l('minical-extension-boilerplate/Document', true); ?></a>
        </li>
    </ul>
</div>

<!-- page body -->
<div class="main-card card">
    <div class="card-body">
        <!-- Required for opening booking dialog while viewing [Show all...] pages -->
        <div class="">
            <h5>This is a sample page showing the list of last 20 bookings, it's just for you to understand how an
                extension works. You can either modify it or
                delete it.</h5>
            <hr>
            <table id="booling_list" class="display" style="width:100%">
                <thead>
                    <tr>
                        <th class=" text-center"><?php echo l('minical-extension-boilerplate/booking_id', true);?></th>

                        <th class="text-center"><?php echo l('minical-extension-boilerplate/room_number', true);?></th>

                        <th class="text-center"><?php echo l('minical-extension-boilerplate/check_in_date', true);?>
                        </th>

                        <th class="text-center"><?php echo l('minical-extension-boilerplate/check_out_date', true);?>
                        </th>

                        <th class="text-center"><?php echo l('minical-extension-boilerplate/customer_name', true);?>
                        </th>

                    </tr>
                </thead>
                <tbody>
                    <?php 
                        if (isset($bookings) && $bookings):
                        foreach ($bookings as $booking) : 
                        if (isset($booking['booking_id'])):
                    ?>
                    <tr class='booking'>
                        <td class="text-center"><?php echo $booking['booking_id']; ?></td>
                        <td class="text-center">
                            <?php echo $booking['room_name'] ? $booking['room_name'] : 'Not Assigned'; ?>
                        </td>
                        <td class="text-center"><?php echo $booking['check_in_date']; ?></td>
                        <td class="text-center"><?php echo $booking['check_out_date']; ?></td>
                        <td class="text-center"><?php echo $booking['customer_name']; ?></td>
                    </tr>
                    <?php 
                    endif;
                    endforeach;
                    else:
                     ?>
                    <tr class='booking' data-booking-id=''>
                        <td></td>
                        <td></td>
                        <td class="text-center">
                            <h3><?php echo l('minical-extension-boilerplate/no_bookings_found', true);?></h3>
                        </td>
                        <td></td>
                        <td></td>
                    </tr>
                    <?php 
                        endif;
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
```

{% endcode %}


# Helper

Each helper file is simply a collection of functions in a particular category. For example, we have a booking\_list\_helper.php file.

```php
<?PHP
//file name booking_list_helper.php
function custom_helper($data){
    // start writing code here   
}
?>
```

**Loading of booking\_list\_helper.php**

For loading helper file go to the autoload.php under config folder of your extension add helper file in the array, use $extension\_helper variable. you can add multiple helper files into this array, they will be loaded automatically by my\_controller.

```php
//file name autoload.php
$extension_helper  = array(
                      'booking_list_helper'
                     );
```


# Library

The library is a class with functions or methods that allows creating an instance of that class. For your extensions you can add a library under the libraries folder, the naming convention should be like GreetingEmail.php. here is an example of a library.

```php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class GreetingEmail {

    public function __construct()
    {
        $this->ci =& get_instance();

        $this->ci->load->library('Email');
        $this->module_name = 'minical-extension-boilerplate';

    }   

    function send_greeting_email()
    {
        $company_id = $this->ci->session->userdata('current_company_id');
        $company = $this->ci->Company_model->get_company($company_id);

        $content =  'Dear [first name] I hope this email finds you well';
        $content1 = "<br/><br/>".'Thank you for your business'.",<br/><br/>"
            .$company['name']."
                <br/>".$company['email']. "<br/>".$company['phone']."<br/>";


        $config['mailtype'] = 'html';

        $this->ci->email->initialize($config);

        $email_data = array (
            'company_name' => $company['name'],
            'company_email' => $company['email'],
            'content' => $content,
            'content1' => $content1
        );

        $customer_email = $company['email'];

        $from_email = 'donotreply@minical.io';

        $email_from = $company['email'];

        $this->ci->email->from($email_from, $company['name']);
        $this->ci->email->to($customer_email);
        $this->ci->email->reply_to($email_data['company_email']);

        $this->ci->email->subject('Hello From miniCal');

        $this->ci->email->message($this->ci->load->view('../extensions/'.$this->module_name.'/views/gretting-mail-html', $email_data, true));

        $this->ci->email->send();
        $msg = l('minical-extension-boilerplate/Email successfully sent to ', true);
        return $msg.$customer_email;
    }

}
?>
```

**Loading of library**

You can load the library into controller, hooks, helper, or model, for loading your custom extension's library use the given syntax.&#x20;

$this->module\_name will have the extension name as value, or you can use the hardcode extension name at its place.

```php
//In controller 
$this->load->library('../extensions/'.$this->module_name.'/libraries/GreetingEmail');
$this->load->library('../extensions/minical-extension-boilerplate/libraries/GreetingEmail');

//In hooks and filter
$CI = &get_instance();
$CI->load->library('../extensions/minical-extension-boilerplate/libraries/GreetingEmail');
 
```


# Hooks

Under the hooks folder, we have 2 files actions.php and filters.php

```
----->hooks
      |----->actions.php
      |----->filters.php
```

**Actions**

Action is one of the two types of hooks. They provide a way for running a function at a specific point in the execution of miniCal Core. Callback functions for an Action do not return anything to the calling Action hook. You can create a hook in the application/hooks folder, here we have created an actions.php file.\
You can find the list of actions here [miniCal Action list](https://github.com/minical/minical/wiki/The-list-of-the-miniCal-actions).

```php
//file name actions.php
// This is a core action that will be executed when a new reservation is created in miniCal
add_action('add.booking.created', 'your_callback_function_1', 10, 1);
function your_callback_function_1($data) {
    // code here
}


// This is a custom action and can be executed from this extension controllers.
add_action('my-custom-action', 'your_custom_callback_function', 10, 1);
function your_custom_callback_function($data) {
    // code here
}
```

**Filters**

They provide a way for functions to modify data during the execution of the miniCal Core. They are the counterpart to action. You can create a hook in the application/hooks folder, here we have created a filers.php file.

{% code title="filters.php" %}

```php
// This is a custom action and can be executed from this extension controllers.
add_filter('my-custom-filter', 'your_callback_function_2', 10, 1);
function your_callback_function_2($data) {
    
    // start writing code here
    // return $data;
}
```

{% endcode %}


# Open-source Extensions

For more real examples, explore our popular open-source extensions:

* [Online Booking Engine](https://github.com/minical/online-booking-engine)
* [Booking Confirmation Email](https://github.com/minical/booking-confirmation-email)
* [Channex Integration](https://github.com/minical/channex_integration)
* [Stripe Payment Gateway](https://github.com/minical/stripe-integration)
* [Boilerplate Extension](https://github.com/minical/minical-extension-boilerplate)


# Config Folder Files

In the process extension develpoment, you will find a config folder. It contains three important files, each of these files has different work.

**Autoload file:-** This loads the **CSS/JS/Helper** dependencies into extension.

{% content-ref url="/pages/Xai3N6b7Vu4vLn3dZHpL" %}
[Autoload File](/build-an-extension/config-folder-files/autoload-file)
{% endcontent-ref %}

**Config file:-** This loads the **config** details of the extension.

{% content-ref url="/pages/e6h84XsWFnZjkMZxsmmQ" %}
[Config File](/build-an-extension/config-folder-files/config-file)
{% endcontent-ref %}

**Route file:-** This manages the **route** of the extension.

{% content-ref url="/pages/yhpt0btO5TTeGGv3Sv90" %}
[Route File](/build-an-extension/config-folder-files/route-file)
{% endcontent-ref %}


# Autoload File

The autoload file contains all the JS/CSS/Helper or any third-party file that needs to be loaded, in extension. For JS and CSS files use the separate array with specifying a key. As the config file, you don't need to load this file or variable anywhere it will load automatically at the time of the extension's activation.

### How to load JS/CSS file

**$config variable used for js/css**

**JS file**

```php
$config['js-files'] = array();
```

**CSS file**

```php
$config['css-files'] = array();
```

The $config variable has an array containing file and location keys.\
**1. file:-** this key has the path of the file.\
**2. location:-** this key has an array of locations where you want to load this specific file. The value passed in this array is the controller name and method name such as **controller\_name/method\_name**, you can add multiple locations in this array.

#### Here is a stepwise syntax

```php
// define an array for js files
1. $config['js-files'] = array();

// add array of js files
2. $config['js-files'] = array(
        array( 
                "file" => '',
                "location" => array(),
        ),
    );

// added file path 
3. $config['js-files'] = array(
        array( 
                "file" => 'assets/js/file_1.js',
                "location" => array(),
        ),
    );

// add location 
4. $config['js-files'] = array(
        array( 
                "file" => 'assets/js/file_1.js',
                "location" => array(
                     "controller_name_1/method_name", 
                ),
        ),
    );
```

Here is a real example

```php
$config['js-files'] = array(
    array(
        "file" => 'assets/js/booking_list.js', // file path
        "location" => array(
            "show_booking/show_latest_bookings", // controller_name/method_name
        ),
    ),
);
```

The same thing goes for CSS files, in place of js-files write css-files.

```php
$config['css-files'] = array(
    array(
        "file" => 'assets/css/booking_list.css', // file path
        "location" => array(
            "show_booking/show_latest_bookings", // controller_name/method_name
        ),
    ),
);
```

### How to load Helpers file

Here is an example of a helper file.

```php
// file name is custom_helper.php
function custom_helper_method($arg){
    // start writing code here   
}
```

**$extension\_helper variable used for loading helpers**

In the $extension\_helper array you can pass multiple helpers.

```php
// single file load
$extension_helper = array('custom_helper');

// multiple file load
$extension_helper = array('custom_helper', 'custom_helper_one');
```

**Use The custom helper on Controller**

When you pass the helper name into the $extension\_helper array it loads automatically on extensions loading. You can use it anywhere below is an example given how.

```php
 // this is just a check for function, it will prevent error if function is loaded
 if(function_exists('custom_helper_method')){
     custom_helper_method($agr);
 }
```

### How to load Third-party files

miniCal allows you to use any third-party packages, either direct CDN path or you want to use downloaded one.\
Here is an example of the CDN path.

```php
// js file 
$config['js-files'] = array(
    array(
        "file" => 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js',
        "location" => array(
            "controller_name/method_name",
        ),
    ),
);

//css file
$config['css-files'] = array(
    array(
          "file" => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
          "location" => array(
            "controller_name/method_name",
        ),
    ),
);
```

If you have your third-party package downloaded and want to load its js/css file then place the package under your extension folder. Here we have a third-party-package under our extension, this package has a city-name folder, and this folder has a city.js file.

```
|->public
     |->application
	    |->extensions
		  |->minical-extension-boilerplate
			 |->assets
                         |->config
                         |->controllers
                         |->helpers
                         |->hooks
                         |->language
                         |->libraries
			 |->models
			 |->views
                         |->third-party-package
                                |->city-name
                                      |->city.js
```

**Load downloaded package JS/CSS**

```php
// js file 
$config['js-files'] = array(
    array(
        "file" => 'third-party-package/city-name/city.js',
        "location" => array(
            "controller_name/method_name",
        ),
    ),
);
```

The same thing goes for the CSS files just place the path of the CSS file.<br>


# Config File

The config file contains all the extension's configuration details. Under the config folder you will find the config.php file, In this file use the $config variable and pass an array of key-value pairs. This array has all the configuration keys and values. This $cofig array will resolve in miniCal core automatically.

```php
$config = array(
        "name" => "Minical Extension Boilerplate",
        "description" => "It is a sample boilerplate extension it contains the basic structure of a typical extension. It will show you the list of bookings.",
        "is_default_active" => 1,
        "version" => "1.0.0", // version of extension
        "logo" => "", // extension's log image
        "view_link" => "bookings_list", // view icon link
        "setting_link" => "bookings_list", // setting icon link
        "categories" => array("payment_process"), // category of extension
        "marketplace_product_link" => ""
    
    );
```

Below is a list of each key and its default values.

<table><thead><tr><th width="150">Key</th><th>Value</th><th>Requirement</th><th>Default value</th></tr></thead><tbody><tr><td>name</td><td>This key contains the extension name as a value.</td><td>Required</td><td>"Extension name" (String)</td></tr><tr><td>description</td><td>This key will conation the short description of the extension.</td><td>Required</td><td>"Extension description" (String)</td></tr><tr><td>is_default_active</td><td>This key will specify whether this extension will be activated by default or not.</td><td>Required</td><td>0 (boolean)</td></tr><tr><td>version</td><td>This key contains the current version of the extension.</td><td>Optional</td><td>"1.0.0" (String)</td></tr><tr><td>logo</td><td>This key contains the extension icon path.</td><td>Optional</td><td>"" (String)</td></tr><tr><td>view_link</td><td>This key contains the route name of the page you want to load on this link click.</td><td>Optional</td><td>"" (String)</td></tr><tr><td>setting_link</td><td>This key same as the view link, except this key will load the setting page for the extension.</td><td>Optional</td><td>"" (String)</td></tr><tr><td>categories</td><td>This key reflected the extension category.</td><td>Optional</td><td>array('') (array)</td></tr><tr><td>marketplace_product_link</td><td>This key will have the link of extension of miniCal marketplace.</td><td>Optional</td><td>"" (String)</td></tr></tbody></table>

#### How to set custom configuration

miniCal allows us to set custom configurations along with the prefined key-values, pass your key-value pair into the config array.

```php
$config = array(
        "name" => "Minical Extension Boilerplate",
        "description" => "It is a sample boilerplate extension it contains the basic structure of a typical extension. It will show you the list of bookings.",
        "is_default_active" => 1,
        "version" => "1.0.0", // version of extension
        "logo" => "", // extension's log image
        "view_link" => "bookings_list", // view icon link
        "setting_link" => "bookings_list", // setting icon link
        "categories" => array("payment_process"), // category of extension
        "marketplace_product_link" => "",
        "custom_key" => "custom value"
    
    );
```

**"logo"** <mark style="color:purple;">this key contains the value path of the extension logo, you can place it inside of your extension folder inside any subfolder. You can name this subfolder accordingly.</mark>

For e.g.

```
 |->minical-extension-boilerplate
    |->images
       |->logo.png
     
 # for this particular example, the value of the logo key would be   
       "logo" => "images/logo.png"
```

#### How to use the custom configuration

For retrieving any configuration key use the given syntax below.&#x20;

At the place of $this->module\_name, you can also use your **extension folder name**.

**Load configuration key on controllers/Models**

```php
$this->all_active_modules[$this->module_name]['custom_key'];

$this->all_active_modules['minical-extension-boilerplate']['custom_key'];
```

**Load configuration key on Libraries/Hooks**

```php
$this->ci->all_active_modules[$this->module_name]['custom_key'];

$this->ci->all_active_modules['minical-extension-boilerplate']['custom_key'];
```

<br>


# Route File

Routes are responsible for responding to URL requests. Routing matches the URL to the pre-defined routes. Routes in miniCal are defined using the below example:

```
Controller/Method/Parameter/
```

* Controller -is mapped to the controller name that should respond to the URL.
* Method – is mapped to the method in the controller that should respond to the URI request.
* Parameter – this section is optional.

### How to define the route for the extensions

For defining route for extension go to the route.php filer under the config folder of your extension.\
Here is an example for the route file.

```php
$extension_route['list'] = 'show_booking/show_latest_bookings';
```

Use the $extension\_route variable for routes, it's the same as CI routes.

```php
$extension_route['list'] 
```

Here this list is the route name, the URL for this route will look like this "[**https://demo.minical.io/list**](https://demo.minical.io/list)"\
Now, this route is bound with a controller and its method. In the above example, we can see that this list route is bound with **show\_booking controller** and the method of show\_booking controller is "**show\_latest\_bookings**".

### How to pass parameters in route

A typical route with a might look something like this:

```php
//Syntaxt
$extension_route['route_name/:num'] = 'contoller/method/$1';
//example
$extension_route['product/:num'] = 'catalog/product_lookup/$1';
```

In a route, the array key contains the URI to be matched, while the array value contains the destination it should be re-routed to. In the above example, if the literal word “product” is found in the first segment of the URL, and a number is found in the second segment, the “catalog” class and the “product\_lookup” method are instead used.\
**(:num) will match a segment containing only numbers.**\
**(:any) will match a segment containing any character (except for ‘/’, which is the segment delimiter).**

You can send n-numbers of parameters with a route

```php
$extension_route['route_one'] = 'controller/method';
$extension_route['route_two/(:any)'] = 'controller/method/$1';
$extension_route['route_three/(:any)/(:any)'] = 'controller/method/$1/$2';
$extension_route['route_four/(:any)/(:any)/(:any)'] = 'controller/method/$1/$2/3';
```

Here we have provided the list of basic URLs (CRUD operations)

<table><thead><tr><th width="341" align="center">Syntaxt</th><th>URL</th><th width="385">Route</th><th width="283">Controller</th><th>Method</th></tr></thead><tbody><tr><td align="center">$extension_route['/booking_list'] = 'bookinng_controller/index';</td><td>/booking_list</td><td>$extension_route['/booking_list']</td><td>bookinng_controller</td><td>index</td></tr><tr><td align="center">$extension_route['/booking/create'] = 'bookinng_controller/create';</td><td>/booking/create</td><td>$extension_route['/booking/create']</td><td>bookinng_controller</td><td>create</td></tr><tr><td align="center">$extension_route['/booking/edit/:id'] = 'bookinng_controller/edit';</td><td>/booking/edit/id</td><td>$extension_route['/booking/edit/:id']</td><td>bookinng_controller</td><td>edit</td></tr><tr><td align="center">$extension_route['/booking/delete/:id'] = 'bookinng_controller/delete';</td><td>/booking/delete/id</td><td>$extension_route['/booking/delete/:id']</td><td>bookinng_controller</td><td>delete</td></tr></tbody></table>


# miniCal Filters

List of supported Actions/Filters Hooks

Filters are functions that always accept data in the form of an Argument and, after processing again, return the data as Return Value. The filter itself means the process of filtering something out. Just like the do\_action, here we have the apply\_filters() function.

```php
$filtered_value = apply_filters('example_filter_to_run', $arg );
```

So, now the $filtered\_value will be the system-generated output until you add a filter on it. In order, add the filter you need to call add\_filter() just like the add\_action(). Below is the example :

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

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

function example_callback_fun($arg) {
// code
return $arg;
}
```

**Customer Filters List**

| METHOD         | NAME                 | PARAMETERS | USE CASE                           |
| -------------- | -------------------- | ---------- | ---------------------------------- |
| apply\_filters | post.add.customer    | $data      | After the creation of new customer |
| apply\_filters | post.update.customer | $data      | After updating a customer          |

**Payment Source Filters List**

| METHOD         | NAME                        | PARAMETERS | USE CASE                                            |
| -------------- | --------------------------- | ---------- | --------------------------------------------------- |
| apply\_filters | post.create.payment\_source | $data      | After the creation of customer's new payment source |
| apply\_filters | post.update.payment\_source | $data      | After updating a customer's payment source          |
| apply\_filters | post.delete.payment\_source | $data      | After deleting a customer's payment source          |


# miniCal Actions

The list of the miniCal actions

miniCal provides us different hooks. They provide a way for running a function at a specific point in the execution of miniCal Core. Callback functions for an Action do not return anything back to the calling Action hook.

```php
do_action( ‘example_action_to_run’, $arg);
```

```php
// The action callback function.
add_action( ‘example_action_to_run’, ‘example_callback_fun’, 10, 1);

function example_callback_fun( $arg) {
You can access the $arg1 here. You just need to manipulate it and check the output.
}
```

This list contains all the actions trigger points of miniCal. You can add a listener with the corresponding action

**Booking Actions List**

| METHOD     | NAME                | PARAMETERS | USE CASE                          |
| ---------- | ------------------- | ---------- | --------------------------------- |
| do\_action | post.create.booking | $data      | After the creation of new booking |
| do\_action | post.delete.booking | $data      | After deleting a booking          |
| do\_action | post.update.booking | $data      | After updating a booking data     |

**Customer Actions List**

| METHOD     | NAME                 | PARAMETERS | USE CASE                           |
| ---------- | -------------------- | ---------- | ---------------------------------- |
| do\_action | post.create.customer | $data      | After the creation of new customer |
| do\_action | post.delete.customer | $data      | After deleting a customer          |
| do\_action | post.update.customer | $data      | After updating a customer data     |

**Charge Actions List**

| METHOD     | NAME               | PARAMETERS | USE CASE                         |
| ---------- | ------------------ | ---------- | -------------------------------- |
| do\_action | post.create.charge | $data      | After the creation of new charge |
| do\_action | post.delete.charge | $data      | After deleting a charge          |
| do\_action | post.update.charge | $data      | After updating a charge data     |

**Payment Actions List**

| METHOD     | NAME                | PARAMETERS | USE CASE                          |
| ---------- | ------------------- | ---------- | --------------------------------- |
| do\_action | post.create.payment | $data      | After the creation of new payment |
| do\_action | post.delete.payment | $data      | After deleting a payment          |
| do\_action | post.update.payment | $data      | After updating a payment data     |

These are basically action triggers, you can add action listener like this:

```php
add_action('post.create.booking', 'your_callback_function', 10, 1);
function your_callback_function($data) {
  // this code will be executed on booking creation, $data will have booking related info
}
```


# Create Custom Hooks

Create New Actions/filters hooks

Custom hooks are created and called in the same way that miniCal Core hooks are.

## **How to Create a Hook**

To create a custom hook, use <mark style="color:blue;">do\_action()</mark> for Actions and <mark style="color:blue;">apply\_filters()</mark> for Filters.

### **Add a Callback to the Hook**&#x20;

To add a callback function to a custom hook, use <mark style="color:blue;">add\_action()</mark> for Actions and <mark style="color:blue;">add\_filter()</mark> for Filters.

### **Naming Conflicts**

Since any extension can create a custom hook, it’s important to prefix your hook names to avoid collisions with other extensions.

For example, the function <mark style="color:blue;">extension\_name\_email\_body\_editor</mark> (where <mark style="color:blue;">extension\_name\_</mark> is a unique prefix for your extension) would avoid any collisions.

### Examples

### Extensible Action: Add Custom Field

**Extension Name: Custom Field (customfield)**

If your extension adds a custom field to a form, you can use Actions to allow other extensions to add their own settings to it.

```php
<?php
    do_action( 'customfield_after_adding_field' );
?>
```

Now another extension can register a callback function for the customfield\_after\_adding\_field hook and inject new settings:

```php
<?php
    add_action( 'customfield_after_adding_field', 'callback_function' );
?>
```

### Extensible Filter: Customer Type

**Extension Name: Custom Type (customtype)**

In this example, when the new customer is registered, the parameters that define it are passed through a filter, so another extension can change them before the customer is created.<br>

```php
<?php
  apply_filters( 'customtype_customer_type', $params )
?>
```

```php
<?php 
  add_filter( 'customtype_customer_type', 'callback_functionhp' );
?>
```


# Store Custom Data

Store custom data for an extension

### Understanding and Working With the miniCal POST and POST-META Tables

Suppose you are building an extension that requires a database to save the extension specify info. For instance, you need to capture username and mail-id so these details will go on the "**post**" and "**post-meta**" tables.

{% content-ref url="/pages/aFVEkgcdooS0h8gPgYg6" %}
[POSTS](/build-an-extension/store-custom-data/posts)
{% endcontent-ref %}

{% content-ref url="/pages/aV46jVY9JBn9RoJqBqHJ" %}
[POSTMETA](/build-an-extension/store-custom-data/postmeta)
{% endcontent-ref %}

### Understanding and Working With the miniCal OPTIONS Table

The options table stores a different kind of data from the other tables: instead of storing data about your extension content, it stores data about the application itself. miniCal provides a set of functions to add, update and delete data from this table. You can add values to existing options and you can also add new records to the table when you want to create new options.

{% content-ref url="/pages/EUwDJLi4RFX4oKPFlg4C" %}
[OPTIONS](/build-an-extension/store-custom-data/options)
{% endcontent-ref %}

| Method             | Description                | Parameters Description                                                                                                                                                                                                                                                                                                                                                                                                                                            | Return value                                                                                                                                               |
| ------------------ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| add\_option()      | Adds a new option value.   | <p><strong>add\_option(string $option, $value = '', bool $autoload = true)</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to add.<br><strong>2.</strong> mixed $value (Optional) Option value.<br><strong>3.</strong> bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.<br></p>                                                                                                | <p><strong>bool</strong><br>True if the option was added, null otherwise.</p>                                                                              |
| get\_option()      | Get option value.          | <p><strong>get\_option( string $option, bool $default = false)</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to add.<br><strong>2.</strong> bool $default (Optional) Default value to return if the option does not exist.<br></p>                                                                                                                                                                                             | <p><strong>bool</strong><br>Value of the option. A value of any type may be returned, If there is no option in the database, boolean false is returned</p> |
| update\_option()   | Update option value.       | <p><strong>update\_option( string $option, $value = '', bool $autoload = true )</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to update.<br><strong>2.</strong> mixed $value (Required) Option value.<br><strong>3.</strong> bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.<br></p>                                                                                        | <p><strong>bool</strong><br>True if the value was updated, false otherwise.</p>                                                                            |
| delete\_option()   | delete option value.       | <p><strong>delete\_option( string $option )</strong><br><br><strong>1.</strong> string $option (Required) Name of the option to delete.</p>                                                                                                                                                                                                                                                                                                                       | <p><strong>bool</strong><br>True if the option was deleted, false otherwise.</p>                                                                           |
| add\_post\_meta()  | Adds a new postmeta value. | <p><strong>add\_post\_meta ($post\_id, $key, $value)</strong><br><br><strong>1.</strong> int $post\_id (Required) The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $key (Required) The meta key.<br><strong>3.</strong> mixed $value (Required) The meta value to the corresponding key.<br></p>                                                                                                                                | <p><strong>null</strong><br></p>                                                                                                                           |
| get\_postmeta()    | Get postmeta value.        | <p><strong>get\_post\_meta(int $post\_id = null, string $key = null, bool $single = false )</strong><br><br><strong>1.</strong> int $post\_id The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $key Optional, The meta key to retrieve. By default, returns data for all keys.<br><strong>3.</strong> boolean $single Optional Whether to return a single value. This parameter has no effect if $key is not specified.<br></p> | <p><strong>mixed</strong><br>Either array or null, if postmeta data is available or no error occurs, then array else null.</p>                             |
| update\_postmeta() | Update postmeta value.     | <p><strong>update\_post\_meta(array $post\_meta = null, int $post\_id = null)</strong><br><br><strong>1.</strong> array $post\_meta An array of postmeta data to be updated.<br><strong>2.</strong> int $post\_id The id of the post corresponds to the postmeta data.<br></p>                                                                                                                                                                                    | <p><strong>mixed</strong><br>Either true or null, if postmeta data is updated then true else null.</p>                                                     |
| detele\_postmeta() | Detele postmeta value.     | <p><strong>delete\_post\_meta(int $post\_id = null, string $meta\_key = null, $meta\_value = null)</strong><br><br><strong>1.</strong> int $post\_id The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $meta\_key name of key.<br><strong>3.</strong> mixed $meta\_value value of key this will make delete more certain (in case key name is same).<br></p>                                                                     | <p><strong>mixed</strong><br>Either true or null, if postmeta data is deleted then true else null.</p>                                                     |
| add\_post()        | Adds a new post value.     | <p><strong>add\_post ($data)</strong><br><br><strong>1.</strong> array $data the data array of post.</p>                                                                                                                                                                                                                                                                                                                                                          | <p><strong>null</strong><br></p>                                                                                                                           |
| get\_post()        | Get post value.            | <p><strong>get\_post( $post )</strong><br><br><strong>1.</strong> mixed $post Int id of post or An Array of post data, this key will be added in where clause.</p>                                                                                                                                                                                                                                                                                                | <p><strong>mixed</strong><br>Either array or null, if post data is available or no error occurs, then array else null.</p>                                 |
| edit\_post()       | Update post value.         | <p><strong>edit\_post(array $post = null)</strong><br><br><strong>1.</strong> array $post An Array of post data including post\_id.</p>                                                                                                                                                                                                                                                                                                                           | <p><strong>mixed</strong><br>Either post\_id or null, if post data is updated or no error occurs, then id else null.</p>                                   |
| detele\_post()     | Detele post value.         | <p><strong>delete\_post(int $post\_id = null, bool $force\_delete = false )</strong><br><br><strong>1.</strong> int $post\_id The id of the post. <strong>2.</strong> bool $force\_delete flag to force delete a post, default is false..</p>                                                                                                                                                                                                                     | <p><strong>mixed</strong><br>Either true or null, if postmeta data is delete then true else null.</p>                                                      |


# POSTS

### Posts

* A post is a content item stored in the posts table. Each has a post\_type assigned to it, which could be an extension setting or user data for the extension page or something else.
* All the data is stored in the Posts table and mapped with the company\_id and user\_id. Here are the important columns the Post table has.

### Structure of the miniCal Post Table

* `post_title` - can be a string like a description related to the post.
* `post_type` - can be a string this can define the type of functionality.
* `post_status` - can be a string (publish/unpublish) it determines whether the post is published or not.
* `post_date` - the Date-Time of a post when created.
* `company_id` - current company id (can get this from the session).
* `user_id` - logged-in user id (can get this from the session).

```php
// Create an post to the database
add_post($post);

// delete a post data. If the second parameter is true then
// the post is deleted permanently, default is false.
delete_post(int $post_id = null, bool $force_delete = false )

// get post form posts table.
get_post( $post );

// edit a post data of posts table
edit_post(array $post = null)
```

### Relationships Between Posts

The `post_parent` the field is an important one, as it stores information about relationships between different posts. These include:

* parent and child pages
* revisions and the post they relate to
* attachments and the post they were uploaded to

You can use the `post_parent` the field in various ways in your queries. For example, to query for child pages of a given page, you would use the following, where `ID` is the ID of the parent page:

```
'post_parent' => 'ID'
```

You could use a similar query to display attachments uploaded to a given post, or alternatively, you could query attachments with no parent (i.e. those uploaded directly to the media screen in the dashboard).&#x20;

To do this, you would use the following argument:

```
'post_parent' => '0'
```

<table><thead><tr><th>Method</th><th width="158">Description</th><th width="225">Parameters Description</th><th>Return value</th></tr></thead><tbody><tr><td><code>add_post()</code></td><td>Adds a new post value.</td><td><strong><code>add_post ($data)</code></strong><br><br><strong>1.</strong> array $data the data array of post.</td><td><strong>null</strong><br></td></tr><tr><td><code>get_post()</code></td><td>Get post value.</td><td><strong><code>get_post( $post )</code></strong><br><br><strong>1.</strong> mixed $post Int id of post or An Array of post data, this key will be added in where clause.</td><td><strong>mixed</strong><br>Either array or null, if post data is available or no error occurs, then array else null.</td></tr><tr><td><code>edit_post()</code></td><td>Update post value.</td><td><strong><code>edit_post(array $post = null)</code></strong><br><br><strong>1.</strong> array $post An Array of post data including post_id.</td><td><strong>mixed</strong><br>Either post_id or null, if post data is updated or no error occurs, then id else null.</td></tr><tr><td><code>detele_post()</code></td><td>Detele post value.</td><td><strong><code>delete_post(int $post_id = null, bool $force_delete = false )</code></strong><br><br><strong>1.</strong> int $post_id The id of the post. <strong>2.</strong> bool $force_delete flag to force delete a post, default is false..</td><td><strong>mixed</strong><br>Either true or null, if postmeta data is delete then true else null.</td></tr></tbody></table>

<br>


# POSTMETA

### Postmeta

#### What is Metadata?

Metadata can be described as data about data. Postmeta is the way to store post-related metadata that has an impact on a post. All the data is stored in the postmeta table and mapped with the post\_id.&#x20;

#### What is stored in the metadata tables? For example:

* For posts, post\_type is an example of metadata, but it's stored in the posts table
* Taxonomy terms, categories, and tags can also be loosely defined as metadata, but these are stored entirely separately, in their own database tables.
* Post metadata such as custom fields and additional metadata added via extension is stored in the postmeta table, as you would expect.

So it's easier to think of metadata in miniCal not according to the strict definition of the term, but as the data stored in the three metadata tables.

#### But let's have a look at some of the more common types of metadata:

* **Metadata about the extension.**
* **Custom Fields.**
* **User Metadata.**&#x20;

### Structure of the miniCal post-meta Table

* `post_id` => //post id
* `post_key` => // key
* `post_value` => // value

#### Add postmeta data with post data

You can add postmeta data with post data, Just add an array with key name meta. Here is an example is given.

```php
    $post = array(  
             'company_id' => $this->company_id,
             'user_id' => $this->user_id,
             'post_title' => 'Book',
             'post_type' => 'self-help-book',
             'post_date' =>  date('Y-m-d H:i:s'),
             'meta' => array(
                     'author' => 'James Clear',
                     'book_name' => 'Atomic Habits',
                     'pages' => '290'
                 )
    );
    
    add_post($post);
```

```php
// Adds meta values to the database
add_post_meta ($post_id, $key, $value);

// to get postmeta data from postmeta table by post_id or meta_key.
get_post_meta(int $post_id = null, string $key = null, bool $single = false );

// update postmeta data. in the array, if a new value pass then added else update.
 update_post_meta(array $post_meta = null, int $post_id = null);

//delete a postmeta data.
delete_post_meta(int $post_id = null, string $meta_key = null, $meta_value = null);
```

###

<table><thead><tr><th width="239">Method</th><th>Description</th><th>Parameters Description</th><th>Return value</th></tr></thead><tbody><tr><td><code>add_post_meta()</code></td><td>Adds a new postmeta value.</td><td><strong><code>add_post_meta ($post_id, $key, $value)</code></strong><br><br><strong>1.</strong> int $post_id (Required) The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $key (Required) The meta key.<br><strong>3.</strong> mixed $value (Required) The meta value to the corresponding key.<br></td><td><strong>null</strong><br></td></tr><tr><td><code>get_postmeta()</code></td><td>Get postmeta value.</td><td><strong><code>get_post_meta(int $post_id = null, string $key = null, bool $single = false )</code></strong><br><br><strong>1.</strong> int $post_id The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $key Optional, The meta key to retrieve. By default, returns data for all keys.<br><strong>3.</strong> boolean $single Optional Whether to return a single value. This parameter has no effect if $key is not specified.<br></td><td><strong>mixed</strong><br>Either array or null, if postmeta data is available or no error occurs, then array else null.</td></tr><tr><td><code>update_postmeta()</code></td><td>Update postmeta value.</td><td><strong><code>update_post_meta(array $post_meta = null, int $post_id = null)</code></strong><br><br><strong>1.</strong> array $post_meta An array of postmeta data to be updated.<br><strong>2.</strong> int $post_id The id of the post corresponds to the postmeta data.<br></td><td><strong>mixed</strong><br>Either true or null, if postmeta data is updated then true else null.</td></tr><tr><td><code>detele_postmeta()</code></td><td>Detele postmeta value.</td><td><strong><code>delete_post_meta(int $post_id = null, string $meta_key = null, $meta_value = null)</code></strong><br><br><strong>1.</strong> int $post_id The id of the post corresponds to the postmeta data.<br><strong>2.</strong> string $meta_key name of key.<br><strong>3.</strong> mixed $meta_value value of key this will make delete more certain (in case key name is same).<br></td><td><strong>mixed</strong><br>Either true or null, if postmeta data is deleted then true else null.</td></tr></tbody></table>


# OPTIONS

### Options

Options are the way to store extension-related settings that have an impact on a company. All the data is stored in the options table and mapped with the company\_id. Here is the columns options table has.

### Structure of the miniCal options Table

The options table has a similar structure to the metadata tables. It has five fields:

* `option_ID`
* `company_id`- Current company id.
* `option_name`- Name of an option (key).
* `option_value`- Value of option (value).
* `autoload` - Whether to load the option when extension starts up. Default is enabled. The boolean value `true/false.`

Each record in the `option_name` field will be a unique value: if you add more than one value to an option, miniCal stores this in an array in the `option_value` field.

```php
// Add a new option.
add_option(string $option, $value = '', bool $autoload = true)

// Removes option by name.
delete_option( string $option )

// Retrieves an option value based on an option name.
get_option( string $option, bool $default = false)

// Update the value of an option that was already added.
update_option( string $option, $value = '', bool $autoload = true )
```

### Using the Options

The Options consists of four functions that allow you to add, get, update or delete options:

<table><thead><tr><th width="215">Method</th><th>Description</th><th>Parameters Description</th><th>Return value</th></tr></thead><tbody><tr><td><code>add_option()</code></td><td>Adds a new option value.</td><td><strong><code>add_option(string $option, $value = '', bool $autoload = true)</code></strong><br><br><strong>1.</strong> string $option (Required) Name of the option to add.<br><strong>2.</strong> mixed $value (Optional) Option value.<br><strong>3.</strong> bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.<br></td><td><strong>bool</strong><br>True if the option was added, null otherwise.</td></tr><tr><td><code>get_option()</code></td><td>Get option value.</td><td><strong><code>get_option( string $option, bool $default = false)</code></strong><br><br><strong>1.</strong> string $option (Required) Name of the option to add.<br><strong>2.</strong> bool $default (Optional) Default value to return if the option does not exist.<br></td><td><strong>bool</strong><br>Value of the option. A value of any type may be returned, If there is no option in the database, boolean false is returned</td></tr><tr><td><code>update_option()</code></td><td>Update option value.</td><td><strong><code>update_option( string $option, $value = '', bool $autoload = true )</code></strong><br><br><strong>1.</strong> string $option (Required) Name of the option to update.<br><strong>2.</strong> mixed $value (Required) Option value.<br><strong>3.</strong> bool $autoload (Optional) Whether to load the option when extension starts up. Default is enabled.<br></td><td><strong>bool</strong><br>True if the value was updated, false otherwise.</td></tr><tr><td><code>delete_option()</code></td><td>delete option value.</td><td><strong><code>delete_option( string $option )</code></strong><br><br><strong>1.</strong> string $option (Required) Name of the option to delete.</td><td><strong>bool</strong><br>True if the option was deleted, false otherwise.</td></tr></tbody></table>


# Composer Dependencies

Composer Dependencies in Extension

The Composer as a package or dependency manager plays a vital role in helping us manage some of these dependencies which our application requires for optimal performance by saving them on a folder, most times the “vendor” folder.

#### How to setup composer in an extension

To install Composer in your project, you need an important file called “composer.json”. This file is where you define all the dependencies/packages needed in your project. Under your extension folder create this file “composer.json”.

**The “require” key**

This is a set of JSON definitions used to tell the composer what packages your extension will depend on. There may be other variables you may need to define in this composer.json file, but most of the time, this “require” key is often the only content of the composer.json file.

```json
{
    "require": {
         "dompdf/dompdf": "^1.1"
    }
}
```

In the above code create the “composer.json” file inside your extension. Then inside the composer.json file, goes my “require” key.

**Folder**

```
  extension->
       |->minical-extension-boilerplate
                  |->composer.json
                  |->vendor  
```

**Package Names**

The package names consist of a vendor name and a project name. In most cases these names are identical. This naming format plays a vital role in preventing naming conflicts, as two or more persons can have a package with the same name but a different vendor name.

**Version Specification**

As seen in the above code snippet, we specified, telling Composer to download only the version of dompdf in the version range of 7.77 the composer will download the latest stable version, within the specified version range.

**Installing Dependencies**

To install these defined dependencies to our extension, we must run the composer “install” command from the terminal in your extension directory. After this command, you will find a vendor folder under the extension, make sure you will upload the folder while creating PR for the miniCal extension.

```
C:\xampp\htdocs\minical-extension-boilerplate> composer install
```

**Updating Packages**

We can also update some of these installed packages in our extension to their latest version, but this must be done with care to prevent our program from breaking. To update packages, we use the composer update command.

```
C:\xampp\htdocs\minical-extension-boilerplate> composer update
```

The above code snippet will update the whole packages, installed in our extension. To update only a single package, we need to specify the name of the package to update as shown below.

```
C:\xampp\htdocs\minical-extension-boilerplate>  composer update dompdf/dompdf
```

#### How to Use composer dependencies in an extension

In the vendor folder, you will find a autoload file you can load this file anywhere you want.

```
  extension->
       |->minical-extension-boilerplate
                  |->composer.json
                  |->vendor  
                         |->autoload.php
```

here is the syntax

```php
require_once FCPATH . 'application/extensions/minical-extension-boilerplate/vendor/autoload.php';
```


# miniCal Marketplace

Extend your miniCal experience! Browse extensions at the [marketplace](http://marketplace.minical.io/).

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FN45UW3l6TZVXBCvuo0xs%2Fimage.png?alt=media\&token=5ad1d733-3f2f-47c5-be30-63cad3aa291e)


# Overbooking for OTAs

Overbooking for OTAs in case of non continuous availability

Let's consider the following scenario, where there are 2 rooms available for each date from 1st to 6th.

\
![](https://camo.githubusercontent.com/44888361fa5fd25dbb9f9bbc07240e50dc119e92f40f59e75ea0a676bc43133d/68747470733a2f2f692e696d6775722e636f6d2f6366794f6171422e706e67)\
\
But none of the rooms have a continuous room availability from date 1st to the 5th.

Room 101 is available on 3, 4, 5, 6, 7\
Room 102 is available on 1, 2, 5, 6, 7\
Room 103 is available on 1, 2, 3, 4, 7\
\
Date wise availability:

On the 1st date, the total number of available rooms: 2 (102, 103)\
On the 2nd date, the total number of available rooms: 2 (102, 103)\
On the 3rd date, the total number of available rooms: 2 (101, 103)\
On the 4th date, the total number of available rooms: 2 (101, 103)\
On the 5th date, the total number of available rooms: 2 (101, 102)\
On the 6th date, the total number of available rooms: 2 (101, 102)\
On the 7th date, the total number of available rooms: 3 (101, 102, 103)\
\
\
OTAs or Channel managers only accept date-wise availability so consider minical sends above date-wise availability to an OTA (Where all dates have at least 2 rooms available).

Now consider we receive a new OTA reservation from 1st to 5th, and miniCal tries to allocate a room for it from 1st to 5th. Although there are rooms available on all dates, there is no single room available that has continuous availability from the 1st to 5th date range.\
\
**miniCal handles this scenario in the following way:**\
\
**If the feature-setting "Allow OTA Bookings With Non-continuous Rooms/blocks" is enabled**, miniCal would create a split booking. For a booking ranging from 1st to 5th, will split into two blocks. The first block will be placed in room 102 for range 1st to 2nd and the second block will be placed in Room 101 for range 3rd to 5th.\
![](https://camo.githubusercontent.com/e674341ee4d8caf80a8912e0018b9a394e5fd9e2a24739eaa2881d8d50a41584/68747470733a2f2f692e696d6775722e636f6d2f547575756b43642e706e67)\
\
**If the feature-setting "Allow OTA Bookings With Non-continuous Rooms/blocks" is disabled**, miniCal would place this reservation on the first room found for a specific room type. That would make this reservation show as an Overbooking.\
\
![](https://camo.githubusercontent.com/35621c5937b6d1d7e4a78103d5a4fcd1cbd03f7da935d53a4dae3d96e4843188/68747470733a2f2f692e696d6775722e636f6d2f734b6a3168374e2e706e67)\
\
Although this can be easily managed by the hotel by moving bookings around the calendar. As shown in the next image.\
\
![](https://camo.githubusercontent.com/57c01cb4dedd97411f28ae4b5ed0432a4aa226b52a5684e7e98c8424dc4a5bdb/68747470733a2f2f692e696d6775722e636f6d2f4971363741334e2e706e67)\ <br>

The chances of these overbooking issues can also be minimized by setting an **OTA CloseOut Threshold** to 1 or more for all room types on the Inventory page. This will allow miniCal to close inventory when the availability reaches the threshold and avoid the chances of non-continuous or overbookings.\
\
![](https://camo.githubusercontent.com/77e786e9c746f982029b5206381698070a9a63c2240cf0a58a7b4d8154892801/68747470733a2f2f692e696d6775722e636f6d2f696f54465a73772e706e67)


# miniCal Cron Setup

Cron is how miniCal does the scheduling time-based tasks. Several miniCal core features, such as checking for updates and getting bookings from OTA's like Booking, Airbnb, and Expedia, utilize Cron.

#### Understanding of miniCal Cron Scheduling

miniCal provides hooks to perform the cron job. Use any given action name and add your call-back function.\
Right now, the default intervals provided by miniCal are:

* **hourly-cron**
* **daily-cron**

Hourly-cron runs from the 0th hour to the 23rd hour a day, for example, if you have an OTA connection and you want your booking updated at every hour, then you can use this hourly-cron job.\
The same goes for the daily-cron; if you want to mail you the daily booking list at any specific time, you can use daily-cron for this.

#### Why Use Cron

* miniCal core and many extensions need a scheduling system to perform time-based tasks. However, many hosting services are shared and do not provide access to the system scheduler.
* miniCal makes sure that the job is done on the next page load if the job is not done.

#### How to Use Cron

```php
// daily cron
add_action('daily-cron', 'your_callback_function', 10, 1);
function your_callback_function($data) {
  // this code will be executed on 0th hour every day
}

// hourly
add_action('hourly-cron', 'your_callback_function', 10, 1);
function your_callback_function($data) {
  // this code will be executed on 0th to 23rd hour every day
}
```


# Automated Night Audit

When you set up miniCal, it will mark the current date as the date you register on the miniCal. In other words, if you set up miniCal and get registered on 12th Jan 2022 so in the booking calendar, the current date (selling date) will be 12th Jan 2022 forever. It will not change the current date (selling date) every day.

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FGmt9h6UJRzlAtMGUXcCv%2Fimage.png?alt=media\&token=039be778-c922-4c4b-b4f8-b6b4e51995ea)

So for this miniCal has provided **"Manual Night Audit**" or **"Automatic Night Audit"**

### [**Automatic Night Audit**](https://marketplace.minical.io/product/automated-night-audit/)

For this particular scenario, miniCal has provided an excellent extension for night audits. Check the [**Automatic Night Audit**](https://marketplace.minical.io/product/automated-night-audit/) extension at miniCal Marketplace. This extension will run a cron every day so that the current date on the calendar will change automatically, and you can manage everyday charges with this. If you use the [Automatic Night Audit](https://marketplace.minical.io/product/automated-night-audit/) extension, then For miniCal hosted service this cron will run automatically. But for miniCal local (hosted on your local server), you need to set up cron.

![](https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FEEmuERNiG7koTghw4rEq%2Fimage.png?alt=media\&token=e96669c4-e377-472a-8e87-ca83e2bd17e6)

In the above screenshot, you will find various options so let's have a look one by one.

1. **Automatically Change Date To The Next Day After:-** This will run a cron at your given time every day. You can change the time in the dropdown.
2. **Apply Night Audit Charges To Checked-in Bookings Regardless Of Their Check-out Date:-** This checkbox determines that the same charges will be applied for a booking as the day booking is created.&#x20;
3. **Apply Night Audit Charges To Checked-in Bookings Only (Not Reservations):-** This will apply the charges on the booking that already checked-in.

### How to add the cron job

#### Syntax of crontab

The syntax is:

```
1 2 3 4 5 /path/to/command arg1 arg2
```

Where,

* 1: Minute (0-59)
* 2: Hours (0-23)
* 3: Day (0-31)
* 4: Month (0-12 \[12 == December])
* 5: Day of the week(0-7 \[7 or 0 == sunday])
* /path/to/command – Script or command name to schedule

### How to run cron for night audit

To run cron for night audit you need to run this command&#x20;

### **`0 * * * * wget path/cron/hourly > /dev/null 2>&1`**

As you see in the above command there are many things so let's check what is what

* **0:-** Run at 0th minute (this cron will run at the 0th minute of an hour)
* **\*:-** This operator specifies all possible values for a field.
* **wget:-** Wget is the non-interactive network downloader is used to download files from the server.
* **path/cron/hourly:-**  This is the domain path you have set for miniCal for example, "<mark style="color:blue;"><http://localhost/minical/public/cron/hourly></mark>" or "<mark style="color:blue;"><http://customdomin/cron/hourly></mark>".
* **/dev/nul l 2>&1:-** To stop default output from crontab you need to append >/dev/null 2>&1.


# Nginx Configuration


# Docker Installation

## Using Docker to run a Minical demo server

You need to have [docker and docker-compose](https://docs.docker.com/desktop/) installed on your system.

Once installed, you can simply run:

```
$ cd docker
docker/ $ docker-compose up
```

This would download and build all docker images and will run all services.

You still need to create the `.env` file in the main directory as described in the Minical Installation instructions. You can copy the `.env` file from the `docker` directory into Minical's root.

NOTE that it is best to change the URLs in the `.env` file from `localhost` to your actual IP address. This is necessary to get some functions working, such as the Room Inventory page which makes internal calls to the site using the API interface.

For running the demo server using docker, you can simply run the following command in the main Minical directory:

```
$ cp docker/.env.example ./.env
```

or if you are in the docker directory:

```
docker/ $ cp .env.example ../.env
```

When everything is started, and the `.env` file exists in the Minical root directory, you can simply visit <http://localhost:8080/public/install.php> to continue with the Minical installation and setup.


# Custom Domain Setup

customer who wants a minical hosted subdomain for their minical website needs some custom domain setup.

Create a new domain for example app.roomsy.com. and then point the domain to \*\*[cname.minical.io](http://cname.minical.io/)\*\* in their DNS setting. after the verification of the domain. we will create a subdomain of minical production from this domain on request.

<figure><img src="https://1085498164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGC5hjGQGneftrkfSeZaa%2Fuploads%2FnndWgEzS8DzEm9eakWTZ%2FScreenshot_1_16_2023.png?alt=media&amp;token=a9b18d6a-742b-45ee-9673-b873b1593ab4" alt=""><figcaption></figcaption></figure>


# API Documentation

The API documentation for MiniCal provides detailed information and guidelines for developers on how to interact with MiniCal's booking platform programmatically.

[Minical APIs](https://api-docs.minical.io/quick-start/get-started) outlines the available endpoints, request/response formats, authentication methods, and any specific parameters or data structures required for integration. The API documentation enables developers to understand and leverage MiniCal's functionality to create custom applications, integrate with other systems, or build additional features on top of the platform. It serves as a comprehensive reference guide, offering clear instructions and examples to facilitate the seamless integration of MiniCal's booking capabilities into third-party software applications.

[Minical APIs](https://api-docs.minical.io/quick-start/get-started) are meant to be consumed. As a result, it is critical to guarantee that users can begin adopting them immediately and without difficulty. Unfortunately, most APIs are inadequately documented, making integration harder and defeating the point of their existence.


# Access minical Data Using Helpers

The supported helper functions are coming soon. That will help you fetch any data into extension without writing custom SQL Queries.


# Company Helper Functions

The helper you can use to get company details and settings for the company.

### function get\_company($company\_id) {....}

**Supported hooks**&#x20;

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

```php
// The filter callback function is based on the filter.
add_filter('before_get_company', 'before_get_company_callback_fn', 10, 1);
 
function before_get_company_callback_fn ($company_id) {
   // This filter would be executed before retrieving company details from database in get_company helper.
}
```

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

```php
// The filter callback function is based on the filter.
add_filter('should_get_company', 'should_get_company_callback_fn', 10, 1);

function should_get_company_callback_fn ($company_id) {
   // This filter would be executed before retrieving company details from database in get_company helper.
}
```

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

```php
// The filter callback function is based on the filter.
add_filter('pre.get.company', 'pre_get_company_callback_fn', 10, 1);

function pre_get_company_callback_fn ($company_id) {
   // This filter would be executed before retrieving comapny from database in get_company helper.
}
```

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

```php
// The filter callback function is based on the filter.
add_filter('post.get.company', ' post_get_company_callback_fn', 10, 1);

function post_get_company_callback_fn ($company_id) {
    // This filter would be executed before retrieving company details from database in get_company helper.
}
```

**Usage**

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

// Retrieves company data or settings based on a company_id.
$company_data = get_company($company_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>$company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>Company Id is the primary key for the company table.</td></tr></tbody></table>

**Response**

```php
// Successfully response giving you array of company & settings details.

Array
(
    [company_id] => 1
    [name] => honey & bunny
    [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
    [GST_number] => 
    [postal_code] => 
    [is_daily_rate_including_tax] => 0
    [is_setup] => 0
    [number_of_rooms] => 10
    [reservation_policies] => 
    [check_in_policies] => 
    [night_audit_auto_prompt] => 0
    [night_audit_auto_prompt_time] => 00:00:00
    [night_audit_force_check_out] => 0
    [night_audit_multiple_days] => 0
    [require_paypal_payment] => 0
    [paypal_account] => 
    [percentage_of_required_paypal_payment] => 50
    [housekeeping_auto_clean_is_enabled] => 1
    [housekeeping_auto_clean_time] => 16:00:00
    [housekeeping_day_interval_for_full_cleaning] => 4
    [online_reservation_confirmation_message] => To secure your reservation spot, please confirm your reservation with the [name] by calling [phone] or by sending email to [email]
    [default_currency_id] => 151
    [night_audit_auto_run_is_enabled] => 0
    [night_audit_auto_run_time] => 04:00:00
    [property_type] => 0
    [invoice_email_header] => 
    [booking_confirmation_email_header] => 
    [send_invoice_email_automatically] => 1
    [ask_for_review_in_invoice_email] => 0
    [hide_decimal_places] => 0
    [companycol] => 
    [redirect_to_trip_advisor] => 0
    [tripadvisor_link] => 
    [employee_auto_logout_is_enabled] => 0
    [api_key] => 
    [website_uri] => 
    [website_about] => 
    [website_latitude] => 
    [website_longitude] => 
    [website_is_taking_online_reservation] => 0
    [website_theme_color] => EDE8EB
    [website_facebook_page_url] => 
    [website_tripadvisor_location_id] => 
    [google_analytics_id] => 
    [google_conversion_id] => 
    [google_conversion_label] => 
    [logo_image_id] => 
    [logo_image_group_id] => 1
    [gallery_image_group_id] => 3
    [slideshow_image_group_id] => 2
    [website_title] => 
    [website_tripadvisor_widget_type] => 0
    [allow_same_day_check_in] => 1
    [booking_email_confirmation_message] => This reservation is provisionary. It is not confirmed until the payment information is given from the customer. For questions, please contact us at [email].
    [invoice_header] => 
    [last_night_audit] => 
    [night_audit_charge_in_house_only] => 0
    [night_audit_ignore_check_out_date] => 0
    [book_over_unconfirmed_reservations] => 0
    [statement_number] => 1
    [enable_card_tokenization] => 1
    [booking_engine_booking_status] => 0
    [is_total_balance_include_forecast] => 1
    [is_display_tooltip] => 1
    [partner_id] => 0
    [booking_dot_com_rate_type] => base_rate
    [common_additional_adult_rate] => 
    [allow_non_continuous_bookings] => 1
    [maximum_no_of_blocks] => 2
    [manual_payment_capture] => 0
    [include_cancelled_noshow_bookings] => 1
    [force_room_selection] => 1
    [send_copy_to_additional_emails] => 0
    [additional_company_emails] => 
    [hide_forecast_charges] => 0
    [housekeeping_auto_dirty_is_enabled] => 0
    [housekeeping_auto_dirty_time] => 16:00:00
    [automatic_feedback_email] => 0
    [subscription_country] => US
    [auto_no_show] => 1
    [last_login] => 
    [show_rate_on_registration_card] => 1
    [automatic_email_confirmation] => 0
    [automatic_email_cancellation] => 0
    [email_confirmation_for_ota_reservations] => 0
    [make_guest_field_mandatory] => 0
    [is_deleted] => 0
    [ui_theme] => 1
    [default_charge_name] => Room Charge
    [date_format] => YY-MM-DD
    [default_room_singular] => room
    [default_room_plural] => rooms
    [default_room_type] => room type
    [avoid_dmarc_blocking] => 0
    [enable_hourly_booking] => 0
    [default_checkin_time] => 12:00 AM
    [default_checkout_time] => 12:00 AM
    [allow_free_bookings] => 0
    [show_logo_on_registration_card] => 0
    [restrict_booking_dates_modification] => 0
    [restrict_checkout_with_balance] => 0
    [enable_api_access] => 1
    [customer_modify_booking] => 0
    [booking_cancelled_with_balance] => 0
    [booking_checkedout_with_balance] => 0
    [enable_new_calendar] => 1
    [default_language] => 1
    [hide_room_name] => 0
    [email_confirmation_for_booking_engine] => 0
    [is_cc_visualization_enabled] => 0
    [send_booking_notes] => 0
    [show_guest_group_invoice] => 0
    [booking_engine_tracking_code] => 
    [email_cancellation_for_ota_reservations] => 0
    [salesforce_url] => 
    [admin_comment] => 
    [creation_date] => 2021-12-10
    [trial_expiry_date] => 2021-12-24
    [trial_extension_reason] => 
    [conversion_date] => 
    [churn_date] => 
    [lead_source_id] => 0
    [utm_source] => 
    [inhouse_settings] => 
    [reservation_settings] => 
    [permission_id] => 2
    [user_id] => 1
    [permission] => is_owner
    [subscription_level] => 0
    [limit_feature] => 1
    [subscription_state] => trialing
    [payment_method] => none
    [subscription_id] => 
    [balance] => 0.00
    [owner_email] => test@minical.io
    [id] => 1
    [current_company_id] => 1
    [first_name] => support
    [last_name] => minical
    [language] => english
    [language_id] => 1
    [number_of_rooms_actual] => 10
    [partner_name] => minical
    [selected_payment_gateway] => 
)

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

### function get\_company\_data($company\_id) {....}

**Supported hooks**&#x20;

**Filter name:**  before\_get\_companies\
**Description:** This filter would be executed before retrieving company details from database in get\_company\_data helper.\
**Usage:**

```php
// The filter callback function is based on the filter.
add_filter('before_get_companies', 'before_get_companies_callback_fn', 10, 1);
 
function before_get_companies_callback_fn ($company_id) {
   // This filter would be executed before retrieving company details from database in get_company helper.
}
```

**Filter name:**  should\_get\_companies\
**Description:** This filter would be executed before retrieving company details from database in get\_company\_data helper.\
**Usage:**

```php
// The filter callback function is based on the filter.
add_filter('should_get_companies', 'should_get_companies_callback_fn', 10, 1);

function should_get_companies_callback_fn ($company_id) {
   // This filter would be executed before retrieving company details from database in get_company helper.
}
```

**Hook name :**  pre.get.companies\
**Description:** This hook would be executed before retrieving company details from database in get\_company\_data helper.\
**Usage:**

```php
// The filter callback function is based on the filter.
add_filter('pre.get.companies', 'pre_get_companies_callback_fn', 10, 1);

function pre_get_companies_callback_fn ($company_id) {
   // This filter would be executed before retrieving company from database in get_company_data helper.
}
```

**Hook name :**  post.get.companies\
**Description:** This hook would be executed after retrieving company details from database in get\_company\_data helper.\
**Usage:**

```php
// The filter callback function is based on the filter.
add_filter('post.get.companies', ' post_get_companies_callback_fn', 10, 1);

function post_get_companies_callback_fn ($company_id) {
    // This filter would be executed before retrieving company details from database in get_company_data helper.
}
```

**Usage**

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

// Retrieves company data or settings based on a company_id. 
// this function will proivde join data from room, user, user_profiles tables
$company_data = get_company_data($company_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>$company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>Company Id is the primary key for the company table.</td></tr></tbody></table>

**Response**

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

Array
(
    [company_id] => 1
    [name] => honey & bunny
    [address] => 
    [phone] => 
    [city] => 
    [region] => 
    [country] => India
    [website] => 
    [email] => support@minical.io
    [fax] => 
    [selling_date] => 2022-01-27
    [nightly_audit_charge_id] => 
    [time_zone] => Pacific/Midway
    [GST_number] => 
    [postal_code] => 
    [is_daily_rate_including_tax] => 0
    [is_setup] => 0
    [number_of_rooms] => 10
    [reservation_policies] => 
    [check_in_policies] => 
    [night_audit_auto_prompt] => 0
    [night_audit_auto_prompt_time] => 00:00:00
    [night_audit_force_check_out] => 0
    [night_audit_multiple_days] => 0
    [require_paypal_payment] => 0
    [paypal_account] => 
    [percentage_of_required_paypal_payment] => 50
    [housekeeping_auto_clean_is_enabled] => 1
    [housekeeping_auto_clean_time] => 16:00:00
    [housekeeping_day_interval_for_full_cleaning] => 4
    [online_reservation_confirmation_message] => To secure your reservation spot, please confirm your reservation with the [name] by calling [phone] or by sending email to [email]
    [default_currency_id] => 151
    [night_audit_auto_run_is_enabled] => 0
    [night_audit_auto_run_time] => 04:00:00
    [property_type] => 0
    [invoice_email_header] => 
    [booking_confirmation_email_header] => 
    [send_invoice_email_automatically] => 1
    [ask_for_review_in_invoice_email] => 0
    [hide_decimal_places] => 0
    [companycol] => 
    [redirect_to_trip_advisor] => 0
    [tripadvisor_link] => 
    [employee_auto_logout_is_enabled] => 0
    [api_key] => 
    [website_uri] => 
    [website_about] => 
    [website_latitude] => 
    [website_longitude] => 
    [website_is_taking_online_reservation] => 0
    [website_theme_color] => EDE8EB
    [website_facebook_page_url] => 
    [website_tripadvisor_location_id] => 
    [google_analytics_id] => 
    [google_conversion_id] => 
    [google_conversion_label] => 
    [logo_image_id] => 
    [logo_image_group_id] => 1
    [gallery_image_group_id] => 3
    [slideshow_image_group_id] => 2
    [website_title] => 
    [website_tripadvisor_widget_type] => 0
    [allow_same_day_check_in] => 1
    [booking_email_confirmation_message] => This reservation is provisionary. It is not confirmed until the payment information is given from the customer. For questions, please contact us at [email].
    [invoice_header] => 
    [last_night_audit] => 
    [night_audit_charge_in_house_only] => 0
    [night_audit_ignore_check_out_date] => 0
    [book_over_unconfirmed_reservations] => 0
    [statement_number] => 1
    [enable_card_tokenization] => 1
    [booking_engine_booking_status] => 0
    [is_total_balance_include_forecast] => 1
    [is_display_tooltip] => 1
    [partner_id] => 0
    [booking_dot_com_rate_type] => base_rate
    [common_additional_adult_rate] => 
    [allow_non_continuous_bookings] => 1
    [maximum_no_of_blocks] => 2
    [manual_payment_capture] => 0
    [include_cancelled_noshow_bookings] => 1
    [force_room_selection] => 1
    [send_copy_to_additional_emails] => 0
    [additional_company_emails] => 
    [hide_forecast_charges] => 0
    [housekeeping_auto_dirty_is_enabled] => 0
    [housekeeping_auto_dirty_time] => 16:00:00
    [automatic_feedback_email] => 0
    [subscription_country] => US
    [auto_no_show] => 1
    [last_login] => 
    [show_rate_on_registration_card] => 1
    [automatic_email_confirmation] => 0
    [automatic_email_cancellation] => 0
    [email_confirmation_for_ota_reservations] => 0
    [make_guest_field_mandatory] => 0
    [is_deleted] => 0
    [ui_theme] => 1
    [default_charge_name] => Room Charge
    [date_format] => YY-MM-DD
    [default_room_singular] => room
    [default_room_plural] => rooms
    [default_room_type] => room type
    [avoid_dmarc_blocking] => 0
    [enable_hourly_booking] => 0
    [default_checkin_time] => 12:00 AM
    [default_checkout_time] => 12:00 AM
    [allow_free_bookings] => 0
    [show_logo_on_registration_card] => 0
    [restrict_booking_dates_modification] => 0
    [restrict_checkout_with_balance] => 0
    [enable_api_access] => 1
    [customer_modify_booking] => 0
    [booking_cancelled_with_balance] => 0
    [booking_checkedout_with_balance] => 0
    [enable_new_calendar] => 1
    [default_language] => 1
    [hide_room_name] => 0
    [email_confirmation_for_booking_engine] => 0
    [is_cc_visualization_enabled] => 0
    [send_booking_notes] => 0
    [show_guest_group_invoice] => 0
    [booking_engine_tracking_code] => 
    [email_cancellation_for_ota_reservations] => 0
)
// If there is no company data for any company id provided in input or any error will return null.
```


# Customer Helper Functions

The helper you can use to create, delete, get and update Customer details.

### function add\_customer($customer) {.....}

#### **Supported hooks**

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

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

add_filter( ‘before_add_customer’, ‘before_add_customer_callback_fun’, 10, 1 );

function before_add_customer_callback_fun($customer) {
 // code
}
```

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

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

add_filter( ‘should_add_customer’, ‘should_add_customer_callback_fun’, 10, 1 );

function should_add_customer_callback_fun($customer) {
    // code
}
```

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

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

add_action('pre.add.customer', 'pre_add_customer_callback_fun', 10, 1);

function pre_add_customer_callback_fun($customer) {
    // code
}
```

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

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

add_action('post.add.customer', 'post_add_customer_callback_fun', 10, 1);

function post_add_customer_callback_fun($customer) {
    // code
}
```

**Usage**

```php
// for use customer helper you need to add this helper on controller or
// you can autoload this helper.

$this->load->helper('includes/customer');

// add a new customer in customer table. And add customer's primary card details. 
$customer_id = add_customer($customer);
```

**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>customer_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The customer name of a specific customer.</td></tr><tr><td>address</td><td>Character</td><td></td><td>Null</td><td>The address for specific customer.</td></tr><tr><td>city</td><td>Character</td><td></td><td>Null</td><td>The city for a specific customer.</td></tr><tr><td>region</td><td>Character</td><td></td><td>Null</td><td>The region for a specific customer.</td></tr><tr><td>country</td><td>Character</td><td></td><td>Null</td><td>The country for a specific customer.</td></tr><tr><td>postal_code</td><td>Character</td><td></td><td>Null</td><td>The postal_code for a specific customer. </td></tr><tr><td>phone</td><td>Character</td><td></td><td>Null</td><td>The phone number of a specific customer.</td></tr><tr><td>fax</td><td>Character</td><td></td><td>Null</td><td>The fax for a specific customer.</td></tr><tr><td>email</td><td>Character</td><td></td><td>Null</td><td>The email id of specific customer.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific customer.</td></tr><tr><td>customer_notes</td><td>Character</td><td></td><td>Null</td><td>The customer_notes for a specific customer.</td></tr><tr><td>phone2</td><td>Character</td><td></td><td>Null</td><td>The phone2 second number of a specific customer.</td></tr><tr><td>address2</td><td>Character</td><td></td><td>Null</td><td>The address2 second address of a specific customer.</td></tr><tr><td>customer_type</td><td>Character</td><td></td><td>Null</td><td>The customer_type  for a specific customer.</td></tr><tr><td>is_primary</td><td>Integer</td><td>Yes</td><td>1</td><td>The is_primary if active then customer card add as a primary card for a specific customer.</td></tr><tr><td>card_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The card_name for a specific customer card  details.</td></tr><tr><td>cc_number</td><td>Character</td><td>Yes</td><td>Null</td><td>The cc_number of the card for customer card details.</td></tr><tr><td>cvc</td><td>Character</td><td>Yes</td><td>Null</td><td>The cvc of the card for customer card details.</td></tr><tr><td>cc_expiry_month</td><td>Character</td><td>Yes</td><td>Null</td><td>The cc_expiry_month of the card for customer card details.</td></tr><tr><td>cc_expiry_year</td><td>Character</td><td>Yes</td><td>Null</td><td>The cc_expiry_year of the card for customer card details.</td></tr></tbody></table>

**Response**

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

```php
return $customer_id;
```

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

### function get\_customer($customer\_id) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_customer’, ‘before_get_customer_callback_fun’, 10, 1 );

function before_get_customer_callback_fun($customer_id) {
 // code
}
```

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

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

add_filter( ‘should_get_customer’, ‘should_get_customer_callback_fun’, 10, 1 );

function should_get_customer_callback_fun($customer_id) {
    // code
}
```

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

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

add_action('pre.get.customer', 'pre_get_customer_callback_fun', 10, 1);

function pre_get_customer_callback_fun($customer_id) {
    // code
}
```

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

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

add_action('post.get.customer', 'post_get_customer_callback_fun', 10, 1);

function post_get_customer_callback_fun($customer_id) {
    // code
}
```

**Usage**

```php
// Retrieves customer data based on a customer_id.
$customer_data = get_customer($customer_id);
```

**Request Parameters**

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

**Response**

```php
// Successfully response giving you array of customer data.
Array
(
    [customer_id] => 21
    [customer_name] => vishal solanki
    [address] => 162 banganga
    [city] => indore
    [region] => 
    [country] => india
    [postal_code] => 452007
    [phone] => 45435656657
    [fax] => 
    [email] => 
    [company_id] => 1
    [customer_notes] => 
    [is_deleted] => 0
    [customer_type] => 
    [cc_number] => 
    [cc_expiry_month] => 
    [cc_expiry_year] => 
    [stripe_customer_id] => 
    [customer_type_id] => 1
    [address2] => 
    [phone2] => 36546667667
    [cc_tokenex_token] => 
    [cc_cvc_encrypted] => 
    [customer_fields] => Array
        (
        )

)

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

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

**Supported hooks**

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

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

add_filter( ‘before_get_customers’, ‘before_get_customers_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_customers’, ‘should_get_customers_callback_fun’, 10, 1 );

function should_get_customers_callback_fun($filter) {
    // code
}

```

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

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

add_action('pre.get.customers', 'pre_get_customers_callback_fun', 10, 1);

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

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

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

add_action('post.get.customers', 'post_get_customers_callback_fun', 10, 1);

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

**Usage**

```php
// Retrieves customer data based on a filter array.
$customer_data = get_customers($filter);
```

**Request Parameters**

parameter array filter required for payment details.

| Param          | Type      | Required | Default | Description                                        |
| -------------- | --------- | -------- | ------- | -------------------------------------------------- |
| customer\_name | Character | Yes      | Null    | The customer name for a specific customer details. |
| customer\_id   | Integer   | Yes      | Null    | The customer\_id  for a specific customer.         |
| company\_id    | Integer   | Yes      | Null    | The company\_id for a specific customer.           |
| email          | Character | Yes      | Null    | The email for a specific customer.                 |

**Response**

```php
// $response array includes following attributes:
// $response['customer_name'] : the customer_name of specific customer.
// $response['address'] : the address for specific customer .
// $response['city'] : the is_percentage for specific customer.
// $response['region'] : the region for specific customer.
// $response['country'] : the country for specific customer.
// $response['postal_code'] : the postal_code for specific customer.
// $response['phone'] : the phone for specific customer.
// $response['fax'] : the fax for specific  customer.
// $response['email'] : the email for specific customer.
// $response['customer_notes'] : the customer_notes for specific customer.
// $response['customer_type'] : the customer_type for specific customer.
// $response['address2'] : the customer_notes for specific customer.
// $response['phone2'] : the customer_notes for specific customer.
// $response['is_primary'] : the is_primary for specific customer card details.
// $response['card_name'] : the card_name for specific customer card details.
// $response['cc_number'] : the cc_number for specific customer card details.
// $response['cvc'] : the cvc for specific customer card details.
// $response['cc_expiry_month'] : the cc_expiry_month for specific customer card details.
// $response['cc_expiry_year'] : the cc_expiry_year for specific customer card details.
// and many more attributes for table customer and join with customer card details .

// Successfully response giving you array of customer data.

Array
(
    [0] => Array
        (
            [customer_id] => 21
            [customer_name] => vishal solanki
            [address] => 162 banganga
            [city] => indore
            [region] => 
            [country] => india
            [postal_code] => 452007
            [phone] => 45435656657
            [fax] => 
            [email] => 
            [company_id] => 1
            [customer_notes] => 
            [is_deleted] => 0
            [customer_type] => 
            [cc_number] => 
            [cc_expiry_month] => 
            [cc_expiry_year] => 
            [stripe_customer_id] => 
            [customer_type_id] => 1
            [address2] => 
            [phone2] => 36546667667
            [cc_tokenex_token] => 
            [cc_cvc_encrypted] => 
            [id] => 6
            [is_primary] => 1
            [evc_card_status] => 
            [card_name] => 
            [is_card_deleted] => 0
            [customer_meta_data] => 
        )

)

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

### function update\_customers($customer, $customer\_id) {....}

**Usage**

```php
//update customer data based on a update data and customer id.
 update_customer($customer, $customer_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_customer’, ‘before_update_customer_callback_fun’, 10, 1 );

function before_update_customer_callback_fun($customer, $customer_id) {
 // code
}
```

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

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

add_filter( ‘should_update_customer’, ‘should_update_customer_callback_fun’, 10, 1 );

function should_update_customer_callback_fun($customer, $customer_id) {
    // code
}

```

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

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

add_action('pre.update.customer', 'pre_update_customer_callback_fun', 10, 1);

function pre_update_customer_callback_fun($customer, $customer_id) {
    //code
}
```

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

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

add_action('post.update.customer', 'post_update_customer_callback_fun', 10, 1);

function post_update_customer_callback_fun($customer, $customer_id) {
    // code
}
```

**Request Parameters**

Request required customer\_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>customer_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The customer name of a specific customer.</td></tr><tr><td>address</td><td>Character</td><td></td><td>Null</td><td>The address for specific customer.</td></tr><tr><td>city</td><td>Character</td><td></td><td>Null</td><td>The city for a specific customer.</td></tr><tr><td>region</td><td>Character</td><td></td><td>Null</td><td>The region for a specific customer.</td></tr><tr><td>country</td><td>Character</td><td></td><td>Null</td><td>The country for a specific customer.</td></tr><tr><td>postal_code</td><td>Character</td><td></td><td>Null</td><td>The postal_code for a specific customer. </td></tr><tr><td>phone</td><td>Character</td><td></td><td>Null</td><td>The phone number of a specific customer.</td></tr><tr><td>fax</td><td>Character</td><td></td><td>Null</td><td>The fax for a specific customer.</td></tr><tr><td>email</td><td>Character</td><td></td><td>Null</td><td>The email id of specific customer.</td></tr><tr><td>customer_notes</td><td>Character</td><td></td><td>Null</td><td>The customer_notes for a specific customer.</td></tr><tr><td>phone2</td><td>Character</td><td></td><td>Null</td><td>The phone2 second number of a specific customer.</td></tr><tr><td>address2</td><td>Character</td><td></td><td>Null</td><td>The address2 second address of a specific customer.</td></tr><tr><td>customer_type</td><td>Character</td><td></td><td>Null</td><td>The customer_type  for a specific customer.</td></tr></tbody></table>

**Response**

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

### **function delete\_**&#x63;ustome&#x72;**(**$customer\_i&#x64;**) {.....}**

**Usage**

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

 delete_customer($customer_id);
```

**Request Parameters**

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

**Response**

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


# Booking Helper Functions

The helper you can use to create, delete, get and update booking.

### 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.
```


# Rates Helper Functions

The helper you can use to create, delete, get and update rates.

### function add\_rates($rates) {.....}

#### **Supported hooks**

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

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

add_filter( ‘before_add_rates’, ‘before_add_rates_callback_fun’, 10, 1 );

function before_add_rates_callback_fun($rates) {
 // code
}
```

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

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

add_filter( ‘should_add_rates’, ‘should_add_rates_callback_fun’, 10, 1 );

function should_add_rates_callback_fun($rates) {
    // code
}

```

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

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

add_action('pre.add.rates', 'pre_add_rates_callback_fun', 10, 1);

function pre_add_rates_callback_fun($rates) {
    // code
}
```

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

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

add_action('post.add.rates', 'post_add_rates_callback_fun', 10, 1);

function post_add_rates_callback_fun($rates) {
    // code
}
```

**Usage**

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

// add a new rate in rates table.
$rate_id = add_rates($rates);
```

**Request Parameters**

Parameters in array format includes following attributes:

| Param                     | Type            | Required | Default | Description                                               |
| ------------------------- | --------------- | -------- | ------- | --------------------------------------------------------- |
| rate\_plan\_id            | Integer         | Yes      | Null    | The rate\_plan\_id  of rate plan table for specific rate. |
| base\_rate                | Integer         |          | Null    | The base\_rate for a specific rate.                       |
| adult\_1\_rate            | Decimal Integer |          | Null    | The adult\_1\_rate for a specific rate.                   |
| adult\_2\_rate            | Decimal Integer |          | Null    | The adult\_2\_rate for a specific rate.                   |
| adult\_3\_rate            | Decimal Integer |          | Null    | The adult\_3\_rate  for a specific rate.                  |
| adult\_4\_rate            | Decimal Integer |          | Null    | The adult\_4\_rate for a specific rate.                   |
| minimum\_length\_of\_stay | Integer         |          | Null    | The additional\_adult\_rate for a specific rate.          |
| closed\_to\_arrival       | Integer         |          | Null    | The closed\_to\_arrival  for a specific rate.             |
| additional\_child\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.          |
| maximum\_length\_of\_stay | Integer         |          | Null    | The maximum\_length\_of\_stay for specific rate.          |
| closed\_to\_departure     | Integer         |          | Null    | The closed\_to\_departure  for a specific rate.           |
| can\_be\_sold\_online     | Integer         |          | Null    | The can\_be\_sold\_online for a specific rate.            |
| additional\_adult\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.          |

**Response**

```
Response include following attributes:
if data have added successfully it would return the key of specific rate id.

```

```php
retrun $rate_id;
```

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

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

#### **Supported hooks**

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

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

add_filter( ‘before_get_rate’, ‘before_get_rate_callback_fun’, 10, 1 );

function before_get_rate_callback_fun($rate_id) {
 // code
}
```

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

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

add_filter( ‘should_get_rate’, ‘should_get_rate_callback_fun’, 10, 1 );

function should_get_rate_callback_fun($rate_id) {
    // code
}

```

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

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

add_action('pre.get.rate', 'pre_get_rate_callback_fun', 10, 1);

function pre_get_rate_callback_fun($rate_id) {
    // code
}
```

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

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

add_action('post.get.rate', 'post_get_rate_callback_fun', 10, 1);

function post_get_rate_callback_fun($rate_id) {
    // code
}
```

**Usage**

```php
// Retrieves rate data based on a rate_id.
$rate_data = get_rate($rate_id);


```

**Request Parameters**

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

**Response**

```php
// $response array includes following attributes:
// $response['rate_plan_id'] : the rate_plan_id of specific rate.
// $response['base_rate'] : the base_rate for specific rate.
// $response['adult_1_rate'] : the adult_1_rate for specific rate.
// $response['adult_2_rate'] : the adult_2_rate for specific rate.
// $response['adult_3_rate'] : the adult_3_rate for specific rate.
// $response['adult_4_rate'] : the adult_4_rate for specific rate.
// $response['additional_adult_rate'] : the additional_adult_rate for specific rate.
// $response['minimum_length_of_stay'] : the minimum_length_of_stay for specific rate.
// $response['closed_to_arrival'] : the closed_to_arrival  for specific rate.
// $response['closed_to_departure'] : the closed_to_departure for specific rate.
// and many more attributes for table rate with rate table.
 
// Successfully response giving an array of rate data.

  Array
  (
    [rate_id] => 2
    [rate_plan_id] => 2
    [base_rate] => 
    [adult_1_rate] => 
    [adult_2_rate] => 
    [adult_3_rate] => 
    [adult_4_rate] => 
    [additional_adult_rate] => 
    [additional_child_rate] => 
    [is_deleted] => 
    [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 data for any rate id provided in input or any error will return null. 
```

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

**Supported hooks**

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

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

add_filter( ‘before_get_rates’, ‘before_get_rates_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_rates’, ‘should_get_rates_callback_fun’, 10, 1 );

function should_get_rates_callback_fun($filter) {
    // code
}

```

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

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

add_action('pre.get.rates', 'pre_get_rates_callback_fun', 10, 1);

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

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

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

add_action('post.get.rates', 'post_get_rates_callback_fun', 10, 1);

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

**Usage**

```php

// Retrieves rate data based on a filter array.
$rate_data = get_rates($filter);
```

**Request Parameters**

parameter array filter required for rate details.

| Param          | Type    | Required | Default | Description                                            |
| -------------- | ------- | -------- | ------- | ------------------------------------------------------ |
| rate\_id       | Integer | Yes      | Null    | The rate id the primary key for a specific rate table. |
| rate\_plan\_id | Integer | Yes      | Null    | The rate plan id for specific rate.                    |

**Response**

```php
// $response array includes following attributes:
// $response['rate_plan_id'] : the rate_plan_id of specific rate.
// $response['base_rate'] : the base_rate for specific rate.
// $response['adult_1_rate'] : the adult_1_rate for specific rate.
// $response['adult_2_rate'] : the adult_2_rate for specific rate.
// $response['adult_3_rate'] : the adult_3_rate for specific rate.
// $response['adult_4_rate'] : the adult_4_rate for specific rate.
// $response['additional_adult_rate'] : the additional_adult_rate for specific rate.
// $response['minimum_length_of_stay'] : the minimum_length_of_stay for specific rate.
// $response['closed_to_arrival'] : the closed_to_arrival  for specific rate.
// $response['closed_to_departure'] : the closed_to_departure for specific rate.

// Successfully response giving you array of rate data.
  Array
(
    [0] => Array
        (
            [rate_id] => 3
            [rate_plan_id] => 1
            [base_rate] => 
            [adult_1_rate] => 20.00
            [adult_2_rate] => 40.00
            [adult_3_rate] => 60.00
            [adult_4_rate] => 80.00
            [additional_adult_rate] => 
            [additional_child_rate] => 
            [is_deleted] => 
            [minimum_length_of_stay] => 
            [maximum_length_of_stay] => 
            [minimum_length_of_stay_arrival] => 
            [maximum_length_of_stay_arrival] => 
            [closed_to_arrival] => 0
            [closed_to_departure] => 0
            [can_be_sold_online] => 1
        )
)

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

### function update\_rates($rates , $rate\_id) {....}

**Usage**

```php
//update rate data based on a update data and rate id.
 update_rates($rates , $rate_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_rates’, ‘before_update_rates_callback_fun’, 10, 1 );

function before_update_rates_callback_fun($rates , $rate_id) {
 // code
}
```

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

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

add_filter( ‘should_update_rates’, ‘should_update_rates_callback_fun’, 10, 1 );

function should_update_rates_callback_fun($rates, $rate_id) {
    // code
}

```

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

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

add_action('pre.update.rates', 'pre_update_rates_callback_fun', 10, 1);

function pre_update_rates_callback_fun($rates, $rate_id) {
    // code
}
```

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

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

add_action('post.update.rates', 'post_update_rates_callback_fun', 10, 1);

function post_update_rates_callback_fun($rates, $rate_id) {
    // code
}
```

**Request Parameters**

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

| Param                     | Type            | Required | Default | Description                                                     |
| ------------------------- | --------------- | -------- | ------- | --------------------------------------------------------------- |
| rate\_id                  | Integer         | Yes      | Null    | The primary key rate id of rate table for specific rate update. |
| rate\_plan\_id            | Integer         | Yes      | Null    | The rate\_plan\_id  of rate plan table for specific rate.       |
| base\_rate                | Integer         |          | Null    | The base\_rate for a specific rate.                             |
| adult\_1\_rate            | Decimal Integer |          | Null    | The adult\_1\_rate for a specific rate.                         |
| adult\_2\_rate            | Decimal Integer |          | Null    | The adult\_2\_rate for a specific rate.                         |
| adult\_3\_rate            | Decimal Integer |          | Null    | The adult\_3\_rate  for a specific rate.                        |
| adult\_4\_rate            | Decimal Integer |          | Null    | The adult\_4\_rate for a specific rate.                         |
| minimum\_length\_of\_stay | Integer         |          | Null    | The additional\_adult\_rate for a specific rate.                |
| closed\_to\_arrival       | Integer         |          | Null    | The closed\_to\_arrival  for a specific rate.                   |
| additional\_child\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.                |
| maximum\_length\_of\_stay | Integer         |          | Null    | The maximum\_length\_of\_stay for specific rate.                |
| closed\_to\_departure     | Integer         |          | Null    | The closed\_to\_departure  for a specific rate.                 |
| can\_be\_sold\_online     | Integer         |          | Null    | The can\_be\_sold\_online for a specific rate.                  |
| additional\_adult\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.                |

**Response**

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

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

**Usage**

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

 delete_rate($rate_id);
```

**Request Parameters**

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

**Response**

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


# Rate Plan Helper Functions

The helper you can use to create, delete, get and update Rate Plan details.

### 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.
```


# Availability Helper Functions

The helper you can use to get room availability details in the company.

### **function get\_**&#x61;vailability($filter) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_availability’, ‘before_get_availability_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_availability’, ‘should_get_availability_callback_fun’, 10, 1 );

function should_get_availability_callback_fun($filter) {
// code
}

```

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

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

add_action('pre.get.availability', 'pre_get_availability_callback_fun', 10, 1);

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

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

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

add_action('post.get.availability', 'post_get_availability_callback_fun', 10, 1);

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

**Usage**

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

// Retrieves room availability data based on the filter.
$availability_data = get_availability($filter);
```

**Request Parameters**

```
Param array $filter (Required)  for availability details.
```

<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>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id of specific company(must require).</td></tr><tr><td>ota_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The ota_id of any specific OTA type (must require)</td></tr><tr><td>start_date</td><td>Date_time</td><td>Yes</td><td>Null</td><td>The start_date of any specific availability data (must required)</td></tr><tr><td>end_date</td><td>Date_time</td><td>Yes</td><td>Null</td><td>The end_date of any specific availability data(must require)</td></tr><tr><td>adult_count</td><td>Integer</td><td></td><td>Null</td><td>The adult_count of any specific availability</td></tr><tr><td>children_count</td><td>Integer</td><td></td><td>Null</td><td>The children_count of any specific availability</td></tr><tr><td>filter_can_be_sold_online</td><td>Boolean</td><td></td><td>True</td><td>The filter_can_be_sold_online of any specific availability.</td></tr><tr><td>company_group_id</td><td>Integer</td><td></td><td>Null</td><td>The company_group_id of any specific availability.</td></tr><tr><td>get_max_availability</td><td>Boolean</td><td></td><td>True</td><td>The get_max_availability of any specific availability.</td></tr><tr><td>get_inventorysold</td><td>Boolean</td><td></td><td>True</td><td>The get_inventorysold of any specific availability.</td></tr><tr><td>get_closeout_status</td><td>Boolean</td><td></td><td>True</td><td>The get_closeout_status of any specific availability.</td></tr><tr><td>get_inventory</td><td>Boolean</td><td></td><td>True</td><td>The get_inventory of any specific availability.</td></tr><tr><td>ota_key</td><td>Character</td><td></td><td>Null</td><td>The ota_key of any specific availability.</td></tr></tbody></table>

**Response**

```php
// Response array includes multiple array of availability for room type have following attributes:
// $response['id'] : the id of specific room types.
// $response['company_id'] : the company_id for specific room types.
// $response['rate_plan_count'] : the rate_plan_count for specific room types.
// $response['max_occupancy'] : the max_occupancy for specific room types.
// $response['max_adult'] : the max_adult for specific room types.
// $response['max_children'] : the max_children for specific room types.
// $response['default_room_charge'] : the default_room_charge for specific room types.
// $response['date_start'] : the date_start for specific room availability.
// $response['date_end'] : the date_end for specific room availability.
// $response['availability'] : the availability for specific room availability.
// $response['max_availability'] : the max_availability for specific room availability.
// $response['max_availability'] : the name for specific room availability.
// $response['inventory_sold'] : the inventory_sold for specific room availability.
// and many more attributes from availability and join with room , room type table.

// Successfully response giving you array of availability data.

Array
(
    [2] => Array
        (
            [id] => 2
            [name] => Sample Room Type
            [company_id] => 1
            [acronym] => SRT
            [is_deleted] => 0
            [max_occupancy] => 6
            [min_occupancy] => 1
            [max_adults] => 2
            [max_children] => 1
            [image_group_id] => 5
            [description] => 
            [can_be_sold_online] => 1
            [ota_close_out_threshold] => 1
            [sort] => 0
            [default_room_charge] => 1
            [prevent_inline_booking] => 0
            [rate_plan_count] => 2
            [availability] => Array
                (
                    [0] => Array
                        (
                            [date_start] => 2022-02-02
                            [date_end] => 2022-02-03
                            [date] => 2022-02-03
                            [availability] => 3
                            [max_availability] => 4
                            [inventory_sold] => 0
                            [closeout_status] => 1
                        )

                )

        )

    [3] => Array
        (
            [id] => 3
            [name] => Super Room Type
            [company_id] => 1
            [acronym] => NRT
            [is_deleted] => 0
            [max_occupancy] => 11
            [min_occupancy] => 1
            [max_adults] => 4
            [max_children] => 4
            [image_group_id] => 6
            [description] => 
            [can_be_sold_online] => 1
            [ota_close_out_threshold] => 1
            [sort] => 0
            [default_room_charge] => 1
            [prevent_inline_booking] => 0
            [rate_plan_count] => 2
            [availability] => Array
                (
                    [0] => Array
                        (
                            [date_start] => 2022-02-02
                            [date_end] => 2022-02-03
                            [date] => 2022-02-03
                            [availability] => 2
                            [max_availability] => 3
                            [inventory_sold] => 0
                            [closeout_status] => 1
                        )

                )

        )

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


# Statement Helper Functions

The helper you can use to create, delete, get and update Statement details.

### function add\_statement($statement) {.....}

#### **Supported hooks**

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

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

add_filter( ‘before_add_statement’, ‘before_add_statement_callback_fun’, 10, 1 );

function before_add_statement_callback_fun($statement) {
 // code
}
```

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

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

add_filter( ‘should_add_statement’, ‘should_add_statement_callback_fun’, 10, 1 );

function should_add_statement_callback_fun($statement) {
    // code
}

```

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

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

add_action('pre.add.statement', 'pre_add_statement_callback_fun', 10, 1);

function pre_add_statement_callback_fun($statement) {
    // code
}
```

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

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

add_action('post.add.statement', 'post_add_statement_callback_fun', 10, 1);

function post_add_statement_callback_fun($statement) {
    // code
}
```

**Usage**

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

// add a new statement in statement table.
$statement_id = add_statement($statement);
```

**Request Parameters**

Parameters in array format includes following attributes:

| Param             | Type       | Required | Default | Description                                                                       |
| ----------------- | ---------- | -------- | ------- | --------------------------------------------------------------------------------- |
| statement\_number | Integer    | Yes      | Null    | The statement\_number of a specific statement.                                    |
| creation\_date    | Date\_time |          | Null    | the creation\_date for specific statement ( must provide date in gmdate() format) |
| statement\_name   | Character  | Yes      | Null    | The statement\_name  for specific statement.                                      |
| booking\_id       | Integer    | Yes      | Null    | The booking\_id create for a specific booking statement.                          |

**Response**

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

```

```php
return $statement_id;
```

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

### function get\_statement($statement\_id) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_statement’, ‘before_get_statement_callback_fun’, 10, 1 );

function before_get_statement_callback_fun($statement_id) {
 // code
}
```

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

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

add_filter( ‘should_get_statement’, ‘should_get_statement_callback_fun’, 10, 1 );

function should_get_statement_callback_fun($statement_id) {
    // code
}
```

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

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

add_action('pre.get.statement', 'pre_get_statement_callback_fun', 10, 1);

function pre_get_statement_callback_fun($statement_id) {
    // code
}
```

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

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

add_action('post.get.statement', 'post_get_statement_callback_fun', 10, 1);

function post_get_statement_callback_fun($statement_id) {
    // code
}
```

**Usage**

```php
// Retrieves statementdata based on a statement_id.
$statement_data = get_statement($statement_id);


```

**Request Parameters**

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

**Response**

```php
// $response array includes following attributes:
// $response['statement_number'] : the statement_number of specific statement.
// $response['creation_date'] : the creation_date for specific statement .
// $response['statement_name'] : the statement_name for specific statement.
// $response['booking_id'] : the booking_id for specific statement.
// and many more attributes for table statement and join with booking_x_statement table.

// Successfully response giving you array of statement data.

Array
(
    [0] => Array
        (
            [statement_id] => 1
            [statement_number] => 0
            [is_deleted] => 0
            [creation_date] => 2022-01-24 05:58:43
            [statement_name] => booking create 
            [booking_id] => 1
        )

)

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

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

**Supported hooks**

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

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

add_filter( ‘before_get_statements’, ‘before_get_statements_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_statements’, ‘should_get_statements_callback_fun’, 10, 1 );

function should_get_statements_callback_fun($filter) {
    // code
}

```

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

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

add_action('pre.get.statements', 'pre_get_statements_callback_fun', 10, 1);

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

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

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

add_action('post.get.statements', 'post_get_statements_callback_fun', 10, 1);

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

**Usage**

```php

// Retrieves statement data based on a filter array.
$statement_data = get_statements($filter);
```

**Request Parameters**

parameter array filter required for statement details.

| Param           | Type      | Required | Default | Description                                   |
| --------------- | --------- | -------- | ------- | --------------------------------------------- |
| statement\_name | Character | Yes      | Null    | The statement\_name for a specific statement. |
| booking\_id     | Integer   | Yes      | Null    | The booking\_id  for specific statement.      |

**Response**

```php
// $response array includes following attributes:
// $response['statement_number'] : the statement_number of specific statement.
// $response['creation_date'] : the creation_date for specific statement .
// $response['statement_name'] : the statement_name for specific statement.
// $response['booking_id'] : the booking_id for specific statement.
// and many more attributes for table statement and join with booking_x_statement table.

// Successfully response giving you array of statement data.

Array
(
    [0] => Array
        (
            [statement_id] => 1
            [statement_number] => 0
            [is_deleted] => 0
            [creation_date] => 2022-01-24 05:58:43
            [statement_name] => booking create must need
            [booking_id] => 1
        )

)

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

### function update\_statement($statement, $statement\_id) {....}

**Usage**

```php
// update statement data based on a statement array data and statement_id.
 update_statement($statement, $statement_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_statement’, ‘before_update_statement_callback_fun’, 10, 1 );

function before_update_statement_callback_fun($statement, $statement_id) {
 // code
}
```

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

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

add_filter( ‘should_update_statement’, ‘should_update_statement_callback_fun’, 10, 1 );

function should_update_statement_callback_fun($statement, $statement_id) {
    // code
}

```

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

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

add_action('pre.update.statement', 'pre_update_statement_callback_fun', 10, 1);

function pre_update_statement_callback_fun($statement, $statement_id) {
    // code
}
```

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

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

add_action('post.update.statement', 'post_update_statement_callback_fun', 10, 1);

function post_update_statement_callback_fun($statement, $statement_id) {
    // code
}
```

**Request Parameters**

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

<table><thead><tr><th width="215">Param</th><th>Type</th><th>Required</th><th>Default</th><th>Description</th><th></th></tr></thead><tbody><tr><td>statement_number</td><td>Integer</td><td>Yes</td><td>Null</td><td>The statement_number of a specific statement.</td><td></td></tr><tr><td>creation_date</td><td>Date_time</td><td></td><td>Null</td><td>the creation_date for specific statement ( must provide date in gmdate() format)</td><td></td></tr><tr><td>statement_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The statement_name  for specific statement.</td><td></td></tr><tr><td>booking_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The booking_id create for a specific booking statement.</td><td></td></tr></tbody></table>

**Response**

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

### **function delete\_**&#x73;tatement **(**$statement\_i&#x64;**) {.....}**

**Usage**

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

 delete_statement($statement_id);
```

**Request Parameters**

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

**Response**

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


# Tax Helper Functions

The helper you can use to create, delete, get and update Tax details.

### 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.
```


# Room Helper Functions

The helper you can use to create, delete, get and update Room details in the company.

### function add\_room($room) {.....}

#### **Supported hooks**

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

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

add_filter( ‘before_add_room’, ‘before_room_tax_callback_fun’, 10, 1 );

function before_add_room_callback_fun($room) {
 // code
}
```

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

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

add_filter( ‘should_add_room’, ‘should_add_room_callback_fun’, 10, 1 );

function should_add_room_callback_fun($room) {
    // code
}
```

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

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

add_action('pre.add.room', 'pre_add_room_callback_fun', 10, 1);

function pre_add_room_callback_fun($room) {
    // code
}
```

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

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

add_action('post.add.room', 'post_add_room_callback_fun', 10, 1);

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

**Usage**

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

// add a new room in room table. you can only add a new room if your number_of_rooms capacity not full in company.
$room_id = add_room($room);
```

**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>room_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The room_name  of a specific room.</td></tr><tr><td>room_type_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The room_type_id  for a specific room.</td></tr><tr><td>sort_order</td><td>Integer</td><td>Yes</td><td>0</td><td>The sort_order  for a specific room.</td></tr><tr><td>status</td><td>Character</td><td>Yes</td><td>Clean</td><td>The room status for a specific room.</td></tr><tr><td>group_id</td><td>Integer</td><td></td><td>0</td><td>The group_id  for a specific room.</td></tr><tr><td>floor_id</td><td>Integer</td><td></td><td>0</td><td>The floor_id for a specific room.</td></tr><tr><td>location_id</td><td>Integer</td><td></td><td>0</td><td>The location_id for a specific room.</td></tr><tr><td>score</td><td>Integer</td><td></td><td>0</td><td>The score for a specific room.</td></tr><tr><td>instructions</td><td>Text</td><td></td><td>Null</td><td>The instructions for a specific room.</td></tr><tr><td>can_be_sold_online</td><td>Integer</td><td></td><td>1</td><td>The can_be_sold_online for a specific room.</td></tr><tr><td>notes</td><td>Text</td><td></td><td>Null</td><td>The notes for a specific room.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific room.</td></tr></tbody></table>

**Response**

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

```

```php
return $room_id;
```

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

### function get\_room($room\_id) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_room’, ‘before_get_room_callback_fun’, 10, 1 );

function before_get_room_callback_fun($room_id) {
 // code
}
```

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

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

add_filter( ‘should_get_room’, ‘should_get_room_callback_fun’, 10, 1 );

function should_get_room_callback_fun($room_id) {
    // code
}
```

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

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

add_action('pre.get.room', 'pre_get_room_callback_fun', 10, 1);

function pre_get_room_callback_fun($room_id) {
    // code
}
```

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

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

add_action('post.get.room', 'post_get_room_callback_fun', 10, 1);

function post_get_room_callback_fun($room_id) {
    // code
}
```

**Usage**

```php
// Retrieves room data based on a room_id.
$room_data = get_room($room_id);
```

**Request Parameters**

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

**Response**

```php
// $response array includes following attributes:
// $response['room_name'] : the room_name of specific room.
// $response['room_type_id'] : the room_type_id for specific room.
// $response['sort_order'] : the sort_order for specific room.
// $response['status'] : the status for specific room.
// $response['company_id'] : the company_id for specific room.
// $response['room_type_name'] : the room_type_name for specific room.
// $response['can_be_sold_online'] : the can_be_sold_online for specific room.
// and many more attributes for table room and join with room type table.

// Successfully response giving you array of room data.
Array
(
    [room_name] => 101
    [room_type_id] => 2
    [status] => Clean
    [notes] => 
    [room_id] => 11
    [is_deleted] => 0
    [company_id] => 1
    [can_be_sold_online] => 1
    [group_id] => 0
    [floor_id] => 0
    [location_id] => 0
    [sort_order] => 0
    [is_hidden] => 0
    [score] => 0
    [instructions] => 
    [id] => 2
    [name] => Sample Room Type
    [acronym] => SRT
    [max_occupancy] => 6
    [min_occupancy] => 1
    [max_adults] => 2
    [max_children] => 1
    [image_group_id] => 5
    [description] => 
    [ota_close_out_threshold] => 1
    [sort] => 0
    [default_room_charge] => 1
    [prevent_inline_booking] => 0
    [room_type_name] => Sample Room Type
)

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

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

**Supported hooks**

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

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

add_filter( ‘before_get_rooms’, ‘before_get_rooms_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_rooms’, ‘should_get_rooms_callback_fun’, 10, 1 );

function should_get_rooms_callback_fun($filter) {
    // code
}

```

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

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

add_action('pre.get.rooms', 'pre_get_rooms_callback_fun', 10, 1);

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

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

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

add_action('post.get.rooms', 'post_get_rooms_callback_fun', 10, 1);

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

**Usage**

```php
// Retrieves room data based on a filter array.
$room_data = get_rooms($filter);
```

**Request Parameters**

parameter array filter required for room details.

| Param          | Type      | Required | Default | Description                            |
| -------------- | --------- | -------- | ------- | -------------------------------------- |
| room\_name     | Character | Yes      | Null    | The room\_name for a specific room.    |
| company\_id    | Integer   | Yes      | Null    | The company\_id  for specific room.    |
| room\_type\_id | Integer   | yes      | Null    | The room\_type\_id  for specific room. |

**Response**

```php
// $response array includes following attributes:
// $response['room_name'] : the room_name of specific room.
// $response['room_type_id'] : the room_type_id for specific room.
// $response['sort_order'] : the sort_order for specific room.
// $response['status'] : the status for specific room.
// $response['company_id'] : the company_id for specific room.
// $response['room_type_name'] : the room_type_name for specific room.
// $response['can_be_sold_online'] : the can_be_sold_online for specific room.
// and many more attributes for table room and join with room type table.

// Successfully response giving you array of room data.

Array
(
    [0] => Array
        (
            [room_name] => 101
            [room_type_id] => 2
            [status] => Clean
            [notes] => 
            [room_id] => 11
            [is_deleted] => 0
            [company_id] => 1
            [can_be_sold_online] => 1
            [group_id] => 0
            [floor_id] => 0
            [location_id] => 0
            [sort_order] => 0
            [is_hidden] => 0
            [score] => 0
            [instructions] => 
            [id] => 2
            [name] => Sample Room Type
            [acronym] => SRT
            [max_occupancy] => 6
            [min_occupancy] => 1
            [max_adults] => 2
            [max_children] => 1
            [image_group_id] => 5
            [description] => 
            [ota_close_out_threshold] => 1
            [sort] => 0
            [default_room_charge] => 1
            [prevent_inline_booking] => 0
        )

)

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

### function update\_room($room, $room\_id) {....}

**Usage**

```php
// update room data based on a update data and room_id.
 update_room($room, $room_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_room’, ‘before_update_room_callback_fun’, 10, 1 );

function before_update_room_callback_fun($room, $room_id) {
 // code
}
```

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

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

add_filter( ‘should_update_room’, ‘should_update_room_callback_fun’, 10, 1 );

function should_update_room_callback_fun($room, $room_id) {
    // code
}
```

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

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

add_action('pre.update.room', 'pre_update_room_callback_fun', 10, 1);

function pre_update_room_callback_fun($room, $room_id) {
    // code
}
```

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

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

add_action('post.update.room', 'post_update_room_callback_fun', 10, 1);

function post_update_room_callback_fun($room, $room_id) {
    // code
}
```

**Request Parameters**

Request required room\_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>room_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The room_id primary key of a specific room.</td></tr><tr><td>room_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The room_name  of a specific room.</td></tr><tr><td>room_type_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The room_type_id  for a specific room.</td></tr><tr><td>sort_order</td><td>Integer</td><td>Yes</td><td>0</td><td>The sort_order  for a specific room.</td></tr><tr><td>status</td><td>Character</td><td>Yes</td><td>Clean</td><td>The room status for a specific room.</td></tr><tr><td>group_id</td><td>Integer</td><td></td><td>0</td><td>The group_id  for a specific room.</td></tr><tr><td>floor_id</td><td>Integer</td><td></td><td>0</td><td>The floor_id for a specific room.</td></tr><tr><td>location_id</td><td>Integer</td><td></td><td>0</td><td>The location_id for a specific room.</td></tr><tr><td>score</td><td>Integer</td><td></td><td>0</td><td>The score for a specific room.</td></tr><tr><td>instructions</td><td>Text</td><td></td><td>Null</td><td>The instructions for a specific room.</td></tr><tr><td>can_be_sold_online</td><td>Integer</td><td></td><td>1</td><td>The can_be_sold_online for a specific room.</td></tr><tr><td>notes</td><td>Text</td><td></td><td>Null</td><td>The notes for a specific room.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific room.</td></tr></tbody></table>

**Response**

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

### **function delete\_**&#x72;oo&#x6D;**(**$room\_i&#x64;**) {.....}**

**Usage**

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

 delete_room($room_id);
```

**Request Parameters**

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

**Response**

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


# Charge Helper Functions

The helper you can use to create, delete, get and update Charge details.

### 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.
```


# Payment Helper Functions

The helper you can use for payment transactions. And get, delete, update payment details.

### function add\_payment($payment) {.....}

#### **Supported hooks**

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

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

add_filter( ‘before_add_payment’, ‘before_add_payment_callback_fun’, 10, 1 );

function before_add_payment_callback_fun($payment) {
 // code
}
```

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

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

add_filter( ‘should_add_payment’, ‘should_add_payment_callback_fun’, 10, 1 );

function should_add_payment_callback_fun($payment) {
    // code
}
```

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

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

add_action('pre.add.payment', 'pre_add_payment_callback_fun', 10, 1);

function pre_add_payment_callback_fun($payment) {
    // code
}
```

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

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

add_action('post.add.payment', 'post_add_payment_callback_fun', 10, 1);

function post_add_payment_callback_fun($payment) {
    // code
}
```

**Usage**

```php
// for use payment helper you need to add this helper on controller or
// you can autoload this helper.

$this->load->helper('includes/payment');

// add a new payment in payment table.
$payment_id = add_payment($payment);
```

**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></td><td>Null</td><td>The description of a specific payment.</td></tr><tr><td>booking_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The booking_id  for a specific payment.</td></tr><tr><td>amount</td><td>Decimal Integer</td><td>Yes</td><td>0</td><td>The amount for a specific payment.</td></tr><tr><td>is_captured</td><td>Integer</td><td></td><td>0</td><td>The is_captured 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 payment ( must provide date in gmdate() format).</td></tr><tr><td>user_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The user_id for a specific payment.</td></tr><tr><td>customer_id</td><td>Integer</td><td></td><td>0</td><td>The customer_id for a specific payment.</td></tr><tr><td>parent_charge_id</td><td>Integer</td><td></td><td>Null</td><td>The parent_charge_id for specific payment.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The company_id for specific payment.</td></tr><tr><td>payment_type_id</td><td>Integer</td><td></td><td>0</td><td>The payment_type_id for a specific payment.</td></tr><tr><td>gateway_charge_id</td><td>Character</td><td>Yes</td><td>Null</td><td>The gateway charge_id for a specific payment.</td></tr><tr><td>payment_gateway_used</td><td>Character</td><td>Yes</td><td>Null</td><td>The payment gateway is used for a specific payment.</td></tr><tr><td>selected_gateway</td><td>Character</td><td>Yes</td><td>Null</td><td>The selected_gateway for a specific payment.</td></tr><tr><td>cvc</td><td>Integer</td><td>Yes</td><td>Null</td><td>The CVC of the user for a specific payment.</td></tr><tr><td>folio_id</td><td>Integer</td><td></td><td>0</td><td>The folio_id for a specific payment.</td></tr></tbody></table>

**Response**

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

```php
return $payment_id;
```

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

### function get\_payment($payment\_id) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_payment’, ‘before_get_payment_callback_fun’, 10, 1 );

function before_get_payment_callback_fun($payment_id) {
 // code
}
```

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

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

add_filter( ‘should_get_payment’, ‘should_get_payment_callback_fun’, 10, 1 );

function should_get_payment_callback_fun($payment_id) {
    // code
}
```

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

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

add_action('pre.get.payment', 'pre_get_payment_callback_fun', 10, 1);

function pre_get_payment_callback_fun($payment_id) {
    // code
}
```

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

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

add_action('post.get.payment', 'post_get_payment_callback_fun', 10, 1);

function post_get_payment_callback_fun($payment_id) {
    // code
}
```

**Usage**

```php
// Retrieves payment data based on a payment_id.
$payment_data = get_payment($payment_id);
```

**Request Parameters**

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

**Response**

```php
// $response array includes following attributes:
// $response['user_id'] : the user_id of specific payment.
// $response['booking_id'] : the booking_id for specific payment .
// $response['selling_date'] : the selling_date for specific payment.
// $response['company_id'] : the company_id for specific payment.
// $response['amount'] : the amount for specific payment.
// $response['customer_id'] : the customer_id for specific payment.
// $response['payment_type_id'] : the payment_type_id for specific payment.
// $response['description'] : the description for specific payment.
// $response['selected_gateway'] : the selected_gateway for specific payment.
// $response['capture_payment_type'] : the capture_payment_type for specific payment.
// and many more attributes for table payment.

// Successfully response giving you array of payment data. 

Array
(
    [payment_id] => 1
    [description] => payment
    [date_time] => 2022-01-26 17:19:53
    [booking_id] => 1
    [amount] => 100.00
    [payment_type_id] => 1
    [credit_card_id] => 1
    [selling_date] => 
    [is_deleted] => 0
    [user_id] => 1
    [customer_id] => 1
    [payment_gateway_used] => 
    [gateway_charge_id] => 
    [read_only] => 
    [payment_status] => charge
    [parent_charge_id] => 
    [is_captured] => 0
    [logs] => 
    [payment_link_id] => 
)

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

### function update\_payment($payment, $payment\_id) {....}

**Usage**

```php
// update payment data based on payment update data and payment_id.
 update_payment($payment, $payment_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_payment’, ‘before_update_payment_callback_fun’, 10, 1 );

function before_update_payment_callback_fun($payment, $payment_id) {
 // code
}
```

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

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

add_filter( ‘should_update_payment’, ‘should_update_payment_callback_fun’, 10, 1 );

function should_update_payment_callback_fun($payment, $payment_id) {
    // code
}
```

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

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

add_action('pre.update.payment', 'pre_update_payment_callback_fun', 10, 1);

function pre_update_payment_callback_fun($payment, $payment_id) {
    // code
}
```

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

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

add_action('post.update.payment', 'post_update_payment_callback_fun', 10, 1);

function post_update_payment_callback_fun($payment, $payment_id) {
    // code
}
```

**Request Parameters**

Request required payment\_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>payment_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The primary key of the payment table for a specific payment.</td></tr><tr><td>description</td><td>Character</td><td></td><td>Null</td><td>The description of a specific payment.</td></tr><tr><td>is_captured</td><td>Integer</td><td></td><td>0</td><td>The is_captured for a specific charge.</td></tr><tr><td>payment_type_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The payment_type_id for a specific payment.</td></tr><tr><td>selected_gateway</td><td>Character</td><td>Yes</td><td>Null</td><td>The selected_gateway for a specific payment.</td></tr><tr><td>payment_status</td><td>Character</td><td>Yes</td><td>Null</td><td>The payment_status for a specific payment.</td></tr><tr><td>folio_id</td><td>Integer</td><td></td><td>0</td><td>The folio_id for a specific payment.</td></tr></tbody></table>

**Response**

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

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

**Supported hooks**

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

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

add_filter( ‘before_get_payments’, ‘before_get_payments_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_payments’, ‘should_get_payments_callback_fun’, 10, 1 );

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

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

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

add_action('pre.get.payments', 'pre_get_payments_callback_fun', 10, 1);

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

**hook name:**  post.get.payments\
**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.payments', 'post_get_payments_callback_fun', 10, 1);

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

**Usage**

```php
// Retrieves payment data based on a filter array.
$payment_data = get_payments($filter);
```

**Request Parameters**

parameter array filter required for payment details.

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

**Response**

```php
// $response array includes following attributes:
// $response['user_id'] : the user_id of specific payment.
// $response['booking_id'] : the booking_id for specific payment.
// $response['cvc'] : the cvc for specific payment.
// $daresponseta['selling_date'] : the selling_date for specific payment.
// $response['company_id'] : the company_id for specific payment.
// $response['amount'] : the amount for specific payment.
// $response['customer_id'] : the customer_id for specific payment.
// $response['payment_type_id'] : the payment_type_id for specific payment.
// $response['description'] : the description for specific payment.
// $response['is_captured'] : the is_captured for specific payment.
// $response['selected_gateway'] : the selected_gateway for specific payment.
// $response['capture_payment_type'] : the capture_payment_type for specific payment.
// $response['folio_id'] : the folio_id for specific payment.
// and many more attributes for table payment and join with customer , user_profiles table.

// Successfully response giving you array of payment data.

Array
(
    [0] => Array
        (
            [payment_id] => 2
            [is_captured] => 0
            [description] => good
            [customer_name] => vishal solanki
            [date_time] => 2022-01-26 17:23:03
            [booking_id] => 1
            [amount] => 0.00
            [payment_status] => charge
            [is_deleted] => 0
            [payment_type] => AMEX
            [payment_type_id] => 1
            [payment_gateway_used] => 
            [gateway_charge_id] => 
            [read_only] => 
            [selling_date] => 
            [user_name] => 
            [folio_id] => 
            [payment_link_id] => 
        )

)

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

### **function delete\_p**aymen&#x74;**(**$payment\_i&#x64;**) {.....}**

**Usage**

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

 delete_payment($payment_id);
```

**Request Parameters**

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

**Response**

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


# Access data in Extension

The supported helper functions are coming soon.


