Skip to main content

gksphone

gksphone​

For gksphone to switch over from default esx_billing to bcs_companymanager billing. Replace the code under if not Config.okokBilling until else of the if.

ESX​

gksphone/serverapi/billing.lua
ESX.RegisterServerCallback('gksphone:getbilling', function(source, cb)
local e = ESX.GetPlayerFromId(source)
MySQL.Async.fetchAll('SELECT * FROM billings WHERE identifier = @identifier AND `status` = "unpaid"',
{ ["@identifier"] = e.identifier }, function(result)
local billingg = {}
for i = 1, #result, 1 do
local jobName = "None"
jobName = result[i].company
table.insert(billingg,
{ id = result[i].id, label = result[i].description, sender = jobName, target = result[i].biller_id,
amount = result[i].price })
end
cb(billingg)
end)
end)

ESX.RegisterServerCallback('gksphone:server:bfaturalist', function(source, cb)
local e = ESX.GetPlayerFromId(source)
MySQL.Async.fetchAll('SELECT * FROM billings WHERE company = @target AND `status` = "unpaid"',
{ ["@target"] = e.getJob().name }, function(result)
local billingg = {}
for i = 1, #result, 1 do
local senderg = result[i].biller
local alici = GetUserData(result[i].identifier)

if senderg == nil then
senderg = "Unknown"
end
if alici == nil then
alici = "Unknown"
end

table.insert(billingg,
{ id = result[i].id, label = result[i].description, sender = senderg, target = result[i].biller_id,
amount = result[i].price, iden = alici })
end
cb(billingg)
end)
end)

RegisterServerEvent("gksphone:faturapayBill")
AddEventHandler("gksphone:faturapayBill", function(id)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)

MySQL.Async.fetchAll('SELECT * FROM billings WHERE id = @id', {
['@id'] = id
}, function(data)
local xTarget = ESX.GetPlayerFromIdentifier(data[1].biller_id)
local target = data[1].biller_id
local amount = data[1].price

if not string.match(target, 'society_') then
if xTarget ~= nil then
if amount ~= nil then
if xPlayer.getAccount('bank').money >= amount then
exports.bcs_companymanager:PayBill(id, amount, data[1].company, target, xPlayer)
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_paid') .. amount,
img = '/html/static/img/icons/logo.png' })
TriggerClientEvent('gksphone:notifi', xTarget.source,
{ title = _U('billing_title'), message = _U('bill_paid') .. amount,
img = '/html/static/img/icons/logo.png' })
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_nocash') .. amount,
img = '/html/static/img/icons/logo.png' })
end
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_nocash') .. amount,
img = '/html/static/img/icons/logo.png' })
end
end
else
TriggerEvent(Config.EsxAddonAcc, target, function(account)
if xPlayer.getAccount("bank").money >= amount then
MySQL.Async.execute('UPDATE billings SET `status`="paid" WHERE id = @id', {
['@id'] = id
}, function(rowsChanged)
xPlayer.removeAccountMoney('bank', amount)
account.addMoney(amount)


TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_paid') .. amount,
img = '/html/static/img/icons/logo.png' })

local jobName = target:gsub("society_", "")
local test = GetSource(jobName)

for i = 1, #test, 1 do
TriggerClientEvent('gksphone:notifi', test[i].id,
{ title = _U('billing_title'), message = _U('bill_paid') .. amount,
img = '/html/static/img/icons/logo.png' })
end
end)
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_nocash') .. amount,
img = '/html/static/img/icons/logo.png' })
end
end)
end
end)
TriggerClientEvent('updatebilling', src, id)
end)

RegisterServerEvent("gksphone:business:delbill")
AddEventHandler("gksphone:business:delbill", function(id)
local src = source
local e = ESX.GetPlayerFromId(src)
local gradejob = e.getJob().grade

if gradejob >= Config.JobGrade then
MySQL.Async.fetchAll('SELECT * FROM billings WHERE biller_id = @target AND id = @id', {
['@target'] = 'society_' .. e.getJob().name,
['@id'] = id
}, function(data)
if data then
MySQL.Async.fetchAll("DELETE FROM billings WHERE id = @id",
{
['@id'] = data[1].id
})
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('bussines_title'), message = _U('buss_delbill'),
img = '/html/static/img/icons/business.png' })
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('bussines_title'), message = _U('buss_nodelbill'),
img = '/html/static/img/icons/business.png' })
end
end)
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('bussines_title'), message = _U('buss_gradenot'), img = '/html/static/img/icons/business.png' })
end
end)

