Update billing_client.lua
This commit is contained in:
		
							parent
							
								
									b43fa3c75e
								
							
						
					
					
						commit
						5bc835bc97
					
				
					 1 changed files with 45 additions and 10 deletions
				
			
		| 
						 | 
					@ -4,16 +4,44 @@ local QBCore = exports['qb-core']:GetCoreObject()
 | 
				
			||||||
local isUiOpen = false
 | 
					local isUiOpen = false
 | 
				
			||||||
local cooldown = false
 | 
					local cooldown = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Command to open billing menu
 | 
					-- Command to open main billing menu
 | 
				
			||||||
RegisterCommand('bill', function()
 | 
					RegisterCommand('bill', function()
 | 
				
			||||||
    OpenBillingMenu()
 | 
					    OpenMainBillingMenu()
 | 
				
			||||||
end, false)
 | 
					end, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Keybind registration
 | 
					-- Keybind registration
 | 
				
			||||||
RegisterKeyMapping('bill', 'Open Billing Menu', 'keyboard', 'F7') -- Default key is F7, can be changed in settings
 | 
					RegisterKeyMapping('bill', 'Open Billing Menu', 'keyboard', 'F7') -- Default key is F7, can be changed in settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Function to open the billing menu
 | 
					-- Function to open the main billing menu
 | 
				
			||||||
function OpenBillingMenu()
 | 
					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
 | 
					    if cooldown then
 | 
				
			||||||
        lib.notify({
 | 
					        lib.notify({
 | 
				
			||||||
            title = 'Billing System',
 | 
					            title = 'Billing System',
 | 
				
			||||||
| 
						 | 
					@ -52,12 +80,13 @@ function OpenBillingMenu()
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    -- Show the list of nearby players first
 | 
					    -- Show the list of nearby players
 | 
				
			||||||
    local playerOptions = {}
 | 
					    local playerOptions = {}
 | 
				
			||||||
    for _, player in ipairs(players) do
 | 
					    for _, player in ipairs(players) do
 | 
				
			||||||
        table.insert(playerOptions, {
 | 
					        table.insert(playerOptions, {
 | 
				
			||||||
            title = player.name,
 | 
					            title = player.name,
 | 
				
			||||||
            description = 'ID: ' .. player.id,
 | 
					            description = 'ID: ' .. player.id,
 | 
				
			||||||
 | 
					            icon = 'user',
 | 
				
			||||||
            onSelect = function()
 | 
					            onSelect = function()
 | 
				
			||||||
                -- When a player is selected, show the billing form
 | 
					                -- When a player is selected, show the billing form
 | 
				
			||||||
                ShowBillingForm(player, accountOptions)
 | 
					                ShowBillingForm(player, accountOptions)
 | 
				
			||||||
| 
						 | 
					@ -69,6 +98,7 @@ function OpenBillingMenu()
 | 
				
			||||||
    lib.registerContext({
 | 
					    lib.registerContext({
 | 
				
			||||||
        id = 'nearby_players_menu',
 | 
					        id = 'nearby_players_menu',
 | 
				
			||||||
        title = 'Select Player to Bill',
 | 
					        title = 'Select Player to Bill',
 | 
				
			||||||
 | 
					        menu = 'main_billing_menu', -- Add back button to main menu
 | 
				
			||||||
        options = playerOptions
 | 
					        options = playerOptions
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
| 
						 | 
					@ -127,6 +157,9 @@ function ShowBillingForm(selectedPlayer, accountOptions)
 | 
				
			||||||
        SetTimeout(5000, function()
 | 
					        SetTimeout(5000, function()
 | 
				
			||||||
            cooldown = false
 | 
					            cooldown = false
 | 
				
			||||||
        end)
 | 
					        end)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        -- Return to main menu
 | 
				
			||||||
 | 
					        OpenMainBillingMenu()
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        lib.notify({
 | 
					        lib.notify({
 | 
				
			||||||
            title = 'Billing System',
 | 
					            title = 'Billing System',
 | 
				
			||||||
| 
						 | 
					@ -146,6 +179,11 @@ function ViewBills()
 | 
				
			||||||
            description = 'You have no unpaid bills',
 | 
					            description = 'You have no unpaid bills',
 | 
				
			||||||
            type = 'info'
 | 
					            type = 'info'
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        -- Return to main menu after a short delay
 | 
				
			||||||
 | 
					        SetTimeout(1000, function()
 | 
				
			||||||
 | 
					            OpenMainBillingMenu()
 | 
				
			||||||
 | 
					        end)
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
| 
						 | 
					@ -155,6 +193,7 @@ function ViewBills()
 | 
				
			||||||
        table.insert(billOptions, {
 | 
					        table.insert(billOptions, {
 | 
				
			||||||
            title = bill.description,
 | 
					            title = bill.description,
 | 
				
			||||||
            description = ('Amount: $%s | Date: %s'):format(bill.amount, timestamp),
 | 
					            description = ('Amount: $%s | Date: %s'):format(bill.amount, timestamp),
 | 
				
			||||||
 | 
					            icon = 'file-invoice',
 | 
				
			||||||
            metadata = {
 | 
					            metadata = {
 | 
				
			||||||
                {label = 'Bill ID', value = bill.id},
 | 
					                {label = 'Bill ID', value = bill.id},
 | 
				
			||||||
                {label = 'Type', value = bill.type},
 | 
					                {label = 'Type', value = bill.type},
 | 
				
			||||||
| 
						 | 
					@ -192,17 +231,13 @@ function ViewBills()
 | 
				
			||||||
    lib.registerContext({
 | 
					    lib.registerContext({
 | 
				
			||||||
        id = 'billing_menu',
 | 
					        id = 'billing_menu',
 | 
				
			||||||
        title = 'Your Bills',
 | 
					        title = 'Your Bills',
 | 
				
			||||||
 | 
					        menu = 'main_billing_menu', -- Add back button to main menu
 | 
				
			||||||
        options = billOptions
 | 
					        options = billOptions
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    lib.showContext('billing_menu')
 | 
					    lib.showContext('billing_menu')
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Command to view bills
 | 
					 | 
				
			||||||
RegisterCommand('bills', function()
 | 
					 | 
				
			||||||
    ViewBills()
 | 
					 | 
				
			||||||
end, false)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
-- Helper function to get nearby players
 | 
					-- Helper function to get nearby players
 | 
				
			||||||
function GetNearbyPlayers()
 | 
					function GetNearbyPlayers()
 | 
				
			||||||
    local playerPed = PlayerPedId()
 | 
					    local playerPed = PlayerPedId()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue