fix: hide subtotal line when it equals the total (no delivery/tax)

Subtotal was always shown alongside Total even for pickup orders with
no additional charges, making both lines identical. Now the breakdown
(Subtotal / Delivery / Tax) only appears when there are fees beyond
the item total. Applies to both customer and store alert emails.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chris 2026-05-09 13:16:33 -04:00
parent 8e283a4dff
commit bbf08e4267

View File

@ -183,17 +183,20 @@ export async function sendOrderConfirmationEmail(params: {
: fmtDate(params.slotISO)
const total = `$${(Number(params.totalCents) / 100).toFixed(2)}`
// Charges breakdown (only shown when subtotal is provided)
// Charges breakdown (only shown when there are additional fees beyond items)
const chargesLines: string[] = []
if (params.subtotalCents != null) {
const impliedTax = Number(params.totalCents) - params.subtotalCents - (params.deliveryCents ?? 0)
const hasBreakdown = !!(params.deliveryCents) || impliedTax > 0
if (hasBreakdown) {
chargesLines.push(`Subtotal: $${(params.subtotalCents / 100).toFixed(2)}`)
if (params.deliveryCents) {
chargesLines.push(`Delivery: $${(params.deliveryCents / 100).toFixed(2)}`)
}
const impliedTax = Number(params.totalCents) - (params.subtotalCents) - (params.deliveryCents ?? 0)
if (impliedTax > 0) {
chargesLines.push(`Tax: $${(impliedTax / 100).toFixed(2)}`)
}
}
chargesLines.push(`Total: ${total}`)
} else {
chargesLines.push(`Total: ${total}`)
@ -323,14 +326,17 @@ export async function sendNewOrderAlert(params: {
const chargesLines: string[] = []
if (params.subtotalCents != null) {
const impliedTax = Number(params.totalCents) - params.subtotalCents - (params.deliveryCents ?? 0)
const hasBreakdown = !!(params.deliveryCents) || impliedTax > 0
if (hasBreakdown) {
chargesLines.push(`Subtotal: $${(params.subtotalCents / 100).toFixed(2)}`)
if (params.deliveryCents) {
chargesLines.push(`Delivery: $${(params.deliveryCents / 100).toFixed(2)}`)
}
const impliedTax = Number(params.totalCents) - params.subtotalCents - (params.deliveryCents ?? 0)
if (impliedTax > 0) {
chargesLines.push(`Tax: $${(impliedTax / 100).toFixed(2)}`)
}
}
chargesLines.push(`Total: ${total}`)
} else {
chargesLines.push(`Total: ${total}`)