Receipt not found

The receipt link may be invalid or expired.

HTML; exit; } $order = queryOne(" SELECT O.OrderTypeID, O.BusinessID, O.Remarks, O.ID, O.BalanceApplied, O.PaymentID, O.TipAmount, B.Name AS BusinessName, B.TaxRate, B.PayfritFee, COALESCE(P.PaymentPaidInCash, 0) AS PaymentPaidInCash, COALESCE(P.PaymentFromCreditCard, 0) AS PaymentFromCreditCard FROM Orders O JOIN Businesses B ON B.ID = O.BusinessID LEFT JOIN Payments P ON P.PaymentID = O.PaymentID WHERE O.UUID = ? ", [$uuid]); if (!$order) { echo << Receipt Not Found

Receipt not found

The receipt link may be invalid or expired.

HTML; exit; } $orderTask = queryOne("SELECT CreatedOn FROM Tasks WHERE OrderID = ? LIMIT 1", [(int) $order['ID']]); $orderType = queryOne("SELECT Name AS OrderTypeName FROM tt_OrderTypes WHERE ID = ?", [(int) $order['OrderTypeID']]); $orderTypeName = $orderType['OrderTypeName'] ?? ''; $deliveryAddress = ''; if ((int) $order['OrderTypeID'] === 3) { $addr = queryOne(" SELECT A.Line1 FROM Addresses A JOIN Orders O ON A.ID = O.AddressID WHERE O.UUID = ? ", [$uuid]); $deliveryAddress = $addr['Line1'] ?? ''; } $parentItems = queryTimed(" SELECT OL.ID, OL.Quantity, OL.Remark, I.ID AS ItemID, I.Name, I.Price, I.CategoryID FROM OrderLineItems OL JOIN Items I ON I.ID = OL.ItemID JOIN Orders O ON O.ID = OL.OrderID WHERE O.UUID = ? AND OL.ParentOrderLineItemID = 0 ORDER BY OL.AddedOn DESC ", [$uuid]); $cartGrandTotal = 0; $payfritsCut = 0; // Helper function esc(string $s): string { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); } function dollars(float $amount): string { return '$' . number_format($amount, 2); } // Build item rows $itemRows = ''; foreach ($parentItems as $parent) { $price = (float) $parent['Price']; $qty = (int) $parent['Quantity']; if ((int) $parent['CategoryID'] !== 31) { $payfritsCut += $price * $qty * (float) $order['PayfritFee']; } $lineTotal = $price * $qty; $cartGrandTotal += $lineTotal; $itemRows .= ''; $itemRows .= '' . esc($parent['Name']) . ''; $itemRows .= '' . $qty . ''; $itemRows .= '' . dollars($price) . ''; $itemRows .= '' . dollars($lineTotal) . ''; $itemRows .= ''; // Child/modifier items $children = queryTimed(" SELECT I.Name, I.Price, I.ParentItemID FROM OrderLineItems OL JOIN Items I ON I.ID = OL.ItemID WHERE OL.ParentOrderLineItemID = ? ORDER BY OL.AddedOn DESC ", [(int) $parent['ID']]); foreach ($children as $child) { $modParent = queryOne("SELECT Name FROM Items WHERE ID = ?", [(int) $child['ParentItemID']]); $modParentName = $modParent['Name'] ?? ''; $modTotal = (float) $child['Price'] * $qty; $cartGrandTotal += $modTotal; $itemRows .= ''; $itemRows .= '' . esc($modParentName) . ': ' . esc($child['Name']) . ' (' . dollars((float) $child['Price']) . ')'; $itemRows .= '' . dollars($modTotal) . ''; $itemRows .= ''; } if (!empty(trim($parent['Remark'] ?? ''))) { $itemRows .= '' . esc($parent['Remark']) . ''; } } // Calculate totals (matches createPaymentIntent logic — no intermediate rounding) $taxAmountRaw = $cartGrandTotal * (float) $order['TaxRate']; $payfritFeeRaw = $payfritsCut; // Delivery fee $deliveryFee = 0; if ((int) $order['OrderTypeID'] === 3) { $delFee = queryOne(" SELECT B.DeliveryFlatFee FROM Businesses B JOIN Orders O ON B.ID = O.BusinessID WHERE O.ID = ? ", [(int) $order['ID']]); $deliveryFee = (float) ($delFee['DeliveryFlatFee'] ?? 0); } $isCashOrder = (float) $order['PaymentPaidInCash'] > 0; $isCardOrder = (float) $order['PaymentFromCreditCard'] > 0; $receiptTip = (float) ($order['TipAmount'] ?? 0); $totalBeforeCardFee = $cartGrandTotal + $taxAmountRaw + $payfritFeeRaw + $deliveryFee + $receiptTip; if ($isCardOrder) { $cardFeePercent = 0.029; $cardFeeFixed = 0.30; $totalCustomerPaysRaw = ($totalBeforeCardFee + $cardFeeFixed) / (1 - $cardFeePercent); $orderGrandTotal = round($totalCustomerPaysRaw * 100) / 100; $taxAmount = round($taxAmountRaw * 100) / 100; $cardFee = $orderGrandTotal - $cartGrandTotal - $taxAmount - round($payfritFeeRaw * 100) / 100 - $deliveryFee - $receiptTip; $cardFee = round($cardFee * 100) / 100; } else { $orderGrandTotal = round($totalBeforeCardFee * 100) / 100; $taxAmount = round($taxAmountRaw * 100) / 100; $cardFee = 0; } $serviceFeeDisplay = round($payfritFeeRaw * 100) / 100; $balanceApplied = (float) ($order['BalanceApplied'] ?? 0); // Build the page $businessName = esc($order['BusinessName']); $orderTypeDisplay = esc($orderTypeName); if ((int) $order['OrderTypeID'] === 3 && $deliveryAddress !== '') { $orderTypeDisplay .= ' to ' . esc($deliveryAddress); } $metaHtml = ''; if ($orderTask && $isAdminView === 0) { $createdOn = new DateTime($orderTask['CreatedOn'], new DateTimeZone('UTC')); $metaHtml .= '
Date' . $createdOn->format('M j, Y') . '
'; $metaHtml .= '
Time' . $createdOn->format('g:i A') . '
'; } $metaHtml .= '
Order#' . (int) $order['ID'] . '
'; $remarksHtml = ''; if (!empty(trim($order['Remarks'] ?? ''))) { $remarksHtml = '
' . esc($order['Remarks']) . '
'; } $totalsHtml = '
Subtotal' . dollars($cartGrandTotal) . '
'; if ($taxAmount > 0) { $totalsHtml .= '
Tax' . dollars($taxAmount) . '
'; } if ($serviceFeeDisplay > 0) { $totalsHtml .= '
Service fee' . dollars($serviceFeeDisplay) . '
'; } if ($deliveryFee > 0) { $totalsHtml .= '
Delivery fee' . dollars($deliveryFee) . '
'; } if ($receiptTip > 0) { $totalsHtml .= '
Tip' . dollars($receiptTip) . '
'; } if ($cardFee > 0) { $totalsHtml .= '
Processing fee' . dollars($cardFee) . '
'; } $totalsHtml .= '
Total' . dollars($orderGrandTotal) . '
'; if ($balanceApplied > 0) { $totalsHtml .= '
Paid with balance' . dollars($balanceApplied) . '
'; $amountCharged = $orderGrandTotal - $balanceApplied; if ($amountCharged > 0) { $chargeLabel = $isCashOrder ? 'Cash due' : 'Charged to card'; $totalsHtml .= '
' . $chargeLabel . '' . dollars($amountCharged) . '
'; } } echo << Receipt - {$businessName}

{$businessName}

{$orderTypeDisplay}
{$metaHtml}
{$remarksHtml}
{$itemRows}
ItemQtyPriceTotal
{$totalsHtml}
HTML;