Início › Documentação › Exports · origen_billing

Exports · origen_billing

Todos os exports são registados com o nome de recurso origen_billing.


Exports do servidor

CreateInvoice(target, amount, description, jobName, author, notes?, company?) → boolean, string|number

Cria uma fatura individual a partir de outro recurso.

lua
local ok, result = exports['origen_billing']:CreateInvoice(
    'ABC12345',   -- target citizenid (or server source as number)
    500,          -- amount
    'Medical fee',
    'ambulance',
    'XYZ99999',   -- author citizenid
    'Notes here', -- optional
    nil           -- optional company label override
)
-- ok = true, result = invoiceId (number)
-- ok = false, result = reason (string)
Parâmetro Tipo Descrição
target string|number Citizenid ou source do servidor do destinatário
amount number Valor da fatura (tem de ser > 0)
description string Descrição curta apresentada na fatura
jobName string Tem de corresponder a um job autorizado com canInvoice = true
author string Citizenid do jogador que emite a fatura
notes string|nil Notas internas opcionais
company string|nil Substituição opcional da etiqueta de empresa apresentada

CreateInvoiceWithItems(target, jobName, author, items, notes?, company?) → boolean, string|number

Cria uma fatura com um carrinho de linhas individuais. O total é calculado automaticamente.

lua
local ok, result = exports['origen_billing']:CreateInvoiceWithItems(
    'ABC12345',
    'mechanic',
    'XYZ99999',
    {
        { name = 'Oil change', price = 150, quantity = 1 },
        { name = 'Tire rotation', price = 80, quantity = 4, product_id = 12 },
    },
    nil, -- notes
    nil  -- company override
)
Parâmetro Tipo Descrição
target string|number Citizenid ou source do servidor do destinatário
jobName string Tem de corresponder a um job autorizado com canInvoice = true
author string Citizenid do jogador que emite a fatura
items table Array de { name, price, quantity, product_id? }
notes string|nil Notas internas opcionais
company string|nil Substituição opcional da etiqueta de empresa

CreateBulkInvoice(targets, amount, description, jobName, author, notes?, company?) → table

Cria a mesma fatura para vários destinatários de uma só vez.

lua
local result = exports['origen_billing']:CreateBulkInvoice(
    { 'ABC12345', 'DEF67890' },
    200,
    'Event fee',
    'police',
    'XYZ99999'
)
-- result = { total, successful, failed, details = { { target, success, result }, ... } }
Campo devolvido Tipo Descrição
total number Total de destinatários tentados
successful number Número de faturas criadas com sucesso
failed number Número de falhas
details table Resultado por destinatário: { target, success, result }

GetJobStatistics(jobName) → table

Devolve as estatísticas de faturação de um job.

lua
local res = exports['origen_billing']:GetJobStatistics('police')
-- res = { success = true, data = { total, pending, paid, cancelled, totalRevenue, totalCommissions, averageAmount } }

GetPlayerTotalDebt(target) → number

Devolve o valor total das faturas pendentes de um jogador. Devolve 0 se o jogador não tiver faturas pendentes ou não puder ser resolvido.

lua
local debt = exports['origen_billing']:GetPlayerTotalDebt('ABC12345')
-- or by server source:
local debt = exports['origen_billing']:GetPlayerTotalDebt(source)

GetPlayerPendingInvoices(target) → table

Devolve a lista de faturas pendentes de um jogador.

lua
local invoices = exports['origen_billing']:GetPlayerPendingInvoices('ABC12345')
-- Array of { id, job_name, company_label, amount, description, notes, context_data, status, created_at }

CanInvoice(source, jobName) → boolean

Devolve true se o jogador indicado estiver atualmente a trabalhar no job especificado e esse job estiver autorizado a emitir faturas.

lua
local allowed = exports['origen_billing']:CanInvoice(source, 'ambulance')

Exports de integração com a polícia

Estes exports destinam-se ao origen_police (ou a qualquer recurso de polícia) e seguem o modelo de faturação policial.

CreatePoliceInvoice(targetIdentifier, amount, description, jobName, author, contextData) → boolean, string|number

Cria uma fatura policial. O campo contextData é uma string codificada em JSON com metadados específicos da polícia (reportid, months, concepts, title, etc.).

lua
local ok, result = exports['origen_billing']:CreatePoliceInvoice(
    'ABC12345',
    1500,
    'Traffic violation | Speeding',
    'police',
    'Officer Smith',
    json.encode({
        title    = 'Traffic Fines',
        reportid = 42,
        months   = 0,
        concepts = {
            { name = 'Speeding', price = 1000 },
            { name = 'No license', price = 500 },
        },
    })
)

UpdatePoliceInvoice(invoiceId, data) → boolean

Atualiza o valor e os metadados de uma fatura policial pendente.

lua
exports['origen_billing']:UpdatePoliceInvoice(invoiceId, {
    price        = 2000,
    description  = 'Updated charges',
    context_data = json.encode({ ... }),
})

CancelPoliceInvoice(invoiceId) → boolean

Cancela uma fatura policial pendente. O recurso que a chama tem de verificar as permissões antes de invocar este export.

lua
exports['origen_billing']:CancelPoliceInvoice(invoiceId)

PayPoliceInvoice(source, invoiceId, paymentMethod) → boolean, string

Paga uma fatura policial. Delega em InvoiceManager, que trata de descontar o dinheiro e do depósito na sociedade.

lua
local ok, reason = exports['origen_billing']:PayPoliceInvoice(source, invoiceId, 'bank')

GetPoliceBillsByIdentifier(identifier, jobCategory?) → boolean, table

Devolve o histórico completo de faturas de um cidadão (todos os estados). Usado nos perfis de cidadão do tablet da polícia.

lua
local ok, bills = exports['origen_billing']:GetPoliceBillsByIdentifier('ABC12345', 'police')

GetPolicePendingByIdentifier(identifier) → boolean, table

Devolve apenas as faturas policiais pendentes de um cidadão. Usado pelos NPC de pagamento.

lua
local ok, bills = exports['origen_billing']:GetPolicePendingByIdentifier('ABC12345')

GetPoliceInvoicesByReportId(reportid) → boolean, table

Devolve todas as faturas policiais associadas a um ID de relatório específico.

lua
local ok, bills = exports['origen_billing']:GetPoliceInvoicesByReportId(42)

GetPoliceDebtorsByCategory(jobCategory) → boolean, table

Devolve uma lista de devedores com faturas policiais pendentes, agrupados por citizenid com a respetiva dívida total.

lua
local ok, debtors = exports['origen_billing']:GetPoliceDebtorsByCategory('police')
-- debtors = { { citizenid, totalprice }, ... }