# Server Exports

## 0R SmartTab — All Exports Reference

Complete reference for every export available in **0r-smarttab**, organized by side and category.

```lua
-- Usage from any other resource
exports['0r-smarttab']:ExportName(...)
```

***

### Table of Contents

**Server-Side Exports**

| #  | Export                      | Category       |
| -- | --------------------------- | -------------- |
| 1  | IsPlayerTabletOpen          | Tablet State   |
| 2  | GetPlayerByTabletSerial     | Tablet State   |
| 3  | IsAppEnabled                | App Management |
| 4  | GetAppJobRequirements       | App Management |
| 5  | SendNotification            | Notifications  |
| 6  | SetAppBadge                 | Notifications  |
| 7  | GetPlayerInvoiceList        | Billing        |
| 8  | GetPlayerInvoiceCount       | Billing        |
| 9  | GetPlayerUnpaidInvoiceCount | Billing        |
| 10 | GetPlayerTotalDebt          | Billing        |
| 11 | CheckUnpaidBills            | Billing        |
| 12 | CreateInvoice               | Billing        |
| 13 | IsPlayerOnDuty              | MDT / Police   |
| 14 | CheckHasWarrant             | MDT / Police   |
| 15 | SendJail                    | Prison         |

**Client-Side Exports**

| #  | Export                      | Category       |
| -- | --------------------------- | -------------- |
| 16 | IsTabletOpen                | Tablet State   |
| 17 | OpenTabletWithApp           | Tablet Control |
| 18 | SendNotification            | Notifications  |
| 19 | SetAppBadge                 | Notifications  |
| 20 | GetPlayerByTabletSerial     | Tablet State   |
| 21 | GetPlayerInvoiceList        | Billing        |
| 22 | GetPlayerInvoiceCount       | Billing        |
| 23 | GetPlayerUnpaidInvoiceCount | Billing        |
| 24 | GetPlayerTotalDebt          | Billing        |
| 25 | GetMugShotBase64            | Utility        |

***

## Server-Side Exports

> All of these run in **server scripts** only.

***

### Tablet State

#### 1. IsPlayerTabletOpen

Check whether a player currently has their tablet open.

```lua
local isOpen = exports['0r-smarttab']:IsPlayerTabletOpen(source)
```

| Parameter | Type   | Description      |
| --------- | ------ | ---------------- |
| `source`  | number | Player server ID |

| Returns | Type    |
| ------- | ------- |
| is open | boolean |

```lua
if exports['0r-smarttab']:IsPlayerTabletOpen(5) then
    print("Player 5 has their tablet open")
end
```

***

#### 2. GetPlayerByTabletSerial

Find the owner of a tablet by its serial number. The owner must be **online**.

```lua
local source, citizenId, name = exports['0r-smarttab']:GetPlayerByTabletSerial(serial)
```

| Parameter | Type   | Description                        |
| --------- | ------ | ---------------------------------- |
| `serial`  | string | Tablet serial (e.g. `"0R-A1B2C3"`) |

| Returns   | Type          | Description           |
| --------- | ------------- | --------------------- |
| source    | number \| nil | Player server ID      |
| citizenId | string \| nil | Owner citizen ID      |
| name      | string \| nil | Player character name |

```lua
local src, cid, name = exports['0r-smarttab']:GetPlayerByTabletSerial("0R-A1B2C3")
if src then
    print(name .. " owns this tablet (server id: " .. src .. ")")
end
```

***

### App Management

#### 3. IsAppEnabled

Check if a specific app is enabled in `server/apps.json`.

```lua
local enabled = exports['0r-smarttab']:IsAppEnabled(appId)
```

| Parameter | Type   | Description                                |
| --------- | ------ | ------------------------------------------ |
| `appId`   | string | App ID (e.g. `"app-mail"`, `"app-police"`) |

| Returns | Type    |
| ------- | ------- |
| enabled | boolean |

```lua
if exports['0r-smarttab']:IsAppEnabled("app-mail") then
    print("Mail app is active")
end
```

***

#### 4. GetAppJobRequirements

Get all job-restricted apps and which jobs they require.

```lua
local requirements = exports['0r-smarttab']:GetAppJobRequirements()
```

| Parameters | — |
| ---------- | - |
| none       |   |

