# Setting individual non-working hours for a provider account

## Formulation of the problem

In MikoPBX, in the **Call Routing** → **Night and Holiday section**, rules for routing calls outside working hours are configured. These rules apply to all calls, regardless of which company number the client called. It is necessary to set individual non-working hours for the Zadarma provider. Working hours for this provider: from 9.00 to 18.00 Moscow time.

## Solution

### Method 1

1. Go to **Modules** → **Dialplan Applications**. Create a new application (Asterisk dialplan) following the [instructions](https://docs.mikopbx.com/mikopbx/english/manual/modules/dialplan-applications). Application parameters take the form:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FnIvh2lcYaTPQfLwERrjk%2FnewDialplan.png?alt=media&#x26;token=cdb1a879-5d99-4d8c-8a25-1d11c14317c7" alt=""><figcaption><p>Parameters of the created dialplan</p></figcaption></figure>

2. The program code of the created application:

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FzV265VLab7wfe0jPOxI4%2FCodeForDialplam.png?alt=media&#x26;token=26321bab-5a9e-42d9-b0d1-48f042faf519" alt=""><figcaption><p>The program code of the application being created</p></figcaption></figure>

The **ExecIfTime** command executes the specified Asterisk application if the current time matches the specified time specification. If we receive a call from 9:00 to 18:00 on any weekday (Monday to Friday), we redirect the call ([Goto ](https://www.voip-info.org/asterisk-cmd-goto/)command) to 2003. **2003** is the IVR menu number.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FKHrUtRWEWSxUSqdrdj1T%2FIVRMenu.png?alt=media&#x26;token=ee0c936f-e3a3-4c9a-95a9-293e484a2398" alt=""><figcaption><p>Settings in the IVR menu</p></figcaption></figure>

Otherwise, the call will be routed to the employee with extension 201.

3. Set up inbound routing rules for the created provider. Go to the **Routing** → **Incoming routing** section. We direct all incoming calls to the created application

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2Fn9O99wNVDqttYn5INaVn%2FIncomingROuting.png?alt=media&#x26;token=6a8f6910-4c8c-4e26-81e4-8158bb825746" alt=""><figcaption><p>Incoming route settings</p></figcaption></figure>

### Method 2

1. Find and copy the provider ID. To do this, go to the configuration of the required provider. In our example, this is **SIP-1687941868**

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FEYIwVVgjToM9L4UQFnxr%2FProviderID.png?alt=media&#x26;token=47ea37f3-431e-4bb4-91de-cac43db56796" alt=""><figcaption><p>Provider ID</p></figcaption></figure>

2. Go to **System** -> **System file customization**

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2Fn06cIfMIqk6wJhcxD3gW%2FSystemFileCustomization.png?alt=media&#x26;token=4edfbfbf-6903-46c5-b1b5-d2a62131f59e" alt=""><figcaption><p>System file customization section</p></figcaption></figure>

3. Open the configuration file **extensions.conf** for editing.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FNuELWVzuFh5rThr08jvu%2FEditExtensions.conf.png?alt=media&#x26;token=567dc075-00ed-45a7-bc10-915ccc1dc97f" alt=""><figcaption><p>Configuration file "extensions.conf"</p></figcaption></figure>

4. Set the "**Add to end of file**" mode. In the black window, add the following code snippet:

```php
[SIP-1687941868-incoming-custom]
exten => _.!,1,NoOp(check time)
    same => n,ExecIfTime(00:00-09:00,mon-fri,*,*?Macro(playback-exit,/offload/asterisk/sounds/other/out_work_times))
    same => n,ExecIfTime(18:00-23:59,mon-fri,*,*?Macro(playback-exit,/offload/asterisk/sounds/other/out_work_times))
    same => n,return
```

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FttAsIiP63beKZJoDE0YS%2FcodeForExtensions.coinf.png?alt=media&#x26;token=0bbb2be0-d456-4bf2-8563-e5f07f87496a" alt=""><figcaption><p>Code for extensions.conf</p></figcaption></figure>

In the above code snippet, you need to make the correct context name.&#x20;

Format of the created context:

```
[PROVIDER-ID-incoming-custom]
```

* **PROVIDER-ID** is the value that you saved in the second step of this instruction. In our example, this is **SIP-1687941868.**

Working hours are from 9.00 to 18.00, therefore it is necessary to set two intervals for non-working hours: 00:00-09:00 and 18:00-23:59.

### ExecIfTime command

Let's analyze the **ExecIfTime** command in more detail. This command executes the specified Asterisk application if the current time matches the specified time specification. In our case, the command plays a sound file located in the **/offload/asterisk/sounds/other/out\_work\_times** directory in MikoPBX.

Command syntax:

```php
ExecIfTime(times,weekdays,mdays,months?appname[(appargs)])
```

* **times** - Time ranges in 24-hour format
* **weekdays -** Days of the week (mon, tue, wed, thu, fri, sat, sun)
* **mdays** - Days of the month (1-31)
* **months** - Months (Jan, Feb, Mar, apr, etc.)
* **appname\[(appargs)]** - Asterisk command specifying the call parameters

In our example, the time range, the range of days of the week are indicated. Instead of specifying days months and months, \* are entered. This symbol means "for all other cases".

```php
ExecIfTime(00:00-08:00,mon-fri,*,*?Macro(playback-exit,/offload/asterisk/sounds/other/out_work_times))
```
