work
This commit is contained in:
@@ -124,18 +124,15 @@
|
||||
<div>
|
||||
<label class="label"><span class="label-text font-bold">Expected Delivery Date</span></label>
|
||||
<input v-model="formDelivery.expected_delivery_date" class="input input-bordered input-sm w-full max-w-xs" type="date" />
|
||||
<div class="flex flex-wrap gap-2 mt-2">
|
||||
<button @click.prevent="setDeliveryDate(0)" class="btn btn-xs btn-outline">Today</button>
|
||||
<button @click.prevent="setDeliveryDate(1)" class="btn btn-xs btn-outline">Tomorrow</button>
|
||||
<button @click.prevent="setDeliveryDate(2)" class="btn btn-xs btn-outline">In 2 Days</button>
|
||||
<button @click.prevent="setDeliveryDate(3)" class="btn btn-xs btn-outline">In 3 Days</button>
|
||||
</div>
|
||||
<span v-if="v$.formDelivery.expected_delivery_date.$error" class="text-red-500 text-xs mt-1">Date is required.</span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label"><span class="label-text font-bold">Assigned Driver</span></label>
|
||||
<select class="select select-bordered select-sm w-full max-w-xs" v-model="formDelivery.driver_employee_id">
|
||||
<option disabled value="">Select a driver</option>
|
||||
<option v-for="driver in truckDriversList" :key="driver.id" :value="driver.id">
|
||||
{{ driver.employee_first_name }} {{ driver.employee_last_name }}
|
||||
</option>
|
||||
</select>
|
||||
<span v-if="v$.formDelivery.driver_employee_id.$error" class="text-red-500 text-xs mt-1">Driver is required.</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label"><span class="label-text font-bold">Apply Promotion</span></label>
|
||||
<select class="select select-bordered select-sm w-full max-w-xs" v-model="formDelivery.promo_id">
|
||||
@@ -358,7 +355,6 @@ interface DeliveryFormData {
|
||||
other: boolean;
|
||||
credit_card_id: number;
|
||||
promo_id: number;
|
||||
driver_employee_id: string | number;
|
||||
}
|
||||
interface CardFormData {
|
||||
card_name: string;
|
||||
@@ -398,7 +394,6 @@ export default defineComponent({
|
||||
other: false,
|
||||
credit_card_id: 0,
|
||||
promo_id: 0,
|
||||
driver_employee_id: '',
|
||||
} as DeliveryFormData,
|
||||
formCard: {
|
||||
card_name: '',
|
||||
@@ -428,7 +423,6 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
expected_delivery_date: { required },
|
||||
driver_employee_id: { required },
|
||||
credit_card_id: {
|
||||
// *** THIS IS THE FIX for both runtime and TypeScript ***
|
||||
// Adding `this: any` tells TypeScript what the context of `this` will be.
|
||||
@@ -494,6 +488,11 @@ export default defineComponent({
|
||||
this.formDelivery.gallons_ordered = String(amount);
|
||||
this.formDelivery.customer_asked_for_fill = false;
|
||||
},
|
||||
setDeliveryDate(days: number) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + days);
|
||||
this.formDelivery.expected_delivery_date = date.toISOString().split('T')[0];
|
||||
},
|
||||
getPricingTiers() {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/info/price/oil/tiers";
|
||||
axios({ method: "get", url: path, withCredentials: true, headers: authHeader() })
|
||||
@@ -593,7 +592,6 @@ export default defineComponent({
|
||||
other: this.formDelivery.other,
|
||||
credit_card_id: this.formDelivery.credit_card_id,
|
||||
promo_id: this.formDelivery.promo_id,
|
||||
driver_employee_id: this.formDelivery.driver_employee_id,
|
||||
};
|
||||
|
||||
let path = `${import.meta.env.VITE_BASE_URL}/delivery/create/${this.customer.id}`;
|
||||
@@ -656,4 +654,4 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<!-- <div>
|
||||
<label class="label"><span class="label-text font-bold">Assigned Driver</span></label>
|
||||
<select v-model="CreateOilOrderForm.basicInfo.driver_employee_id" class="select select-bordered select-sm w-full">
|
||||
<option disabled :value="0">Select a driver</option>
|
||||
@@ -131,7 +131,7 @@
|
||||
{{ driver.employee_first_name }} {{ driver.employee_last_name }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- Dispatcher Notes -->
|
||||
|
||||
@@ -359,11 +359,15 @@ export default defineComponent({
|
||||
if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) {
|
||||
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
||||
}
|
||||
|
||||
this.FinalizeOilOrderForm.cash_recieved = response.data.delivery.cash_recieved;
|
||||
this.FinalizeOilOrderForm.check_number = response.data.delivery.check_number;
|
||||
|
||||
// Properly initialize all form fields with existing delivery data
|
||||
this.FinalizeOilOrderForm.cash_recieved = response.data.delivery.cash_recieved || '';
|
||||
this.FinalizeOilOrderForm.check_number = response.data.delivery.check_number || '';
|
||||
this.FinalizeOilOrderForm.credit_card_id = response.data.delivery.payment_card_id;
|
||||
this.FinalizeOilOrderForm.customer_filled = response.data.delivery.customer_filled == 1;
|
||||
this.FinalizeOilOrderForm.gallons_delivered = response.data.delivery.gallons_delivered || '';
|
||||
this.FinalizeOilOrderForm.driver = response.data.delivery.driver_employee_id || 0;
|
||||
this.FinalizeOilOrderForm.delivery_status = 10; // Finalization status - hardcoded for finalizing action
|
||||
} else {
|
||||
console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
|
||||
}
|
||||
@@ -485,62 +489,96 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
|
||||
async onSubmit() {
|
||||
// First, check if there's a pre-authorized transaction for this delivery.
|
||||
try {
|
||||
// This is the CORRECT URL for the backend endpoint.
|
||||
const correctedUrl = `${import.meta.env.VITE_AUTHORIZE_URL}/api/transaction/delivery/${this.$route.params.id}`;
|
||||
|
||||
const transactionResponse = await axios.get(correctedUrl, {
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
});
|
||||
|
||||
// If a valid, approved, pre-auth transaction is found...
|
||||
if (transactionResponse.data && transactionResponse.data.transaction_type === 1 && transactionResponse.data.status === 0) {
|
||||
|
||||
// Recalculate the final amount based on the GALLONS DELIVERED from the form
|
||||
const gallons = this.FinalizeOilOrderForm.gallons_delivered || '0';
|
||||
const pricePerGallon = parseFloat(this.deliveryOrder.customer_price);
|
||||
let finalAmount = parseFloat(gallons) * pricePerGallon;
|
||||
async onSubmit() {
|
||||
// Step 1: ALWAYS build the payload with the latest form data.
|
||||
const payload = {
|
||||
cash_recieved: this.FinalizeOilOrderForm.cash_recieved,
|
||||
check_number: this.FinalizeOilOrderForm.check_number,
|
||||
delivery_status: this.FinalizeOilOrderForm.delivery_status,
|
||||
driver_employee_id: this.FinalizeOilOrderForm.driver,
|
||||
gallons_delivered: this.FinalizeOilOrderForm.gallons_delivered,
|
||||
customer_filled: this.FinalizeOilOrderForm.customer_filled,
|
||||
fill_location: this.FinalizeOilOrderForm.fill_location,
|
||||
};
|
||||
|
||||
if (this.deliveryOrder.prime == 1) {
|
||||
finalAmount += parseFloat(this.pricing.price_prime.toString()) || 0;
|
||||
}
|
||||
if (this.deliveryOrder.same_day == 1) {
|
||||
finalAmount += parseFloat(this.pricing.price_same_day.toString()) || 0;
|
||||
}
|
||||
// Step 2: ALWAYS update the delivery order with the payload.
|
||||
// We make this an async call and wait for it to finish.
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/deliverydata/finalize/${this.deliveryOrder.id}`;
|
||||
const finalizeResponse = await axios.put(path, payload, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
// ...then redirect to the capture page with the correct data.
|
||||
this.$router.push({
|
||||
name: 'captureAuthorize',
|
||||
params: { id: this.$route.params.id },
|
||||
query: {
|
||||
gallons: gallons,
|
||||
amount: finalAmount.toFixed(2).toString()
|
||||
}
|
||||
});
|
||||
return; // IMPORTANT: Stop execution here to prevent finalization.
|
||||
}
|
||||
} catch (error: any) { // ✅ FIX: Added ': any' to solve TypeScript error
|
||||
// This is the expected path if no pre-auth transaction exists.
|
||||
// We log the error for debugging but continue to the finalization logic below.
|
||||
console.log("No pre-authorized transaction found. Proceeding with standard finalization.");
|
||||
if (!finalizeResponse.data.ok) {
|
||||
// If the update fails, stop everything and show an error.
|
||||
notify({
|
||||
title: "Error",
|
||||
text: finalizeResponse.data.error || "Could not update delivery details.",
|
||||
type: "error"
|
||||
});
|
||||
return; // Stop execution.
|
||||
}
|
||||
} catch (error: any) {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Failed to update delivery details.",
|
||||
type: "error"
|
||||
});
|
||||
console.error("FinalizeOrder error:", error);
|
||||
return; // Stop execution.
|
||||
}
|
||||
|
||||
// Step 3: NOW, check if there's a pre-authorized transaction.
|
||||
try {
|
||||
const transactionUrl = `${import.meta.env.VITE_AUTHORIZE_URL}/api/transaction/delivery/${this.$route.params.id}`;
|
||||
const transactionResponse = await axios.get(transactionUrl, {
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
});
|
||||
|
||||
// If a valid, approved, pre-auth transaction is found...
|
||||
if (transactionResponse.data && transactionResponse.data.transaction_type === 1 && transactionResponse.data.status === 0) {
|
||||
|
||||
// ...redirect to the capture page. The delivery is already updated.
|
||||
const gallons = this.FinalizeOilOrderForm.gallons_delivered || '0';
|
||||
const pricePerGallon = parseFloat(this.deliveryOrder.customer_price);
|
||||
let finalAmount = parseFloat(gallons) * pricePerGallon;
|
||||
|
||||
if (this.deliveryOrder.prime == 1) {
|
||||
finalAmount += parseFloat(this.pricing.price_prime.toString()) || 0;
|
||||
}
|
||||
if (this.deliveryOrder.same_day == 1) {
|
||||
finalAmount += parseFloat(this.pricing.price_same_day.toString()) || 0;
|
||||
}
|
||||
|
||||
// If no pre-auth transaction was found, proceed with the normal finalization flow.
|
||||
const payload = {
|
||||
cash_recieved: this.FinalizeOilOrderForm.cash_recieved,
|
||||
check_number: this.FinalizeOilOrderForm.check_number,
|
||||
delivery_status: this.FinalizeOilOrderForm.delivery_status,
|
||||
driver_employee_id: this.FinalizeOilOrderForm.driver,
|
||||
gallons_delivered: this.FinalizeOilOrderForm.gallons_delivered,
|
||||
customer_filled: this.FinalizeOilOrderForm.customer_filled,
|
||||
fill_location: this.FinalizeOilOrderForm.fill_location,
|
||||
};
|
||||
this.$router.push({
|
||||
name: 'captureAuthorize',
|
||||
params: { id: this.$route.params.id },
|
||||
query: {
|
||||
gallons: gallons,
|
||||
amount: finalAmount.toFixed(2).toString()
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
// Step 4a: If no pre-auth transaction, finalize the financial part and redirect.
|
||||
notify({ title: "Success", text: "Ticket details have been updated.", type: "success" });
|
||||
this.CreateTransaction();
|
||||
this.$router.push({ name: "deliveryOrder", params: { id: this.deliveryOrder.id } });
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Step 4b: If checking for pre-auth fails, but the update succeeded,
|
||||
// finalize the financial part and redirect.
|
||||
console.log("No pre-authorized transaction found. Proceeding with standard finalization.");
|
||||
notify({ title: "Success", text: "Ticket details have been updated.", type: "success" });
|
||||
this.CreateTransaction();
|
||||
this.$router.push({ name: "deliveryOrder", params: { id: this.deliveryOrder.id } });
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
this.FinalizeOrder(payload);
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -84,10 +84,10 @@
|
||||
<span v-else-if="deliveryOrder.delivery_status == 10">Finalized</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<!-- <div>
|
||||
<div class="font-bold text-sm">Assigned Driver</div>
|
||||
<div>{{ deliveryOrder.driver_first_name }} {{ deliveryOrder.driver_last_name }}</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<div>
|
||||
<div class="font-bold text-sm">Scheduled Date</div>
|
||||
<div>{{ deliveryOrder.expected_delivery_date }}</div>
|
||||
|
||||
Reference in New Issue
Block a user