From 5bc835bc97bf0be808c6420efa2cd320049612ce Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Tue, 5 Aug 2025 11:19:51 +0200 Subject: [PATCH] Update billing_client.lua --- .../[tools]/nordi_billing/billing_client.lua | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/resources/[tools]/nordi_billing/billing_client.lua b/resources/[tools]/nordi_billing/billing_client.lua index a4ddbbd4b..d68dea435 100644 --- a/resources/[tools]/nordi_billing/billing_client.lua +++ b/resources/[tools]/nordi_billing/billing_client.lua @@ -4,16 +4,44 @@ local QBCore = exports['qb-core']:GetCoreObject() local isUiOpen = false local cooldown = false --- Command to open billing menu +-- Command to open main billing menu RegisterCommand('bill', function() - OpenBillingMenu() + OpenMainBillingMenu() end, false) -- Keybind registration RegisterKeyMapping('bill', 'Open Billing Menu', 'keyboard', 'F7') -- Default key is F7, can be changed in settings --- Function to open the billing menu -function OpenBillingMenu() +-- Function to open the main billing menu +function OpenMainBillingMenu() + lib.registerContext({ + id = 'main_billing_menu', + title = 'Billing System', + options = { + { + title = 'Create Bill', + description = 'Send a bill to a nearby player', + icon = 'file-invoice-dollar', + onSelect = function() + OpenCreateBillMenu() + end + }, + { + title = 'My Bills', + description = 'View and pay your received bills', + icon = 'money-check', + onSelect = function() + ViewBills() + end + } + } + }) + + lib.showContext('main_billing_menu') +end + +-- Function to open the create bill menu +function OpenCreateBillMenu() if cooldown then lib.notify({ title = 'Billing System', @@ -52,12 +80,13 @@ function OpenBillingMenu() }) end - -- Show the list of nearby players first + -- Show the list of nearby players local playerOptions = {} for _, player in ipairs(players) do table.insert(playerOptions, { title = player.name, description = 'ID: ' .. player.id, + icon = 'user', onSelect = function() -- When a player is selected, show the billing form ShowBillingForm(player, accountOptions) @@ -69,6 +98,7 @@ function OpenBillingMenu() lib.registerContext({ id = 'nearby_players_menu', title = 'Select Player to Bill', + menu = 'main_billing_menu', -- Add back button to main menu options = playerOptions }) @@ -127,6 +157,9 @@ function ShowBillingForm(selectedPlayer, accountOptions) SetTimeout(5000, function() cooldown = false end) + + -- Return to main menu + OpenMainBillingMenu() else lib.notify({ title = 'Billing System', @@ -146,6 +179,11 @@ function ViewBills() description = 'You have no unpaid bills', type = 'info' }) + + -- Return to main menu after a short delay + SetTimeout(1000, function() + OpenMainBillingMenu() + end) return end @@ -155,6 +193,7 @@ function ViewBills() table.insert(billOptions, { title = bill.description, description = ('Amount: $%s | Date: %s'):format(bill.amount, timestamp), + icon = 'file-invoice', metadata = { {label = 'Bill ID', value = bill.id}, {label = 'Type', value = bill.type}, @@ -192,17 +231,13 @@ function ViewBills() lib.registerContext({ id = 'billing_menu', title = 'Your Bills', + menu = 'main_billing_menu', -- Add back button to main menu options = billOptions }) lib.showContext('billing_menu') end --- Command to view bills -RegisterCommand('bills', function() - ViewBills() -end, false) - -- Helper function to get nearby players function GetNearbyPlayers() local playerPed = PlayerPedId()