Fix receipt for balance-only payments and add tip display

Receipt was treating balance-only orders as card payments, adding
Stripe processing fees that inflated the total. Now checks
PaymentFromCreditCard to determine if card fees apply. Also adds
tip line and includes TipAmount in total calculation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-03-11 12:05:42 -07:00
parent 15e76c7170
commit acdb28a0d0

View file

@ -16,9 +16,10 @@
<cfset cart_grand_total = 0>
<cfquery name="get_order_info">
SELECT O.OrderTypeID, O.BusinessID, O.Remarks, O.ID, O.BalanceApplied, O.PaymentID,
SELECT O.OrderTypeID, O.BusinessID, O.Remarks, O.ID, O.BalanceApplied, O.PaymentID, O.TipAmount,
B.Name, B.TaxRate, B.PayfritFee,
COALESCE(P.PaymentPaidInCash, 0) AS PaymentPaidInCash
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
@ -306,26 +307,28 @@
<cfset PaymentDeliveryFee = calculated_delivery_fee>
</cfif>
<!--- Determine if this is a cash order --->
<!--- Determine payment method: cash, balance-only, or card --->
<cfset isCashOrder = val(get_order_info.PaymentPaidInCash) GT 0>
<cfset isCardOrder = val(get_order_info.PaymentFromCreditCard) GT 0>
<!--- Calculate total BEFORE card fee (no rounding) --->
<cfset totalBeforeCardFee = cart_grand_total + tax_amount_raw + payfrit_fee_raw + PaymentDeliveryFee>
<cfset receiptTip = val(get_order_info.TipAmount)>
<cfset totalBeforeCardFee = cart_grand_total + tax_amount_raw + payfrit_fee_raw + PaymentDeliveryFee + receiptTip>
<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>
<cfif isCardOrder>
<!--- 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 = order_grand_total - cart_grand_total - tax_amount - round(payfrit_fee_raw * 100) / 100 - PaymentDeliveryFee - receiptTip>
<cfset cardFee = round(cardFee * 100) / 100>
<cfelse>
<!--- Cash or balance-only: no card processing fee --->
<cfset order_grand_total = round(totalBeforeCardFee * 100) / 100>
<cfset tax_amount = round(tax_amount_raw * 100) / 100>
<cfset cardFee = 0>
</cfif>
<!--- Display fees --->
@ -350,6 +353,13 @@
</div>
</cfif>
<cfif receiptTip GT 0>
<div class="total-row">
<span>Tip</span>
<span>#dollarFormat(receiptTip)#</span>
</div>
</cfif>
<cfif cardFee GT 0>
<div class="total-row">
<span>Processing fee</span>