small fixes routing

This commit is contained in:
2025-09-06 13:40:58 -04:00
parent 8649c3815c
commit e74f5510f0
4 changed files with 134 additions and 35 deletions

View File

@@ -84,6 +84,6 @@ interface Props {
// 3. Use the generic version of defineProps to apply the types
defineProps<Props>();
const deliveryStatus = (s: number) => ({0:'Waiting',1:'Cancelled',2:'Out',3:'Tomorrow',5:'Issue',10:'Finalized'}[s] || 'N/A');
const statusClass = (s: number) => ({0:'badge-warning',1:'badge-error',2:'badge-info',3:'badge-ghost',5:'badge-error',10:'badge-success'}[s] || '');
const deliveryStatus = (s: number) => ({0:'Waiting',1:'Cancelled',2:'Out',3:'Tomorrow',5:'Issue',9:'Pending_Payment', 10:'Finalized'}[s] || 'N/A');
const statusClass = (s: number) => ({0:'badge-warning',1:'badge-error',2:'badge-info',3:'badge-ghost',5:'badge-error', 9:'badge-warning', 10:'badge-success'}[s] || '');
</script>

View File

@@ -110,7 +110,7 @@
<select class="select select-bordered select-sm w-full max-w-xs" v-model="formDelivery.credit_card_id">
<option disabled :value="0">Select a card</option>
<option v-for="card in userCards" :key="card.id" :value="card.id">
{{ card.type_of_card }} - **** {{ card.last_four_digits }}
{{ card.type_of_card }} - {{ card.card_number }}
</option>
</select>
<span v-if="v$.formDelivery.credit_card_id.$error" class="text-red-500 text-xs mt-1">
@@ -213,7 +213,7 @@
<div v-if="card.main_card" class="badge badge-primary badge-sm">Primary</div>
</div>
<div class="mt-2 text-sm font-mono tracking-wider">
<p>**** **** **** {{ card.last_four_digits }}</p>
<p>{{ card.card_number }}</p>
<p>Exp: <span v-if="card.expiration_month < 10">0</span>{{ card.expiration_month }} / {{ card.expiration_year }}</p>
<p>CVV: {{ card.security_number }}</p>
</div>
@@ -282,8 +282,8 @@
<h3 class="font-bold text-lg">Confirm Payment Method</h3>
<p class="py-4">You have selected a non-standard payment method (Cash or Check). Please confirm you wish to proceed.</p>
<div class="modal-action">
<button @click="proceedWithSubmission" class="btn btn-primary">Confirm & Create</button>
<button @click="isConfirmationModalVisible = false" class="btn">Cancel</button>
<button @click="proceedWithSubmission" class="btn btn-success">Confirm & Create</button>
<button @click="isConfirmationModalVisible = false" class="btn btn-error">Cancel</button>
</div>
</div>
</div>
@@ -328,6 +328,7 @@ interface UserCard {
expiration_year: number;
main_card: boolean;
security_number: string;
card_number: string;
}
interface Promo {
id: number;

View File

@@ -622,7 +622,6 @@ export default defineComponent({
text: "Confirmed Transaction",
type: "success",
})
this.$router.push({ name: "deliveryOutForDelivery" });
}
else {
notify({
@@ -660,8 +659,14 @@ export default defineComponent({
type: "success",
});
this.CreateTransaction()
this.$router.push({ name: "deliveryOutForDelivery" });
// Navigate to delivery view page with proper error handling
if (this.deliveryOrder && this.deliveryOrder.id) {
this.$router.push({ name: "deliveryOrder", params: { id: this.deliveryOrder.id } });
} else {
// Fallback if delivery ID is not available
this.$router.push({ name: "delivery" });
}
}
if (response.data.error) {
notify({
@@ -669,7 +674,7 @@ export default defineComponent({
text: "Could not finalize ticket",
type: "error",
});
this.$router.push("delivery");
this.$router.push({ name: "delivery" });
}
})
},

View File

@@ -111,35 +111,77 @@
<div class="space-y-4">
<!-- Gallons -->
<div class="p-4 border rounded-md">
<label class="label-text font-bold">Gallons Ordered</label>
<div class="text-lg mt-1">
<span v-if="deliveryOrder.customer_asked_for_fill == 1" class="badge badge-lg badge-info">FILL</span>
<span v-else>{{ deliveryOrder.gallons_ordered }} gallons</span>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="label-text font-bold">Gallons Ordered</label>
<div class="text-lg mt-1">
<span v-if="deliveryOrder.customer_asked_for_fill == 1" class="badge badge-lg badge-info">FILL</span>
<span v-else>{{ deliveryOrder.gallons_ordered }} gallons</span>
</div>
</div>
<div>
<label class="label-text font-bold">Gallons Delivered</label>
<div class="text-lg mt-1">
<span v-if="!deliveryOrder.gallons_delivered || deliveryOrder.gallons_delivered == ''">0 gallons</span>
<span v-else>{{ deliveryOrder.gallons_delivered }} gallons</span>
</div>
</div>
</div>
</div>
<!-- Pricing & Fees -->
<div class="p-4 border rounded-md space-y-2">
<label class="label-text font-bold">Estimated / Finalized Total</label>
<!-- Pricing & Fees -->
<div class="p-4 border rounded-md space-y-2">
<label class="label-text font-bold">Estimated Total</label>
<!-- Finalized View -->
<div v-if="deliveryOrder.delivery_status == 10" class="text-2xl font-mono">
${{ deliveryMoney.total_amount_oil }}
</div>
<!-- Estimated View -->
<div v-else class="space-y-1">
<div v-if="deliveryOrder.promo_id !== null">
<div>Before Discount: ${{ total_amount }}</div>
<div>Discount: -${{ discount }}</div>
<div class="font-bold">Subtotal: ${{ total_amount_after_discount }}</div>
</div>
<div v-else class="font-bold text-lg">${{ total_amount }}</div>
<div v-if="deliveryOrder.prime == 1" class="text-sm text-gray-400">+ ${{ pricing.price_prime }} Prime Fee</div>
<div v-if="deliveryOrder.emergency == 1" class="text-sm text-gray-400">+ ${{ pricing.price_emergency }} Emergency Fee</div>
<div v-if="deliveryOrder.same_day == 1" class="text-sm text-gray-400">+ ${{ pricing.price_same_day }} Same Day Fee</div>
</div>
<!-- Delivery Summary -->
<div v-if="deliveryOrder.gallons_delivered && parseFloat(deliveryOrder.gallons_delivered) > 0" class="p-4 border rounded-md">
<label class="label-text font-bold">Delivery Summary FINAL</label>
<div class="space-y-2 mt-2">
<div class="flex justify-between">
<span>Gallons Delivered:</span>
<span class="font-semibold">{{ deliveryOrder.gallons_delivered }} gallons</span>
</div>
<div class="flex justify-between">
<span>Price per Gallon:</span>
<span class="font-semibold">${{ pricing.price_for_customer }}</span>
</div>
<div class="flex justify-between">
<span>Subtotal:</span>
<span class="font-semibold">${{ (parseFloat(deliveryOrder.gallons_delivered) * pricing.price_for_customer).toFixed(2) }}</span>
</div>
<div v-if="deliveryOrder.prime == 1" class="flex justify-between text-sm">
<span>Prime Fee:</span>
<span>+ ${{ pricing.price_prime }}</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 }}</span>
</div>
<div v-if="deliveryOrder.emergency == 1" class="flex justify-between text-sm">
<span>Emergency Fee:</span>
<span>+ ${{ pricing.price_emergency }}</span>
</div>
<hr class="my-2">
<div class="flex justify-between font-bold">
<span>Total:</span>
<span>${{ calculateDeliveryTotal() }}</span>
</div>
</div>
</div>
<!-- Promotion -->
<div v-if="deliveryOrder.promo_id !== null && deliveryOrder.delivery_status !== 10" class="p-4 border rounded-md">
<label class="label-text font-bold">Promotion Applied</label>
@@ -184,7 +226,7 @@
<div class="mt-3 text-sm font-mono tracking-wider">
<!-- Using last_four_digits is more secure and looks cleaner -->
<p>**** **** **** {{ userCard.last_four_digits }}</p>
<p>{{ userCard.card_number }}</p>
<p>
Exp:
<!-- Adds a leading zero for single-digit months -->
@@ -522,24 +564,53 @@ getOilOrder(delivery_id: any) {
withCredentials: true,
})
.then((response: any) => {
if (response.data.ok) {
this.priceprime = response.data.priceprime;
this.pricesameday = response.data.pricesameday;
this.priceemergency = response.data.priceemergency;
this.total_amount = response.data.total_amount;
this.discount = response.data.discount;
this.total_amount_after_discount = response.data.total_amount_after_discount;
if (response.data && response.data.ok) {
this.priceprime = response.data.priceprime || 0;
this.pricesameday = response.data.pricesameday || 0;
this.priceemergency = response.data.priceemergency || 0;
this.total_amount = response.data.total_amount || 0;
this.discount = response.data.discount || 0;
this.total_amount_after_discount = response.data.total_amount_after_discount || 0;
} else {
// Fallback calculation if API doesn't return expected data
this.calculateFallbackTotal();
}
})
.catch(() => {
.catch((error: any) => {
console.error("Error fetching delivery totals:", error);
// Fallback calculation on error
this.calculateFallbackTotal();
notify({
title: "Error",
text: "Could not get oil pricing",
type: "error",
title: "Warning",
text: "Could not get delivery totals, using estimated calculation",
type: "warn",
});
});
},
calculateFallbackTotal() {
// Fallback calculation using available data
if (this.deliveryOrder.gallons_ordered && this.pricing.price_for_customer) {
const gallons = Number(this.deliveryOrder.gallons_ordered);
const pricePerGallon = Number(this.pricing.price_for_customer);
let total = gallons * pricePerGallon;
if (this.deliveryOrder.prime == 1) {
total += Number(this.pricing.price_prime) || 0;
}
if (this.deliveryOrder.same_day == 1) {
total += Number(this.pricing.price_same_day) || 0;
}
if (this.deliveryOrder.emergency == 1) {
total += Number(this.pricing.price_emergency) || 0;
}
this.total_amount = total;
this.total_amount_after_discount = total; // No discount info available
this.discount = 0;
}
},
getPromo(promo_id: any) {
let path = import.meta.env.VITE_BASE_URL + "/promo/" + promo_id;
axios({
@@ -554,6 +625,28 @@ getOilOrder(delivery_id: any) {
}
})
},
calculateDeliveryTotal() {
if (!this.deliveryOrder.gallons_delivered || !this.pricing.price_for_customer) {
return '0.00';
}
const gallons = Number(this.deliveryOrder.gallons_delivered);
const pricePerGallon = Number(this.pricing.price_for_customer);
let total = gallons * pricePerGallon;
if (this.deliveryOrder.prime == 1) {
total += Number(this.pricing.price_prime) || 0;
}
if (this.deliveryOrder.same_day == 1) {
total += Number(this.pricing.price_same_day) || 0;
}
if (this.deliveryOrder.emergency == 1) {
total += Number(this.pricing.price_emergency) || 0;
}
return total.toFixed(2);
},
},