# Invoice ${OrderID}

Date: ${OrderDate}
Customer: ${CustomerID} (${CompanyName!'N/A'})

## Details

Product | Quantity | Unit Price | Discount | Line Total
--- | --- | --- | --- | ---
<#assign subtotal = 0> <#if details??> <#list details as item> <#-- Handle potential nulls in item map --> <#assign qty = (item.Quantity!0)> <#assign price = (item.UnitPrice!0)> <#assign discount = (item.Discount!0)> <#assign lineTotal = (qty * price * (1 - discount)) > <#assign subtotal = subtotal + lineTotal>
${item.ProductName!'N/A'} | ${qty} | ${price?string("0.00")} | ${discount?string("0%")} | ${lineTotal?string("0.00")}
Subtotal: | ${subtotal?string("0.00")}
Freight: | ${(Freight!0)?string("0.00")}
<#-- Assuming Tax is calculated or provided --> <#assign freightVal = (Freight!0)> <#assign tax = (subtotal + freightVal) * 0.08 > <#-- Example Tax Calc -->
Tax (8%): | ${tax?string("0.00")}
Grand Total: | ${(subtotal + freightVal + tax)?string("0.00")}