| Returns      | Type  | Description                        |
| ------------ | ----- | ---------------------------------- |
| requirements | table | `{ [appId] = { "job1", "job2" } }` |

```lua
local reqs = exports['0r-smarttab']:GetAppJobRequirements()
-- reqs["app-police"] = { "police", "sheriff" }
-- reqs["app-ems"]    = { "ambulance" }
```

***

### Notifications

#### 5. SendNotification (Server)

Send a notification to a player's tablet from the server. Shows immediately if the tablet is open, otherwise queues as a peek notification.

```lua
exports['0r-smarttab']:SendNotification(targetSrc, data)
```

| Parameter   | Type   | Description             |
| ----------- | ------ | ----------------------- |
| `targetSrc` | number | Target player server ID |
| `data`      | table  | Notification payload    |

**Payload fields:**

| Field      | Type   | Required | Description                   |
| ---------- | ------ | -------- | ----------------------------- |
| `title`    | string | yes      | Title                         |
| `message`  | string | yes      | Body text                     |
| `app`      | string | no       | App ID for icon               |
| `icon`     | string | no       | Custom icon                   |
| `duration` | number | no       | Duration in ms (default 4000) |

```lua
exports['0r-smarttab']:SendNotification(source, {
    title    = "Delivery",
    message  = "New package available for pickup.",
    app      = "app-mail",
    duration = 5000
})
```

***

#### 6. SetAppBadge (Server)

Set a badge counter on an app icon for a player (from server).

```lua
exports['0r-smarttab']:SetAppBadge(targetSrc, appId, count)
```

| Parameter   | Type   | Description               |
| ----------- | ------ | ------------------------- |
| `targetSrc` | number | Target player server ID   |
| `appId`     | string | App ID                    |
| `count`     | number | Badge number (0 to clear) |

```lua
exports['0r-smarttab']:SetAppBadge(source, "app-mail", 3)
```

***

### Billing

#### 7. GetPlayerInvoiceList

Get the full invoice list for a player (paid + unpaid). Reads from `phone_invoices` (QBCore/Qbox) or `billing` (ESX).

```lua
local invoices = exports['0r-smarttab']:GetPlayerInvoiceList(source)
```

| Parameter | Type   | Description      |
| --------- | ------ | ---------------- |
| `source`  | number | Player server ID |

| Returns  | Type         |
| -------- | ------------ |
| invoices | table \| nil |

**Each invoice object:**

| Field            | Type          | Description                         |
| ---------------- | ------------- | ----------------------------------- |
| `id`             | number/string | Invoice ID                          |
| `title`          | string        | Label                               |
| `sender`         | string        | Sender name / society               |
| `amount`         | number        | Total (with interest)               |
| `baseAmount`     | number        | Original amount                     |
| `interestAmount` | number        | Accrued interest                    |
| `status`         | string        | `"unpaid"` / `"overdue"` / `"paid"` |
| `dueDate`        | string        | Due date                            |
| `daysOverdue`    | number        | Days past due                       |

```lua
local list = exports['0r-smarttab']:GetPlayerInvoiceList(source)
if list then
    for _, inv in ipairs(list) do
        print(inv.title, inv.amount, inv.status)
    end
end
```

***

#### 8. GetPlayerInvoiceCount

Total number of invoices (paid + unpaid).

```lua
local count = exports['0r-smarttab']:GetPlayerInvoiceCount(source)
```

| Parameter | Type   |
| --------- | ------ |
| `source`  | number |

| Returns | Type   |
| ------- | ------ |
| count   | number |

***

#### 9. GetPlayerUnpaidInvoiceCount

Number of unpaid + overdue invoices only.

```lua
local unpaid = exports['0r-smarttab']:GetPlayerUnpaidInvoiceCount(source)
```

| Parameter | Type   |
| --------- | ------ |
| `source`  | number |

| Returns | Type   |
| ------- | ------ |
| count   | number |

***

#### 10. GetPlayerTotalDebt

Total debt across all unpaid/overdue invoices (interest included).

```lua
local debt = exports['0r-smarttab']:GetPlayerTotalDebt(source)
```

| Parameter | Type   |
| --------- | ------ |
| `source`  | number |

| Returns   | Type   |
| --------- | ------ |
| totalDebt | number |

***

