Skip to content

Commit

Permalink
Merge pull request #20 from Z3rio/main
Browse files Browse the repository at this point in the history
feat: trigger event upon paying bill
  • Loading branch information
Gellipapa authored Jun 24, 2024
2 parents 93ef807 + f1b804a commit c20ec38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
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

0 comments on commit c20ec38

Please sign in to comment.