Society Account
Instruction and guide on how to setup your society account for T1GER resources
Last updated
function GetSharedAccount(name)exports("GetSharedAccount", GetSharedAccount)function AddSharedAccount(society, amount)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)-- ## 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)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)GetSharedAccount(society)
-- parameters: society(string)
-- returns account(table or integer (based on resource return value))CreateSharedAccount(society, startBalance)
-- parameters: society(string), startBalance(integer)
-- returns account(table/integer)GetSharedAccountBalance(society)
-- parameters: society(string)
-- returns balance(integer)AddSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: adds m amount to shared account with society/job nameRemoveSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: removes m amount from shared account with society/job nameSetSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: sets m amount to shared account with society/job name