2022-08-22 21:32:15 +01:00
local QBCore = exports [ 'qb-core' ]: GetCoreObject ()
2022-08-22 22:13:56 +01:00
RegisterNetEvent ( 'QBCore:Server:UpdateObject' , function () if source ~= '' then return false end QBCore = exports [ 'qb-core' ]: GetCoreObject () end )
2022-08-22 21:32:15 +01:00
local function cv ( amount )
local formatted = amount
while true do
formatted , k = string.gsub ( formatted , "^(-?%d+)(%d%d%d)" , '%1,%2' )
if ( k == 0 ) then
break
end
end
return formatted
end
RegisterServerEvent ( 'jim-payments:server:ATM:use' , function ( amount , billtype , baccount , account , society , gsociety )
local src = source
local Player = QBCore.Functions . GetPlayer ( src )
local cashB = Player.Functions . GetMoney ( "cash" )
local bankB = Player.Functions . GetMoney ( "bank" )
local amount = tonumber ( amount )
--Simple transfers from bank to wallet --
if account == "bank" or account == "atm" then
if billtype == "withdraw" then
2022-09-02 20:04:22 +08:00
if bankB < amount then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "bank_low" ], "error" , src )
2022-08-22 21:32:15 +01:00
elseif bankB >= tonumber ( amount ) then
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "draw" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "from_bank" ], "success" ) -- Don't really need this as phone gets notified when money is withdrawn
2022-08-22 21:32:15 +01:00
Player.Functions . RemoveMoney ( 'bank' , amount ) Wait ( 1500 )
Player.Functions . AddMoney ( 'cash' , amount )
end
elseif billtype == "deposit" then
2022-09-02 20:04:22 +08:00
if cashB < amount then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "no_cash" ], "error" , src )
2022-08-22 21:32:15 +01:00
elseif cashB >= amount then
Player.Functions . RemoveMoney ( 'cash' , amount ) Wait ( 1500 )
Player.Functions . AddMoney ( 'bank' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "deposited" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "into_bank" ], "success" , src )
2022-08-22 21:32:15 +01:00
end
end
-- Transfers from bank to savings account --
elseif account == "savings" then
local getSavingsAccount = MySQL.Sync . fetchAll ( 'SELECT * FROM bank_accounts WHERE citizenid = ? AND account_type = ?' , { Player.PlayerData . citizenid , 'Savings' })
if getSavingsAccount [ 1 ] ~= nil then savbal = tonumber ( getSavingsAccount [ 1 ]. amount ) aid = getSavingsAccount [ 1 ]. record_id end
if billtype == "withdraw" then
if savbal >= amount then
2022-09-18 15:32:10 +01:00
savbal -= amount
2022-08-22 21:32:15 +01:00
Player.Functions . AddMoney ( 'bank' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , "$" .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "draw_save" ], "success" , src )
2022-08-22 21:32:15 +01:00
MySQL.Async . execute ( 'UPDATE bank_accounts SET amount = ? WHERE citizenid = ? AND record_id = ?' , { savbal , Player.PlayerData . citizenid , getSavingsAccount [ 1 ]. record_id }, function ( success )
if success then return true else return false end
end )
elseif savbal < amount then
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. error [ "saving_low" ], "error" )
2022-08-22 21:32:15 +01:00
end
elseif billtype == "deposit" then
if amount < bankB then
2022-09-18 15:32:10 +01:00
savbal += amount
2022-08-22 21:32:15 +01:00
Player.Functions . RemoveMoney ( 'bank' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , "$" .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "depos_save" ], "success" , src )
2022-08-22 21:32:15 +01:00
MySQL.Async . execute ( 'UPDATE bank_accounts SET amount = ? WHERE citizenid = ? AND record_id = ?' , { savbal , Player.PlayerData . citizenid , getSavingsAccount [ 1 ]. record_id }, function ( success )
if success then return true else return false end
end )
2022-09-02 20:04:22 +08:00
else triggerNotify ( nil , Loc [ Config.Lan ]. error [ "bank_low" ], "error" , src )
2022-08-22 21:32:15 +01:00
end
end
--Simple transfers from society account to bank --
elseif account == "society" then
if billtype == "withdraw" then
2022-09-02 20:04:22 +08:00
if tonumber ( society ) < amount then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "soc_low" ], "error" , src )
2022-08-22 21:32:15 +01:00
elseif tonumber ( society ) >= amount then
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "draw" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "fromthe" ] .. Player.PlayerData . job.label .. Loc [ Config.Lan ]. success [ "account" ], "success" , src )
2022-08-22 21:32:15 +01:00
Player.Functions . AddMoney ( 'bank' , amount )
2023-01-28 14:05:58 +00:00
if Config.RenewedBanking then TriggerEvent ( "qb-bossmenu:server:removeAccountMoney" , tostring ( Player.PlayerData . job.name ), amount )
else exports [ "qb-management" ]: RemoveMoney ( tostring ( Player.PlayerData . job.name ), amount ) end
2022-08-22 21:32:15 +01:00
end
elseif billtype == "deposit" then
2022-09-02 20:04:22 +08:00
if bankB < amount then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "nomoney_bank" ], "error" , src )
2022-08-22 21:32:15 +01:00
elseif bankB >= amount then
2023-01-28 14:05:58 +00:00
if Config.RenewedBanking then TriggerEvent ( "qb-bossmenu:server:addAccountMoney" , tostring ( Player.PlayerData . job.name ), amount )
else exports [ "qb-management" ]: AddMoney ( tostring ( Player.PlayerData . job.name ), amount ) end
2022-08-22 21:32:15 +01:00
Player.Functions . RemoveMoney ( 'bank' , amount ) Wait ( 1500 )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "deposited" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "into" ] .. Player.PlayerData . job.label .. Loc [ Config.Lan ]. success [ "account" ], "success" , src )
2022-08-22 21:32:15 +01:00
end
end
-- Transfer from boss account to players --
elseif account == "societytransfer" then
local bannedCharacters = { '%' , '$' , ';' }
local newAmount = tostring ( amount )
local newiban = tostring ( baccount )
for _ , v in pairs ( bannedCharacters ) do
newAmount = string.gsub ( newAmount , '%' .. v , '' )
newiban = string.gsub ( newiban , '%' .. v , '' )
end
baccount = newiban
amount = tonumber ( newAmount )
local Player = QBCore.Functions . GetPlayer ( src )
if ( society - amount ) >= 0 then
local query = '%"account":"' .. baccount .. '"%'
local result = MySQL.Sync . fetchAll ( 'SELECT * FROM players WHERE charinfo LIKE ?' , { query })
if result [ 1 ] then
local Reciever = QBCore.Functions . GetPlayerByCitizenId ( result [ 1 ]. citizenid )
2023-01-28 14:05:58 +00:00
if Config.RenewedBanking then TriggerEvent ( "qb-bossmenu:server:removeAccountMoney" , tostring ( Player.PlayerData . job.name ), amount )
else exports [ "qb-management" ]: RemoveMoney ( tostring ( Player.PlayerData . job.name ), amount ) end
2022-08-22 21:32:15 +01:00
if Reciever then
Reciever.Functions . AddMoney ( 'bank' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "sent" ] .. amount .. Loc [ Config.Lan ]. success [ "to" ] .. Reciever.PlayerData . charinfo.firstname .. " " .. Reciever.PlayerData . charinfo.lastname , "success" , src )
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "recieved" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "from" ] .. tostring ( Player.PlayerData . job.label ) .. Loc [ Config.Lan ]. success [ "account" ], "success" , Reciever.PlayerData . source )
2022-08-22 21:32:15 +01:00
else
local RecieverMoney = json.decode ( result [ 1 ]. money )
2022-09-18 15:32:10 +01:00
RecieverMoney.bank += amount
2022-08-22 21:32:15 +01:00
MySQL.Async . execute ( 'UPDATE players SET money = ? WHERE citizenid = ?' , { json.encode ( RecieverMoney ), result [ 1 ]. citizenid })
end
2022-09-02 20:04:22 +08:00
elseif not result [ 1 ] then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "error_start" ] .. baccount .. Loc [ Config.Lan ]. error [ "error_end" ], "error" , src )
2022-08-22 21:32:15 +01:00
end
end
--Simple transfers from gang society account to bank --
elseif account == "gang" then
if billtype == "withdraw" then
2022-09-02 20:04:22 +08:00
if tonumber ( gsociety ) < amount then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "soc_low" ], "error" , src )
2022-08-22 21:32:15 +01:00
elseif tonumber ( gsociety ) >= amount then
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "draw" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "fromthe" ] .. Player.PlayerData . gang.label .. Loc [ Config.Lan ]. success [ "account" ], "success" , src )
2022-08-22 21:32:15 +01:00
Player.Functions . AddMoney ( 'bank' , amount )
2023-01-28 14:05:58 +00:00
if Config.RenewedBanking then TriggerEvent ( "qb-gangmenu:server:removeAccountMoney" , tostring ( Player.PlayerData . gang.name ), amount )
else exports [ "qb-management" ]: RemoveGangMoney ( tostring ( Player.PlayerData . gang.name ), amount ) end
2022-08-22 21:32:15 +01:00
end
elseif billtype == "deposit" then
2022-09-02 20:04:22 +08:00
if bankB < amount then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "nomoney_bank" ], "error" , src )
2022-08-22 21:32:15 +01:00
elseif bankB >= amount then
2023-01-28 14:05:58 +00:00
if Config.RenewedBanking then TriggerEvent ( "qb-gangmenu:server:addAccountMoney" , tostring ( Player.PlayerData . gang.name ), amount )
else exports [ "qb-management" ]: AddGangMoney ( tostring ( Player.PlayerData . gang.name ), amount ) end
2022-08-22 21:32:15 +01:00
Player.Functions . RemoveMoney ( 'bank' , amount ) Wait ( 1500 )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "deposited" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "into" ] .. Player.PlayerData . gang.label .. Loc [ Config.Lan ]. success [ "account" ], "success" , src )
2022-08-22 21:32:15 +01:00
end
end
-- Transfer from gang account to players --
elseif account == "gangtransfer" then
local bannedCharacters = { '%' , '$' , ';' }
local newAmount = tostring ( amount )
local newiban = tostring ( baccount )
for _ , v in pairs ( bannedCharacters ) do
newAmount = string.gsub ( newAmount , '%' .. v , '' )
newiban = string.gsub ( newiban , '%' .. v , '' )
end
baccount = newiban
amount = tonumber ( newAmount )
local Player = QBCore.Functions . GetPlayer ( src )
if ( gsociety - amount ) >= 0 then
local query = '%"account":"' .. baccount .. '"%'
local result = MySQL.Sync . fetchAll ( 'SELECT * FROM players WHERE charinfo LIKE ?' , { query })
if result [ 1 ] then
local Reciever = QBCore.Functions . GetPlayerByCitizenId ( result [ 1 ]. citizenid )
2023-01-28 14:05:58 +00:00
if Config.RenewedBanking then TriggerEvent ( "qb-bossmenu:server:removeAccountMoney" , tostring ( Player.PlayerData . gang.name ), amount )
else exports [ "qb-management" ]: RemoveGangMoney ( tostring ( Player.PlayerData . gang.name ), amount ) end
2022-08-22 21:32:15 +01:00
if not Reciever then
Reciever.Functions . AddMoney ( 'bank' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "sent" ] .. amount .. Loc [ Config.Lan ]. success [ "to" ] .. Reciever.PlayerData . charinfo.firstname .. " " .. Reciever.PlayerData . charinfo.lastname , "success" , src )
triggerNotify ( nil , Reciever.PlayerData . source , Loc [ Config.Lan ]. success [ "recieved" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "from" ] .. tostring ( Player.PlayerData . gang.label ) .. Loc [ Config.Lan ]. success [ "account" ], "success" , Reciever.PlayerData . source )
2022-08-22 21:32:15 +01:00
else
local RecieverMoney = json.decode ( result [ 1 ]. money )
2022-09-18 15:32:10 +01:00
RecieverMoney.bank += amount
2022-08-22 21:32:15 +01:00
MySQL.Async . execute ( 'UPDATE players SET money = ? WHERE citizenid = ?' , { json.encode ( RecieverMoney ), result [ 1 ]. citizenid })
end
2022-09-02 20:04:22 +08:00
elseif not result [ 1 ] then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "error_start" ] .. baccount .. Loc [ Config.Lan ]. error [ "error_end" ], "error" , src )
2022-08-22 21:32:15 +01:00
end
end
elseif account == "transfer" then
local bannedCharacters = { '%' , '$' , ';' }
local newAmount = tostring ( amount )
local newiban = tostring ( baccount )
for _ , v in pairs ( bannedCharacters ) do
newAmount = string.gsub ( newAmount , '%' .. v , '' )
newiban = string.gsub ( newiban , '%' .. v , '' )
end
baccount = newiban
amount = tonumber ( newAmount )
local Player = QBCore.Functions . GetPlayer ( src )
if ( Player.PlayerData . money.bank - amount ) >= 0 then
local query = '%"account":"' .. baccount .. '"%'
local result = MySQL.Sync . fetchAll ( 'SELECT * FROM players WHERE charinfo LIKE ?' , { query })
if result [ 1 ] then
local Reciever = QBCore.Functions . GetPlayerByCitizenId ( result [ 1 ]. citizenid )
Player.Functions . RemoveMoney ( 'bank' , amount )
if Reciever then
Reciever.Functions . AddMoney ( 'bank' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "sent" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "to" ] .. Reciever.PlayerData . charinfo.firstname .. " " .. Reciever.PlayerData . charinfo.lastname , "success" , src )
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "recieved" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "from" ] .. Player.PlayerData . charinfo.firstname .. " " .. Player.PlayerData . charinfo.lastname , "success" , Reciever.PlayerData . source )
2022-08-22 21:32:15 +01:00
else
local RecieverMoney = json.decode ( result [ 1 ]. money )
2022-09-18 15:32:10 +01:00
RecieverMoney.bank += amount
2022-08-22 21:32:15 +01:00
MySQL.Async . execute ( 'UPDATE players SET money = ? WHERE citizenid = ?' , { json.encode ( RecieverMoney ), result [ 1 ]. citizenid })
end
2022-09-02 20:04:22 +08:00
elseif not result [ 1 ] then triggerNotify ( nil , Loc [ Config.Lan ]. error [ "error_start" ] .. baccount .. Loc [ Config.Lan ]. error [ "error_end" ], "error" , src )
2022-08-22 21:32:15 +01:00
end
end
end
end )
QBCore.Functions . CreateCallback ( 'jim-payments:ATM:Find' , function ( source , cb )
local Player = QBCore.Functions . GetPlayer ( source )
local name = Player.PlayerData . charinfo.firstname .. ' ' .. Player.PlayerData . charinfo.lastname
local cid = Player.PlayerData . citizenid .. " [" .. source .. "]"
local cash = Player.Functions . GetMoney ( "cash" )
local bank = Player.Functions . GetMoney ( "bank" )
local account = Player.PlayerData . charinfo.account
local society = 0
local gsociety = 0
-- If qb-management, grab info directly from database
2023-01-28 14:05:58 +00:00
if Config.RenewedBanking then
2022-08-22 21:32:15 +01:00
local result = MySQL.Sync . fetchAll ( 'SELECT * FROM management_funds' )
for _ , v in pairs ( result ) do
if Player.PlayerData . job.name == v.job_name then society = v.amount end
end
if Player.PlayerData . gang.name ~= "none" then
for _ , v in pairs ( result ) do
if Player.PlayerData . gang.name == v.job_name then gsociety = v.amount end
end
end
else
end
-- Grab Savings account info
local result = MySQL.Sync . fetchAll ( 'SELECT * FROM bank_accounts WHERE citizenid = ? AND account_type = ?' , { Player.PlayerData . citizenid , 'Savings' })
if result [ 1 ] then
accountID = result [ 1 ]. record_id
savingBalance = result [ 1 ]. amount
else
MySQL.Async . insert ( 'INSERT INTO bank_accounts (citizenid, amount, account_type) VALUES (?, ?, ?)' , { Player.PlayerData . citizenid , 0 , 'Savings' }, function () completed = true end ) repeat Wait ( 0 ) until completed == true
local result = MySQL.Sync . fetchAll ( 'SELECT * FROM bank_accounts WHERE citizenid = ? AND account_type = ?' , { Player.PlayerData . citizenid , 'Savings' })
aid = result [ 1 ]. record_id
savingBalance = result [ 1 ]. amount
end
cb ({ name = name ,
cash = cash ,
bank = bank ,
account = account ,
cid = cid ,
savbal = savingBalance ,
aid = accountID ,
society = society ,
gsociety = gsociety })
end )
2022-09-02 20:04:22 +08:00
QBCore.Commands . Add ( "cashgive" , Loc [ Config.Lan ]. command [ "pay_user" ], {}, false , function ( source ) TriggerClientEvent ( "jim-payments:client:ATM:give" , source ) end )
2022-08-22 21:32:15 +01:00
RegisterServerEvent ( "jim-payments:server:ATM:give" , function ( citizen , price )
local Player = QBCore.Functions . GetPlayer ( source )
local Reciever = QBCore.Functions . GetPlayer ( tonumber ( citizen ))
local amount = tonumber ( price )
local balance = Player.Functions . GetMoney ( "cash" )
if amount and amount > 0 then
if balance >= amount then
Player.Functions . RemoveMoney ( 'cash' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "you_gave" ] .. Reciever.PlayerData . charinfo.firstname .. " $" .. cv ( amount ), "success" , source )
2022-08-22 21:32:15 +01:00
Reciever.Functions . AddMoney ( 'cash' , amount )
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. success [ "you_got" ] .. cv ( amount ) .. Loc [ Config.Lan ]. success [ "from" ] .. Player.PlayerData . charinfo.firstname , "success" , tonumber ( citizen ))
2022-08-22 21:32:15 +01:00
elseif balance < amount then
2022-09-02 20:04:22 +08:00
triggerNotify ( nil , Loc [ Config.Lan ]. error [ "not_enough" ], "error" , source )
2022-08-22 21:32:15 +01:00
end
2022-09-02 20:04:22 +08:00
else triggerNotify ( nil , Loc [ Config.Lan ]. error [ "zero" ], 'error' , source ) end
end )
2023-01-28 14:05:58 +00:00