2025-08-05 11:16:01 +02:00
|
|
|
-- Initialize QBCore
|
2025-08-05 11:15:04 +02:00
|
|
|
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
|
2025-08-05 11:11:48 +02:00
|
|
|
local isUiOpen = false
|
|
|
|
local cooldown = false
|
|
|
|
|
2025-08-05 11:19:51 +02:00
|
|
|
-- Command to open main billing menu
|
2025-08-05 11:11:48 +02:00
|
|
|
RegisterCommand('bill', function()
|
2025-08-05 11:19:51 +02:00
|
|
|
OpenMainBillingMenu()
|
2025-08-05 11:11:48 +02:00
|
|
|
end, false)
|
|
|
|
|
|
|
|
-- Keybind registration
|
|
|
|
RegisterKeyMapping('bill', 'Open Billing Menu', 'keyboard', 'F7') -- Default key is F7, can be changed in settings
|
|
|
|
|
2025-08-05 11:19:51 +02:00
|
|
|
-- Function to open the main billing menu
|
|
|
|
function OpenMainBillingMenu()
|
|
|
|
lib.registerContext({
|
|
|
|
id = 'main_billing_menu',
|
|
|
|
title = 'Billing System',
|
|
|
|
options = {
|
|
|
|
{
|
2025-08-05 11:23:12 +02:00
|
|
|
title = 'Rechnung erstellen',
|
|
|
|
description = 'Sende eine Rechnung an einen Spieler in der Nähe',
|
2025-08-05 11:19:51 +02:00
|
|
|
icon = 'file-invoice-dollar',
|
|
|
|
onSelect = function()
|
|
|
|
OpenCreateBillMenu()
|
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
2025-08-05 11:23:12 +02:00
|
|
|
title = 'Meine Rechnungen',
|
|
|
|
description = 'Sehe & bezahle deine erhaltenen Rechnungen',
|
2025-08-05 11:19:51 +02:00
|
|
|
icon = 'money-check',
|
|
|
|
onSelect = function()
|
|
|
|
ViewBills()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
lib.showContext('main_billing_menu')
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Function to open the create bill menu
|
|
|
|
function OpenCreateBillMenu()
|
2025-08-05 11:11:48 +02:00
|
|
|
if cooldown then
|
|
|
|
lib.notify({
|
|
|
|
title = 'Billing System',
|
|
|
|
description = 'Please wait before using the billing system again',
|
|
|
|
type = 'error'
|
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Get nearby players
|
|
|
|
local players = GetNearbyPlayers()
|
|
|
|
if #players == 0 then
|
|
|
|
lib.notify({
|
|
|
|
title = 'Billing System',
|
|
|
|
description = 'No players nearby to bill',
|
|
|
|
type = 'error'
|
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Get player's accounts for receiving payment
|
|
|
|
local accounts = lib.callback.await('ps-banking:server:getAccounts', false) or {}
|
|
|
|
local accountOptions = {}
|
|
|
|
|
|
|
|
-- Add default bank account
|
|
|
|
table.insert(accountOptions, {
|
|
|
|
value = 'personal',
|
|
|
|
label = 'Personal Bank Account'
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Add other accounts
|
|
|
|
for _, account in ipairs(accounts) do
|
|
|
|
table.insert(accountOptions, {
|
|
|
|
value = account.id,
|
|
|
|
label = account.holder .. ' - ' .. account.cardNumber
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2025-08-05 11:19:51 +02:00
|
|
|
-- Show the list of nearby players
|
2025-08-05 11:11:48 +02:00
|
|
|
local playerOptions = {}
|
|
|
|
for _, player in ipairs(players) do
|
|
|
|
table.insert(playerOptions, {
|
2025-08-05 11:16:01 +02:00
|
|
|
title = player.name,
|
|
|
|
description = 'ID: ' .. player.id,
|
2025-08-05 11:19:51 +02:00
|
|
|
icon = 'user',
|
2025-08-05 11:16:01 +02:00
|
|
|
onSelect = function()
|
|
|
|
-- When a player is selected, show the billing form
|
|
|
|
ShowBillingForm(player, accountOptions)
|
|
|
|
end
|
2025-08-05 11:11:48 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2025-08-05 11:16:01 +02:00
|
|
|
-- Register and show the player selection menu
|
|
|
|
lib.registerContext({
|
|
|
|
id = 'nearby_players_menu',
|
|
|
|
title = 'Select Player to Bill',
|
2025-08-05 11:19:51 +02:00
|
|
|
menu = 'main_billing_menu', -- Add back button to main menu
|
2025-08-05 11:16:01 +02:00
|
|
|
options = playerOptions
|
|
|
|
})
|
|
|
|
|
|
|
|
lib.showContext('nearby_players_menu')
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Function to show the billing form after selecting a player
|
|
|
|
function ShowBillingForm(selectedPlayer, accountOptions)
|
|
|
|
local input = lib.inputDialog('Create Bill for ' .. selectedPlayer.name, {
|
2025-08-05 11:11:48 +02:00
|
|
|
{
|
|
|
|
type = 'number',
|
|
|
|
label = 'Amount ($)',
|
|
|
|
description = 'Enter the bill amount',
|
|
|
|
icon = 'dollar-sign',
|
|
|
|
required = true,
|
|
|
|
min = 1,
|
|
|
|
max = 100000
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type = 'input',
|
|
|
|
label = 'Reason',
|
|
|
|
description = 'Enter the reason for the bill',
|
|
|
|
placeholder = 'Services provided...',
|
|
|
|
required = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type = 'select',
|
|
|
|
label = 'Receiving Account',
|
|
|
|
options = accountOptions,
|
|
|
|
required = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if not input then return end
|
|
|
|
|
|
|
|
-- Play animation
|
|
|
|
PlayBillingAnimation()
|
|
|
|
|
|
|
|
-- Send the bill
|
|
|
|
local success = lib.callback.await('billing:server:sendBill', false, {
|
2025-08-05 11:16:01 +02:00
|
|
|
playerId = selectedPlayer.id,
|
|
|
|
amount = input[1],
|
|
|
|
reason = input[2],
|
|
|
|
account = input[3]
|
2025-08-05 11:11:48 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if success then
|
|
|
|
lib.notify({
|
|
|
|
title = 'Billing System',
|
2025-08-05 11:16:01 +02:00
|
|
|
description = 'Bill sent successfully to ' .. selectedPlayer.name,
|
2025-08-05 11:11:48 +02:00
|
|
|
type = 'success'
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Set cooldown
|
|
|
|
cooldown = true
|
|
|
|
SetTimeout(5000, function()
|
|
|
|
cooldown = false
|
|
|
|
end)
|
2025-08-05 11:19:51 +02:00
|
|
|
|
|
|
|
-- Return to main menu
|
|
|
|
OpenMainBillingMenu()
|
2025-08-05 11:11:48 +02:00
|
|
|
else
|
|
|
|
lib.notify({
|
|
|
|
title = 'Billing System',
|
|
|
|
description = 'Failed to send bill',
|
|
|
|
type = 'error'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Function to view received bills
|
|
|
|
function ViewBills()
|
|
|
|
local bills = lib.callback.await('ps-banking:server:getBills', false)
|
|
|
|
|
|
|
|
if not bills or #bills == 0 then
|
|
|
|
lib.notify({
|
|
|
|
title = 'Billing System',
|
|
|
|
description = 'You have no unpaid bills',
|
|
|
|
type = 'info'
|
|
|
|
})
|
2025-08-05 11:19:51 +02:00
|
|
|
|
|
|
|
-- Return to main menu after a short delay
|
|
|
|
SetTimeout(1000, function()
|
|
|
|
OpenMainBillingMenu()
|
|
|
|
end)
|
2025-08-05 11:11:48 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local billOptions = {}
|
|
|
|
for _, bill in ipairs(bills) do
|
|
|
|
local timestamp = os.date('%Y-%m-%d %H:%M', bill.date)
|
|
|
|
table.insert(billOptions, {
|
|
|
|
title = bill.description,
|
|
|
|
description = ('Amount: $%s | Date: %s'):format(bill.amount, timestamp),
|
2025-08-05 11:19:51 +02:00
|
|
|
icon = 'file-invoice',
|
2025-08-05 11:11:48 +02:00
|
|
|
metadata = {
|
|
|
|
{label = 'Bill ID', value = bill.id},
|
|
|
|
{label = 'Type', value = bill.type},
|
|
|
|
{label = 'Status', value = bill.isPaid and 'Paid' or 'Unpaid'}
|
|
|
|
},
|
|
|
|
onSelect = function()
|
|
|
|
local confirm = lib.alertDialog({
|
|
|
|
header = 'Pay Bill',
|
|
|
|
content = ('Do you want to pay $%s for %s?'):format(bill.amount, bill.description),
|
|
|
|
centered = true,
|
|
|
|
cancel = true
|
|
|
|
})
|
|
|
|
|
|
|
|
if confirm == 'confirm' then
|
|
|
|
local success = lib.callback.await('ps-banking:server:payBill', false, bill.id)
|
|
|
|
if success then
|
|
|
|
lib.notify({
|
|
|
|
title = 'Billing System',
|
|
|
|
description = 'Bill paid successfully',
|
|
|
|
type = 'success'
|
|
|
|
})
|
|
|
|
ViewBills() -- Refresh the list
|
|
|
|
else
|
|
|
|
lib.notify({
|
|
|
|
title = 'Billing System',
|
|
|
|
description = 'Failed to pay bill. Insufficient funds.',
|
|
|
|
type = 'error'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
lib.registerContext({
|
|
|
|
id = 'billing_menu',
|
|
|
|
title = 'Your Bills',
|
2025-08-05 11:19:51 +02:00
|
|
|
menu = 'main_billing_menu', -- Add back button to main menu
|
2025-08-05 11:11:48 +02:00
|
|
|
options = billOptions
|
|
|
|
})
|
|
|
|
|
|
|
|
lib.showContext('billing_menu')
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Helper function to get nearby players
|
|
|
|
function GetNearbyPlayers()
|
|
|
|
local playerPed = PlayerPedId()
|
2025-08-05 11:16:01 +02:00
|
|
|
local playerCoords = GetEntityCoords(playerPed)
|
|
|
|
local players = {}
|
2025-08-05 11:11:48 +02:00
|
|
|
|
2025-08-05 11:16:01 +02:00
|
|
|
-- Get all players
|
|
|
|
local allPlayers = GetActivePlayers()
|
|
|
|
|
|
|
|
for _, player in ipairs(allPlayers) do
|
2025-08-05 11:11:48 +02:00
|
|
|
local targetPed = GetPlayerPed(player)
|
|
|
|
local targetCoords = GetEntityCoords(targetPed)
|
2025-08-05 11:16:01 +02:00
|
|
|
local distance = #(playerCoords - targetCoords)
|
2025-08-05 11:11:48 +02:00
|
|
|
|
|
|
|
if distance <= 5.0 and targetPed ~= playerPed then
|
|
|
|
local targetId = GetPlayerServerId(player)
|
|
|
|
local targetName = GetPlayerName(player)
|
2025-08-05 11:16:01 +02:00
|
|
|
table.insert(players, {id = targetId, name = targetName})
|
2025-08-05 11:11:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-08-05 11:16:01 +02:00
|
|
|
return players
|
2025-08-05 11:11:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Animation function
|
|
|
|
function PlayBillingAnimation()
|
|
|
|
lib.requestAnimDict("cellphone@")
|
|
|
|
|
|
|
|
-- Request the prop model
|
|
|
|
local propModel = 'bzzz_prop_payment_terminal'
|
|
|
|
lib.requestModel(propModel)
|
|
|
|
|
|
|
|
-- Create prop
|
|
|
|
local playerPed = PlayerPedId()
|
|
|
|
local coords = GetEntityCoords(playerPed)
|
|
|
|
local prop = CreateObject(GetHashKey(propModel), coords.x, coords.y, coords.z, true, true, true)
|
|
|
|
|
|
|
|
-- Attach prop to player
|
|
|
|
AttachEntityToEntity(prop, playerPed, GetPedBoneIndex(playerPed, 57005),
|
|
|
|
0.18, 0.01, 0.0, -54.0, 220.0, 43.0,
|
|
|
|
true, true, false, true, 1, true)
|
|
|
|
|
|
|
|
-- Play animation
|
|
|
|
TaskPlayAnim(playerPed, "cellphone@", "cellphone_text_read_base", 2.0, 3.0, -1, 49, 0, false, false, false)
|
|
|
|
|
|
|
|
-- Wait for animation to complete
|
|
|
|
Wait(5000)
|
|
|
|
|
|
|
|
-- Clear animation and delete prop
|
|
|
|
ClearPedTasks(playerPed)
|
|
|
|
DeleteEntity(prop)
|
|
|
|
end
|