Documentation Index
Fetch the complete documentation index at: https://docs.ledgerbox.io/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Receipt model extracts and structures information from receipts, including merchant information, line items, payments, and tax details.
Schema Structure
Root Level Fields
| Field | Type | Description |
|---|
MerchantName | string? | Name of the merchant issuing the receipt |
MerchantPhoneNumber | string? | Listed phone number of merchant |
MerchantAddress | Address? | Listed address of merchant |
Total | number? | Full transaction total of receipt |
Subtotal | number? | Subtotal before taxes |
TotalTax | number? | Total tax amount |
Tip | number? | Tip amount |
TransactionDate | string? | Date the receipt was issued |
TransactionTime | string? | Time the receipt was issued |
CountryRegion | string? | Country or region where receipt was issued |
ReceiptType | string? | Type of receipt |
Line Item Fields
Each item in the Items array contains:
| Field | Type | Description |
|---|
Description | string? | Item description |
TotalPrice | number? | Total price for this line item |
Quantity | number? | Quantity of each item |
Price | number? | Individual price of each item unit |
ProductCode | string? | Product code or SKU |
QuantityUnit | string? | Unit of measure |
Payment Fields
Each payment in the Payments array contains:
| Field | Type | Description |
|---|
Method | string? | Method of payment |
Amount | number? | Amount of payment |
Tax Detail Fields
Each tax detail in the TaxDetails array contains:
| Field | Type | Description |
|---|
Amount | number? | Tax amount |
Rate | number? | Tax rate as a percentage |
NetAmount | number? | Net amount before tax |
Description | string? | Description of the tax |
Type Definitions
import type {
ReceiptItem,
Payment,
ReceiptTaxDetail,
Receipt,
ReceiptResponse,
StrictReceiptResponse
} from '@your-package/models';
Validation Rules
Basic Validation
- All fields are optional by default
- Items, Payments, and TaxDetails default to empty arrays if not specified
Strict Validation
The following fields are required in strict mode:
- MerchantName
- Total
- TransactionDate
- Items (minimum 1 item)
Example Usage
import { validateReceipt } from '@your-package/models';
// Example receipt data
const receiptData = {
MerchantName: "Local Store",
Total: 50.00,
TransactionDate: "2024-01-01",
Items: [
{
Description: "Office Supplies",
Quantity: 2,
Price: 25.00,
TotalPrice: 50.00
}
],
Payments: [
{
Method: "Credit Card",
Amount: 50.00
}
]
};
// Validate the receipt
const validatedReceipt = validateReceipt(receiptData);
// Access validated data through result property
console.log(validatedReceipt.result.Total);
Date Handling
The model accepts dates in multiple formats:
- ISO 8601 datetime strings
- YYYY-MM-DD format
All dates are converted to ISO format during validation.
Best Practices
- Always validate receipts:
const receipt = validateReceipt(receiptData);
- Access data through the result property:
const total = receipt.result.Total;
- Handle optional fields appropriately:
const tip = receipt.result.Tip || 0;
- Check arrays before processing:
const items = receipt.result.Items || [];
const payments = receipt.result.Payments || [];
- Calculate totals carefully:
const totalWithTip = (receipt.result.Total || 0) + (receipt.result.Tip || 0);