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:
parent
15e76c7170
commit
acdb28a0d0
1 changed files with 21 additions and 11 deletions
|
|
@ -16,9 +16,10 @@
|
||||||
<cfset cart_grand_total = 0>
|
<cfset cart_grand_total = 0>
|
||||||
|
|
||||||
<cfquery name="get_order_info">
|
<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,
|
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
|
FROM Orders O
|
||||||
JOIN Businesses B ON B.ID = O.BusinessID
|
JOIN Businesses B ON B.ID = O.BusinessID
|
||||||
LEFT JOIN Payments P ON P.PaymentID = O.PaymentID
|
LEFT JOIN Payments P ON P.PaymentID = O.PaymentID
|
||||||
|
|
@ -306,26 +307,28 @@
|
||||||
<cfset PaymentDeliveryFee = calculated_delivery_fee>
|
<cfset PaymentDeliveryFee = calculated_delivery_fee>
|
||||||
</cfif>
|
</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 isCashOrder = val(get_order_info.PaymentPaidInCash) GT 0>
|
||||||
|
<cfset isCardOrder = val(get_order_info.PaymentFromCreditCard) GT 0>
|
||||||
|
|
||||||
<!--- Calculate total BEFORE card fee (no rounding) --->
|
<!--- 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>
|
<cfif isCardOrder>
|
||||||
<!--- 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%) --->
|
<!--- Card: add Stripe fees: (amount + $0.30) / (1 - 2.9%) --->
|
||||||
<cfset cardFeePercent = 0.029>
|
<cfset cardFeePercent = 0.029>
|
||||||
<cfset cardFeeFixed = 0.30>
|
<cfset cardFeeFixed = 0.30>
|
||||||
<cfset totalCustomerPays_raw = (totalBeforeCardFee + cardFeeFixed) / (1 - cardFeePercent)>
|
<cfset totalCustomerPays_raw = (totalBeforeCardFee + cardFeeFixed) / (1 - cardFeePercent)>
|
||||||
<cfset order_grand_total = round(totalCustomerPays_raw * 100) / 100>
|
<cfset order_grand_total = round(totalCustomerPays_raw * 100) / 100>
|
||||||
<cfset tax_amount = round(tax_amount_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>
|
<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>
|
</cfif>
|
||||||
|
|
||||||
<!--- Display fees --->
|
<!--- Display fees --->
|
||||||
|
|
@ -350,6 +353,13 @@
|
||||||
</div>
|
</div>
|
||||||
</cfif>
|
</cfif>
|
||||||
|
|
||||||
|
<cfif receiptTip GT 0>
|
||||||
|
<div class="total-row">
|
||||||
|
<span>Tip</span>
|
||||||
|
<span>#dollarFormat(receiptTip)#</span>
|
||||||
|
</div>
|
||||||
|
</cfif>
|
||||||
|
|
||||||
<cfif cardFee GT 0>
|
<cfif cardFee GT 0>
|
||||||
<div class="total-row">
|
<div class="total-row">
|
||||||
<span>Processing fee</span>
|
<span>Processing fee</span>
|
||||||
|
|
|
||||||
Reference in a new issue