RegisterServerEvent("gksphone:server:faturapayBill")
AddEventHandler("gksphone:server:faturapayBill", function()
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
MySQL.Async.fetchAll('SELECT * FROM billings WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(data)
for i = 1, #data, 1 do
Wait(500)
local xTarget = ESX.GetPlayerFromIdentifier(data[i].biller_id)
local target = data[i].biller_id

if not string.match(target, 'society_') then
if xTarget ~= nil then
if data[i].price ~= nil then
if xPlayer.getAccount('bank').money >= data[i].price then
exports.bcs_companymanager:PayBill(data[i].id, data[i].price, data[i].company, target,
xPlayer)


TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_paid') .. data[i].price,
img = '/html/static/img/icons/logo.png' })
TriggerClientEvent('gksphone:notifi', xTarget.source,
{ title = _U('billing_title'), message = _U('bill_paid') .. data[i].price,
img = '/html/static/img/icons/logo.png' })

MySQL.Async.execute(
"INSERT INTO gksphone_bank_transfer (type, identifier, price, name) VALUES (@type, @identifier, @price, @name)",
{
["@type"] = 1,
["@identifier"] = xPlayer.identifier,
["@price"] = data[i].price,
["@name"] = _U('bill_billing') .. data[i].price
})
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_nocash') .. data[i].price,
img = '/html/static/img/icons/logo.png' })
end
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_nocash') .. data[i].price,
img = '/html/static/img/icons/logo.png' })
break
end
end
else
TriggerEvent(Config.EsxAddonAcc, target, function(account)
if xPlayer.getAccount("bank").money >= data[i].price then
MySQL.Async.execute('UPDATE billing SET `status`="paid" WHERE id = @id', {
['@id'] = data[i].id
}, function(rowsChanged)
xPlayer.removeAccountMoney('bank', data[i].price)
account.addMoney(data[i].price)

TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_paid') .. data[i].price,
img = '/html/static/img/icons/logo.png' })

local jobName = target:gsub("society_", "")
local test = GetSource(jobName)

for i = 1, #test, 1 do
TriggerClientEvent('gksphone:notifi', test[i].id,
{ title = _U('billing_title'), message = _U('bill_paid') .. data[i].price,
img = '/html/static/img/icons/logo.png' })
end
end)
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_nocash') .. data[i].price,
img = '/html/static/img/icons/logo.png' })
end
end)
end
end

TriggerClientEvent('updatebilling', src, src)
end)
end)

QB Core​

gksphone/server/serverAPI/billing.lua
-- BILLING --
Config.Core.Functions.CreateCallback('gksphone:getbilling', function(source, cb)
local e = Config.Core.Functions.GetPlayer(source)
MySQL.Async.fetchAll('SELECT * FROM billings WHERE identifier = @identifier AND `status` = "unpaid"',
{ ["@identifier"] = e.PlayerData.citizenid }, function(result)
local billingg = {}
for i = 1, #result, 1 do
local jobName = "None"
jobName = result[i].company
table.insert(billingg,
{
id = result[i].id,
sender = jobName,
sendercitizenid = result[i].biller_id,
label = result[i].description,
amount = result[i].price
})
end
cb(billingg)
end)
end)