#### 11. CheckUnpaidBills

Quick boolean check + count for unpaid bills.

```lua
local hasUnpaid, count = exports['0r-smarttab']:CheckUnpaidBills(source)
```

| Parameter | Type   |
| --------- | ------ |
| `source`  | number |

| Returns   | Type    | Description                      |
| --------- | ------- | -------------------------------- |
| hasUnpaid | boolean | `true` if any unpaid bills exist |
| count     | number  | Number of unpaid bills           |

```lua
local hasUnpaid, count = exports['0r-smarttab']:CheckUnpaidBills(source)
if hasUnpaid then
    print("Player owes " .. count .. " bill(s)")
end
```

***

#### 12. CreateInvoice

Create a new invoice for a target citizen. Officer info is auto-resolved from `source`. Supports QBCore/Qbox (`phone_invoices`) and ESX (`billing`).

```lua
exports['0r-smarttab']:CreateInvoice(source, targetId, amount, reason)
```

| Parameter  | Type   | Description                    |
| ---------- | ------ | ------------------------------ |
| `source`   | number | Officer / sender server ID     |
| `targetId` | string | Target citizen ID / identifier |
| `amount`   | number | Amount (> 0)                   |
| `reason`   | string | Invoice label / reason         |

Returns nothing (async).

```lua
exports['0r-smarttab']:CreateInvoice(source, "ABC12345", 5000, "Speeding violation")
```

***

### MDT / Police

#### 13. IsPlayerOnDuty

Check if a player is currently on duty (job `onduty` flag).

```lua
local onDuty = exports['0r-smarttab']:IsPlayerOnDuty(source)
```

| Parameter | Type   |
| --------- | ------ |
| `source`  | number |

| Returns | Type    |
| ------- | ------- |
| onDuty  | boolean |

```lua
if exports['0r-smarttab']:IsPlayerOnDuty(source) then
    print("Officer is on duty")
end
```

***

#### 14. CheckHasWarrant

Check if a citizen has active warrants in the MDT.

```lua
local hasWarrant, count, records = exports['0r-smarttab']:CheckHasWarrant(citizenid)
```

| Parameter   | Type   |
| ----------- | ------ |
| `citizenid` | string |

| Returns    | Type    | Description              |
| ---------- | ------- | ------------------------ |
| hasWarrant | boolean | `true` if warrants exist |
| count      | number  | Number of warrants       |
| records    | table   | Array of warrant rows    |

```lua
local has, count, recs = exports['0r-smarttab']:CheckHasWarrant("ABC12345")
if has then
    print(count .. " active warrant(s)")
end
```

***

### Prison

#### 15. SendJail

Send a player to jail. Auto-detects the prison resource (`xt-prison`, `qb-prison`, `qb-policejob`, `esx_policejob`).

```lua
exports['0r-smarttab']:SendJail(source, targetId, jailTime)
```

| Parameter  | Type   | Description                    |
| ---------- | ------ | ------------------------------ |
| `source`   | number | Officer server ID              |
| `targetId` | string | Target citizen ID / identifier |
| `jailTime` | number | Time in months/minutes (> 0)   |

Returns nothing. Target must be **online**.

```lua
exports['0r-smarttab']:SendJail(source, "ABC12345", 30)
```

***

## Client-Side Exports

> All of these run in **client scripts** only and affect the local player.

***

### Tablet State & Control

#### 16. IsTabletOpen

Check if the local player's tablet is currently open.

```lua
local isOpen = exports['0r-smarttab']:IsTabletOpen()
```

| Parameters | — |
| ---------- | - |
| none       |   |

| Returns | Type    |
| ------- | ------- |
| isOpen  | boolean |

```lua
if exports['0r-smarttab']:IsTabletOpen() then
    print("My tablet is open")
end
```

***

#### 17. OpenTabletWithApp

Open the tablet and jump directly to a specific app. The player must have a tablet item in their inventory.

```lua
exports['0r-smarttab']:OpenTabletWithApp(appId)
```

| Parameter | Type   | Description                       |
| --------- | ------ | --------------------------------- |
| `appId`   | string | App ID or action from `apps.json` |

Returns nothing.

