@revenexx/cover 0.2.40 → 0.2.42

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.
@@ -246,6 +246,7 @@
246
246
  "directOrder": { "title": "Quick entry", "description": "Enter article numbers directly" },
247
247
  "orderLists": { "description": "Recurring requirements" },
248
248
  "orders": { "description": "Status & reordering" },
249
+ "quotes": { "description": "Review and order your quotes" },
249
250
  "cart": { "description": "Go to checkout" },
250
251
  "dashboard": { "description": "Your account at a glance" },
251
252
  "carts": { "description": "Saved shopping carts" },
@@ -566,5 +567,99 @@
566
567
  "title": "No users",
567
568
  "description": "Invite the first user via “Invite user”."
568
569
  }
570
+ },
571
+ "quotes": {
572
+ "title": "Quotes",
573
+ "description": "Your quotation requests and the quotes we made you for them.",
574
+ "searchPlaceholder": "Search quote number",
575
+ "errorTitle": "Quotes could not be loaded",
576
+ "errorDescription": "Please try again later.",
577
+ "notFound": "This quote does not exist (any more).",
578
+ "shippingPending": "Carriage being priced",
579
+ "filter": {
580
+ "waiting": "Waiting on you"
581
+ },
582
+ "columns": {
583
+ "number": "Quote",
584
+ "date": "Requested",
585
+ "status": "Status",
586
+ "validUntil": "Valid until",
587
+ "total": "Total (net)"
588
+ },
589
+ "status": {
590
+ "requested": "Requested",
591
+ "in_review": "In review",
592
+ "quoted": "Quote ready",
593
+ "partially_accepted": "Partly ordered",
594
+ "accepted": "Ordered",
595
+ "declined": "Declined",
596
+ "rejected": "Not quoted",
597
+ "expired": "Expired"
598
+ },
599
+ "empty": {
600
+ "title": "No quotes yet",
601
+ "description": "When a cart cannot be ordered directly – for example because the consignment exceeds parcel dimensions – you can request a quote from the cart."
602
+ },
603
+ "actions": {
604
+ "review": "Review & order",
605
+ "open": "Open",
606
+ "order": "Order at the quoted price ({total})",
607
+ "decline": "Decline quote"
608
+ },
609
+ "detail": {
610
+ "requestedAt": "Requested",
611
+ "validUntil": "Valid until",
612
+ "total": "Total (net)",
613
+ "positions": "Positions",
614
+ "goods": "Goods",
615
+ "carriage": "Carriage",
616
+ "totalNet": "Total (net)",
617
+ "taxHint": "Plus statutory VAT. The order shows the tax.",
618
+ "shippingAddress": "Shipping address",
619
+ "billingAddress": "Billing address",
620
+ "buyerNote": "Your message",
621
+ "sellerNote": "Our message",
622
+ "trail": "History",
623
+ "onRequest": "on request",
624
+ "hint": {
625
+ "ready": "Your quote is ready. You can order it on these terms until {date}.",
626
+ "pending": "We are pricing the carriage for your consignment and will email you as soon as the quote is ready.",
627
+ "expired": "This quote has expired. Request a new one if you still need it.",
628
+ "rejected": "We cannot make an offer for this: {reason}",
629
+ "ordered": "This quote has been ordered."
630
+ }
631
+ },
632
+ "trail": {
633
+ "requested": "Requested",
634
+ "quoted": "Quote issued",
635
+ "accepted": "Accepted",
636
+ "partially_accepted": "Partly accepted",
637
+ "declined": "Declined",
638
+ "rejected": "Not quoted",
639
+ "ordered": "Ordered",
640
+ "expired": "Expired",
641
+ "note": "Message"
642
+ },
643
+ "order": {
644
+ "title": "Order quote {number}",
645
+ "intro": "You order every position at the quoted prices including carriage – {total} net in total, to the shipping address on the quote. Payment is by invoice.",
646
+ "customerOrderNumber": "Your order number (optional)",
647
+ "customerOrderNumberPlaceholder": "e.g. PO-2026-0815",
648
+ "note": "Note for the order (optional)",
649
+ "terms": "Our terms and conditions apply to your order.",
650
+ "cancel": "Cancel",
651
+ "submit": "Place binding order",
652
+ "success": "Order {number} placed",
653
+ "failed": "Order failed"
654
+ },
655
+ "decline": {
656
+ "title": "Decline quote",
657
+ "reason": "Why? (optional)",
658
+ "reasonPlaceholder": "Helps us make you a better offer next time.",
659
+ "cancel": "Cancel",
660
+ "submit": "Decline",
661
+ "success": "Quote declined",
662
+ "failed": "Declining failed"
663
+ }
569
664
  }
