This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/receipt/index.cfm
John Mizerek 3e1f344fc1 Fix receipt page: show service fee, fix tax calculation
- Always show service fee (was hidden from non-admin)
- Fix tax formula: /100 not /10000

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 17:05:01 -08:00

341 lines
9.4 KiB
Text

<cfparam name="url.UUID" default="">
<cfparam name="url.is_admin_view" default="0">
<cfif NOT len(trim(url.UUID))>
<cfoutput>
<!DOCTYPE html>
<html><head><title>Receipt Not Found</title>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<style>body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;display:flex;justify-content:center;align-items:center;min-height:100vh;margin:0;background:##f5f5f5;color:##333}
.msg{text-align:center;padding:40px}.msg h2{margin-bottom:8px}</style>
</head><body><div class="msg"><h2>Receipt not found</h2><p>The receipt link may be invalid or expired.</p></div></body></html>
</cfoutput>
<cfabort>
</cfif>
<cfset cart_grand_total = 0>
<cfquery name="get_order_info">
SELECT O.OrderTypeID, O.BusinessID, O.Remarks, O.ID,
B.Name, B.TaxRate
FROM Orders O
JOIN Businesses B ON B.ID = O.BusinessID
WHERE O.UUID = <cfqueryparam value="#url.UUID#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfif get_order_info.recordcount EQ 0>
<cfoutput>
<!DOCTYPE html>
<html><head><title>Receipt Not Found</title>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<style>body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;display:flex;justify-content:center;align-items:center;min-height:100vh;margin:0;background:##f5f5f5;color:##333}
.msg{text-align:center;padding:40px}.msg h2{margin-bottom:8px}</style>
</head><body><div class="msg"><h2>Receipt not found</h2><p>The receipt link may be invalid or expired.</p></div></body></html>
</cfoutput>
<cfabort>
</cfif>
<cfquery name="get_order_task">
SELECT T.CreatedOn
FROM Tasks T
WHERE T.OrderID = <cfqueryparam value="#get_order_info.ID#" cfsqltype="cf_sql_integer">
LIMIT 1
</cfquery>
<cfquery name="get_order_type">
SELECT Name AS tt_OrderTypeName
FROM tt_OrderTypes
WHERE ID =<cfqueryparam value="#get_order_info.OrderTypeID#" cfsqltype="cf_sql_integer">
</cfquery>
<cfif get_order_info.OrderTypeID EQ 3>
<cfquery name="get_address">
SELECT A.Line1
FROM Addresses A, Orders O
WHERE O.UUID = <cfqueryparam value="#url.UUID#" cfsqltype="cf_sql_varchar">
AND A.ID = O.AddressID
</cfquery>
</cfif>
<cfquery name="get_parent_items">
SELECT OL.ID, OL.Quantity, OL.Remark,
I.ID, 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 = <cfqueryparam value="#url.UUID#" cfsqltype="cf_sql_varchar">
AND OL.ParentOrderLineItemID = 0
ORDER BY OL.AddedOn DESC
</cfquery>
<cfset PaymentPayfritsCut = 0>
<cfoutput>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Receipt - #htmlEditFormat(get_order_info.Name)#</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: ##f0f0f0;
color: ##333;
padding: 20px;
}
.receipt {
max-width: 480px;
margin: 0 auto;
background: ##fff;
border-radius: 12px;
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
overflow: hidden;
}
.receipt-header {
background: ##1a1a2e;
color: ##fff;
padding: 28px 24px 20px;
text-align: center;
}
.receipt-header h1 {
font-size: 22px;
font-weight: 600;
margin-bottom: 6px;
}
.receipt-header .order-type {
font-size: 14px;
opacity: 0.8;
}
.receipt-meta {
padding: 16px 24px;
border-bottom: 1px dashed ##ddd;
font-size: 14px;
color: ##666;
}
.receipt-meta .meta-row {
display: flex;
justify-content: space-between;
margin-bottom: 4px;
}
.items {
padding: 16px 24px;
}
.items table {
width: 100%;
border-collapse: collapse;
}
.items th {
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: ##999;
border-bottom: 1px solid ##eee;
padding: 0 0 8px;
text-align: left;
}
.items th:last-child,
.items td.amt {
text-align: right;
}
.items td {
padding: 10px 0;
font-size: 14px;
border-bottom: 1px solid ##f5f5f5;
vertical-align: top;
}
.items td.qty {
text-align: center;
color: ##888;
width: 40px;
}
.items .modifier td {
padding: 2px 0 2px 16px;
font-size: 13px;
color: ##777;
border-bottom: none;
}
.items .remark td {
padding: 2px 0 8px 16px;
font-size: 13px;
color: ##c0392b;
border-bottom: none;
font-style: italic;
}
.totals {
padding: 16px 24px 24px;
border-top: 1px dashed ##ddd;
}
.totals .total-row {
display: flex;
justify-content: space-between;
padding: 4px 0;
font-size: 14px;
color: ##666;
}
.totals .grand-total {
font-size: 18px;
font-weight: 700;
color: ##1a1a2e;
border-top: 2px solid ##1a1a2e;
margin-top: 8px;
padding-top: 12px;
}
.receipt-footer {
text-align: center;
padding: 16px 24px 24px;
font-size: 12px;
color: ##aaa;
}
.order-remarks {
padding: 8px 24px;
font-size: 13px;
color: ##c0392b;
font-style: italic;
border-bottom: 1px dashed ##ddd;
}
@media print {
body { background: ##fff; padding: 0; }
.receipt { box-shadow: none; border-radius: 0; }
}
</style>
</head>
<body>
<div class="receipt">
<div class="receipt-header">
<h1>#htmlEditFormat(get_order_info.Name)#</h1>
<div class="order-type">#htmlEditFormat(get_order_type.tt_OrderTypeName)#<cfif get_order_info.OrderTypeID EQ 3 AND isDefined("get_address")> to #htmlEditFormat(get_address.Line1)#</cfif></div>
</div>
<div class="receipt-meta">
<cfif get_order_task.recordcount GT 0 AND url.is_admin_view EQ 0>
<div class="meta-row">
<span>Date</span>
<span>#dateFormat(get_order_task.CreatedOn, "mmm d, yyyy")#</span>
</div>
<div class="meta-row">
<span>Time</span>
<span>#timeFormat(get_order_task.CreatedOn, "h:mm tt")#</span>
</div>
</cfif>
<div class="meta-row">
<span>Order</span>
<span>###get_order_info.ID#</span>
</div>
</div>
<cfif len(trim(get_order_info.Remarks))>
<div class="order-remarks">#htmlEditFormat(get_order_info.Remarks)#</div>
</cfif>
<div class="items">
<table>
<thead>
<tr><th>Item</th><th>Qty</th><th>Price</th><th>Total</th></tr>
</thead>
<tbody>
<cfloop query="get_parent_items">
<cfif get_parent_items.CategoryID NEQ 31>
<cfset PaymentPayfritsCut = PaymentPayfritsCut + (get_parent_items.Price * get_parent_items.Quantity * 0.05)>
</cfif>
<cfset line_total = get_parent_items.Price * get_parent_items.Quantity>
<cfset cart_grand_total = cart_grand_total + line_total>
<tr>
<td>#htmlEditFormat(get_parent_items.Name)#</td>
<td class="qty">#get_parent_items.Quantity#</td>
<td class="amt">#dollarFormat(get_parent_items.Price)#</td>
<td class="amt">#dollarFormat(line_total)#</td>
</tr>
<!--- Child/modifier items --->
<cfquery name="get_child_items">
SELECT I.Name, I.Price, I.ParentItemID
FROM OrderLineItems OL
JOIN Items I ON I.ID = OL.ItemID
WHERE OL.ParentOrderLineItemID = <cfqueryparam value="#get_parent_items.ID#" cfsqltype="cf_sql_integer">
ORDER BY OL.AddedOn DESC
</cfquery>
<cfif get_child_items.recordcount GT 0>
<cfloop query="get_child_items">
<cfquery name="get_mod_parent_name">
SELECT Name FROM Items
WHERE ID = <cfqueryparam value="#get_child_items.ParentItemID#" cfsqltype="cf_sql_integer">
</cfquery>
<cfset mod_total = get_child_items.Price * get_parent_items.Quantity>
<cfset cart_grand_total = cart_grand_total + mod_total>
<tr class="modifier">
<td colspan="3">#htmlEditFormat(get_mod_parent_name.Name)#: #htmlEditFormat(get_child_items.Name)# (#dollarFormat(get_child_items.Price)#)</td>
<td class="amt">#dollarFormat(mod_total)#</td>
</tr>
</cfloop>
</cfif>
<cfif len(trim(get_parent_items.Remark))>
<tr class="remark">
<td colspan="4">#htmlEditFormat(get_parent_items.Remark)#</td>
</tr>
</cfif>
</cfloop>
</tbody>
</table>
</div>
<div class="totals">
<div class="total-row">
<span>Subtotal</span>
<span>#dollarFormat(cart_grand_total)#</span>
</div>
<cfif get_order_info.TaxRate GT 0>
<cfset tax_amount = round(cart_grand_total * get_order_info.TaxRate * 100) / 100>
<cfelse>
<cfset tax_amount = 0>
</cfif>
<cfset order_grand_total = cart_grand_total + tax_amount>
<cfif tax_amount GT 0>
<div class="total-row">
<span>Tax</span>
<span>#dollarFormat(tax_amount)#</span>
</div>
</cfif>
<cfif PaymentPayfritsCut GT 0>
<div class="total-row">
<span>Service fee</span>
<span>#dollarFormat(PaymentPayfritsCut)#</span>
</div>
</cfif>
<cfset order_grand_total = order_grand_total + PaymentPayfritsCut>
<cfif get_order_info.OrderTypeID EQ 3>
<cfmodule template="../modules/get_delivery_fee.cfm" OrderID="#get_order_info.ID#">
<cfset PaymentDeliveryFee = calculated_delivery_fee>
<div class="total-row">
<span>Delivery fee</span>
<span>#dollarFormat(PaymentDeliveryFee)#</span>
</div>
<cfset order_grand_total = order_grand_total + PaymentDeliveryFee>
</cfif>
<div class="total-row grand-total">
<span>Total</span>
<span>#dollarFormat(order_grand_total)#</span>
</div>
</div>
<div class="receipt-footer">
Powered by Payfrit
</div>
</div>
</body>
</html>
</cfoutput>