fixes to amounts
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -56,10 +56,10 @@
|
||||
<hr class="my-3">
|
||||
<div class="flex justify-between font-bold text-lg">
|
||||
<span>Total:</span>
|
||||
<span>${{ promo_active ? total_amount_after_discount : total_amount }}</span>
|
||||
<span>${{ calculateTotalAmount() }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- close space-y-2 -->
|
||||
</div> <!-- close bg-base-100 -->
|
||||
|
||||
<!-- Credit Card Display -->
|
||||
<div class="bg-base-100 rounded-lg p-6">
|
||||
@@ -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')
|
||||
},
|
||||
|
||||
@@ -68,33 +68,39 @@
|
||||
<!-- Financial Summary Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Financial Summary</h3>
|
||||
<div class="space-y-3">
|
||||
<!-- Pricing & Gallons -->
|
||||
<div class="grid grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<div class="font-bold">Price / Gallon</div>
|
||||
<div class="opacity-80">${{ Number(deliveryOrder.customer_price).toFixed(2) }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-bold">Gallons Delivered</div>
|
||||
<div class="opacity-80">{{ gallonsDelivered || '0.00' }}</div>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<div class="flex justify-between">
|
||||
<span>Gallons Delivered:</span>
|
||||
<span>{{ gallonsDelivered || 0 }} gallons</span>
|
||||
</div>
|
||||
<!-- Fees -->
|
||||
<div class="text-sm space-y-1 border-t border-base-100 pt-3">
|
||||
<div v-if="deliveryOrder.prime == 1" class="flex justify-between">
|
||||
<span>Prime Fee</span>
|
||||
<span>${{ Number(pricing.price_prime).toFixed(2) }}</span>
|
||||
</div>
|
||||
<div v-if="deliveryOrder.same_day === 1" class="flex justify-between">
|
||||
<span>Same Day Fee</span>
|
||||
<span>${{ Number(pricing.price_same_day).toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Price per Gallon:</span>
|
||||
<span>${{ deliveryOrder.customer_price || 0 }}</span>
|
||||
</div>
|
||||
<!-- Total -->
|
||||
<div class="flex justify-between items-center border-t border-base-100 pt-3">
|
||||
<span class="text-lg font-bold">Total Amount</span>
|
||||
<span class="text-2xl font-bold text-success">${{ Number(captureAmount).toFixed(2) }}</span>
|
||||
<div class="flex justify-between font-semibold">
|
||||
<span>Subtotal:</span>
|
||||
<span>${{ calculateSubtotal() }}</span>
|
||||
</div>
|
||||
<div v-if="deliveryOrder.prime == 1" class="flex justify-between text-sm">
|
||||
<span>Prime Fee:</span>
|
||||
<span>+ ${{ pricing.price_prime || 0 }}</span>
|
||||
</div>
|
||||
<div v-if="deliveryOrder.same_day == 1" class="flex justify-between text-sm">
|
||||
<span>Same Day Fee:</span>
|
||||
<span>+ ${{ pricing.price_same_day || 0 }}</span>
|
||||
</div>
|
||||
<div v-if="deliveryOrder.emergency == 1" class="flex justify-between text-sm">
|
||||
<span>Emergency Fee:</span>
|
||||
<span>+ ${{ pricing.price_emergency || 0 }}</span>
|
||||
</div>
|
||||
<div v-if="promo_active" class="flex justify-between text-success">
|
||||
<span>{{ promo.name_of_promotion }}:</span>
|
||||
<span>- ${{ discount }}</span>
|
||||
</div>
|
||||
<hr class="my-3">
|
||||
<div class="flex justify-between font-bold text-lg">
|
||||
<span>Total:</span>
|
||||
<span>${{ calculateTotalAmount() }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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) {
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-lg font-bold">Total to be Charged</span>
|
||||
<span class="text-2xl font-bold text-accent">
|
||||
${{ promo_active ? total_amount_after_discount : total_amount }}
|
||||
${{ calculateTotalAmount() }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user