570
665
  }
@@ -215,6 +215,27 @@
215
215
  "delivery": "Ordered by 4 pm – delivered the next business day",
216
216
  "invoice": "Buy on invoice for business customers",
217
217
  "support": "Personal service team, weekdays 8 am–5 pm"
218
+ },
219
+ "quote": {
220
+ "action": "Request a quote",
221
+ "ctaHint": "Shipping on request – we price the carriage, you order from your account afterwards.",
222
+ "title": "Request a quote",
223
+ "description": "We price the carriage for your consignment and send you a quote.",
224
+ "shippingAddress": "Shipping address",
225
+ "shippingAddressHint": "The carriage is priced for this address",
226
+ "billingAddress": "Billing address",
227
+ "note": "Message to us (optional)",
228
+ "notePlaceholder": "e.g. preferred delivery date, tail-lift delivery …",
229
+ "steps": {
230
+ "price": "We price the carriage and make you a quote.",
231
+ "notify": "You receive an email as soon as the quote is ready.",
232
+ "order": "You order it with one click under “Quotes” in your account."
233
+ },
234
+ "cancel": "Cancel",
235
+ "submit": "Request quote",
236
+ "success": "Request {number} received",
237
+ "successDescription": "Your cart was moved into the request.",
238
+ "failed": "Request failed"
218
239
  }
219
240
  },
220
241
  "calc": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.40",
3
+ "version": "0.2.42",
4
4
  "description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -0,0 +1,39 @@
