# Facility Billing

Facility billing lets facility staff create and manage medical invoices from the facility panel. Invoices are stored by `0r-ambulancejob` first, so the feature can work even when you do not use a separate billing/payment resource.

Custom external billing calls are isolated in `modules/billing/server.lua`. By default, the bridge detects:

* `okokBilling`
* `qb-phone` for QBCore/Qbox servers

If no supported billing resource is started, invoices stay manual and staff can mark them paid from the facility panel after role-play payment.

## Configuration

Billing settings are inside `config/facility.lua`:

```lua
Config.facility.runtime.billing = {
    enabled = true,
    depositPaidInvoicesToFacilityAccount = true,
    presets = {
        { key = "revive",     label = "facility_billing_preset_revive",     amount = 750 },
        { key = "treatment",  label = "facility_billing_preset_treatment",  amount = 500 },
        { key = "surgery",    label = "facility_billing_preset_surgery",    amount = 2500 },
        { key = "scan",       label = "facility_billing_preset_scan",       amount = 900 },
        { key = "blood_test", label = "facility_billing_preset_blood_test", amount = 350 },
    },
}
```

* `enabled`: enables or disables facility invoice creation.
* `depositPaidInvoicesToFacilityAccount`: when `true`, paid invoices are deposited into the facility account.
* `presets`: quick invoice options shown in the facility billing UI.

## Database

Billing uses the `0resmon_ambulance_facility_invoices` table.

{% content-ref url="/pages/arRnnfdsNTlR4P4iiumo" %}
[Database SQL](/0resmon/0r-resources/0r-ambulancejob/setup-and-database/database.sql.md)
{% endcontent-ref %}

## Custom Payment Sync

When a custom billing resource confirms payment, call this from server-side code:

```lua
TriggerEvent("0r_ambulancejob:server:billingPaid", {
    invoice_id = 12,
    -- or external_invoice_id = "custom-bridge-id"
})
```

Client-triggered calls to this event are ignored.

## Server Exports

```lua
exports["0r-ambulancejob"]:CreateFacilityInvoice(payload)
exports["0r-ambulancejob"]:MarkFacilityInvoicePaid(invoiceId, options)
exports["0r-ambulancejob"]:CancelFacilityInvoice(invoiceId, reason)
exports["0r-ambulancejob"]:GetFacilityInvoices(facilityId, filters)
exports["0r-ambulancejob"]:GetPlayerUnpaidFacilityInvoices(identifier)
```

`CreateFacilityInvoice` accepts:

```lua
{
    facility_id = 1,
    patient_source = 23,
    amount = 750,
    preset_key = "revive",
    reason = "Revive"
}
```

You can also pass `patient_identifier` and `patient_name` instead of `patient_source` when the patient is not online.


---

# 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-ambulancejob/billing.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.
