work
This commit is contained in:
@@ -124,18 +124,15 @@
|
|||||||
<div>
|
<div>
|
||||||
<label class="label"><span class="label-text font-bold">Expected Delivery Date</span></label>
|
<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" />
|
<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>
|
<span v-if="v$.formDelivery.expected_delivery_date.$error" class="text-red-500 text-xs mt-1">Date is required.</span>
|
||||||
</div>
|
</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>
|
<div>
|
||||||
<label class="label"><span class="label-text font-bold">Apply Promotion</span></label>
|
<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">
|
<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;
|
other: boolean;
|
||||||
credit_card_id: number;
|
credit_card_id: number;
|
||||||
promo_id: number;
|
promo_id: number;
|
||||||
driver_employee_id: string | number;
|
|
||||||
}
|
}
|
||||||
interface CardFormData {
|
interface CardFormData {
|
||||||
card_name: string;
|
card_name: string;
|
||||||
@@ -398,7 +394,6 @@ export default defineComponent({
|
|||||||
other: false,
|
other: false,
|
||||||
credit_card_id: 0,
|
credit_card_id: 0,
|
||||||
promo_id: 0,
|
promo_id: 0,
|
||||||
driver_employee_id: '',
|
|
||||||
} as DeliveryFormData,
|
} as DeliveryFormData,
|
||||||
formCard: {
|
formCard: {
|
||||||
card_name: '',
|
card_name: '',
|
||||||
@@ -428,7 +423,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
expected_delivery_date: { required },
|
expected_delivery_date: { required },
|
||||||
driver_employee_id: { required },
|
|
||||||
credit_card_id: {
|
credit_card_id: {
|
||||||
// *** THIS IS THE FIX for both runtime and TypeScript ***
|
// *** THIS IS THE FIX for both runtime and TypeScript ***
|
||||||
// Adding `this: any` tells TypeScript what the context of `this` will be.
|
// 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.gallons_ordered = String(amount);
|
||||||
this.formDelivery.customer_asked_for_fill = false;
|
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() {
|
getPricingTiers() {
|
||||||
let path = import.meta.env.VITE_BASE_URL + "/info/price/oil/tiers";
|
let path = import.meta.env.VITE_BASE_URL + "/info/price/oil/tiers";
|
||||||
axios({ method: "get", url: path, withCredentials: true, headers: authHeader() })
|
axios({ method: "get", url: path, withCredentials: true, headers: authHeader() })
|
||||||
@@ -593,7 +592,6 @@ export default defineComponent({
|
|||||||
other: this.formDelivery.other,
|
other: this.formDelivery.other,
|
||||||
credit_card_id: this.formDelivery.credit_card_id,
|
credit_card_id: this.formDelivery.credit_card_id,
|
||||||
promo_id: this.formDelivery.promo_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}`;
|
let path = `${import.meta.env.VITE_BASE_URL}/delivery/create/${this.customer.id}`;
|
||||||
|
|||||||
@@ -123,7 +123,7 @@
|
|||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<!-- <div>
|
||||||
<label class="label"><span class="label-text font-bold">Assigned Driver</span></label>
|
<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">
|
<select v-model="CreateOilOrderForm.basicInfo.driver_employee_id" class="select select-bordered select-sm w-full">
|
||||||
<option disabled :value="0">Select a driver</option>
|
<option disabled :value="0">Select a driver</option>
|
||||||
@@ -131,7 +131,7 @@
|
|||||||
{{ driver.employee_first_name }} {{ driver.employee_last_name }}
|
{{ driver.employee_first_name }} {{ driver.employee_last_name }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div> -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Dispatcher Notes -->
|
<!-- Dispatcher Notes -->
|
||||||
|
|||||||
@@ -360,10 +360,14 @@ export default defineComponent({
|
|||||||
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.FinalizeOilOrderForm.cash_recieved = response.data.delivery.cash_recieved;
|
// Properly initialize all form fields with existing delivery data
|
||||||
this.FinalizeOilOrderForm.check_number = response.data.delivery.check_number;
|
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.credit_card_id = response.data.delivery.payment_card_id;
|
||||||
this.FinalizeOilOrderForm.customer_filled = response.data.delivery.customer_filled == 1;
|
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 {
|
} 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.");
|
||||||
}
|
}
|
||||||
@@ -485,13 +489,49 @@ 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, {
|
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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() });
|
||||||
|
|
||||||
|
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,
|
withCredentials: true,
|
||||||
headers: authHeader(),
|
headers: authHeader(),
|
||||||
});
|
});
|
||||||
@@ -499,7 +539,7 @@ export default defineComponent({
|
|||||||
// If a valid, approved, pre-auth transaction is found...
|
// If a valid, approved, pre-auth transaction is found...
|
||||||
if (transactionResponse.data && transactionResponse.data.transaction_type === 1 && transactionResponse.data.status === 0) {
|
if (transactionResponse.data && transactionResponse.data.transaction_type === 1 && transactionResponse.data.status === 0) {
|
||||||
|
|
||||||
// Recalculate the final amount based on the GALLONS DELIVERED from the form
|
// ...redirect to the capture page. The delivery is already updated.
|
||||||
const gallons = this.FinalizeOilOrderForm.gallons_delivered || '0';
|
const gallons = this.FinalizeOilOrderForm.gallons_delivered || '0';
|
||||||
const pricePerGallon = parseFloat(this.deliveryOrder.customer_price);
|
const pricePerGallon = parseFloat(this.deliveryOrder.customer_price);
|
||||||
let finalAmount = parseFloat(gallons) * pricePerGallon;
|
let finalAmount = parseFloat(gallons) * pricePerGallon;
|
||||||
@@ -511,7 +551,6 @@ export default defineComponent({
|
|||||||
finalAmount += parseFloat(this.pricing.price_same_day.toString()) || 0;
|
finalAmount += parseFloat(this.pricing.price_same_day.toString()) || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...then redirect to the capture page with the correct data.
|
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
name: 'captureAuthorize',
|
name: 'captureAuthorize',
|
||||||
params: { id: this.$route.params.id },
|
params: { id: this.$route.params.id },
|
||||||
@@ -520,27 +559,26 @@ export default defineComponent({
|
|||||||
amount: finalAmount.toFixed(2).toString()
|
amount: finalAmount.toFixed(2).toString()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return; // IMPORTANT: Stop execution here to prevent finalization.
|
|
||||||
|
} 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) { // ✅ FIX: Added ': any' to solve TypeScript error
|
} catch (error: any) {
|
||||||
// This is the expected path if no pre-auth transaction exists.
|
// Step 4b: If checking for pre-auth fails, but the update succeeded,
|
||||||
// We log the error for debugging but continue to the finalization logic below.
|
// finalize the financial part and redirect.
|
||||||
console.log("No pre-authorized transaction found. Proceeding with standard finalization.");
|
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 } });
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// 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.FinalizeOrder(payload);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -84,10 +84,10 @@
|
|||||||
<span v-else-if="deliveryOrder.delivery_status == 10">Finalized</span>
|
<span v-else-if="deliveryOrder.delivery_status == 10">Finalized</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<!-- <div>
|
||||||
<div class="font-bold text-sm">Assigned Driver</div>
|
<div class="font-bold text-sm">Assigned Driver</div>
|
||||||
<div>{{ deliveryOrder.driver_first_name }} {{ deliveryOrder.driver_last_name }}</div>
|
<div>{{ deliveryOrder.driver_first_name }} {{ deliveryOrder.driver_last_name }}</div>
|
||||||
</div>
|
</div> -->
|
||||||
<div>
|
<div>
|
||||||
<div class="font-bold text-sm">Scheduled Date</div>
|
<div class="font-bold text-sm">Scheduled Date</div>
|
||||||
<div>{{ deliveryOrder.expected_delivery_date }}</div>
|
<div>{{ deliveryOrder.expected_delivery_date }}</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user