JG Docs
Dealerships

Server API

These exports are only available in Dealerships v2.1.1 or newer.

Player Identifiers: Some exports accept an identifier parameter. This is the player's citizenid (QBCore/Qbox) or identifier (ESX), depending on your framework.

Return Pattern: Mutation exports return boolean, string? - the boolean indicates success, and the optional string provides an error message on failure.

Stock Management

incrementStock

Increment a vehicle's stock at a specific dealership.

local success, err = exports['jg-dealerships']:incrementStock(dealership, spawnCode, amount)
ParameterTypeRequiredDescription
dealershipstringYesDealership ID
spawnCodestringYesVehicle spawn code (e.g. "adder")
amountintegerNoAmount to increment by (default: 1)
ReturnsTypeDescription
successbooleanWhether the call succeeded
errorstring?Error message when it fails

decrementStock

Decrement a vehicle's stock at a specific dealership. Blocked if stock would go below 0.

local success, err = exports['jg-dealerships']:decrementStock(dealership, spawnCode, amount)
ParameterTypeRequiredDescription
dealershipstringYesDealership ID
spawnCodestringYesVehicle spawn code
amountintegerNoAmount to decrement by (default: 1)
ReturnsTypeDescription
successbooleanWhether the call succeeded
errorstring?Error message when it fails

setStock

Set a vehicle's stock to an exact value at a specific dealership.

local success, err = exports['jg-dealerships']:setStock(dealership, spawnCode, stock)
ParameterTypeRequiredDescription
dealershipstringYesDealership ID
spawnCodestringYesVehicle spawn code
stockintegerYesNew stock value (must be >= 0)
ReturnsTypeDescription
successbooleanWhether the call succeeded
errorstring?Error message when it fails

getVehiclePrice

Get the price of a vehicle. If dealershipId is provided, returns the per-dealership price. Otherwise returns the base catalogue price.

local price, err = exports['jg-dealerships']:getVehiclePrice(spawnCode, dealershipId)
ParameterTypeRequiredDescription
spawnCodestringYesVehicle spawn code
dealershipIdstringNoDealership ID for per-dealership pricing
ReturnsTypeDescription
pricenumber|falseThe price, or false on failure
errorstring?Error message when it fails

Example:

-- Get base catalog price
local price = exports['jg-dealerships']:getVehiclePrice("adder")

-- Get price at a specific dealership
local price = exports['jg-dealerships']:getVehiclePrice("adder", "pdm")

getVehicleStock

Get the current stock level of a vehicle at a specific dealership.

local stock, err = exports['jg-dealerships']:getVehicleStock(spawnCode, dealershipId)
ParameterTypeRequiredDescription
spawnCodestringYesVehicle spawn code
dealershipIdstringYesDealership ID
ReturnsTypeDescription
stocknumber|falseThe stock, or false on failure
errorstring?Error message when it fails

Finance

getPlayerFinancedVehicles

Get all financed vehicles for a player.

local vehicles = exports['jg-dealerships']:getPlayerFinancedVehicles(identifier)
ParameterTypeRequiredDescription
identifierstringYesPlayer identifier (citizenid / identifier)
ReturnsTypeDescription
vehiclestable[]Array of financed vehicle records. Each record contains plate, financed, finance_data (JSON string), and all other columns from the vehicles table.

Example:

local vehicles = exports['jg-dealerships']:getPlayerFinancedVehicles("ABC12345")
for _, vehicle in ipairs(vehicles) do
  local financeData = json.decode(vehicle.finance_data)
  print(vehicle.plate, financeData.payments_complete .. "/" .. financeData.total_payments)
end

getFinanceByPlate

Get finance details for a specific vehicle by its plate.

local vehicle = exports['jg-dealerships']:getFinanceByPlate(plate)
ParameterTypeRequiredDescription
platestringYesVehicle plate
ReturnsTypeDescription
vehicletable?The vehicle record if financed, or nil if not found/not financed.

makeFinancePayment

Programmatically make a finance payment for an online player. Deducts money from their account.

local success, err = exports['jg-dealerships']:makeFinancePayment(src, plate)
ParameterTypeRequiredDescription
srcnumberYesPlayer server ID (must be online)
platestringYesVehicle plate
ReturnsTypeDescription
successbooleanWhether the call succeeded
errorstring?Error message when it fails

Note: This deducts the recurring payment amount from the player's account using the currency configured for the finance. The player must be online.

getPlayerFinanceCount

Get the number of active financed vehicles a player has.

local count = exports['jg-dealerships']:getPlayerFinanceCount(identifier)
ParameterTypeRequiredDescription
identifierstringYesPlayer identifier (citizenid / identifier)
ReturnsTypeDescription
countintegerNumber of financed vehicles.

Dealership Balance

getDealershipBalance

Get the current balance of a dealership's account.

local balance, err = exports['jg-dealerships']:getDealershipBalance(dealershipId)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
ReturnsTypeDescription
balancenumber|falseThe balance, or false on failure
errorstring?Error message when it fails

Note: When using framework jobs, this returns the society/job account balance. Otherwise it returns the balance column from dealership_locations.

addDealershipBalance

Add funds to a dealership's account.

local success, err = exports['jg-dealerships']:addDealershipBalance(dealershipId, amount)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
amountnumberYesAmount to add (must be > 0)
ReturnsTypeDescription
successbooleanWhether the call succeeded
errorstring?Error message when it fails

removeDealershipBalance

Remove funds from a dealership's account.

local success, err = exports['jg-dealerships']:removeDealershipBalance(dealershipId, amount)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
amountnumberYesAmount to remove (must be > 0)
ReturnsTypeDescription
successbooleanWhether the call succeeded
errorstring?Error message when it fails

Employees

isEmployee

Check if a player is an employee at a dealership.

