forked from Simnation/Main
Update billing_server.lua
This commit is contained in:
parent
6875b8a071
commit
d72b640e12
1 changed files with 75 additions and 0 deletions
|
@ -439,3 +439,78 @@ RegisterServerEvent('billing:server:notifyBillDeclined', function(senderId, amou
|
|||
TriggerClientEvent('QBCore:Notify', sender.PlayerData.source, receiverName .. ' hat deine Rechnung über $' .. amount .. ' abgelehnt', 'error')
|
||||
end
|
||||
end)
|
||||
|
||||
-- Add a new callback for handling bill responses
|
||||
lib.callback.register('billing:server:handleBillResponse', function(source, data)
|
||||
local src = source
|
||||
local player = QBCore.Functions.GetPlayer(src)
|
||||
|
||||
if not player then return false end
|
||||
|
||||
if data.action == 'pay' then
|
||||
-- Process payment based on selected account
|
||||
if data.accountId == 'personal' then
|
||||
-- Pay from personal bank account
|
||||
local billResult = MySQL.query.await('SELECT * FROM ps_banking_bills WHERE id = ?', {data.billId})
|
||||
if not billResult or #billResult == 0 then return false end
|
||||
|
||||
local bill = billResult[1]
|
||||
local amount = tonumber(bill.amount)
|
||||
|
||||
-- Check if player has enough money in their bank account
|
||||
if player.PlayerData.money["bank"] < amount then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Process payment manually instead of using callback to avoid issues
|
||||
player.Functions.RemoveMoney("bank", amount, "bill-payment")
|
||||
|
||||
-- IMPORTANT: Delete the bill from ps_banking_bills table
|
||||
MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId})
|
||||
|
||||
-- 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
|
||||
local success = PayBillFromSharedAccount(src, data.billId, data.accountId)
|
||||
return success
|
||||
end
|
||||
elseif data.action == 'decline' then
|
||||
-- Mark as declined in our system
|
||||
MySQL.update.await('UPDATE billing_accounts SET declined = 1 WHERE bill_id = ?', {data.billId})
|
||||
|
||||
-- IMPORTANT: Delete the bill from ps_banking_bills table when declined
|
||||
MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId})
|
||||
|
||||
-- Find the sender to notify them
|
||||
local billInfo = MySQL.query.await('SELECT * FROM billing_accounts WHERE bill_id = ?', {data.billId})
|
||||
if billInfo and #billInfo > 0 then
|
||||
local senderId = billInfo[1].sender_id
|
||||
local sender = QBCore.Functions.GetPlayerByCitizenId(senderId)
|
||||
|
||||
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
|
||||
|
||||
-- Notify the player
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Die Rechnung wurde für später gespeichert', 'info')
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue