> For the complete documentation index, see [llms.txt](https://fantasy-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fantasy-scripts.gitbook.io/docs/advanced-government/exports.md).

# Exports

## Taxation System Exports

### Available Exports

#### 1. AddTax

Add a tax record to the government database.

**Syntax:**

```lua
exports['fs-government']:AddTax(taxType, amount, payerIdentifier, payerName, metadata)
```

**Parameters:**

* `taxType` (string) - Type of tax: 'salary', 'business', 'vehicle', 'property', or custom type
* `amount` (number) - Tax amount (must be > 0)
* `payerIdentifier` (string) - Player identifier who paid the tax
* `payerName` (string, optional) - Player name for display
* `metadata` (table, optional) - Additional data to store with the tax record

**Returns:** boolean - Success status

**Example:**

```lua
-- Add a salary tax
exports['fs-government']:AddTax('salary', 150, 'license:abc123', 'John Doe', {
    job = 'police',
    gross_salary = 1000,
    net_salary = 850
})

-- Add a vehicle tax
exports['fs-government']:AddTax('vehicle', 500, 'license:abc123', 'John Doe', {
    vehicle_model = 'adder',
    vehicle_plate = 'ABC 123'
})

-- Add a custom tax type
exports['fs-government']:AddTax('parking_fine', 250, 'license:abc123', 'John Doe', {
    location = 'Legion Square',
    violation = 'Illegal Parking'
})
```

***

#### 2. GetTaxRates

Get all current tax rates.

**Syntax:**

```lua
local rates = exports['fs-government']:GetTaxRates()
```

**Returns:** table - Tax rates object

```lua
{
    salary = 0.15,      -- 15%
    business = 0.10,    -- 10%
    vehicle = 0.05,     -- 5%
    property = 0.08     -- 8%
}
```

**Example:**

```lua
local rates = exports['fs-government']:GetTaxRates()
print('Salary tax rate: ' .. (rates.salary * 100) .. '%')
```

***

#### 3. GetTaxRate

Get a specific tax rate.

**Syntax:**

```lua
local rate = exports['fs-government']:GetTaxRate(taxType)
```

**Parameters:**

* `taxType` (string) - Type of tax: 'salary', 'business', 'vehicle', 'property'

**Returns:** number - Tax rate as decimal (e.g., 0.15 for 15%)

**Example:**

```lua
local salaryTaxRate = exports['fs-government']:GetTaxRate('salary')
print('Salary tax: ' .. (salaryTaxRate * 100) .. '%')
```

***

#### 4. CalculateTax

Calculate tax amount based on base amount and tax type.

**Syntax:**

```lua
local taxAmount = exports['fs-government']:CalculateTax(amount, taxType)
```

**Parameters:**

* `amount` (number) - Base amount to calculate tax on
* `taxType` (string) - Type of tax

**Returns:** number - Calculated tax amount (rounded down)

**Example:**

```lua
local salary = 1000
local taxAmount = exports['fs-government']:CalculateTax(salary, 'salary')
local netSalary = salary - taxAmount

print('Gross: $' .. salary)
print('Tax: $' .. taxAmount)
print('Net: $' .. netSalary)
```

***

#### 5. GetTaxRevenue

Get tax revenue statistics for a specific period.

**Syntax:**

```lua
local revenue = exports['fs-government']:GetTaxRevenue(days, taxType)
```

**Parameters:**

* `days` (number, optional) - Number of days to look back (default: 30)
* `taxType` (string, optional) - Filter by specific tax type

**Returns:** table - Revenue breakdown

```lua
{
    total = 15000,
    period_days = 30,
    breakdown = {
        salary = { amount = 8000, count = 50 },
        business = { amount = 5000, count = 20 },
        vehicle = { amount = 2000, count = 10 }
    }
}
```

**Example:**

```lua
-- Get all tax revenue for last 7 days
local revenue = exports['fs-government']:GetTaxRevenue(7)
print('Total tax revenue (7 days): $' .. revenue.total)

-- Get only salary tax revenue for last 30 days
local salaryRevenue = exports['fs-government']:GetTaxRevenue(30, 'salary')
print('Salary tax revenue: $' .. salaryRevenue.total)
```

***

#### 6. GetTaxRecords

Get detailed tax records with optional filters.

**Syntax:**

```lua
local records = exports['fs-government']:GetTaxRecords(filters)
```

**Parameters:**

* `filters` (table, optional) - Filter options:
  * `taxType` (string) - Filter by tax type
  * `payerIdentifier` (string) - Filter by player identifier
  * `startDate` (string) - Filter by start date (YYYY-MM-DD HH:MM:SS)
  * `endDate` (string) - Filter by end date (YYYY-MM-DD HH:MM:SS)
  * `limit` (number) - Maximum records to return (default: 100)

**Returns:** table - Array of tax records

**Example:**

```lua
-- Get all tax records for a specific player
local records = exports['fs-government']:GetTaxRecords({
    payerIdentifier = 'license:abc123',
    limit = 50
})

for i, record in ipairs(records) do
    print(record.tax_type .. ': $' .. record.amount)
end

-- Get salary taxes from last month
local records = exports['fs-government']:GetTaxRecords({
    taxType = 'salary',
    startDate = '2024-01-01 00:00:00',
    endDate = '2024-01-31 23:59:59'
})
```

***

#### 7. UpdateTaxRates

Update tax rates (requires government permission).

**Syntax:**

```lua
local success = exports['fs-government']:UpdateTaxRates(source, newRates)
```

**Parameters:**

* `source` (number) - Player server ID
* `newRates` (table) - New tax rates object (values must be between 0 and 1)

**Returns:** boolean - Success status

**Example:**

```lua
local newRates = {
    salary = 0.20,      -- 20%
    business = 0.15,    -- 15%
    vehicle = 0.10,     -- 10%
    property = 0.12     -- 12%
}

local success = exports['fs-government']:UpdateTaxRates(source, newRates)
if success then
    print('Tax rates updated successfully')
end
```

***

### Server Events

#### fs-government:server:addTax

Trigger this event to add a tax record from another resource.

**Example:**

```lua
TriggerEvent('fs-government:server:addTax', 'salary', 150, 'license:abc123', 'John Doe', {
    job = 'police',
    gross_salary = 1000
})
```

***

#### fs-government:server:requestTaxRates

Request current tax rates (sends response to client).

**Example:**

```lua
-- Server side
TriggerEvent('fs-government:server:requestTaxRates')

-- Client side - listen for response
RegisterNetEvent('fs-government:client:receiveTaxRates', function(rates)
    print('Current salary tax: ' .. (rates.salary * 100) .. '%')
end)
```

***

#### fs-government:server:processSalaryTax

Automatically process salary tax when paying salaries.

**Example:**

```lua
-- In your paycheck script
TriggerEvent('fs-government:server:processSalaryTax', playerId, 1000, 'police')
-- This will:
-- 1. Calculate tax based on current salary tax rate
-- 2. Remove tax from player's bank
-- 3. Record the tax in government database
-- 4. Notify the player
```

***

### Events Triggered by Taxation System

#### fs-government:server:taxRecorded

Triggered when a tax is recorded in the database.

**Example:**

```lua
AddEventHandler('fs-government:server:taxRecorded', function(taxData)
    print('Tax recorded:')
    print('  Type: ' .. taxData.taxType)
    print('  Amount: $' .. taxData.amount)
    print('  Payer: ' .. taxData.payerName)
end)
```

***

#### fs-government:server:taxRatesUpdated

Triggered when tax rates are updated.

**Example:**

```lua
AddEventHandler('fs-government:server:taxRatesUpdated', function(newRates, updatedBy)
    print('Tax rates updated by player ' .. updatedBy)
    print('New salary rate: ' .. (newRates.salary * 100) .. '%')
end)
```

***

### Integration Examples

#### Example 1: Paycheck System Integration

```lua
-- In your paycheck resource
RegisterNetEvent('paycheck:receive', function()
    local source = source
    local Player = GetPlayer(source) -- Your framework function

    local grossSalary = 1000

    -- Calculate and deduct tax
    local taxAmount = exports['fs-government']:CalculateTax(grossSalary, 'salary')
    local netSalary = grossSalary - taxAmount

    -- Give net salary to player
    Player.addAccountMoney('bank', netSalary)

    -- Record tax
    exports['fs-government']:AddTax('salary', taxAmount, Player.identifier, Player.getName(), {
        job = Player.job.name,
        grade = Player.job.grade,
        gross_salary = grossSalary,
        net_salary = netSalary
    })

    -- Notify player
    TriggerClientEvent('notification', source, 'Paycheck received: $' .. netSalary .. ' (Tax: $' .. taxAmount .. ')')
end)
```

***

#### Example 2: Vehicle Shop Integration

```lua
-- In your vehicle shop resource
RegisterNetEvent('vehicleshop:purchase', function(vehicleModel, price, plate)
    local source = source
    local Player = GetPlayer(source)

    -- Calculate vehicle tax
    local taxAmount = exports['fs-government']:CalculateTax(price, 'vehicle')
    local totalPrice = price + taxAmount

    -- Check if player has enough money
    if Player.getMoney() >= totalPrice then
        -- Remove money
        Player.removeMoney(totalPrice)

        -- Give vehicle (your code here)

        -- Record tax
        exports['fs-government']:AddTax('vehicle', taxAmount, Player.identifier, Player.getName(), {
            vehicle_model = vehicleModel,
            vehicle_plate = plate,
            vehicle_price = price
        })

        TriggerClientEvent('notification', source, 'Vehicle purchased: $' .. price .. ' + Tax: $' .. taxAmount)
    else
        TriggerClientEvent('notification', source, 'Insufficient funds. Total: $' .. totalPrice)
    end
end)
```

***

#### Example 3: Business System Integration

```lua
-- In your business resource
RegisterNetEvent('business:collectRevenue', function()
    local source = source
    local Player = GetPlayer(source)
    local businessRevenue = 5000

    -- Calculate business tax
    local taxAmount = exports['fs-government']:CalculateTax(businessRevenue, 'business')
    local netRevenue = businessRevenue - taxAmount

    -- Give net revenue to business owner
    Player.addAccountMoney('bank', netRevenue)

    -- Record tax
    exports['fs-government']:AddTax('business', taxAmount, Player.identifier, Player.getName(), {
        business_name = GetBusinessName(source),
        gross_revenue = businessRevenue,
        net_revenue = netRevenue
    })

    TriggerClientEvent('notification', source, 'Revenue collected: $' .. netRevenue .. ' (Tax: $' .. taxAmount .. ')')
end)
```

***

#### Example 4: Custom Tax Type

```lua
-- Add a parking fine as a tax
RegisterNetEvent('parking:fine', function(targetId, fineAmount)
    local source = source
    local Officer = GetPlayer(source)
    local Target = GetPlayer(targetId)

    -- Remove money from target
    if Target.removeAccountMoney('bank', fineAmount) then
        -- Record as custom tax
        exports['fs-government']:AddTax('parking_fine', fineAmount, Target.identifier, Target.getName(), {
            issued_by = Officer.getName(),
            location = GetPlayerLocation(targetId),
            reason = 'Illegal Parking'
        })

        TriggerClientEvent('notification', targetId, 'Parking fine issued: $' .. fineAmount)
        TriggerClientEvent('notification', source, 'Fine issued successfully')
    end
end)
```

#### Example 5: ESX DMV School

```lua
ESX.RegisterServerCallback('esx_dmvschool:canYouPay', function(source, cb, type)
    local xPlayer = ESX.GetPlayerFromId(source)
    local basePrice = Config.Prices[type] or 0

    if basePrice <= 0 then
        cb(false)
        return
    end

    -- 🧮 Calculate DMV tax (make sure 'dmv_fee' exists in Config.Taxation.rates)
    local taxAmount = exports['fs-government']:CalculateTax(basePrice, 'dmv_fee')
    local totalPrice = basePrice + taxAmount

    if xPlayer.getMoney() >= totalPrice then
        -- 💸 Remove total amount (price + tax)
        xPlayer.removeMoney(totalPrice, "DMV Purchase + Tax")

        -- 🧾 Record the tax in government system
        exports['fs-government']:AddTax('dmv_fee', taxAmount, xPlayer.identifier, xPlayer.getName(), {
            fee_type = type,
            base_price = basePrice,
            total_paid = totalPrice,
            location = "Driving School"
        })

        -- 📢 Notify player
        TriggerClientEvent('esx:showNotification', source,
            ('You paid $%s + $%s DMV tax = $%s total'):format(basePrice, taxAmount, totalPrice)
        )

        cb(true)
    else
        -- ❌ Not enough money
        TriggerClientEvent('esx:showNotification', source,
            ('Not enough money. You need $%s total (including tax).'):format(totalPrice)
        )
        cb(false)
    end
end)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://fantasy-scripts.gitbook.io/docs/advanced-government/exports.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
