diff --git a/client/main.lua b/client/main.lua index b8d76ac6..4bf3e121 100644 --- a/client/main.lua +++ b/client/main.lua @@ -11,7 +11,6 @@ PhoneData = { MentionedTweets = {}, Hashtags = {}, Chats = {}, - Invoices = {}, CallData = {}, RecentCalls = {}, Garage = {}, @@ -227,13 +226,6 @@ local function LoadPhone() PhoneData.Chats = Chats end - if pData.Invoices ~= nil and next(pData.Invoices) ~= nil then - for _, invoice in pairs(pData.Invoices) do - invoice.name = IsNumberInContacts(invoice.number) - end - PhoneData.Invoices = pData.Invoices - end - if pData.Hashtags ~= nil and next(pData.Hashtags) ~= nil then PhoneData.Hashtags = pData.Hashtags end @@ -598,11 +590,9 @@ RegisterNUICallback('GetBankContacts', function(_, cb) end) RegisterNUICallback('GetInvoices', function(_, cb) - if PhoneData.Invoices ~= nil and next(PhoneData.Invoices) ~= nil then - cb(PhoneData.Invoices) - else - cb(nil) - end + QBCore.Functions.TriggerCallback('qb-phone:server:GetInvoices', function(resp) + cb(resp) + end) end) RegisterNUICallback('SharedLocation', function(data, cb) @@ -665,9 +655,8 @@ RegisterNUICallback('PayInvoice', function(data, cb) local society = data.society local amount = data.amount local invoiceId = data.invoiceId - QBCore.Functions.TriggerCallback('qb-phone:server:PayInvoice', function(CanPay, Invoices) - if CanPay then PhoneData.Invoices = Invoices end - cb(CanPay) + QBCore.Functions.TriggerCallback('qb-phone:server:PayInvoice', function(resp) + cb(resp) end, society, amount, invoiceId, senderCitizenId) TriggerServerEvent('qb-phone:server:BillingEmail', data, true) end) @@ -676,9 +665,8 @@ RegisterNUICallback('DeclineInvoice', function(data, cb) local society = data.society local amount = data.amount local invoiceId = data.invoiceId - QBCore.Functions.TriggerCallback('qb-phone:server:DeclineInvoice', function(_, Invoices) - PhoneData.Invoices = Invoices - cb('ok') + QBCore.Functions.TriggerCallback('qb-phone:server:DeclineInvoice', function(resp) + cb(resp) end, society, amount, invoiceId) TriggerServerEvent('qb-phone:server:BillingEmail', data, false) end) @@ -1456,7 +1444,6 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() MentionedTweets = {}, Hashtags = {}, Chats = {}, - Invoices = {}, CallData = {}, RecentCalls = {}, Garage = {}, diff --git a/html/css/bank.css b/html/css/bank.css index 5eb682ab..074c67b2 100644 --- a/html/css/bank.css +++ b/html/css/bank.css @@ -76,37 +76,44 @@ background-color: #dc143c; } .bank-app-invoice { - position: relative; - height: 6vh; + height: fit-content; + display: flex; + flex-direction: column; + padding: 8px 16px; width: 100%; letter-spacing: .05vh; border-bottom: .2vh solid #363d4b; } .bank-app-invoice-title { text-transform : capitalize; - position: absolute; - top: 1vh; - left: 2vh; + width: 100%; color: white; font-family: 'Poppins', sans-serif; font-size: 1.3vh; } +.bank-app-invoice-info { + width: 100%; + display: flex; + flex-direction: row; +} .bank-app-invoice-amount { - position: absolute; - bottom: 1vh; - left: 2vh; color: rgba(255, 255, 255, 0.781); font-family: 'Poppins', sans-serif; font-size: 1.22vh; } .bank-app-invoice-buttons { - position: absolute; - right: 1.2vh; - bottom: .1vh; - height: 3vh; - width: 7vh; - text-align: center; - line-height: 3.5vh; + margin-left: auto; +} +.bank-app-invoice-reason { + color: rgba(255, 255, 255, 0.85); + font-family: 'Poppins', sans-serif; + font-size: 1.22vh; + + width: 100%; + + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } .bank-app-invoice-buttons > i { margin-left: .5vh; diff --git a/html/js/bank.js b/html/js/bank.js index 15610bf7..90194bbe 100644 --- a/html/js/bank.js +++ b/html/js/bank.js @@ -134,7 +134,7 @@ GetInvoiceLabel = function(type) { $(document).on('click', '.pay-invoice', function(event){ event.preventDefault(); - var InvoiceId = $(this).parent().parent().attr('id'); + var InvoiceId = $(this).parent().parent().parent().attr('id'); var InvoiceData = $("#"+InvoiceId).data('invoicedata'); var BankBalance = $(".bank-app-account-balance").data('balance'); @@ -168,24 +168,29 @@ $(document).on('click', '.pay-invoice', function(event){ } }); -$(document).on('click', '.decline-invoice', function(event){ +$(document).on('click', '.decline-invoice', async function(event) { event.preventDefault(); - var InvoiceId = $(this).parent().parent().attr('id'); + var InvoiceId = $(this).parent().parent().parent().attr('id'); var InvoiceData = $("#"+InvoiceId).data('invoicedata'); - $.post('https://qb-phone/DeclineInvoice', JSON.stringify({ + const resp = await $.post('https://qb-phone/DeclineInvoice', JSON.stringify({ sender: InvoiceData.sender, amount: InvoiceData.amount, society: InvoiceData.society, invoiceId: InvoiceData.id, })); - $("#"+InvoiceId).animate({ - left: 30+"vh", - }, 300, function(){ - setTimeout(function(){ - $("#"+InvoiceId).remove(); - }, 100); - }); + if(resp === true) { + QB.Phone.Notifications.Add("fas fa-university", "QBank", "You declined the invoice", "#8c7ae6") + $("#"+InvoiceId).animate({ + left: 30+"vh", + }, 300, function(){ + setTimeout(function(){ + $("#"+InvoiceId).remove(); + }, 100); + }); + } else { + QB.Phone.Notifications.Add("fas fa-university", "QBank", "Couldnt decline this invoice...", "#8c7ae6") + } }); QB.Phone.Functions.LoadBankInvoices = function(invoices) { @@ -193,10 +198,10 @@ QB.Phone.Functions.LoadBankInvoices = function(invoices) { $(".bank-app-invoices-list").html(""); $.each(invoices, function(i, invoice){ - var Elem = '
'+invoice.society+' (Sender: '+invoice.sender+')
$ '+invoice.amount+'
'; + var Elem = '
'+invoice.society+' (Sender: '+invoice.sender+')
' + (typeof invoice.reason === 'string' ? `
${invoice.reason}
` : '') + '
$ '+invoice.amount+'
'+ (invoice.candecline === 1 ? '' : '') + '
'; $(".bank-app-invoices-list").append(Elem); - $("#invoiceid-"+i).data('invoicedata', invoice); + $("#invoiceid-"+invoice.id).data('invoicedata', invoice); }); } } diff --git a/qb-phone.sql b/qb-phone.sql index 6aa3a09a..50fee154 100644 --- a/qb-phone.sql +++ b/qb-phone.sql @@ -15,6 +15,8 @@ CREATE TABLE IF NOT EXISTS `phone_invoices` ( `society` tinytext DEFAULT NULL, `sender` varchar(50) DEFAULT NULL, `sendercitizenid` varchar(50) DEFAULT NULL, + `candecline` int(1) not null default 1, + `reason` varchar(256) default null, PRIMARY KEY (`id`), KEY `citizenid` (`citizenid`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; diff --git a/server/main.lua b/server/main.lua index 0b69d6b1..998505d4 100644 --- a/server/main.lua +++ b/server/main.lua @@ -160,6 +160,32 @@ end exports('sendNewMailToOffline', sendNewMailToOffline) -- Callbacks +QBCore.Functions.CreateCallback("qb-phone:server:GetInvoices", function(source, cb) + local Player = QBCore.Functions.GetPlayer(source) + + if Player then + local invoices = MySQL.query.await('SELECT * FROM phone_invoices WHERE citizenid = ?', { Player.PlayerData.citizenid }) + for _, v in pairs(invoices) do + local Ply = QBCore.Functions.GetPlayerByCitizenId(v.sender) + if Ply ~= nil then + v.number = Ply.PlayerData.charinfo.phone + else + local res = MySQL.query.await('SELECT * FROM players WHERE citizenid = ?', { v.sender }) + if res[1] ~= nil then + res[1].charinfo = json.decode(res[1].charinfo) + v.number = res[1].charinfo.phone + else + v.number = nil + end + end + end + cb(invoices) + return + end + + cb({}) +end) + QBCore.Functions.CreateCallback('qb-phone:server:GetCallState', function(_, cb, ContactData) local Target = QBCore.Functions.GetPlayerByPhone(ContactData.number) if Target ~= nil then @@ -187,7 +213,6 @@ QBCore.Functions.CreateCallback('qb-phone:server:GetPhoneData', function(source, MentionedTweets = {}, Chats = {}, Hashtags = {}, - Invoices = {}, Garage = {}, Mails = {}, Adverts = {}, @@ -207,25 +232,6 @@ QBCore.Functions.CreateCallback('qb-phone:server:GetPhoneData', function(source, PhoneData.PlayerContacts = result end - local invoices = MySQL.query.await('SELECT * FROM phone_invoices WHERE citizenid = ?', { Player.PlayerData.citizenid }) - if invoices[1] ~= nil then - for _, v in pairs(invoices) do - local Ply = QBCore.Functions.GetPlayerByCitizenId(v.sender) - if Ply ~= nil then - v.number = Ply.PlayerData.charinfo.phone - else - local res = MySQL.query.await('SELECT * FROM players WHERE citizenid = ?', { v.sender }) - if res[1] ~= nil then - res[1].charinfo = json.decode(res[1].charinfo) - v.number = res[1].charinfo.phone - else - v.number = nil - end - end - end - PhoneData.Invoices = invoices - end - local garageresult = MySQL.query.await('SELECT * FROM player_vehicles WHERE citizenid = ?', { Player.PlayerData.citizenid }) if garageresult[1] ~= nil then PhoneData.Garage = garageresult @@ -283,45 +289,57 @@ QBCore.Functions.CreateCallback('qb-phone:server:GetPhoneData', function(source, end) QBCore.Functions.CreateCallback('qb-phone:server:PayInvoice', function(source, cb, society, amount, invoiceId, sendercitizenid) - local Invoices = {} local Ply = QBCore.Functions.GetPlayer(source) local SenderPly = QBCore.Functions.GetPlayerByCitizenId(sendercitizenid) - local invoiceMailData = {} - if SenderPly and Config.BillingCommissions[society] then - local commission = round(amount * Config.BillingCommissions[society]) - SenderPly.Functions.AddMoney('bank', commission) - invoiceMailData = { - sender = 'Billing Department', - subject = 'Commission Received', - message = string.format('You received a commission check of $%s when %s %s paid a bill of $%s.', commission, Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo.lastname, amount) - } - elseif not SenderPly and Config.BillingCommissions[society] then - invoiceMailData = { - sender = 'Billing Department', - subject = 'Bill Paid', - message = string.format('%s %s paid a bill of $%s', Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo.lastname, amount) - } - end - Ply.Functions.RemoveMoney('bank', amount, 'paid-invoice') - exports['qb-phone']:sendNewMailToOffline(sendercitizenid, invoiceMailData) - exports['qb-banking']:AddMoney(society, amount, 'Phone invoice') - MySQL.query('DELETE FROM phone_invoices WHERE id = ?', { invoiceId }) - local invoices = MySQL.query.await('SELECT * FROM phone_invoices WHERE citizenid = ?', { Ply.PlayerData.citizenid }) - if invoices[1] ~= nil then - Invoices = invoices + local invoiceMailData = nil + if Ply then + local exists = MySQL.query.await('select count(1) as count FROM phone_invoices WHERE id = ? and citizenid = ?', { invoiceId, Ply.PlayerData.citizenid }) + + if exists[1] and exists[1]["count"] == 1 then + if SenderPly and Config.BillingCommissions[society] then + local commission = round(amount * Config.BillingCommissions[society]) + SenderPly.Functions.AddMoney('bank', commission) + invoiceMailData = { + sender = 'Billing Department', + subject = 'Commission Received', + message = string.format('You received a commission check of $%s when %s %s paid a bill of $%s.', commission, Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo.lastname, amount) + } + elseif not SenderPly and Config.BillingCommissions[society] then + invoiceMailData = { + sender = 'Billing Department', + subject = 'Bill Paid', + message = string.format('%s %s paid a bill of $%s', Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo.lastname, amount) + } + end + if Ply.Functions.RemoveMoney('bank', amount, 'paid-invoice') then + MySQL.query('DELETE FROM phone_invoices WHERE id = ? and citizenid = ?', { invoiceId, Ply.PlayerData.citizenid }) + if invoiceMailData then + exports['qb-phone']:sendNewMailToOffline(sendercitizenid, invoiceMailData) + end + TriggerEvent("qb-phone:server:paidInvoice", source, invoiceId) + exports['qb-banking']:AddMoney(society, amount, 'Phone invoice') + cb(true) + return + end + end end - cb(true, Invoices) + cb(false) end) QBCore.Functions.CreateCallback('qb-phone:server:DeclineInvoice', function(source, cb, _, _, invoiceId) - local Invoices = {} local Ply = QBCore.Functions.GetPlayer(source) - MySQL.query('DELETE FROM phone_invoices WHERE id = ?', { invoiceId }) - local invoices = MySQL.query.await('SELECT * FROM phone_invoices WHERE citizenid = ?', { Ply.PlayerData.citizenid }) - if invoices[1] ~= nil then - Invoices = invoices + if Ply then + local exists = MySQL.query.await('select count(1) as count FROM phone_invoices WHERE id = ? and citizenid = ? and candecline = ?', { invoiceId, Ply.PlayerData.citizenid, 1 }) + + if exists[1] and exists[1]["count"] == 1 then + TriggerEvent("qb-phone:server:declinedInvoice", source, invoiceId) + MySQL.query('DELETE FROM phone_invoices WHERE id = ? and citizenid = ? and candecline = ?', { invoiceId, Ply.PlayerData.citizenid, 1 }) + cb(true) + return + end end - cb(true, Invoices) + + cb(false) end) QBCore.Functions.CreateCallback('qb-phone:server:GetContactPictures', function(_, cb, Chats)