fixes to amounts
This commit is contained in:
@@ -343,9 +343,12 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
finalChargeAmount(): number {
|
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) {
|
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
|
// Otherwise, calculate locally
|
||||||
|
|||||||
@@ -56,10 +56,10 @@
|
|||||||
<hr class="my-3">
|
<hr class="my-3">
|
||||||
<div class="flex justify-between font-bold text-lg">
|
<div class="flex justify-between font-bold text-lg">
|
||||||
<span>Total:</span>
|
<span>Total:</span>
|
||||||
<span>${{ promo_active ? total_amount_after_discount : total_amount }}</span>
|
<span>${{ calculateTotalAmount() }}</span>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div> <!-- close space-y-2 -->
|
||||||
|
</div> <!-- close bg-base-100 -->
|
||||||
|
|
||||||
<!-- Credit Card Display -->
|
<!-- Credit Card Display -->
|
||||||
<div class="bg-base-100 rounded-lg p-6">
|
<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) {
|
sumdelivery(delivery_id: any) {
|
||||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id;
|
let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id;
|
||||||
axios({
|
axios({
|
||||||
@@ -319,13 +331,18 @@ export default defineComponent({
|
|||||||
this.discount = parseFloat(response.data.discount) || 0;
|
this.discount = parseFloat(response.data.discount) || 0;
|
||||||
this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0;
|
this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0;
|
||||||
|
|
||||||
// Auto-populate charge amount with the calculated total
|
// 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) {
|
if (this.promo_active) {
|
||||||
this.chargeAmount = this.total_amount_after_discount;
|
this.chargeAmount = this.total_amount_after_discount;
|
||||||
} else {
|
} else {
|
||||||
this.chargeAmount = this.total_amount;
|
this.chargeAmount = this.total_amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
notify({
|
notify({
|
||||||
@@ -349,10 +366,8 @@ export default defineComponent({
|
|||||||
this.promo = response.data
|
this.promo = response.data
|
||||||
this.promo_active = true
|
this.promo_active = true
|
||||||
|
|
||||||
// Update charge amount when promo is applied
|
// Trigger a charge amount update if all data is available
|
||||||
if (this.total_amount_after_discount > 0) {
|
this.updateChargeAmount();
|
||||||
this.chargeAmount = this.total_amount_after_discount
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -381,6 +396,8 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
this.pricing = response.data;
|
this.pricing = response.data;
|
||||||
|
// Try to update charge amount when pricing is loaded
|
||||||
|
this.updateChargeAmount();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
notify({
|
notify({
|
||||||
@@ -449,6 +466,52 @@ export default defineComponent({
|
|||||||
return (gallons * pricePerGallon).toFixed(2)
|
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() {
|
async handlePreauthorize() {
|
||||||
await this.processPayment('preauthorize')
|
await this.processPayment('preauthorize')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -68,33 +68,39 @@
|
|||||||
<!-- Financial Summary Card -->
|
<!-- Financial Summary Card -->
|
||||||
<div class="bg-neutral rounded-lg p-5">
|
<div class="bg-neutral rounded-lg p-5">
|
||||||
<h3 class="text-xl font-bold mb-4">Financial Summary</h3>
|
<h3 class="text-xl font-bold mb-4">Financial Summary</h3>
|
||||||
<div class="space-y-3">
|
<div class="space-y-2">
|
||||||
<!-- Pricing & Gallons -->
|
<div class="flex justify-between">
|
||||||
<div class="grid grid-cols-2 gap-3 text-sm">
|
<span>Gallons Delivered:</span>
|
||||||
<div>
|
<span>{{ gallonsDelivered || 0 }} gallons</span>
|
||||||
<div class="font-bold">Price / Gallon</div>
|
|
||||||
<div class="opacity-80">${{ Number(deliveryOrder.customer_price).toFixed(2) }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Gallons Delivered</div>
|
<span>Price per Gallon:</span>
|
||||||
<div class="opacity-80">{{ gallonsDelivered || '0.00' }}</div>
|
<span>${{ deliveryOrder.customer_price || 0 }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex justify-between font-semibold">
|
||||||
|
<span>Subtotal:</span>
|
||||||
|
<span>${{ calculateSubtotal() }}</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- Fees -->
|
<div v-if="deliveryOrder.prime == 1" class="flex justify-between text-sm">
|
||||||
<div class="text-sm space-y-1 border-t border-base-100 pt-3">
|
<span>Prime Fee:</span>
|
||||||
<div v-if="deliveryOrder.prime == 1" class="flex justify-between">
|
<span>+ ${{ pricing.price_prime || 0 }}</span>
|
||||||
<span>Prime Fee</span>
|
|
||||||
<span>${{ Number(pricing.price_prime).toFixed(2) }}</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-if="deliveryOrder.same_day === 1" class="flex justify-between">
|
<div v-if="deliveryOrder.same_day == 1" class="flex justify-between text-sm">
|
||||||
<span>Same Day Fee</span>
|
<span>Same Day Fee:</span>
|
||||||
<span>${{ Number(pricing.price_same_day).toFixed(2) }}</span>
|
<span>+ ${{ pricing.price_same_day || 0 }}</span>
|
||||||
</div>
|
</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>
|
||||||
<!-- Total -->
|
<div v-if="promo_active" class="flex justify-between text-success">
|
||||||
<div class="flex justify-between items-center border-t border-base-100 pt-3">
|
<span>{{ promo.name_of_promotion }}:</span>
|
||||||
<span class="text-lg font-bold">Total Amount</span>
|
<span>- ${{ discount }}</span>
|
||||||
<span class="text-2xl font-bold text-success">${{ Number(captureAmount).toFixed(2) }}</span>
|
</div>
|
||||||
|
<hr class="my-3">
|
||||||
|
<div class="flex justify-between font-bold text-lg">
|
||||||
|
<span>Total:</span>
|
||||||
|
<span>${{ calculateTotalAmount() }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -293,6 +299,8 @@ export default defineComponent({
|
|||||||
dispatcher_notes: '',
|
dispatcher_notes: '',
|
||||||
prime: 0,
|
prime: 0,
|
||||||
same_day: 0,
|
same_day: 0,
|
||||||
|
emergency: 0,
|
||||||
|
promo_id: 0,
|
||||||
payment_type: 0,
|
payment_type: 0,
|
||||||
payment_card_id: '',
|
payment_card_id: '',
|
||||||
driver_employee_id: 0,
|
driver_employee_id: 0,
|
||||||
@@ -306,8 +314,19 @@ export default defineComponent({
|
|||||||
price_for_employee: 0,
|
price_for_employee: 0,
|
||||||
price_same_day: 0,
|
price_same_day: 0,
|
||||||
price_prime: 0,
|
price_prime: 0,
|
||||||
|
price_emergency: 0,
|
||||||
date: "",
|
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: {
|
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) {
|
getOilOrder(delivery_id: any) {
|
||||||
const path = `${import.meta.env.VITE_BASE_URL}/delivery/order/${delivery_id}`;
|
const path = `${import.meta.env.VITE_BASE_URL}/delivery/order/${delivery_id}`;
|
||||||
axios.get(path, { withCredentials: true, headers: authHeader() })
|
axios.get(path, { withCredentials: true, headers: authHeader() })
|
||||||
@@ -326,13 +387,16 @@ export default defineComponent({
|
|||||||
this.deliveryOrder = response.data.delivery;
|
this.deliveryOrder = response.data.delivery;
|
||||||
this.gallonsDelivered = this.deliveryOrder.gallons_delivered;
|
this.gallonsDelivered = this.deliveryOrder.gallons_delivered;
|
||||||
this.getCustomer(this.deliveryOrder.customer_id);
|
this.getCustomer(this.deliveryOrder.customer_id);
|
||||||
|
this.sumdelivery(delivery_id);
|
||||||
|
|
||||||
if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) {
|
if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) {
|
||||||
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate capture amount if pricing is already loaded
|
if (this.deliveryOrder.promo_id != null) {
|
||||||
this.calculateCaptureAmount();
|
this.getPromo(this.deliveryOrder.promo_id);
|
||||||
|
this.promo_active = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
|
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() {
|
calculateCaptureAmount() {
|
||||||
// Only calculate if we have both delivery order and pricing data
|
// Only calculate if we have both delivery order and pricing data
|
||||||
if (this.deliveryOrder.id && this.pricing.price_for_customer) {
|
if (this.deliveryOrder.id && this.pricing.price_for_customer) {
|
||||||
|
|||||||
@@ -142,7 +142,7 @@
|
|||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="text-lg font-bold">Total to be Charged</span>
|
<span class="text-lg font-bold">Total to be Charged</span>
|
||||||
<span class="text-2xl font-bold text-accent">
|
<span class="text-2xl font-bold text-accent">
|
||||||
${{ promo_active ? total_amount_after_discount : total_amount }}
|
${{ calculateTotalAmount() }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -461,6 +461,29 @@ export default defineComponent({
|
|||||||
this.customer = response.data
|
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) {
|
checkoutOilUpdatePayment(payment_type: number) {
|
||||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/cash/" + this.delivery.id + '/' + payment_type;
|
let path = import.meta.env.VITE_BASE_URL + "/delivery/cash/" + this.delivery.id + '/' + payment_type;
|
||||||
axios({
|
axios({
|
||||||
|
|||||||
Reference in New Issue
Block a user