2022-02-05 15:44:29 +00:00
local QBCore = exports [ ' qb-core ' ] : GetCoreObject ( )
2022-02-20 15:30:15 +00:00
local function cv ( amount )
local formatted = amount
2022-05-04 10:17:43 +01:00
while true do formatted , k = string.gsub ( formatted , " ^(-?%d+)(%d%d%d) " , ' %1,%2 ' ) if ( k == 0 ) then break end Wait ( 0 ) end
2022-02-20 15:30:15 +00:00
return formatted
end
2022-05-21 11:36:51 +01:00
AddEventHandler ( ' onResourceStart ' , function ( resource ) if GetCurrentResourceName ( ) ~= resource then return end
for k , v in pairs ( Config.Jobs ) do if not QBCore.Shared . Jobs [ k ] then print ( " Jim-Payments: Config.Jobs searched for job ' " .. k .. " ' and couldn't find it in the Shared " ) end end
2022-04-25 10:01:51 +01:00
end )
2022-05-05 21:34:34 +01:00
QBCore.Commands . Add ( " cashregister " , " Use mobile cash register " , { } , false , function ( source ) TriggerClientEvent ( " jim-payments:client:Charge " , source , { } , true ) end )
2022-02-20 15:30:15 +00:00
2022-06-06 20:42:02 +01:00
RegisterServerEvent ( ' jim-payments:Tickets:Give ' , function ( data , biller , popup )
if biller then -- If this is found, it ISN'T a phone payment, so add money to society here
if Config.Manage then exports [ " qb-management " ] : AddMoney ( tostring ( biller.PlayerData . job.name ) , data.amount )
if Config.Debug then print ( " QB-Management: Adding $ " .. data.amount .. " to account ' " .. tostring ( biller.PlayerData . job.name ) .. " ' " ) end
else TriggerEvent ( " qb-bossmenu:server:addAccountMoney " , tostring ( biller.PlayerData . job.name ) , data.amount )
if Config.Debug then print ( " QB-BossMenu: Adding $ " .. data.amount .. " to account ' " .. tostring ( biller.PlayerData . job.name ) .. " ' " ) end
end
elseif not biller then --Find the biller from their citizenid
2022-02-20 15:30:15 +00:00
for k , v in pairs ( QBCore.Functions . GetPlayers ( ) ) do
2022-04-11 18:59:47 +01:00
local Player = QBCore.Functions . GetPlayer ( v )
if Player.PlayerData . citizenid == data.senderCitizenId then biller = Player end
end
2022-05-18 11:18:07 +01:00
TriggerClientEvent ( ' QBCore:Notify ' , biller.PlayerData . source , data.sender .. " Paid their $ " .. data.amount .. " invoice " , " success " )
2022-04-11 18:59:47 +01:00
end
2022-06-06 20:42:02 +01:00
2022-05-05 21:34:34 +01:00
local duty = true
if biller.PlayerData . job.onduty then duty = true else duty = false end
2022-06-06 20:42:02 +01:00
2022-04-15 18:25:27 +01:00
-- If ticket system enabled, do this
2022-05-05 21:34:34 +01:00
if duty and Config.TicketSystem then
2022-04-11 18:59:47 +01:00
if data.amount >= Config.Jobs [ data.society ] . MinAmountforTicket then
for k , v in pairs ( QBCore.Functions . GetPlayers ( ) ) do
local Player = QBCore.Functions . GetPlayer ( v )
if Player ~= nil then
if Player.PlayerData . job.name == data.society and Player.PlayerData . job.onduty then
2022-02-20 15:30:15 +00:00
Player.Functions . AddItem ( ' payticket ' , 1 , false , { [ " quality " ] = nil } )
TriggerClientEvent ( ' QBCore:Notify ' , Player.PlayerData . source , ' Receipt received ' , ' success ' )
TriggerClientEvent ( ' inventory:client:ItemBox ' , Player.PlayerData . source , QBCore.Shared . Items [ ' payticket ' ] , " add " , 1 )
2022-04-11 18:59:47 +01:00
end
end
end
end
end
-- Commission section, does each config option separately
local comm = tonumber ( Config.Jobs [ data.society ] . Commission )
if Config.Commission and comm ~= 0 then
if Config.CommissionLimit and data.amount < Config.Jobs [ data.society ] . MinAmountforTicket then return end
if Config.CommissionDouble then
biller.Functions . AddMoney ( " bank " , math.floor ( tonumber ( data.amount ) * ( comm * 2 ) ) )
TriggerClientEvent ( " QBCore:Notify " , biller.PlayerData . source , " Recieved $ " .. math.floor ( tonumber ( data.amount ) * ( comm * 2 ) ) .. " in Commission " , " success " )
else biller.Functions . AddMoney ( " bank " , math.floor ( tonumber ( data.amount ) * comm ) )
TriggerClientEvent ( " QBCore:Notify " , biller.PlayerData . source , " Recieved $ " .. math.floor ( tonumber ( data.amount ) * comm ) .. " in Commission " , " success " )
end
if Config.CommissionAll then
for k , v in pairs ( QBCore.Functions . GetPlayers ( ) ) do
local Player = QBCore.Functions . GetPlayer ( v )
if Player ~= nil and Player ~= biller then
if Player.PlayerData . job.name == data.society and Player.PlayerData . job.onduty then
Player.Functions . AddMoney ( " bank " , math.floor ( tonumber ( data.amount ) * comm ) )
TriggerClientEvent ( " QBCore:Notify " , Player.PlayerData . source , " Recieved $ " .. math.floor ( tonumber ( data.amount ) * comm ) .. " in Commission " , " success " )
2022-02-20 15:30:15 +00:00
end
end
end
end
end
2022-05-04 10:17:43 +01:00
2022-02-05 15:44:29 +00:00
end )
2022-02-11 18:29:47 +00:00
RegisterServerEvent ( ' jim-payments:Tickets:Sell ' , function ( )
2022-02-05 15:44:29 +00:00
local Player = QBCore.Functions . GetPlayer ( source )
if Player.Functions . GetItemByName ( " payticket " ) == nil then TriggerClientEvent ( ' QBCore:Notify ' , source , " No tickets to trade " , ' error ' ) return
else
tickets = Player.Functions . GetItemByName ( " payticket " ) . amount
Player.Functions . RemoveItem ( ' payticket ' , tickets )
2022-02-05 20:15:02 +00:00
pay = ( tickets * Config.Jobs [ Player.PlayerData . job.name ] . PayPerTicket )
2022-02-05 20:02:29 +00:00
Player.Functions . AddMoney ( ' bank ' , pay , ' ticket-payment ' )
2022-02-05 15:44:29 +00:00
TriggerClientEvent ( ' inventory:client:ItemBox ' , source , QBCore.Shared . Items [ ' payticket ' ] , " remove " , tickets )
2022-02-20 15:30:15 +00:00
TriggerClientEvent ( ' QBCore:Notify ' , source , " Tickets traded: " .. tickets .. " Total: $ " .. cv ( pay ) , ' success ' )
2022-02-05 15:44:29 +00:00
end
end )
2022-02-09 12:55:49 +00:00
QBCore.Functions . CreateCallback ( ' jim-payments:Ticket:Count ' , function ( source , cb )
if QBCore.Functions . GetPlayer ( source ) . Functions.GetItemByName ( ' payticket ' ) == nil then amount = 0
else amount = QBCore.Functions . GetPlayer ( source ) . Functions.GetItemByName ( ' payticket ' ) . amount end
cb ( amount )
end )
2022-05-18 11:18:07 +01:00
RegisterServerEvent ( " jim-payments:server:Charge " , function ( citizen , price , billtype , img , outside )
2022-03-11 00:30:49 +00:00
local src = source
local biller = QBCore.Functions . GetPlayer ( src )
2022-02-05 15:44:29 +00:00
local billed = QBCore.Functions . GetPlayer ( tonumber ( citizen ) )
local amount = tonumber ( price )
2022-04-11 18:59:47 +01:00
local balance = billed.Functions . GetMoney ( billtype )
2022-02-11 18:29:47 +00:00
if amount and amount > 0 then
2022-04-11 18:59:47 +01:00
if balance < amount then
TriggerClientEvent ( " QBCore:Notify " , src , " Customer doesn't have enough cash to pay " , " error " )
TriggerClientEvent ( " QBCore:Notify " , tonumber ( citizen ) , " You don't have enough cash to pay " , " error " )
return
end
if billtype == " cash " then
2022-04-12 21:10:48 +01:00
TriggerClientEvent ( " jim-payments:client:PayPopup " , billed.PlayerData . source , amount , src , billtype , img , biller.PlayerData . job.label )
2022-04-06 22:30:26 +01:00
elseif billtype == " bank " then
2022-03-11 00:30:49 +00:00
if Config.PhoneBank == false then
2022-04-12 21:10:48 +01:00
TriggerClientEvent ( " jim-payments:client:PayPopup " , billed.PlayerData . source , amount , src , billtype , img , biller.PlayerData . job.label )
2022-03-11 00:30:49 +00:00
else
2022-04-21 19:53:48 +01:00
if Config.PhoneType == " qb " then
MySQL.Async . insert (
' INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?) ' ,
{ billed.PlayerData . citizenid , amount , biller.PlayerData . job.name , biller.PlayerData . charinfo.firstname , biller.PlayerData . citizenid } )
TriggerClientEvent ( ' qb-phone:RefreshPhone ' , billed.PlayerData . source )
elseif Config.PhoneType == " gks " then
2022-05-23 17:19:49 +01:00
MySQL.Async . execute ( ' INSERT INTO gksphone_invoices (citizenid, amount, society, sender, sendercitizenid, label) VALUES (@citizenid, @amount, @society, @sender, @sendercitizenid, @label) ' , {
[ ' @citizenid ' ] = billed.PlayerData . citizenid ,
[ ' @amount ' ] = amount ,
[ ' @society ' ] = biller.PlayerData . job.name ,
[ ' @sender ' ] = biller.PlayerData . charinfo.firstname ,
[ ' @sendercitizenid ' ] = biller.PlayerData . citizenid ,
[ ' @label ' ] = biller.PlayerData . job.label ,
} )
TriggerClientEvent ( ' gksphone:notifi ' , src , { title = ' Billing ' , message = ' Invoice Successfully Sent ' , img = ' /html/static/img/icons/logo.png ' } )
TriggerClientEvent ( ' gksphone:notifi ' , billed.PlayerData . source , { title = ' Billing ' , message = ' New Invoice Recieved ' , img = ' /html/static/img/icons/logo.png ' } )
2022-04-21 19:53:48 +01:00
end
2022-03-11 00:30:49 +00:00
TriggerClientEvent ( ' QBCore:Notify ' , src , ' Invoice Successfully Sent ' , ' success ' )
TriggerClientEvent ( ' QBCore:Notify ' , billed.PlayerData . source , ' New Invoice Received ' )
end
2022-02-05 15:44:29 +00:00
end
2022-02-11 18:29:47 +00:00
else TriggerClientEvent ( ' QBCore:Notify ' , source , " You can't charge $0 " , ' error ' ) return end
2022-02-05 15:44:29 +00:00
end )
2022-02-09 12:55:49 +00:00
2022-03-11 00:30:49 +00:00
RegisterServerEvent ( " jim-payments:server:PayPopup " , function ( data )
local src = source
2022-04-03 20:41:07 +01:00
local billed = QBCore.Functions . GetPlayer ( src )
local biller = QBCore.Functions . GetPlayer ( tonumber ( data.biller ) )
2022-04-11 18:59:47 +01:00
local newdata = { senderCitizenId = biller.PlayerData . citizenid , society = biller.PlayerData . job.name , amount = data.amount }
2022-03-11 00:30:49 +00:00
if data.accept == true then
2022-04-15 18:25:27 +01:00
billed.Functions . RemoveMoney ( tostring ( data.billtype ) , data.amount )
2022-04-11 18:59:47 +01:00
TriggerEvent ( ' jim-payments:Tickets:Give ' , newdata , biller )
2022-05-18 11:18:07 +01:00
TriggerClientEvent ( " QBCore:Notify " , data.biller , billed.PlayerData . charinfo.firstname .. " accepted the $ " .. data.amount .. " payment " , " success " )
2022-03-11 00:30:49 +00:00
elseif data.accept == false then
TriggerClientEvent ( " QBCore:Notify " , src , " You declined the payment " )
2022-05-18 11:18:07 +01:00
TriggerClientEvent ( " QBCore:Notify " , data.biller , billed.PlayerData . charinfo.firstname .. " declined the $ " .. data.amount .. " payment " , " error " )
2022-03-11 00:30:49 +00:00
end
end )
2022-02-17 12:44:17 +00:00
QBCore.Functions . CreateCallback ( ' jim-payments:MakePlayerList ' , function ( source , cb )
local onlineList = { }
for k , v in pairs ( QBCore.Functions . GetPlayers ( ) ) do
2022-02-17 16:36:16 +00:00
local P = QBCore.Functions . GetPlayer ( v )
onlineList [ # onlineList + 1 ] = { value = tonumber ( v ) , text = " [ " .. v .. " ] - " .. P.PlayerData . charinfo.firstname .. ' ' .. P.PlayerData . charinfo.lastname }
2022-02-17 12:44:17 +00:00
end
cb ( onlineList )
2022-05-18 11:18:07 +01:00
end )