diff --git a/src/pages/delivery/update_tickets/finalize_ticket.vue b/src/pages/delivery/update_tickets/finalize_ticket.vue index 55d115d..113b1b4 100755 --- a/src/pages/delivery/update_tickets/finalize_ticket.vue +++ b/src/pages/delivery/update_tickets/finalize_ticket.vue @@ -343,9 +343,12 @@ export default defineComponent({ }, computed: { finalChargeAmount(): number { - // If promo is active, use server-calculated totals (which include discounts) + // If promo is active, use server-calculated totals with fees added if (this.promo_active && this.total_amount_after_discount > 0) { - return this.total_amount_after_discount; + let total = this.total_amount_after_discount; + if (this.deliveryOrder.prime === 1) total += Number(this.pricing.price_prime); + if (this.deliveryOrder.same_day === 1) total += Number(this.pricing.price_same_day); + return total; } // Otherwise, calculate locally diff --git a/src/pages/pay/oil/authorize_preauthcharge.vue b/src/pages/pay/oil/authorize_preauthcharge.vue index bb8901d..df77863 100644 --- a/src/pages/pay/oil/authorize_preauthcharge.vue +++ b/src/pages/pay/oil/authorize_preauthcharge.vue @@ -56,10 +56,10 @@
Total: - ${{ promo_active ? total_amount_after_discount : total_amount }} + ${{ calculateTotalAmount() }}
- - + +
@@ -306,6 +306,18 @@ export default defineComponent({ }) }, + updateChargeAmount() { + // Only update if we have all necessary data + if (this.total_amount_after_discount > 0 && + this.pricing.price_prime !== undefined && + this.pricing.price_same_day !== undefined && + this.pricing.price_emergency !== undefined) { + this.chargeAmount = this.calculateTotalAsNumber(); + return true; + } + return false; + }, + sumdelivery(delivery_id: any) { let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id; axios({ @@ -319,11 +331,16 @@ export default defineComponent({ this.discount = parseFloat(response.data.discount) || 0; this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0; - // Auto-populate charge amount with the calculated total - if (this.promo_active) { - this.chargeAmount = this.total_amount_after_discount; - } else { - this.chargeAmount = this.total_amount; + // Try to update charge amount with complete pricing + const updated = this.updateChargeAmount(); + + // Fallback only if pricing not loaded yet and calculation didn't run + if (!updated) { + if (this.promo_active) { + this.chargeAmount = this.total_amount_after_discount; + } else { + this.chargeAmount = this.total_amount; + } } } }) @@ -349,10 +366,8 @@ export default defineComponent({ this.promo = response.data this.promo_active = true - // Update charge amount when promo is applied - if (this.total_amount_after_discount > 0) { - this.chargeAmount = this.total_amount_after_discount - } + // Trigger a charge amount update if all data is available + this.updateChargeAmount(); } }) }, @@ -381,6 +396,8 @@ export default defineComponent({ }) .then((response: any) => { this.pricing = response.data; + // Try to update charge amount when pricing is loaded + this.updateChargeAmount(); }) .catch(() => { notify({ @@ -449,6 +466,52 @@ export default defineComponent({ return (gallons * pricePerGallon).toFixed(2) }, + calculateTotalAmount() { + if (this.total_amount_after_discount == null || this.total_amount_after_discount === undefined) { + return '0.00'; + } + + let totalNum = Number(this.total_amount_after_discount); + if (isNaN(totalNum)) { + return '0.00'; + } + + if (this.delivery && this.delivery.prime == 1 && this.pricing && this.pricing.price_prime) { + totalNum += Number(this.pricing.price_prime) || 0; + } + if (this.delivery && this.delivery.same_day == 1 && this.pricing && this.pricing.price_same_day) { + totalNum += Number(this.pricing.price_same_day) || 0; + } + if (this.delivery && this.delivery.emergency == 1 && this.pricing && this.pricing.price_emergency) { + totalNum += Number(this.pricing.price_emergency) || 0; + } + + return totalNum.toFixed(2); + }, + + calculateTotalAsNumber() { + if (this.total_amount_after_discount == null || this.total_amount_after_discount === undefined) { + return 0; + } + + let totalNum = Number(this.total_amount_after_discount); + if (isNaN(totalNum)) { + return 0; + } + + if (this.delivery && this.delivery.prime == 1 && this.pricing && this.pricing.price_prime) { + totalNum += Number(this.pricing.price_prime) || 0; + } + if (this.delivery && this.delivery.same_day == 1 && this.pricing && this.pricing.price_same_day) { + totalNum += Number(this.pricing.price_same_day) || 0; + } + if (this.delivery && this.delivery.emergency == 1 && this.pricing && this.pricing.price_emergency) { + totalNum += Number(this.pricing.price_emergency) || 0; + } + + return totalNum; + }, + async handlePreauthorize() { await this.processPayment('preauthorize') }, diff --git a/src/pages/pay/oil/capture_authorize.vue b/src/pages/pay/oil/capture_authorize.vue index 6352e55..8d82ee4 100644 --- a/src/pages/pay/oil/capture_authorize.vue +++ b/src/pages/pay/oil/capture_authorize.vue @@ -68,33 +68,39 @@

Financial Summary

-
- -
-
-
Price / Gallon
-
${{ Number(deliveryOrder.customer_price).toFixed(2) }}
-
-
-
Gallons Delivered
-
{{ gallonsDelivered || '0.00' }}
-
+
+
+ Gallons Delivered: + {{ gallonsDelivered || 0 }} gallons
- -
-
- Prime Fee - ${{ Number(pricing.price_prime).toFixed(2) }} -
-
- Same Day Fee - ${{ Number(pricing.price_same_day).toFixed(2) }} -
+
+ Price per Gallon: + ${{ deliveryOrder.customer_price || 0 }}
- -
- Total Amount - ${{ Number(captureAmount).toFixed(2) }} +
+ Subtotal: + ${{ calculateSubtotal() }} +
+
+ Prime Fee: + + ${{ pricing.price_prime || 0 }} +
+
+ Same Day Fee: + + ${{ pricing.price_same_day || 0 }} +
+
+ Emergency Fee: + + ${{ pricing.price_emergency || 0 }} +
+
+ {{ promo.name_of_promotion }}: + - ${{ discount }} +
+
+
+ Total: + ${{ calculateTotalAmount() }}
@@ -293,6 +299,8 @@ export default defineComponent({ dispatcher_notes: '', prime: 0, same_day: 0, + emergency: 0, + promo_id: 0, payment_type: 0, payment_card_id: '', driver_employee_id: 0, @@ -306,8 +314,19 @@ export default defineComponent({ price_for_employee: 0, price_same_day: 0, price_prime: 0, + price_emergency: 0, date: "", }, + promo_active: false, + promo: { + name_of_promotion: '', + description: '', + money_off_delivery: 0, + text_on_ticket: '' + }, + total_amount: 0, + discount: 0, + total_amount_after_discount: 0, } }, @@ -318,6 +337,48 @@ export default defineComponent({ }, methods: { + sumdelivery(delivery_id: any) { + let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id; + axios({ + method: "get", + url: path, + withCredentials: true, + }) + .then((response: any) => { + if (response.data.ok) { + this.total_amount = parseFloat(response.data.total_amount) || 0; + this.discount = parseFloat(response.data.discount) || 0; + this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0; + + // Set capture amount to the calculated total including fees and discount + this.captureAmount = this.calculateTotalAsNumber(); + } + }) + .catch(() => { + notify({ + title: "Error", + text: "Could not get totals", + type: "error", + }); + }); + }, + + getPromo(promo_id: any) { + let path = import.meta.env.VITE_BASE_URL + "/promo/" + promo_id; + axios({ + method: "get", + url: path, + withCredentials: true, + headers: authHeader(), + }) + .then((response: any) => { + if (response.data) { + this.promo = response.data + this.promo_active = true + } + }) + }, + getOilOrder(delivery_id: any) { const path = `${import.meta.env.VITE_BASE_URL}/delivery/order/${delivery_id}`; axios.get(path, { withCredentials: true, headers: authHeader() }) @@ -326,13 +387,16 @@ export default defineComponent({ this.deliveryOrder = response.data.delivery; this.gallonsDelivered = this.deliveryOrder.gallons_delivered; this.getCustomer(this.deliveryOrder.customer_id); + this.sumdelivery(delivery_id); if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) { this.getPaymentCard(this.deliveryOrder.payment_card_id); } - // Calculate capture amount if pricing is already loaded - this.calculateCaptureAmount(); + if (this.deliveryOrder.promo_id != null) { + this.getPromo(this.deliveryOrder.promo_id); + this.promo_active = true; + } } else { console.error("API Error:", response.data.error || "Failed to fetch delivery data."); } @@ -464,6 +528,58 @@ export default defineComponent({ } }, + calculateSubtotal() { + const gallons = parseFloat(this.gallonsDelivered || '0') || 0; + const pricePerGallon = typeof this.deliveryOrder.customer_price === 'string' ? parseFloat(this.deliveryOrder.customer_price) : Number(this.deliveryOrder.customer_price) || 0; + return (gallons * pricePerGallon).toFixed(2); + }, + + calculateTotalAmount() { + if (this.total_amount_after_discount == null || this.total_amount_after_discount === undefined) { + return '0.00'; + } + + let totalNum = Number(this.total_amount_after_discount); + if (isNaN(totalNum)) { + return '0.00'; + } + + if (this.deliveryOrder && this.deliveryOrder.prime == 1 && this.pricing && this.pricing.price_prime) { + totalNum += Number(this.pricing.price_prime) || 0; + } + if (this.deliveryOrder && this.deliveryOrder.same_day == 1 && this.pricing && this.pricing.price_same_day) { + totalNum += Number(this.pricing.price_same_day) || 0; + } + if (this.deliveryOrder && this.deliveryOrder.emergency == 1 && this.pricing && this.pricing.price_emergency) { + totalNum += Number(this.pricing.price_emergency) || 0; + } + + return totalNum.toFixed(2); + }, + + calculateTotalAsNumber() { + if (this.total_amount_after_discount == null || this.total_amount_after_discount === undefined) { + return 0; + } + + let totalNum = Number(this.total_amount_after_discount); + if (isNaN(totalNum)) { + return 0; + } + + if (this.deliveryOrder && this.deliveryOrder.prime == 1 && this.pricing && this.pricing.price_prime) { + totalNum += Number(this.pricing.price_prime) || 0; + } + if (this.deliveryOrder && this.deliveryOrder.same_day == 1 && this.pricing && this.pricing.price_same_day) { + totalNum += Number(this.pricing.price_same_day) || 0; + } + if (this.deliveryOrder && this.deliveryOrder.emergency == 1 && this.pricing && this.pricing.price_emergency) { + totalNum += Number(this.pricing.price_emergency) || 0; + } + + return totalNum; + }, + calculateCaptureAmount() { // Only calculate if we have both delivery order and pricing data if (this.deliveryOrder.id && this.pricing.price_for_customer) { diff --git a/src/pages/pay/oil/pay_oil.vue b/src/pages/pay/oil/pay_oil.vue index 93110d8..2b2868d 100755 --- a/src/pages/pay/oil/pay_oil.vue +++ b/src/pages/pay/oil/pay_oil.vue @@ -142,7 +142,7 @@
Total to be Charged - ${{ promo_active ? total_amount_after_discount : total_amount }} + ${{ calculateTotalAmount() }}
@@ -461,6 +461,29 @@ export default defineComponent({ this.customer = response.data }) }, + calculateTotalAmount() { + if (this.total_amount_after_discount == null || this.total_amount_after_discount === undefined) { + return '0.00'; + } + + let totalNum = Number(this.total_amount_after_discount); + if (isNaN(totalNum)) { + return '0.00'; + } + + if (this.delivery && this.delivery.prime == 1 && this.pricing && this.pricing.price_prime) { + totalNum += Number(this.pricing.price_prime) || 0; + } + if (this.delivery && this.delivery.same_day == 1 && this.pricing && this.pricing.price_same_day) { + totalNum += Number(this.pricing.price_same_day) || 0; + } + if (this.delivery && this.delivery.emergency == 1 && this.pricing && this.pricing.price_emergency) { + totalNum += Number(this.pricing.price_emergency) || 0; + } + + return totalNum.toFixed(2); + }, + checkoutOilUpdatePayment(payment_type: number) { let path = import.meta.env.VITE_BASE_URL + "/delivery/cash/" + this.delivery.id + '/' + payment_type; axios({