# Database Reference

Database Reference — moh-billing

moh-billing uses two database tables. Both are created by `install.sql`. Table names can be changed in `config.lua` if needed.

### moh\_billing

Stores every invoice, past and present.

```
CREATE TABLE IF NOT EXISTS `moh_billing` (
    `id`                  INT(11)      NOT NULL AUTO_INCREMENT,
    `receiver_identifier` VARCHAR(60)  NOT NULL,
    `receiver_name`       VARCHAR(80)  NOT NULL,
    `author_identifier`   VARCHAR(60)  NOT NULL,
    `author_name`         VARCHAR(80)  NOT NULL,
    `society`             VARCHAR(60)  NOT NULL,
    `society_name`        VARCHAR(80)  NOT NULL,
    `item`                VARCHAR(255) NOT NULL,
    `invoice_value`       FLOAT        NOT NULL DEFAULT 0,
    `status`              VARCHAR(20)  NOT NULL DEFAULT 'unpaid',
    `notes`               TEXT,
    `sent_date`           DATETIME     DEFAULT NULL,
    `paid_date`           DATETIME     DEFAULT NULL,
    `limit_pay_date`      DATETIME     DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

#### Column reference

| Column                | Type                | Description                                                                                              |
| --------------------- | ------------------- | -------------------------------------------------------------------------------------------------------- |
| `id`                  | INT AUTO\_INCREMENT | Unique invoice identifier shown in the UI and logs.                                                      |
| `receiver_identifier` | VARCHAR(60)         | QBCore `citizenid` / ESX `identifier` of the player who must pay.                                        |
| `receiver_name`       | VARCHAR(80)         | Full name of the payer at the time the invoice was created.                                              |
| `author_identifier`   | VARCHAR(60)         | Identifier of the player who created the invoice.                                                        |
| `author_name`         | VARCHAR(80)         | Full name of the invoice creator.                                                                        |
| `society`             | VARCHAR(60)         | Job name of the creating society (e.g. `police`).                                                        |
| `society_name`        | VARCHAR(80)         | Display label of the society (e.g. `Police Department`).                                                 |
| `item`                | VARCHAR(255)        | Reason / description entered when the invoice was created.                                               |
| `invoice_value`       | FLOAT               | Amount due in dollars. Always stored as a positive number; rounded up to the nearest integer on payment. |
| `status`              | VARCHAR(20)         | `unpaid` or `paid`. The UI only loads `unpaid` invoices.                                                 |
| `notes`               | TEXT                | Optional notes field (reserved for future UI use; stored but not currently displayed).                   |
| `sent_date`           | DATETIME            | Timestamp when the invoice was created (`NOW()`).                                                        |
| `paid_date`           | DATETIME            | Timestamp when the invoice was paid. `NULL` until payment.                                               |
| `limit_pay_date`      | DATETIME            | Payment deadline. Only set when `Config.LimitDate = true`. `NULL` otherwise.                             |

#### Useful queries

```
-- All unpaid invoices for a specific player
SELECT * FROM moh_billing
WHERE receiver_identifier = 'QBZ12345'
  AND status = 'unpaid'
ORDER BY id DESC;
-- All invoices created by a specific society
SELECT * FROM moh_billing
WHERE society = 'police'
ORDER BY sent_date DESC;
-- Total collected by a society (paid only)
SELECT society_name, SUM(invoice_value) AS total
FROM moh_billing
WHERE status = 'paid'
GROUP BY society_name;
-- Overdue invoices (past limit_pay_date, still unpaid)
SELECT * FROM moh_billing
WHERE status = 'unpaid'
AND limit_pay_date IS NOT NULL
AND limit_pay_date < NOW();
```

***

### management\_funds

Stores the current fund balance for each society. One row per job. Compatible with qb-management and other QBCore boss-menu resources.

```
CREATE TABLE IF NOT EXISTS `management_funds` (
    `id`        INT(11)      NOT NULL AUTO_INCREMENT,
    `job_name`  VARCHAR(60)  NOT NULL,
    `amount`    FLOAT        NOT NULL DEFAULT 0,
    `type`      VARCHAR(20)  NOT NULL DEFAULT 'boss',
    PRIMARY KEY (`id`),
    UNIQUE KEY `job_name` (`job_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

#### Column reference

| Column     | Description                                                                  |
| ---------- | ---------------------------------------------------------------------------- |
| `id`       | Auto-increment primary key.                                                  |
| `job_name` | Job identifier string (e.g. `police`). Unique — one row per society.         |
| `amount`   | Current fund balance in dollars.                                             |
| `type`     | Always `'boss'` in this resource. Kept for compatibility with qb-management. |

#### Useful queries

```
-- Check balance of a specific society
SELECT amount FROM management_funds WHERE job_name = 'police';
-- All society balances sorted by richest
SELECT job_name, amount FROM management_funds ORDER BY amount DESC;
-- Manually set a balance (server maintenance)
UPDATE management_funds SET amount = 10000 WHERE job_name = 'police';
```


---

# 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://mohssins.gitbook.io/mohscriptsdocs/moh-billing/database-reference.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.
