API reference
Orders, products, customers and invoices
Statuses, attention rules, views and totals of the commerce and billing modules.
Everything in utils/ is a pure function: it takes data and returns data, with no Vue and no global state. Pass the current date as now so results are deterministic. Each file has its unit tests in tests/unit/.
orderStepIndex()
The fulfilment step of an order.
orderStepIndex(order: Pick<Order, 'status'>): number
orderStepDate()
When an order reached a step.
orderStepDate(order: Pick<Order, 'events'>, step: OrderStep): string | undefined
orderDispatchDue()
The date an order must be dispatched.
orderDispatchDue(order: Order): string
isOrderLate()
Whether an order missed its dispatch or delivery window.
isOrderLate(order: Order, now: Date): boolean
matchesOrderView()
Whether an order belongs to a view.
matchesOrderView(order: Pick<Order, 'status' | 'paymentStatus'>, view: OrderView): boolean
orderViewCounts()
The count of every order view.
orderViewCounts(orders: Pick<Order, 'status' | 'paymentStatus'>[]): Record<OrderView, number>
orderAttention()
Orders that need attention now.
orderAttention(orders: Order[], now: Date): { late: number; unpaid: number; }lateunpaidproductStock()
Total stock across variants.
productStock(product: Pick<Product, 'variants'>): number
productStockState()
in, low or out of stock.
productStockState(product: StockFields): ProductStockState
productSales()
Units sold in the period.
productSales(product: Pick<Product, 'dailySales'>): number
productRevenue()
Revenue in the period.
productRevenue(product: Pick<Product, 'dailySales' | 'price'>): number
productSalesTrend()
Change of sales against the previous half.
productSalesTrend(product: Pick<Product, 'dailySales'>): number
productDaysLeft()
Days until the stock runs out at the current pace.
productDaysLeft(product: Pick<Product, 'variants' | 'dailySales'>): number | undefined
productMargin()
Margin from price and cost.
productMargin(product: Pick<Product, 'price' | 'cost'>): number
productDiscount()
Discount from the compare-at price.
productDiscount(product: Pick<Product, 'price' | 'compareAtPrice'>): number
matchesProductView()
Whether a product belongs to a view.
matchesProductView(product: Pick<Product, 'status' | 'variants' | 'lowStockThreshold'>, view: ProductView): boolean
productViewCounts()
The count of every product view.
productViewCounts(products: Pick<Product, 'status' | 'variants' | 'lowStockThreshold'>[]): Record<ProductView, number>
productAttention()
Products out of stock or running out soon.
productAttention(products: Product[]): { out: number; runningLow: number; }outrunningLowcustomerSegment()
VIP, regular, new or at risk, derived from activity.
customerSegment(customer: ActivityFields, now: Date): CustomerSegment
customerDaysSinceOrder()
Days since the last order.
customerDaysSinceOrder(customer: Pick<Customer, 'lastOrder'>, now: Date): number
customerAverageOrder()
Average order value.
customerAverageOrder(customer: Pick<Customer, 'spent' | 'orders'>): number
customerSpendTrend()
Spend trend over 12 months.
customerSpendTrend(customer: Pick<Customer, 'monthlySpend'>): number
customerOrderInterval()
Average days between orders.
customerOrderInterval(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders'>): number | undefined
customerNextOrderIn()
Days until the expected next order.
customerNextOrderIn(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders' | 'status'>, now: Date): number | undefined
matchesCustomerView()
Whether a customer belongs to a view.
matchesCustomerView(customer: ActivityFields, view: CustomerView, now: Date): boolean
customerViewCounts()
The count of every customer view.
customerViewCounts(customers: ActivityFields[], now: Date): Record<CustomerView, number>
customerAttention()
Customers to win back.
customerAttention(customers: Customer[], now: Date): { atRisk: number; value: number; }atRiskvalueinvoiceTotals()
Subtotal, discount, tax and total.
invoiceTotals(invoice: Pick<Invoice, 'lines' | 'taxRate' | 'discountRate'>): InvoiceTotals
subtotaldiscounttaxtotalinvoicePaid()
The amount paid so far.
invoicePaid(invoice: Pick<Invoice, 'payments'>): number
invoiceBalance()
The amount still due.
invoiceBalance(invoice: Invoice): number
invoiceDaysToDue()
Days to the due date (negative when overdue).
invoiceDaysToDue(invoice: Pick<Invoice, 'due'>, now: Date): number
invoiceStatus()
Draft, pending, partial, overdue or paid.
invoiceStatus(invoice: Invoice, now: Date): InvoiceStatus
invoiceAgingBucket()
The aging bucket of an unpaid invoice.
invoiceAgingBucket(invoice: Invoice, now: Date): InvoiceAgingBucket | undefined
invoiceAging()
Outstanding amounts by aging bucket.
invoiceAging(invoices: Invoice[], now: Date): { buckets: Record<InvoiceAgingBucket, number>; count: number; total: number; }bucketscounttotalinvoicePaidSince()
Amount collected since a date.
invoicePaidSince(invoices: Invoice[], since: Date): number
averageCollectionDays()
Average days to get paid.
averageCollectionDays(invoices: Invoice[]): number | undefined
matchesInvoiceView()
Whether an invoice belongs to a view.
matchesInvoiceView(invoice: Invoice, view: InvoiceView, now: Date): boolean
invoiceViewCounts()
The count of every invoice view.
invoiceViewCounts(invoices: Invoice[], now: Date): Record<InvoiceView, number>