local role = exports['jg-dealerships']:isEmployee(src, dealershipId)
ParameterTypeRequiredDescription
srcnumberYesPlayer server ID
dealershipIdstringYesDealership ID
ReturnsTypeDescription
rolestring|falseRole name (e.g. "manager", "salesman") or false if not an employee.

Note: When using framework jobs, this checks the player's current job/grade. When using the built-in employee system, this checks the dealership_employees table.

Example:

local role = exports['jg-dealerships']:isEmployee(source, "pdm")
if role then
  print("Player is a " .. role .. " at PDM")
end

hasPermission

Check if a player has a specific permission at a dealership.

local allowed = exports['jg-dealerships']:hasPermission(src, dealershipId, permission)
ParameterTypeRequiredDescription
srcnumberYesPlayer server ID
dealershipIdstringYesDealership ID
permissionstringYesPermission to check
ReturnsTypeDescription
allowedbooleanSee description above

Available Permissions:

PermissionDescription
ADMINFull access to everything
MANAGE_EMPLOYEESHire, fire, and change employee roles
MANAGE_INVENTORYOrder vehicles, manage stock, display vehicles, pricing
MANAGE_FINANCESAccess dealership bank and settings
SELLPerform direct sales and test drives
DELIVERComplete trucking delivery missions
VIEW_RECORDSView sales and order history

getEmployees

Get all employees at a dealership.

local employees = exports['jg-dealerships']:getEmployees(dealershipId)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
ReturnsTypeDescription
employeestable[]Array of employee records with id, identifier, dealership, role, joined.

Locations

getDealerships

Get all dealership locations.

local dealerships = exports['jg-dealerships']:getDealerships()
ReturnsTypeDescription
dealershipsLocation[]Array of all dealership location objects with their full configuration.

Example:

local dealerships = exports['jg-dealerships']:getDealerships()
for _, dealership in ipairs(dealerships) do
  print(dealership.id, dealership.name, dealership.type)
end

getDealership

Get a specific dealership by its ID.

local dealership = exports['jg-dealerships']:getDealership(dealershipId)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID (UUID)
ReturnsTypeDescription
dealershipLocation|falseThe dealership location object, or false if not found

Showroom

getShowroomVehicles

Get all vehicles available in a dealership's showroom (with current stock and per-dealership pricing).

local vehicles = exports['jg-dealerships']:getShowroomVehicles(dealershipId)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
ReturnsTypeDescription
vehiclesVehicle[]|falseShowroom vehicles with stock and pricing, or false if the dealership is not found

Each vehicle contains: spawn_code, brand, model, category, price (per-dealership), stock, unlimited_stock, global_stock_limit.

Example:

local vehicles = exports['jg-dealerships']:getShowroomVehicles("pdm")
if vehicles then
  for _, v in ipairs(vehicles) do
    print(v.spawn_code, v.price, v.stock)
  end
end

Coupons

createCoupon

Programmatically create a coupon for a dealership.

local coupon, err = exports['jg-dealerships']:createCoupon(dealershipId, data)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
datatableYesCoupon configuration (see below)

Coupon Data:

FieldTypeRequiredDescription
codestringNoCustom coupon code. Auto-generated if omitted (XXXX-XXXX format)
discount_typestringYes"percent" or "fixed"
discount_valuenumberYesDiscount amount (percentage or fixed value)
max_usesintegerNoMaximum total uses
per_player_limitintegerNoMaximum uses per player
expiry_dateintegerNoExpiry timestamp in milliseconds
vehicle_restrictionsstring[]NoArray of spawn codes this coupon is valid for
category_restrictionsstring[]NoArray of categories this coupon is valid for
allow_financebooleanNoWhether coupon can be used with financed purchases (default: false)
ReturnsTypeDescription
coupontable|falseThe created coupon object (with id, code, etc.), or false on failure
errstring?Error message when creation fails

Example:

local coupon, err = exports['jg-dealerships']:createCoupon("pdm", {
  discount_type = "percent",
  discount_value = 15,
  max_uses = 100,
  per_player_limit = 1,
  category_restrictions = { "super", "sports" },
  allow_finance = false
})

if coupon then
  print("Created coupon: " .. coupon.code)
end

validateCoupon

Validate a coupon code without consuming it. Useful for checking eligibility before a purchase.

local result = exports['jg-dealerships']:validateCoupon(code, dealershipId, spawnCode, category, isFinanced)
ParameterTypeRequiredDescription
codestringYesCoupon code
dealershipIdstringYesDealership ID
spawnCodestringNoVehicle spawn code (for vehicle restriction check)
categorystringNoVehicle category (for category restriction check)
isFinancedbooleanNoWhether the purchase is financed
ReturnsTypeDescription
validbooleanWhether the coupon is valid
messagestring?Error message if invalid
discountnumber?Calculated discount amount (if spawnCode provided and vehicle has a price at this dealership)
discount_typestring?"percent" or "fixed" (if valid)
discount_valuenumber?Raw discount value (if valid)

Note: This does NOT consume the coupon or increment its usage count. It is a read-only check.

Sales History

getSalesHistory

Get recent sales records for a dealership.

local sales = exports['jg-dealerships']:getSalesHistory(dealershipId, limit)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
limitintegerNoMax records to return (default: 50, max: 500)
ReturnsTypeDescription
salestable[]Array of sale records ordered by most recent first. Each record contains id, dealership, vehicle, plate, player, seller, purchase_type, paid, owed.

getTotalSales

Get the total revenue (sum of all payments received) for a dealership.

local total = exports['jg-dealerships']:getTotalSales(dealershipId)
ParameterTypeRequiredDescription
dealershipIdstringYesDealership ID
ReturnsTypeDescription
totalnumberTotal revenue amount.

On this page