RegisterServerEvent("gksphone:faturapayBill")
AddEventHandler("gksphone:faturapayBill", function(id)
local src = source
local Ply = Config.Core.Functions.GetPlayer(src)

MySQL.Async.fetchAll('SELECT * FROM billings WHERE id = @id', {
['@id'] = id.id
}, function(data)
if Ply.PlayerData.money.bank >= data[1].price then
local target = data[1].biller_id
local amount = data[1].price
if Config.UseBillingCommission then
local SenderPly = Config.Core.Functions.GetPlayerByCitizenId(data[1].biller_id)
if SenderPly ~= nil then
if Config.BillingCommissions[data[1].company] then
local commission = Round(data[1].price * Config.BillingCommissions[data[1].company])
SenderPly.Functions.AddMoney('bank', commission)
if GetResourceState("qb-management") == "started" then
exports['qb-management']:RemoveMoney(data[1].company, commission)
Wait(500)
elseif GetResourceState("qb-bossmenu") == "started" then
TriggerEvent("qb-bossmenu:server:removeAccountMoney", data[1].company, commission)
Wait(500)
end
TriggerClientEvent('gksphone:notifi', SenderPly.PlayerData.source,
{
title = _U('billing_title'),
message = string.format(
'You received a commission check of $%s when %s %s paid a bill of $%s.'
, commission, Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo.lastname,
data[1].price),
img = '/html/static/img/icons/logo.png'
})
end
end
end
Ply.source = Ply.PlayerData.source
Ply.identifier = Ply.PlayerData.citizenid
exports.bcs_companymanager:PayBill(id.id, amount, data[1].company, target, Ply)
-- Ply.Functions.RemoveMoney('bank', data[1].price, "paid-invoice")
if GetResourceState("qb-management") == "started" then
Wait(500)
exports['qb-management']:AddMoney(data[1].company, data[1].price)
elseif GetResourceState("qb-bossmenu") == "started" then
Wait(500)
TriggerEvent("qb-bossmenu:server:addAccountMoney", data[1].company, data[1].price)
end
TriggerEvent('gksphone:server:bank_gettransferinfo', src)
-- MySQL.Async.execute('DELETE FROM gksphone_invoices WHERE id=@id', { ['@id'] = id.id })
TriggerClientEvent('updatebilling', src)


MySQL.Async.execute(
"INSERT INTO gksphone_bank_transfer (type, identifier, price, name) VALUES (@type, @identifier, @price, @name)"
, {
["@type"] = 1,
["@identifier"] = Ply.PlayerData.citizenid,
["@price"] = data[1].price,
["@name"] = _U('bill_billing') .. data[1].price
})
TriggerClientEvent('gksphone:client:changeCharge', src, 'billing')
else
TriggerClientEvent('gksphone:notifi', Ply.PlayerData.source,
{ title = _U('billing_title'), message = _U('bill_nocash'), img = '/html/static/img/icons/logo.png' })
TriggerEvent('gksphone:server:bank_gettransferinfo', src)
TriggerClientEvent('updatebilling', src)
end
end)
end)

RegisterServerEvent("gksphone:server:faturapayBill")
AddEventHandler("gksphone:server:faturapayBill", function()
local src = source
local Ply = Config.Core.Functions.GetPlayer(src)
local money = Ply.PlayerData.money.bank
MySQL.Async.fetchAll('SELECT * FROM billings WHERE identifier = @citizenid', {
['@citizenid'] = Ply.PlayerData.citizenid
}, function(data)
for i = 1, #data, 1 do
if money >= data[i].price then
local target = data[i].biller_id
if Config.UseBillingCommission then
local SenderPly = Config.Core.Functions.GetPlayerByCitizenId(data[i].biller_id)
if SenderPly ~= nil then
if Config.BillingCommissions[data[i].company] then
local commission = Round(data[i].price * Config.BillingCommissions[data[i].company])
SenderPly.Functions.AddMoney('bank', commission)
if GetResourceState("qb-management") == "started" then
exports['qb-management']:RemoveMoney(data[i].company, commission)
Wait(500)
elseif GetResourceState("qb-bossmenu") == "started" then
TriggerEvent("qb-bossmenu:server:removeAccountMoney", data[i].company, commission)
Wait(500)
end
TriggerClientEvent('gksphone:notifi', tonumber(SenderPly.PlayerData.source),
{
title = _U('billing_title'),
message = string.format(
'You received a commission check of $%s when %s %s paid a bill of $%s.'
, commission, Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo
.lastname,
data[i].price),
img = '/html/static/img/icons/logo.png'
})
end
end
end

money = money - data[i].price
-- Ply.Functions.RemoveMoney('bank', data[i].price, "paid-invoice")
Ply.source = Ply.PlayerData.source
Ply.identifier = Ply.PlayerData.citizenid
exports.bcs_companymanager:PayBill(data[i].id, data[i].price, data[i].company, target,
Ply)
if GetResourceState("qb-management") == "started" then
Wait(500)
exports['qb-management']:AddMoney(data[i].company, data[i].price)
elseif GetResourceState("qb-bossmenu") == "started" then
Wait(500)
TriggerEvent("qb-bossmenu:server:addAccountMoney", data[i].company, data[i].price)
end
MySQL.Async.execute('DELETE FROM gksphone_invoices WHERE id=@id', { ['@id'] = data[i].id })

MySQL.Async.execute(
"INSERT INTO gksphone_bank_transfer (type, identifier, price, name) VALUES (@type, @identifier, @price, @name)"
, {
["@type"] = 1,
["@identifier"] = Ply.PlayerData.citizenid,
["@price"] = data[i].price,
["@name"] = _U('bill_billing') .. data[i].price
})
TriggerClientEvent('gksphone:client:changeCharge', src, 'billing')
else
TriggerClientEvent('gksphone:notifi', src,
{ title = _U('billing_title'), message = _U('bill_nocash'), img = '/html/static/img/icons/logo.png' })
break
end
end
TriggerEvent('gksphone:server:bank_gettransferinfo', src)
TriggerClientEvent('updatebilling', src)
end)
end)

