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


💸 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

Type
Description

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