Good progress
This commit is contained in:
@@ -14,7 +14,35 @@
|
||||
<!-- TOP SECTION: Customer Info -->
|
||||
<div class="my-6">
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<!-- ... (this section is fine, no changes needed) ... -->
|
||||
<div class="text-xl font-bold mb-2">Customer</div>
|
||||
<div>
|
||||
<div class="font-bold">{{ customer.customer_first_name }} {{ customer.customer_last_name }}</div>
|
||||
<div>{{ customer.customer_address }}</div>
|
||||
<div v-if="customer.customer_apt && customer.customer_apt !== 'None'">{{ customer.customer_apt }}</div>
|
||||
<div>
|
||||
{{ customer.customer_town }},
|
||||
<span v-if="customer.customer_state == 0">Massachusetts</span>
|
||||
<span v-else-if="customer.customer_state == 1">Rhode Island</span>
|
||||
<span v-else-if="customer.customer_state == 2">New Hampshire</span>
|
||||
<span v-else-if="customer.customer_state == 3">Maine</span>
|
||||
<span v-else-if="customer.customer_state == 4">Vermont</span>
|
||||
<span v-else-if="customer.customer_state == 5">Maine</span>
|
||||
<span v-else-if="customer.customer_state == 6">New York</span>
|
||||
<span v-else>Unknown state</span>
|
||||
{{ customer.customer_zip }}
|
||||
</div>
|
||||
<div class="mt-2 text-sm">
|
||||
{{ customer.customer_phone_number }}
|
||||
(<span v-if="customer.customer_home_type == 0">Residential</span>
|
||||
<span v-else-if="customer.customer_home_type == 1">apartment</span>
|
||||
<span v-else-if="customer.customer_home_type == 2">condo</span>
|
||||
<span v-else-if="customer.customer_home_type == 3">commercial</span>
|
||||
<span v-else-if="customer.customer_home_type == 4">business</span>
|
||||
<span v-else-if="customer.customer_home_type == 5">construction</span>
|
||||
<span v-else-if="customer.customer_home_type == 6">container</span>
|
||||
<span v-else>Unknown type</span>)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -109,7 +109,6 @@ interface Transaction {
|
||||
charge_amount: number | null;
|
||||
transaction_type: number;
|
||||
status: number;
|
||||
customer_name: string;
|
||||
created_at: string;
|
||||
auth_net_transaction_id: string | null;
|
||||
rejection_reason: string | null;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<!-- src/pages/delivery/update_tickets/finalize_ticket.vue -->
|
||||
<template>
|
||||
<div class="flex">
|
||||
|
||||
@@ -90,7 +89,7 @@
|
||||
<div class="font-bold">When Ordered</div>
|
||||
<div class="opacity-80">{{ deliveryOrder.when_ordered }}</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -159,12 +158,14 @@
|
||||
<div class="font-bold text-sm">Payment Method</div>
|
||||
<div class="opacity-80 text-sm">
|
||||
<span v-if="deliveryOrder.payment_type == 0">Cash</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 1">Credit Card</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 2">Credit Card & cash</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 1">CC - Tiger (Physical)</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 11">CC - Authorize (API)</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 2">Credit Card & Cash</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 3">Check</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 4">Other</span>
|
||||
<span v-else>No Payment Type Added</span>
|
||||
</div>
|
||||
<div v-if="userCardfound && (deliveryOrder.payment_type == 1 || deliveryOrder.payment_type == 2)" class="mt-2 p-3 rounded-lg border bg-accent/20 border-accent">
|
||||
<div v-if="userCardfound && (deliveryOrder.payment_type == 1 || deliveryOrder.payment_type == 2 || deliveryOrder.payment_type == 11)" class="mt-2 p-3 rounded-lg border bg-accent/20 border-accent">
|
||||
<!-- --- MODIFICATION --- Full display of card data -->
|
||||
<div class="font-bold text-sm">{{ userCard.type_of_card }}</div>
|
||||
<div class="text-sm font-mono tracking-wider space-y-1">
|
||||
@@ -175,15 +176,30 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Total -->
|
||||
<div class="flex justify-between items-center border-t border-base-100 pt-3">
|
||||
<span class="text-lg font-bold">
|
||||
Final Charge Amount
|
||||
</span>
|
||||
<!-- --- MODIFICATION --- Use `finalChargeAmount` computed property for live updates -->
|
||||
<span class="text-2xl font-bold text-success">
|
||||
${{ finalChargeAmount.toFixed(2) }}
|
||||
</span>
|
||||
<!-- Total Breakdown -->
|
||||
<div class="border-t border-base-100 pt-3 space-y-2">
|
||||
<!-- Show breakdown only when promo is active -->
|
||||
<div v-if="promo_active">
|
||||
<!-- Oil & Fees Total (before discount) -->
|
||||
<div class="flex justify-between items-center text-sm">
|
||||
<span>Oil & Fees Total</span>
|
||||
<span>${{ total_amount.toFixed(2) }}</span>
|
||||
</div>
|
||||
<!-- Promo Discount -->
|
||||
<div class="flex justify-between items-center text-sm text-success">
|
||||
<span>{{ promo.name_of_promotion }}</span>
|
||||
<span>-${{ discount.toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Final Charge Amount (always show) -->
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-lg font-bold">
|
||||
Final Charge Amount
|
||||
</span>
|
||||
<span class="text-2xl font-bold text-success">
|
||||
${{ finalChargeAmount.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -205,7 +221,7 @@
|
||||
<label class="label"><span class="label-text font-bold">Fill Location</span></label>
|
||||
<input v-model="FinalizeOilOrderForm.fill_location" class="input input-bordered input-sm w-full max-w-xs" type="text" placeholder="Fill location (e.g., 1-12)" />
|
||||
</div>
|
||||
|
||||
|
||||
<div>
|
||||
<label class="label"><span class="label-text font-bold">Cash Received</span></label>
|
||||
<input v-model="FinalizeOilOrderForm.cash_recieved" class="input input-bordered input-sm w-full max-w-xs" type="number" step="0.01" placeholder="Amount received" />
|
||||
@@ -270,7 +286,6 @@ export default defineComponent({
|
||||
isLoading: false,
|
||||
user: { id: 0 },
|
||||
userCardfound: false,
|
||||
total_amount: 0,
|
||||
preChargeTotal: 0,
|
||||
FinalizeOilOrderForm: {
|
||||
cash_recieved: '',
|
||||
@@ -307,16 +322,33 @@ export default defineComponent({
|
||||
same_day: 0,
|
||||
payment_type: 0,
|
||||
payment_card_id: '',
|
||||
promo_id: null,
|
||||
},
|
||||
pricing: {
|
||||
price_prime: 0,
|
||||
price_same_day: 0,
|
||||
},
|
||||
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,
|
||||
transaction: null as any,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
finalChargeAmount(): number {
|
||||
// If promo is active, use server-calculated totals (which include discounts)
|
||||
if (this.promo_active && this.total_amount_after_discount > 0) {
|
||||
return this.total_amount_after_discount;
|
||||
}
|
||||
|
||||
// Otherwise, calculate locally
|
||||
const gallons = Number(this.FinalizeOilOrderForm.gallons_delivered);
|
||||
const pricePerGallon = Number(this.deliveryOrder.customer_price);
|
||||
if (isNaN(gallons) || isNaN(pricePerGallon) || gallons <= 0) {
|
||||
@@ -340,7 +372,7 @@ export default defineComponent({
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/delivery/order/${delivery_id}`;
|
||||
// --- DEBUGGING STEP 2 ---
|
||||
console.log(`[DEBUG] Calling getOilOrder API at: ${path}`);
|
||||
|
||||
|
||||
try {
|
||||
const response = await axios.get(path, { withCredentials: true, headers: authHeader() });
|
||||
// --- DEBUGGING STEP 3 ---
|
||||
@@ -349,10 +381,10 @@ export default defineComponent({
|
||||
if (response.data && response.data.ok) {
|
||||
console.log('[DEBUG] Response is OK. Processing data...');
|
||||
this.deliveryOrder = response.data.delivery;
|
||||
|
||||
|
||||
// --- DEBUGGING STEP 4 ---
|
||||
console.log(`[DEBUG] Value of response.data.total_amount is:`, response.data.total_amount);
|
||||
|
||||
|
||||
this.total_amount = response.data.delivery.total_amount || 0;
|
||||
this.preChargeTotal = response.data.delivery.total_amount || 0;
|
||||
this.FinalizeOilOrderForm.gallons_delivered = this.deliveryOrder.gallons_delivered || '';
|
||||
@@ -360,10 +392,17 @@ export default defineComponent({
|
||||
|
||||
await this.getCustomer(this.deliveryOrder.customer_id);
|
||||
|
||||
if ([1, 2].includes(this.deliveryOrder.payment_type) && this.deliveryOrder.payment_card_id) {
|
||||
if ([1, 2, 11].includes(this.deliveryOrder.payment_type) && this.deliveryOrder.payment_card_id) {
|
||||
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
||||
}
|
||||
|
||||
if (this.deliveryOrder.promo_id != null) {
|
||||
this.getPromo(this.deliveryOrder.promo_id);
|
||||
}
|
||||
|
||||
// Fetch calculated totals including discounts
|
||||
this.sumdelivery(delivery_id);
|
||||
|
||||
// Call transaction fetch after customer is loaded
|
||||
setTimeout(() => this.getTransaction(delivery_id), 500);
|
||||
} else {
|
||||
@@ -411,57 +450,95 @@ export default defineComponent({
|
||||
.then((response: any) => { this.pricing = response.data; })
|
||||
.catch((error: any) => { console.error("[DEBUG] Error fetching oil pricing:", error); });
|
||||
},
|
||||
getTransaction(delivery_id: any) {
|
||||
// Consistent with delivery/view.vue - use customer transaction endpoint
|
||||
if (this.customer && this.customer.id) {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/payment/transactions/customer/${this.customer.id}/1`;
|
||||
axios.get(path, { withCredentials: true, headers: authHeader() })
|
||||
.then((response: any) => {
|
||||
console.log("Transaction API response:", response.data);
|
||||
// Handle both single transaction object and array responses
|
||||
if (response.data && Array.isArray(response.data) && response.data.length > 0) {
|
||||
// Find the transaction for this specific delivery
|
||||
const deliveryTransaction = response.data.find((txn: any) =>
|
||||
txn.delivery_id === parseInt(delivery_id) ||
|
||||
txn.transaction_id === delivery_id ||
|
||||
txn.delivery_number === delivery_id
|
||||
);
|
||||
this.transaction = deliveryTransaction || null;
|
||||
} else if (response.data && !Array.isArray(response.data)) {
|
||||
// If single transaction, check if it's for this delivery
|
||||
const txn = response.data;
|
||||
if (txn.delivery_id === parseInt(delivery_id) ||
|
||||
txn.transaction_id === delivery_id ||
|
||||
txn.delivery_number === delivery_id) {
|
||||
this.transaction = txn;
|
||||
} else {
|
||||
this.transaction = null;
|
||||
}
|
||||
} else {
|
||||
this.transaction = null;
|
||||
}
|
||||
|
||||
if (!this.transaction) {
|
||||
console.log(`No transaction found for delivery ${delivery_id} among customer transactions`);
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
// Handle various error responses gracefully
|
||||
if (error.response && error.response.status === 404) {
|
||||
console.log(`No transactions found for customer ${this.customer.id}`);
|
||||
this.transaction = null;
|
||||
} else if (error.response && error.response.status === 400) {
|
||||
console.log(`Bad request for customer transactions: ${error.response.data?.detail || error.message}`);
|
||||
this.transaction = null;
|
||||
} else {
|
||||
console.error("Error fetching transaction:", error);
|
||||
this.transaction = null;
|
||||
}
|
||||
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
|
||||
}
|
||||
})
|
||||
},
|
||||
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;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing",
|
||||
type: "error",
|
||||
});
|
||||
} else {
|
||||
console.log("Customer data not available, cannot fetch transactions");
|
||||
this.transaction = null;
|
||||
});
|
||||
},
|
||||
getTransaction(delivery_id: any) {
|
||||
// Add guard to prevent undefined customer ID API calls
|
||||
if (!delivery_id || !this.customer || !this.customer.id) {
|
||||
console.log("Skipping transaction fetch - delivery or customer data not available");
|
||||
return;
|
||||
}
|
||||
|
||||
// Consistent with delivery/view.vue - use customer transaction endpoint
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/payment/transactions/customer/${this.customer.id}/1`;
|
||||
axios.get(path, { withCredentials: true, headers: authHeader() })
|
||||
.then((response: any) => {
|
||||
console.log("Transaction API response:", response.data);
|
||||
// Handle both single transaction object and array responses
|
||||
if (response.data && Array.isArray(response.data) && response.data.length > 0) {
|
||||
// Find the transaction for this specific delivery
|
||||
const deliveryTransaction = response.data.find((txn: any) =>
|
||||
txn.delivery_id === parseInt(delivery_id) ||
|
||||
txn.transaction_id === delivery_id ||
|
||||
txn.delivery_number === delivery_id
|
||||
);
|
||||
this.transaction = deliveryTransaction || null;
|
||||
} else if (response.data && !Array.isArray(response.data)) {
|
||||
// If single transaction, check if it's for this delivery
|
||||
const txn = response.data;
|
||||
if (txn.delivery_id === parseInt(delivery_id) ||
|
||||
txn.transaction_id === delivery_id ||
|
||||
txn.delivery_number === delivery_id) {
|
||||
this.transaction = txn;
|
||||
} else {
|
||||
this.transaction = null;
|
||||
}
|
||||
} else {
|
||||
this.transaction = null;
|
||||
}
|
||||
|
||||
if (!this.transaction) {
|
||||
console.log(`No transaction found for delivery ${delivery_id} among customer transactions`);
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
// Handle various error responses gracefully
|
||||
if (error.response && error.response.status === 404) {
|
||||
console.log(`No transactions found for customer ${this.customer.id}`);
|
||||
this.transaction = null;
|
||||
} else if (error.response && error.response.status === 400) {
|
||||
console.log(`Bad request for customer transactions: ${error.response.data?.detail || error.message}`);
|
||||
this.transaction = null;
|
||||
} else {
|
||||
console.error("Error fetching transaction:", error);
|
||||
this.transaction = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
getTypeColor(transactionType: number) {
|
||||
switch (transactionType) {
|
||||
@@ -499,12 +576,12 @@ export default defineComponent({
|
||||
this.CreateTransaction();
|
||||
notify({ title: "Success", text: "Ticket has been finalized.", type: "success" });
|
||||
|
||||
// Redirect based on payment type - redirect to capture for credit card payments
|
||||
if ([1, 2].includes(this.deliveryOrder.payment_type)) {
|
||||
this.$router.push({ name: "captureAuthorize", params: { id: this.deliveryOrder.id } });
|
||||
} else {
|
||||
this.$router.push({ name: "deliveryOrder", params: { id: this.deliveryOrder.id } });
|
||||
}
|
||||
// FIX: Wait for customer data to be loaded before redirecting
|
||||
await this.waitForCustomerData(this.deliveryOrder.customer_id);
|
||||
|
||||
// Updated redirect logic based on your requirements
|
||||
await this.handleRedirect();
|
||||
|
||||
} catch (error: any) {
|
||||
const errorMessage = error.response?.data?.detail || "An error occurred during finalization.";
|
||||
notify({ title: "Error", text: errorMessage, type: "error" });
|
||||
@@ -512,6 +589,75 @@ export default defineComponent({
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
// NEW: Wait for customer data to be loaded before redirecting
|
||||
async waitForCustomerData(customerId: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const checkCustomer = () => {
|
||||
if (this.customer && this.customer.id && this.customer.id === customerId) {
|
||||
resolve();
|
||||
} else {
|
||||
setTimeout(checkCustomer, 100);
|
||||
}
|
||||
};
|
||||
checkCustomer();
|
||||
});
|
||||
},
|
||||
|
||||
// NEW: Updated redirect logic based on payment type and transaction status
|
||||
async handleRedirect() {
|
||||
console.log('[DEBUG] Starting redirect logic...');
|
||||
console.log('[DEBUG] payment_type:', this.deliveryOrder.payment_type);
|
||||
console.log('[DEBUG] transaction:', this.transaction);
|
||||
console.log('[DEBUG] customer:', this.customer);
|
||||
|
||||
if (this.deliveryOrder.payment_type === 1) {
|
||||
// payment_type 1: Manual charging - already charged, just redirect to profile
|
||||
console.log('[DEBUG] payment_type 1 - redirecting to customer profile');
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
|
||||
} else if (this.deliveryOrder.payment_type === 11) {
|
||||
// payment_type 11: API charging - check transaction type
|
||||
console.log('[DEBUG] payment_type 11 - checking transaction type');
|
||||
|
||||
if (this.transaction) {
|
||||
console.log('[DEBUG] Transaction found, type:', this.transaction.transaction_type);
|
||||
|
||||
if (this.transaction.transaction_type === 0) {
|
||||
// Already charged (transaction_type = 0) - redirect to profile
|
||||
console.log('[DEBUG] Already charged - redirecting to customer profile');
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
|
||||
} else if (this.transaction.transaction_type === 1) {
|
||||
// Auth only (transaction_type = 1) - redirect to capture page
|
||||
console.log('[DEBUG] Auth only - redirecting to capture page');
|
||||
this.$router.push({ name: "captureAuthorize", params: { id: this.deliveryOrder.id } });
|
||||
|
||||
} else {
|
||||
// Unknown transaction type - default to customer profile
|
||||
console.log('[DEBUG] Unknown transaction type - redirecting to customer profile');
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
}
|
||||
|
||||
} else {
|
||||
// No transaction found for payment_type 11 - redirect to customer profile
|
||||
console.log('[DEBUG] No transaction found for payment_type 11 - redirecting to customer profile');
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
}
|
||||
|
||||
} else if ([2].includes(this.deliveryOrder.payment_type)) {
|
||||
// payment_type 2: Credit Card & Cash - go to capture page for any remaining payment
|
||||
console.log('[DEBUG] payment_type 2 - redirecting to capture page');
|
||||
this.$router.push({ name: "captureAuthorize", params: { id: this.deliveryOrder.id } });
|
||||
|
||||
} else {
|
||||
// Default case (cash, check, etc.) - redirect to customer profile
|
||||
console.log('[DEBUG] Default payment type - redirecting to customer profile');
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
|
||||
@@ -132,25 +132,44 @@
|
||||
<!-- 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.promo_id !== null">
|
||||
<div>Before Discount: ${{ total_amount }}</div>
|
||||
<div>Discount: -${{ discount }}</div>
|
||||
<div class="font-bold">Subtotal: ${{ total_amount_after_discount }}</div>
|
||||
<!-- Total Breakdown -->
|
||||
<div class="space-y-2">
|
||||
<!-- Show breakdown only when promo is active -->
|
||||
<div v-if="promo && promo.name_of_promotion">
|
||||
<!-- Oil & Fees Total (before discount) -->
|
||||
<div class="flex justify-between items-center text-sm">
|
||||
<span>Oil & Fees Total</span>
|
||||
<span>${{ calculateEstimatedTotal().toFixed(2) }}</span>
|
||||
</div>
|
||||
<!-- Promo Discount -->
|
||||
<div class="flex justify-between items-center text-sm text-success">
|
||||
<span>{{ promo.name_of_promotion }}</span>
|
||||
<span>-${{ discount.toFixed(2) }}</span>
|
||||
</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>
|
||||
<!-- Final Charge Amount (always show) -->
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-lg font-bold">
|
||||
Estimated Charge Amount
|
||||
</span>
|
||||
<span class="text-2xl font-bold text-success">
|
||||
${{ (promo && promo.name_of_promotion ? (calculateEstimatedTotal() - discount).toFixed(2) : calculateEstimatedTotal().toFixed(2)) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Fee Details (show regardless of promo) -->
|
||||
<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>
|
||||
|
||||
<!-- Transaction Summary -->
|
||||
<div v-if="transaction && (transaction.transaction_type !== undefined || transaction.preauthorize_amount || transaction.charge_amount)" class="p-4 border rounded-md">
|
||||
<label class="label-text font-bold">Transaction Summary</label>
|
||||
<div class="mt-2 space-y-2">
|
||||
<div v-if="deliveryOrder.payment_type == 11" class="p-4 border rounded-md">
|
||||
<label class="label-text font-bold">Authorize.net Transaction Details</label>
|
||||
<div v-if="transaction" class="mt-2 space-y-2">
|
||||
<div class="flex justify-between">
|
||||
<span>Transaction ID:</span>
|
||||
<span class="font-mono">{{ transaction.auth_net_transaction_id }}</span>
|
||||
<span class="font-bold">Transaction ID:</span>
|
||||
<span class="font-mono">{{ transaction.auth_net_transaction_id || 'N/A' }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Pre-Auth Amount:</span>
|
||||
@@ -162,7 +181,9 @@
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Type:</span>
|
||||
<span :class="getTypeColor(transaction.transaction_type)">{{ transaction.transaction_type === 0 ? 'Charge' : transaction.transaction_type === 1 ? 'Auth' : 'Capture' }}</span>
|
||||
<span :class="getTypeColor(transaction.transaction_type)">
|
||||
{{ transaction.transaction_type === 0 ? 'Charge' : transaction.transaction_type === 1 ? 'Auth' : transaction.transaction_type === 2 ? 'Capture' : 'Other' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Date:</span>
|
||||
@@ -175,6 +196,17 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="mt-2 text-gray-500">
|
||||
No authorize.net transaction data available
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Simple Payment Display for Other Types -->
|
||||
<div v-else-if="deliveryOrder.payment_type == 1" class="p-4 border rounded-md">
|
||||
<label class="label-text font-bold">Payment Method</label>
|
||||
<div class="mt-2">
|
||||
<span class="text-info font-semibold">Processed via Tiger Card Machine</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delivery Summary -->
|
||||
@@ -206,9 +238,20 @@
|
||||
<span>+ ${{ pricing.price_emergency }}</span>
|
||||
</div>
|
||||
<hr class="my-2">
|
||||
<!-- Show promo breakdown for delivered amounts -->
|
||||
<div v-if="promo && promo.name_of_promotion">
|
||||
<div class="flex justify-between text-sm">
|
||||
<span>Delivered Total (before discount):</span>
|
||||
<span>${{ calculateDeliveryTotal() }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-sm text-success">
|
||||
<span>{{ promo.name_of_promotion }}</span>
|
||||
<span>-${{ discount.toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between font-bold">
|
||||
<span>Total:</span>
|
||||
<span>${{ calculateDeliveryTotal() }}</span>
|
||||
<span>${{ (promo && promo.name_of_promotion ? (parseFloat(calculateDeliveryTotal()) - discount).toFixed(2) : calculateDeliveryTotal()) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -234,7 +277,8 @@
|
||||
<div class="mt-1">
|
||||
<div class="text-lg">
|
||||
<span v-if="deliveryOrder.payment_type == 0">Cash</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 1">Credit Card</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 1">Tiger Card Machine</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 11">Authorize.net PCI Card API</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 2">Credit Card & Cash</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 3">Check</span>
|
||||
<span v-else-if="deliveryOrder.payment_type == 4">Other</span>
|
||||
@@ -513,7 +557,7 @@ export default defineComponent({
|
||||
.then((response: any) => {
|
||||
this.pricing = response.data;
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((error: any) => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing",
|
||||
@@ -522,26 +566,22 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
getCustomer(user_id: any) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/customer/" + user_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
let path = import.meta.env.VITE_BASE_URL + "/customer/" + user_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.customer = response.data;
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.customer = response.data;
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not find customer",
|
||||
type: "error",
|
||||
});
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getPaymentCard(card_id: any) {
|
||||
@@ -572,26 +612,25 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
|
||||
async getOilOrder(delivery_id: any) {
|
||||
getOilOrder(delivery_id: any) {
|
||||
if (!delivery_id) { // Add a guard to prevent calls with an undefined ID
|
||||
console.error("getOilOrder called with no ID.");
|
||||
return;
|
||||
}
|
||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/" + delivery_id;
|
||||
try {
|
||||
const response = await axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
});
|
||||
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
})
|
||||
.then((response: any) => {
|
||||
// FIX: Check for the 'ok' flag and access the nested 'delivery' object
|
||||
if (response.data && response.data.ok) {
|
||||
this.deliveryOrder = response.data.delivery; // <-- THIS IS THE CRITICAL CHANGE
|
||||
|
||||
// Now that this.deliveryOrder is the correct object, the rest of the logic will work.
|
||||
await this.getCustomer(this.deliveryOrder.customer_id);
|
||||
this.getCustomer(this.deliveryOrder.customer_id);
|
||||
|
||||
if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) {
|
||||
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
||||
@@ -600,16 +639,19 @@ export default defineComponent({
|
||||
this.getPromo(this.deliveryOrder.promo_id);
|
||||
}
|
||||
|
||||
// Now that customer is loaded, we can fetch transactions directly
|
||||
this.getTransaction(delivery_id);
|
||||
// Only fetch transactions for Authorize.net payments
|
||||
if (this.deliveryOrder.payment_type == 11) {
|
||||
this.getTransaction(delivery_id);
|
||||
}
|
||||
|
||||
} else {
|
||||
console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
|
||||
notify({ title: "Error", text: "Could not load delivery details.", type: "error" });
|
||||
console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
|
||||
notify({ title: "Error", text: "Could not load delivery details.", type: "error" });
|
||||
}
|
||||
} catch (error) {
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error("Error fetching delivery order:", error);
|
||||
}
|
||||
});
|
||||
},
|
||||
getOilOrderMoney(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_MONEY_URL + "/delivery/order/money/" + delivery_id;
|
||||
@@ -637,9 +679,9 @@ export default defineComponent({
|
||||
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;
|
||||
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;
|
||||
} else {
|
||||
// Fallback calculation if API doesn't return expected data
|
||||
this.calculateFallbackTotal();
|
||||
@@ -690,9 +732,12 @@ export default defineComponent({
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data) {
|
||||
this.promo = response.data
|
||||
this.promo = response.data;
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('Error fetching promo:', error);
|
||||
})
|
||||
},
|
||||
|
||||
calculateDeliveryTotal() {
|
||||
@@ -716,59 +761,46 @@ export default defineComponent({
|
||||
|
||||
return total.toFixed(2);
|
||||
},
|
||||
calculateEstimatedTotal() {
|
||||
if (!this.deliveryOrder.gallons_ordered || !this.pricing.price_for_customer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return total;
|
||||
},
|
||||
|
||||
getTransaction(delivery_id: any) {
|
||||
// Fix: Use customer transaction endpoint to get transactions for this delivery's customer
|
||||
// The API seems to work with customer-centric endpoints
|
||||
if (this.customer && this.customer.id) {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/payment/transactions/customer/${this.customer.id}/1`;
|
||||
axios.get(path, { withCredentials: true, headers: authHeader() })
|
||||
.then((response: any) => {
|
||||
console.log("Transaction API response:", response.data); // Debug log to see actual response structure
|
||||
// Handle both single transaction object and array responses
|
||||
if (response.data && Array.isArray(response.data) && response.data.length > 0) {
|
||||
// Find the transaction for this specific delivery
|
||||
const deliveryTransaction = response.data.find((txn: any) =>
|
||||
txn.delivery_id === parseInt(delivery_id) ||
|
||||
txn.transaction_id === delivery_id ||
|
||||
txn.delivery_number === delivery_id
|
||||
);
|
||||
this.transaction = deliveryTransaction || null;
|
||||
} else if (response.data && !Array.isArray(response.data)) {
|
||||
// If single transaction, check if it's for this delivery
|
||||
const txn = response.data;
|
||||
if (txn.delivery_id === parseInt(delivery_id) ||
|
||||
txn.transaction_id === delivery_id ||
|
||||
txn.delivery_number === delivery_id) {
|
||||
this.transaction = txn;
|
||||
} else {
|
||||
this.transaction = null;
|
||||
}
|
||||
} else {
|
||||
this.transaction = null;
|
||||
}
|
||||
|
||||
if (!this.transaction) {
|
||||
console.log(`No transaction found for delivery ${delivery_id} among customer transactions`);
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
// Handle various error responses gracefully
|
||||
if (error.response && error.response.status === 404) {
|
||||
console.log(`No transactions found for customer ${this.customer.id}`);
|
||||
this.transaction = null;
|
||||
} else if (error.response && error.response.status === 400) {
|
||||
console.log(`Bad request for customer transactions: ${error.response.data?.detail || error.message}`);
|
||||
this.transaction = null;
|
||||
} else {
|
||||
console.error("Error fetching transaction:", error);
|
||||
this.transaction = null;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("Customer data not available, cannot fetch transactions");
|
||||
// Simple endpoint to get transaction directly by delivery_id
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/payment/transaction/delivery/${delivery_id}`;
|
||||
axios.get(path, {
|
||||
withCredentials: true,
|
||||
headers: authHeader()
|
||||
}).then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
this.transaction = response.data.transaction;
|
||||
console.log("Transaction loaded:", this.transaction);
|
||||
} else {
|
||||
console.log("No transaction found for delivery:", delivery_id);
|
||||
this.transaction = null;
|
||||
}
|
||||
}).catch((error: any) => {
|
||||
console.error("Error fetching transaction:", error);
|
||||
this.transaction = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -315,9 +315,9 @@ export default defineComponent({
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
this.total_amount = response.data.total_amount;
|
||||
this.discount = response.data.discount;
|
||||
this.total_amount_after_discount = response.data.total_amount_after_discount;
|
||||
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;
|
||||
|
||||
// Auto-populate charge amount with the calculated total
|
||||
if (this.promo_active) {
|
||||
@@ -513,8 +513,8 @@ export default defineComponent({
|
||||
|
||||
const response = await axios.post(chargePath, chargePayload, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
// Assuming your backend charge response has the same structure
|
||||
if (response.data && response.data.status === 'APPROVED') { // Adjust based on your actual response
|
||||
// Status codes: 0 = APPROVED, 1 = DECLINED (based on backend TransactionStatus enum)
|
||||
if (response.data && response.data.status === 0) { // 0 = APPROVED
|
||||
this.success = `Charge successful! Transaction ID: ${response.data.auth_net_transaction_id || 'N/A'}`;
|
||||
setTimeout(() => {
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
@@ -525,6 +525,7 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
this.error = error.response?.data?.detail || `Failed to ${actionType} payment`
|
||||
notify({
|
||||
title: "Error",
|
||||
|
||||
@@ -339,8 +339,7 @@ export default defineComponent({
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
console.log('%%%%%%%%%%%%%%%')
|
||||
console.log(response.data)
|
||||
|
||||
|
||||
this.priceprime = response.data.priceprime;
|
||||
this.pricesameday = response.data.pricesameday;
|
||||
@@ -348,7 +347,7 @@ export default defineComponent({
|
||||
this.total_amount = response.data.total_amount;
|
||||
this.discount = response.data.discount;
|
||||
this.total_amount_after_discount = response.data.total_amount_after_discount;
|
||||
console.log('%%%%%%%%%%%%%%%')
|
||||
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -408,7 +407,6 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
getOilOrder(delivery_id: any) {
|
||||
console.log("=== DEBUG: getOilOrder called with delivery_id:", delivery_id);
|
||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/order/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
@@ -500,6 +498,13 @@ export default defineComponent({
|
||||
type: "success",
|
||||
});
|
||||
}
|
||||
if (payment_type == 11) {
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "marked payment as CC - Authorize (API)",
|
||||
type: "success",
|
||||
});
|
||||
}
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user