fix tax and tip not showing yay
This commit is contained in:
parent
5fe178ade3
commit
48996f4d84
2 changed files with 80 additions and 11 deletions
|
@ -123,8 +123,8 @@ const normalizeFormData = (data: EventRequestFormData | (EventRequest & {
|
||||||
...(parsed as any),
|
...(parsed as any),
|
||||||
items: Array.isArray((parsed as any).items) ? (parsed as any).items : [],
|
items: Array.isArray((parsed as any).items) ? (parsed as any).items : [],
|
||||||
// Normalize tax/tip fields
|
// Normalize tax/tip fields
|
||||||
taxAmount: parseFloat(parsed.taxAmount || parsed.tax || 0),
|
taxAmount: Number(parsed.taxAmount ?? parsed.tax ?? 0),
|
||||||
tipAmount: parseFloat(parsed.tipAmount || parsed.tip || 0)
|
tipAmount: Number(parsed.tipAmount ?? parsed.tip ?? 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normalize item property names
|
// Normalize item property names
|
||||||
|
@ -153,8 +153,8 @@ const normalizeFormData = (data: EventRequestFormData | (EventRequest & {
|
||||||
...parsed,
|
...parsed,
|
||||||
items: Array.isArray(parsed.items) ? parsed.items : [],
|
items: Array.isArray(parsed.items) ? parsed.items : [],
|
||||||
// Normalize tax/tip fields
|
// Normalize tax/tip fields
|
||||||
taxAmount: parseFloat(parsed.taxAmount || parsed.tax || 0),
|
taxAmount: Number(parsed.taxAmount ?? parsed.tax ?? 0),
|
||||||
tipAmount: parseFloat(parsed.tipAmount || parsed.tip || 0)
|
tipAmount: Number(parsed.tipAmount ?? parsed.tip ?? 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normalize item property names
|
// Normalize item property names
|
||||||
|
@ -180,8 +180,8 @@ const normalizeFormData = (data: EventRequestFormData | (EventRequest & {
|
||||||
...parsed,
|
...parsed,
|
||||||
items: Array.isArray(parsed.items) ? parsed.items : [],
|
items: Array.isArray(parsed.items) ? parsed.items : [],
|
||||||
// Normalize tax/tip fields
|
// Normalize tax/tip fields
|
||||||
taxAmount: parseFloat(parsed.taxAmount || parsed.tax || 0),
|
taxAmount: Number(parsed.taxAmount ?? parsed.tax ?? 0),
|
||||||
tipAmount: parseFloat(parsed.tipAmount || parsed.tip || 0)
|
tipAmount: Number(parsed.tipAmount ?? parsed.tip ?? 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normalize item property names
|
// Normalize item property names
|
||||||
|
@ -775,11 +775,11 @@ const EventRequestFormPreview: React.FC<EventRequestFormPreviewProps> = ({
|
||||||
</tr>
|
</tr>
|
||||||
<tr className="border-t border-base-300">
|
<tr className="border-t border-base-300">
|
||||||
<td colSpan={3} className="py-2 text-right font-medium text-base-content">Tax:</td>
|
<td colSpan={3} className="py-2 text-right font-medium text-base-content">Tax:</td>
|
||||||
<td className="py-2 text-right font-medium text-base-content">${(typeof formData.invoiceData.taxAmount === 'number' ? formData.invoiceData.taxAmount : 0).toFixed(2)}</td>
|
<td className="py-2 text-right font-medium text-base-content">${(formData.invoiceData.taxAmount || 0).toFixed(2)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr className="border-t border-base-300">
|
<tr className="border-t border-base-300">
|
||||||
<td colSpan={3} className="py-2 text-right font-medium text-base-content">Tip:</td>
|
<td colSpan={3} className="py-2 text-right font-medium text-base-content">Tip:</td>
|
||||||
<td className="py-2 text-right font-medium text-base-content">${(typeof formData.invoiceData.tipAmount === 'number' ? formData.invoiceData.tipAmount : 0).toFixed(2)}</td>
|
<td className="py-2 text-right font-medium text-base-content">${(formData.invoiceData.tipAmount || 0).toFixed(2)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr className="bg-primary/5">
|
<tr className="bg-primary/5">
|
||||||
<td colSpan={3} className="py-2 text-right font-bold text-primary">Total:</td>
|
<td colSpan={3} className="py-2 text-right font-bold text-primary">Total:</td>
|
||||||
|
|
|
@ -27,12 +27,81 @@ const convertToFormData = (request: EventRequest): EventRequestFormData => {
|
||||||
try {
|
try {
|
||||||
if (request.itemized_invoice) {
|
if (request.itemized_invoice) {
|
||||||
if (typeof request.itemized_invoice === 'string') {
|
if (typeof request.itemized_invoice === 'string') {
|
||||||
invoiceData = JSON.parse(request.itemized_invoice);
|
const parsedInvoice = JSON.parse(request.itemized_invoice) as Record<string, any>;
|
||||||
|
|
||||||
|
// Get or calculate subtotal from items
|
||||||
|
const subtotal = parsedInvoice.subtotal ??
|
||||||
|
(Array.isArray(parsedInvoice.items) ?
|
||||||
|
parsedInvoice.items.reduce((sum: number, item: any) => {
|
||||||
|
const amount = typeof item.amount === 'number' ? item.amount : 0;
|
||||||
|
return sum + amount;
|
||||||
|
}, 0) : 0);
|
||||||
|
|
||||||
|
// Normalize tax and tip amounts
|
||||||
|
const taxAmount = Number(parsedInvoice.taxAmount ?? parsedInvoice.tax ?? 0);
|
||||||
|
const tipAmount = Number(parsedInvoice.tipAmount ?? parsedInvoice.tip ?? 0);
|
||||||
|
|
||||||
|
// Calculate or get total
|
||||||
|
const total = parsedInvoice.total ?? (subtotal + taxAmount + tipAmount);
|
||||||
|
|
||||||
|
invoiceData = {
|
||||||
|
...parsedInvoice,
|
||||||
|
subtotal,
|
||||||
|
taxAmount,
|
||||||
|
tipAmount,
|
||||||
|
total
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
invoiceData = request.itemized_invoice;
|
const parsedInvoice = request.itemized_invoice as Record<string, any>;
|
||||||
|
|
||||||
|
// Get or calculate subtotal from items
|
||||||
|
const subtotal = parsedInvoice.subtotal ??
|
||||||
|
(Array.isArray(parsedInvoice.items) ?
|
||||||
|
parsedInvoice.items.reduce((sum: number, item: any) => {
|
||||||
|
const amount = typeof item.amount === 'number' ? item.amount : 0;
|
||||||
|
return sum + amount;
|
||||||
|
}, 0) : 0);
|
||||||
|
|
||||||
|
// Normalize tax and tip amounts
|
||||||
|
const taxAmount = Number(parsedInvoice.taxAmount ?? parsedInvoice.tax ?? 0);
|
||||||
|
const tipAmount = Number(parsedInvoice.tipAmount ?? parsedInvoice.tip ?? 0);
|
||||||
|
|
||||||
|
// Calculate or get total
|
||||||
|
const total = parsedInvoice.total ?? (subtotal + taxAmount + tipAmount);
|
||||||
|
|
||||||
|
invoiceData = {
|
||||||
|
...parsedInvoice,
|
||||||
|
subtotal,
|
||||||
|
taxAmount,
|
||||||
|
tipAmount,
|
||||||
|
total
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} else if (request.invoice_data) {
|
} else if (request.invoice_data) {
|
||||||
invoiceData = request.invoice_data;
|
const parsedInvoice = request.invoice_data as Record<string, any>;
|
||||||
|
|
||||||
|
// Get or calculate subtotal from items
|
||||||
|
const subtotal = parsedInvoice.subtotal ??
|
||||||
|
(Array.isArray(parsedInvoice.items) ?
|
||||||
|
parsedInvoice.items.reduce((sum: number, item: any) => {
|
||||||
|
const amount = typeof item.amount === 'number' ? item.amount : 0;
|
||||||
|
return sum + amount;
|
||||||
|
}, 0) : 0);
|
||||||
|
|
||||||
|
// Normalize tax and tip amounts
|
||||||
|
const taxAmount = Number(parsedInvoice.taxAmount ?? parsedInvoice.tax ?? 0);
|
||||||
|
const tipAmount = Number(parsedInvoice.tipAmount ?? parsedInvoice.tip ?? 0);
|
||||||
|
|
||||||
|
// Calculate or get total
|
||||||
|
const total = parsedInvoice.total ?? (subtotal + taxAmount + tipAmount);
|
||||||
|
|
||||||
|
invoiceData = {
|
||||||
|
...parsedInvoice,
|
||||||
|
subtotal,
|
||||||
|
taxAmount,
|
||||||
|
tipAmount,
|
||||||
|
total
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error parsing invoice data:', e);
|
console.error('Error parsing invoice data:', e);
|
||||||
|
|
Loading…
Reference in a new issue