diff --git a/resources/[tools]/nordi_billing/billing_client.lua b/resources/[tools]/nordi_billing/billing_client.lua index e9ed9bd47..ff0574eaf 100644 --- a/resources/[tools]/nordi_billing/billing_client.lua +++ b/resources/[tools]/nordi_billing/billing_client.lua @@ -3,6 +3,7 @@ local QBCore = exports['qb-core']:GetCoreObject() local isUiOpen = false local cooldown = false +local pendingBills = {} -- Command to open main billing menu RegisterCommand('bill', function() @@ -138,14 +139,14 @@ function ShowBillingForm(selectedPlayer, accountOptions) PlayBillingAnimation() -- Send the bill - local success = lib.callback.await('billing:server:sendBill', false, { + local billData = lib.callback.await('billing:server:sendBill', false, { playerId = selectedPlayer.id, amount = input[1], reason = input[2], account = input[3] }) - if success then + if billData and billData.success then lib.notify({ title = 'Billing System', description = 'Rechnung erfolgreich an ' .. selectedPlayer.name .. ' gesendet', @@ -158,17 +159,56 @@ function ShowBillingForm(selectedPlayer, accountOptions) cooldown = false end) - -- Return to main menu - OpenMainBillingMenu() + -- Add to pending bills + 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 lib.notify({ title = 'Billing System', description = 'Fehler beim Senden der Rechnung', type = 'error' }) + + -- Return to main menu + OpenMainBillingMenu() 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 ShowPaymentAccountSelection(billId, amount, description) -- Get player's accounts for payment @@ -390,6 +430,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) description = 'Du hast die Rechnung erfolgreich bezahlt', type = 'success' }) + + -- Notify the sender + TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'pay') else lib.notify({ title = 'Zahlung fehlgeschlagen', @@ -419,6 +462,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) description = 'Du hast die Rechnung erfolgreich bezahlt', type = 'success' }) + + -- Notify the sender + TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'pay') else lib.notify({ title = 'Zahlung fehlgeschlagen', @@ -473,6 +519,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) description = 'Du hast die Rechnung abgelehnt', type = 'info' }) + + -- Notify the sender + TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'decline') else lib.notify({ title = 'Fehler', @@ -499,6 +548,9 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) description = 'Die Rechnung wurde für später gespeichert', type = 'info' }) + + -- Notify the sender + TriggerServerEvent('billing:server:notifyBillSender', data.billId, 'later') else lib.notify({ title = 'Fehler', @@ -523,6 +575,70 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) lib.showContext('bill_payment_prompt') 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() ViewBills() 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) + +