-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/add-auto-finance-payment-ability #60
Changes from all commits
3a68170
a190132
70c1971
e668d90
a9e8704
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ Config.UsingTarget = GetConvar('UseTarget', 'false') == 'true' | |
Config.Commission = 0.10 -- Percent that goes to sales person from a full car sale 10% | ||
Config.FinanceCommission = 0.05 -- Percent that goes to sales person from a finance sale 5% | ||
Config.FinanceZone = vector3(-29.53, -1103.67, 26.42)-- Where the finance menu is located | ||
Config.FinanceAuto = true, -- Automatically take the money out of the user's account if they have it. If the time is up, they'll still need to make payment before repo... | ||
Config.FinanceAutoCashPayAllowed = true, -- If they don't have enough money in bank, do we take from their cash? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be false by default |
||
Config.PaymentWarning = 10 -- time in minutes that player has to make payment before repo | ||
Config.PaymentInterval = 24 -- time in hours between payment being due | ||
Config.MinimumDown = 10 -- minimum percentage allowed down | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,17 +429,62 @@ end) | |
RegisterNetEvent('qb-vehicleshop:server:checkFinance', function() | ||
local src = source | ||
local player = QBCore.Functions.GetPlayer(src) | ||
local cash = player.PlayerData.money['cash'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These vars should be moved down into the auto finance loop code block. Otherwise, they won't update whenever a payment is made. |
||
local bank = player.PlayerData.money['bank'] | ||
local query = 'SELECT * FROM player_vehicles WHERE citizenid = ? AND balance > 0 AND financetime < 1' | ||
local result = MySQL.query.await(query, {player.PlayerData.citizenid}) | ||
if result[1] then | ||
TriggerClientEvent('QBCore:Notify', src, Lang:t('general.paymentduein', {time = Config.PaymentWarning})) | ||
Wait(Config.PaymentWarning * 60000) | ||
local vehicles = MySQL.query.await(query, {player.PlayerData.citizenid}) | ||
for _, v in pairs(vehicles) do | ||
local plate = v.plate | ||
MySQL.query('DELETE FROM player_vehicles WHERE plate = @plate', {['@plate'] = plate}) | ||
--MySQL.update('UPDATE player_vehicles SET citizenid = ? WHERE plate = ?', {'REPO-'..v.citizenid, plate}) -- Use this if you don't want them to be deleted | ||
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.repossessed', {plate = plate}), 'error') | ||
if not Config.FinanceAuto then | ||
TriggerClientEvent('QBCore:Notify', src, Lang:t('general.paymentduein', {time = Config.PaymentWarning})) | ||
Wait(Config.PaymentWarning * 60000) | ||
local vehicles = MySQL.query.await(query, {player.PlayerData.citizenid}) | ||
for _, v in pairs(vehicles) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code duplication here. |
||
local plate = v.plate | ||
MySQL.query('DELETE FROM player_vehicles WHERE plate = @plate', {['@plate'] = plate}) | ||
--MySQL.update('UPDATE player_vehicles SET citizenid = ? WHERE plate = ?', {'REPO-'..v.citizenid, plate}) -- Use this if you don't want them to be deleted | ||
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.repossessed', {plate = plate}), 'error') | ||
end | ||
else | ||
-- Automatically take the money out from their account if they have it... If they do not have it, they have certain amount of time until it is repoed... | ||
local allPaid = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this above |
||
for ind, row in pairs(result) do | ||
local paid = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary var here. Can just assign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, you don't need semi-colons on line endings in lua |
||
local paymentNeeded = result[ind].paymentamount; | ||
local balance = result[ind].balance; | ||
local payLeft = result[ind].paymentsleft; | ||
local plate = result[ind].plate; | ||
local timer = (Config.PaymentInterval * 60) | ||
if (bank >= paymentNeeded) then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if (bank >= paymentNeeded) or ((cash >= paymentNeeded) and (Config.FinanceAutoCashPayAllowed)) then
local paymentMethod = (bank >= paymentNeeded) and 'bank' or 'cash'
player.Functions.RemoveMoney(paymentMethod, paymentNeeded)
local newBalance, newPaymentsLeft, newPayment = calculateNewFinance(paymentNeeded, {balance = balance, paymentsLeft = payLeft})
MySQL.update('UPDATE player_vehicles SET balance = ?, paymentamount = ?, paymentsleft = ?, financetime = ? WHERE plate = ?', {newBalance, newPayment, newPaymentsLeft, timer, plate})
TriggerClientEvent('QBCore:Notify', src, Lang:t('general.finance_auto_paid_' .. paymentMethod, {payment = paymentNeeded, plate = plate}))
else
allPaid = false
end |
||
-- Payment via bank | ||
paid = true; | ||
player.Functions.RemoveMoney('bank', paymentNeeded); | ||
TriggerClientEvent('QBCore:Notify', src, Lang:t('general.finance_auto_paid_bank', {payment = paymentNeeded, plate = plate})); | ||
elseif (cash >= paymentNeeded) and (Config.FinanceAutoCashPayAllowed) then | ||
-- Payment via cash | ||
paid = true; | ||
player.Functions.RemoveMoney('cash', paymentNeeded); | ||
TriggerClientEvent('QBCore:Notify', src, Lang:t('general.finance_auto_paid_cash', {payment = paymentNeeded, plate = plate})); | ||
end | ||
if paid then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if statement & the next one can be removed w/ my changes above. |
||
local newBalance, newPaymentsLeft, newPayment = calculateNewFinance(paymentNeeded, {balance = balance, paymentsLeft = payLeft}); | ||
MySQL.update('UPDATE player_vehicles SET balance = ?, paymentamount = ?, paymentsleft = ?, financetime = ? WHERE plate = ?', {newBalance, newPayment, newPaymentsLeft, timer, plate}); | ||
end | ||
-- They do not have enough money, let them know the vehicle may be revoked... | ||
if not paid then | ||
allPaid = false; | ||
end | ||
end | ||
if not allPaid then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this out of the |
||
TriggerClientEvent('QBCore:Notify', src, Lang:t('general.paymentduein', {time = Config.PaymentWarning})) | ||
Wait(Config.PaymentWarning * 60000) | ||
local vehicles = MySQL.query.await(query, {player.PlayerData.citizenid}) | ||
for _, v in pairs(vehicles) do | ||
local plate = v.plate | ||
MySQL.query('DELETE FROM player_vehicles WHERE plate = @plate', {['@plate'] = plate}) | ||
--MySQL.update('UPDATE player_vehicles SET citizenid = ? WHERE plate = ?', {'REPO-'..v.citizenid, plate}) -- Use this if you don't want them to be deleted | ||
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.repossessed', {plate = plate}), 'error') | ||
end | ||
end | ||
end | ||
end | ||
end) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be false by default