+
+ 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({