fixes to amounts

This commit is contained in:
2025-09-18 14:12:41 -04:00
parent dc71eee4db
commit f7bc23d9ed
4 changed files with 247 additions and 42 deletions

View File

@@ -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')
},