--- Business Ä°nvoices ---
Config.Core.Functions.CreateCallback('gksphone:server:bfaturalist', function(source, cb)
local e = Config.Core.Functions.GetPlayer(source)
local billingg = {}
MySQL.query("SELECT * FROM billings WHERE company = @society", { ["@society"] = e.PlayerData.job.name },
function(result)
for i = 1, #result, 1 do
local senderg = result[i].biller
if senderg == nil then
senderg = "Unknown"
end
local yPlayer = Config.Core.Functions.GetPlayerByCitizenId(result[i].identifier)
if yPlayer then
table.insert(billingg,
{
id = result[i].id,
alici = yPlayer.PlayerData.charinfo.firstname,
society = result[i].company,
sender = senderg,
sendercitizenid = result[i].biller_id,
label = result[i].description,
amount = result[i].price
})
else
local players = MySQL.scalar.await("SELECT charinfo FROM `players` WHERE `citizenid` LIKE '%" ..
result[i].identifier .. "%'", {})
if players then
local name = json.decode(players)
table.insert(billingg,
{
id = result[i].id,
alici = name.firstname,
society = result[i].company,
sender = senderg,
sendercitizenid = result[i].biller_id,
label = result[i].description,
amount = result[i].price
})
else
table.insert(billingg,
{
id = result[i].id,
alici = "",
society = result[i].company,
sender = senderg,
sendercitizenid = result[i].biller_id,
label = result[i].description,
amount = result[i].price
})
end
end
end
cb(billingg)
end)
end)

RegisterServerEvent("gksphone:business:delbill")
AddEventHandler("gksphone:business:delbill", function(id)
local src = source
local e = Config.Core.Functions.GetPlayer(src)

MySQL.Async.fetchAll('SELECT * FROM billings WHERE company = @society AND id = @id', {
['@society'] = e.PlayerData.job.name,
['@id'] = id
}, function(data)
if data[1] then
local Player = Config.Core.Functions.GetPlayerByCitizenId(data[1].biller_id)
if Player then
TriggerClientEvent('gksphone:notifi', Player.PlayerData.source,
{
title = _U('bussines_title'),
message = data[1].label .. _U('bill_invoicecancel'),
img = '/html/static/img/icons/logo.png'
})
end
TriggerEvent('bill:deleteBill', data[1].id)
-- MySQL.Async.fetchAll("DELETE FROM gksphone_invoices WHERE id = @id",
-- {
-- ['@id'] = data[1].id
-- })
TriggerClientEvent('gksphone:notifi', src,
{
title = _U('bussines_title'),
message = _U('buss_delbill'),
img = '/html/static/img/icons/business.png'
})
TriggerClientEvent("gksphone:client:billrefresh", src)
else
TriggerClientEvent('gksphone:notifi', src,
{
title = _U('bussines_title'),
message = _U('buss_nodelbill'),
img = '/html/static/img/icons/business.png'
})
end
end)
end)

RegisterNetEvent("gksphone:server:createbill", function(data)
local src
local biller = Config.Core.Functions.GetPlayer(source)
if biller then
if data.id then
if src ~= data.id then
local billed = Config.Core.Functions.GetPlayer(tonumber(data.id))
if not billed then
TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_notplayer', data.id),
img =
'/html/static/img/icons/logo.png'
})
return
end
local amount = tonumber(data.amount)
if amount and amount > 0 then
local from = {
label = biller.PlayerData.job.label,
job = biller.PlayerData.job.name,
identifier = biller.PlayerData.job.name,
}
TriggerEvent('bill:createBill', tonumber(data.id), amount, data.fine, from, source)

TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_invosucss'),
img = '/html/static/img/icons/logo.png'
})
TriggerClientEvent('gksphone:notifi', billed.PlayerData.source,
{
title = _U('billing_title'),
message = _U('bill_younewin'),
img = '/html/static/img/icons/logo.png'
})

local webhookdata = {
receiverSrc = data.id,
receiverName = billed.PlayerData.charinfo.firstname .. ' ' .. billed.PlayerData.charinfo
.lastname,
receiverID = billed.PlayerData.citizenid,
billingLabel = data.fine,
billingSociety = biller.PlayerData.job.name,
billingAmaount = amount,
senderName = biller.PlayerData.charinfo.firstname .. ' ' .. biller.PlayerData.charinfo.lastname,
senderID = biller.PlayerData.citizenid
}

