GenerateBill
exports['kartik-banking']:GenerateBill(data)๐งพ Description
Generates an invoice entry in the kartik_banking_invoices table. Supports one-time, subscription, and emi (installment) billing types. It validates the account, calculates required fields, and stores metadata for recurring or installment-based billing.
๐ง Parameters
data: table
A Lua table containing all relevant invoice information.
| Field | Type | Required | Description |
|---|---|---|---|
owner | string | โ | Account number to which this bill applies. |
sender_name | string | โ | Sender/Issuer of the invoice (default: "System"). |
issuer_account_number | string | โ | Sender/Issuer of the invoice ( If this is sent, then the paid amount will directly be transfered to that account). |
title | string | โ | Title of the invoice (default: "Untitled Invoice"). |
description | string | โ | Description of the invoice or charge. |
frequency | string | โ | "daily", "monthly", "weekly", or "custom". |
custom_frequency_days | number | โ | Used when frequency = "custom". 0 = one-time. |
next_due | string | โ | Date/time when the bill is due (format: "YYYY-MM-DD HH:MM:SS"). |
auto_pay | boolean | โ | Enables automatic payment deduction if true. |
amount | number | โ /โ | Required unless metadata.type is "emi", in which case it's calculated. |
metadata | table | โ | Details based on bill type. Also includes accountType automatically. |
๐ฆ metadata Content
| Field | Required | Used For | Description |
|---|---|---|---|
type | โ | All | "one-time" | "emi", "subscription" |
accountType | Auto | All | Fetched from GetAccountDataByAccountNumber(owner) |
original_amount | โ for EMI | EMI | Full loan amount |
installments_total | โ for EMI | EMI | Number of EMIs |
installment_amount | Auto/Optional | EMI | Amount per EMI (calculated if not provided) |
installments_paid | Auto | EMI | Set to 0 initially |
๐ค Returns
| Type | Description |
|---|---|
true, invoiceId | The invoice was created. invoiceId can be used with GetInvoice and CancelInvoice |
false / nil | The invoice was not created (unknown account or no amount) |
Creating an invoice also fires the onInvoiceCreated event.
๐ธ Behavior Based on Type
- EMI:
- Calculates installment if not provided.
- Sets initial
installments_paidto 0. - Stores full EMI metadata.
- Disables (
active = 0) if all paid.
- One-Time:
- Requires
custom_frequency_days = 0. - Can be used for things like tow fees, medical charges, etc.
- Requires
- Subscription:
- Typical recurring bills (electricity, water, internet, etc).
- Can be paired with
auto_pay.
โ Example Usage
1. One-Time Bill
exports['kartik-banking']:GenerateBill({
owner = "1223443",
title = "Tow Service Fee",
issuer_account_number= 17273738, -- optional
frequency = "custom",
custom_frequency_days = 0,
amount = 300,
metadata = {
type = "one-time",
}
})2. Subscription Bill
exports['kartik-banking']:exports['kartik-banking']:GenerateBill({
owner = "234324",
title = "Electricity Bill",
frequency = "monthly",
issuer_account_number= 17273738, -- optional
auto_pay = true,
amount = 250,
metadata = {
type = "subscription",
}
})3. EMI-based Loan Bill
exports['kartik-banking']:GenerateBill({
owner = "432444",
title = "Vehicle Loan EMI",
frequency = "monthly",
issuer_account_number= 17273738, -- optional
auto_pay = true,
metadata = {
type = "emi",
original_amount = 1200,
installments_total = 12
-- installment_amount will be calculated automatically if not given
}
})๐ Return Value
| Type | Description |
|---|---|
true | Successfully created the invoice. |
false | Error occurred (account not found, invalid data). |
๐ง Notes
accountTypeis auto-filled inside metadata.- Will fail silently if account is invalid.
- Ideal for personal, companies, and shared account invoicing.