@ticketboothapp/booking 1.2.147 → 1.2.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -43,6 +43,15 @@ function hasTaxLine(lines: PriceSummaryLine[]): boolean {
|
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
function amendmentLineOrder(line: PriceSummaryLine): number {
|
|
47
|
+
if (line.kind === 'ticket') return 0;
|
|
48
|
+
const type = String(line.type ?? '').toUpperCase();
|
|
49
|
+
if (type === 'TICKET') return 0;
|
|
50
|
+
if (type === 'RETURN_OPTION' || type === 'CANCELLATION_UPGRADE') return 1;
|
|
51
|
+
if (type === 'FEE' || type === 'ADD_ON') return 2;
|
|
52
|
+
return 3;
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
export function AdminChangeReceiptComparison({
|
|
47
56
|
originalReceipt,
|
|
48
57
|
amendmentLines,
|
|
@@ -61,6 +70,39 @@ export function AdminChangeReceiptComparison({
|
|
|
61
70
|
const existingLines = originalLines(originalReceipt);
|
|
62
71
|
const originalCurrency = originalReceipt.currency ?? currency;
|
|
63
72
|
const quoteReady = amendmentLines != null && amountDue != null && updatedTotal != null;
|
|
73
|
+
const amendmentTax = amendmentLines?.reduce(
|
|
74
|
+
(sum, line) =>
|
|
75
|
+
line.kind === 'line' && String(line.type ?? '').toUpperCase() === 'TAX'
|
|
76
|
+
? sum + line.amount
|
|
77
|
+
: sum,
|
|
78
|
+
0,
|
|
79
|
+
) ?? 0;
|
|
80
|
+
const amendmentNonTaxLines = amendmentLines
|
|
81
|
+
? amendmentLines
|
|
82
|
+
.filter(
|
|
83
|
+
(line) => line.kind !== 'line' || String(line.type ?? '').toUpperCase() !== 'TAX',
|
|
84
|
+
)
|
|
85
|
+
.map((line, index) => ({ line, index }))
|
|
86
|
+
.sort((a, b) => amendmentLineOrder(a.line) - amendmentLineOrder(b.line) || a.index - b.index)
|
|
87
|
+
.map(({ line }) => line)
|
|
88
|
+
: [];
|
|
89
|
+
const amendmentSubtotal = amendmentNonTaxLines.reduce(
|
|
90
|
+
(sum, line) => sum + (line.kind === 'ticket' ? line.itemTotal : line.amount),
|
|
91
|
+
0,
|
|
92
|
+
);
|
|
93
|
+
const amendmentDisplayLines: PriceSummaryLine[] = amendmentLines
|
|
94
|
+
? [
|
|
95
|
+
...amendmentNonTaxLines,
|
|
96
|
+
...(Math.abs(amendmentTax) >= 0.005
|
|
97
|
+
? [{
|
|
98
|
+
kind: 'line' as const,
|
|
99
|
+
label: amendmentTax < 0 ? 'Refunded tax' : 'Additional tax',
|
|
100
|
+
amount: amendmentTax,
|
|
101
|
+
type: 'TAX',
|
|
102
|
+
}]
|
|
103
|
+
: []),
|
|
104
|
+
]
|
|
105
|
+
: [];
|
|
64
106
|
const amountDueClass =
|
|
65
107
|
amountDue != null && amountDue < -0.005
|
|
66
108
|
? 'text-emerald-700'
|
|
@@ -114,16 +156,17 @@ export function AdminChangeReceiptComparison({
|
|
|
114
156
|
<div className="rounded-md border border-dashed border-stone-300 bg-white/70 px-3 py-4 text-center">
|
|
115
157
|
<p className="text-sm font-medium text-stone-700">Waiting for server price…</p>
|
|
116
158
|
</div>
|
|
117
|
-
) :
|
|
159
|
+
) : amendmentDisplayLines.length === 0 && Math.abs(amountDue) < 0.005 ? (
|
|
118
160
|
<div className="rounded-md border border-dashed border-stone-300 bg-white/70 px-3 py-4 text-center">
|
|
119
161
|
<p className="text-sm font-medium text-stone-700">No pricing changes</p>
|
|
120
162
|
</div>
|
|
121
163
|
) : (
|
|
122
164
|
<PriceSummary
|
|
123
|
-
lines={
|
|
165
|
+
lines={amendmentDisplayLines}
|
|
124
166
|
total={amountDue}
|
|
125
167
|
currency={currency}
|
|
126
168
|
locale={displayLocale}
|
|
169
|
+
subtotal={amendmentSubtotal}
|
|
127
170
|
size="sm"
|
|
128
171
|
t={t}
|
|
129
172
|
/>
|
|
@@ -132,6 +132,19 @@ function breakdownFromPriceBasis(priceBasis: PriceBasisSnapshot | null | undefin
|
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
function finalUnitOnlyBreakdown(itemTotal: number, quantity: number) {
|
|
136
|
+
const finalUnitAmount = quantity > 0 ? roundMoney(itemTotal / quantity) : roundMoney(itemTotal);
|
|
137
|
+
return {
|
|
138
|
+
lineItems: [],
|
|
139
|
+
subtotalAfterAdjustments: finalUnitAmount,
|
|
140
|
+
feeLines: [],
|
|
141
|
+
taxRate: 0,
|
|
142
|
+
taxAmount: 0,
|
|
143
|
+
isTaxIncluded: false,
|
|
144
|
+
finalPrice: finalUnitAmount,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
135
148
|
function hasPaymentCreditLine(lines: PriceSummaryLine[]): boolean {
|
|
136
149
|
return lines.some((line) => {
|
|
137
150
|
if (line.kind !== 'line') return false;
|
|
@@ -193,7 +206,8 @@ export function mapQuoteLineItemsToPriceSummaryLines(
|
|
|
193
206
|
category,
|
|
194
207
|
qty: qty > 0 ? qty : 1,
|
|
195
208
|
itemTotal: amount,
|
|
196
|
-
breakdown:
|
|
209
|
+
breakdown:
|
|
210
|
+
breakdownFromPriceBasis(item.priceBasis) ?? finalUnitOnlyBreakdown(amount, qty > 0 ? qty : 1),
|
|
197
211
|
});
|
|
198
212
|
continue;
|
|
199
213
|
}
|
|
@@ -213,7 +227,8 @@ export function mapQuoteLineItemsToPriceSummaryLines(
|
|
|
213
227
|
category: lettersOnly,
|
|
214
228
|
qty,
|
|
215
229
|
itemTotal: amount,
|
|
216
|
-
breakdown:
|
|
230
|
+
breakdown:
|
|
231
|
+
breakdownFromPriceBasis(item.priceBasis) ?? finalUnitOnlyBreakdown(amount, qty),
|
|
217
232
|
});
|
|
218
233
|
continue;
|
|
219
234
|
}
|