forked from Simnation/Main
185 lines
5.7 KiB
Lua
185 lines
5.7 KiB
Lua
RegisterServerEvent('roadphone:bank:transfer')
|
|
AddEventHandler('roadphone:bank:transfer', function(number, amount)
|
|
local src = tonumber(source)
|
|
local xPlayer = QBCore.Functions.GetPlayer(src)
|
|
local targetplayer = nil
|
|
|
|
if Config.okokBanking then
|
|
targetplayer = getPlayerFromIban(number)
|
|
else
|
|
targetplayer = GetPlayerFromPhone(number)
|
|
end
|
|
|
|
if Config.okokBanking and targetplayer == nil then
|
|
targetplayer = GetPlayerFromPhone(number)
|
|
end
|
|
|
|
local balance = tonumber(xPlayer.Functions.GetMoney('bank'))
|
|
|
|
amount = tonumber(amount)
|
|
|
|
if not xPlayer then
|
|
return;
|
|
end
|
|
|
|
if not targetplayer then
|
|
TriggerClientEvent("roadphone:sendNotification", src, {
|
|
apptitle = 'APP_BANK_NAME',
|
|
title = 'APP_BANK_NUMBER_NOT_FOUND_TITLE',
|
|
message = 'APP_BANK_NUMBER_NOT_FOUND_MESSAGE',
|
|
img = "/public/img/Apps/light_mode/bank.webp"
|
|
})
|
|
return;
|
|
end
|
|
|
|
local numberfromsource = getNumberFromIdentifier(xPlayer.PlayerData.citizenid)
|
|
local targetbalance = tonumber(targetplayer.Functions.GetMoney('bank'))
|
|
|
|
if numberfromsource == number then
|
|
TriggerClientEvent("roadphone:sendNotification", src, {
|
|
apptitle = 'APP_BANK_NAME',
|
|
title = 'APP_BANK_SEND_MONEY_TO_YOURSELF_TITLE',
|
|
img = "/public/img/Apps/light_mode/bank.webp"
|
|
})
|
|
return;
|
|
end
|
|
|
|
if targetbalance < 0 or balance < 0 then
|
|
TriggerClientEvent("roadphone:sendNotification", src, {
|
|
apptitle = "APP_BANK_NAME",
|
|
title = 'APP_BANK_INVALID_INPUT',
|
|
img = "/public/img/App/bank.png"
|
|
})
|
|
return;
|
|
end
|
|
|
|
if not amount or amount < 0 then
|
|
TriggerClientEvent("roadphone:sendNotification", src, {
|
|
apptitle = 'APP_BANK_NAME',
|
|
title = 'APP_BANK_INVALID_INPUT',
|
|
img = "/public/img/Apps/light_mode/bank.webp"
|
|
})
|
|
return;
|
|
end
|
|
|
|
if amount > balance then
|
|
TriggerClientEvent("roadphone:sendNotification", src, {
|
|
apptitle = 'APP_BANK_NAME',
|
|
title = 'APP_BANK_NOT_ENOUGH_MONEY',
|
|
message = 'APP_BANK_NOT_ENOUGH_MONEY_MESSAGE',
|
|
img = "/public/img/Apps/light_mode/bank.webp"
|
|
})
|
|
return;
|
|
end
|
|
|
|
local selfname, targetname = getNameFromIdentifier(xPlayer.PlayerData.citizenid), getNameFromIdentifier(targetplayer.PlayerData.citizenid)
|
|
|
|
if not selfname or not targetname then
|
|
return;
|
|
end
|
|
|
|
local percent = amount * Cfg.BankPayTax
|
|
|
|
local endamount = amount - percent
|
|
|
|
xPlayer.Functions.RemoveMoney('bank', amount)
|
|
targetplayer.Functions.AddMoney('bank', endamount)
|
|
|
|
TriggerEvent("roadphone:addBankTransfer", numberfromsource, number, Lang:t('info.bank_money_transaction', { value = targetname }), amount)
|
|
|
|
TriggerClientEvent("roadphone:sendNotification", src, {
|
|
apptitle = 'APP_BANK_NAME',
|
|
title = 'APP_BANK_MONEY_SENT',
|
|
message = Lang:t('info.bank_app_sent_money_text', { value = amount}),
|
|
img = "/public/img/Apps/light_mode/bank.webp"
|
|
})
|
|
|
|
TriggerClientEvent("roadphone:sendNotification", targetplayer.PlayerData.source, {
|
|
apptitle = 'APP_BANK_NAME',
|
|
title = 'APP_BANK_MONEY_RECEIVED',
|
|
message = Lang:t('info.bank_app_received_money_text', { value = QBCore.Shared.Round(endamount, 2)}),
|
|
img = "/public/img/Apps/light_mode/bank.webp"
|
|
})
|
|
|
|
if amount >= Cfg.MinimumBankTransfer then
|
|
bankWebhook(src, targetplayer.source, selfname, targetname, amount)
|
|
end
|
|
|
|
end)
|
|
|
|
RegisterServerEvent("roadphone:addBankTransfer")
|
|
AddEventHandler("roadphone:addBankTransfer", function(sender, receiver, reason, amount)
|
|
if sender and receiver then
|
|
MySQL.Async.insert(
|
|
"INSERT INTO roadshop_banktransfer (sender,receiver,reason,amount) VALUES (@sender, @receiver, @reason, @amount)",
|
|
{
|
|
["@sender"] = sender,
|
|
["@receiver"] = receiver,
|
|
["@reason"] = reason,
|
|
["@amount"] = amount
|
|
}, function(id)
|
|
|
|
local transaction = {
|
|
id = id,
|
|
sender = sender,
|
|
receiver = receiver,
|
|
reason = reason,
|
|
amount = amount
|
|
}
|
|
|
|
local selfplayer = GetPlayerFromPhone(sender)
|
|
local target = GetPlayerFromPhone(receiver)
|
|
|
|
if selfplayer then
|
|
TriggerClientEvent('roadphone:bank:addTransaction', selfplayer.PlayerData.source, transaction)
|
|
end
|
|
|
|
if target then
|
|
TriggerClientEvent('roadphone:bank:addTransaction', target.PlayerData.source, transaction)
|
|
end
|
|
end)
|
|
end
|
|
end)
|
|
|
|
QBCore.Functions.CreateCallback("roadphone:getBankBalance", function(source, cb)
|
|
|
|
local xPlayer = QBCore.Functions.GetPlayer(source)
|
|
|
|
if not xPlayer then
|
|
return;
|
|
end
|
|
|
|
cb(xPlayer.Functions.GetMoney('bank'))
|
|
|
|
end)
|
|
|
|
exports("addBankTransaction", function(sender, receiver, reason, amount)
|
|
|
|
TriggerEvent("roadphone:addBankTransaction", sender, receiver, reason, amount)
|
|
|
|
end)
|
|
|
|
function getBankTransactions(number)
|
|
|
|
local result = MySQL.Sync.fetchAll('SELECT * FROM roadshop_banktransfer WHERE sender = @sender OR receiver = @receiver', {
|
|
['@sender'] = number,
|
|
['@receiver'] = number
|
|
})
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
local cooldownspambank = 0
|
|
|
|
QBCore.Functions.CreateCallback('roadphone:bank:checkSpam', function(source, cb)
|
|
if cooldownspambank == 0 then
|
|
cb(0)
|
|
cooldownspambank = cooldownspambank + 1
|
|
Wait(1000)
|
|
cooldownspambank = 0
|
|
else
|
|
cb(1)
|
|
end
|
|
end)
|