From 6c570cee98e85b34dba4ff7a49acbef1396156c7 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 25 Nov 2018 15:54:19 +0100 Subject: [PATCH] Added sold vehicles list --- client/main.lua | 38 ++++++++++++++++++++++++++++++++++---- esx_vehicleshop.sql | 10 ++++++++++ locales/br.lua | 8 ++++++++ locales/en.lua | 8 ++++++++ locales/fi.lua | 8 ++++++++ locales/fr.lua | 8 ++++++++ locales/pl.lua | 8 ++++++++ locales/sv.lua | 8 ++++++++ server/main.lua | 32 ++++++++++++++++++++++++++------ 9 files changed, 118 insertions(+), 10 deletions(-) diff --git a/client/main.lua b/client/main.lua index 851ff5d5..cec2dabb 100644 --- a/client/main.lua +++ b/client/main.lua @@ -487,6 +487,7 @@ function OpenResellerMenu() SetVehicleNumberPlateText(LastVehicles[#LastVehicles], newPlate) TriggerServerEvent('esx_vehicleshop:sellVehicle', model) + TriggerServerEvent('esx_vehicleshop:addToList', GetPlayerServerId(closestPlayer), model, newPlate) if Config.EnableOwnedVehicles then TriggerServerEvent('esx_vehicleshop:setVehicleOwnedPlayerId', GetPlayerServerId(closestPlayer), vehicleProps) @@ -513,6 +514,7 @@ function OpenResellerMenu() SetVehicleNumberPlateText(LastVehicles[#LastVehicles], newPlate) TriggerServerEvent('esx_vehicleshop:sellVehicle', model) + TriggerServerEvent('esx_vehicleshop:addToList', GetPlayerServerId(closestPlayer), model, newPlate) if Config.EnableSocietyOwnedVehicles then TriggerServerEvent('esx_vehicleshop:setVehicleOwnedSociety', xPlayer.job.name, vehicleProps) @@ -639,12 +641,40 @@ function OpenBossActionsMenu() title = _U('dealer_boss'), align = 'top-left', elements = { - {label = _U('boss_actions'), value = 'boss_actions'} + {label = _U('boss_actions'), value = 'boss_actions'}, + {label = _U('boss_sold'), value = 'sold_vehicles'} } }, function (data, menu) if data.current.value == 'boss_actions' then - TriggerEvent('esx_society:openBossMenu', 'cardealer', function(data, menu) - menu.close() + TriggerEvent('esx_society:openBossMenu', 'cardealer', function(data2, menu2) + menu2.close() + end) + elseif data.current.value == 'sold_vehicles' then + + ESX.TriggerServerCallback('esx_vehicleshop:getSoldVehicles', function(customers) + local elements = { + head = { _U('customer_client'), _U('customer_model'), _U('customer_plate'), _U('customer_soldby'), _U('customer_date') }, + rows = {} + } + + for i=1, #customers, 1 do + table.insert(elements.rows, { + data = customers[i], + cols = { + customers[i].client, + customers[i].model, + customers[i].plate, + customers[i].soldby, + customers[i].date + } + }) + end + + ESX.UI.Menu.Open('list', GetCurrentResourceName(), 'sold_vehicles', elements, function(data2, menu2) + + end, function(data2, menu2) + menu2.close() + end) end) end @@ -687,7 +717,7 @@ function OpenGetStocksMenu() TriggerServerEvent('esx_vehicleshop:getStockItem', itemName, count) menu2.close() menu.close() - OpenGetStocksMenu() + OpenGetStocksMenu() end end, function (data2, menu2) menu2.close() diff --git a/esx_vehicleshop.sql b/esx_vehicleshop.sql index de0f6f08..b92a15b5 100644 --- a/esx_vehicleshop.sql +++ b/esx_vehicleshop.sql @@ -26,6 +26,16 @@ CREATE TABLE `cardealer_vehicles` ( PRIMARY KEY (`id`) ); +CREATE TABLE `vehicle_sold` ( + `client` VARCHAR(50) NOT NULL, + `model` VARCHAR(50) NOT NULL, + `plate` VARCHAR(50) NOT NULL, + `soldby` VARCHAR(50) NOT NULL, + `date` VARCHAR(50) NOT NULL, + + PRIMARY KEY (`plate`) +) + CREATE TABLE `owned_vehicles` ( `owner` varchar(30) NOT NULL, `plate` varchar(12) NOT NULL, diff --git a/locales/br.lua b/locales/br.lua index 5f4b5ce7..a824928c 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -48,4 +48,12 @@ Locales['br'] = { ['have_withdrawn'] = 'you have withdrawn ~y~x%s~s~ ~b~%s~s~', ['have_deposited'] = 'you have deposited ~y~x%s~s~ ~b~%s~s~', ['boss_actions'] = 'boss actions', + + -- sold vehicles + ['boss_sold'] = 'list of sold vehicles', + ['customer_client'] = 'customer name', + ['customer_model'] = 'car model', + ['customer_plate'] = 'car plate', + ['customer_soldby'] = 'sold by', + ['customer_date'] = 'date', } diff --git a/locales/en.lua b/locales/en.lua index d1d0c2a7..6af5f877 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -53,4 +53,12 @@ Locales['en'] = { ['have_withdrawn'] = 'you have withdrawn ~y~x%s~s~ ~b~%s~s~', ['have_deposited'] = 'you have deposited ~y~x%s~s~ ~b~%s~s~', ['boss_actions'] = 'boss actions', + + -- sold vehicles + ['boss_sold'] = 'list of sold vehicles', + ['customer_client'] = 'customer name', + ['customer_model'] = 'car model', + ['customer_plate'] = 'car plate', + ['customer_soldby'] = 'sold by', + ['customer_date'] = 'date', } diff --git a/locales/fi.lua b/locales/fi.lua index 1f0a81fb..2fa5a683 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -53,4 +53,12 @@ Locales['fi'] = { ['have_withdrawn'] = 'sinä otit ~y~x%s~s~ ~b~%s~s~', ['have_deposited'] = 'sinä talletit ~y~x%s~s~ ~b~%s~s~', ['boss_actions'] = 'Pomo toiminnot', + + -- sold vehicles + ['boss_sold'] = 'list of sold vehicles', + ['customer_client'] = 'customer name', + ['customer_model'] = 'car model', + ['customer_plate'] = 'car plate', + ['customer_soldby'] = 'sold by', + ['customer_date'] = 'date', } diff --git a/locales/fr.lua b/locales/fr.lua index 33d278ae..57bda500 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -52,4 +52,12 @@ Locales['fr'] = { ['have_withdrawn'] = 'you have withdrawn ~y~x%s~s~ ~b~%s~s~', ['have_deposited'] = 'you have deposited ~y~x%s~s~ ~b~%s~s~', ['boss_actions'] = 'boss actions', + + -- sold vehicles + ['boss_sold'] = 'list of sold vehicles', + ['customer_client'] = 'customer name', + ['customer_model'] = 'car model', + ['customer_plate'] = 'car plate', + ['customer_soldby'] = 'sold by', + ['customer_date'] = 'date', } diff --git a/locales/pl.lua b/locales/pl.lua index b7691093..0dc3a276 100644 --- a/locales/pl.lua +++ b/locales/pl.lua @@ -51,4 +51,12 @@ Locales['pl'] = { ['have_withdrawn'] = 'wyciągasz ~y~x%s~s~ ~b~%s~s~', ['have_deposited'] = 'deponujesz ~y~x%s~s~ ~b~%s~s~', ['boss_actions'] = 'akcje szefa', + + -- sold vehicles + ['boss_sold'] = 'list of sold vehicles', + ['customer_client'] = 'customer name', + ['customer_model'] = 'car model', + ['customer_plate'] = 'car plate', + ['customer_soldby'] = 'sold by', + ['customer_date'] = 'date', } diff --git a/locales/sv.lua b/locales/sv.lua index 8364adc4..1206c15e 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -53,4 +53,12 @@ Locales['sv'] = { ['have_withdrawn'] = 'du har tagit ut ~y~x%s~s~ ~b~%s~s~', ['have_deposited'] = 'du har lagt in ~y~x%s~s~ ~b~%s~s~', ['boss_actions'] = 'chef handlingar', + + -- sold vehicles + ['boss_sold'] = 'lista av sålda fordon', + ['customer_client'] = 'kund', + ['customer_model'] = 'bil modell', + ['customer_plate'] = 'registreringsnummer', + ['customer_soldby'] = 'såld av', + ['customer_date'] = 'datum', } diff --git a/server/main.lua b/server/main.lua index 2a72afa5..ee51ebb3 100644 --- a/server/main.lua +++ b/server/main.lua @@ -92,6 +92,32 @@ AddEventHandler('esx_vehicleshop:sellVehicle', function (vehicle) end) end) +RegisterServerEvent('esx_vehicleshop:addToList') +AddEventHandler('esx_vehicleshop:addToList', function(target, model, plate) + local xPlayer, xTarget = ESX.GetPlayerFromId(source), ESX.GetPlayerFromId(target) + local dateNow = os.date('%Y-%m-%d %H:%M') + + if xPlayer.job.name ~= 'cardealer' then + print(('esx_vehicleshop: %s attempted to add a sold vehicle to list!'):format(xPlayer.identifier)) + return + end + + MySQL.Async.execute('INSERT INTO vehicle_sold (client, model, plate, soldby, date) VALUES (@client, @model, @plate, @soldby, @date)', { + ['@client'] = xTarget.getName(), + ['@model'] = model, + ['@plate'] = plate, + ['@soldby'] = xPlayer.getName(), + ['@date'] = dateNow + }) +end) + +ESX.RegisterServerCallback('esx_vehicleshop:getSoldVehicles', function (source, cb) + + MySQL.Async.fetchAll('SELECT * FROM vehicle_sold', {}, function(result) + cb(result) + end) +end) + RegisterServerEvent('esx_vehicleshop:rentVehicle') AddEventHandler('esx_vehicleshop:rentVehicle', function (vehicle, plate, playerName, basePrice, rentPrice, target) local xPlayer = ESX.GetPlayerFromId(target) @@ -119,12 +145,6 @@ AddEventHandler('esx_vehicleshop:rentVehicle', function (vehicle, plate, playerN end) end) --- unused? -RegisterServerEvent('esx_vehicleshop:setVehicleForAllPlayers') -AddEventHandler('esx_vehicleshop:setVehicleForAllPlayers', function (props, x, y, z, radius) - TriggerClientEvent('esx_vehicleshop:setVehicle', -1, props, x, y, z, radius) -end) - RegisterServerEvent('esx_vehicleshop:getStockItem') AddEventHandler('esx_vehicleshop:getStockItem', function (itemName, count) local _source = source