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.
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
metadata
Contenttype
β
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
πΈ Behavior Based on Type
EMI:
Calculates installment if not provided.
Sets initial
installments_paid
to 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.
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
true
Successfully created the invoice.
false
Error occurred (account not found, invalid data).
π§ Notes
accountType
is auto-filled inside metadata.Will fail silently if account is invalid.
Ideal for personal, companies, and shared account invoicing.
Last updated