# Billing System

> The script includes a simple yet highly functional billing system, allowing businesses to send invoices to clients. Clients can choose their preferred payment method and decide when to pay. It's important to note that expired invoices will be automatically charged whenever the player receives money in their bank account.

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2FUmMbLSftzRozFmOQAbac%2Fimage.png?alt=media&#x26;token=dae30fe0-71d0-4602-958c-eddbd7ad5d26" alt=""><figcaption></figcaption></figure>

### Available Money Accounts

> Players can choose a money account to use for paying their invoices, you can find the list in `config/ billing.lua > Config.AvailableAccounts`&#x20;
>
> If using the option Cash with ESX Framework, make sure to change the value to "money".

### Adding new Products/Services to the list.

> By default, the products and services listed under "Product" are pulled from the `av_items` table, using the items created by the business. However, if you want to include custom products or services—such as a list of fines for the Police job or medical treatments for the Ambulance job—you can easily add them manually as follows:

* Go to `business/client/editable/billing.lua`, here you will find a function named **getBillingItems(business)**.
* This function receives the job name as argument, we will use it to retrieve our custom list.
* For this _**EXAMPLE**_ we are gonna show a list of custom fines for police job, we will pull the data from **ps-mdt.** _And again, this is just an example, is on you to retrieve the data from your own script and process it._

#### Example using ps-mdt

* ps-mdt doesn’t provide a native export to retrieve the list of fines, as all the data is stored directly in its config. To make it accessible, we need to create a custom export ourselves. To do this, open `ps-mdt/client/main.lua` and add the following code at the very end of the file:

```lua
exports("getFines", function()
    return Config and Config.PenalCode or false
end)
```

* Now we have an export we can use to retrieve the needed data, go back to `business/edutable/billing.lua` and add the export.

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2F2JZn8Qt6iXpfHFHl95BK%2Fimage.png?alt=media&#x26;token=ced4b622-7d13-48db-935b-6000196ac310" alt=""><figcaption></figcaption></figure>

* We now have access to the list of fines in our code — all that’s left is to iterate through it to extract the data we need:

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2FAncItjbGQ1MkstBJtPst%2Fimage.png?alt=media&#x26;token=bad5c52e-34bf-4889-bbbd-5d8af72e6a3b" alt=""><figcaption></figcaption></figure>

* So far, we can access all fine data without any issues. However, the `items` table requires the following structure:
  * **item**: `string` (This is the product/service title)
  * **price**:`number`
* This is how our final code will look like (for this EXAMPLE):

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2FGxh19ygpC4MOwvZ29Pb6%2Fimage.png?alt=media&#x26;token=ed1c5443-5889-4b31-a5d9-07b4ba1789b2" alt=""><figcaption></figcaption></figure>

* Now you can go to Billing tab > Send Bill and see the full list of fines :)

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2FZ8aNNgEvP07d6pDkkzk9%2Fimage.png?alt=media&#x26;token=da8ccb56-c744-4214-9c19-d00810ee9ab5" alt=""><figcaption></figcaption></figure>

* Make sure to use the correct Server ID from the player u want to receive the invoice, if the player is close to you (3 meters) you can click the player icon and the script will add the server id to the field automatically.
* Once the player accepts the invoice, it will show in your panel.

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2FTD5vmOn9EXifzm0Pvaj8%2Fimage.png?alt=media&#x26;token=9f851a2e-0a0f-4394-9b82-ca527493f19b" alt=""><figcaption></figcaption></figure>

* Players can access their invoices by using the command `/billing`

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2FznVyyJicazlRj0Sfq86j%2Fimage.png?alt=media&#x26;token=eb86787e-8ea3-45c9-a31f-e02e14f52632" alt=""><figcaption></figcaption></figure>

