diff --git a/client/main.lua b/client/main.lua index 9de1b2f6..68e0b34b 100644 --- a/client/main.lua +++ b/client/main.lua @@ -23,38 +23,30 @@ end) function ShowBillsMenu() ESX.TriggerServerCallback('esx_billing:getBills', function(bills) - ESX.UI.Menu.CloseAll() - local elements = {} for i=1, #bills, 1 do - table.insert(elements, {label = bills[i].label .. ' - $' .. bills[i].amount .. '', value = bills[i].id}) + table.insert(elements, { + label = ('%s - %s'):format(bills[i].label, _U('invoices_item', ESX.Math.GroupDigits(bills[i].amount))), + billID = bills[i].id + }) end - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'billing', - { - title = _U('invoices'), - align = 'bottom-right', - elements = elements - }, - function(data, menu) - - menu.close() - - local billId = data.current.value - - ESX.TriggerServerCallback('esx_billing:payBill', function() - ShowBillsMenu() - end, billId) - - end, - function(data, menu) - menu.close() - end - ) + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'billing', + { + title = _U('invoices'), + align = 'bottom-right', + elements = elements + }, function(data, menu) + menu.close() + ESX.TriggerServerCallback('esx_billing:payBill', function() + ShowBillsMenu() + end, data.current.billID) + end, function(data, menu) + menu.close() + end) end) end diff --git a/locales/br.lua b/locales/br.lua index 7921cda0..caf96470 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -1,5 +1,6 @@ Locales['br'] = { ['invoices'] = 'faturas', + ['invoices_item'] = '$%s', ['received_invoice'] = 'você ~r~recebeu~s~ uma fatura', ['paid_invoice'] = 'você ~g~pagou~s~ uma fatura de ~r~$%s~s~', ['received_payment'] = 'você ~g~recebeu~s~ um pagamento de ~r~$%s~s~', diff --git a/locales/de.lua b/locales/de.lua index f7bf1a0d..5c8ea45d 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -1,5 +1,6 @@ Locales['de'] = { ['invoices'] = 'rechnungen', + ['invoices_item'] = '$%s', ['received_invoice'] = 'you hast eine Rechnung ~r~erhlaten~s~', ['paid_invoice'] = 'du ~g~bezahlst~s~ eine Rechnung von ~r~$%s~s~', ['received_payment'] = 'du ~g~erhältst~s~ eine Zahlung von ~r~$%s~s~', diff --git a/locales/en.lua b/locales/en.lua index a2137db9..7c08b09a 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,5 +1,6 @@ Locales['en'] = { ['invoices'] = 'invoices', + ['invoices_item'] = '$%s', ['received_invoice'] = 'you have just ~r~received~s~ an invoice', ['paid_invoice'] = 'you ~g~paid~s~ an invoice of ~r~$%s~s~', ['received_payment'] = 'you ~g~received~s~ a payment of ~r~$%s~s~', diff --git a/locales/es.lua b/locales/es.lua index 17a232c9..a2c8dce9 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -1,5 +1,6 @@ Locales['es'] = { ['invoices'] = 'facturas', + ['invoices_item'] = '€%s', ['received_invoice'] = 'has ~r~recibido~s~ una multa', ['paid_invoice'] = 'has ~g~pagado~s~ una multa de ~r~€%s~s~', ['received_payment'] = 'has ~g~recibido~s~ un pago de ~g~€%s~s~', diff --git a/locales/fi.lua b/locales/fi.lua index f4b7820d..f91ca3ff 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -1,5 +1,6 @@ Locales['fi'] = { ['invoices'] = 'laskut', + ['invoices_item'] = '$%s', ['received_invoice'] = 'sinä ~r~sait~s~ laskun', ['paid_invoice'] = 'sinä ~g~maksoit~s~ laskun suuruudelta ~r~$%s~s~', ['received_payment'] = 'sinä ~g~sait~s~ maksun suuruudelta ~r~$%s~s~', diff --git a/locales/fr.lua b/locales/fr.lua index be53d3b2..9e3d201d 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -1,5 +1,6 @@ Locales['fr'] = { ['invoices'] = 'factures', + ['invoices_item'] = '$%s', ['received_invoice'] = 'vous avez ~r~reçu~s~ une facture', ['paid_invoice'] = 'vous avez ~g~payé~s~ une facture de ~r~$%s~s~', ['received_payment'] = 'vous avez ~g~reçu~s~ un paiement de ~g~$%s~s~', diff --git a/locales/sv.lua b/locales/sv.lua index adab3253..2bbae28d 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -1,5 +1,6 @@ Locales['sv'] = { ['invoices'] = 'räkningar', + ['invoices_item'] = '%s SEK', ['received_invoice'] = 'du har ~y~mottagit~s~ en räkning', ['paid_invoice'] = 'du ~y~betalade~s~ precis en räkning på ~g~%s SEK~s~', ['received_payment'] = 'du har ~y~mottagit~s~ en räkning på ~g~%s SEK~s~', diff --git a/server/main.lua b/server/main.lua index 37f4abca..ca96824a 100644 --- a/server/main.lua +++ b/server/main.lua @@ -7,47 +7,42 @@ AddEventHandler('esx_billing:sendBill', function(playerId, sharedAccountName, la local _source = source local xPlayer = ESX.GetPlayerFromId(_source) local xTarget = ESX.GetPlayerFromId(playerId) + amount = ESX.Math.Round(amount) TriggerEvent('esx_addonaccount:getSharedAccount', sharedAccountName, function(account) if amount < 0 then - print('esx_billing: ' .. GetPlayerName(_source) .. ' tried sending a negative bill!') + print(('esx_billing: %s attempted to send a negative bill!'):format(xPlayer.identifier)) elseif account == nil then if xTarget ~= nil then - MySQL.Async.execute( - 'INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)', - { - ['@identifier'] = xTarget.identifier, - ['@sender'] = xPlayer.identifier, - ['@target_type'] = 'player', - ['@target'] = xPlayer.identifier, - ['@label'] = label, - ['@amount'] = amount - }, - function(rowsChanged) - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_invoice')) - end - ) + MySQL.Async.execute('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)', + { + ['@identifier'] = xTarget.identifier, + ['@sender'] = xPlayer.identifier, + ['@target_type'] = 'player', + ['@target'] = xPlayer.identifier, + ['@label'] = label, + ['@amount'] = amount + }, function(rowsChanged) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_invoice')) + end) end else if xTarget ~= nil then - MySQL.Async.execute( - 'INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)', - { - ['@identifier'] = xTarget.identifier, - ['@sender'] = xPlayer.identifier, - ['@target_type'] = 'society', - ['@target'] = sharedAccountName, - ['@label'] = label, - ['@amount'] = amount - }, - function(rowsChanged) - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_invoice')) - end - ) + MySQL.Async.execute('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)', + { + ['@identifier'] = xTarget.identifier, + ['@sender'] = xPlayer.identifier, + ['@target_type'] = 'society', + ['@target'] = sharedAccountName, + ['@label'] = label, + ['@amount'] = amount + }, function(rowsChanged) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_invoice')) + end) end end @@ -58,180 +53,156 @@ end) ESX.RegisterServerCallback('esx_billing:getBills', function(source, cb) local xPlayer = ESX.GetPlayerFromId(source) - MySQL.Async.fetchAll( - 'SELECT * FROM billing WHERE identifier = @identifier', - { - ['@identifier'] = xPlayer.identifier - }, - function(result) - - local bills = {} - - for i=1, #result, 1 do - table.insert(bills, { - id = result[i].id, - identifier = result[i].identifier, - sender = result[i].sender, - targetType = result[i].target_type, - target = result[i].target, - label = result[i].label, - amount = result[i].amount - }) - end - - cb(bills) - + MySQL.Async.fetchAll('SELECT * FROM billing WHERE identifier = @identifier', { + ['@identifier'] = xPlayer.identifier + }, function(result) + local bills = {} + for i=1, #result, 1 do + table.insert(bills, { + id = result[i].id, + identifier = result[i].identifier, + sender = result[i].sender, + targetType = result[i].target_type, + target = result[i].target, + label = result[i].label, + amount = result[i].amount + }) end - ) + cb(bills) + end) end) ESX.RegisterServerCallback('esx_billing:getTargetBills', function(source, cb, target) local xPlayer = ESX.GetPlayerFromId(target) - MySQL.Async.fetchAll( - 'SELECT * FROM billing WHERE identifier = @identifier', - { - ['@identifier'] = xPlayer.identifier - }, - function(result) - - local bills = {} - - for i=1, #result, 1 do - table.insert(bills, { - id = result[i].id, - identifier = result[i].identifier, - sender = result[i].sender, - targetType = result[i].target_type, - target = result[i].target, - label = result[i].label, - amount = result[i].amount - }) - end - - cb(bills) - + MySQL.Async.fetchAll('SELECT * FROM billing WHERE identifier = @identifier', { + ['@identifier'] = xPlayer.identifier + }, function(result) + local bills = {} + for i=1, #result, 1 do + table.insert(bills, { + id = result[i].id, + identifier = result[i].identifier, + sender = result[i].sender, + targetType = result[i].target_type, + target = result[i].target, + label = result[i].label, + amount = result[i].amount + }) end - ) + cb(bills) + end) end) ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id) local xPlayer = ESX.GetPlayerFromId(source) - MySQL.Async.fetchAll( - 'SELECT * FROM billing WHERE id = @id', - { - ['@id'] = id - }, function(result) + MySQL.Async.fetchAll('SELECT * FROM billing WHERE id = @id', { + ['@id'] = id + }, function(result) - local sender = result[1].sender - local targetType = result[1].target_type - local target = result[1].target - local amount = result[1].amount + local sender = result[1].sender + local targetType = result[1].target_type + local target = result[1].target + local amount = result[1].amount - local xTarget = ESX.GetPlayerFromIdentifier(sender) + local xTarget = ESX.GetPlayerFromIdentifier(sender) - if targetType == 'player' then + if targetType == 'player' then - if xTarget ~= nil then + if xTarget ~= nil then - if xPlayer.getMoney() >= amount then + if xPlayer.getMoney() >= amount then - MySQL.Async.execute('DELETE from billing WHERE id = @id', - { - ['@id'] = id - }, function(rowsChanged) - xPlayer.removeMoney(amount) - xTarget.addMoney(amount) + MySQL.Async.execute('DELETE from billing WHERE id = @id', { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeMoney(amount) + xTarget.addMoney(amount) - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) - - cb() - end) - - elseif xPlayer.getBank() >= amount then - - MySQL.Async.execute('DELETE from billing WHERE id = @id', - { - ['@id'] = id - }, function(rowsChanged) - xPlayer.removeAccountMoney('bank', amount) - xTarget.addAccountMoney('bank', amount) - - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) - - cb() - end) - - else - TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money')) - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount))) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount))) cb() - end + end) + + elseif xPlayer.getBank() >= amount then + + MySQL.Async.execute('DELETE from billing WHERE id = @id', { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeAccountMoney('bank', amount) + xTarget.addAccountMoney('bank', amount) + + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount))) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount))) + + cb() + end) else - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('player_not_online')) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money')) + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + cb() end else + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('player_not_online')) + cb() + end - TriggerEvent('esx_addonaccount:getSharedAccount', target, function(account) + else - if xPlayer.getMoney() >= amount then + TriggerEvent('esx_addonaccount:getSharedAccount', target, function(account) - MySQL.Async.execute('DELETE from billing WHERE id = @id', - { - ['@id'] = id - }, function(rowsChanged) - xPlayer.removeMoney(amount) - account.addMoney(amount) + if xPlayer.getMoney() >= amount then - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) - if xTarget ~= nil then - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) - end - - cb() - end) - - elseif xPlayer.getBank() >= amount then - - MySQL.Async.execute('DELETE from billing WHERE id = @id', - { - ['@id'] = id - }, function(rowsChanged) - xPlayer.removeAccountMoney('bank', amount) - account.addMoney(amount) - - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) - if xTarget ~= nil then - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) - end - - cb() - end) - - else - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + MySQL.Async.execute('DELETE from billing WHERE id = @id', { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeMoney(amount) + account.addMoney(amount) + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount))) if xTarget ~= nil then - TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money')) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount))) end cb() - end - end) + end) - end + elseif xPlayer.getBank() >= amount then + + MySQL.Async.execute('DELETE from billing WHERE id = @id', { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeAccountMoney('bank', amount) + account.addMoney(amount) + + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount))) + if xTarget ~= nil then + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount))) + end + + cb() + end) + + else + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + + if xTarget ~= nil then + TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money')) + end + + cb() + end + end) end - ) + end) end) \ No newline at end of file