> For the complete documentation index, see [llms.txt](https://docs.t1ger.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.t1ger.net/resources/t1ger-library/installation/society-account.md).

# Society Account

## Introduction

T1GER Resources supports compatibility with society accounts handled by `esx_addonaccount`, `qb-banking` or `qb-management`.

{% hint style="success" %}
You can also use a custom society-/shared account resource, however you need to implement the functionality yourself.
{% endhint %}

### Config.SocietyAccount

```lua
Config.SocietyAccount = 'esx_addonaccount' -- Set the society account system
```

Specifies the society account system in use. Update this based on your selected society system.

* **Type**: `string`
* **Options**:
  * `'esx_addonaccount'` - [ESX addon Account](https://github.com/esx-framework/esx_addonaccount)
  * `'qb-banking'` - [QB Banking](https://docs.qbcore.org/qbcore-documentation/qbcore-resources/qb-banking)
  * `'qb-management'` - [QB Management](https://docs.qbcore.org/qbcore-documentation/qbcore-resources/qb-management)
  * `'`renewed-banking`'` - [Renewed Banking](https://github.com/Renewed-Scripts/Renewed-Banking)
  * `'custom'` - You need to make your own integrations!

## Setup

This guide will help you setup society account functionality with T1GER Resources.

<details>

<summary>ESX</summary>

## `esx_addonaccount`

Setting up functionality to create shared account in runtime is very simple; all you need to is download and install latest `esx_addonaccount` from here: <https://github.com/esx-framework/esx_addonaccount>.&#x20;

*<mark style="color:red;">**Only do the following if you CANNOT download and install latest version and you are required/force to do the changes manually!!**</mark>*

If you prefer to keep your current `esx_addonaccount` resource for some weird reason, you can also manually implement the functionality.&#x20;

1. Navigate to `esx_addonaccount/server/main.lua`
2. Find this function:&#x20;

{% code fullWidth="false" %}

```lua
function GetSharedAccount(name)
```

{% endcode %}

3. Add this export code below the function

```lua
exports("GetSharedAccount", GetSharedAccount)
```

If done correct, it will look like this:\
![](/files/qHUwxFa4OOy9gmTnTtuC)

5. Now in the same file, find this function:

```lua
function AddSharedAccount(society, amount)
```

6. If the function exists, replace the whole function, if it doesn't exist, the insert - in both cases it's the same code:&#x20;

```lua
function AddSharedAccount(society, amount)
    -- society.name = job_name/society_name
    -- society.label = label for the job/account
    -- amount = if the shared account should start with x amount
    if type(society) ~= 'table' or not society?.name or not society?.label then return end

    -- check if account already exist?
    if SharedAccounts[society.name] ~= nil then return SharedAccounts[society.name] end

    -- addon account:
    local account = MySQL.insert.await('INSERT INTO `addon_account` (name, label, shared) VALUES (?, ?, ?)', {
        society.name, society.label, 1
    })
    if not account then return end

    -- if addon account inserted, insert addon account data:
    local account_data = MySQL.insert.await('INSERT INTO `addon_account_data` (account_name, money) VALUES (?, ?)', {
        society.name, (amount or 0)
    })
    if not account_data then return end
	
    -- if all data inserted successfully to sql:
    SharedAccounts[society.name] = CreateAddonAccount(society.name, nil, (amount or 0))
	return SharedAccounts[society.name]
end
exports("AddSharedAccount", AddSharedAccount)
```

6. You have succesfully set up `esx_addonaccount` to allow for automatic society account creation in runtime. All you need to do is restart the server!

</details>

<details>

<summary>QB Core</summary>

## `qb-banking`

Setting up functionality to create shared account in runtime is very simple; all you need to is download and install latest `qb-banking` from here: <https://github.com/qbcore-framework/qb-banking>.&#x20;

## `qb-management`

*<mark style="color:red;">**Only do the following if you are using**</mark><mark style="color:red;">**&#x20;**</mark><mark style="color:red;">**`qb-management`**</mark><mark style="color:red;">**:**</mark>*

1. Navigate to `qb-management/server/sv_boss.lua`
2. Scroll down all the way to the bottom and insert the following code:

```lua
-- ## T1GER Integrations:
function CreateManagementAccount(job_name, amount)
	local findRow = MySQL.query.await('SELECT * FROM management_funds WHERE type = @type AND job_name = @job_name', {
		['@job_name'] = job_name,
		['@type'] = 'boss'
	})
	if not findRow[1] then 
		MySQL.insert('INSERT INTO management_funds (job_name, amount, type) VALUES (@job_name, @amount, @type)', {
			['@job_name'] = job_name,
			['@amount'] = amount or 0,
			['@type'] = 'boss'
		})
		Accounts[job_name] = amount or 0
	end
end
exports("CreateManagementAccount", CreateManagementAccount)
```

3. Restart your server and you will now be able to create society accounts in runtime!

</details>

<details>

<summary>Qbox</summary>

## Renewed Banking

Setting up functionality to create shared account in runtime is very simple; all you need to is download and install latest `Renwed-Banking` from here: <https://github.com/Renewed-Scripts/Renewed-Banking/releases>.

1. Navigate to `Renewed-Banking/server/main.lua`
2. Go all the way to bottom of the file.
3. Paste the follow coding there: <br>

   ```lua
   local function CreateJobAccount(job, initialBalance)
       -- job(table): name(string), label(string) - job name and job label
       -- initialBalance(int): (optional) amount for account to start with
       if not job.name or not job.label then return end

       -- check if account already exist?
       if cachedAccounts[job.name] then return cachedAccounts[job.name] end

       cachedAccounts[job.name] = {
           id = job.name,
           type = locale('org'),
           name = job.label,
           frozen = 0,
           amount = initialBalance or 0,
           transactions = {},
           auth = {},
           creator = nil
       }

       MySQL.insert("INSERT INTO bank_accounts_new (id, amount, transactions, auth, isFrozen, creator) VALUES (?, ?, ?, ?, ?, NULL) ",{
           job.name, cachedAccounts[job.name].amount, json.encode(cachedAccounts[job.name].transactions), json.encode({}), cachedAccounts[job.name].frozen
       })

       return cachedAccounts[job.name]
   end
   exports('CreateJobAccount', CreateJobAccount)
   ```
4. You have succesfully set up qbox default banking resource to allow for automatic society account creation in runtime. All you need to do is restart the server!

</details>

## Functions

These are the functions used in our T1GER resources.

{% hint style="info" %}
These are also the functions you want to modify in case you want to integrate your custom society/shared account resource. Simply use `'custom'` in `Config.SocietyAccount` and integrate your export/functions in the if/else statements for `'custom'`.
{% endhint %}

### GetSharedAccount

```lua
GetSharedAccount(society)
-- parameters: society(string)
-- returns account(table or integer (based on resource return value))
```

### CreateSharedAccount

```lua
CreateSharedAccount(society, startBalance)
-- parameters: society(string), startBalance(integer)
-- returns account(table/integer)
```

### GetSharedAccountBalance

```lua
GetSharedAccountBalance(society)
-- parameters: society(string)
-- returns balance(integer)
```

### AddSharedAccountMoney

```lua
AddSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: adds m amount to shared account with society/job name
```

### RemoveSharedAccountMoney

```lua
RemoveSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: removes m amount from shared account with society/job name
```

### SetSharedAccountMoney

```lua
SetSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: sets m amount to shared account with society/job name
```