```lua
-- Open directly to the Mail app
exports['0r-smarttab']:OpenTabletWithApp("app-mail")

-- Open directly to a custom app
exports['0r-smarttab']:OpenTabletWithApp("customapp")

-- Open directly to Settings
exports['0r-smarttab']:OpenTabletWithApp("settings")

-- Open directly to the Police MDT
exports['0r-smarttab']:OpenTabletWithApp("app-police")
```

***

### Notifications

#### 18. SendNotification (Client)

Send a notification to the local player's tablet. If open, appears immediately; if closed, queues and shows a peek animation.

```lua
exports['0r-smarttab']:SendNotification(data)
```

| Parameter | Type  | Description                                          |
| --------- | ----- | ---------------------------------------------------- |
| `data`    | table | Notification payload (same fields as server version) |

```lua
exports['0r-smarttab']:SendNotification({
    title   = "Alert",
    message = "Something happened nearby.",
    app     = "app-police",
    duration = 4000
})
```

***

#### 19. SetAppBadge (Client)

Set a badge counter on an app icon (local player only).

```lua
exports['0r-smarttab']:SetAppBadge(appId, count)
```

| Parameter | Type   | Description               |
| --------- | ------ | ------------------------- |
| `appId`   | string | App ID                    |
| `count`   | number | Badge number (0 to clear) |

```lua
exports['0r-smarttab']:SetAppBadge("app-mail", 5)
```

***

### Tablet Lookup (Async)

#### 20. GetPlayerByTabletSerial (Client)

Look up a tablet's owner by serial number. Queries the server asynchronously.

```lua
exports['0r-smarttab']:GetPlayerByTabletSerial(serial, callback)
```

| Parameter  | Type     | Description                            |
| ---------- | -------- | -------------------------------------- |
| `serial`   | string   | Tablet serial number                   |
| `callback` | function | `function(result)` — result is a table |

**Result table:**

| Field       | Type          |
| ----------- | ------------- |
| `source`    | number \| nil |
| `citizenid` | string \| nil |
| `name`      | string \| nil |

```lua
exports['0r-smarttab']:GetPlayerByTabletSerial("0R-A1B2C3", function(result)
    if result.source then
        print(result.name .. " — server id: " .. result.source)
    end
end)
```

***

### Billing (Async)

All client billing exports query the server and return data via callback.

#### 21. GetPlayerInvoiceList (Client)

```lua
exports['0r-smarttab']:GetPlayerInvoiceList(function(list)
    for _, inv in ipairs(list) do
        print(inv.title, inv.amount, inv.status)
    end
end)
```

| Parameter  | Type           |
| ---------- | -------------- |
| `callback` | function(list) |

***

#### 22. GetPlayerInvoiceCount (Client)

```lua
exports['0r-smarttab']:GetPlayerInvoiceCount(function(count)
    print("Total invoices: " .. count)
end)
```

| Parameter  | Type            |
| ---------- | --------------- |
| `callback` | function(count) |

***

#### 23. GetPlayerUnpaidInvoiceCount (Client)

```lua
exports['0r-smarttab']:GetPlayerUnpaidInvoiceCount(function(count)
    print("Unpaid: " .. count)
end)
```

| Parameter  | Type            |
| ---------- | --------------- |
| `callback` | function(count) |

***

#### 24. GetPlayerTotalDebt (Client)

```lua
exports['0r-smarttab']:GetPlayerTotalDebt(function(debt)
    print("Total debt: $" .. debt)
end)
```

| Parameter  | Type                |
| ---------- | ------------------- |
| `callback` | function(totalDebt) |

***

### Utility

#### 25. GetMugShotBase64

Capture a ped's headshot as a texture dictionary string (for NUI/UI display).

```lua
local txd = exports['0r-smarttab']:GetMugShotBase64(ped, transparent)
```

| Parameter     | Type    | Description                |
| ------------- | ------- | -------------------------- |
| `ped`         | number  | Ped handle                 |
| `transparent` | boolean | Use transparent background |

| Returns | Type   | Description                                   |
| ------- | ------ | --------------------------------------------- |
| txd     | string | Texture dictionary name (`"none"` on failure) |

```lua
local ped = PlayerPedId()
local headshot = exports['0r-smarttab']:GetMugShotBase64(ped, true)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.0resmon.org/0resmon/0r-resources/0r-smarttab/exports/server-exports.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
