Good progress

This commit is contained in:
2025-09-18 13:02:28 -04:00
parent 827debd1cc
commit 6baefe9f50
6 changed files with 397 additions and 186 deletions

View File

@@ -14,7 +14,35 @@
<!-- TOP SECTION: Customer Info --> <!-- TOP SECTION: Customer Info -->
<div class="my-6"> <div class="my-6">
<div class="bg-neutral rounded-lg p-5"> <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>
</div> </div>

View File

@@ -109,7 +109,6 @@ interface Transaction {
charge_amount: number | null; charge_amount: number | null;
transaction_type: number; transaction_type: number;
status: number; status: number;
customer_name: string;
created_at: string; created_at: string;
auth_net_transaction_id: string | null; auth_net_transaction_id: string | null;
rejection_reason: string | null; rejection_reason: string | null;

View File

@@ -1,4 +1,3 @@
<!-- src/pages/delivery/update_tickets/finalize_ticket.vue -->
<template> <template>
<div class="flex"> <div class="flex">
@@ -90,7 +89,7 @@
<div class="font-bold">When Ordered</div> <div class="font-bold">When Ordered</div>
<div class="opacity-80">{{ deliveryOrder.when_ordered }}</div> <div class="opacity-80">{{ deliveryOrder.when_ordered }}</div>
</div> </div>
</div> </div>
</div> </div>
@@ -159,12 +158,14 @@
<div class="font-bold text-sm">Payment Method</div> <div class="font-bold text-sm">Payment Method</div>
<div class="opacity-80 text-sm"> <div class="opacity-80 text-sm">
<span v-if="deliveryOrder.payment_type == 0">Cash</span> <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">CC - Tiger (Physical)</span>
<span v-else-if="deliveryOrder.payment_type == 2">Credit Card & cash</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 == 3">Check</span>
<span v-else-if="deliveryOrder.payment_type == 4">Other</span>
<span v-else>No Payment Type Added</span> <span v-else>No Payment Type Added</span>
</div> </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 --> <!-- --- MODIFICATION --- Full display of card data -->
<div class="font-bold text-sm">{{ userCard.type_of_card }}</div> <div class="font-bold text-sm">{{ userCard.type_of_card }}</div>
<div class="text-sm font-mono tracking-wider space-y-1"> <div class="text-sm font-mono tracking-wider space-y-1">
@@ -175,15 +176,30 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Total --> <!-- Total Breakdown -->
<div class="flex justify-between items-center border-t border-base-100 pt-3"> <div class="border-t border-base-100 pt-3 space-y-2">
<span class="text-lg font-bold"> <!-- Show breakdown only when promo is active -->
Final Charge Amount <div v-if="promo_active">
</span> <!-- Oil & Fees Total (before discount) -->
<!-- --- MODIFICATION --- Use `finalChargeAmount` computed property for live updates --> <div class="flex justify-between items-center text-sm">
<span class="text-2xl font-bold text-success"> <span>Oil & Fees Total</span>
${{ finalChargeAmount.toFixed(2) }} <span>${{ total_amount.toFixed(2) }}</span>
</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> </div>
</div> </div>
@@ -205,7 +221,7 @@
<label class="label"><span class="label-text font-bold">Fill Location</span></label> <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)" /> <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>
<div> <div>
<label class="label"><span class="label-text font-bold">Cash Received</span></label> <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" /> <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, isLoading: false,
user: { id: 0 }, user: { id: 0 },
userCardfound: false, userCardfound: false,
total_amount: 0,
preChargeTotal: 0, preChargeTotal: 0,
FinalizeOilOrderForm: { FinalizeOilOrderForm: {
cash_recieved: '', cash_recieved: '',
@@ -307,16 +322,33 @@ export default defineComponent({
same_day: 0, same_day: 0,
payment_type: 0, payment_type: 0,
payment_card_id: '', payment_card_id: '',
promo_id: null,
}, },
pricing: { pricing: {
price_prime: 0, price_prime: 0,
price_same_day: 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, transaction: null as any,
} }
}, },
computed: { computed: {
finalChargeAmount(): number { 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 gallons = Number(this.FinalizeOilOrderForm.gallons_delivered);
const pricePerGallon = Number(this.deliveryOrder.customer_price); const pricePerGallon = Number(this.deliveryOrder.customer_price);
if (isNaN(gallons) || isNaN(pricePerGallon) || gallons <= 0) { 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}`; const path = `${import.meta.env.VITE_BASE_URL}/delivery/order/${delivery_id}`;
// --- DEBUGGING STEP 2 --- // --- DEBUGGING STEP 2 ---
console.log(`[DEBUG] Calling getOilOrder API at: ${path}`); console.log(`[DEBUG] Calling getOilOrder API at: ${path}`);
try { try {
const response = await axios.get(path, { withCredentials: true, headers: authHeader() }); const response = await axios.get(path, { withCredentials: true, headers: authHeader() });
// --- DEBUGGING STEP 3 --- // --- DEBUGGING STEP 3 ---
@@ -349,10 +381,10 @@ export default defineComponent({
if (response.data && response.data.ok) { if (response.data && response.data.ok) {
console.log('[DEBUG] Response is OK. Processing data...'); console.log('[DEBUG] Response is OK. Processing data...');
this.deliveryOrder = response.data.delivery; this.deliveryOrder = response.data.delivery;
// --- DEBUGGING STEP 4 --- // --- DEBUGGING STEP 4 ---
console.log(`[DEBUG] Value of response.data.total_amount is:`, response.data.total_amount); console.log(`[DEBUG] Value of response.data.total_amount is:`, response.data.total_amount);
this.total_amount = response.data.delivery.total_amount || 0; this.total_amount = response.data.delivery.total_amount || 0;
this.preChargeTotal = response.data.delivery.total_amount || 0; this.preChargeTotal = response.data.delivery.total_amount || 0;
this.FinalizeOilOrderForm.gallons_delivered = this.deliveryOrder.gallons_delivered || ''; this.FinalizeOilOrderForm.gallons_delivered = this.deliveryOrder.gallons_delivered || '';
@@ -360,10 +392,17 @@ export default defineComponent({
await this.getCustomer(this.deliveryOrder.customer_id); 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); 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 // Call transaction fetch after customer is loaded
setTimeout(() => this.getTransaction(delivery_id), 500); setTimeout(() => this.getTransaction(delivery_id), 500);
} else { } else {
@@ -411,57 +450,95 @@ export default defineComponent({
.then((response: any) => { this.pricing = response.data; }) .then((response: any) => { this.pricing = response.data; })
.catch((error: any) => { console.error("[DEBUG] Error fetching oil pricing:", error); }); .catch((error: any) => { console.error("[DEBUG] Error fetching oil pricing:", error); });
}, },
getTransaction(delivery_id: any) { getPromo(promo_id: any) {
// Consistent with delivery/view.vue - use customer transaction endpoint let path = import.meta.env.VITE_BASE_URL + "/promo/" + promo_id;
if (this.customer && this.customer.id) { axios({
const path = `${import.meta.env.VITE_BASE_URL}/payment/transactions/customer/${this.customer.id}/1`; method: "get",
axios.get(path, { withCredentials: true, headers: authHeader() }) url: path,
.then((response: any) => { withCredentials: true,
console.log("Transaction API response:", response.data); headers: authHeader(),
// Handle both single transaction object and array responses })
if (response.data && Array.isArray(response.data) && response.data.length > 0) { .then((response: any) => {
// Find the transaction for this specific delivery if (response.data) {
const deliveryTransaction = response.data.find((txn: any) => this.promo = response.data
txn.delivery_id === parseInt(delivery_id) || this.promo_active = true
txn.transaction_id === delivery_id || }
txn.delivery_number === delivery_id })
); },
this.transaction = deliveryTransaction || null; sumdelivery(delivery_id: any) {
} else if (response.data && !Array.isArray(response.data)) { let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id;
// If single transaction, check if it's for this delivery axios({
const txn = response.data; method: "get",
if (txn.delivery_id === parseInt(delivery_id) || url: path,
txn.transaction_id === delivery_id || withCredentials: true,
txn.delivery_number === delivery_id) { })
this.transaction = txn; .then((response: any) => {
} else { if (response.data.ok) {
this.transaction = null; this.total_amount = parseFloat(response.data.total_amount) || 0;
} this.discount = parseFloat(response.data.discount) || 0;
} else { this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0;
this.transaction = null; }
} })
.catch(() => {
if (!this.transaction) { notify({
console.log(`No transaction found for delivery ${delivery_id} among customer transactions`); title: "Error",
} text: "Could not get oil pricing",
}) type: "error",
.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"); },
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) { getTypeColor(transactionType: number) {
switch (transactionType) { switch (transactionType) {
@@ -499,12 +576,12 @@ export default defineComponent({
this.CreateTransaction(); this.CreateTransaction();
notify({ title: "Success", text: "Ticket has been finalized.", type: "success" }); notify({ title: "Success", text: "Ticket has been finalized.", type: "success" });
// Redirect based on payment type - redirect to capture for credit card payments // FIX: Wait for customer data to be loaded before redirecting
if ([1, 2].includes(this.deliveryOrder.payment_type)) { await this.waitForCustomerData(this.deliveryOrder.customer_id);
this.$router.push({ name: "captureAuthorize", params: { id: this.deliveryOrder.id } });
} else { // Updated redirect logic based on your requirements
this.$router.push({ name: "deliveryOrder", params: { id: this.deliveryOrder.id } }); await this.handleRedirect();
}
} catch (error: any) { } catch (error: any) {
const errorMessage = error.response?.data?.detail || "An error occurred during finalization."; const errorMessage = error.response?.data?.detail || "An error occurred during finalization.";
notify({ title: "Error", text: errorMessage, type: "error" }); notify({ title: "Error", text: errorMessage, type: "error" });
@@ -512,6 +589,75 @@ export default defineComponent({
this.isLoading = false; 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> </script>
<style scoped></style>

View File

@@ -132,25 +132,44 @@
<!-- Pricing & Fees --> <!-- Pricing & Fees -->
<div class="p-4 border rounded-md space-y-2"> <div class="p-4 border rounded-md space-y-2">
<label class="label-text font-bold">Estimated Total</label> <label class="label-text font-bold">Estimated Total</label>
<!-- Finalized View --> <!-- Total Breakdown -->
<div v-if="deliveryOrder.promo_id !== null"> <div class="space-y-2">
<div>Before Discount: ${{ total_amount }}</div> <!-- Show breakdown only when promo is active -->
<div>Discount: -${{ discount }}</div> <div v-if="promo && promo.name_of_promotion">
<div class="font-bold">Subtotal: ${{ total_amount_after_discount }}</div> <!-- 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>
<div v-else class="font-bold text-lg">${{ total_amount }}</div> <!-- Final Charge Amount (always show) -->
<div v-if="deliveryOrder.prime == 1" class="text-sm text-gray-400">+ ${{ pricing.price_prime }} Prime Fee</div> <div class="flex justify-between items-center">
<div v-if="deliveryOrder.emergency == 1" class="text-sm text-gray-400">+ ${{ pricing.price_emergency }} Emergency Fee</div> <span class="text-lg font-bold">
<div v-if="deliveryOrder.same_day == 1" class="text-sm text-gray-400">+ ${{ pricing.price_same_day }} Same Day Fee</div> 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> </div>
<!-- Transaction Summary --> <!-- Transaction Summary -->
<div v-if="transaction && (transaction.transaction_type !== undefined || transaction.preauthorize_amount || transaction.charge_amount)" class="p-4 border rounded-md"> <div v-if="deliveryOrder.payment_type == 11" class="p-4 border rounded-md">
<label class="label-text font-bold">Transaction Summary</label> <label class="label-text font-bold">Authorize.net Transaction Details</label>
<div class="mt-2 space-y-2"> <div v-if="transaction" class="mt-2 space-y-2">
<div class="flex justify-between"> <div class="flex justify-between">
<span>Transaction ID:</span> <span class="font-bold">Transaction ID:</span>
<span class="font-mono">{{ transaction.auth_net_transaction_id }}</span> <span class="font-mono">{{ transaction.auth_net_transaction_id || 'N/A' }}</span>
</div> </div>
<div class="flex justify-between"> <div class="flex justify-between">
<span>Pre-Auth Amount:</span> <span>Pre-Auth Amount:</span>
@@ -162,7 +181,9 @@
</div> </div>
<div class="flex justify-between"> <div class="flex justify-between">
<span>Type:</span> <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>
<div class="flex justify-between"> <div class="flex justify-between">
<span>Date:</span> <span>Date:</span>
@@ -175,6 +196,17 @@
</span> </span>
</div> </div>
</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> </div>
<!-- Delivery Summary --> <!-- Delivery Summary -->
@@ -206,9 +238,20 @@
<span>+ ${{ pricing.price_emergency }}</span> <span>+ ${{ pricing.price_emergency }}</span>
</div> </div>
<hr class="my-2"> <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"> <div class="flex justify-between font-bold">
<span>Total:</span> <span>Total:</span>
<span>${{ calculateDeliveryTotal() }}</span> <span>${{ (promo && promo.name_of_promotion ? (parseFloat(calculateDeliveryTotal()) - discount).toFixed(2) : calculateDeliveryTotal()) }}</span>
</div> </div>
</div> </div>
</div> </div>
@@ -234,7 +277,8 @@
<div class="mt-1"> <div class="mt-1">
<div class="text-lg"> <div class="text-lg">
<span v-if="deliveryOrder.payment_type == 0">Cash</span> <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 == 2">Credit Card & Cash</span>
<span v-else-if="deliveryOrder.payment_type == 3">Check</span> <span v-else-if="deliveryOrder.payment_type == 3">Check</span>
<span v-else-if="deliveryOrder.payment_type == 4">Other</span> <span v-else-if="deliveryOrder.payment_type == 4">Other</span>
@@ -513,7 +557,7 @@ export default defineComponent({
.then((response: any) => { .then((response: any) => {
this.pricing = response.data; this.pricing = response.data;
}) })
.catch(() => { .catch((error: any) => {
notify({ notify({
title: "Error", title: "Error",
text: "Could not get oil pricing", text: "Could not get oil pricing",
@@ -522,26 +566,22 @@ export default defineComponent({
}); });
}, },
getCustomer(user_id: any) { getCustomer(user_id: any) {
return new Promise((resolve, reject) => { let path = import.meta.env.VITE_BASE_URL + "/customer/" + user_id;
let path = import.meta.env.VITE_BASE_URL + "/customer/" + user_id; axios({
axios({ method: "get",
method: "get", url: path,
url: path, withCredentials: true,
withCredentials: true, })
.then((response: any) => {
this.customer = response.data;
}) })
.then((response: any) => {
this.customer = response.data;
resolve(response.data);
})
.catch((error: any) => { .catch((error: any) => {
notify({ notify({
title: "Error", title: "Error",
text: "Could not find customer", text: "Could not find customer",
type: "error", type: "error",
}); });
reject(error);
}); });
});
}, },
getPaymentCard(card_id: any) { 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 if (!delivery_id) { // Add a guard to prevent calls with an undefined ID
console.error("getOilOrder called with no ID."); console.error("getOilOrder called with no ID.");
return; return;
} }
let path = import.meta.env.VITE_BASE_URL + "/delivery/" + delivery_id; let path = import.meta.env.VITE_BASE_URL + "/delivery/" + delivery_id;
try { axios({
const response = await axios({ method: "get",
method: "get", url: path,
url: path, withCredentials: true,
withCredentials: true, headers: authHeader(),
headers: authHeader(), })
}); .then((response: any) => {
// FIX: Check for the 'ok' flag and access the nested 'delivery' object // FIX: Check for the 'ok' flag and access the nested 'delivery' object
if (response.data && response.data.ok) { if (response.data && response.data.ok) {
this.deliveryOrder = response.data.delivery; // <-- THIS IS THE CRITICAL CHANGE 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. // 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)) { if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) {
this.getPaymentCard(this.deliveryOrder.payment_card_id); this.getPaymentCard(this.deliveryOrder.payment_card_id);
@@ -600,16 +639,19 @@ export default defineComponent({
this.getPromo(this.deliveryOrder.promo_id); this.getPromo(this.deliveryOrder.promo_id);
} }
// Now that customer is loaded, we can fetch transactions directly // Only fetch transactions for Authorize.net payments
this.getTransaction(delivery_id); if (this.deliveryOrder.payment_type == 11) {
this.getTransaction(delivery_id);
}
} 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.");
notify({ title: "Error", text: "Could not load delivery details.", type: "error" }); notify({ title: "Error", text: "Could not load delivery details.", type: "error" });
} }
} catch (error) { })
.catch((error: any) => {
console.error("Error fetching delivery order:", error); console.error("Error fetching delivery order:", error);
} });
}, },
getOilOrderMoney(delivery_id: any) { getOilOrderMoney(delivery_id: any) {
let path = import.meta.env.VITE_MONEY_URL + "/delivery/order/money/" + delivery_id; 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.priceprime = response.data.priceprime || 0;
this.pricesameday = response.data.pricesameday || 0; this.pricesameday = response.data.pricesameday || 0;
this.priceemergency = response.data.priceemergency || 0; this.priceemergency = response.data.priceemergency || 0;
this.total_amount = response.data.total_amount || 0; this.total_amount = parseFloat(response.data.total_amount) || 0;
this.discount = response.data.discount || 0; this.discount = parseFloat(response.data.discount) || 0;
this.total_amount_after_discount = response.data.total_amount_after_discount || 0; this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0;
} else { } else {
// Fallback calculation if API doesn't return expected data // Fallback calculation if API doesn't return expected data
this.calculateFallbackTotal(); this.calculateFallbackTotal();
@@ -690,9 +732,12 @@ export default defineComponent({
}) })
.then((response: any) => { .then((response: any) => {
if (response.data) { if (response.data) {
this.promo = response.data this.promo = response.data;
} }
}) })
.catch((error: any) => {
console.error('Error fetching promo:', error);
})
}, },
calculateDeliveryTotal() { calculateDeliveryTotal() {
@@ -716,59 +761,46 @@ export default defineComponent({
return total.toFixed(2); 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) { getTransaction(delivery_id: any) {
// Fix: Use customer transaction endpoint to get transactions for this delivery's customer // Simple endpoint to get transaction directly by delivery_id
// The API seems to work with customer-centric endpoints const path = `${import.meta.env.VITE_BASE_URL}/payment/transaction/delivery/${delivery_id}`;
if (this.customer && this.customer.id) { axios.get(path, {
const path = `${import.meta.env.VITE_BASE_URL}/payment/transactions/customer/${this.customer.id}/1`; withCredentials: true,
axios.get(path, { withCredentials: true, headers: authHeader() }) headers: authHeader()
.then((response: any) => { }).then((response: any) => {
console.log("Transaction API response:", response.data); // Debug log to see actual response structure if (response.data.ok) {
// Handle both single transaction object and array responses this.transaction = response.data.transaction;
if (response.data && Array.isArray(response.data) && response.data.length > 0) { console.log("Transaction loaded:", this.transaction);
// Find the transaction for this specific delivery } else {
const deliveryTransaction = response.data.find((txn: any) => console.log("No transaction found for delivery:", delivery_id);
txn.delivery_id === parseInt(delivery_id) || this.transaction = null;
txn.transaction_id === delivery_id || }
txn.delivery_number === delivery_id }).catch((error: any) => {
); console.error("Error fetching transaction:", error);
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");
this.transaction = null; this.transaction = null;
} });
}, },
}, },
}) })

View File

@@ -315,9 +315,9 @@ export default defineComponent({
}) })
.then((response: any) => { .then((response: any) => {
if (response.data.ok) { if (response.data.ok) {
this.total_amount = response.data.total_amount; this.total_amount = parseFloat(response.data.total_amount) || 0;
this.discount = response.data.discount; this.discount = parseFloat(response.data.discount) || 0;
this.total_amount_after_discount = response.data.total_amount_after_discount; this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0;
// Auto-populate charge amount with the calculated total // Auto-populate charge amount with the calculated total
if (this.promo_active) { if (this.promo_active) {
@@ -513,8 +513,8 @@ export default defineComponent({
const response = await axios.post(chargePath, chargePayload, { withCredentials: true, headers: authHeader() }); const response = await axios.post(chargePath, chargePayload, { withCredentials: true, headers: authHeader() });
// Assuming your backend charge response has the same structure // Status codes: 0 = APPROVED, 1 = DECLINED (based on backend TransactionStatus enum)
if (response.data && response.data.status === 'APPROVED') { // Adjust based on your actual response if (response.data && response.data.status === 0) { // 0 = APPROVED
this.success = `Charge successful! Transaction ID: ${response.data.auth_net_transaction_id || 'N/A'}`; this.success = `Charge successful! Transaction ID: ${response.data.auth_net_transaction_id || 'N/A'}`;
setTimeout(() => { setTimeout(() => {
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } }); this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
@@ -525,6 +525,7 @@ export default defineComponent({
} }
} }
} catch (error: any) { } catch (error: any) {
console.log(error)
this.error = error.response?.data?.detail || `Failed to ${actionType} payment` this.error = error.response?.data?.detail || `Failed to ${actionType} payment`
notify({ notify({
title: "Error", title: "Error",

View File

@@ -339,8 +339,7 @@ export default defineComponent({
}) })
.then((response: any) => { .then((response: any) => {
if (response.data.ok) { if (response.data.ok) {
console.log('%%%%%%%%%%%%%%%')
console.log(response.data)
this.priceprime = response.data.priceprime; this.priceprime = response.data.priceprime;
this.pricesameday = response.data.pricesameday; this.pricesameday = response.data.pricesameday;
@@ -348,7 +347,7 @@ export default defineComponent({
this.total_amount = response.data.total_amount; this.total_amount = response.data.total_amount;
this.discount = response.data.discount; this.discount = response.data.discount;
this.total_amount_after_discount = response.data.total_amount_after_discount; this.total_amount_after_discount = response.data.total_amount_after_discount;
console.log('%%%%%%%%%%%%%%%')
} }
}) })
.catch(() => { .catch(() => {
@@ -408,7 +407,6 @@ export default defineComponent({
}); });
}, },
getOilOrder(delivery_id: any) { 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; let path = import.meta.env.VITE_BASE_URL + "/delivery/order/" + delivery_id;
axios({ axios({
method: "get", method: "get",
@@ -500,6 +498,13 @@ export default defineComponent({
type: "success", 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 } }); this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
} }
}) })