Files
jim-payments/server/chargerserver.lua

104 lines
4.4 KiB
Lua
Raw Normal View History

2025-02-21 13:54:49 +00:00
onResourceStart(function()
2024-01-27 21:57:05 +00:00
for k in pairs(Config.Receipts.Jobs) do
2025-02-21 13:54:49 +00:00
while not Jobs do Wait(10) end
2024-01-27 21:57:05 +00:00
if not Jobs[k] and not Gangs[k] then
2025-02-21 13:54:49 +00:00
debugPrint("^1Error^7: ^5Config^7.^5Receipts^7.^5Jobs ^2searched for job/gang ^7'^3"..k.."^7' ^2and couldn't find it in the Shared^7")
2024-01-27 21:57:05 +00:00
end
end
2025-02-21 13:54:49 +00:00
if Items and not Items["payticket"] then
debugPrint("^1Error^7: ^2Unable to find ^7'^3payticket^7' ^2item it in the Shared^7")
end
end, true)
2024-01-27 21:57:05 +00:00
2025-02-21 13:54:49 +00:00
registerCommand("cashregister", {
2025-02-22 13:23:43 +00:00
locale("command", "cash_reg"), {}, false,
2025-02-21 13:54:49 +00:00
function(source)
TriggerClientEvent(getScript()..":client:Charge", source, {}, true)
end
})
createCallback(getScript()..":MakePlayerList", function(source)
2024-01-27 21:57:05 +00:00
local onlineList = {}
2025-02-21 13:54:49 +00:00
for _, v in pairs(GetPlayers()) do
if v ~= nil or type(v) ~= "number" then
local Player = getPlayer(v)
onlineList[#onlineList+1] = { value = tonumber(v), text = "["..v.."] - "..Player.name }
Wait(10)
end
2024-01-27 21:57:05 +00:00
end
2025-02-21 13:54:49 +00:00
return onlineList
2024-01-27 21:57:05 +00:00
end)
2025-02-21 13:54:49 +00:00
RegisterServerEvent(getScript()..":server:Charge", function(citizen, price, billtype, img, outside, gang)
2024-01-27 21:57:05 +00:00
local src = source
2025-02-21 13:54:49 +00:00
local biller = getPlayer(src)
local billed = getPlayer(tonumber(citizen))
2024-01-27 21:57:05 +00:00
local amount = tonumber(price)
2025-02-21 13:54:49 +00:00
local balance = billed[billtype]
2024-01-27 21:57:05 +00:00
if amount and amount > 0 then
if balance < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error", "customer_nocash"), "error", src)
triggerNotify(nil, locale("error", "you_nocash"), "error", tonumber(citizen))
2024-01-27 21:57:05 +00:00
return
end
2025-02-21 13:54:49 +00:00
local label = gang == true and Gangs[biller.gang].label or Jobs[biller.job].label
2024-01-27 21:57:05 +00:00
if Config.General.PhoneBank == false or gang == true or billtype == "cash" then
2025-02-21 13:54:49 +00:00
TriggerClientEvent(getScript()..":client:PayPopup", billed.source, amount, src, billtype, img, label, gang, outside)
2024-01-27 21:57:05 +00:00
else
if Config.General.PhoneType == "qb" then
MySQL.Async.insert(
'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)',
2025-02-21 13:54:49 +00:00
{billed.citizenid, amount, biller.job, biller.firstname, biller.citizenid}, function(id)
2024-01-27 21:57:05 +00:00
if id then
2025-02-21 13:54:49 +00:00
TriggerClientEvent('qb-phone:client:AcceptorDenyInvoice', billed.source, id, biller.firstname, biller.job, biller.citizenid, amount, GetInvokingResource())
2024-01-27 21:57:05 +00:00
end
end)
2025-02-21 13:54:49 +00:00
TriggerClientEvent('qb-phone:RefreshPhone', billed.source)
2024-01-27 21:57:05 +00:00
elseif Config.General.PhoneType == "gks" then
MySQL.Async.execute('INSERT INTO gksphone_invoices (citizenid, amount, society, sender, sendercitizenid, label) VALUES (@citizenid, @amount, @society, @sender, @sendercitizenid, @label)', {
2025-02-21 13:54:49 +00:00
['@citizenid'] = billed.citizenid,
2024-01-27 21:57:05 +00:00
['@amount'] = amount,
2025-02-21 13:54:49 +00:00
['@society'] = biller.job,
['@sender'] = biller.firstname,
['@sendercitizenid'] = biller.citizenid,
['@label'] = label,
2024-01-27 21:57:05 +00:00
})
2025-02-22 13:23:43 +00:00
TriggerClientEvent('gksphone:notifi', src, {title = 'Billing', message = locale("success", "inv_succ"), img= '/html/static/img/icons/logo.png' })
TriggerClientEvent('gksphone:notifi', billed.source, {title = 'Billing', message = locale("success", "inv_recieved"), img= '/html/static/img/icons/logo.png' })
2024-01-27 21:57:05 +00:00
end
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success", "inv_succ"), 'success', src)
triggerNotify(nil, locale("success", "inv_recieved"), nil, billed.source)
2024-01-27 21:57:05 +00:00
end
2025-02-22 13:23:43 +00:00
else triggerNotify(nil, locale("error", "charge_zero"), 'error', source) return end
2024-01-27 21:57:05 +00:00
end)
2025-02-21 13:54:49 +00:00
RegisterServerEvent(getScript()..":server:PayPopup", function(data)
2024-01-27 21:57:05 +00:00
local src = source
2025-02-21 13:54:49 +00:00
local billed = getPlayer(src)
local biller = getPlayer(tonumber(data.biller))
2024-01-27 21:57:05 +00:00
local newdata = {
2025-02-21 13:54:49 +00:00
senderCitizenId = biller.citizenid,
society = data.gang and biller.gang or biller.job,
2024-01-27 21:57:05 +00:00
amount = data.amount
}
if data.accept then
2025-02-21 13:54:49 +00:00
chargePlayer(data.amount, data.billtype, src)
if Config.General.ApGov then
exports['ap-government']:chargeCityTax(billed.source, "Item", data.amount)
end
TriggerEvent(getScript()..":Tickets:Give", newdata, biller, data.gang)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, billed.firstname..locale("success", "accepted_pay")..data.amount..locale("success", "payment"), "success", data.biller)
2024-01-27 21:57:05 +00:00
elseif not data.accept then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success", "declined"), "error", src)
triggerNotify(nil, billed.firstname..locale("error", "decline_pay")..data.amount..locale("success", "payment"), "error", data.biller)
2024-01-27 21:57:05 +00:00
end
end)
CreateThread(function()
2025-02-21 13:54:49 +00:00
if Config.General.Usebzzz then
createUseableItem('terminal', function(source, item)
TriggerClientEvent(getScript()..":client:Charge", source, {}, true)
2024-01-27 21:57:05 +00:00
end)
end
end)