From 7b2fab60e1c8d61ef11158cb56ccebde201e9483 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Sun, 29 Jun 2025 07:31:34 +0200 Subject: [PATCH] Update server.lua --- resources/[tools]/okokBanking/server.lua | 332 +++-------------------- 1 file changed, 38 insertions(+), 294 deletions(-) diff --git a/resources/[tools]/okokBanking/server.lua b/resources/[tools]/okokBanking/server.lua index bbc13cf64..c09154ad2 100644 --- a/resources/[tools]/okokBanking/server.lua +++ b/resources/[tools]/okokBanking/server.lua @@ -616,68 +616,6 @@ AddEventHandler("okokBanking:DepositMoneyToSociety", function(amount, society, s end end) -RegisterServerEvent("okokBanking:DepositMoneyToSociety") -AddEventHandler("okokBanking:DepositMoneyToSociety", function(amount, society, societyName) - local _source = source - local xPlayer = QBCore.Functions.GetPlayer(_source) - local playerMoney = xPlayer.PlayerData.money.cash - local itemCash = xPlayer.Functions.GetItemByName("cash") - local playerMoneyCash = 0 - if itemCash ~= nil then - playerMoneyCash = itemCash.amount - end - - if amount <= playerMoney and not Config.UseCashAsItem or amount <= playerMoneyCash and Config.UseCashAsItem then - if Config.UseQBManagement then - exports['qb-management']:AddMoney(society, amount) - elseif Config.UseQBBanking then - -- Direct database update for qb-banking since export isn't available - MySQL.query('UPDATE bank_accounts SET account_balance = account_balance + @amount WHERE account_name = @society', { - ['@amount'] = amount, - ['@society'] = society, - }, function(changed) - print("Updated bank account for " .. society .. " with amount " .. amount) - end) - else - MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE society = @society AND society_name = @society_name', { - ['@value'] = amount, - ['@society'] = society, - ['@society_name'] = societyName, - }, function(changed) - end) - end - - if Config.UseCashAsItem then - xPlayer.Functions.RemoveItem('cash', amount) - else - xPlayer.Functions.RemoveMoney('cash', amount) - end - xPlayer = QBCore.Functions.GetPlayer(_source) - local itemCashUpdated = xPlayer.Functions.GetItemByName("cash") - local playerMoneyCashUpdated = 0 - if itemCashUpdated ~= nil then - playerMoneyCashUpdated = itemCashUpdated.amount - end - TriggerEvent('okokBanking:AddDepositTransactionToSociety', amount, _source, society, societyName) - if Config.UseCashAsItem then - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerMoneyCashUpdated) - else - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash) - end - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('deposited_to').title, interp(_L('deposited_to').text, {s1 = amount, s2 = societyName}), _L('deposited_to').time, _L('deposited_to').type) - else - TriggerClientEvent('QBCore:Notify', _source, interp(_L('deposited_to').text, {s1 = amount, s2 = societyName}), _L('deposited_to').type) - end - TransferMoneyWebhook({sender_name = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname, receiver_name = societyName..' ('..society..')', value = amount}) - else - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('no_money_pocket').title, _L('no_money_pocket').text, _L('no_money_pocket').time, _L('no_money_pocket').type) - else - TriggerClientEvent('QBCore:Notify', _source, _L('no_money_pocket').text, _L('no_money_pocket').type) - end - end -end) RegisterServerEvent("okokBanking:WithdrawMoneyToSociety") AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society, societyName, societyMoney) @@ -794,119 +732,6 @@ AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society, end) -RegisterServerEvent("okokBanking:WithdrawMoneyToSociety") -AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society, societyName, societyMoney) - local _source = source - local xPlayer = QBCore.Functions.GetPlayer(_source) - local db - local hasChecked = false - - if Config.UseQBManagement then - MySQL.Async.fetchAll('SELECT * FROM management_funds WHERE job_name = @job_name', { - ['@job_name'] = society, - }, function(result) - db = result[1] - hasChecked = true - db.value = db.amount - end) - elseif Config.UseQBBanking then - MySQL.Async.fetchAll('SELECT * FROM bank_accounts WHERE account_name = @account_name', { - ['@account_name'] = society, - }, function(result) - db = result[1] - hasChecked = true - db.value = db.account_balance - end) - else - MySQL.query('SELECT * FROM okokbanking_societies WHERE society = @society', { - ['@society'] = society - }, function(result) - db = result[1] - hasChecked = true - end) - end - - if not Config.UseQBManagement then - MySQL.query('UPDATE okokbanking_societies SET is_withdrawing = 1 WHERE society = @society AND society_name = @society_name', { - ['@value'] = amount, - ['@society'] = society, - ['@society_name'] = societyName, - }, function(changed) - end) - end - - while not hasChecked do - Citizen.Wait(100) - end - - if amount <= db.value then - if db.is_withdrawing == 1 then - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('someone_withdrawing').title, _L('someone_withdrawing').text, _L('someone_withdrawing').time, _L('someone_withdrawing').type) - else - TriggerClientEvent('QBCore:Notify', _source, _L('someone_withdrawing').text, _L('someone_withdrawing').type) - end - else - if Config.UseQBManagement then - exports['qb-management']:RemoveMoney(society, amount) - elseif Config.UseQBBanking then - -- Direct database update for qb-banking since export isn't available - MySQL.query('UPDATE bank_accounts SET account_balance = account_balance - @amount WHERE account_name = @society', { - ['@amount'] = amount, - ['@society'] = society, - }, function(changed) - print("Updated bank account for " .. society .. " with withdrawal of " .. amount) - end) - else - MySQL.query('UPDATE okokbanking_societies SET value = value - @value WHERE society = @society AND society_name = @society_name', { - ['@value'] = amount, - ['@society'] = society, - ['@society_name'] = societyName, - }, function(changed) - end) - end - - if Config.UseCashAsItem then - xPlayer.Functions.AddItem('cash', amount) - else - xPlayer.Functions.AddMoney('cash', amount) - end - xPlayer = QBCore.Functions.GetPlayer(_source) - local itemCash = xPlayer.Functions.GetItemByName("cash") - local PlayerCashMoney = 0 - if itemCash ~= nil then - PlayerCashMoney = itemCash.amount - end - TriggerEvent('okokBanking:AddWithdrawTransactionToSociety', amount, _source, society, societyName) - if Config.UseCashAsItem then - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, PlayerCashMoney) - else - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash) - end - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('you_have_withdrawn').title, interp(_L('you_have_withdrawn').text, {s1 = amount, s2 = societyName}), _L('you_have_withdrawn').time, _L('you_have_withdrawn').type) - else - TriggerClientEvent('QBCore:Notify', _source, interp(_L('you_have_withdrawn').text, {s1 = amount, s2 = societyName}), _L('you_have_withdrawn').type) - end - TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname, value = amount}) - end - else - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('society_no_money').title, _L('society_no_money').text, _L('society_no_money').time, _L('society_no_money').type) - else - TriggerClientEvent('QBCore:Notify', _source, _L('society_no_money').text, _L('society_no_money').type) - end - end - - if not Config.UseQBManagement then - MySQL.query('UPDATE okokbanking_societies SET is_withdrawing = 0 WHERE society = @society AND society_name = @society_name', { - ['@value'] = amount, - ['@society'] = society, - ['@society_name'] = societyName, - }, function(changed) - end) - end -end) RegisterServerEvent("okokBanking:TransferMoneyToSociety") AddEventHandler("okokBanking:TransferMoneyToSociety", function(amount, ibanNumber, societyName, society) @@ -1054,91 +879,46 @@ function getSocietyInfo(society, iban) return societyInfo end -RegisterServerEvent("okokBanking:TransferMoneyToSociety") -AddEventHandler("okokBanking:TransferMoneyToSociety", function(amount, ibanNumber, societyName, society) + + +RegisterServerEvent("okokBanking:TransferMoneyToSocietyFromSociety") +AddEventHandler("okokBanking:TransferMoneyToSocietyFromSociety", function(amount, ibanNumber, societyNameTarget, societyTarget, society, societyName, societyMoney) local _source = source local xPlayer = QBCore.Functions.GetPlayer(_source) - local playerMoney = xPlayer.PlayerData.money.bank + local playerJob = xPlayer.PlayerData.job.name - if amount <= playerMoney then - if Config.UseQBManagement then - exports['qb-management']:AddMoney(society, amount) - elseif Config.UseQBBanking then - -- Direct database update for qb-banking since export isn't available - MySQL.query('UPDATE bank_accounts SET account_balance = account_balance + @amount WHERE account_name = @society', { - ['@amount'] = amount, - ['@society'] = society, - }, function(changed) - print("Updated bank account for " .. society .. " with transfer of " .. amount) - end) - else - MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE iban = @iban', { - ['@value'] = amount, - ['@iban'] = ibanNumber - }, function(changed) - end) - end - - xPlayer.Functions.RemoveMoney('bank', amount) - xPlayer = QBCore.Functions.GetPlayer(_source) - local itemCash = xPlayer.Functions.GetItemByName("cash") - local playerCashMoney = 0 - if itemCash ~= nil then - playerCashMoney = itemCash.amount - end - TriggerEvent('okokBanking:AddTransferTransactionToSociety', amount, _source, society, societyName) - if Config.UseCashAsItem then - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney) - TriggerClientEvent('okokBanking:updateTransactions', _source, xPlayer.PlayerData.money.bank, playerCashMoney) - TriggerClientEvent('okokBanking:updateMoney', _source, xPlayer.PlayerData.money.bank, playerCashMoney) - else - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash) - TriggerClientEvent('okokBanking:updateTransactions', _source, xPlayer.PlayerData.money.bank, xPlayer.PlayerData.money.cash) - TriggerClientEvent('okokBanking:updateMoney', _source, xPlayer.PlayerData.money.bank, xPlayer.PlayerData.money.cash) - end - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = societyName}), _L('transferred_to').time, _L('transferred_to').type) - else - TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = societyName}), _L('transferred_to').type) - end - TransferMoneyWebhook({sender_name = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname, receiver_name = societyName..' ('..society..')', value = amount}) - else - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('no_money_bank').title, _L('no_money_bank').text, _L('no_money_bank').time, _L('no_money_bank').type) - else - TriggerClientEvent('QBCore:Notify', _source, _L('no_money_bank').text, _L('no_money_bank').type) - end + if society ~= playerJob then + return end -end) - -RegisterServerEvent("okokBanking:TransferMoneyToPlayerFromSociety") -AddEventHandler("okokBanking:TransferMoneyToPlayerFromSociety", function(amount, ibanNumber, targetIdentifier, acc, targetName, society, societyName, societyMoney, toMyself) - local _source = source - local xPlayer = QBCore.Functions.GetPlayer(_source) local itemCash = xPlayer.Functions.GetItemByName("cash") local playerCashMoney = 0 if itemCash ~= nil then playerCashMoney = itemCash.amount end local xTarget = QBCore.Functions.GetPlayerByCitizenId(targetIdentifier) - local itemCashTarget = xTarget and xTarget.Functions.GetItemByName("cash") - local playerCashMoneyTarget = 0 - if itemCashTarget ~= nil then - playerCashMoneyTarget = itemCashTarget.amount - end local xPlayers = QBCore.Functions.GetPlayers() - if amount <= societyMoney then + local societyInfo = getSocietyInfo(society, ibanNumber) + + if amount <= societyInfo.value then if Config.UseQBManagement then exports['qb-management']:RemoveMoney(society, amount) + exports['qb-management']:AddMoney(societyTarget, amount) elseif Config.UseQBBanking then -- Direct database update for qb-banking since export isn't available MySQL.query('UPDATE bank_accounts SET account_balance = account_balance - @amount WHERE account_name = @society', { ['@amount'] = amount, ['@society'] = society, }, function(changed) - print("Updated bank account for " .. society .. " with withdrawal of " .. amount) + print("Updated source bank account for " .. society .. " with transfer of " .. amount) + + MySQL.query('UPDATE bank_accounts SET account_balance = account_balance + @amount WHERE account_name = @society', { + ['@amount'] = amount, + ['@society'] = societyTarget, + }, function(changed) + print("Updated target bank account for " .. societyTarget .. " with transfer of " .. amount) + end) end) else MySQL.query('UPDATE okokbanking_societies SET value = value - @value WHERE society = @society AND society_name = @society_name', { @@ -1146,64 +926,27 @@ AddEventHandler("okokBanking:TransferMoneyToPlayerFromSociety", function(amount, ['@society'] = society, ['@society_name'] = societyName, }, function(changed) + MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE society = @society AND society_name = @society_name', { + ['@value'] = amount, + ['@society'] = societyTarget, + ['@society_name'] = societyNameTarget, + }, function(changed) + end) end) end - if xTarget ~= nil then - xTarget.Functions.AddMoney('bank', amount) - if not toMyself then - for i=1, #xPlayers, 1 do - local xForPlayer = QBCore.Functions.GetPlayer(xPlayers[i]) - if xForPlayer.PlayerData.citizenid == targetIdentifier then - if Config.UseCashAsItem then - TriggerClientEvent('okokBanking:updateTransactions', xPlayers[i], xTarget.PlayerData.money.bank, playerCashMoneyTarget) - else - TriggerClientEvent('okokBanking:updateTransactions', xPlayers[i], xTarget.PlayerData.money.bank, xTarget.PlayerData.money.cash) - end - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', xPlayers[i], _L('received_from').title, interp(_L('received_from').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('received_from').time, _L('received_from').type) - else - TriggerClientEvent('QBCore:Notify', xPlayers[i], interp(_L('received_from').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('received_from').type) - end - end - end - end - TriggerEvent('okokBanking:AddTransferTransactionFromSocietyToP', amount, society, societyName, targetIdentifier, targetName) - if Config.UseCashAsItem then - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney) - else - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash) - end - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('transferred_to').time, _L('transferred_to').type) - else - TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('transferred_to').type) - end - TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = xTarget.PlayerData.charinfo.firstname..' '..xTarget.PlayerData.charinfo.lastname, value = amount}) - elseif xTarget == nil then - local playerAccount = json.decode(acc) - playerAccount.bank = playerAccount.bank + amount - playerAccount = json.encode(playerAccount) - - TriggerEvent('okokBanking:AddTransferTransactionFromSocietyToP', amount, society, societyName, targetIdentifier, targetName) - if Config.UseCashAsItem then - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney) - else - TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash) - end - if Config.okokNotify then - TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = targetName }), _L('transferred_to').time, _L('transferred_to').type) - else - TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = targetName }), _L('transferred_to').type) - end - TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = targetName..' (Offline User)', value = amount}) - - MySQL.query('UPDATE players SET money = @playerAccount WHERE citizenid = @target', { - ['@playerAccount'] = playerAccount, - ['@target'] = targetIdentifier - }, function(changed) - - end) + + TriggerEvent('okokBanking:AddTransferTransactionFromSociety', amount, society, societyName, societyTarget, societyNameTarget) + if Config.UseCashAsItem then + TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney) + else + TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash) end + if Config.okokNotify then + TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = societyNameTarget}), _L('transferred_to').time, _L('transferred_to').type) + else + TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = societyNameTarget}), _L('transferred_to').type) + end + TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = societyNameTarget..' ('..societyTarget..')', value = amount}) else if Config.okokNotify then TriggerClientEvent('okokNotify:Alert', _source, _L('society_no_money').title, _L('society_no_money').text, _L('society_no_money').time, _L('society_no_money').type) @@ -1216,6 +959,7 @@ end) + RegisterServerEvent("okokBanking:TransferMoneyToPlayerFromSociety") AddEventHandler("okokBanking:TransferMoneyToPlayerFromSociety", function(amount, ibanNumber, targetIdentifier, acc, targetName, society, societyName, societyMoney, toMyself) local _source = source