> For the complete documentation index, see [llms.txt](https://corem.gitbook.io/corem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://corem.gitbook.io/corem/crm-billing/exports.md).

# Exports

{% hint style="danger" %}
Prior experience as a developer or basic programming skills are recommended to effectively navigate this section of the documentation.
{% endhint %}

### Billing Exports

*<mark style="color:$info;">This module provides a set of exports to interact with the billing system.</mark>*

You can use these exports from other resources with:

```lua
exports["crm-billing"]:functionName(args)
```

***

### 🔸getInvoiceById

<mark style="color:$info;">Retrieve a single invoice by its ID.</mark>

```lua
local crm_invoice = exports["crm-billing"]:getInvoiceById(crm_id)
```

#### Parameters

* `crm_id` *(number)* – Invoice ID.

#### Returns

* *(table | nil)* – Invoice object if found, otherwise `nil`.

#### Example

```lua
local crm_invoice = exports["crm-billing"]:getInvoiceById(12)
if crm_invoice then
    print(("Invoice #%s amount: %s"):format(crm_invoice.crm_id, crm_invoice.crm_amount))
end
```

***

### 🔸getPlayerInvoices

<mark style="color:$info;">Retrieve all invoices for a player.</mark>

```lua
local crm_invoices = exports["crm-billing"]:getPlayerInvoices(crm_identifier)
```

#### Parameters

* `crm_identifier` *(string)* – Character identifier.

#### Returns

* *(table | nil)* – Table of player invoices if found, otherwise `nil`.

#### Example

```lua
local crm_invoices = exports["crm-billing"]:getPlayerInvoices("RO7G58L8")
if crm_invoices then
    for _, crm_invoice in pairs(crm_invoices) do
        print(("Invoice #%s - %s$"):format(crm_invoice.crm_id, crm_invoice.crm_reason))
    end
end
```

***

### 🔸getSocietyInvoices

<mark style="color:$info;">Retrieve all invoices for a society (job).</mark>

```lua
local crm_invoices = exports["crm-billing"]:getSocietyInvoices(crm_job)
```

#### Parameters

* `crm_job` *(string)* – Job name (e.g., `"police"`, `"mechanic"`).

#### Returns

* *(table | nil)* – Table of society invoices if found, otherwise `nil`.

#### Example

```lua
local crm_invoices = exports["crm-billing"]:getSocietyInvoices("police")
if crm_invoices then
    print(("Police department has %s invoices"):format(#crm_invoices))
end
```

***

### 🔸payInvoice

<mark style="color:$info;">Pay an invoice if possible.</mark>

```lua
local crm_success = exports["crm-billing"]:payInvoice(crm_id)
```

#### Parameters

* `crm_id` *(number)* – Invoice ID.

#### Returns

* *(boolean)* – `true` if paid successfully, `false` otherwise.

#### Example

```lua
local crm_ok = exports["crm-billing"]:payInvoice(10)
if crm_ok then
    print("Invoice paid successfully!")
else
    print("Failed to pay invoice.")
end
```

***

### 🔸cancelInvoice

<mark style="color:$info;">Cancel an invoice.</mark>

```lua
local crm_success = exports["crm-billing"]:cancelInvoice(crm_id)
```

#### Parameters

* `crm_id` *(number)* – Invoice ID.

#### Returns

* *(boolean)* – `true` if invoice was cancelled, `false` if not found.

#### Example

```lua
if exports["crm-billing"]:cancelInvoice(5) then
    print("Invoice cancelled.")
else
    print("Invoice not found.")
end
```

***

### 🔸addPersonalInvoice

<mark style="color:$info;">Create a new personal invoice.</mark>

```lua
exports["crm-billing"]:addPersonalInvoice(crm_sender, crm_receiver, crm_amount, crm_reason, crm_cb)
```

#### Parameters

* `crm_sender` *(number)* – Sender server ID (must be online).
* `crm_receiver` *(number)* – Receiver server ID (must be online).
* `crm_amount` *(number)* – Invoice amount.
* `crm_reason` *(string)* – Invoice data. Example:
* `crm_cb` *(function | optional)* – Callback function returning the created invoice.

#### Example

```lua
exports["crm-billing"]:addPersonalInvoice(
    1,  -- sender
    2,  -- receiver
    crm_amount = 150,
    crm_reason = "Repair service",
    function(crm_invoice)
        print("Invoice created with ID:", crm_invoice.crm_id)
    end
)
```

***

### 🔸addSocietyInvoice

<mark style="color:$info;">Create a new society invoice.</mark>

```lua
local crm_invoice = exports["crm-billing"]:addSocietyInvoice(crm_data)
```

#### Parameters

* `crm_data` *(table)* – Invoice data. Example:

  ```lua
  {
      crm_id = "police", -- society Name
      crm_label = "Police Department", -- society Label
      crm_receiver = 1, -- Target player server id
      crm_amount = 600, -- Invoice amount
      crm_reason = "Reckless driving", -- Invoice reason
  }
  ```

#### Returns

* *(table | false)* – Invoice object if created, otherwise `false`.

#### Example

```lua
local crm_invoice = exports['crm-billing']:addSocietyInvoice({
    crm_id = "police", -- society Name
    crm_label = "Police Department", -- society Label
    crm_receiver = 1, -- Target player server id
    crm_amount = 600, -- Invoice amount
    crm_reason = "Reckless driving", -- Invoice reason
})
if crm_invoice then
    print("Invoice created with ID:", crm_invoice.crm_id)
end
```

***

### 🔸addOfflineInvoice

<mark style="color:$info;">Create a new offline invoice.</mark>

```lua
local crm_invoice exports["crm-billing"]:addOfflineInvoice(crm_data)
```

#### Parameters

* `crm_data` *(table)* – Invoice data. Example:

  ```lua
  {
      crm_type = "crm-society", -- "crm-personal" or "crm-society"
      crm_sender = {crm_id = "police", crm_label = "Police Department"},
      crm_receiver = {crm_id = "Z4VNKWZ5", crm_label = "Dev Nezaik"},
      crm_amount = 600, -- Invoice amount
      crm_reason = "Reckless driving", -- Invoice reason
  }
  ```

#### Returns

* *(table | false)* – Invoice object if created, otherwise `false`.

#### Example

```lua
-- PERSONAL INVOICE
local crm_personal_invoice = exports['crm-billing']:addOfflineInvoice({
    crm_type = "crm-personal",
    crm_sender = {crm_id = "Z4VNKWZ5", crm_label = "Dev Nezaik"},
    crm_receiver = {crm_id = "A6RFMX9", crm_label = "CoreM Dev"},
    crm_reason = "Custom Reason",
    crm_amount = 500,
})
if crm_personal_invoice then
    print("Invoice created with ID:", crm_personal_invoice.crm_id)
end

-- SOCIETY INVOICE
local crm_society_invoice = exports['crm-billing']:addOfflineInvoice({
    crm_type = "crm-society",
    crm_sender = {crm_id = "ambulance", crm_label = "EMS"},
    crm_receiver = {crm_id = "A6RFMX9", crm_label = "CoreM Dev"},
    crm_reason = "Custom Reason",
    crm_amount = 500,
})
if crm_society_invoice then
    print("Invoice created with ID:", crm_society_invoice.crm_id)
end
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://corem.gitbook.io/corem/crm-billing/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.
