Invoice schema for PhoenixKit Billing system.
Invoices are generated from orders and sent to customers for payment.
They include receipt functionality once payment is confirmed.
Schema Fields
Identity & Relations
user_id: Foreign key to the userorder_id: Foreign key to the source order (optional)invoice_number: Unique invoice identifier (e.g., "INV-2024-0001")status: Invoice status workflow
Financial
subtotal, tax_amount, tax_rate, total: Financial amountscurrency: ISO 4217 currency codedue_date: Payment due date
Billing Details
billing_details: Full snapshot of billing profileline_items: Copy of order line itemspayment_terms: Payment terms textbank_details: Bank account for payment
Receipt
receipt_number: Receipt identifier (generated after payment)receipt_generated_at: When receipt was generatedreceipt_data: Additional receipt data (PDF URL, etc.)
Status Workflow
draft → sent → paid
↘
overdue → paid
↘
void
Usage Examples
# Generate invoice from order
{:ok, invoice} = Billing.create_invoice_from_order(order)
# Send invoice
{:ok, invoice} = Billing.send_invoice(invoice)
# Mark as paid (generates receipt)
{:ok, invoice} = Billing.mark_invoice_paid(invoice)
# Get receipt
receipt = Billing.get_receipt(invoice)