Kartik Scripts

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.

FieldTypeRequiredDescription
ownerstringโœ…Account number to which this bill applies.
sender_namestringโŒSender/Issuer of the invoice (default: "System").
issuer_account_numberstringโŒSender/Issuer of the invoice ( If this is sent, then the paid amount will directly be transfered to that account).
titlestringโŒTitle of the invoice (default: "Untitled Invoice").
descriptionstringโŒDescription of the invoice or charge.
frequencystringโŒ"daily", "monthly", "weekly", or "custom".
custom_frequency_daysnumberโŒUsed when frequency = "custom". 0 = one-time.
next_duestringโŒDate/time when the bill is due (format: "YYYY-MM-DD HH:MM:SS").
auto_paybooleanโŒEnables automatic payment deduction if true.
amountnumberโœ…/โŒRequired unless metadata.type is "emi", in which case it's calculated.
metadatatableโœ…Details based on bill type. Also includes accountType automatically.

๐Ÿ“ฆ metadata Content

FieldRequiredUsed ForDescription
typeโœ…All"one-time" | "emi", "subscription"
accountTypeAutoAllFetched from GetAccountDataByAccountNumber(owner)
original_amountโœ… for EMIEMIFull loan amount
installments_totalโœ… for EMIEMINumber of EMIs
installment_amountAuto/OptionalEMIAmount per EMI (calculated if not provided)
installments_paidAutoEMISet to 0 initially

๐Ÿ“ค Returns

TypeDescription
true, invoiceIdThe invoice was created. invoiceId can be used with GetInvoice and CancelInvoice
false / nilThe 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_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

TypeDescription
trueSuccessfully created the invoice.
falseError 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.

On this page