local function firstToUpper(str) return (str:gsub("^%l", string.upper)) end local function GetCasinoBalance(cid, cb) cb(exports.oxmysql:fetchSync('SELECT amount FROM casinobalance WHERE cid=:cid LIMIT 1', { cid = cid })) end RegisterNetEvent('erp_banking:info') AddEventHandler('erp_banking:info', function(show, inCasino) local source = source if show then TriggerEvent('echorp:getplayerfromid', source, function(player) if player then local cid, job, grade = player.cid, player.job.name, player.job.grade local function Normal() TriggerClientEvent('erp_banking:info', source, player.bank, cid, false) end TriggerEvent('echorp:getJobInfo', job, function(res) if res then if res['business'] and (res['grades'][grade]['owner'] == 1 or res['grades'][grade]['owner'] == 3) then TriggerEvent('erp_phone:GetMoney', job, function(bMoney) TriggerClientEvent('erp_banking:info', source, player.bank, cid, true, bMoney or 0, job) end) else Normal() end else Normal() end end) if inCasino then GetCasinoBalance(player.cid, function(result) if result and result[1] then TriggerClientEvent('erp_banking:casino', player.source, result[1]['amount']) else TriggerClientEvent('erp_banking:casino', player.source, 0) end end) end end end) end end) RegisterNetEvent('erp_banking:withdraw') AddEventHandler('erp_banking:withdraw', function(amount, isJob, note) local source = source TriggerEvent('echorp:getplayerfromid', source, function(player) if player then if isJob then local name = player.job.name TriggerEvent('erp_phone:GetMoney', name, function(bMoney) if bMoney then if bMoney >= amount then exports.oxmysql:execute("UPDATE businesses SET funds = funds-:amount WHERE name=:name", {amount = amount, name = name}, function(endResult) if endResult then TriggerEvent('AdjustCash', player.cid, amount, true, function(bankResult) if bankResult then TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'Money withdrawed from business.', length = 4500 }) TriggerEvent('echorp:getplayerfromid', source, function(player) if player then TriggerClientEvent('erp_banking:info', source, player.bank, player.cid) TriggerClientEvent("banking:viewBalance", player.source, player.bank) TriggerClientEvent("banking:addBalance", player.source, amount) -- Transfer logs local type = (firstToUpper(name) .. " Business Account") TriggerEvent('erp_banking:history', source, type, "Withdraw", amount, note) TriggerClientEvent('erp_phone:updateBanking', source) end end) end end) end end) end end end) else if player.bank >= amount then TriggerEvent('AdjustBank', player.cid, -amount, true, false, function(bankResult) if bankResult then TriggerEvent('AdjustCash', player.cid, amount, true, function(cashResult) if cashResult then TriggerEvent('echorp:getplayerfromid', source, function(player) if player then TriggerClientEvent('erp_banking:info', source, player.bank, player.cid) TriggerClientEvent("banking:viewBalance", player.source, player.bank) TriggerClientEvent("banking:removeBalance", player.source, amount) TriggerClientEvent('banking:viewCash', player.source, player.cash) TriggerClientEvent("banking:addCash", player.source, amount) TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = "You withdrawed out $"..amount.." from the bank.", length = 5000 }) -- Transfer logs TriggerEvent('erp_banking:history', source, 'Personal Account', "Withdraw", amount, note) TriggerClientEvent('erp_phone:updateBanking', source) end end) end end) end end) end end end end) end) RegisterNetEvent('erp_banking:deposit') AddEventHandler('erp_banking:deposit', function(amount, isJob, note) local source = source TriggerEvent('echorp:getplayerfromid', source, function(player) if player then if isJob then local name = player.job.name if player.cash >= amount then exports.oxmysql:execute("UPDATE businesses SET funds = funds+:amount WHERE name=:name", {amount = amount, name = name}, function(endResult) if endResult then TriggerEvent('AdjustCash', player.cid, -amount, true, function(cashResult) if cashResult then TriggerEvent('echorp:getplayerfromid', source, function(player) if player then TriggerClientEvent('erp_banking:info', source, player.bank, player.cid) TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = "You deposited $"..amount.." into the business account.", length = 5000 }) -- Notifs TriggerClientEvent('banking:viewCash', player.source, player.cash) TriggerClientEvent("banking:removeCash", player.source, amount) -- Transfer logs local type = (firstToUpper(name) .. " Business Account") TriggerEvent('erp_banking:history', source, type, "Deposit", amount, note) TriggerClientEvent('erp_phone:updateBanking', source) end end) end end) end end) end else if player.cash >= amount then TriggerEvent('AdjustCash', player.cid, -amount, true, function(cashResult) if cashResult then TriggerEvent('AdjustBank', player.cid, amount, true, false, function(bankResult) if bankResult then TriggerEvent('echorp:getplayerfromid', source, function(player) if player then TriggerClientEvent('erp_banking:info', source, player.bank, player.cid) -- Notif Start TriggerClientEvent("banking:viewBalance", player.source, player.bank) TriggerClientEvent("banking:addBalance", player.source, amount) TriggerClientEvent('banking:viewCash', player.source, player.cash) TriggerClientEvent("banking:removeCash", player.source, amount) -- Notif End TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = "You deposited $"..amount.." into your bank.", length = 5000 }) -- Transfer logs TriggerEvent('erp_banking:history', source, 'Personal Account', "Deposit", amount, note) TriggerClientEvent('erp_phone:updateBanking', source) end end) end end) end end) end end end end) end) RegisterNetEvent('erp_banking:transfer') AddEventHandler('erp_banking:transfer', function(target, amount, note, business) local source = source local isBusiness = business ~= "personal" if target and amount then TriggerEvent('echorp:getplayerfromid', source, function(player) if player and amount > 0 then if not isBusiness then if player.bank >= amount then if cid ~= target then TriggerEvent('TransferBank', source, target, amount, true, function(res) if res then TriggerEvent('echorp:getplayerfromid', source, function(player) if player then TriggerClientEvent('erp_banking:info', source, player.bank, player.cid) TriggerClientEvent("banking:viewBalance", player.source, player.bank) TriggerClientEvent("banking:removeBalance", player.source, amount) TriggerClientEvent('erp_phone:updateBanking', source) TriggerClientEvent('erp_phone:sendNotification', source, {img = 'banknotif.png', title = "Banking", content = "You transferred $"..amount.." to citizen "..target, time = 10000 }) -- Logging exports.oxmysql:executeSync("INSERT INTO bank_history (`cid`, `account`, `text`, `amount`, `note`, `time`) VALUES (:cid, :account, :text, :amount, :note, :time)", { cid = target, account = 'Personal Account', text = 'Transfer from Citizen '..player['cid'], amount = amount, note = note, time = os.time() * 1000 }) exports.oxmysql:executeSync("INSERT INTO bank_history (`cid`, `account`, `text`, `amount`, `note`, `time`) VALUES (:cid, :account, :text, :amount, :note, :time)", { cid = player['cid'], account = 'Personal Account', text = 'Transfer to Citizen '..target, amount = amount, note = note, time = os.time() * 1000 }) end end) end end) else TriggerClientEvent('erp_phone:sendNotification', source, {img = 'banknotif.png', title = "Banking", content = "You can not transfer money to yourself.", time = 7500 }) end end elseif isBusiness then TriggerEvent('erp_phone:GetMoney', business, function(res) if res > amount then exports.oxmysql:executeSync("UPDATE businesses SET funds = funds-:amount WHERE name=:name", {amount = amount, name = business}) TriggerEvent('AddBank', target, amount, true, true, false, function(res) if res then TriggerClientEvent('erp_phone:sendNotification', source, {img = 'banknotif.png', title = "Banking", content = "You transferred $"..amount.." to citizen "..target, time = 10000 }) local type = (firstToUpper(business) .. " Business Account") TriggerEvent('erp_banking:history', source, type, "Transfer to Citizen "..target, amount, note) exports.oxmysql:executeSync("INSERT INTO bank_history (`cid`, `account`, `text`, `amount`, `note`, `time`) VALUES (:cid, :account, :text, :amount, :note, :time)", { cid = target, account = 'Personal Account', text = 'Transfer from '..type, amount = amount, note = note, time = os.time() * 1000 }) TriggerClientEvent('erp_phone:updateBanking', source) end end) end end) end end end) end end) RegisterNetEvent('erp_banking:history') AddEventHandler('erp_banking:history', function(source, account, text, amount, note) TriggerEvent('echorp:getplayerfromid', source, function(player) if player then exports.oxmysql:execute("INSERT INTO bank_history (`cid`, `account`, `text`, `amount`, `note`, `time`) VALUES (:cid, :account, :text, :amount, :note, :time)", { cid = player.cid, account = account, text = text, amount = amount, note = note, time = os.time() * 1000 }) end end) end) RegisterNetEvent('erp_banking:getHistory') AddEventHandler('erp_banking:getHistory', function(account, text, amount) local source = source TriggerEvent('echorp:getplayerfromid', source, function(player) if player then exports.oxmysql:fetch('SELECT account, text, amount, note FROM bank_history WHERE cid = :cid ORDER BY `id` DESC LIMIT 50', { cid = player.cid }, function(data) TriggerClientEvent('erp_banking:getHistory', source, data) end) end end) end) RegisterCommand("cash", function(source, args, rawCommand) TriggerEvent('echorp:getplayerfromid', source, function(player) if player then TriggerClientEvent('banking:viewCash', source, player.cash) end end) end, false) RegisterCommand("bank", function(source, args, rawCommand) TriggerEvent('echorp:getplayerfromid', source, function(player) if player then TriggerClientEvent('banking:viewBalance', source, player.bank) end end) end, false)