forked from Simnation/Main
ed
This commit is contained in:
parent
693bd8b898
commit
6875b8a071
1 changed files with 120 additions and 4 deletions
|
@ -3,6 +3,7 @@ local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
local isUiOpen = false
|
local isUiOpen = false
|
||||||
local cooldown = false
|
local cooldown = false
|
||||||
|
local pendingBills = {}
|
||||||
|
|
||||||
-- Command to open main billing menu
|
-- Command to open main billing menu
|
||||||
RegisterCommand('bill', function()
|
RegisterCommand('bill', function()
|
||||||
|
@ -138,14 +139,14 @@ function ShowBillingForm(selectedPlayer, accountOptions)
|
||||||
PlayBillingAnimation()
|
PlayBillingAnimation()
|
||||||
|
|
||||||
-- Send the bill
|
-- Send the bill
|
||||||
local success = lib.callback.await('billing:server:sendBill', false, {
|
local billData = lib.callback.await('billing:server:sendBill', false, {
|
||||||
playerId = selectedPlayer.id,
|
playerId = selectedPlayer.id,
|
||||||
amount = input[1],
|
amount = input[1],
|
||||||
reason = input[2],
|
reason = input[2],
|
||||||
account = input[3]
|
account = input[3]
|
||||||
})
|
})
|
||||||
|
|
||||||
if success then
|
if billData and billData.success then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Billing System',
|
title = 'Billing System',
|
||||||
description = 'Rechnung erfolgreich an ' .. selectedPlayer.name .. ' gesendet',
|
description = 'Rechnung erfolgreich an ' .. selectedPlayer.name .. ' gesendet',
|
||||||
|
@ -158,17 +159,56 @@ function ShowBillingForm(selectedPlayer, accountOptions)
|
||||||
cooldown = false
|
cooldown = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Return to main menu
|
-- Add to pending bills
|
||||||
OpenMainBillingMenu()
|
pendingBills[billData.billId] = {
|
||||||
|
player = selectedPlayer,
|
||||||
|
amount = input[1],
|
||||||
|
reason = input[2],
|
||||||
|
account = input[3],
|
||||||
|
timestamp = GetGameTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Show waiting screen
|
||||||
|
ShowWaitingScreen(billData.billId, selectedPlayer.name)
|
||||||
else
|
else
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Billing System',
|
title = 'Billing System',
|
||||||
description = 'Fehler beim Senden der Rechnung',
|
description = 'Fehler beim Senden der Rechnung',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Return to main menu
|
||||||
|
OpenMainBillingMenu()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Function to show waiting screen
|
||||||
|
function ShowWaitingScreen(billId, playerName)
|
||||||
|
lib.registerContext({
|
||||||
|
id = 'bill_waiting_screen',
|
||||||
|
title = 'Warte auf Antwort',
|
||||||
|
options = {
|
||||||
|
{
|
||||||
|
title = 'Rechnung gesendet',
|
||||||
|
description = 'Warte auf Antwort von ' .. playerName,
|
||||||
|
icon = 'clock',
|
||||||
|
disabled = true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = 'Abbrechen',
|
||||||
|
description = 'Zurück zum Hauptmenü',
|
||||||
|
icon = 'times-circle',
|
||||||
|
onSelect = function()
|
||||||
|
pendingBills[billId] = nil
|
||||||
|
OpenMainBillingMenu()
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
lib.showContext('bill_waiting_screen')
|
||||||
|
end
|
||||||
|
|
||||||
-- Function to show payment account selection
|
-- Function to show payment account selection
|
||||||
function ShowPaymentAccountSelection(billId, amount, description)
|
function ShowPaymentAccountSelection(billId, amount, description)
|
||||||
-- Get player's accounts for payment
|
-- Get player's accounts for payment
|
||||||
|
@ -390,6 +430,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data)
|
||||||
description = 'Du hast die Rechnung erfolgreich bezahlt',
|
description = 'Du hast die Rechnung erfolgreich bezahlt',
|
||||||
type = 'success'
|
type = 'success'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Notify the sender
|
||||||
|
TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'pay')
|
||||||
else
|
else
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Zahlung fehlgeschlagen',
|
title = 'Zahlung fehlgeschlagen',
|
||||||
|
@ -419,6 +462,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data)
|
||||||
description = 'Du hast die Rechnung erfolgreich bezahlt',
|
description = 'Du hast die Rechnung erfolgreich bezahlt',
|
||||||
type = 'success'
|
type = 'success'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Notify the sender
|
||||||
|
TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'pay')
|
||||||
else
|
else
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Zahlung fehlgeschlagen',
|
title = 'Zahlung fehlgeschlagen',
|
||||||
|
@ -473,6 +519,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data)
|
||||||
description = 'Du hast die Rechnung abgelehnt',
|
description = 'Du hast die Rechnung abgelehnt',
|
||||||
type = 'info'
|
type = 'info'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Notify the sender
|
||||||
|
TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'decline')
|
||||||
else
|
else
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Fehler',
|
title = 'Fehler',
|
||||||
|
@ -499,6 +548,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data)
|
||||||
description = 'Die Rechnung wurde für später gespeichert',
|
description = 'Die Rechnung wurde für später gespeichert',
|
||||||
type = 'info'
|
type = 'info'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Notify the sender
|
||||||
|
TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'later')
|
||||||
else
|
else
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Fehler',
|
title = 'Fehler',
|
||||||
|
@ -523,6 +575,70 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data)
|
||||||
lib.showContext('bill_payment_prompt')
|
lib.showContext('bill_payment_prompt')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Event to handle bill response
|
||||||
|
RegisterNetEvent('billing:client:billResponse', function(billId, action, playerName)
|
||||||
|
-- Check if this bill is in our pending bills
|
||||||
|
if pendingBills[billId] then
|
||||||
|
local bill = pendingBills[billId]
|
||||||
|
|
||||||
|
if action == 'pay' then
|
||||||
|
lib.notify({
|
||||||
|
title = 'Rechnung bezahlt',
|
||||||
|
description = playerName .. ' hat deine Rechnung über $' .. bill.amount .. ' bezahlt',
|
||||||
|
type = 'success'
|
||||||
|
})
|
||||||
|
elseif action == 'decline' then
|
||||||
|
lib.notify({
|
||||||
|
title = 'Rechnung abgelehnt',
|
||||||
|
description = playerName .. ' hat deine Rechnung über $' .. bill.amount .. ' abgelehnt',
|
||||||
|
type = 'error'
|
||||||
|
})
|
||||||
|
elseif action == 'later' then
|
||||||
|
lib.notify({
|
||||||
|
title = 'Rechnung gespeichert',
|
||||||
|
description = playerName .. ' wird deine Rechnung später bezahlen',
|
||||||
|
type = 'info'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remove from pending bills
|
||||||
|
pendingBills[billId] = nil
|
||||||
|
|
||||||
|
-- Return to main menu
|
||||||
|
OpenMainBillingMenu()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Event handler for opening bills menu from command
|
||||||
RegisterNetEvent('billing:client:openBillsMenu', function()
|
RegisterNetEvent('billing:client:openBillsMenu', function()
|
||||||
ViewBills()
|
ViewBills()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Check for timed out bills every minute
|
||||||
|
Citizen.CreateThread(function()
|
||||||
|
while true do
|
||||||
|
Citizen.Wait(60000) -- Check every minute
|
||||||
|
|
||||||
|
local currentTime = GetGameTimer()
|
||||||
|
local timeoutBills = {}
|
||||||
|
|
||||||
|
for billId, bill in pairs(pendingBills) do
|
||||||
|
-- If bill is older than 5 minutes, consider it timed out
|
||||||
|
if (currentTime - bill.timestamp) > 300000 then
|
||||||
|
table.insert(timeoutBills, billId)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clean up timed out bills
|
||||||
|
for _, billId in ipairs(timeoutBills) do
|
||||||
|
lib.notify({
|
||||||
|
title = 'Rechnung Timeout',
|
||||||
|
description = 'Keine Antwort von ' .. pendingBills[billId].player.name .. ' erhalten',
|
||||||
|
type = 'warning'
|
||||||
|
})
|
||||||
|
pendingBills[billId] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue