@zenuinebit/supplier-ledger
v0.1.0
Published
Supplier payables: bills, payments, TDS withheld, ageing, due list, payment planning and early-payment discounts.
Readme
@zenuinebit/supplier-ledger
Payables for one supplier: statement, open bills with payment matching, ageing, a due list, payment planning with a limited budget, and early-payment discounts. Built on @zenuinebit/customer-ledger but speaking the language of payables. Amounts are positive integers in minor units; dates are "YYYY-MM-DD".
import { statement, openBills, balance, ageing, dueList, paymentPlan, earlyPaymentOffers, type SupplierTxn } from "@zenuinebit/supplier-ledger";
const txns: SupplierTxn[] = [
{ id: "B1", date: "2025-03-01", type: "bill", amount: 100_000, dueDate: "2025-03-31",
terms: { percent: 2, withinDays: 10 } }, // "2/10 net 30"
{ id: "B2", date: "2025-03-05", type: "bill", amount: 50_000, dueDate: "2025-04-04" },
{ id: "T1", date: "2025-03-20", type: "tds", amount: 2_000, appliesTo: "B1" }, // TDS you withheld
{ id: "P1", date: "2025-03-20", type: "payment", amount: 98_000, appliesTo: "B1" },
];
balance(txns, "2025-03-25"); // what you owe: 50_000
openBills(txns, "2025-04-10"); // each bill: paid, balance, status, daysOverdue; plus owed, overdue, advance
ageing(txns, "2025-04-10"); // Current, 1-30, 31-60, 61-90, 90+
dueList(txns, "2025-03-25", 7); // { overdue, dueSoon, totals }
// Which bills should this week's cash cover?
paymentPlan(txns, "2025-04-10", { budget: 30_000, strategy: "earliest-due" });
// { payments: [{ id, pay, partial }], total, remainingBudget, unpaid }
// Early-payment discounts still on offer
earlyPaymentOffers(txns, "2025-03-05");
// [{ billId: "B1", deadline: "2025-03-11", discount: 2000, payNow: 98000, impliedAnnualPercent: 37.2 }]Transaction types: increase what you owe: opening, bill, extra-charge. Reduce it: payment, credit-note (issued by the supplier), purchase-return, tds (withheld, to be paid to the government), discount (early-payment discount taken). A reducing entry can name its bill with appliesTo; otherwise the oldest due bill is paid first.
Good to know
- A positive balance means you owe the supplier; a negative one means they hold an advance from you (
advancein the results). - To take an early-payment discount, post a
discountfor the offer'sdiscountand apaymentforpayNow, both withappliesTothe bill. impliedAnnualPercentis what paying early earns as a yearly rate (a "2/10 net 30" discount is about 37%). It isnullif the bill is not due after the discount deadline.paymentPlanonly plans. By default it covers what is due today or overdue; passdueWithinDaysto include bills falling due soon,allowPartial: falseto avoid part payments, and astrategyofearliest-due,smallest-firstorlargest-first.- Pair with
@zenuinebit/tds-calcto work out the TDS to withhold, and@zenuinebit/purchase-gstfor input credit.
Not included: several suppliers in one call (keep a list per supplier), storage, remittance advice, and foreign currency.