1
+ /** The buyer says no to a quote — every position still open is declined with it. */
2
+ export default defineEventHandler(async (event): Promise<{ ok: true }> => {
3
+ const id = getRouterParam(event, "id") ?? "";
4
+ const body = await readBody<{ reason?: string }>(event).catch(() => ({} as { reason?: string }));
5
+ const actor = await quoteActor(event);
6
+ if (!actor.user) {
7
+ throw createError({ statusCode: 401, message: "Unauthorized" });
8
+ }
9
+ const quote = await loadOwnQuote(event, id, actor);
10
+ if (!mapQuote(quote).canDecline) {
11
+ throw createError({ statusCode: 422, message: "This quote can no longer be declined" });
12
+ }
13
+
14
+ if (resolveQuotesServiceKey(event) === "api") {
15
+ try {
16
+ await liveQuoteDecline(id, body?.reason?.trim() || undefined);
17
+ }
18
+ catch (err) {
19
+ if (err instanceof RevenexxException && (err.code === 409 || err.code === 422)) {
20
+ throw createError({ statusCode: 422, message: err.message });
21
+ }
22
+ getLogService().error("Quote decline failed", apiErrorContext(err));
23
+ throw createError({ statusCode: 502, message: "Quote service unavailable" });
24
+ }
25
+ return { ok: true };
26
+ }
27
+
28
+ const quotes = await readMockQuotes();
29
+ const now = new Date().toISOString();
30
+ await writeMockQuotes(quotes.map(q => q.id !== id
31
+ ? q
32
+ : {
33
+ ...q,
34
+ status: "declined",
35
+ items: (q.items ?? []).map(i => (i.decision === "open" ? { ...i, decision: "declined" } : i)),
36
+ events: [...(q.events ?? []), { kind: "declined", actor: "buyer", body: body?.reason ?? null, visibility: "customer", created_at: now }],
37
+ }));
38
+ return { ok: true };
39
+ });
@@ -0,0 +1,153 @@
1
+ import { OrderPaymentStatus } from "@revenexx/sdk";
2
+ import type { Models } from "@revenexx/sdk";
3
+
4
+ import type { QuoteOrderPayload, QuoteOrderResult } from "../../../../../app/interfaces/account/quotes";
5
+
6
+ /**
7
+ * Order a quote at the quoted figures (RX-783).
8
+ *
9
+ * The quotes app answers acceptance with a draft; it never places the order
10
+ * itself, so this route does what the checkout does for a cart — with the
11
+ * difference that nothing is re-priced. The negotiated price arrives as each
12
+ * line's unit price and the quoted carriage as the shipping line, to the
13
+ * addresses the carriage was priced for. The order records which quote it came
14
+ * out of, and the quote records which order took it.
15
+ *
16
+ * No promotions are evaluated: a quote is already the negotiated price, and
17
+ * stacking a campaign on top of it is a decision the merchant makes in the
18
+ * price, not one the storefront makes afterwards.
19
+ */
20
+ function toIsoCountry(value: unknown): string {
21
+ const raw = String(value ?? "").trim();
22
+ if (/^[A-Za-z]{2}$/.test(raw)) {
23
+ return raw.toUpperCase();
24
+ }
25
+ const names: Record<string, string> = { deutschland: "DE", germany: "DE", österreich: "AT", austria: "AT", schweiz: "CH", switzerland: "CH" };
26
+ return names[raw.toLowerCase()] ?? raw;
27
+ }
28
+
29
+ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
30
+ const id = getRouterParam(event, "id") ?? "";
31
+ const body = await readBody<QuoteOrderPayload>(event).catch(() => ({} as QuoteOrderPayload));
32
+ const actor = await quoteActor(event);
33
+ if (!actor.user) {
34
+ throw createError({ statusCode: 401, message: "Unauthorized" });
35
+ }
36
+
37
+ const quote = await loadOwnQuote(event, id, actor);
38
+ const view = mapQuote(quote);
39
+ if (!view.canOrder) {
40
+ throw createError({
41
+ statusCode: 422,
42
+ message: view.expired ? "This quote has expired" : "This quote cannot be ordered",
43
+ });
44
+ }
45
+
46
+ const config = useAppConfig() as { quotes?: { paymentMethod?: string } };
47
+ const paymentMethod = config.quotes?.paymentMethod ?? "invoice";
48
+
49
+ /* ---- demo ------------------------------------------------------------ */
50
+ if (resolveQuotesServiceKey(event) !== "api") {
51
+ const quotes = await readMockQuotes();
52
+ const now = new Date().toISOString();
53
+ const orderNumber = `ORD-${Date.now()}`;
54
+ await writeMockQuotes(quotes.map(q => q.id !== id
55
+ ? q
56
+ : {
57
+ ...q,
58
+ status: "accepted",
59
+ items: (q.items ?? []).map(i => (i.decision === "open" ? { ...i, decision: "accepted", order_id: orderNumber } : i)),
60
+ events: [...(q.events ?? []), { kind: "ordered", actor: "buyer", body: null, visibility: "customer", created_at: now }],
61
+ }));
62
+ return { orderId: orderNumber, orderNumber };
63
+ }
64
+
65
+ /* ---- live ------------------------------------------------------------ */
66
+ const sdk = useRevenexxSdk();
67
+ let draft;
68
+ try {
69
+ draft = (await liveQuoteAccept(id)).order_draft;
70
+ }
71
+ catch (err) {
72
+ if (err instanceof RevenexxException && [403, 409, 422].includes(err.code)) {
73
+ throw createError({ statusCode: 422, message: err.message });
74
+ }
75
+ getLogService().error("Quote acceptance failed", apiErrorContext(err));
76
+ throw createError({ statusCode: 502, message: "Quote service unavailable" });
77
+ }
78
+
79
+ let placed: { id: string; number: string; grand_total?: number };
80
+ try {
81
+ placed = await sdk.orders.ordersPlace({
82
+ contactId: draft.contact_id ?? actor.contactId,
83
+ organizationId: draft.organization_id ?? actor.organizationId,
84
+ currency: draft.currency,
85
+ ...(body?.customerOrderNumber?.trim() ? { customerOrderNumber: body.customerOrderNumber.trim() } : {}),
86
+ buyer: (draft.buyer ?? { name: actor.user.name, email: actor.user.email }) as object,
87
+ billingAddress: (draft.billing_address ?? null) as object,
88
+ shippingAddress: (draft.shipping_address ?? null) as object,
89
+ payment: { method: paymentMethod },
90
+ // The carriage the merchant quoted — or none, when they quoted the
91
+ // goods alone. Taxed by order management at the quoted rate.
92
+ shipping: draft.shipping ?? { method: "quote", price: 0, tax_rate: 0 },
93
+ items: draft.items.map(line => ({
94
+ ...(line.product_id ? { product_id: line.product_id } : {}),
95
+ ...(line.sku ? { sku: line.sku } : {}),
96
+ name: line.name,
97
+ quantity: line.quantity,
98
+ unit_price: line.unit_price,
99
+ tax_rate: line.tax_rate ?? 0,
100
+ })) as unknown as Models.OrderItemCreateRequest[],
101
+ metadata: { quote_id: quote.id, quote_number: quote.number },
102
+ userData: {
103
+ quote_number: quote.number,
104
+ ...(body?.orderNote?.trim() ? { order_note: body.orderNote.trim() } : {}),
105
+ },
106
+ }) as unknown as { id: string; number: string; grand_total?: number };
107
+ }
108
+ catch (err) {
109
+ // The quote is accepted and no order exists. Say so in the log with
110
+ // the quote number: the merchant sees an accepted quote without an
111
+ // order and can place it by hand, which beats a buyer retrying into a
112
+ // second acceptance of a quote that has nothing left open.
113
+ getLogService().error(`Order placement for quote ${quote.number} failed after acceptance`, apiErrorContext(err));
114
+ if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
115
+ throw createError({ statusCode: 422, message: err.message });
116
+ }
117
+ throw createError({ statusCode: 502, message: "Order service unavailable" });
118
+ }
119
+
120
+ if (resolvePaymentServiceKey(event) === "api") {
121
+ try {
122
+ const payment = await sdk.call<{ id: string; status: string }>("POST", "/v1/payments", {
123
+ body: {
124
+ method_code: paymentMethod,
125
+ amount: Math.max(0, Math.round((placed.grand_total ?? view.grandTotal) * 100) / 100),
126
+ currency: draft.currency,
127
+ country: toIsoCountry(draft.billing_address?.country ?? draft.shipping_address?.country),
128
+ order_ref: placed.number,
129
+ idempotency_key: `quote-${quote.id}-${placed.id}`,
130
+ metadata: { quote_number: quote.number },
131
+ },
132
+ });
133
+ const mapped = ["captured", "succeeded", "paid"].includes(payment.status)
134
+ ? OrderPaymentStatus.Paid
135
+ : payment.status === "authorized" ? OrderPaymentStatus.Authorized : OrderPaymentStatus.Pending;
136
+ await sdk.orders.ordersPaymentStatusUpdate({ id: placed.id, status: mapped });
137
+ }
138
+ catch (err) {
139
+ // An invoice order stands without a captured payment; the payment
140
+ // record is bookkeeping here, not the gate it is at checkout.
141
+ getLogService().error(`Payment for quote order ${placed.number} failed`, apiErrorContext(err));
142
+ }
143
+ }
144
+
145
+ try {
146
+ await liveQuoteOrdered(id, placed.id);
147
+ }
148
+ catch (err) {
149
+ getLogService().error(`Writing order ${placed.number} back to quote ${quote.number} failed`, apiErrorContext(err));
150
+ }
151
+
152
+ return { orderId: placed.id, orderNumber: placed.number };
153
+ });
@@ -0,0 +1,11 @@
1
+ import type { AccountQuote } from "../../../../app/interfaces/account/quotes";
2
+
3
+ /** One quote as its buyer reads it: positions, carriage, addresses, the customer's trail. */
4
+ export default defineEventHandler(async (event): Promise<AccountQuote> => {
5
+ const id = getRouterParam(event, "id") ?? "";
6
+ const actor = await quoteActor(event);
7
+ if (!actor.user) {
8
+ throw createError({ statusCode: 401, message: "Unauthorized" });
9
+ }
10
+ return mapQuote(await loadOwnQuote(event, id, actor));
11
+ });
@@ -0,0 +1,26 @@
1
+ import type { AccountQuoteListResponse } from "../../../app/interfaces/account/quotes";
2
+
3
+ /** The buyer's quotes, newest first — their organisation's, as the quotes app accepts by organisation. */
4
+ export default defineEventHandler(async (event): Promise<AccountQuoteListResponse> => {
5
+ const actor = await quoteActor(event);
6
+ if (!actor.user) {
7
+ throw createError({ statusCode: 401, message: "Unauthorized" });
8
+ }
9
+
10
+ if (resolveQuotesServiceKey(event) === "api") {
11
+ try {
12
+ const rows = await liveQuoteList(actor.organizationId, actor.contactId);
13
+ // Belt and braces: the app filtered by organisation, and nothing
14
+ // that is not the buyer's may reach the page even if it did not.
15
+ const quotes = rows.filter(row => ownsQuote(row, actor)).map(mapQuote);
16
+ return { quotes, total: quotes.length };
17
+ }
18
+ catch (err) {
19
+ getLogService().error("Live quote list failed", apiErrorContext(err));
20
+ throw createError({ statusCode: 502, message: "Quote service unavailable" });
21
+ }
22
+ }
23
+
24
+ const quotes = (await readMockQuotes()).filter(row => ownsQuote(row, actor) || (!row.organization_id && !row.contact_id)).map(mapQuote);
25
+ return { quotes, total: quotes.length };
26
+ });
@@ -0,0 +1,176 @@
1
+ import type { Models } from "@revenexx/sdk";
2
+
3
+ import type { QuoteRequestPayload, QuoteRequestResult } from "../../../app/interfaces/account/quotes";
4
+ import type { LiveQuote } from "../../utils/quotesService";
5
+
6
+ /**
7
+ * Turn the active cart into a quotation request (RX-783).
8
+ *
9
+ * For a cart the shop cannot order as it is — a consignment over the parcel
10
+ * limit is the case that brought this in. The buyer picks the delivery and the
11
+ * billing address from their own address book (selection only; the ERP owns
12
+ * the addresses), because the carriage is priced for where the goods go, and
13
+ * the order the quote becomes must go to the same address with the same ids
14
+ * the ERP export reads.
15
+ *
16
+ * The positions are copied onto the quote at the prices the buyer was shown.
17
+ * The cart is then handed over to the quote the way an order takes it — frozen
18
+ * under the quote number — so the buyer starts clean and cannot order the same
19
+ * goods a second time while the merchant is still pricing them.
20
+ */
21
+ export default defineEventHandler(async (event): Promise<QuoteRequestResult> => {
22
+ const body = await readBody<QuoteRequestPayload>(event);
23
+ if (!body?.items?.length) {
24
+ throw createError({ statusCode: 400, message: "Cart is empty" });
25
+ }
26
+ if (!body.shippingAddressId || !body.billingAddressId) {
27
+ throw createError({ statusCode: 422, message: "A delivery and a billing address are required" });
28
+ }
29
+
30
+ const actor = await quoteActor(event);
31
+ if (!actor.user) {
32
+ throw createError({ statusCode: 401, message: "Sign in to ask for a quote" });
33
+ }
34
+
35
+ const profile = await getCheckoutProfileService().getProfile(event, actor.user.$id);
36
+ const shippingAddress = profile.addresses.find(a => a.id === body.shippingAddressId);
37
+ const billingAddress = profile.addresses.find(a => a.id === body.billingAddressId);
38
+ if (!shippingAddress || !billingAddress) {
39
+ throw createError({ statusCode: 422, message: "The chosen address is not in your address book" });
40
+ }
41
+
42
+ const currency = resolveSelectedCurrency(event) ?? "EUR";
43
+ const live = resolveQuotesServiceKey(event) === "api";
44
+
45
+ // The list price per line, resolved the same way the order would be — a
46
+ // quote asked at a price the buyer never saw is no basis for a decision.
47
+ const listPrice = new Map<string, number>();
48
+ const taxRate = new Map<string, number>();
49
+ if (live) {
50
+ try {
51
+ const { prices } = await useRevenexxSdk().prices.pricesResolve({
52
+ items: body.items.map(it => ({ product_id: String(it.id), sku: it.sku || undefined, quantity: Number(it.quantity) || 1 })) as Models.PriceResolveItem[],
53
+ ...(actor.contactId ? { contactId: actor.contactId } : {}),
54
+ ...(actor.organizationId ? { organizationId: actor.organizationId } : {}),
55
+ currency,
56
+ }) as unknown as { prices: Array<{ product_id: string | null; sku: string | null; tax_rate: number | null; on_request: boolean; unit_price: number | null }> };
57
+ for (const p of prices) {
58
+ const keys = [p.product_id, p.sku].filter((k): k is string => Boolean(k));
59
+ for (const key of keys) {
60
+ if (!p.on_request && p.unit_price != null) listPrice.set(key, p.unit_price);
61
+ if (p.tax_rate != null) taxRate.set(key, p.tax_rate);
62
+ }
63
+ }
64
+ }
65
+ catch (err) {
66
+ getLogService().error("Quote request price resolution failed", apiErrorContext(err));
67
+ }
68
+ }
69
+
70
+ const items = body.items.map((it, index) => {
71
+ const key = String(it.id);
72
+ const price = listPrice.get(key) ?? listPrice.get(String(it.sku ?? "")) ?? (Number.isFinite(Number(it.price)) ? Number(it.price) : null);
73
+ const rate = taxRate.get(key) ?? taxRate.get(String(it.sku ?? ""));
74
+ return {
75
+ position: (index + 1) * 10,
76
+ product_id: key,
77
+ ...(it.sku ? { sku: String(it.sku) } : {}),
78
+ name: String(it.name ?? it.sku ?? it.id),
79
+ quantity: Number(it.quantity),
80
+ ...(price !== null ? { list_price: price } : {}),
81
+ ...(rate !== undefined ? { tax_rate: rate } : {}),
82
+ ...(it.image ? { metadata: { image: String(it.image) } } : {}),
83
+ };
84
+ });
85
+
86
+ const buyer = {
87
+ name: actor.user.name,
88
+ email: actor.user.email,
89
+ company: shippingAddress.companyName || billingAddress.companyName || undefined,
90
+ };
91
+
92
+ let cartId: string | null = null;
93
+ const manager = getCartManager(event);
94
+ try {
95
+ cartId = (await manager?.listCarts(event))?.activeCartId ?? null;
96
+ }
97
+ catch (err) {
98
+ getLogService().error("Active cart lookup failed", apiErrorContext(err));
99
+ }
100
+
101
+ let created: { id: string; number: string };
102
+ if (live) {
103
+ try {
104
+ const quote = await liveQuoteRequest({
105
+ currency,
106
+ items,
107
+ ...(cartId ? { cart_id: cartId } : {}),
108
+ ...(actor.contactId ? { contact_id: actor.contactId } : {}),
109
+ ...(actor.organizationId ? { organization_id: actor.organizationId } : {}),
110
+ buyer,
111
+ shipping_address: shippingAddress,
112
+ billing_address: billingAddress,
113
+ ...(body.note?.trim() ? { buyer_note: body.note.trim() } : {}),
114
+ ...(body.reason ? { reason: body.reason } : {}),
115
+ });
116
+ created = { id: quote.id, number: quote.number };
117
+ }
118
+ catch (err) {
119
+ if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
120
+ throw createError({ statusCode: 422, message: err.message });
121
+ }
122
+ getLogService().error("Quote request failed", apiErrorContext(err));
123
+ throw createError({ statusCode: 502, message: "Quote service unavailable" });
124
+ }
125
+ }
126
+ else {
127
+ const quotes = await readMockQuotes();
128
+ const number = `ANG-${String(quotes.length + 1).padStart(6, "0")}`;
129
+ const now = new Date().toISOString();
130
+ const record: LiveQuote = {
131
+ id: crypto.randomUUID(),
132
+ number,
133
+ status: "requested",
134
+ currency,
135
+ contact_id: actor.contactId ?? null,
136
+ organization_id: actor.organizationId ?? null,
137
+ reason: body.reason ?? null,
138
+ buyer_note: body.note?.trim() || null,
139
+ list_total: items.reduce((sum, it) => sum + (it.list_price ?? 0) * it.quantity, 0),
140
+ quoted_total: items.reduce((sum, it) => sum + (it.list_price ?? 0) * it.quantity, 0),
141
+ grand_total: items.reduce((sum, it) => sum + (it.list_price ?? 0) * it.quantity, 0),
142
+ requested_at: now,
143
+ created_at: now,
144
+ buyer,
145
+ shipping_address: shippingAddress as unknown as Record<string, unknown>,
146
+ billing_address: billingAddress as unknown as Record<string, unknown>,
147
+ items: items.map(it => ({
148
+ id: crypto.randomUUID(),
149
+ product_id: it.product_id,
150
+ sku: it.sku ?? null,
151
+ name: it.name,
152
+ quantity: it.quantity,
153
+ list_price: it.list_price ?? null,
154
+ tax_rate: it.tax_rate ?? null,
155
+ line_total: (it.list_price ?? 0) * it.quantity,
156
+ decision: "open",
157
+ })),
158
+ events: [{ kind: "requested", actor: "buyer", body: body.note?.trim() || null, visibility: "customer", created_at: now }],
159
+ };
160
+ await writeMockQuotes([record, ...quotes]);
161
+ created = { id: record.id, number };
162
+ }
163
+
164
+ // The cart goes to the quote. Best-effort, like the order hand-over: a
165
+ // cart that stays active is an inconvenience, a lost request is not.
166
+ if (manager) {
167
+ try {
168
+ await manager.orderActiveCart(event, created.number);
169
+ }
170
+ catch (err) {
171
+ getLogService().error("Cart hand-over to quote failed", toErrorContext(err));
172
+ }
173
+ }
174
+
175
+ return created;
176
+ });
@@ -0,0 +1,34 @@
1
+ {
2
+ "quotes": [
3
+ {
4
+ "id": "5b8f9a1e-0000-4000-8000-000000000001",
5
+ "number": "ANG-000001",
6
+ "status": "quoted",
7
+ "currency": "EUR",
8
+ "contact_id": null,
9
+ "organization_id": null,
10
+ "reason": "shipping-on-request",
11
+ "buyer_note": "Bitte Anlieferung mit Hebebühne.",
12
+ "seller_note": "Speditionsversand auf Einwegpalette, Lieferung in 5 Werktagen nach Bestellung.",
13
+ "list_total": 2176,
14
+ "quoted_total": 2176,
15
+ "shipping_amount": 185,
16
+ "shipping_tax_rate": 19,
17
+ "grand_total": 2361,
18
+ "valid_until": "2099-12-31T00:00:00.000Z",
19
+ "requested_at": "2026-09-22T08:00:00.000Z",
20
+ "quoted_at": "2026-09-22T09:30:00.000Z",
21
+ "created_at": "2026-09-22T08:00:00.000Z",
22
+ "buyer": { "name": "Max Mustermann", "email": "max@example.com", "company": "Musterfirma GmbH" },
23
+ "shipping_address": { "id": "addr-1", "companyName": "Musterfirma GmbH", "contactName": "Max Mustermann", "street": "Industriestraße 12", "postalCode": "68753", "city": "Waghäusel", "country": "DE" },
24
+ "billing_address": { "id": "addr-1", "companyName": "Musterfirma GmbH", "contactName": "Max Mustermann", "street": "Industriestraße 12", "postalCode": "68753", "city": "Waghäusel", "country": "DE" },
25
+ "items": [
26
+ { "id": "5b8f9a1e-0000-4000-8000-0000000000a1", "sku": "D22020005", "name": "Umkehrkammer 4102", "quantity": 2, "list_price": 1088, "quoted_price": null, "tax_rate": 19, "line_total": 2176, "decision": "open" }
27
+ ],
28
+ "events": [
29
+ { "kind": "requested", "actor": "buyer", "body": "Bitte Anlieferung mit Hebebühne.", "visibility": "customer", "created_at": "2026-09-22T08:00:00.000Z" },
30
+ { "kind": "quoted", "actor": "seller", "body": "Speditionsversand auf Einwegpalette, Lieferung in 5 Werktagen nach Bestellung.", "visibility": "customer", "created_at": "2026-09-22T09:30:00.000Z" }
31
+ ]
32
+ }
33
+ ]
34
+ }