Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add function for billing per identifier instead of only source #19

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 47 additions & 15 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@

RegisterNetEvent('esx_billing:sendBill', function(playerId, sharedAccountName, label, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local xTarget = ESX.GetPlayerFromId(playerId)
function BillPlayerByIdentifier(targetIdentifier, senderIdentifier, sharedAccountName, label, amount)
local xTarget = ESX.GetPlayerFromIdentifier(targetIdentifier)
amount = ESX.Math.Round(amount)

if amount > 0 and xTarget then
if amount > 0 then
if string.match(sharedAccountName, "society_") then
local jobName = string.gsub(sharedAccountName, 'society_', '')
if xPlayer.job.name ~= jobName then
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from a society (^5%s^7), but does not have the correct Job - Possibly Cheats"):format(xPlayer.source, sharedAccountName))
return
end
TriggerEvent('esx_addonaccount:getSharedAccount', sharedAccountName, function(account)
if account then
MySQL.insert('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)', {xTarget.identifier, xPlayer.identifier, 'society', sharedAccountName, label, amount},
MySQL.insert('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)', {targetIdentifier, senderIdentifier, 'society', sharedAccountName, label, amount},
function(rowsChanged)
xTarget.showNotification(TranslateCap('received_invoice'))
if xTarget then
Z3rio marked this conversation as resolved.
Show resolved Hide resolved
xTarget.showNotification(TranslateCap('received_invoice'))
end
end)
else
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from invalid society - ^5%s^7"):format(xPlayer.source, sharedAccountName))
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from invalid society - ^5%s^7"):format(senderIdentifier, sharedAccountName))
end
end)
else
MySQL.insert('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)', {xTarget.identifier, xPlayer.identifier, 'player', xPlayer.identifier, label, amount},
MySQL.insert('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)', {targetIdentifier, senderIdentifier, 'player', senderIdentifier, label, amount},
function(rowsChanged)
xTarget.showNotification(TranslateCap('received_invoice'))
if xTarget then
Z3rio marked this conversation as resolved.
Show resolved Hide resolved
xTarget.showNotification(TranslateCap('received_invoice'))
end
end)
end
end
end

function BillPlayer(targetId, senderIdentiier, sharedAccountName, label, amount)
Z3rio marked this conversation as resolved.
Show resolved Hide resolved
local xTarget = ESX.GetPlayerFromId(targetId)

if xTarget then
Z3rio marked this conversation as resolved.
Show resolved Hide resolved
BillPlayerByIdentifier(xTarget.identifier, senderIdentiier, sharedAccountName, label, amount)
end
end

RegisterNetEvent('esx_billing:sendBill', function(targetId, sharedAccountName, label, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local jobName = string.gsub(sharedAccountName, 'society_', '')

if xPlayer.job.name ~= jobName then
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from a society (^5%s^7), but does not have the correct Job - Possibly Cheats"):format(xPlayer.source, sharedAccountName))
return
end

BillPlayer(targetId, xPlayer.identifier, sharedAccountName, label, amount)
end)
exports("BillPlayer", BillPlayer)

RegisterNetEvent('esx_billing:sendBillToIdentifier', function(targetIdentifier, sharedAccountName, label, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local jobName = string.gsub(sharedAccountName, 'society_', '')

if xPlayer.job.name ~= jobName then
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from a society (^5%s^7), but does not have the correct Job - Possibly Cheats"):format(xPlayer.source, sharedAccountName))
return
end

BillPlayerByIdentifier(targetIdentifier, xPlayer.identifier, sharedAccountName, label, amount)
end)
exports("BillPlayerByIdentifier", BillPlayerByIdentifier)


ESX.RegisterServerCallback('esx_billing:getBills', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
Expand Down