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: trigger event upon paying bill #20

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ function ShowBillsMenu()
end

ESX.OpenContext("right", elements, function(menu,element)
ESX.TriggerServerCallback('esx_billing:payBill', function()
local billId = element.billId

ESX.TriggerServerCallback('esx_billing:payBill', function(resp)
ShowBillsMenu()
end, element.billId)

if not resp then
return
end
TriggerEvent("esx_billing:paidBill", billId)
end, billId)
end)
else
ESX.ShowNotification(TranslateCap('no_invoices'))
Expand Down
34 changes: 19 additions & 15 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,34 +107,36 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, billId)
if rowsChanged == 1 then
xPlayer.removeMoney(amount, "Bill Paid")
xTarget.addMoney(amount, "Paid bill")

TriggerEvent("esx_billing:paidBill", source, billId)
xPlayer.showNotification(TranslateCap('paid_invoice', ESX.Math.GroupDigits(amount)))
xTarget.showNotification(TranslateCap('received_payment', ESX.Math.GroupDigits(amount)))
cb(true)
else
cb(nil)
end

cb()
end)
elseif xPlayer.getAccount('bank').money >= amount then
MySQL.update('DELETE FROM billing WHERE id = ?', {billId},
function(rowsChanged)
if rowsChanged == 1 then
xPlayer.removeAccountMoney('bank', amount, "Bill Paid")
xTarget.addAccountMoney('bank', amount, "Paid bill")

TriggerEvent("esx_billing:paidBill", source, billId)
xPlayer.showNotification(TranslateCap('paid_invoice', ESX.Math.GroupDigits(amount)))
xTarget.showNotification(TranslateCap('received_payment', ESX.Math.GroupDigits(amount)))
cb(true)
else
cb(nil)
end

cb()
end)
else
xTarget.showNotification(TranslateCap('target_no_money'))
xPlayer.showNotification(TranslateCap('no_money'))
cb()
cb(nil)
end
else
xPlayer.showNotification(TranslateCap('player_not_online'))
cb()
cb(nil)
end
else
TriggerEvent('esx_addonaccount:getSharedAccount', result.target, function(account)
Expand All @@ -144,14 +146,15 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, billId)
if rowsChanged == 1 then
xPlayer.removeMoney(amount, "Bill Paid")
account.addMoney(amount)

TriggerEvent("esx_billing:paidBill", source, billId)
xPlayer.showNotification(TranslateCap('paid_invoice', ESX.Math.GroupDigits(amount)))
if xTarget then
xTarget.showNotification(TranslateCap('received_payment', ESX.Math.GroupDigits(amount)))
end
cb(true)
else
cb(nil)
end

cb()
end)
elseif xPlayer.getAccount('bank').money >= amount then
MySQL.update('DELETE FROM billing WHERE id = ?', {billId},
Expand All @@ -160,21 +163,22 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, billId)
xPlayer.removeAccountMoney('bank', amount, "Bill Paid")
account.addMoney(amount)
xPlayer.showNotification(TranslateCap('paid_invoice', ESX.Math.GroupDigits(amount)))

TriggerEvent("esx_billing:paidBill", source, billId)
if xTarget then
xTarget.showNotification(TranslateCap('received_payment', ESX.Math.GroupDigits(amount)))
end
cb(true)
else
cb(nil)
end

cb()
end)
else
if xTarget then
xTarget.showNotification(TranslateCap('target_no_money'))
end

xPlayer.showNotification(TranslateCap('no_money'))
cb()
cb(nil)
end
end)
end
Expand Down