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_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.
Subscription:
Typical recurring bills (electricity, water, internet, etc).
Can be paired with
auto_pay.
✅ Example Usage
1. One-Time Bill
2. Subscription Bill
3. EMI-based Loan Bill
🔁 Return Value
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.
Last updated