# Server

## Exports

### Send Mail

```lua
-- src => Player's ID
local src = source
local MailData = {
  sender = 'GKSHOP',
  image = '/html/img/icons/mail.png',
  subject = "GKSPHONE",
  message = 'TEST',
  button = {   --- If you don't want it to be a button, please remove it.
       enabled = true,
       buttonEvent = "xxxxx:client:setLocation",
       buttonData = waitingDelivery,  -- data
       buttonname = "Test Button"
  }
}
exports["gksphone"]:SendNewMail(src, MailData)
```

### Send Offline Mail

```lua
-- citizenID => ESX identifier
local xPlayer = ESX.GetPlayerFromId(source)
local citizenID = xPlayer.identifier
local MailData = {
  sender = 'GKSHOP',
  image = '/html/img/icons/mail.png',
  subject = "GKSPHONE",
  message = 'TEST',
  button = {   --- If you don't want it to be a button, please remove it.
       enabled = true,
       buttonEvent = "xxxxx:client:setLocation",
       buttonData = waitingDelivery,  -- data
       buttonname = "Test Button"
  }
}
exports["gksphone"]:SendNewMailOffline(citizenID, MailData)
```

### New Billing

```lua
-- src => Player's ID
-- label => Billing description
-- society => By which job the billingwas created
-- senderBilling => Who is the person sending the billing?
-- senderID => ESX Identifier of the billing originator
-- amount => Billing price
local src = source
local label = "Excessive Speed"
local society = "police"
local senderBilling = "GKSHOP XENKNIGHT"  -- Player Name
local senderID = "char1:4b110a7811" -- xPlayer.identifier
local amount = 500
exports["gksphone"]:NewBilling(src, label, society, senderBilling, senderID, amount)
```

### **Send Notification**

```lua
-- src => Player's ID
local src = source
local NotifData = {
    title = "Notification header", -- Notification header
    message = "Notification Message", -- Notification content message
    icon    = '/html/img/icons/messages.png', -- Icon of the notification
    duration = 5000, -- specify how many seconds,
    type = "success", -- the home screen will also appear on the notification side.
    buttonactive = false, -- Activate if you want to use the button function
    button = {
       buttonEvent = "gksphone:client:Test", -- event name to use if the button approves
       buttonData = "test", -- If you want to transfer any data in the button
    }
}
exports["gksphone"]:sendNotification(src, NotifData)
```

### New Number

```lua
local source = src -- player id
local phoneID = uniqID or nil
local NewNumber = "555555" -- example
local newNumber = exports["gksphone"]:NewNumber(source, phoneID, NewNumber)
print(newNumber) -- true/false
```

### Send Dispatch

```lua
local src = source
local ped = GetPlayerPed(src)

local reportMessage = "Dispatch Message"
local reportPhoto = "Image Link" or nil
local job = "police" -- job code 
local anonymous = false -- or true
local playerCoords = GetEntityCoords(ped)
local streedZone = "Street name" or "Unknown"
local sendDispatch = exports["gksphone"]:SendDispatch(src, reportMessage, reportPhoto, job, anonymous, playerCoords, streedZone)
print(sendDispatch) -- true/false
```

### Bank History Save

```lua
local src = source
local type = 1 -- 1 (-) or 2 (+)
local amount = 500
local description = "Bank History Desc"

local historySave = exports["gksphone"]:BankSaveHistory(src, type, amount, description)
print(historySave) -- true/false
```

### Job Status Change

The job in the Dispatch section is for opening and closing

```lua
local job = "police" -- job code
local status = true -- true or false
exports["gksphone"]:JobStatusChange(job, status)
```

### Is Unpaid Bill

To inquire if the player has any outstanding bills

```lua
local xPlayer = ESX.GetPlayerFromId(source)
local citizenID = xPlayer.identifier
local isBills = exports["gksphone"]:IsUnpaidBillsbyCid(citizenID)
print(isBills) -- true or false
```

### Change Number

Change phone number

```lua
local phoneID = "GKSXXXXXXX" -- Phone Uniq ID
local oldNumber = "5555"
local newNumber = "2222"
local changeNumber = exports["gksphone"]:ChangeNumber(phoneID, oldNumber, newNumber)
print(changeNumber) -- true or false
```

## Phone Data Exports

### GetPhoneBySource

Find phone number with Source

```lua
local src = source
local phoneNumber = exports["gksphone"]:GetPhoneBySource(src)
print(phoneNumber)

-- OR

local xPlayer = ESX.GetPlayerFromId(source)
local phoneNumber = xPlayer.getMeta("phoneNumber")
print(phoneNumber)
```

### GetSourceByPhone

Finding a source by phone number

```lua
local phoneNumber = number
local source = exports["gksphone"]:GetSourceByPhone(phoneNumber)
print(source)
```

### GetPhoneDataBySource

Access the data of the phone used with the Source number

```lua
local src = source
local phoneData = exports["gksphone"]:GetPhoneDataBySource(src)
print(json.encode(phoneData))
```

### GetPhoneDataByNumber

Accessing the phone's data with the phone number

```lua
local phoneNumber = number
local phoneData = exports["gksphone"]:GetPhoneDataByNumber(phoneNumber)
print(json.encode(phoneData))
```

### GetPhoneDataBySetupOwner

Accessing all phone data of the player

```lua
local xPlayer = ESX.GetPlayerFromId(source)
local citizenID = xPlayer.identifier
local phoneData = exports["gksphone"]:GetPhoneDataBySetupOwner(citizenID)
print(json.encode(phoneData))
```

### GetPhoneDataByPhoneUniqID

Access phone data with the phone's UniqID

```lua
local phoneUniqID = id
local phoneData = exports["gksphone"]:GetPhoneDataByPhoneUniqID(phoneUniqID)
print(json.encode(phoneData))
```

### GetPhoneDataByCitizenID

Access phone data with the user's ID (You will access the data of the last phone the user opened)

```lua
local xPlayer = ESX.GetPlayerFromId(source)
local citizenID = xPlayer.identifier
local phoneData = exports["gksphone"]:GetPhoneDataByCitizenID(citizenID)
print(json.encode(phoneData))
```

### GetPhoneLangBySource

The language the user chooses on the phone

```lua
local src = source
local PhoneLang = exports["gksphone"]:GetPhoneLangBySource(src)
print(PhoneLang)
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gkshop.org/gksphone-v1/gksphonev2/exports/server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
