Skip to main content

InvoiceTemplate

The InvoiceTemplate interface represents a reusable invoice template that can be used to quickly generate new invoices with predefined items, customer details, and settings.
id
string
required
Unique identifier for the template
name
string
required
Display name for the template (e.g., “Monthly Retainer”, “Consulting Services”)
description
string
Optional description explaining when or how to use this template
customer
Partial<Customer>
required
items
Partial<InvoiceItem>[]
required
notes
string
Optional default notes or terms to include on invoices created from this template
taxRate
number
Optional default tax rate as a percentage (e.g., 10 for 10%)
currency
string
required
Three-letter ISO 4217 currency code (e.g., “USD”, “EUR”, “GBP”)
createdAt
string
required
Timestamp when the template was created in ISO 8601 format

TypeScript definition

export interface InvoiceTemplate {
  id: string;
  name: string;
  description?: string;
  customer: Partial<Customer>;
  items: Partial<InvoiceItem>[];
  notes?: string;
  taxRate?: number;
  currency: string;
  createdAt: string;
}

Example

const template: InvoiceTemplate = {
  id: "tmpl_abc123",
  name: "Web Development - Monthly Retainer",
  description: "Standard monthly retainer for ongoing web development services",
  customer: {
    // Leave most fields empty for flexibility
    country: "United States",
    state: "CA"
  },
  items: [
    {
      description: "Monthly Development Hours",
      rate: 150,
      // quantity will be filled in per invoice
    },
    {
      description: "Project Management",
      quantity: 1,
      rate: 500
    },
    {
      description: "Hosting & Maintenance",
      quantity: 1,
      rate: 200
    }
  ],
  notes: "Payment due within 30 days. Includes up to 2 hours of support.",
  taxRate: 8.5,
  currency: "USD",
  createdAt: "2026-01-15T12:00:00Z"
};

Creating invoices from templates

Templates serve as blueprints for new invoices. When creating an invoice from a template:
  1. Copy predefined items and fill in missing quantities
  2. Merge template customer data with specific customer details
  3. Use template defaults for currency, tax rate, and notes
  4. Generate new invoice-specific fields (id, invoiceNumber, dates, status)
import type { Invoice, InvoiceTemplate } from './types';

function createInvoiceFromTemplate(
  template: InvoiceTemplate,
  customer: Customer,
  overrides?: Partial<Invoice>
): Invoice {
  return {
    id: generateId(),
    invoiceNumber: generateInvoiceNumber(),
    date: new Date().toISOString(),
    dueDate: addDays(new Date(), 30).toISOString(),
    status: "draft",
    customer: {
      ...template.customer,
      ...customer // Override template customer with actual customer
    },
    items: template.items.map(item => ({
      id: generateId(),
      description: item.description || "",
      quantity: item.quantity || 1,
      rate: item.rate || 0,
      discount: item.discount,
      taxRate: item.taxRate
    })),
    notes: template.notes,
    taxRate: template.taxRate,
    currency: template.currency,
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString(),
    ...overrides
  };
}

Use cases

Templates are useful for:
  • Recurring services: Monthly retainers with standard line items
  • Package deals: Predefined service bundles at set prices
  • Industry-specific invoices: Templates for common services in your industry
  • Multi-currency invoicing: Separate templates for different currencies
  • Regional variations: Templates with different tax rates or terms by region

Build docs developers (and LLMs) love