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 06adc1211e Fix receipt showing processing fee for cash orders
Cash orders have no card processing fee. Now checks PaymentPaidInCash
to determine payment type and skips the Stripe fee calculation + display
for cash orders.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 11:24:23 -07:00

382 lines
11 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, O.BalanceApplied, O.PaymentID,
B.Name, B.TaxRate, B.PayfritFee,
COALESCE(P.PaymentPaidInCash, 0) AS PaymentPaidInCash
FROM Orders O
JOIN Businesses B ON B.ID = O.BusinessID
LEFT JOIN Payments P ON P.ID = O.PaymentID
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 * get_order_info.PayfritFee)>
</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>
<!--- Calculate all fees WITHOUT rounding intermediate values (matches createPaymentIntent.cfm) --->
<cfset tax_amount_raw = cart_grand_total * get_order_info.TaxRate>
<cfset payfrit_fee_raw = PaymentPayfritsCut>
<!--- Delivery Fee --->
<cfset PaymentDeliveryFee = 0>
<cfif get_order_info.OrderTypeID EQ 3>
<cfmodule template="../modules/get_delivery_fee.cfm" OrderID="#get_order_info.ID#">
<cfset PaymentDeliveryFee = calculated_delivery_fee>
</cfif>
<!--- Determine if this is a cash order --->
<cfset isCashOrder = val(get_order_info.PaymentPaidInCash) GT 0>
<!--- Calculate total BEFORE card fee (no rounding) --->
<cfset totalBeforeCardFee = cart_grand_total + tax_amount_raw + payfrit_fee_raw + PaymentDeliveryFee>
<cfif isCashOrder>
<!--- Cash: no card processing fee --->
<cfset order_grand_total = round(totalBeforeCardFee * 100) / 100>
<cfset tax_amount = round(tax_amount_raw * 100) / 100>
<cfset cardFee = 0>
<cfelse>
<!--- Card: add Stripe fees: (amount + $0.30) / (1 - 2.9%) --->
<cfset cardFeePercent = 0.029>
<cfset cardFeeFixed = 0.30>
<cfset totalCustomerPays_raw = (totalBeforeCardFee + cardFeeFixed) / (1 - cardFeePercent)>
<cfset order_grand_total = round(totalCustomerPays_raw * 100) / 100>
<cfset tax_amount = round(tax_amount_raw * 100) / 100>
<cfset cardFee = order_grand_total - cart_grand_total - tax_amount - round(payfrit_fee_raw * 100) / 100 - PaymentDeliveryFee>
<cfset cardFee = round(cardFee * 100) / 100>
</cfif>
<!--- Display fees --->
<cfif tax_amount GT 0>
<div class="total-row">
<span>Tax</span>
<span>#dollarFormat(tax_amount)#</span>
</div>
</cfif>
<cfif payfrit_fee_raw GT 0>
<div class="total-row">
<span>Service fee</span>
<span>#dollarFormat(round(payfrit_fee_raw * 100) / 100)#</span>
</div>
</cfif>
<cfif PaymentDeliveryFee GT 0>
<div class="total-row">
<span>Delivery fee</span>
<span>#dollarFormat(PaymentDeliveryFee)#</span>
</div>
</cfif>
<cfif cardFee GT 0>
<div class="total-row">
<span>Processing fee</span>
<span>#dollarFormat(cardFee)#</span>
</div>
</cfif>
<cfset receiptBalanceApplied = val(get_order_info.BalanceApplied)>
<cfif receiptBalanceApplied GT 0>
<div class="total-row">
<span>Balance applied</span>
<span>-#dollarFormat(receiptBalanceApplied)#</span>
</div>
<cfset order_grand_total = order_grand_total - receiptBalanceApplied>
</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>