TriggerEvent("gksphone:webhook:newbilling", webhookdata)
else
TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_amounterror'),
img = '/html/static/img/icons/logo.png'
})
end
end
elseif data.contact then
local contact = data.contact
local amount = tonumber(data.amount)

if amount and amount > 0 then
for k, l in pairs(contact) do
if l.number then
local number = l.number
local billed = Config.Core.Functions.GetPlayerByPhone(number)
if billed then
local from = {
label = biller.PlayerData.job.label,
job = biller.PlayerData.job.name,
identifier = biller.PlayerData.job.name,
}
TriggerEvent('bill:createBill', billed.PlayerData.source, amount, data.fine, from, source)

TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_invosucss'),
img = '/html/static/img/icons/logo.png'
})
TriggerClientEvent('gksphone:notifi', billed.PlayerData.source,
{
title = _U('billing_title'),
message = _U('bill_younewin'),
img = '/html/static/img/icons/logo.png'
})

local webhookdata = {
receiverSrc = data.id,
receiverName = billed.PlayerData.charinfo.firstname ..
' ' .. billed.PlayerData.charinfo.lastname,
receiverID = billed.PlayerData.citizenid,
billingLabel = data.fine,
billingSociety = biller.PlayerData.job.name,
billingAmaount = amount,
senderName = biller.PlayerData.charinfo.firstname ..
' ' .. biller.PlayerData.charinfo.lastname,
senderID = biller.PlayerData.citizenid
}

TriggerEvent("gksphone:webhook:newbilling", webhookdata)
else
TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_notplayer', number),
img =
'/html/static/img/icons/logo.png'
})
end
end
end
else
TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_amounterror'),
img =
'/html/static/img/icons/logo.png'
})
end
elseif data.airdrop then
local airdrop = data.airdrop
local amount = tonumber(data.amount)

if amount and amount > 0 then
for k, l in pairs(airdrop) do
if l.pid then
local bsrc = tonumber(l.pid)
local billed = Config.Core.Functions.GetPlayer(bsrc)
if billed then
local from = {
label = biller.PlayerData.job.label,
job = biller.PlayerData.job.name,
identifier = biller.PlayerData.job.name,
}
TriggerEvent('bill:createBill', billed.PlayerData.source, amount, data.fine, from, source)


TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_invosucss'),
img = '/html/static/img/icons/logo.png'
})
TriggerClientEvent('gksphone:notifi', billed.PlayerData.source,
{
title = _U('billing_title'),
message = _U('bill_younewin'),
img = '/html/static/img/icons/logo.png'
})

local webhookdata = {
receiverSrc = data.id,
receiverName = billed.PlayerData.charinfo.firstname ..
' ' .. billed.PlayerData.charinfo.lastname,
receiverID = billed.PlayerData.citizenid,
billingLabel = data.fine,
billingSociety = biller.PlayerData.job.name,
billingAmaount = amount,
senderName = biller.PlayerData.charinfo.firstname ..
' ' .. biller.PlayerData.charinfo.lastname,
senderID = biller.PlayerData.citizenid
}

TriggerEvent("gksphone:webhook:newbilling", webhookdata)
else
TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_notplayer', bsrc),
img =
'/html/static/img/icons/logo.png'
})
end
end
end
else
TriggerClientEvent('gksphone:notifi', source,
{
title = _U('billing_title'),
message = _U('bill_amounterror'),
img =
'/html/static/img/icons/logo.png'
})
end
end
end
end)


-- New Bill Export --
function NewBilling(source, label, society, senderBilling, senderID, amountt)
local create = false
local src = source
local biller = Config.Core.Functions.GetPlayer(source)

if biller then
local amount = tonumber(amountt)
if amount and amount > 0 then
local from = {
label = society,
job = society,
identifier = society,
}
TriggerEvent('bill:createBill', biller.PlayerData.source, amount, label, from, source)
local webhookdata = {
receiverSrc = src,
receiverName = biller.PlayerData.charinfo.firstname .. ' ' .. biller.PlayerData.charinfo.lastname,
receiverID = biller.PlayerData.citizenid,
billingLabel = label,
billingSociety = society,
billingAmaount = amount,
senderName = "It was created by the system. " .. senderBilling,
senderID = "system " .. senderID
}
TriggerClientEvent('gksphone:notifi', source,
{ title = _U('billing_title'), message = _U('bill_invosucss'), img = '/html/static/img/icons/logo.png' })
TriggerEvent("gksphone:webhook:newbilling", webhookdata)
create = true
end
end

return create
end

exports("NewBilling", NewBilling)