diff --git a/resources/[tools]/nordi_billing/billing_client.lua b/resources/[tools]/nordi_billing/billing_client.lua index 7015e5c19..e9ed9bd47 100644 --- a/resources/[tools]/nordi_billing/billing_client.lua +++ b/resources/[tools]/nordi_billing/billing_client.lua @@ -473,6 +473,12 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) description = 'Du hast die Rechnung abgelehnt', type = 'info' }) + else + lib.notify({ + title = 'Fehler', + description = 'Fehler beim Ablehnen der Rechnung', + type = 'error' + }) end end end @@ -482,16 +488,24 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) description = 'Rechnung für später speichern', icon = 'clock', onSelect = function() - lib.callback.await('billing:server:handleBillResponse', false, { + local success = lib.callback.await('billing:server:handleBillResponse', false, { action = 'later', billId = data.billId }) - lib.notify({ - title = 'Rechnung gespeichert', - description = 'Die Rechnung wurde für später gespeichert', - type = 'info' - }) + if success then + lib.notify({ + title = 'Rechnung gespeichert', + description = 'Die Rechnung wurde für später gespeichert', + type = 'info' + }) + else + lib.notify({ + title = 'Fehler', + description = 'Fehler beim Speichern der Rechnung', + type = 'error' + }) + end end } } @@ -508,3 +522,7 @@ RegisterNetEvent('billing:client:showPaymentPrompt', function(data) -- Show the payment prompt lib.showContext('bill_payment_prompt') end) + +RegisterNetEvent('billing:client:openBillsMenu', function() + ViewBills() +end) diff --git a/resources/[tools]/nordi_billing/billing_server.lua b/resources/[tools]/nordi_billing/billing_server.lua index fcc205a5d..3dfcc5e9a 100644 --- a/resources/[tools]/nordi_billing/billing_server.lua +++ b/resources/[tools]/nordi_billing/billing_server.lua @@ -47,6 +47,9 @@ lib.callback.register('billing:server:sendBill', function(source, data) sender = senderName }) + -- Notify the sender + TriggerClientEvent('QBCore:Notify', src, 'Rechnung über $' .. data.amount .. ' an ' .. target.PlayerData.charinfo.firstname .. ' gesendet', 'success') + return true end) @@ -112,6 +115,9 @@ lib.callback.register('billing:server:handleBillResponse', function(source, data -- Process the payment to the recipient's account ProcessBillPayment(data.billId) + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Du hast die Rechnung über $' .. amount .. ' bezahlt', 'success') + return true else -- Pay from shared account @@ -131,13 +137,19 @@ lib.callback.register('billing:server:handleBillResponse', function(source, data if sender then TriggerClientEvent('QBCore:Notify', sender.PlayerData.source, 'Deine Rechnung wurde abgelehnt', 'error') end - end + } + + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Du hast die Rechnung abgelehnt', 'info') return true elseif data.action == 'later' then -- Simply close the prompt without any action -- The bill will remain in the system as unpaid - -- No need to update anything in the database + + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Die Rechnung wurde für später gespeichert', 'info') + return true end @@ -180,10 +192,16 @@ function PayBillFromSharedAccount(source, billId, accountId) end end - if not hasAccess then return false end + if not hasAccess then + TriggerClientEvent('QBCore:Notify', src, 'Du hast keinen Zugriff auf dieses Konto', 'error') + return false + end -- Check if account has enough balance - if tonumber(account.balance) < amount then return false end + if tonumber(account.balance) < amount then + TriggerClientEvent('QBCore:Notify', src, 'Nicht genug Geld auf diesem Konto', 'error') + return false + end -- Process payment MySQL.update.await('UPDATE ps_banking_accounts SET balance = balance - ? WHERE id = ?', {amount, accountId}) @@ -192,6 +210,9 @@ function PayBillFromSharedAccount(source, billId, accountId) -- Process the payment to the recipient's account ProcessBillPayment(billId) + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Du hast die Rechnung über $' .. amount .. ' vom Konto ' .. account.holder .. ' bezahlt', 'success') + return true end @@ -212,6 +233,7 @@ lib.callback.register('billing:server:payBillFromAccount', function(source, data -- Check if player has enough money in their bank account if player.PlayerData.money["bank"] < amount then + TriggerClientEvent('QBCore:Notify', src, 'Nicht genug Geld auf deinem Konto', 'error') return false end @@ -222,6 +244,9 @@ lib.callback.register('billing:server:payBillFromAccount', function(source, data -- Process the payment to the recipient's account ProcessBillPayment(data.billId) + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Du hast die Rechnung über $' .. amount .. ' bezahlt', 'success') + return true else -- Pay from shared account @@ -261,6 +286,18 @@ function ProcessBillPayment(billId) amount, accountId }) + + -- Try to notify the account owner if online + local accountResult = MySQL.query.await('SELECT * FROM ps_banking_accounts WHERE id = ?', {accountId}) + if accountResult and #accountResult > 0 then + local account = accountResult[1] + local owner = json.decode(account.owner) + local ownerPlayer = QBCore.Functions.GetPlayerByCitizenId(owner.identifier) + + if ownerPlayer then + TriggerClientEvent('QBCore:Notify', ownerPlayer.PlayerData.source, 'Das Konto ' .. account.holder .. ' hat $' .. amount .. ' von einer Rechnungszahlung erhalten', 'success') + end + end end -- Update the bill status @@ -323,6 +360,12 @@ RegisterNetEvent('QBCore:Server:PlayerLoaded', function() MySQL.update.await('UPDATE offline_payments SET processed = 1 WHERE citizen_id = ? AND processed = 0', {citizenId}) end end + + -- Check for unpaid bills + local unpaidBills = MySQL.query.await('SELECT COUNT(*) as count FROM ps_banking_bills WHERE identifier = ? AND isPaid = 0', {citizenId}) + if unpaidBills and unpaidBills[1].count > 0 then + TriggerClientEvent('QBCore:Notify', src, 'Du hast ' .. unpaidBills[1].count .. ' unbezahlte Rechnungen. Tippe /bills um sie anzuzeigen.', 'info') + end end) -- Alternative hook method if you can't modify ps-banking @@ -339,3 +382,32 @@ AddEventHandler('oxmysql:query', function(query, params) end end end) + +-- Register a command to check bills +QBCore.Commands.Add('bills', 'Zeige deine unbezahlten Rechnungen an', {}, false, function(source) + TriggerClientEvent('QBCore:Notify', source, 'Öffne Rechnungsübersicht...', 'info') + -- This will trigger the client to open the bills menu + TriggerClientEvent('billing:client:openBillsMenu', source) +end) + +-- Event handler for opening bills menu from command +RegisterNetEvent('billing:client:openBillsMenu', function() + -- This is handled on the client side +end) + +-- Add a server event to notify bill sender when a bill is paid +RegisterServerEvent('billing:server:notifyBillPaid', function(senderId, amount, receiverName) + local sender = QBCore.Functions.GetPlayerByCitizenId(senderId) + if sender then + TriggerClientEvent('QBCore:Notify', sender.PlayerData.source, receiverName .. ' hat deine Rechnung über $' .. amount .. ' bezahlt', 'success') + end +end) + +-- Add a server event to notify bill sender when a bill is declined +RegisterServerEvent('billing:server:notifyBillDeclined', function(senderId, amount, receiverName) + local sender = QBCore.Functions.GetPlayerByCitizenId(senderId) + if sender then + TriggerClientEvent('QBCore:Notify', sender.PlayerData.source, receiverName .. ' hat deine Rechnung über $' .. amount .. ' abgelehnt', 'error') + end +end) +