forked from Simnation/Main
Update billing_server.lua
This commit is contained in:
parent
625f80361b
commit
d7e99ab851
1 changed files with 76 additions and 4 deletions
|
@ -126,6 +126,15 @@ lib.callback.register('billing:server:handleBillResponse', function(source, data
|
|||
-- Process payment manually instead of using callback to avoid issues
|
||||
player.Functions.RemoveMoney("bank", amount, "bill-payment")
|
||||
|
||||
-- Log transaction in ps-banking history for the payer
|
||||
MySQL.insert.await('INSERT INTO ps_banking_transactions (identifier, description, type, amount, date, isIncome) VALUES (?, ?, ?, ?, NOW(), ?)', {
|
||||
player.PlayerData.citizenid,
|
||||
"Bezahlte Rechnung: " .. bill.description,
|
||||
"bank",
|
||||
amount,
|
||||
false -- isIncome = false
|
||||
})
|
||||
|
||||
-- IMPORTANT: Delete the bill from ps_banking_bills table
|
||||
MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId})
|
||||
|
||||
|
@ -164,7 +173,6 @@ lib.callback.register('billing:server:handleBillResponse', function(source, data
|
|||
|
||||
return true
|
||||
end
|
||||
-- "later" action removed
|
||||
|
||||
return false
|
||||
end)
|
||||
|
@ -182,6 +190,7 @@ function PayBillFromSharedAccount(source, billId, accountId)
|
|||
|
||||
local bill = billResult[1]
|
||||
local amount = tonumber(bill.amount)
|
||||
|
||||
-- Get account details
|
||||
local accountResult = MySQL.query.await('SELECT * FROM ps_banking_accounts WHERE id = ?', {accountId})
|
||||
if not accountResult or #accountResult == 0 then return false end
|
||||
|
@ -218,6 +227,15 @@ function PayBillFromSharedAccount(source, billId, accountId)
|
|||
-- Process payment
|
||||
MySQL.update.await('UPDATE ps_banking_accounts SET balance = balance - ? WHERE id = ?', {amount, accountId})
|
||||
|
||||
-- Log transaction in ps-banking history for the account owner
|
||||
MySQL.insert.await('INSERT INTO ps_banking_transactions (identifier, description, type, amount, date, isIncome) VALUES (?, ?, ?, ?, NOW(), ?)', {
|
||||
accountOwner.identifier,
|
||||
"Bezahlte Rechnung von Konto " .. account.holder .. ": " .. bill.description,
|
||||
"bank",
|
||||
amount,
|
||||
false -- isIncome = false
|
||||
})
|
||||
|
||||
-- IMPORTANT: Delete the bill from ps_banking_bills table
|
||||
MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {billId})
|
||||
|
||||
|
@ -254,6 +272,15 @@ lib.callback.register('billing:server:payBillFromAccount', function(source, data
|
|||
-- Process payment manually
|
||||
player.Functions.RemoveMoney("bank", amount, "bill-payment")
|
||||
|
||||
-- Log transaction in ps-banking history for the payer
|
||||
MySQL.insert.await('INSERT INTO ps_banking_transactions (identifier, description, type, amount, date, isIncome) VALUES (?, ?, ?, ?, NOW(), ?)', {
|
||||
player.PlayerData.citizenid,
|
||||
"Bezahlte Rechnung: " .. bill.description,
|
||||
"bank",
|
||||
amount,
|
||||
false -- isIncome = false
|
||||
})
|
||||
|
||||
-- IMPORTANT: Delete the bill from ps_banking_bills table
|
||||
MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId})
|
||||
|
||||
|
@ -280,6 +307,7 @@ function ProcessBillPayment(billId)
|
|||
local receiverId = bill.sender_id
|
||||
local accountId = bill.account_id
|
||||
local amount = tonumber(bill.amount)
|
||||
local description = bill.bill_description or "Rechnungszahlung"
|
||||
|
||||
-- If it's a personal account
|
||||
if accountId == 'personal' then
|
||||
|
@ -287,13 +315,32 @@ function ProcessBillPayment(billId)
|
|||
if receiver then
|
||||
-- Add money directly to the receiver's bank account
|
||||
receiver.Functions.AddMoney('bank', amount, 'bill-payment')
|
||||
|
||||
-- Log transaction in ps-banking history for the receiver
|
||||
MySQL.insert.await('INSERT INTO ps_banking_transactions (identifier, description, type, amount, date, isIncome) VALUES (?, ?, ?, ?, NOW(), ?)', {
|
||||
receiverId,
|
||||
"Erhaltene Rechnung: " .. description,
|
||||
"bank",
|
||||
amount,
|
||||
true -- isIncome = true
|
||||
})
|
||||
|
||||
TriggerClientEvent('QBCore:Notify', receiver.PlayerData.source, 'Du hast $' .. amount .. ' von einer Rechnungszahlung erhalten', 'success')
|
||||
else
|
||||
-- Handle offline player
|
||||
MySQL.insert.await('INSERT INTO offline_payments (citizen_id, amount, reason) VALUES (?, ?, ?)', {
|
||||
receiverId,
|
||||
amount,
|
||||
'Rechnungszahlung'
|
||||
'Rechnungszahlung: ' .. description
|
||||
})
|
||||
|
||||
-- Log transaction in ps-banking history for offline player
|
||||
MySQL.insert.await('INSERT INTO ps_banking_transactions (identifier, description, type, amount, date, isIncome) VALUES (?, ?, ?, ?, NOW(), ?)', {
|
||||
receiverId,
|
||||
"Erhaltene Rechnung: " .. description,
|
||||
"bank",
|
||||
amount,
|
||||
true -- isIncome = true
|
||||
})
|
||||
end
|
||||
else
|
||||
|
@ -310,6 +357,15 @@ function ProcessBillPayment(billId)
|
|||
local owner = json.decode(account.owner)
|
||||
local ownerPlayer = QBCore.Functions.GetPlayerByCitizenId(owner.identifier)
|
||||
|
||||
-- Log transaction in ps-banking history for the account
|
||||
MySQL.insert.await('INSERT INTO ps_banking_transactions (identifier, description, type, amount, date, isIncome) VALUES (?, ?, ?, ?, NOW(), ?)', {
|
||||
owner.identifier,
|
||||
"Erhaltene Rechnung auf Konto " .. account.holder .. ": " .. description,
|
||||
"bank",
|
||||
amount,
|
||||
true -- isIncome = true
|
||||
})
|
||||
|
||||
if ownerPlayer then
|
||||
TriggerClientEvent('QBCore:Notify', ownerPlayer.PlayerData.source, 'Das Konto ' .. account.holder .. ' hat $' .. amount .. ' von einer Rechnungszahlung erhalten', 'success')
|
||||
end
|
||||
|
@ -444,6 +500,24 @@ AddEventHandler('oxmysql:query', function(query, params)
|
|||
-- This is likely a bill payment
|
||||
local billId = params[1]
|
||||
if billId then
|
||||
-- Get bill details before it's deleted
|
||||
local billResult = MySQL.query.await('SELECT * FROM ps_banking_bills WHERE id = ?', {billId})
|
||||
if billResult and #billResult > 0 then
|
||||
local bill = billResult[1]
|
||||
local identifier = bill.identifier
|
||||
local amount = tonumber(bill.amount)
|
||||
local description = bill.description
|
||||
|
||||
-- Log transaction in ps-banking history for the payer
|
||||
MySQL.insert.await('INSERT INTO ps_banking_transactions (identifier, description, type, amount, date, isIncome) VALUES (?, ?, ?, ?, NOW(), ?)', {
|
||||
identifier,
|
||||
"Bezahlte Rechnung: " .. description,
|
||||
"bank",
|
||||
amount,
|
||||
false -- isIncome = false
|
||||
})
|
||||
end
|
||||
|
||||
-- Small delay to ensure the deletion completes
|
||||
SetTimeout(100, function()
|
||||
ProcessBillPayment(billId)
|
||||
|
@ -458,5 +532,3 @@ QBCore.Commands.Add('bills', 'Zeige deine unbezahlten Rechnungen an', {}, false,
|
|||
-- This will trigger the client to open the bills menu
|
||||
TriggerClientEvent('billing:client:openBillsMenu', source)
|
||||
end)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue