@open-mercato/core 0.4.5-develop-3ce83a8b24 → 0.4.5-develop-539cff4960
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/dist/generated/entities/catalog_product/index.js +16 -0
- package/dist/generated/entities/catalog_product/index.js.map +2 -2
- package/dist/generated/entities/catalog_product_unit_conversion/index.js +27 -0
- package/dist/generated/entities/catalog_product_unit_conversion/index.js.map +7 -0
- package/dist/generated/entities/sales_credit_memo_line/index.js +7 -1
- package/dist/generated/entities/sales_credit_memo_line/index.js.map +2 -2
- package/dist/generated/entities/sales_invoice_line/index.js +7 -1
- package/dist/generated/entities/sales_invoice_line/index.js.map +2 -2
- package/dist/generated/entities/sales_order_line/index.js +6 -0
- package/dist/generated/entities/sales_order_line/index.js.map +2 -2
- package/dist/generated/entities/sales_quote_line/index.js +6 -0
- package/dist/generated/entities/sales_quote_line/index.js.map +2 -2
- package/dist/generated/entities.ids.generated.js +1 -0
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +2 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/catalog/api/prices/route.js +123 -8
- package/dist/modules/catalog/api/prices/route.js.map +2 -2
- package/dist/modules/catalog/api/product-unit-conversions/route.js +194 -0
- package/dist/modules/catalog/api/product-unit-conversions/route.js.map +7 -0
- package/dist/modules/catalog/api/products/route.js +351 -201
- package/dist/modules/catalog/api/products/route.js.map +2 -2
- package/dist/modules/catalog/backend/catalog/products/[id]/page.js +1267 -497
- package/dist/modules/catalog/backend/catalog/products/[id]/page.js.map +2 -2
- package/dist/modules/catalog/backend/catalog/products/create/page.js +733 -210
- package/dist/modules/catalog/backend/catalog/products/create/page.js.map +2 -2
- package/dist/modules/catalog/commands/index.js +1 -0
- package/dist/modules/catalog/commands/index.js.map +2 -2
- package/dist/modules/catalog/commands/productUnitConversions.js +503 -0
- package/dist/modules/catalog/commands/productUnitConversions.js.map +7 -0
- package/dist/modules/catalog/commands/products.js +355 -73
- package/dist/modules/catalog/commands/products.js.map +2 -2
- package/dist/modules/catalog/commands/shared.js +18 -4
- package/dist/modules/catalog/commands/shared.js.map +2 -2
- package/dist/modules/catalog/components/products/ProductUomSection.js +591 -0
- package/dist/modules/catalog/components/products/ProductUomSection.js.map +7 -0
- package/dist/modules/catalog/components/products/productForm.js +66 -5
- package/dist/modules/catalog/components/products/productForm.js.map +2 -2
- package/dist/modules/catalog/components/products/productFormUtils.js +68 -0
- package/dist/modules/catalog/components/products/productFormUtils.js.map +7 -0
- package/dist/modules/catalog/data/entities.js +86 -0
- package/dist/modules/catalog/data/entities.js.map +2 -2
- package/dist/modules/catalog/data/validators.js +65 -3
- package/dist/modules/catalog/data/validators.js.map +2 -2
- package/dist/modules/catalog/events.js +3 -0
- package/dist/modules/catalog/events.js.map +2 -2
- package/dist/modules/catalog/lib/unitCodes.js +7 -0
- package/dist/modules/catalog/lib/unitCodes.js.map +7 -0
- package/dist/modules/catalog/lib/unitResolution.js +53 -0
- package/dist/modules/catalog/lib/unitResolution.js.map +7 -0
- package/dist/modules/catalog/migrations/Migration20260218225422.js +19 -0
- package/dist/modules/catalog/migrations/Migration20260218225422.js.map +7 -0
- package/dist/modules/catalog/migrations/Migration20260219084500.js +27 -0
- package/dist/modules/catalog/migrations/Migration20260219084500.js.map +7 -0
- package/dist/modules/catalog/search.js +69 -1
- package/dist/modules/catalog/search.js.map +2 -2
- package/dist/modules/catalog/seed/examples.js +91 -42
- package/dist/modules/catalog/seed/examples.js.map +2 -2
- package/dist/modules/dashboards/seed/analytics.js +3 -0
- package/dist/modules/dashboards/seed/analytics.js.map +2 -2
- package/dist/modules/sales/api/order-lines/route.js +98 -15
- package/dist/modules/sales/api/order-lines/route.js.map +2 -2
- package/dist/modules/sales/api/quote-lines/route.js +101 -14
- package/dist/modules/sales/api/quote-lines/route.js.map +2 -2
- package/dist/modules/sales/api/quotes/public/[token]/route.js +87 -12
- package/dist/modules/sales/api/quotes/public/[token]/route.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +1424 -260
- package/dist/modules/sales/commands/documents.js.map +3 -3
- package/dist/modules/sales/commands/shared.js +6 -2
- package/dist/modules/sales/commands/shared.js.map +2 -2
- package/dist/modules/sales/components/documents/ItemsSection.js +216 -86
- package/dist/modules/sales/components/documents/ItemsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/LineItemDialog.js +913 -241
- package/dist/modules/sales/components/documents/LineItemDialog.js.map +3 -3
- package/dist/modules/sales/components/documents/ShipmentsSection.js +15 -3
- package/dist/modules/sales/components/documents/ShipmentsSection.js.map +2 -2
- package/dist/modules/sales/data/entities.js +59 -3
- package/dist/modules/sales/data/entities.js.map +2 -2
- package/dist/modules/sales/data/validators.js +35 -0
- package/dist/modules/sales/data/validators.js.map +2 -2
- package/dist/modules/sales/frontend/quote/[token]/page.js +15 -1
- package/dist/modules/sales/frontend/quote/[token]/page.js.map +2 -2
- package/dist/modules/sales/migrations/Migration20260218225423.js +31 -0
- package/dist/modules/sales/migrations/Migration20260218225423.js.map +7 -0
- package/dist/modules/sales/migrations/Migration20260219084501.js +71 -0
- package/dist/modules/sales/migrations/Migration20260219084501.js.map +7 -0
- package/dist/modules/sales/search.js +28 -0
- package/dist/modules/sales/search.js.map +2 -2
- package/dist/modules/sales/seed/examples.js +14 -1
- package/dist/modules/sales/seed/examples.js.map +2 -2
- package/dist/modules/sales/widgets/injection/document-history/widget.client.js +1 -1
- package/dist/modules/sales/widgets/injection/document-history/widget.client.js.map +2 -2
- package/dist/modules/staff/backend/staff/team-members/[id]/page.js +28 -15
- package/dist/modules/staff/backend/staff/team-members/[id]/page.js.map +2 -2
- package/dist/modules/staff/translations.js +9 -0
- package/dist/modules/staff/translations.js.map +7 -0
- package/dist/modules/translations/components/TranslationDrawerAction.js +97 -0
- package/dist/modules/translations/components/TranslationDrawerAction.js.map +7 -0
- package/dist/modules/translations/lib/extract-record-id.js +31 -2
- package/dist/modules/translations/lib/extract-record-id.js.map +2 -2
- package/dist/modules/translations/lib/resolve-field-list.js +3 -0
- package/dist/modules/translations/lib/resolve-field-list.js.map +2 -2
- package/dist/modules/translations/widgets/injection/translation-manager/widget.client.js +105 -36
- package/dist/modules/translations/widgets/injection/translation-manager/widget.client.js.map +2 -2
- package/dist/modules/translations/widgets/injection-table.js +18 -29
- package/dist/modules/translations/widgets/injection-table.js.map +2 -2
- package/generated/entities/catalog_product/index.ts +8 -0
- package/generated/entities/catalog_product_unit_conversion/index.ts +12 -0
- package/generated/entities/sales_credit_memo_line/index.ts +3 -0
- package/generated/entities/sales_invoice_line/index.ts +3 -0
- package/generated/entities/sales_order_line/index.ts +3 -0
- package/generated/entities/sales_quote_line/index.ts +3 -0
- package/generated/entities.ids.generated.ts +1 -0
- package/generated/entity-fields-registry.ts +2 -0
- package/package.json +2 -2
- package/src/modules/auth/i18n/de.json +1 -1
- package/src/modules/auth/i18n/en.json +1 -1
- package/src/modules/auth/i18n/es.json +1 -1
- package/src/modules/auth/i18n/pl.json +1 -1
- package/src/modules/catalog/api/prices/route.ts +213 -81
- package/src/modules/catalog/api/product-unit-conversions/route.ts +195 -0
- package/src/modules/catalog/api/products/route.ts +638 -402
- package/src/modules/catalog/backend/catalog/products/[id]/page.tsx +2085 -1072
- package/src/modules/catalog/backend/catalog/products/create/page.tsx +1288 -593
- package/src/modules/catalog/commands/index.ts +1 -0
- package/src/modules/catalog/commands/productUnitConversions.ts +626 -0
- package/src/modules/catalog/commands/products.ts +1151 -693
- package/src/modules/catalog/commands/shared.ts +19 -5
- package/src/modules/catalog/components/products/ProductUomSection.tsx +745 -0
- package/src/modules/catalog/components/products/productForm.ts +369 -256
- package/src/modules/catalog/components/products/productFormUtils.ts +82 -0
- package/src/modules/catalog/data/entities.ts +82 -1
- package/src/modules/catalog/data/validators.ts +118 -34
- package/src/modules/catalog/events.ts +3 -0
- package/src/modules/catalog/i18n/de.json +56 -0
- package/src/modules/catalog/i18n/en.json +56 -0
- package/src/modules/catalog/i18n/es.json +56 -0
- package/src/modules/catalog/i18n/pl.json +56 -0
- package/src/modules/catalog/lib/unitCodes.ts +1 -0
- package/src/modules/catalog/lib/unitResolution.ts +62 -0
- package/src/modules/catalog/migrations/.snapshot-open-mercato.json +245 -0
- package/src/modules/catalog/migrations/Migration20260218225422.ts +21 -0
- package/src/modules/catalog/migrations/Migration20260219084500.ts +26 -0
- package/src/modules/catalog/search.ts +73 -1
- package/src/modules/catalog/seed/examples.ts +552 -479
- package/src/modules/dashboards/i18n/de.json +1 -1
- package/src/modules/dashboards/i18n/en.json +1 -1
- package/src/modules/dashboards/i18n/es.json +1 -1
- package/src/modules/dashboards/i18n/pl.json +1 -1
- package/src/modules/dashboards/seed/analytics.ts +3 -0
- package/src/modules/sales/api/order-lines/route.ts +158 -68
- package/src/modules/sales/api/quote-lines/route.ts +161 -67
- package/src/modules/sales/api/quotes/public/[token]/route.ts +122 -36
- package/src/modules/sales/commands/documents.ts +4250 -2424
- package/src/modules/sales/commands/shared.ts +7 -2
- package/src/modules/sales/components/documents/ItemsSection.tsx +580 -310
- package/src/modules/sales/components/documents/LineItemDialog.tsx +1988 -833
- package/src/modules/sales/components/documents/ShipmentsSection.tsx +17 -3
- package/src/modules/sales/components/documents/lineItemTypes.ts +6 -0
- package/src/modules/sales/data/entities.ts +53 -0
- package/src/modules/sales/data/validators.ts +36 -0
- package/src/modules/sales/frontend/quote/[token]/page.tsx +25 -1
- package/src/modules/sales/i18n/de.json +23 -3
- package/src/modules/sales/i18n/en.json +23 -3
- package/src/modules/sales/i18n/es.json +23 -3
- package/src/modules/sales/i18n/pl.json +23 -3
- package/src/modules/sales/lib/types.ts +30 -0
- package/src/modules/sales/migrations/.snapshot-open-mercato.json +172 -0
- package/src/modules/sales/migrations/Migration20260218225423.ts +37 -0
- package/src/modules/sales/migrations/Migration20260219084501.ts +73 -0
- package/src/modules/sales/search.ts +28 -0
- package/src/modules/sales/seed/examples.ts +20 -1
- package/src/modules/sales/widgets/injection/document-history/widget.client.tsx +1 -1
- package/src/modules/staff/backend/staff/team-members/[id]/page.tsx +8 -0
- package/src/modules/staff/translations.ts +5 -0
- package/src/modules/translations/components/TranslationDrawerAction.tsx +107 -0
- package/src/modules/translations/lib/extract-record-id.ts +47 -3
- package/src/modules/translations/lib/resolve-field-list.ts +4 -0
- package/src/modules/translations/widgets/injection/translation-manager/widget.client.tsx +108 -36
- package/src/modules/translations/widgets/injection-table.ts +19 -33
- package/src/modules/workflows/i18n/de.json +4 -4
- package/src/modules/workflows/i18n/en.json +4 -4
- package/src/modules/workflows/i18n/es.json +4 -4
- package/src/modules/workflows/i18n/pl.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sales/seed/examples.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomUUID } from 'crypto'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AppContainer } from '@open-mercato/shared/lib/di/container'\nimport {\n SalesOrder,\n SalesOrderLine,\n SalesOrderAdjustment,\n SalesQuote,\n SalesQuoteLine,\n SalesQuoteAdjustment,\n SalesShipment,\n SalesShipmentItem,\n SalesPayment,\n SalesPaymentAllocation,\n SalesDocumentAddress,\n SalesNote,\n SalesChannel,\n SalesPaymentMethod,\n SalesShippingMethod,\n type SalesAdjustmentKind,\n type SalesLineKind,\n} from '../data/entities'\nimport { seedSalesDictionaries } from '../lib/dictionaries'\nimport { refreshShipmentItemsSnapshot } from '../lib/shipments/snapshots'\nimport { toNumericString } from '../commands/shared'\nimport type { SalesCalculationService } from '../services/salesCalculationService'\nimport { ensureExamplePaymentMethods, ensureExampleShippingMethods, type SeedScope } from './examples-data'\nimport {\n CatalogProduct,\n CatalogProductPrice,\n CatalogProductVariant,\n} from '@open-mercato/core/modules/catalog/data/entities'\nimport {\n CustomerAddress,\n CustomerEntity,\n CustomerPersonProfile,\n} from '@open-mercato/core/modules/customers/data/entities'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\n\ntype ExampleAddress = {\n role: 'billing' | 'shipping'\n companyName?: string | null\n name?: string | null\n addressLine1: string\n addressLine2?: string | null\n city?: string | null\n region?: string | null\n postalCode?: string | null\n country?: string | null\n latitude?: number | null\n longitude?: number | null\n customerAddressId?: string | null\n}\n\ntype ExampleLine = {\n kind?: SalesLineKind\n name: string\n description?: string\n quantity: number\n unitPriceNet: number\n unitPriceGross?: number\n taxRate?: number\n discountPercent?: number\n quantityUnit?: string\n comment?: string\n productHandle?: string\n variantSku?: string\n}\n\ntype ExampleAdjustment = {\n scope: 'order' | 'line'\n kind: SalesAdjustmentKind\n label?: string\n amountNet: number\n amountGross?: number\n rate?: number\n lineIndex?: number\n position?: number\n}\n\ntype ExampleNote = {\n body: string\n createdAt?: Date\n appearanceIcon?: string | null\n appearanceColor?: string | null\n}\n\ntype ExampleShipment = {\n shipmentNumber?: string\n methodCode?: string\n status?: string\n shippedAt?: Date\n deliveredAt?: Date\n trackingNumbers?: string[]\n weightKg?: number\n declaredValue?: number\n currencyCode?: string\n notes?: string\n items: Array<{ lineIndex: number; quantity: number }>\n}\n\ntype ExamplePayment = {\n reference?: string\n methodCode?: string\n status?: string\n amount: number\n currencyCode: string\n receivedAt?: Date\n capturedAt?: Date\n}\n\ntype ExampleQuote = {\n quoteNumber: string\n status?: string\n comments?: string\n validFrom?: Date\n validUntil?: Date\n currencyCode: string\n shippingMethodCode?: string\n paymentMethodCode?: string\n addresses?: ExampleAddress[]\n lines: ExampleLine[]\n adjustments?: ExampleAdjustment[]\n notes?: ExampleNote[]\n metadata?: Record<string, unknown>\n channelCode?: string\n customerKey?: string\n}\n\ntype ExampleOrder = {\n orderNumber: string\n status?: string\n fulfillmentStatus?: string\n paymentStatus?: string\n comments?: string\n internalNotes?: string\n placedAt?: Date\n expectedDeliveryAt?: Date\n currencyCode: string\n shippingMethodCode?: string\n paymentMethodCode?: string\n channelCode?: string\n addresses?: ExampleAddress[]\n lines: ExampleLine[]\n adjustments?: ExampleAdjustment[]\n notes?: ExampleNote[]\n shipments?: ExampleShipment[]\n payments?: ExamplePayment[]\n metadata?: Record<string, unknown>\n customerKey?: string\n}\n\nconst CHANNEL_SEEDS = [\n { code: 'online', name: 'Online Store', description: 'Orders captured from the storefront.' },\n {\n code: 'field-sales',\n name: 'Field Sales',\n description: 'Quotes negotiated by the sales team and converted offline.',\n },\n] as const\n\nconst CUSTOMER_LINKS: CustomerLookup[] = [\n { key: 'brightside', displayName: 'Brightside Solar' },\n { key: 'harborview', displayName: 'Harborview Analytics' },\n { key: 'copperleaf', displayName: 'Copperleaf Design Co.' },\n] as const\n\nconst QUOTE_SEEDS: ExampleQuote[] = [\n {\n quoteNumber: 'SQ-DEMO-1001',\n status: 'draft',\n comments: 'Pricing reflects bundled onboarding; valid for 30 days.',\n validFrom: daysFromNow(-2),\n validUntil: daysFromNow(28),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n lines: [\n {\n name: 'Remote onboarding package',\n description: 'Kick-off, workflow design, and training for distributed teams.',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 10,\n },\n {\n name: 'Implementation workshop (4h)',\n description: 'Hands-on configuration session with stakeholders.',\n quantity: 1,\n unitPriceNet: 320,\n taxRate: 0,\n comment: 'Can be split into two shorter sessions on request.',\n },\n ],\n adjustments: [\n { scope: 'order', kind: 'discount', label: 'Pilot discount', amountNet: 45, position: 1 },\n {\n scope: 'order',\n kind: 'shipping',\n label: 'Expedited shipping',\n amountNet: 25,\n amountGross: 27.5,\n position: 2,\n },\n ],\n addresses: [\n {\n role: 'billing',\n companyName: 'Northwind Ventures',\n name: 'Nora Winters',\n addressLine1: '200 Pine St',\n addressLine2: 'Suite 900',\n city: 'Seattle',\n region: 'WA',\n postalCode: '98101',\n country: 'US',\n },\n {\n role: 'shipping',\n companyName: 'Northwind Ventures',\n name: 'Receiving Dock',\n addressLine1: '4124 4th Ave S',\n city: 'Seattle',\n region: 'WA',\n postalCode: '98134',\n country: 'US',\n },\n ],\n notes: [\n {\n body: 'Requested weekend training option if schedules slip.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:calendar-clock',\n appearanceColor: '#0ea5e9',\n },\n {\n body: 'Prefers invoicing after acceptance instead of deposit.',\n createdAt: daysFromNow(0),\n appearanceIcon: 'lucide:receipt',\n appearanceColor: '#f97316',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n quoteNumber: 'SQ-DEMO-1002',\n status: 'draft',\n comments: 'Footwear replenishment and event outfits pulled from catalog offers.',\n validFrom: daysFromNow(-1),\n validUntil: daysFromNow(21),\n currencyCode: 'USD',\n shippingMethodCode: 'standard-ground',\n paymentMethodCode: 'card',\n channelCode: 'online',\n customerKey: 'brightside',\n lines: [\n {\n name: 'Atlas Runner Sneaker',\n quantity: 3,\n unitPriceNet: 120,\n taxRate: 10,\n variantSku: 'ATLAS-RUN-NAVY-8',\n },\n {\n name: 'Aurora Wrap Dress',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 10,\n variantSku: 'AURORA-ROSE-M',\n discountPercent: 5,\n },\n ],\n adjustments: [\n { scope: 'order', kind: 'discount', label: 'Preferred customer', amountNet: 35, position: 1 },\n ],\n notes: [\n {\n body: 'Requested quick turn on delivery dates for press shoot.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:camera',\n appearanceColor: '#0ea5e9',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n quoteNumber: 'SQ-DEMO-1003',\n status: 'sent',\n comments: 'Bundle of apparel and on-site styling block for the studio launch.',\n validFrom: daysFromNow(-3),\n validUntil: daysFromNow(10),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n customerKey: 'copperleaf',\n lines: [\n {\n name: 'Aurora Wrap Dress',\n quantity: 2,\n unitPriceNet: 180,\n taxRate: 10,\n variantSku: 'AURORA-CELESTIAL-L',\n comment: 'Alternate colorway accepted if Celestial runs out.',\n },\n {\n name: 'Signature Haircut & Finish',\n quantity: 4,\n unitPriceNet: 95,\n taxRate: 0,\n variantSku: 'SERV-HAIR-60',\n quantityUnit: 'hour',\n comment: 'Styling sessions during opening week.',\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'discount',\n label: 'Launch partner credit',\n amountNet: 60,\n position: 1,\n },\n ],\n notes: [\n {\n body: 'Prefers consolidated invoicing after the event.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:file-text',\n appearanceColor: '#f97316',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n]\n\nconst ORDER_SEEDS: ExampleOrder[] = [\n {\n orderNumber: 'SO-DEMO-2001',\n status: 'confirmed',\n fulfillmentStatus: 'in_fulfillment',\n comments: 'White-glove delivery requested for the larger items.',\n internalNotes: 'Coordinate with facilities for access badges.',\n placedAt: daysFromNow(-3),\n expectedDeliveryAt: daysFromNow(4),\n currencyCode: 'USD',\n shippingMethodCode: 'standard-ground',\n paymentMethodCode: 'card',\n channelCode: 'online',\n lines: [\n {\n name: 'Modular desk system',\n quantity: 1,\n unitPriceNet: 640,\n taxRate: 10,\n description: 'Corner configuration with cable routing.',\n },\n {\n name: 'Acoustic panel set',\n quantity: 3,\n unitPriceNet: 85,\n taxRate: 10,\n description: 'Charcoal grey finish, adhesive mount.',\n discountPercent: 5,\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'shipping',\n label: 'White-glove delivery',\n amountNet: 60,\n amountGross: 66,\n position: 1,\n },\n { scope: 'order', kind: 'discount', label: 'New office promo', amountNet: 75, position: 2 },\n {\n scope: 'order',\n kind: 'surcharge',\n label: 'After-hours install',\n amountNet: 35,\n amountGross: 38.5,\n position: 3,\n },\n ],\n shipments: [\n {\n shipmentNumber: 'SHIP-2001-1',\n methodCode: 'standard-ground',\n status: 'shipped',\n shippedAt: daysFromNow(-1),\n trackingNumbers: ['1Z-234-ACOUSTICS'],\n weightKg: 38,\n declaredValue: 720,\n currencyCode: 'USD',\n notes: 'Panels shipped separately to avoid freight delay.',\n items: [\n { lineIndex: 1, quantity: 2 },\n ],\n },\n {\n shipmentNumber: 'SHIP-2001-2',\n methodCode: 'express-air',\n status: 'in_transit',\n shippedAt: daysFromNow(0),\n trackingNumbers: ['1Z-987-DESK'],\n weightKg: 72,\n declaredValue: 560,\n currencyCode: 'USD',\n notes: 'Desk ships via express due to size.',\n items: [{ lineIndex: 0, quantity: 1 }],\n },\n ],\n payments: [\n {\n reference: 'AUTH-2001-CC',\n methodCode: 'card',\n status: 'captured',\n amount: 600,\n currencyCode: 'USD',\n receivedAt: daysFromNow(-2),\n capturedAt: daysFromNow(-1),\n },\n {\n reference: 'WIRE-2001',\n methodCode: 'bank-transfer',\n status: 'received',\n amount: 414,\n currencyCode: 'USD',\n receivedAt: daysFromNow(1),\n },\n ],\n addresses: [\n {\n role: 'billing',\n companyName: 'Harborview Analytics',\n name: 'Accounts Payable',\n addressLine1: '355 Atlantic Ave Floor 6',\n city: 'Boston',\n region: 'MA',\n postalCode: '02210',\n country: 'US',\n },\n {\n role: 'shipping',\n companyName: 'Harborview Analytics',\n name: 'Loading Dock',\n addressLine1: '9 Drydock Ave',\n city: 'Boston',\n region: 'MA',\n postalCode: '02210',\n country: 'US',\n },\n ],\n notes: [\n {\n body: 'Facilities requested 2-hour delivery window notice.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:bell-ring',\n appearanceColor: '#0ea5e9',\n },\n {\n body: 'Panels can be staged in conference room A.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:warehouse',\n appearanceColor: '#22c55e',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n orderNumber: 'SO-DEMO-2002',\n status: 'confirmed',\n fulfillmentStatus: 'fulfilled',\n paymentStatus: 'partial',\n comments: 'Subscription setup aligns with fiscal Q3 start.',\n placedAt: daysFromNow(-6),\n expectedDeliveryAt: daysFromNow(1),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n lines: [\n {\n name: 'On-site enablement',\n quantity: 1,\n unitPriceNet: 280,\n taxRate: 0,\n description: 'Day of workshops across two teams.',\n },\n {\n name: 'Support retainer (Q3)',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 0,\n description: 'Response SLA with named TAM.',\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'shipping',\n label: 'Travel & lodging',\n amountNet: 20,\n amountGross: 22,\n position: 1,\n },\n {\n scope: 'order',\n kind: 'discount',\n label: 'Multi-team starter',\n amountNet: 25,\n position: 2,\n },\n ],\n shipments: [\n {\n shipmentNumber: 'SHIP-2002-1',\n methodCode: 'express-air',\n status: 'delivered',\n shippedAt: daysFromNow(-4),\n deliveredAt: daysFromNow(-2),\n trackingNumbers: ['AIR-22002-KIT'],\n declaredValue: 150,\n currencyCode: 'USD',\n notes: 'Enablement kit delivered to training room.',\n items: [\n { lineIndex: 0, quantity: 1 },\n { lineIndex: 1, quantity: 1 },\n ],\n },\n ],\n payments: [\n {\n reference: 'WIRE-2002',\n methodCode: 'bank-transfer',\n status: 'received',\n amount: 250,\n currencyCode: 'USD',\n receivedAt: daysFromNow(-1),\n },\n ],\n addresses: [\n {\n role: 'billing',\n companyName: 'Brightside Solar',\n name: 'Finance',\n addressLine1: '245 Market St Suite 400',\n city: 'San Francisco',\n region: 'CA',\n postalCode: '94105',\n country: 'US',\n },\n {\n role: 'shipping',\n companyName: 'Brightside Solar',\n name: 'Training Room B',\n addressLine1: '245 Market St Suite 410',\n city: 'San Francisco',\n region: 'CA',\n postalCode: '94105',\n country: 'US',\n },\n ],\n notes: [\n {\n body: 'TAM onboarding scheduled next Tuesday.',\n createdAt: daysFromNow(-3),\n appearanceIcon: 'lucide:users',\n appearanceColor: '#a855f7',\n },\n {\n body: 'Retainer renewal review in mid-Q4.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:clock-3',\n appearanceColor: '#f97316',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n orderNumber: 'SO-DEMO-2003',\n status: 'confirmed',\n fulfillmentStatus: 'in_fulfillment',\n paymentStatus: 'partial',\n comments: 'Equipment refresh for analytics field team with matching footwear.',\n internalNotes: 'Coordinate delivery around team offsite schedule.',\n placedAt: daysFromNow(-2),\n expectedDeliveryAt: daysFromNow(5),\n currencyCode: 'USD',\n shippingMethodCode: 'standard-ground',\n paymentMethodCode: 'card',\n channelCode: 'online',\n customerKey: 'harborview',\n lines: [\n {\n name: 'Atlas Runner Sneaker',\n quantity: 4,\n unitPriceNet: 120,\n taxRate: 10,\n variantSku: 'ATLAS-RUN-GLACIER-10',\n comment: 'Size mix handled via catalog variants.',\n },\n {\n name: 'Aurora Wrap Dress',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 10,\n variantSku: 'AURORA-ROSE-M',\n discountPercent: 10,\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'shipping',\n label: 'Ground shipping',\n amountNet: 25,\n amountGross: 27.5,\n position: 1,\n },\n ],\n shipments: [\n {\n shipmentNumber: 'SHIP-2003-1',\n methodCode: 'standard-ground',\n status: 'pending',\n shippedAt: undefined,\n trackingNumbers: [],\n weightKg: 12,\n declaredValue: 0,\n currencyCode: 'USD',\n notes: 'Bundle footwear and apparel together.',\n items: [\n { lineIndex: 0, quantity: 4 },\n { lineIndex: 1, quantity: 1 },\n ],\n },\n ],\n payments: [\n {\n reference: 'CARD-2003',\n methodCode: 'card',\n status: 'authorized',\n amount: 300,\n currencyCode: 'USD',\n receivedAt: daysFromNow(-1),\n },\n ],\n notes: [\n {\n body: 'Leadership wants tracking shared in Slack channel.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:message-circle',\n appearanceColor: '#22c55e',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n orderNumber: 'SO-DEMO-2004',\n status: 'confirmed',\n fulfillmentStatus: 'pending',\n paymentStatus: 'unpaid',\n comments: 'On-site styling block for studio launch week.',\n placedAt: daysFromNow(-4),\n expectedDeliveryAt: daysFromNow(1),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n customerKey: 'copperleaf',\n lines: [\n {\n name: 'Signature Haircut & Finish',\n quantity: 6,\n unitPriceNet: 95,\n taxRate: 0,\n variantSku: 'SERV-HAIR-60',\n quantityUnit: 'hour',\n comment: 'Block book stylists for staggered sessions.',\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'discount',\n label: 'Launch week courtesy',\n amountNet: 45,\n position: 1,\n },\n ],\n payments: [\n {\n reference: 'WIRE-2004',\n methodCode: 'bank-transfer',\n status: 'pending',\n amount: 0,\n currencyCode: 'USD',\n },\n ],\n notes: [\n {\n body: 'Confirm stylist roster by Friday.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:check-circle',\n appearanceColor: '#0ea5e9',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n]\n\nfunction daysFromNow(offset: number): Date {\n const now = new Date()\n const copy = new Date(now)\n copy.setUTCDate(now.getUTCDate() + offset)\n return copy\n}\n\nfunction toAmount(value: number | null | undefined): string {\n if (value === null || value === undefined || Number.isNaN(value)) return '0'\n return toNumericString(Math.round((value + Number.EPSILON) * 10000) / 10000) ?? '0'\n}\n\nfunction toSnapshot<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T\n}\n\nfunction normalizeKey(value: string | null | undefined): string {\n return (value ?? '').trim().toLowerCase()\n}\n\nfunction asNumber(value: unknown): number {\n if (typeof value === 'number') return value\n if (typeof value === 'string') {\n const parsed = Number(value)\n return Number.isFinite(parsed) ? parsed : 0\n }\n return 0\n}\n\ntype CatalogLookup = {\n productsByHandle: Map<string, CatalogProduct>\n variantsBySku: Map<string, CatalogProductVariant>\n variantPrices: Map<string, { net: number; gross: number; currency: string }>\n}\n\nasync function loadCatalogLookups(em: EntityManager, scope: SeedScope): Promise<CatalogLookup> {\n const [products, variants, prices] = await Promise.all([\n em.find(CatalogProduct, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n }),\n em.find(\n CatalogProductVariant,\n { organizationId: scope.organizationId, tenantId: scope.tenantId, deletedAt: null },\n { populate: ['product'] }\n ),\n em.find(CatalogProductPrice, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }),\n ])\n\n const productsByHandle = new Map<string, CatalogProduct>()\n products.forEach((product) => {\n const key = normalizeKey(product.handle ?? product.sku ?? product.title)\n if (key) productsByHandle.set(key, product)\n })\n\n const variantsBySku = new Map<string, CatalogProductVariant>()\n variants.forEach((variant) => {\n const key = normalizeKey(variant.sku)\n if (key) variantsBySku.set(key, variant)\n })\n\n const variantPrices = new Map<string, { net: number; gross: number; currency: string }>()\n for (const price of prices) {\n const variantId =\n typeof price.variant === 'string' ? price.variant : price.variant?.id ?? (price as any)?.variant_id ?? null\n if (!variantId) continue\n const gross = asNumber((price as any).unitPriceGross ?? price.unitPriceGross)\n const net = asNumber((price as any).unitPriceNet ?? price.unitPriceNet ?? gross)\n const currency = typeof price.currencyCode === 'string' ? price.currencyCode : 'USD'\n const isSale = normalizeKey((price as any).kind) === 'sale' || normalizeKey((price as any)?.priceKind?.code) === 'sale'\n const existing = variantPrices.get(variantId)\n if (!existing || isSale) {\n variantPrices.set(variantId, { net, gross, currency })\n }\n }\n\n return { productsByHandle, variantsBySku, variantPrices }\n}\n\nfunction buildCatalogSnapshot(\n product: CatalogProduct | null,\n variant: CatalogProductVariant | null,\n price: { net: number; gross: number; currency: string } | null\n): Record<string, unknown> | null {\n if (!product) return null\n const productThumbnail =\n (product as any).defaultMediaUrl ??\n (product as any).thumbnailUrl ??\n (product.metadata && typeof product.metadata === 'object'\n ? ((product.metadata as any).thumbnailUrl as string | null | undefined)\n : null) ??\n null\n const variantThumbnail =\n variant && variant.metadata && typeof variant.metadata === 'object'\n ? ((variant.metadata as any).thumbnailUrl as string | null | undefined) ?? null\n : null\n return {\n product: {\n id: product.id,\n title: product.title,\n handle: product.handle ?? null,\n sku: product.sku ?? null,\n thumbnailUrl: productThumbnail,\n },\n variant: variant\n ? {\n id: variant.id,\n name: variant.name ?? product.title,\n sku: variant.sku ?? null,\n optionValues: variant.optionValues ?? null,\n thumbnailUrl: variantThumbnail,\n }\n : null,\n price: price\n ? {\n currencyCode: price.currency,\n unitPriceNet: price.net,\n unitPriceGross: price.gross,\n }\n : null,\n }\n}\n\nfunction resolveCatalogLine(\n line: ExampleLine,\n catalog: CatalogLookup\n): {\n productId: string | null\n variantId: string | null\n unitPriceNet: number | null\n unitPriceGross: number | null\n currencyCode: string | null\n snapshot: Record<string, unknown> | null\n productThumbnail: string | null\n variantThumbnail: string | null\n} {\n const variant =\n line.variantSku && catalog.variantsBySku.size\n ? catalog.variantsBySku.get(normalizeKey(line.variantSku))\n : null\n const product =\n variant?.product ??\n (line.productHandle ? catalog.productsByHandle.get(normalizeKey(line.productHandle)) ?? null : null)\n const price = variant ? catalog.variantPrices.get(variant.id) ?? null : null\n const snapshot = buildCatalogSnapshot(product ?? null, variant ?? null, price ?? null)\n const productThumbnail =\n (snapshot as any)?.product?.thumbnailUrl ??\n (product as any)?.defaultMediaUrl ??\n (product as any)?.thumbnailUrl ??\n null\n const variantThumbnail = (snapshot as any)?.variant?.thumbnailUrl ?? null\n return {\n productId: product ? product.id : null,\n variantId: variant ? variant.id : null,\n unitPriceNet: price?.net ?? null,\n unitPriceGross: price?.gross ?? null,\n currencyCode: price?.currency ?? null,\n snapshot,\n productThumbnail: productThumbnail ?? null,\n variantThumbnail: variantThumbnail ?? null,\n }\n}\n\ntype CustomerLookup = {\n key: string\n displayName: string\n}\n\ntype CustomerLookupSpec = CustomerLookup & { normalizedName: string }\n\ntype CustomerContext = {\n entity: CustomerEntity\n contact: CustomerPersonProfile | null\n contactId: string | null\n snapshot: Record<string, unknown> | null\n addresses: ExampleAddress[]\n}\n\nfunction buildCustomerSnapshot(\n entity: CustomerEntity,\n contact: CustomerPersonProfile | null\n): Record<string, unknown> | null {\n const base = {\n id: entity.id,\n kind: entity.kind,\n displayName: entity.displayName,\n primaryEmail: entity.primaryEmail ?? null,\n primaryPhone: entity.primaryPhone ?? null,\n personProfile: entity.personProfile\n ? {\n id: entity.personProfile.id,\n firstName: entity.personProfile.firstName ?? null,\n lastName: entity.personProfile.lastName ?? null,\n preferredName: entity.personProfile.preferredName ?? null,\n jobTitle: entity.personProfile.jobTitle ?? null,\n department: entity.personProfile.department ?? null,\n seniority: entity.personProfile.seniority ?? null,\n timezone: entity.personProfile.timezone ?? null,\n }\n : null,\n companyProfile: entity.companyProfile\n ? {\n id: entity.companyProfile.id,\n legalName: entity.companyProfile.legalName ?? null,\n brandName: entity.companyProfile.brandName ?? null,\n domain: entity.companyProfile.domain ?? null,\n websiteUrl: entity.companyProfile.websiteUrl ?? null,\n }\n : null,\n }\n const contactSnapshot = contact\n ? {\n id: contact.id,\n firstName: contact.firstName ?? null,\n lastName: contact.lastName ?? null,\n email: contact.entity?.primaryEmail ?? null,\n phone: contact.entity?.primaryPhone ?? null,\n companyId: contact.company ? (typeof contact.company === 'string' ? contact.company : contact.company.id) : null,\n }\n : null\n return { customer: base, contact: contactSnapshot }\n}\n\nfunction toExampleAddresses(customer: CustomerEntity, address: CustomerAddress | null): ExampleAddress[] {\n if (!address) return []\n const base = {\n companyName: address.companyName ?? customer.displayName ?? null,\n name: address.name ?? address.companyName ?? customer.displayName ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n city: address.city ?? null,\n region: address.region ?? null,\n postalCode: address.postalCode ?? null,\n country: address.country ?? null,\n latitude: address.latitude ?? null,\n longitude: address.longitude ?? null,\n customerAddressId: address.id,\n }\n return [\n { role: 'billing', ...base },\n { role: 'shipping', ...base },\n ]\n}\n\nasync function loadCustomerLookups(\n em: EntityManager,\n scope: SeedScope,\n lookups: CustomerLookup[]\n): Promise<Map<string, CustomerContext>> {\n const map = new Map<string, CustomerContext>()\n if (lookups.length === 0) return map\n const lookupSpecs: CustomerLookupSpec[] = lookups.map((lookup) => ({\n ...lookup,\n normalizedName: normalizeKey(lookup.displayName),\n }))\n const unresolved = new Map<string, CustomerLookupSpec>()\n for (const spec of lookupSpecs) {\n unresolved.set(spec.key, spec)\n }\n\n const customers = await findWithDecryption(\n em,\n CustomerEntity,\n {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n { populate: ['personProfile', 'companyProfile'] },\n { tenantId: scope.tenantId, organizationId: scope.organizationId }\n )\n\n const doesMatch = (candidate: string, spec: CustomerLookupSpec): boolean => {\n if (!candidate) return false\n return (\n candidate === spec.normalizedName ||\n candidate.includes(spec.normalizedName) ||\n spec.normalizedName.includes(candidate)\n )\n }\n\n const matchedPairs: Array<{ spec: CustomerLookupSpec; customer: CustomerEntity }> = []\n\n for (const customer of customers) {\n if (unresolved.size === 0) break\n const tokens = new Set<string>()\n tokens.add(normalizeKey(customer.displayName))\n if (customer.companyProfile) {\n tokens.add(normalizeKey(customer.companyProfile.legalName ?? ''))\n tokens.add(normalizeKey(customer.companyProfile.brandName ?? ''))\n tokens.add(normalizeKey(customer.companyProfile.domain ?? ''))\n }\n if (customer.personProfile) {\n tokens.add(normalizeKey(customer.personProfile.firstName ?? ''))\n tokens.add(normalizeKey(customer.personProfile.lastName ?? ''))\n const fullName = [customer.personProfile.firstName, customer.personProfile.lastName]\n .filter((part) => (part ?? '').trim().length > 0)\n .join(' ')\n tokens.add(normalizeKey(fullName))\n }\n\n const matchedSpec = lookupSpecs.find(\n (spec) => unresolved.has(spec.key) && Array.from(tokens).some((token) => doesMatch(token, spec))\n )\n if (!matchedSpec) continue\n matchedPairs.push({ spec: matchedSpec, customer })\n unresolved.delete(matchedSpec.key)\n }\n\n const matchIds = matchedPairs.map(({ customer }) => customer.id)\n\n const addresses = matchIds.length\n ? await findWithDecryption(\n em,\n CustomerAddress,\n { organizationId: scope.organizationId, tenantId: scope.tenantId, entity: { $in: matchIds } },\n { orderBy: { isPrimary: 'desc', createdAt: 'asc' } as any },\n { tenantId: scope.tenantId, organizationId: scope.organizationId }\n )\n : []\n const addressByCustomer = new Map<string, CustomerAddress>()\n for (const address of addresses) {\n const entityId = typeof address.entity === 'string' ? address.entity : address.entity?.id\n if (!entityId || addressByCustomer.has(entityId)) continue\n addressByCustomer.set(entityId, address)\n }\n\n const contacts = matchIds.length\n ? await findWithDecryption(\n em,\n CustomerPersonProfile,\n { organizationId: scope.organizationId, tenantId: scope.tenantId, company: { $in: matchIds } },\n { populate: ['entity', 'company'] },\n { tenantId: scope.tenantId, organizationId: scope.organizationId }\n )\n : []\n const contactByCompany = new Map<string, CustomerPersonProfile>()\n for (const contact of contacts) {\n const companyId = typeof contact.company === 'string' ? contact.company : contact.company?.id\n if (!companyId || contactByCompany.has(companyId)) continue\n contactByCompany.set(companyId, contact)\n }\n\n for (const { spec, customer } of matchedPairs) {\n const contact = contactByCompany.get(customer.id) ?? null\n const snapshot = buildCustomerSnapshot(customer, contact)\n const addresses = toExampleAddresses(customer, addressByCustomer.get(customer.id) ?? null)\n map.set(spec.key, {\n entity: customer,\n contact,\n contactId: contact?.id ?? null,\n snapshot,\n addresses,\n })\n }\n\n for (const lookup of lookups) {\n if (!map.has(lookup.key)) {\n console.warn(`[sales.examples] Customer \"${lookup.displayName}\" not found; skipping seeded linkage.`)\n }\n }\n\n return map\n}\n\nasync function ensureChannels(\n em: EntityManager,\n scope: SeedScope\n): Promise<Map<string, SalesChannel>> {\n const existing = await em.find(SalesChannel, {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n deletedAt: null,\n })\n const map = new Map<string, SalesChannel>()\n existing.forEach((entry) => map.set((entry.code ?? '').toLowerCase(), entry))\n const now = new Date()\n for (const seed of CHANNEL_SEEDS) {\n const code = seed.code.toLowerCase()\n if (map.has(code)) continue\n const record = em.create(SalesChannel, {\n id: randomUUID(),\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n name: seed.name,\n code: seed.code,\n description: seed.description,\n isActive: true,\n createdAt: now,\n updatedAt: now,\n })\n em.persist(record)\n map.set(code, record)\n }\n return map\n}\n\nfunction buildAddressSnapshot(address: ExampleAddress) {\n return {\n companyName: address.companyName ?? null,\n name: address.name ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n city: address.city ?? null,\n region: address.region ?? null,\n postalCode: address.postalCode ?? null,\n country: address.country ?? null,\n latitude: address.latitude ?? null,\n longitude: address.longitude ?? null,\n }\n}\n\nfunction buildShippingMethodSnapshot(method?: SalesShippingMethod | null) {\n if (!method) return null\n return {\n id: method.id,\n code: method.code,\n name: method.name,\n providerKey: method.providerKey ?? null,\n serviceLevel: method.serviceLevel ?? null,\n estimatedTransitDays: method.estimatedTransitDays ?? null,\n baseRateNet: method.baseRateNet,\n baseRateGross: method.baseRateGross,\n currencyCode: method.currencyCode,\n metadata: method.metadata ?? null,\n }\n}\n\nfunction buildPaymentMethodSnapshot(method?: SalesPaymentMethod | null) {\n if (!method) return null\n return {\n id: method.id,\n code: method.code,\n name: method.name,\n providerKey: method.providerKey ?? null,\n terms: method.terms ?? null,\n metadata: method.metadata ?? null,\n }\n}\n\nfunction attachDocumentAddresses(\n em: EntityManager,\n scope: SeedScope,\n params: {\n documentId: string\n documentKind: 'order' | 'quote'\n addresses: ExampleAddress[]\n order?: SalesOrder\n quote?: SalesQuote\n }\n): void {\n const { documentId, documentKind, addresses, order, quote } = params\n for (const entry of addresses) {\n const now = new Date()\n const record = em.create(SalesDocumentAddress, {\n id: randomUUID(),\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n documentId,\n documentKind,\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n companyName: entry.companyName ?? null,\n purpose: entry.role,\n addressLine1: entry.addressLine1,\n addressLine2: entry.addressLine2 ?? null,\n city: entry.city ?? null,\n region: entry.region ?? null,\n postalCode: entry.postalCode ?? null,\n country: entry.country ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n buildingNumber: null,\n flatNumber: null,\n order: documentKind === 'order' ? order ?? null : null,\n quote: documentKind === 'quote' ? quote ?? null : null,\n createdAt: now,\n updatedAt: now,\n })\n em.persist(record)\n }\n}\n\nfunction attachNotes(\n em: EntityManager,\n scope: SeedScope,\n params: {\n contextId: string\n contextType: 'order' | 'quote'\n notes: ExampleNote[]\n order?: SalesOrder\n quote?: SalesQuote\n }\n) {\n const { contextId, contextType, notes, order, quote } = params\n for (const note of notes) {\n const record = em.create(SalesNote, {\n id: randomUUID(),\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n contextType,\n contextId,\n body: note.body,\n appearanceIcon: note.appearanceIcon ?? null,\n appearanceColor: note.appearanceColor ?? null,\n createdAt: note.createdAt ?? new Date(),\n updatedAt: note.createdAt ?? new Date(),\n })\n record.order = contextType === 'order' ? order ?? null : null\n record.quote = contextType === 'quote' ? quote ?? null : null\n em.persist(record)\n }\n}\n\nfunction mapPaymentStatus(outstanding: number): string | null {\n if (outstanding <= 0.01) return 'paid'\n if (outstanding > 0) return 'partial'\n return null\n}\n\nexport async function seedSalesExamples(\n em: EntityManager,\n container: AppContainer,\n scope: SeedScope\n): Promise<boolean> {\n const hasOrders =\n ORDER_SEEDS.length > 0\n ? await em.count(SalesOrder, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n orderNumber: { $in: ORDER_SEEDS.map((item) => item.orderNumber) as any },\n })\n : 0\n const hasQuotes =\n QUOTE_SEEDS.length > 0\n ? await em.count(SalesQuote, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n quoteNumber: { $in: QUOTE_SEEDS.map((item) => item.quoteNumber) as any },\n })\n : 0\n\n if (hasOrders > 0 || hasQuotes > 0) {\n return false\n }\n\n await seedSalesDictionaries(em, scope)\n const [shippingMethods, paymentMethods, channels] = await Promise.all([\n ensureExampleShippingMethods(em, scope, { skipFlush: true }),\n ensureExamplePaymentMethods(em, scope, { skipFlush: true }),\n ensureChannels(em, scope),\n ])\n await em.flush()\n const catalogLookups = await loadCatalogLookups(em, scope)\n const customerLookups = await loadCustomerLookups(em, scope, [...CUSTOMER_LINKS])\n\n const calculationService = container.resolve<SalesCalculationService>('salesCalculationService')\n\n for (const seed of QUOTE_SEEDS) {\n const quoteId = randomUUID()\n const customer = seed.customerKey ? customerLookups.get(seed.customerKey) ?? null : null\n if (seed.customerKey && !customer) {\n console.warn(`[sales.examples] Skipping quote ${seed.quoteNumber} because customer \"${seed.customerKey}\" is missing.`)\n continue\n }\n const shippingMethod = seed.shippingMethodCode\n ? shippingMethods.get(seed.shippingMethodCode.toLowerCase()) ?? null\n : null\n const paymentMethod = seed.paymentMethodCode\n ? paymentMethods.get(seed.paymentMethodCode.toLowerCase()) ?? null\n : null\n const channel = seed.channelCode ? channels.get(seed.channelCode.toLowerCase()) ?? null : null\n\n const lineSnapshots = seed.lines.map((line) => {\n const catalogRef = resolveCatalogLine(line, catalogLookups)\n if ((line.kind ?? 'product') === 'product' && !catalogRef.productId) {\n console.warn(\n `[sales.examples] Missing catalog match for quote line \"${line.name ?? line.variantSku ?? line.productHandle ?? 'unknown'}\".`\n )\n }\n const unitPriceNet = line.unitPriceNet ?? catalogRef.unitPriceNet ?? 0\n const unitPriceGross = line.unitPriceGross ?? catalogRef.unitPriceGross ?? unitPriceNet\n const currencyCode = catalogRef.currencyCode ?? seed.currencyCode\n const metadata: Record<string, unknown> = {}\n if (catalogRef.productThumbnail) metadata.productThumbnail = catalogRef.productThumbnail\n if (catalogRef.variantThumbnail) metadata.variantThumbnail = catalogRef.variantThumbnail\n return {\n id: randomUUID(),\n kind: line.kind ?? 'product',\n name: line.name,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n currencyCode,\n unitPriceNet,\n unitPriceGross,\n taxRate: line.taxRate ?? 0,\n discountPercent: line.discountPercent ?? null,\n productId: catalogRef.productId,\n productVariantId: catalogRef.variantId,\n catalogSnapshot: catalogRef.snapshot,\n metadata: Object.keys(metadata).length ? metadata : null,\n }\n })\n\n const adjustmentDrafts =\n seed.adjustments?.map((adj) => ({\n id: randomUUID(),\n scope: adj.scope,\n kind: adj.kind,\n code: adj.label ?? null,\n label: adj.label ?? null,\n rate: adj.rate ?? null,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross ?? adj.amountNet,\n currencyCode: seed.currencyCode,\n position: adj.position ?? 0,\n metadata: adj.lineIndex !== undefined ? { lineIndex: adj.lineIndex } : null,\n })) ?? []\n\n const calculation = await calculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n currencyCode: seed.currencyCode,\n },\n })\n\n const totals = calculation.totals\n const quoteNumber = seed.quoteNumber ?? `SQ-${quoteId.slice(0, 8).toUpperCase()}`\n const quote = em.create(SalesQuote, {\n id: quoteId,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n quoteNumber,\n status: seed.status ?? 'draft',\n customerEntityId: customer?.entity.id ?? null,\n customerContactId: customer?.contactId ?? null,\n customerSnapshot: customer?.snapshot ? toSnapshot(customer.snapshot) : null,\n currencyCode: seed.currencyCode,\n validFrom: seed.validFrom ?? null,\n validUntil: seed.validUntil ?? null,\n comments: seed.comments ?? null,\n shippingMethodId: shippingMethod?.id ?? null,\n shippingMethodCode: shippingMethod?.code ?? seed.shippingMethodCode ?? null,\n paymentMethodId: paymentMethod?.id ?? null,\n paymentMethodCode: paymentMethod?.code ?? seed.paymentMethodCode ?? null,\n channelId: channel?.id ?? null,\n shippingMethodSnapshot: buildShippingMethodSnapshot(shippingMethod),\n paymentMethodSnapshot: buildPaymentMethodSnapshot(paymentMethod),\n metadata: seed.metadata ?? { seed: 'sales.examples' },\n subtotalNetAmount: toAmount(totals.subtotalNetAmount),\n subtotalGrossAmount: toAmount(totals.subtotalGrossAmount),\n discountTotalAmount: toAmount(totals.discountTotalAmount),\n taxTotalAmount: toAmount(totals.taxTotalAmount),\n grandTotalNetAmount: toAmount(totals.grandTotalNetAmount),\n grandTotalGrossAmount: toAmount(totals.grandTotalGrossAmount),\n totalsSnapshot: toSnapshot(totals),\n lineItemCount: seed.lines.length,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(quote)\n\n calculation.lines.forEach((lineResult, idx) => {\n const source = lineSnapshots[idx]\n const line = em.create(SalesQuoteLine, {\n id: source.id,\n quote,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n lineNumber: idx + 1,\n kind: source.kind ?? 'product',\n name: source.name,\n description: source.description,\n comment: source.comment,\n quantity: toAmount(source.quantity),\n quantityUnit: source.quantityUnit ?? null,\n currencyCode: source.currencyCode,\n unitPriceNet: toAmount(source.unitPriceNet ?? 0),\n unitPriceGross: toAmount(source.unitPriceGross ?? source.unitPriceNet ?? 0),\n discountAmount: toAmount(lineResult.discountAmount),\n discountPercent:\n source.discountPercent !== null && source.discountPercent !== undefined\n ? toAmount(source.discountPercent)\n : '0',\n taxRate: toAmount(source.taxRate ?? 0),\n taxAmount: toAmount(lineResult.taxAmount),\n totalNetAmount: toAmount(lineResult.netAmount),\n totalGrossAmount: toAmount(lineResult.grossAmount),\n productId: source.productId ?? null,\n productVariantId: source.productVariantId ?? null,\n catalogSnapshot: source.catalogSnapshot ? toSnapshot(source.catalogSnapshot) : null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(line)\n })\n\n calculation.adjustments.forEach((adj, idx) => {\n const lineIndex = adj.metadata && typeof adj.metadata === 'object' ? (adj.metadata as any).lineIndex : null\n const lineRef =\n typeof lineIndex === 'number' && lineIndex >= 0 && lineIndex < seed.lines.length\n ? lineSnapshots[lineIndex]?.id ?? null\n : null\n const adjustment = em.create(SalesQuoteAdjustment, {\n id: adj.id ?? randomUUID(),\n quote,\n quoteLine: lineRef ? (lineRef as unknown as SalesQuoteLine) : null,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? adj.label ?? null,\n label: adj.label ?? adj.code ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate !== null && adj.rate !== undefined ? toAmount(adj.rate) : '0',\n amountNet: toAmount(adj.amountNet ?? 0),\n amountGross: toAmount(adj.amountGross ?? adj.amountNet ?? 0),\n currencyCode: adj.currencyCode ?? seed.currencyCode,\n metadata: adj.metadata ?? null,\n position: adj.position ?? idx,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(adjustment)\n })\n\n quote.subtotalNetAmount = toAmount(calculation.totals.subtotalNetAmount)\n quote.subtotalGrossAmount = toAmount(calculation.totals.subtotalGrossAmount)\n quote.discountTotalAmount = toAmount(calculation.totals.discountTotalAmount)\n quote.taxTotalAmount = toAmount(calculation.totals.taxTotalAmount)\n quote.grandTotalNetAmount = toAmount(calculation.totals.grandTotalNetAmount)\n quote.grandTotalGrossAmount = toAmount(calculation.totals.grandTotalGrossAmount)\n quote.totalsSnapshot = toSnapshot(calculation.totals)\n quote.lineItemCount = seed.lines.length\n\n const quoteAddresses = seed.addresses ?? customer?.addresses ?? []\n if (quoteAddresses.length) {\n attachDocumentAddresses(em, scope, {\n documentId: quoteId,\n documentKind: 'quote',\n addresses: quoteAddresses,\n quote,\n })\n const billing = quoteAddresses.find((a) => a.role === 'billing')\n const shipping = quoteAddresses.find((a) => a.role === 'shipping')\n quote.billingAddressId = billing?.customerAddressId ?? null\n quote.shippingAddressId = shipping?.customerAddressId ?? null\n quote.billingAddressSnapshot = billing ? buildAddressSnapshot(billing) : null\n quote.shippingAddressSnapshot = shipping ? buildAddressSnapshot(shipping) : null\n }\n if (seed.notes?.length) {\n attachNotes(em, scope, {\n contextId: quoteId,\n contextType: 'quote',\n notes: seed.notes,\n quote,\n })\n }\n }\n\n for (const seed of ORDER_SEEDS) {\n const orderId = randomUUID()\n const customer = seed.customerKey ? customerLookups.get(seed.customerKey) ?? null : null\n if (seed.customerKey && !customer) {\n console.warn(`[sales.examples] Skipping order ${seed.orderNumber} because customer \"${seed.customerKey}\" is missing.`)\n continue\n }\n const shippingMethod = seed.shippingMethodCode\n ? shippingMethods.get(seed.shippingMethodCode.toLowerCase()) ?? null\n : null\n const paymentMethod = seed.paymentMethodCode\n ? paymentMethods.get(seed.paymentMethodCode.toLowerCase()) ?? null\n : null\n const channel = seed.channelCode ? channels.get(seed.channelCode.toLowerCase()) ?? null : null\n\n const lineSnapshots = seed.lines.map((line) => {\n const catalogRef = resolveCatalogLine(line, catalogLookups)\n if ((line.kind ?? 'product') === 'product' && !catalogRef.productId) {\n console.warn(\n `[sales.examples] Missing catalog match for order line \"${line.name ?? line.variantSku ?? line.productHandle ?? 'unknown'}\".`\n )\n }\n const unitPriceNet = line.unitPriceNet ?? catalogRef.unitPriceNet ?? 0\n const unitPriceGross = line.unitPriceGross ?? catalogRef.unitPriceGross ?? unitPriceNet\n const currencyCode = catalogRef.currencyCode ?? seed.currencyCode\n const metadata: Record<string, unknown> = {}\n if (catalogRef.productThumbnail) metadata.productThumbnail = catalogRef.productThumbnail\n if (catalogRef.variantThumbnail) metadata.variantThumbnail = catalogRef.variantThumbnail\n return {\n id: randomUUID(),\n kind: line.kind ?? 'product',\n name: line.name,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n currencyCode,\n unitPriceNet,\n unitPriceGross,\n taxRate: line.taxRate ?? 0,\n discountPercent: line.discountPercent ?? null,\n productId: catalogRef.productId,\n productVariantId: catalogRef.variantId,\n catalogSnapshot: catalogRef.snapshot,\n metadata: Object.keys(metadata).length ? metadata : null,\n }\n })\n\n const adjustmentDrafts =\n seed.adjustments?.map((adj) => ({\n id: randomUUID(),\n scope: adj.scope,\n kind: adj.kind,\n code: adj.label ?? null,\n label: adj.label ?? null,\n rate: adj.rate ?? null,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross ?? adj.amountNet,\n currencyCode: seed.currencyCode,\n position: adj.position ?? 0,\n metadata: adj.lineIndex !== undefined ? { lineIndex: adj.lineIndex } : null,\n })) ?? []\n\n const calculation = await calculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n currencyCode: seed.currencyCode,\n },\n })\n\n const totals = calculation.totals\n const order = em.create(SalesOrder, {\n id: orderId,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n orderNumber: seed.orderNumber,\n status: seed.status ?? 'confirmed',\n fulfillmentStatus: seed.fulfillmentStatus ?? null,\n paymentStatus: seed.paymentStatus ?? null,\n customerEntityId: customer?.entity.id ?? null,\n customerContactId: customer?.contactId ?? null,\n customerSnapshot: customer?.snapshot ? toSnapshot(customer.snapshot) : null,\n currencyCode: seed.currencyCode,\n placedAt: seed.placedAt ?? null,\n expectedDeliveryAt: seed.expectedDeliveryAt ?? null,\n comments: seed.comments ?? null,\n internalNotes: seed.internalNotes ?? null,\n shippingMethodId: shippingMethod?.id ?? null,\n shippingMethodCode: shippingMethod?.code ?? seed.shippingMethodCode ?? null,\n paymentMethodId: paymentMethod?.id ?? null,\n paymentMethodCode: paymentMethod?.code ?? seed.paymentMethodCode ?? null,\n channelId: channel?.id ?? null,\n shippingMethodSnapshot: buildShippingMethodSnapshot(shippingMethod),\n paymentMethodSnapshot: buildPaymentMethodSnapshot(paymentMethod),\n metadata: seed.metadata ?? { seed: 'sales.examples' },\n subtotalNetAmount: toAmount(totals.subtotalNetAmount),\n subtotalGrossAmount: toAmount(totals.subtotalGrossAmount),\n discountTotalAmount: toAmount(totals.discountTotalAmount),\n taxTotalAmount: toAmount(totals.taxTotalAmount),\n shippingNetAmount: toAmount(totals.shippingNetAmount ?? 0),\n shippingGrossAmount: toAmount(totals.shippingGrossAmount ?? 0),\n surchargeTotalAmount: toAmount(totals.surchargeTotalAmount ?? 0),\n grandTotalNetAmount: toAmount(totals.grandTotalNetAmount),\n grandTotalGrossAmount: toAmount(totals.grandTotalGrossAmount),\n paidTotalAmount: toAmount(totals.paidTotalAmount ?? 0),\n refundedTotalAmount: toAmount(totals.refundedTotalAmount ?? 0),\n outstandingAmount: toAmount(totals.outstandingAmount ?? totals.grandTotalGrossAmount),\n totalsSnapshot: toSnapshot(totals),\n lineItemCount: seed.lines.length,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n\n const lineEntities: SalesOrderLine[] = []\n calculation.lines.forEach((lineResult, idx) => {\n const source = lineSnapshots[idx]\n const entity = em.create(SalesOrderLine, {\n id: source.id,\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n lineNumber: idx + 1,\n kind: source.kind ?? 'product',\n name: source.name,\n description: source.description,\n comment: source.comment,\n quantity: toAmount(source.quantity),\n quantityUnit: source.quantityUnit ?? null,\n reservedQuantity: '0',\n fulfilledQuantity: '0',\n invoicedQuantity: '0',\n returnedQuantity: '0',\n currencyCode: source.currencyCode,\n unitPriceNet: toAmount(source.unitPriceNet ?? 0),\n unitPriceGross: toAmount(source.unitPriceGross ?? source.unitPriceNet ?? 0),\n discountAmount: toAmount(lineResult.discountAmount),\n discountPercent:\n source.discountPercent !== null && source.discountPercent !== undefined\n ? toAmount(source.discountPercent)\n : '0',\n taxRate: toAmount(source.taxRate ?? 0),\n taxAmount: toAmount(lineResult.taxAmount),\n totalNetAmount: toAmount(lineResult.netAmount),\n totalGrossAmount: toAmount(lineResult.grossAmount),\n productId: source.productId ?? null,\n productVariantId: source.productVariantId ?? null,\n catalogSnapshot: source.catalogSnapshot ? toSnapshot(source.catalogSnapshot) : null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n lineEntities.push(entity)\n })\n\n calculation.adjustments.forEach((adj, idx) => {\n const lineIndex = adj.metadata && typeof adj.metadata === 'object' ? (adj.metadata as any).lineIndex : null\n const lineRef =\n typeof lineIndex === 'number' && lineIndex >= 0 && lineIndex < seed.lines.length\n ? lineEntities[lineIndex] ?? null\n : null\n const adjustment = em.create(SalesOrderAdjustment, {\n id: adj.id ?? randomUUID(),\n order,\n orderLine: lineRef,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? adj.label ?? null,\n label: adj.label ?? adj.code ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate !== null && adj.rate !== undefined ? toAmount(adj.rate) : '0',\n amountNet: toAmount(adj.amountNet ?? 0),\n amountGross: toAmount(adj.amountGross ?? adj.amountNet ?? 0),\n currencyCode: adj.currencyCode ?? seed.currencyCode,\n metadata: adj.metadata ?? null,\n position: adj.position ?? idx,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(adjustment)\n })\n\n order.subtotalNetAmount = toAmount(calculation.totals.subtotalNetAmount)\n order.subtotalGrossAmount = toAmount(calculation.totals.subtotalGrossAmount)\n order.discountTotalAmount = toAmount(calculation.totals.discountTotalAmount)\n order.taxTotalAmount = toAmount(calculation.totals.taxTotalAmount)\n order.shippingNetAmount = toAmount(calculation.totals.shippingNetAmount ?? 0)\n order.shippingGrossAmount = toAmount(calculation.totals.shippingGrossAmount ?? 0)\n order.surchargeTotalAmount = toAmount(calculation.totals.surchargeTotalAmount ?? 0)\n order.grandTotalNetAmount = toAmount(calculation.totals.grandTotalNetAmount)\n order.grandTotalGrossAmount = toAmount(calculation.totals.grandTotalGrossAmount)\n order.paidTotalAmount = toAmount(calculation.totals.paidTotalAmount ?? 0)\n order.refundedTotalAmount = toAmount(calculation.totals.refundedTotalAmount ?? 0)\n order.outstandingAmount = toAmount(calculation.totals.outstandingAmount ?? calculation.totals.grandTotalGrossAmount)\n order.totalsSnapshot = toSnapshot(calculation.totals)\n order.lineItemCount = seed.lines.length\n\n const lineMap = new Map(lineEntities.map((line) => [line.id, line]))\n if (seed.shipments?.length) {\n for (const shipmentSeed of seed.shipments) {\n const shipment = em.create(SalesShipment, {\n id: randomUUID(),\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n shipmentNumber: shipmentSeed.shipmentNumber ?? null,\n shippingMethodId: shipmentSeed.methodCode\n ? shippingMethods.get(shipmentSeed.methodCode.toLowerCase())?.id ?? null\n : null,\n status: shipmentSeed.status ?? null,\n carrierName: null,\n trackingNumbers: shipmentSeed.trackingNumbers ?? null,\n shippedAt: shipmentSeed.shippedAt ?? null,\n deliveredAt: shipmentSeed.deliveredAt ?? null,\n weightValue: shipmentSeed.weightKg ? toAmount(shipmentSeed.weightKg) : null,\n weightUnit: shipmentSeed.weightKg ? 'kg' : null,\n declaredValueNet: shipmentSeed.declaredValue ? toAmount(shipmentSeed.declaredValue) : null,\n declaredValueGross: shipmentSeed.declaredValue ? toAmount(shipmentSeed.declaredValue) : null,\n currencyCode: shipmentSeed.currencyCode ?? seed.currencyCode,\n notesText: shipmentSeed.notes ?? null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(shipment)\n\n const shipmentItems: SalesShipmentItem[] = []\n for (const item of shipmentSeed.items) {\n const line = lineEntities[item.lineIndex]\n if (!line) continue\n line.fulfilledQuantity = toAmount(\n Number(line.fulfilledQuantity ?? '0') + Math.max(item.quantity, 0)\n )\n const shipmentItem = em.create(SalesShipmentItem, {\n id: randomUUID(),\n shipment,\n orderLine: line,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n quantity: toAmount(item.quantity),\n metadata: null,\n })\n shipmentItems.push(shipmentItem)\n em.persist(shipmentItem)\n }\n await refreshShipmentItemsSnapshot(em, shipment, { items: shipmentItems, lineMap })\n }\n }\n\n let paymentTotal = 0\n if (seed.payments?.length) {\n for (const paymentSeed of seed.payments) {\n paymentTotal += paymentSeed.amount\n const method = paymentSeed.methodCode\n ? paymentMethods.get(paymentSeed.methodCode.toLowerCase()) ?? null\n : paymentMethod\n const payment = em.create(SalesPayment, {\n id: randomUUID(),\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n paymentMethod: method ?? null,\n paymentReference: paymentSeed.reference ?? null,\n status: paymentSeed.status ?? null,\n amount: toAmount(paymentSeed.amount),\n currencyCode: paymentSeed.currencyCode,\n capturedAmount: toAmount(paymentSeed.capturedAt ? paymentSeed.amount : 0),\n refundedAmount: '0',\n receivedAt: paymentSeed.receivedAt ?? null,\n capturedAt: paymentSeed.capturedAt ?? null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(payment)\n const allocation = em.create(SalesPaymentAllocation, {\n id: randomUUID(),\n payment,\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n amount: toAmount(paymentSeed.amount),\n currencyCode: paymentSeed.currencyCode,\n metadata: null,\n })\n em.persist(allocation)\n }\n }\n\n const orderAddresses = seed.addresses ?? customer?.addresses ?? []\n if (orderAddresses.length) {\n attachDocumentAddresses(em, scope, {\n documentId: orderId,\n documentKind: 'order',\n addresses: orderAddresses,\n order,\n })\n const billing = orderAddresses.find((a) => a.role === 'billing')\n const shipping = orderAddresses.find((a) => a.role === 'shipping')\n order.billingAddressId = billing?.customerAddressId ?? null\n order.shippingAddressId = shipping?.customerAddressId ?? null\n order.billingAddressSnapshot = billing ? buildAddressSnapshot(billing) : null\n order.shippingAddressSnapshot = shipping ? buildAddressSnapshot(shipping) : null\n }\n if (seed.notes?.length) {\n attachNotes(em, scope, {\n contextId: orderId,\n contextType: 'order',\n notes: seed.notes,\n order,\n })\n }\n\n const grandTotal = Number(order.grandTotalGrossAmount ?? '0')\n order.paidTotalAmount = toAmount(paymentTotal)\n order.outstandingAmount = toAmount(Math.max(grandTotal - paymentTotal, 0))\n order.paymentStatus = seed.paymentStatus ?? mapPaymentStatus(grandTotal - paymentTotal)\n const isFullyFulfilled = lineEntities.every((line, idx) => {\n const expected = Number(seed.lines[idx]?.quantity ?? 0)\n const fulfilled = Number(line.fulfilledQuantity ?? '0')\n return fulfilled >= expected\n })\n order.fulfillmentStatus = seed.fulfillmentStatus ?? (isFullyFulfilled ? 'fulfilled' : 'in_fulfillment')\n }\n\n await em.flush()\n return true\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAG3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,6BAA6B;AACtC,SAAS,oCAAoC;AAC7C,SAAS,uBAAuB;AAEhC,SAAS,6BAA6B,oCAAoD;AAC1F;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAmHnC,MAAM,gBAAgB;AAAA,EACpB,EAAE,MAAM,UAAU,MAAM,gBAAgB,aAAa,uCAAuC;AAAA,EAC5F;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,aAAa;AAAA,EACf;AACF;AAEA,MAAM,iBAAmC;AAAA,EACvC,EAAE,KAAK,cAAc,aAAa,mBAAmB;AAAA,EACrD,EAAE,KAAK,cAAc,aAAa,uBAAuB;AAAA,EACzD,EAAE,KAAK,cAAc,aAAa,wBAAwB;AAC5D;AAEA,MAAM,cAA8B;AAAA,EAClC;AAAA,IACE,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,WAAW,YAAY,EAAE;AAAA,IACzB,YAAY,YAAY,EAAE;AAAA,IAC1B,cAAc;AAAA,IACd,oBAAoB;AAAA,IACpB,mBAAmB;AAAA,IACnB,aAAa;AAAA,IACb,OAAO;AAAA,MACL;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,QACV,cAAc;AAAA,QACd,SAAS;AAAA,MACX;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;A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AAM,oBAAoB,SAAS,KAAK,IAAI,aAAa,cAAc,CAAC,CAAC;AACzE,UAAM,gBAAgB,KAAK,iBAAiB,iBAAiB,aAAa,YAAY;AACtF,UAAM,mBAAmB,aAAa,MAAM,CAAC,MAAM,QAAQ;AACzD,YAAM,WAAW,OAAO,KAAK,MAAM,GAAG,GAAG,YAAY,CAAC;AACtD,YAAM,YAAY,OAAO,KAAK,qBAAqB,GAAG;AACtD,aAAO,aAAa;AAAA,IACtB,CAAC;AACD,UAAM,oBAAoB,KAAK,sBAAsB,mBAAmB,cAAc;AAAA,EACxF;AAEA,QAAM,GAAG,MAAM;AACf,SAAO;AACT;",
|
|
4
|
+
"sourcesContent": ["import { randomUUID } from 'crypto'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AppContainer } from '@open-mercato/shared/lib/di/container'\nimport {\n SalesOrder,\n SalesOrderLine,\n SalesOrderAdjustment,\n SalesQuote,\n SalesQuoteLine,\n SalesQuoteAdjustment,\n SalesShipment,\n SalesShipmentItem,\n SalesPayment,\n SalesPaymentAllocation,\n SalesDocumentAddress,\n SalesNote,\n SalesChannel,\n SalesPaymentMethod,\n SalesShippingMethod,\n type SalesAdjustmentKind,\n type SalesLineKind,\n} from '../data/entities'\nimport { seedSalesDictionaries } from '../lib/dictionaries'\nimport { refreshShipmentItemsSnapshot } from '../lib/shipments/snapshots'\nimport { toNumericString } from '../commands/shared'\nimport type { SalesCalculationService } from '../services/salesCalculationService'\nimport { ensureExamplePaymentMethods, ensureExampleShippingMethods, type SeedScope } from './examples-data'\nimport {\n CatalogProduct,\n CatalogProductPrice,\n CatalogProductVariant,\n} from '@open-mercato/core/modules/catalog/data/entities'\nimport {\n CustomerAddress,\n CustomerEntity,\n CustomerPersonProfile,\n} from '@open-mercato/core/modules/customers/data/entities'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\n\ntype ExampleAddress = {\n role: 'billing' | 'shipping'\n companyName?: string | null\n name?: string | null\n addressLine1: string\n addressLine2?: string | null\n city?: string | null\n region?: string | null\n postalCode?: string | null\n country?: string | null\n latitude?: number | null\n longitude?: number | null\n customerAddressId?: string | null\n}\n\ntype ExampleLine = {\n kind?: SalesLineKind\n name: string\n description?: string\n quantity: number\n unitPriceNet: number\n unitPriceGross?: number\n taxRate?: number\n discountPercent?: number\n quantityUnit?: string\n comment?: string\n productHandle?: string\n variantSku?: string\n}\n\ntype ExampleAdjustment = {\n scope: 'order' | 'line'\n kind: SalesAdjustmentKind\n label?: string\n amountNet: number\n amountGross?: number\n rate?: number\n lineIndex?: number\n position?: number\n}\n\ntype ExampleNote = {\n body: string\n createdAt?: Date\n appearanceIcon?: string | null\n appearanceColor?: string | null\n}\n\ntype ExampleShipment = {\n shipmentNumber?: string\n methodCode?: string\n status?: string\n shippedAt?: Date\n deliveredAt?: Date\n trackingNumbers?: string[]\n weightKg?: number\n declaredValue?: number\n currencyCode?: string\n notes?: string\n items: Array<{ lineIndex: number; quantity: number }>\n}\n\ntype ExamplePayment = {\n reference?: string\n methodCode?: string\n status?: string\n amount: number\n currencyCode: string\n receivedAt?: Date\n capturedAt?: Date\n}\n\ntype ExampleQuote = {\n quoteNumber: string\n status?: string\n comments?: string\n validFrom?: Date\n validUntil?: Date\n currencyCode: string\n shippingMethodCode?: string\n paymentMethodCode?: string\n addresses?: ExampleAddress[]\n lines: ExampleLine[]\n adjustments?: ExampleAdjustment[]\n notes?: ExampleNote[]\n metadata?: Record<string, unknown>\n channelCode?: string\n customerKey?: string\n}\n\ntype ExampleOrder = {\n orderNumber: string\n status?: string\n fulfillmentStatus?: string\n paymentStatus?: string\n comments?: string\n internalNotes?: string\n placedAt?: Date\n expectedDeliveryAt?: Date\n currencyCode: string\n shippingMethodCode?: string\n paymentMethodCode?: string\n channelCode?: string\n addresses?: ExampleAddress[]\n lines: ExampleLine[]\n adjustments?: ExampleAdjustment[]\n notes?: ExampleNote[]\n shipments?: ExampleShipment[]\n payments?: ExamplePayment[]\n metadata?: Record<string, unknown>\n customerKey?: string\n}\n\nconst CHANNEL_SEEDS = [\n { code: 'online', name: 'Online Store', description: 'Orders captured from the storefront.' },\n {\n code: 'field-sales',\n name: 'Field Sales',\n description: 'Quotes negotiated by the sales team and converted offline.',\n },\n] as const\n\nconst CUSTOMER_LINKS: CustomerLookup[] = [\n { key: 'brightside', displayName: 'Brightside Solar' },\n { key: 'harborview', displayName: 'Harborview Analytics' },\n { key: 'copperleaf', displayName: 'Copperleaf Design Co.' },\n] as const\n\nconst QUOTE_SEEDS: ExampleQuote[] = [\n {\n quoteNumber: 'SQ-DEMO-1001',\n status: 'draft',\n comments: 'Pricing reflects bundled onboarding; valid for 30 days.',\n validFrom: daysFromNow(-2),\n validUntil: daysFromNow(28),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n lines: [\n {\n name: 'Remote onboarding package',\n description: 'Kick-off, workflow design, and training for distributed teams.',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 10,\n },\n {\n name: 'Implementation workshop (4h)',\n description: 'Hands-on configuration session with stakeholders.',\n quantity: 1,\n unitPriceNet: 320,\n taxRate: 0,\n comment: 'Can be split into two shorter sessions on request.',\n },\n ],\n adjustments: [\n { scope: 'order', kind: 'discount', label: 'Pilot discount', amountNet: 45, position: 1 },\n {\n scope: 'order',\n kind: 'shipping',\n label: 'Expedited shipping',\n amountNet: 25,\n amountGross: 27.5,\n position: 2,\n },\n ],\n addresses: [\n {\n role: 'billing',\n companyName: 'Northwind Ventures',\n name: 'Nora Winters',\n addressLine1: '200 Pine St',\n addressLine2: 'Suite 900',\n city: 'Seattle',\n region: 'WA',\n postalCode: '98101',\n country: 'US',\n },\n {\n role: 'shipping',\n companyName: 'Northwind Ventures',\n name: 'Receiving Dock',\n addressLine1: '4124 4th Ave S',\n city: 'Seattle',\n region: 'WA',\n postalCode: '98134',\n country: 'US',\n },\n ],\n notes: [\n {\n body: 'Requested weekend training option if schedules slip.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:calendar-clock',\n appearanceColor: '#0ea5e9',\n },\n {\n body: 'Prefers invoicing after acceptance instead of deposit.',\n createdAt: daysFromNow(0),\n appearanceIcon: 'lucide:receipt',\n appearanceColor: '#f97316',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n quoteNumber: 'SQ-DEMO-1002',\n status: 'draft',\n comments: 'Footwear replenishment and event outfits pulled from catalog offers.',\n validFrom: daysFromNow(-1),\n validUntil: daysFromNow(21),\n currencyCode: 'USD',\n shippingMethodCode: 'standard-ground',\n paymentMethodCode: 'card',\n channelCode: 'online',\n customerKey: 'brightside',\n lines: [\n {\n name: 'Atlas Runner Sneaker',\n quantity: 3,\n unitPriceNet: 120,\n taxRate: 10,\n variantSku: 'ATLAS-RUN-NAVY-8',\n },\n {\n name: 'Aurora Wrap Dress',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 10,\n variantSku: 'AURORA-ROSE-M',\n discountPercent: 5,\n },\n ],\n adjustments: [\n { scope: 'order', kind: 'discount', label: 'Preferred customer', amountNet: 35, position: 1 },\n ],\n notes: [\n {\n body: 'Requested quick turn on delivery dates for press shoot.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:camera',\n appearanceColor: '#0ea5e9',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n quoteNumber: 'SQ-DEMO-1003',\n status: 'sent',\n comments: 'Bundle of apparel and on-site styling block for the studio launch.',\n validFrom: daysFromNow(-3),\n validUntil: daysFromNow(10),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n customerKey: 'copperleaf',\n lines: [\n {\n name: 'Aurora Wrap Dress',\n quantity: 2,\n unitPriceNet: 180,\n taxRate: 10,\n variantSku: 'AURORA-CELESTIAL-L',\n comment: 'Alternate colorway accepted if Celestial runs out.',\n },\n {\n name: 'Signature Haircut & Finish',\n quantity: 4,\n unitPriceNet: 95,\n taxRate: 0,\n variantSku: 'SERV-HAIR-60',\n quantityUnit: 'hour',\n comment: 'Styling sessions during opening week.',\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'discount',\n label: 'Launch partner credit',\n amountNet: 60,\n position: 1,\n },\n ],\n notes: [\n {\n body: 'Prefers consolidated invoicing after the event.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:file-text',\n appearanceColor: '#f97316',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n]\n\nconst ORDER_SEEDS: ExampleOrder[] = [\n {\n orderNumber: 'SO-DEMO-2001',\n status: 'confirmed',\n fulfillmentStatus: 'in_fulfillment',\n comments: 'White-glove delivery requested for the larger items.',\n internalNotes: 'Coordinate with facilities for access badges.',\n placedAt: daysFromNow(-3),\n expectedDeliveryAt: daysFromNow(4),\n currencyCode: 'USD',\n shippingMethodCode: 'standard-ground',\n paymentMethodCode: 'card',\n channelCode: 'online',\n lines: [\n {\n name: 'Modular desk system',\n quantity: 1,\n unitPriceNet: 640,\n taxRate: 10,\n description: 'Corner configuration with cable routing.',\n },\n {\n name: 'Acoustic panel set',\n quantity: 3,\n unitPriceNet: 85,\n taxRate: 10,\n description: 'Charcoal grey finish, adhesive mount.',\n discountPercent: 5,\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'shipping',\n label: 'White-glove delivery',\n amountNet: 60,\n amountGross: 66,\n position: 1,\n },\n { scope: 'order', kind: 'discount', label: 'New office promo', amountNet: 75, position: 2 },\n {\n scope: 'order',\n kind: 'surcharge',\n label: 'After-hours install',\n amountNet: 35,\n amountGross: 38.5,\n position: 3,\n },\n ],\n shipments: [\n {\n shipmentNumber: 'SHIP-2001-1',\n methodCode: 'standard-ground',\n status: 'shipped',\n shippedAt: daysFromNow(-1),\n trackingNumbers: ['1Z-234-ACOUSTICS'],\n weightKg: 38,\n declaredValue: 720,\n currencyCode: 'USD',\n notes: 'Panels shipped separately to avoid freight delay.',\n items: [\n { lineIndex: 1, quantity: 2 },\n ],\n },\n {\n shipmentNumber: 'SHIP-2001-2',\n methodCode: 'express-air',\n status: 'in_transit',\n shippedAt: daysFromNow(0),\n trackingNumbers: ['1Z-987-DESK'],\n weightKg: 72,\n declaredValue: 560,\n currencyCode: 'USD',\n notes: 'Desk ships via express due to size.',\n items: [{ lineIndex: 0, quantity: 1 }],\n },\n ],\n payments: [\n {\n reference: 'AUTH-2001-CC',\n methodCode: 'card',\n status: 'captured',\n amount: 600,\n currencyCode: 'USD',\n receivedAt: daysFromNow(-2),\n capturedAt: daysFromNow(-1),\n },\n {\n reference: 'WIRE-2001',\n methodCode: 'bank-transfer',\n status: 'received',\n amount: 414,\n currencyCode: 'USD',\n receivedAt: daysFromNow(1),\n },\n ],\n addresses: [\n {\n role: 'billing',\n companyName: 'Harborview Analytics',\n name: 'Accounts Payable',\n addressLine1: '355 Atlantic Ave Floor 6',\n city: 'Boston',\n region: 'MA',\n postalCode: '02210',\n country: 'US',\n },\n {\n role: 'shipping',\n companyName: 'Harborview Analytics',\n name: 'Loading Dock',\n addressLine1: '9 Drydock Ave',\n city: 'Boston',\n region: 'MA',\n postalCode: '02210',\n country: 'US',\n },\n ],\n notes: [\n {\n body: 'Facilities requested 2-hour delivery window notice.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:bell-ring',\n appearanceColor: '#0ea5e9',\n },\n {\n body: 'Panels can be staged in conference room A.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:warehouse',\n appearanceColor: '#22c55e',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n orderNumber: 'SO-DEMO-2002',\n status: 'confirmed',\n fulfillmentStatus: 'fulfilled',\n paymentStatus: 'partial',\n comments: 'Subscription setup aligns with fiscal Q3 start.',\n placedAt: daysFromNow(-6),\n expectedDeliveryAt: daysFromNow(1),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n lines: [\n {\n name: 'On-site enablement',\n quantity: 1,\n unitPriceNet: 280,\n taxRate: 0,\n description: 'Day of workshops across two teams.',\n },\n {\n name: 'Support retainer (Q3)',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 0,\n description: 'Response SLA with named TAM.',\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'shipping',\n label: 'Travel & lodging',\n amountNet: 20,\n amountGross: 22,\n position: 1,\n },\n {\n scope: 'order',\n kind: 'discount',\n label: 'Multi-team starter',\n amountNet: 25,\n position: 2,\n },\n ],\n shipments: [\n {\n shipmentNumber: 'SHIP-2002-1',\n methodCode: 'express-air',\n status: 'delivered',\n shippedAt: daysFromNow(-4),\n deliveredAt: daysFromNow(-2),\n trackingNumbers: ['AIR-22002-KIT'],\n declaredValue: 150,\n currencyCode: 'USD',\n notes: 'Enablement kit delivered to training room.',\n items: [\n { lineIndex: 0, quantity: 1 },\n { lineIndex: 1, quantity: 1 },\n ],\n },\n ],\n payments: [\n {\n reference: 'WIRE-2002',\n methodCode: 'bank-transfer',\n status: 'received',\n amount: 250,\n currencyCode: 'USD',\n receivedAt: daysFromNow(-1),\n },\n ],\n addresses: [\n {\n role: 'billing',\n companyName: 'Brightside Solar',\n name: 'Finance',\n addressLine1: '245 Market St Suite 400',\n city: 'San Francisco',\n region: 'CA',\n postalCode: '94105',\n country: 'US',\n },\n {\n role: 'shipping',\n companyName: 'Brightside Solar',\n name: 'Training Room B',\n addressLine1: '245 Market St Suite 410',\n city: 'San Francisco',\n region: 'CA',\n postalCode: '94105',\n country: 'US',\n },\n ],\n notes: [\n {\n body: 'TAM onboarding scheduled next Tuesday.',\n createdAt: daysFromNow(-3),\n appearanceIcon: 'lucide:users',\n appearanceColor: '#a855f7',\n },\n {\n body: 'Retainer renewal review in mid-Q4.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:clock-3',\n appearanceColor: '#f97316',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n orderNumber: 'SO-DEMO-2003',\n status: 'confirmed',\n fulfillmentStatus: 'in_fulfillment',\n paymentStatus: 'partial',\n comments: 'Equipment refresh for analytics field team with matching footwear.',\n internalNotes: 'Coordinate delivery around team offsite schedule.',\n placedAt: daysFromNow(-2),\n expectedDeliveryAt: daysFromNow(5),\n currencyCode: 'USD',\n shippingMethodCode: 'standard-ground',\n paymentMethodCode: 'card',\n channelCode: 'online',\n customerKey: 'harborview',\n lines: [\n {\n name: 'Atlas Runner Sneaker',\n quantity: 4,\n unitPriceNet: 120,\n taxRate: 10,\n variantSku: 'ATLAS-RUN-GLACIER-10',\n comment: 'Size mix handled via catalog variants.',\n },\n {\n name: 'Aurora Wrap Dress',\n quantity: 1,\n unitPriceNet: 180,\n taxRate: 10,\n variantSku: 'AURORA-ROSE-M',\n discountPercent: 10,\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'shipping',\n label: 'Ground shipping',\n amountNet: 25,\n amountGross: 27.5,\n position: 1,\n },\n ],\n shipments: [\n {\n shipmentNumber: 'SHIP-2003-1',\n methodCode: 'standard-ground',\n status: 'pending',\n shippedAt: undefined,\n trackingNumbers: [],\n weightKg: 12,\n declaredValue: 0,\n currencyCode: 'USD',\n notes: 'Bundle footwear and apparel together.',\n items: [\n { lineIndex: 0, quantity: 4 },\n { lineIndex: 1, quantity: 1 },\n ],\n },\n ],\n payments: [\n {\n reference: 'CARD-2003',\n methodCode: 'card',\n status: 'authorized',\n amount: 300,\n currencyCode: 'USD',\n receivedAt: daysFromNow(-1),\n },\n ],\n notes: [\n {\n body: 'Leadership wants tracking shared in Slack channel.',\n createdAt: daysFromNow(-1),\n appearanceIcon: 'lucide:message-circle',\n appearanceColor: '#22c55e',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n {\n orderNumber: 'SO-DEMO-2004',\n status: 'confirmed',\n fulfillmentStatus: 'pending',\n paymentStatus: 'unpaid',\n comments: 'On-site styling block for studio launch week.',\n placedAt: daysFromNow(-4),\n expectedDeliveryAt: daysFromNow(1),\n currencyCode: 'USD',\n shippingMethodCode: 'express-air',\n paymentMethodCode: 'bank-transfer',\n channelCode: 'field-sales',\n customerKey: 'copperleaf',\n lines: [\n {\n name: 'Signature Haircut & Finish',\n quantity: 6,\n unitPriceNet: 95,\n taxRate: 0,\n variantSku: 'SERV-HAIR-60',\n quantityUnit: 'hour',\n comment: 'Block book stylists for staggered sessions.',\n },\n ],\n adjustments: [\n {\n scope: 'order',\n kind: 'discount',\n label: 'Launch week courtesy',\n amountNet: 45,\n position: 1,\n },\n ],\n payments: [\n {\n reference: 'WIRE-2004',\n methodCode: 'bank-transfer',\n status: 'pending',\n amount: 0,\n currencyCode: 'USD',\n },\n ],\n notes: [\n {\n body: 'Confirm stylist roster by Friday.',\n createdAt: daysFromNow(-2),\n appearanceIcon: 'lucide:check-circle',\n appearanceColor: '#0ea5e9',\n },\n ],\n metadata: { seed: 'sales.examples' },\n },\n]\n\nfunction daysFromNow(offset: number): Date {\n const now = new Date()\n const copy = new Date(now)\n copy.setUTCDate(now.getUTCDate() + offset)\n return copy\n}\n\nfunction toAmount(value: number | null | undefined): string {\n if (value === null || value === undefined || Number.isNaN(value)) return '0'\n return toNumericString(Math.round((value + Number.EPSILON) * 10000) / 10000) ?? '0'\n}\n\nfunction toSnapshot<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T\n}\n\nfunction normalizeKey(value: string | null | undefined): string {\n return (value ?? '').trim().toLowerCase()\n}\n\nfunction asNumber(value: unknown): number {\n if (typeof value === 'number') return value\n if (typeof value === 'string') {\n const parsed = Number(value)\n return Number.isFinite(parsed) ? parsed : 0\n }\n return 0\n}\n\ntype CatalogLookup = {\n productsByHandle: Map<string, CatalogProduct>\n variantsBySku: Map<string, CatalogProductVariant>\n variantPrices: Map<string, { net: number; gross: number; currency: string }>\n}\n\nasync function loadCatalogLookups(em: EntityManager, scope: SeedScope): Promise<CatalogLookup> {\n const [products, variants, prices] = await Promise.all([\n em.find(CatalogProduct, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n }),\n em.find(\n CatalogProductVariant,\n { organizationId: scope.organizationId, tenantId: scope.tenantId, deletedAt: null },\n { populate: ['product'] }\n ),\n em.find(CatalogProductPrice, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n }),\n ])\n\n const productsByHandle = new Map<string, CatalogProduct>()\n products.forEach((product) => {\n const key = normalizeKey(product.handle ?? product.sku ?? product.title)\n if (key) productsByHandle.set(key, product)\n })\n\n const variantsBySku = new Map<string, CatalogProductVariant>()\n variants.forEach((variant) => {\n const key = normalizeKey(variant.sku)\n if (key) variantsBySku.set(key, variant)\n })\n\n const variantPrices = new Map<string, { net: number; gross: number; currency: string }>()\n for (const price of prices) {\n const variantId =\n typeof price.variant === 'string' ? price.variant : price.variant?.id ?? (price as any)?.variant_id ?? null\n if (!variantId) continue\n const gross = asNumber((price as any).unitPriceGross ?? price.unitPriceGross)\n const net = asNumber((price as any).unitPriceNet ?? price.unitPriceNet ?? gross)\n const currency = typeof price.currencyCode === 'string' ? price.currencyCode : 'USD'\n const isSale = normalizeKey((price as any).kind) === 'sale' || normalizeKey((price as any)?.priceKind?.code) === 'sale'\n const existing = variantPrices.get(variantId)\n if (!existing || isSale) {\n variantPrices.set(variantId, { net, gross, currency })\n }\n }\n\n return { productsByHandle, variantsBySku, variantPrices }\n}\n\nfunction buildCatalogSnapshot(\n product: CatalogProduct | null,\n variant: CatalogProductVariant | null,\n price: { net: number; gross: number; currency: string } | null\n): Record<string, unknown> | null {\n if (!product) return null\n const productThumbnail =\n (product as any).defaultMediaUrl ??\n (product as any).thumbnailUrl ??\n (product.metadata && typeof product.metadata === 'object'\n ? ((product.metadata as any).thumbnailUrl as string | null | undefined)\n : null) ??\n null\n const variantThumbnail =\n variant && variant.metadata && typeof variant.metadata === 'object'\n ? ((variant.metadata as any).thumbnailUrl as string | null | undefined) ?? null\n : null\n return {\n product: {\n id: product.id,\n title: product.title,\n handle: product.handle ?? null,\n sku: product.sku ?? null,\n thumbnailUrl: productThumbnail,\n },\n variant: variant\n ? {\n id: variant.id,\n name: variant.name ?? product.title,\n sku: variant.sku ?? null,\n optionValues: variant.optionValues ?? null,\n thumbnailUrl: variantThumbnail,\n }\n : null,\n price: price\n ? {\n currencyCode: price.currency,\n unitPriceNet: price.net,\n unitPriceGross: price.gross,\n }\n : null,\n }\n}\n\nfunction resolveCatalogLine(\n line: ExampleLine,\n catalog: CatalogLookup\n): {\n productId: string | null\n variantId: string | null\n unitPriceNet: number | null\n unitPriceGross: number | null\n currencyCode: string | null\n snapshot: Record<string, unknown> | null\n productThumbnail: string | null\n variantThumbnail: string | null\n} {\n const variant =\n line.variantSku && catalog.variantsBySku.size\n ? catalog.variantsBySku.get(normalizeKey(line.variantSku))\n : null\n const product =\n variant?.product ??\n (line.productHandle ? catalog.productsByHandle.get(normalizeKey(line.productHandle)) ?? null : null)\n const price = variant ? catalog.variantPrices.get(variant.id) ?? null : null\n const snapshot = buildCatalogSnapshot(product ?? null, variant ?? null, price ?? null)\n const productThumbnail =\n (snapshot as any)?.product?.thumbnailUrl ??\n (product as any)?.defaultMediaUrl ??\n (product as any)?.thumbnailUrl ??\n null\n const variantThumbnail = (snapshot as any)?.variant?.thumbnailUrl ?? null\n return {\n productId: product ? product.id : null,\n variantId: variant ? variant.id : null,\n unitPriceNet: price?.net ?? null,\n unitPriceGross: price?.gross ?? null,\n currencyCode: price?.currency ?? null,\n snapshot,\n productThumbnail: productThumbnail ?? null,\n variantThumbnail: variantThumbnail ?? null,\n }\n}\n\ntype CustomerLookup = {\n key: string\n displayName: string\n}\n\ntype CustomerLookupSpec = CustomerLookup & { normalizedName: string }\n\ntype CustomerContext = {\n entity: CustomerEntity\n contact: CustomerPersonProfile | null\n contactId: string | null\n snapshot: Record<string, unknown> | null\n addresses: ExampleAddress[]\n}\n\nfunction buildCustomerSnapshot(\n entity: CustomerEntity,\n contact: CustomerPersonProfile | null\n): Record<string, unknown> | null {\n const base = {\n id: entity.id,\n kind: entity.kind,\n displayName: entity.displayName,\n primaryEmail: entity.primaryEmail ?? null,\n primaryPhone: entity.primaryPhone ?? null,\n personProfile: entity.personProfile\n ? {\n id: entity.personProfile.id,\n firstName: entity.personProfile.firstName ?? null,\n lastName: entity.personProfile.lastName ?? null,\n preferredName: entity.personProfile.preferredName ?? null,\n jobTitle: entity.personProfile.jobTitle ?? null,\n department: entity.personProfile.department ?? null,\n seniority: entity.personProfile.seniority ?? null,\n timezone: entity.personProfile.timezone ?? null,\n }\n : null,\n companyProfile: entity.companyProfile\n ? {\n id: entity.companyProfile.id,\n legalName: entity.companyProfile.legalName ?? null,\n brandName: entity.companyProfile.brandName ?? null,\n domain: entity.companyProfile.domain ?? null,\n websiteUrl: entity.companyProfile.websiteUrl ?? null,\n }\n : null,\n }\n const contactSnapshot = contact\n ? {\n id: contact.id,\n firstName: contact.firstName ?? null,\n lastName: contact.lastName ?? null,\n email: contact.entity?.primaryEmail ?? null,\n phone: contact.entity?.primaryPhone ?? null,\n companyId: contact.company ? (typeof contact.company === 'string' ? contact.company : contact.company.id) : null,\n }\n : null\n return { customer: base, contact: contactSnapshot }\n}\n\nfunction toExampleAddresses(customer: CustomerEntity, address: CustomerAddress | null): ExampleAddress[] {\n if (!address) return []\n const base = {\n companyName: address.companyName ?? customer.displayName ?? null,\n name: address.name ?? address.companyName ?? customer.displayName ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n city: address.city ?? null,\n region: address.region ?? null,\n postalCode: address.postalCode ?? null,\n country: address.country ?? null,\n latitude: address.latitude ?? null,\n longitude: address.longitude ?? null,\n customerAddressId: address.id,\n }\n return [\n { role: 'billing', ...base },\n { role: 'shipping', ...base },\n ]\n}\n\nasync function loadCustomerLookups(\n em: EntityManager,\n scope: SeedScope,\n lookups: CustomerLookup[]\n): Promise<Map<string, CustomerContext>> {\n const map = new Map<string, CustomerContext>()\n if (lookups.length === 0) return map\n const lookupSpecs: CustomerLookupSpec[] = lookups.map((lookup) => ({\n ...lookup,\n normalizedName: normalizeKey(lookup.displayName),\n }))\n const unresolved = new Map<string, CustomerLookupSpec>()\n for (const spec of lookupSpecs) {\n unresolved.set(spec.key, spec)\n }\n\n const customers = await findWithDecryption(\n em,\n CustomerEntity,\n {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n { populate: ['personProfile', 'companyProfile'] },\n { tenantId: scope.tenantId, organizationId: scope.organizationId }\n )\n\n const doesMatch = (candidate: string, spec: CustomerLookupSpec): boolean => {\n if (!candidate) return false\n return (\n candidate === spec.normalizedName ||\n candidate.includes(spec.normalizedName) ||\n spec.normalizedName.includes(candidate)\n )\n }\n\n const matchedPairs: Array<{ spec: CustomerLookupSpec; customer: CustomerEntity }> = []\n\n for (const customer of customers) {\n if (unresolved.size === 0) break\n const tokens = new Set<string>()\n tokens.add(normalizeKey(customer.displayName))\n if (customer.companyProfile) {\n tokens.add(normalizeKey(customer.companyProfile.legalName ?? ''))\n tokens.add(normalizeKey(customer.companyProfile.brandName ?? ''))\n tokens.add(normalizeKey(customer.companyProfile.domain ?? ''))\n }\n if (customer.personProfile) {\n tokens.add(normalizeKey(customer.personProfile.firstName ?? ''))\n tokens.add(normalizeKey(customer.personProfile.lastName ?? ''))\n const fullName = [customer.personProfile.firstName, customer.personProfile.lastName]\n .filter((part) => (part ?? '').trim().length > 0)\n .join(' ')\n tokens.add(normalizeKey(fullName))\n }\n\n const matchedSpec = lookupSpecs.find(\n (spec) => unresolved.has(spec.key) && Array.from(tokens).some((token) => doesMatch(token, spec))\n )\n if (!matchedSpec) continue\n matchedPairs.push({ spec: matchedSpec, customer })\n unresolved.delete(matchedSpec.key)\n }\n\n const matchIds = matchedPairs.map(({ customer }) => customer.id)\n\n const addresses = matchIds.length\n ? await findWithDecryption(\n em,\n CustomerAddress,\n { organizationId: scope.organizationId, tenantId: scope.tenantId, entity: { $in: matchIds } },\n { orderBy: { isPrimary: 'desc', createdAt: 'asc' } as any },\n { tenantId: scope.tenantId, organizationId: scope.organizationId }\n )\n : []\n const addressByCustomer = new Map<string, CustomerAddress>()\n for (const address of addresses) {\n const entityId = typeof address.entity === 'string' ? address.entity : address.entity?.id\n if (!entityId || addressByCustomer.has(entityId)) continue\n addressByCustomer.set(entityId, address)\n }\n\n const contacts = matchIds.length\n ? await findWithDecryption(\n em,\n CustomerPersonProfile,\n { organizationId: scope.organizationId, tenantId: scope.tenantId, company: { $in: matchIds } },\n { populate: ['entity', 'company'] },\n { tenantId: scope.tenantId, organizationId: scope.organizationId }\n )\n : []\n const contactByCompany = new Map<string, CustomerPersonProfile>()\n for (const contact of contacts) {\n const companyId = typeof contact.company === 'string' ? contact.company : contact.company?.id\n if (!companyId || contactByCompany.has(companyId)) continue\n contactByCompany.set(companyId, contact)\n }\n\n for (const { spec, customer } of matchedPairs) {\n const contact = contactByCompany.get(customer.id) ?? null\n const snapshot = buildCustomerSnapshot(customer, contact)\n const addresses = toExampleAddresses(customer, addressByCustomer.get(customer.id) ?? null)\n map.set(spec.key, {\n entity: customer,\n contact,\n contactId: contact?.id ?? null,\n snapshot,\n addresses,\n })\n }\n\n for (const lookup of lookups) {\n if (!map.has(lookup.key)) {\n console.warn(`[sales.examples] Customer \"${lookup.displayName}\" not found; skipping seeded linkage.`)\n }\n }\n\n return map\n}\n\nasync function ensureChannels(\n em: EntityManager,\n scope: SeedScope\n): Promise<Map<string, SalesChannel>> {\n const existing = await em.find(SalesChannel, {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n deletedAt: null,\n })\n const map = new Map<string, SalesChannel>()\n existing.forEach((entry) => map.set((entry.code ?? '').toLowerCase(), entry))\n const now = new Date()\n for (const seed of CHANNEL_SEEDS) {\n const code = seed.code.toLowerCase()\n if (map.has(code)) continue\n const record = em.create(SalesChannel, {\n id: randomUUID(),\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n name: seed.name,\n code: seed.code,\n description: seed.description,\n isActive: true,\n createdAt: now,\n updatedAt: now,\n })\n em.persist(record)\n map.set(code, record)\n }\n return map\n}\n\nfunction buildAddressSnapshot(address: ExampleAddress) {\n return {\n companyName: address.companyName ?? null,\n name: address.name ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n city: address.city ?? null,\n region: address.region ?? null,\n postalCode: address.postalCode ?? null,\n country: address.country ?? null,\n latitude: address.latitude ?? null,\n longitude: address.longitude ?? null,\n }\n}\n\nfunction buildShippingMethodSnapshot(method?: SalesShippingMethod | null) {\n if (!method) return null\n return {\n id: method.id,\n code: method.code,\n name: method.name,\n providerKey: method.providerKey ?? null,\n serviceLevel: method.serviceLevel ?? null,\n estimatedTransitDays: method.estimatedTransitDays ?? null,\n baseRateNet: method.baseRateNet,\n baseRateGross: method.baseRateGross,\n currencyCode: method.currencyCode,\n metadata: method.metadata ?? null,\n }\n}\n\nfunction buildPaymentMethodSnapshot(method?: SalesPaymentMethod | null) {\n if (!method) return null\n return {\n id: method.id,\n code: method.code,\n name: method.name,\n providerKey: method.providerKey ?? null,\n terms: method.terms ?? null,\n metadata: method.metadata ?? null,\n }\n}\n\nfunction attachDocumentAddresses(\n em: EntityManager,\n scope: SeedScope,\n params: {\n documentId: string\n documentKind: 'order' | 'quote'\n addresses: ExampleAddress[]\n order?: SalesOrder\n quote?: SalesQuote\n }\n): void {\n const { documentId, documentKind, addresses, order, quote } = params\n for (const entry of addresses) {\n const now = new Date()\n const record = em.create(SalesDocumentAddress, {\n id: randomUUID(),\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n documentId,\n documentKind,\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n companyName: entry.companyName ?? null,\n purpose: entry.role,\n addressLine1: entry.addressLine1,\n addressLine2: entry.addressLine2 ?? null,\n city: entry.city ?? null,\n region: entry.region ?? null,\n postalCode: entry.postalCode ?? null,\n country: entry.country ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n buildingNumber: null,\n flatNumber: null,\n order: documentKind === 'order' ? order ?? null : null,\n quote: documentKind === 'quote' ? quote ?? null : null,\n createdAt: now,\n updatedAt: now,\n })\n em.persist(record)\n }\n}\n\nfunction attachNotes(\n em: EntityManager,\n scope: SeedScope,\n params: {\n contextId: string\n contextType: 'order' | 'quote'\n notes: ExampleNote[]\n order?: SalesOrder\n quote?: SalesQuote\n }\n) {\n const { contextId, contextType, notes, order, quote } = params\n for (const note of notes) {\n const record = em.create(SalesNote, {\n id: randomUUID(),\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n contextType,\n contextId,\n body: note.body,\n appearanceIcon: note.appearanceIcon ?? null,\n appearanceColor: note.appearanceColor ?? null,\n createdAt: note.createdAt ?? new Date(),\n updatedAt: note.createdAt ?? new Date(),\n })\n record.order = contextType === 'order' ? order ?? null : null\n record.quote = contextType === 'quote' ? quote ?? null : null\n em.persist(record)\n }\n}\n\nfunction mapPaymentStatus(outstanding: number): string | null {\n if (outstanding <= 0.01) return 'paid'\n if (outstanding > 0) return 'partial'\n return null\n}\n\nexport async function seedSalesExamples(\n em: EntityManager,\n container: AppContainer,\n scope: SeedScope\n): Promise<boolean> {\n const hasOrders =\n ORDER_SEEDS.length > 0\n ? await em.count(SalesOrder, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n orderNumber: { $in: ORDER_SEEDS.map((item) => item.orderNumber) as any },\n })\n : 0\n const hasQuotes =\n QUOTE_SEEDS.length > 0\n ? await em.count(SalesQuote, {\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n quoteNumber: { $in: QUOTE_SEEDS.map((item) => item.quoteNumber) as any },\n })\n : 0\n\n if (hasOrders > 0 || hasQuotes > 0) {\n return false\n }\n\n await seedSalesDictionaries(em, scope)\n const [shippingMethods, paymentMethods, channels] = await Promise.all([\n ensureExampleShippingMethods(em, scope, { skipFlush: true }),\n ensureExamplePaymentMethods(em, scope, { skipFlush: true }),\n ensureChannels(em, scope),\n ])\n await em.flush()\n const catalogLookups = await loadCatalogLookups(em, scope)\n const customerLookups = await loadCustomerLookups(em, scope, [...CUSTOMER_LINKS])\n\n const calculationService = container.resolve<SalesCalculationService>('salesCalculationService')\n\n for (const seed of QUOTE_SEEDS) {\n const quoteId = randomUUID()\n const customer = seed.customerKey ? customerLookups.get(seed.customerKey) ?? null : null\n if (seed.customerKey && !customer) {\n console.warn(`[sales.examples] Skipping quote ${seed.quoteNumber} because customer \"${seed.customerKey}\" is missing.`)\n continue\n }\n const shippingMethod = seed.shippingMethodCode\n ? shippingMethods.get(seed.shippingMethodCode.toLowerCase()) ?? null\n : null\n const paymentMethod = seed.paymentMethodCode\n ? paymentMethods.get(seed.paymentMethodCode.toLowerCase()) ?? null\n : null\n const channel = seed.channelCode ? channels.get(seed.channelCode.toLowerCase()) ?? null : null\n\n const lineSnapshots = seed.lines.map((line) => {\n const catalogRef = resolveCatalogLine(line, catalogLookups)\n if ((line.kind ?? 'product') === 'product' && !catalogRef.productId) {\n console.warn(\n `[sales.examples] Missing catalog match for quote line \"${line.name ?? line.variantSku ?? line.productHandle ?? 'unknown'}\".`\n )\n }\n const unitPriceNet = line.unitPriceNet ?? catalogRef.unitPriceNet ?? 0\n const unitPriceGross = line.unitPriceGross ?? catalogRef.unitPriceGross ?? unitPriceNet\n const currencyCode = catalogRef.currencyCode ?? seed.currencyCode\n const metadata: Record<string, unknown> = {}\n if (catalogRef.productThumbnail) metadata.productThumbnail = catalogRef.productThumbnail\n if (catalogRef.variantThumbnail) metadata.variantThumbnail = catalogRef.variantThumbnail\n return {\n id: randomUUID(),\n kind: line.kind ?? 'product',\n name: line.name,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n normalizedQuantity: line.quantity,\n normalizedUnit: line.quantityUnit ?? null,\n uomSnapshot: null,\n currencyCode,\n unitPriceNet,\n unitPriceGross,\n taxRate: line.taxRate ?? 0,\n discountPercent: line.discountPercent ?? null,\n productId: catalogRef.productId,\n productVariantId: catalogRef.variantId,\n catalogSnapshot: catalogRef.snapshot,\n metadata: Object.keys(metadata).length ? metadata : null,\n }\n })\n\n const adjustmentDrafts =\n seed.adjustments?.map((adj) => ({\n id: randomUUID(),\n scope: adj.scope,\n kind: adj.kind,\n code: adj.label ?? null,\n label: adj.label ?? null,\n rate: adj.rate ?? null,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross ?? adj.amountNet,\n currencyCode: seed.currencyCode,\n position: adj.position ?? 0,\n metadata: adj.lineIndex !== undefined ? { lineIndex: adj.lineIndex } : null,\n })) ?? []\n\n const calculation = await calculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n currencyCode: seed.currencyCode,\n },\n })\n\n const totals = calculation.totals\n const quoteNumber = seed.quoteNumber ?? `SQ-${quoteId.slice(0, 8).toUpperCase()}`\n const quote = em.create(SalesQuote, {\n id: quoteId,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n quoteNumber,\n status: seed.status ?? 'draft',\n customerEntityId: customer?.entity.id ?? null,\n customerContactId: customer?.contactId ?? null,\n customerSnapshot: customer?.snapshot ? toSnapshot(customer.snapshot) : null,\n currencyCode: seed.currencyCode,\n validFrom: seed.validFrom ?? null,\n validUntil: seed.validUntil ?? null,\n comments: seed.comments ?? null,\n shippingMethodId: shippingMethod?.id ?? null,\n shippingMethodCode: shippingMethod?.code ?? seed.shippingMethodCode ?? null,\n paymentMethodId: paymentMethod?.id ?? null,\n paymentMethodCode: paymentMethod?.code ?? seed.paymentMethodCode ?? null,\n channelId: channel?.id ?? null,\n shippingMethodSnapshot: buildShippingMethodSnapshot(shippingMethod),\n paymentMethodSnapshot: buildPaymentMethodSnapshot(paymentMethod),\n metadata: seed.metadata ?? { seed: 'sales.examples' },\n subtotalNetAmount: toAmount(totals.subtotalNetAmount),\n subtotalGrossAmount: toAmount(totals.subtotalGrossAmount),\n discountTotalAmount: toAmount(totals.discountTotalAmount),\n taxTotalAmount: toAmount(totals.taxTotalAmount),\n grandTotalNetAmount: toAmount(totals.grandTotalNetAmount),\n grandTotalGrossAmount: toAmount(totals.grandTotalGrossAmount),\n totalsSnapshot: toSnapshot(totals),\n lineItemCount: seed.lines.length,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(quote)\n\n calculation.lines.forEach((lineResult, idx) => {\n const source = lineSnapshots[idx]\n const line = em.create(SalesQuoteLine, {\n id: source.id,\n quote,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n lineNumber: idx + 1,\n kind: source.kind ?? 'product',\n name: source.name,\n description: source.description,\n comment: source.comment,\n quantity: toAmount(source.quantity),\n quantityUnit: source.quantityUnit ?? null,\n normalizedQuantity: toAmount(source.normalizedQuantity ?? source.quantity),\n normalizedUnit: source.normalizedUnit ?? source.quantityUnit ?? null,\n uomSnapshot:\n source.uomSnapshot && typeof source.uomSnapshot === 'object'\n ? (toSnapshot(source.uomSnapshot as Record<string, unknown>) as typeof source.uomSnapshot)\n : null,\n currencyCode: source.currencyCode,\n unitPriceNet: toAmount(source.unitPriceNet ?? 0),\n unitPriceGross: toAmount(source.unitPriceGross ?? source.unitPriceNet ?? 0),\n discountAmount: toAmount(lineResult.discountAmount),\n discountPercent:\n source.discountPercent !== null && source.discountPercent !== undefined\n ? toAmount(source.discountPercent)\n : '0',\n taxRate: toAmount(source.taxRate ?? 0),\n taxAmount: toAmount(lineResult.taxAmount),\n totalNetAmount: toAmount(lineResult.netAmount),\n totalGrossAmount: toAmount(lineResult.grossAmount),\n productId: source.productId ?? null,\n productVariantId: source.productVariantId ?? null,\n catalogSnapshot: source.catalogSnapshot ? toSnapshot(source.catalogSnapshot) : null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(line)\n })\n\n calculation.adjustments.forEach((adj, idx) => {\n const adjMeta = adj.metadata && typeof adj.metadata === 'object' ? (adj.metadata as Record<string, unknown>) : null\n const lineIndex = adjMeta ? (adjMeta.lineIndex as number | null) : null\n const lineRef =\n typeof lineIndex === 'number' && lineIndex >= 0 && lineIndex < seed.lines.length\n ? lineSnapshots[lineIndex]?.id ?? null\n : null\n const adjustment = em.create(SalesQuoteAdjustment, {\n id: adj.id ?? randomUUID(),\n quote,\n quoteLine: lineRef ? (lineRef as unknown as SalesQuoteLine) : null,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? adj.label ?? null,\n label: adj.label ?? adj.code ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate !== null && adj.rate !== undefined ? toAmount(adj.rate) : '0',\n amountNet: toAmount(adj.amountNet ?? 0),\n amountGross: toAmount(adj.amountGross ?? adj.amountNet ?? 0),\n currencyCode: adj.currencyCode ?? seed.currencyCode,\n metadata: adj.metadata ?? null,\n position: adj.position ?? idx,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(adjustment)\n })\n\n quote.subtotalNetAmount = toAmount(calculation.totals.subtotalNetAmount)\n quote.subtotalGrossAmount = toAmount(calculation.totals.subtotalGrossAmount)\n quote.discountTotalAmount = toAmount(calculation.totals.discountTotalAmount)\n quote.taxTotalAmount = toAmount(calculation.totals.taxTotalAmount)\n quote.grandTotalNetAmount = toAmount(calculation.totals.grandTotalNetAmount)\n quote.grandTotalGrossAmount = toAmount(calculation.totals.grandTotalGrossAmount)\n quote.totalsSnapshot = toSnapshot(calculation.totals)\n quote.lineItemCount = seed.lines.length\n\n const quoteAddresses = seed.addresses ?? customer?.addresses ?? []\n if (quoteAddresses.length) {\n attachDocumentAddresses(em, scope, {\n documentId: quoteId,\n documentKind: 'quote',\n addresses: quoteAddresses,\n quote,\n })\n const billing = quoteAddresses.find((a) => a.role === 'billing')\n const shipping = quoteAddresses.find((a) => a.role === 'shipping')\n quote.billingAddressId = billing?.customerAddressId ?? null\n quote.shippingAddressId = shipping?.customerAddressId ?? null\n quote.billingAddressSnapshot = billing ? buildAddressSnapshot(billing) : null\n quote.shippingAddressSnapshot = shipping ? buildAddressSnapshot(shipping) : null\n }\n if (seed.notes?.length) {\n attachNotes(em, scope, {\n contextId: quoteId,\n contextType: 'quote',\n notes: seed.notes,\n quote,\n })\n }\n }\n\n for (const seed of ORDER_SEEDS) {\n const orderId = randomUUID()\n const customer = seed.customerKey ? customerLookups.get(seed.customerKey) ?? null : null\n if (seed.customerKey && !customer) {\n console.warn(`[sales.examples] Skipping order ${seed.orderNumber} because customer \"${seed.customerKey}\" is missing.`)\n continue\n }\n const shippingMethod = seed.shippingMethodCode\n ? shippingMethods.get(seed.shippingMethodCode.toLowerCase()) ?? null\n : null\n const paymentMethod = seed.paymentMethodCode\n ? paymentMethods.get(seed.paymentMethodCode.toLowerCase()) ?? null\n : null\n const channel = seed.channelCode ? channels.get(seed.channelCode.toLowerCase()) ?? null : null\n\n const lineSnapshots = seed.lines.map((line) => {\n const catalogRef = resolveCatalogLine(line, catalogLookups)\n if ((line.kind ?? 'product') === 'product' && !catalogRef.productId) {\n console.warn(\n `[sales.examples] Missing catalog match for order line \"${line.name ?? line.variantSku ?? line.productHandle ?? 'unknown'}\".`\n )\n }\n const unitPriceNet = line.unitPriceNet ?? catalogRef.unitPriceNet ?? 0\n const unitPriceGross = line.unitPriceGross ?? catalogRef.unitPriceGross ?? unitPriceNet\n const currencyCode = catalogRef.currencyCode ?? seed.currencyCode\n const metadata: Record<string, unknown> = {}\n if (catalogRef.productThumbnail) metadata.productThumbnail = catalogRef.productThumbnail\n if (catalogRef.variantThumbnail) metadata.variantThumbnail = catalogRef.variantThumbnail\n return {\n id: randomUUID(),\n kind: line.kind ?? 'product',\n name: line.name,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n normalizedQuantity: line.quantity,\n normalizedUnit: line.quantityUnit ?? null,\n uomSnapshot: null,\n currencyCode,\n unitPriceNet,\n unitPriceGross,\n taxRate: line.taxRate ?? 0,\n discountPercent: line.discountPercent ?? null,\n productId: catalogRef.productId,\n productVariantId: catalogRef.variantId,\n catalogSnapshot: catalogRef.snapshot,\n metadata: Object.keys(metadata).length ? metadata : null,\n }\n })\n\n const adjustmentDrafts =\n seed.adjustments?.map((adj) => ({\n id: randomUUID(),\n scope: adj.scope,\n kind: adj.kind,\n code: adj.label ?? null,\n label: adj.label ?? null,\n rate: adj.rate ?? null,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross ?? adj.amountNet,\n currencyCode: seed.currencyCode,\n position: adj.position ?? 0,\n metadata: adj.lineIndex !== undefined ? { lineIndex: adj.lineIndex } : null,\n })) ?? []\n\n const calculation = await calculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n currencyCode: seed.currencyCode,\n },\n })\n\n const totals = calculation.totals\n const order = em.create(SalesOrder, {\n id: orderId,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n orderNumber: seed.orderNumber,\n status: seed.status ?? 'confirmed',\n fulfillmentStatus: seed.fulfillmentStatus ?? null,\n paymentStatus: seed.paymentStatus ?? null,\n customerEntityId: customer?.entity.id ?? null,\n customerContactId: customer?.contactId ?? null,\n customerSnapshot: customer?.snapshot ? toSnapshot(customer.snapshot) : null,\n currencyCode: seed.currencyCode,\n placedAt: seed.placedAt ?? null,\n expectedDeliveryAt: seed.expectedDeliveryAt ?? null,\n comments: seed.comments ?? null,\n internalNotes: seed.internalNotes ?? null,\n shippingMethodId: shippingMethod?.id ?? null,\n shippingMethodCode: shippingMethod?.code ?? seed.shippingMethodCode ?? null,\n paymentMethodId: paymentMethod?.id ?? null,\n paymentMethodCode: paymentMethod?.code ?? seed.paymentMethodCode ?? null,\n channelId: channel?.id ?? null,\n shippingMethodSnapshot: buildShippingMethodSnapshot(shippingMethod),\n paymentMethodSnapshot: buildPaymentMethodSnapshot(paymentMethod),\n metadata: seed.metadata ?? { seed: 'sales.examples' },\n subtotalNetAmount: toAmount(totals.subtotalNetAmount),\n subtotalGrossAmount: toAmount(totals.subtotalGrossAmount),\n discountTotalAmount: toAmount(totals.discountTotalAmount),\n taxTotalAmount: toAmount(totals.taxTotalAmount),\n shippingNetAmount: toAmount(totals.shippingNetAmount ?? 0),\n shippingGrossAmount: toAmount(totals.shippingGrossAmount ?? 0),\n surchargeTotalAmount: toAmount(totals.surchargeTotalAmount ?? 0),\n grandTotalNetAmount: toAmount(totals.grandTotalNetAmount),\n grandTotalGrossAmount: toAmount(totals.grandTotalGrossAmount),\n paidTotalAmount: toAmount(totals.paidTotalAmount ?? 0),\n refundedTotalAmount: toAmount(totals.refundedTotalAmount ?? 0),\n outstandingAmount: toAmount(totals.outstandingAmount ?? totals.grandTotalGrossAmount),\n totalsSnapshot: toSnapshot(totals),\n lineItemCount: seed.lines.length,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n\n const lineEntities: SalesOrderLine[] = []\n calculation.lines.forEach((lineResult, idx) => {\n const source = lineSnapshots[idx]\n const entity = em.create(SalesOrderLine, {\n id: source.id,\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n lineNumber: idx + 1,\n kind: source.kind ?? 'product',\n name: source.name,\n description: source.description,\n comment: source.comment,\n quantity: toAmount(source.quantity),\n quantityUnit: source.quantityUnit ?? null,\n normalizedQuantity: toAmount(source.normalizedQuantity ?? source.quantity),\n normalizedUnit: source.normalizedUnit ?? source.quantityUnit ?? null,\n uomSnapshot:\n source.uomSnapshot && typeof source.uomSnapshot === 'object'\n ? (toSnapshot(source.uomSnapshot as Record<string, unknown>) as typeof source.uomSnapshot)\n : null,\n reservedQuantity: '0',\n fulfilledQuantity: '0',\n invoicedQuantity: '0',\n returnedQuantity: '0',\n currencyCode: source.currencyCode,\n unitPriceNet: toAmount(source.unitPriceNet ?? 0),\n unitPriceGross: toAmount(source.unitPriceGross ?? source.unitPriceNet ?? 0),\n discountAmount: toAmount(lineResult.discountAmount),\n discountPercent:\n source.discountPercent !== null && source.discountPercent !== undefined\n ? toAmount(source.discountPercent)\n : '0',\n taxRate: toAmount(source.taxRate ?? 0),\n taxAmount: toAmount(lineResult.taxAmount),\n totalNetAmount: toAmount(lineResult.netAmount),\n totalGrossAmount: toAmount(lineResult.grossAmount),\n productId: source.productId ?? null,\n productVariantId: source.productVariantId ?? null,\n catalogSnapshot: source.catalogSnapshot ? toSnapshot(source.catalogSnapshot) : null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n lineEntities.push(entity)\n })\n\n calculation.adjustments.forEach((adj, idx) => {\n const lineIndex = adj.metadata && typeof adj.metadata === 'object' ? (adj.metadata as any).lineIndex : null\n const lineRef =\n typeof lineIndex === 'number' && lineIndex >= 0 && lineIndex < seed.lines.length\n ? lineEntities[lineIndex] ?? null\n : null\n const adjustment = em.create(SalesOrderAdjustment, {\n id: adj.id ?? randomUUID(),\n order,\n orderLine: lineRef,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? adj.label ?? null,\n label: adj.label ?? adj.code ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate !== null && adj.rate !== undefined ? toAmount(adj.rate) : '0',\n amountNet: toAmount(adj.amountNet ?? 0),\n amountGross: toAmount(adj.amountGross ?? adj.amountNet ?? 0),\n currencyCode: adj.currencyCode ?? seed.currencyCode,\n metadata: adj.metadata ?? null,\n position: adj.position ?? idx,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(adjustment)\n })\n\n order.subtotalNetAmount = toAmount(calculation.totals.subtotalNetAmount)\n order.subtotalGrossAmount = toAmount(calculation.totals.subtotalGrossAmount)\n order.discountTotalAmount = toAmount(calculation.totals.discountTotalAmount)\n order.taxTotalAmount = toAmount(calculation.totals.taxTotalAmount)\n order.shippingNetAmount = toAmount(calculation.totals.shippingNetAmount ?? 0)\n order.shippingGrossAmount = toAmount(calculation.totals.shippingGrossAmount ?? 0)\n order.surchargeTotalAmount = toAmount(calculation.totals.surchargeTotalAmount ?? 0)\n order.grandTotalNetAmount = toAmount(calculation.totals.grandTotalNetAmount)\n order.grandTotalGrossAmount = toAmount(calculation.totals.grandTotalGrossAmount)\n order.paidTotalAmount = toAmount(calculation.totals.paidTotalAmount ?? 0)\n order.refundedTotalAmount = toAmount(calculation.totals.refundedTotalAmount ?? 0)\n order.outstandingAmount = toAmount(calculation.totals.outstandingAmount ?? calculation.totals.grandTotalGrossAmount)\n order.totalsSnapshot = toSnapshot(calculation.totals)\n order.lineItemCount = seed.lines.length\n\n const lineMap = new Map(lineEntities.map((line) => [line.id, line]))\n if (seed.shipments?.length) {\n for (const shipmentSeed of seed.shipments) {\n const shipment = em.create(SalesShipment, {\n id: randomUUID(),\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n shipmentNumber: shipmentSeed.shipmentNumber ?? null,\n shippingMethodId: shipmentSeed.methodCode\n ? shippingMethods.get(shipmentSeed.methodCode.toLowerCase())?.id ?? null\n : null,\n status: shipmentSeed.status ?? null,\n carrierName: null,\n trackingNumbers: shipmentSeed.trackingNumbers ?? null,\n shippedAt: shipmentSeed.shippedAt ?? null,\n deliveredAt: shipmentSeed.deliveredAt ?? null,\n weightValue: shipmentSeed.weightKg ? toAmount(shipmentSeed.weightKg) : null,\n weightUnit: shipmentSeed.weightKg ? 'kg' : null,\n declaredValueNet: shipmentSeed.declaredValue ? toAmount(shipmentSeed.declaredValue) : null,\n declaredValueGross: shipmentSeed.declaredValue ? toAmount(shipmentSeed.declaredValue) : null,\n currencyCode: shipmentSeed.currencyCode ?? seed.currencyCode,\n notesText: shipmentSeed.notes ?? null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(shipment)\n\n const shipmentItems: SalesShipmentItem[] = []\n for (const item of shipmentSeed.items) {\n const line = lineEntities[item.lineIndex]\n if (!line) continue\n line.fulfilledQuantity = toAmount(\n Number(line.fulfilledQuantity ?? '0') + Math.max(item.quantity, 0)\n )\n const shipmentItem = em.create(SalesShipmentItem, {\n id: randomUUID(),\n shipment,\n orderLine: line,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n quantity: toAmount(item.quantity),\n metadata: null,\n })\n shipmentItems.push(shipmentItem)\n em.persist(shipmentItem)\n }\n await refreshShipmentItemsSnapshot(em, shipment, { items: shipmentItems, lineMap })\n }\n }\n\n let paymentTotal = 0\n if (seed.payments?.length) {\n for (const paymentSeed of seed.payments) {\n paymentTotal += paymentSeed.amount\n const method = paymentSeed.methodCode\n ? paymentMethods.get(paymentSeed.methodCode.toLowerCase()) ?? null\n : paymentMethod\n const payment = em.create(SalesPayment, {\n id: randomUUID(),\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n paymentMethod: method ?? null,\n paymentReference: paymentSeed.reference ?? null,\n status: paymentSeed.status ?? null,\n amount: toAmount(paymentSeed.amount),\n currencyCode: paymentSeed.currencyCode,\n capturedAmount: toAmount(paymentSeed.capturedAt ? paymentSeed.amount : 0),\n refundedAmount: '0',\n receivedAt: paymentSeed.receivedAt ?? null,\n capturedAt: paymentSeed.capturedAt ?? null,\n metadata: null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(payment)\n const allocation = em.create(SalesPaymentAllocation, {\n id: randomUUID(),\n payment,\n order,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n amount: toAmount(paymentSeed.amount),\n currencyCode: paymentSeed.currencyCode,\n metadata: null,\n })\n em.persist(allocation)\n }\n }\n\n const orderAddresses = seed.addresses ?? customer?.addresses ?? []\n if (orderAddresses.length) {\n attachDocumentAddresses(em, scope, {\n documentId: orderId,\n documentKind: 'order',\n addresses: orderAddresses,\n order,\n })\n const billing = orderAddresses.find((a) => a.role === 'billing')\n const shipping = orderAddresses.find((a) => a.role === 'shipping')\n order.billingAddressId = billing?.customerAddressId ?? null\n order.shippingAddressId = shipping?.customerAddressId ?? null\n order.billingAddressSnapshot = billing ? buildAddressSnapshot(billing) : null\n order.shippingAddressSnapshot = shipping ? buildAddressSnapshot(shipping) : null\n }\n if (seed.notes?.length) {\n attachNotes(em, scope, {\n contextId: orderId,\n contextType: 'order',\n notes: seed.notes,\n order,\n })\n }\n\n const grandTotal = Number(order.grandTotalGrossAmount ?? '0')\n order.paidTotalAmount = toAmount(paymentTotal)\n order.outstandingAmount = toAmount(Math.max(grandTotal - paymentTotal, 0))\n order.paymentStatus = seed.paymentStatus ?? mapPaymentStatus(grandTotal - paymentTotal)\n const isFullyFulfilled = lineEntities.every((line, idx) => {\n const expected = Number(seed.lines[idx]?.quantity ?? 0)\n const fulfilled = Number(line.fulfilledQuantity ?? '0')\n return fulfilled >= expected\n })\n order.fulfillmentStatus = seed.fulfillmentStatus ?? (isFullyFulfilled ? 'fulfilled' : 'in_fulfillment')\n }\n\n await em.flush()\n return true\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAG3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,6BAA6B;AACtC,SAAS,oCAAoC;AAC7C,SAAS,uBAAuB;AAEhC,SAAS,6BAA6B,oCAAoD;AAC1F;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAmHnC,MAAM,gBAAgB;AAAA,EACpB,EAAE,MAAM,UAAU,MAAM,gBAAgB,aAAa,uCAAuC;AAAA,EAC5F;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,aAAa;AAAA,EACf;AACF;AAEA,MAAM,iBAAmC;AAAA,EACvC,EAAE,KAAK,cAAc,aAAa,mBAAmB;AAAA,EACrD,EAAE,KAAK,cAAc,aAAa,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,YAAY,CAAC;AACtD,YAAM,YAAY,OAAO,KAAK,qBAAqB,GAAG;AACtD,aAAO,aAAa;AAAA,IACtB,CAAC;AACD,UAAM,oBAAoB,KAAK,sBAAsB,mBAAmB,cAAc;AAAA,EACxF;AAEA,QAAM,GAAG,MAAM;AACf,SAAO;AACT;",
|
|
6
6
|
"names": ["addresses"]
|
|
7
7
|
}
|
|
@@ -62,7 +62,7 @@ function TimelineItem({
|
|
|
62
62
|
const relativeTime = formatRelativeTime(entry.occurredAt);
|
|
63
63
|
const absoluteTime = formatDateTime(entry.occurredAt);
|
|
64
64
|
const isStatusChange = entry.kind === "status" && entry.metadata?.statusTo;
|
|
65
|
-
return /* @__PURE__ */ jsxs("div", { className: "relative flex gap-3", children: [
|
|
65
|
+
return /* @__PURE__ */ jsxs("div", { "data-testid": "timeline-entry", className: "relative flex gap-3", children: [
|
|
66
66
|
!isLast && /* @__PURE__ */ jsx("div", { className: "absolute left-[11px] top-6 bottom-0 w-px bg-border", "aria-hidden": true }),
|
|
67
67
|
/* @__PURE__ */ jsx(
|
|
68
68
|
"div",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/sales/widgets/injection/document-history/widget.client.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from \"react\"\nimport { Spinner } from \"@open-mercato/ui/primitives/spinner\"\nimport { useT } from \"@open-mercato/shared/lib/i18n/context\"\nimport { apiCall } from \"@open-mercato/ui/backend/utils/apiCall\"\nimport { formatRelativeTime, formatDateTime } from \"@open-mercato/shared/lib/time\"\nimport { cn } from \"@open-mercato/shared/lib/utils\"\nimport type { InjectionWidgetComponentProps } from '@open-mercato/shared/modules/widgets/injection'\nimport { ArrowRightLeft, Zap, MessageSquare, User, Filter, ChevronDown, Check } from 'lucide-react'\n\nexport type TimelineEntry = {\n id: string\n occurredAt: string\n kind: \"status\" | \"action\" | \"comment\"\n action: string\n actor: { id: string | null; label: string }\n source: \"action_log\" | \"note\"\n metadata?: {\n statusFrom?: string | null\n statusTo?: string | null\n documentKind?: \"order\" | \"quote\"\n commandId?: string\n }\n}\n\ntype StatusOption = {\n value: string\n label: string\n color: string | null\n icon: string | null\n}\n\ntype TimelineContext = {\n kind: \"order\" | \"quote\"\n record: { id: string }\n}\n\nconst isValidContext = (ctx: unknown): ctx is TimelineContext =>\n ctx !== null &&\n typeof ctx === 'object' &&\n 'kind' in ctx &&\n 'record' in ctx &&\n ((ctx as TimelineContext).kind === 'order' || (ctx as TimelineContext).kind === 'quote') &&\n typeof (ctx as TimelineContext).record === 'object' &&\n (ctx as TimelineContext).record !== null &&\n 'id' in (ctx as TimelineContext).record &&\n typeof (ctx as TimelineContext).record.id === 'string'\n\nconst KIND_ICONS = {\n status: ArrowRightLeft,\n action: Zap,\n comment: MessageSquare,\n}\n\nconst KIND_ICON_COLORS = {\n status: 'text-foreground',\n action: 'text-foreground',\n comment: 'text-foreground',\n}\n\nconst KIND_BG_COLORS = {\n status: 'bg-muted',\n action: 'bg-muted',\n comment: 'bg-muted',\n}\n\nfunction StatusDot({ color, className }: { color: string | null | undefined; className?: string }) {\n if (!color) return <span className={cn('h-2.5 w-2.5 rounded-full bg-muted-foreground/40 border border-border inline-flex', className)} />\n return (\n <span\n className={cn('h-2.5 w-2.5 rounded-full border border-border/60 inline-flex', className)}\n style={{ backgroundColor: color }}\n aria-hidden\n />\n )\n}\n\nfunction StatusTransition({\n statusFrom,\n statusTo,\n statusMap,\n}: {\n statusFrom: string | null | undefined\n statusTo: string | null | undefined\n statusMap: Record<string, StatusOption>\n}) {\n const from = statusFrom ? (statusMap[statusFrom] ?? { value: statusFrom, label: statusFrom, color: null, icon: null }) : null\n const to = statusTo ? (statusMap[statusTo] ?? { value: statusTo, label: statusTo, color: null, icon: null }) : null\n\n return (\n <div className=\"flex items-center gap-1.5 flex-wrap\">\n {from ? (\n <span className=\"inline-flex items-center gap-1 text-xs text-muted-foreground\">\n <StatusDot color={from.color} />\n <span>{from.label}</span>\n </span>\n ) : null}\n {from && to ? (\n <ArrowRightLeft className=\"h-3 w-3 text-muted-foreground/60 shrink-0\" />\n ) : null}\n {to ? (\n <span className=\"inline-flex items-center gap-1 text-xs font-medium text-foreground\">\n <StatusDot color={to.color} />\n <span>{to.label}</span>\n </span>\n ) : null}\n </div>\n )\n}\n\nfunction TimelineItem({\n entry,\n statusMap,\n isLast,\n}: {\n entry: TimelineEntry\n statusMap: Record<string, StatusOption>\n isLast: boolean\n}) {\n const KindIcon = KIND_ICONS[entry.kind]\n const relativeTime = formatRelativeTime(entry.occurredAt)\n const absoluteTime = formatDateTime(entry.occurredAt)\n\n const isStatusChange = entry.kind === 'status' && entry.metadata?.statusTo\n\n return (\n <div className=\"relative flex gap-3\">\n {/* Vertical connector line */}\n {!isLast && (\n <div className=\"absolute left-[11px] top-6 bottom-0 w-px bg-border\" aria-hidden />\n )}\n\n {/* Icon circle */}\n <div\n className={cn(\n 'relative z-10 flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-border',\n KIND_BG_COLORS[entry.kind],\n )}\n >\n <KindIcon className={cn('h-3 w-3', KIND_ICON_COLORS[entry.kind])} aria-hidden />\n </div>\n\n {/* Content card */}\n <div className=\"flex-1 pb-4\">\n <div className=\"group rounded-lg border bg-card p-3 space-y-1.5\">\n {/* Header: actor + time */}\n <div className=\"flex items-center justify-between gap-2 flex-wrap\">\n <span className=\"inline-flex items-center gap-1.5 text-xs font-medium text-foreground\">\n <User className=\"h-3 w-3 text-muted-foreground\" aria-hidden />\n {entry.actor.label}\n </span>\n <span\n className=\"text-xs text-muted-foreground\"\n title={absoluteTime ?? undefined}\n >\n {relativeTime ?? absoluteTime}\n </span>\n </div>\n\n {/* Body */}\n {isStatusChange ? (\n <StatusTransition\n statusFrom={entry.metadata?.statusFrom}\n statusTo={entry.metadata?.statusTo}\n statusMap={statusMap}\n />\n ) : (\n <div className=\"text-sm text-foreground\">{entry.action}</div>\n )}\n </div>\n </div>\n </div>\n )\n}\n\ntype FilterKind = 'all' | 'status' | 'action' | 'comment'\n\ntype FilterOption = { value: FilterKind; label: string }\n\nfunction FilterDropdown({ filter, onChange }: { filter: FilterKind; onChange: (kind: FilterKind) => void }) {\n const t = useT()\n const [open, setOpen] = React.useState(false)\n const ref = React.useRef<HTMLDivElement>(null)\n\n React.useEffect(() => {\n if (!open) return\n function onDocClick(e: MouseEvent) {\n if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false)\n }\n function onKey(e: KeyboardEvent) {\n if (e.key === 'Escape') setOpen(false)\n }\n document.addEventListener('mousedown', onDocClick)\n document.addEventListener('keydown', onKey)\n return () => {\n document.removeEventListener('mousedown', onDocClick)\n document.removeEventListener('keydown', onKey)\n }\n }, [open])\n\n const options: FilterOption[] = [\n { value: 'all', label: t('sales.documents.history.filter.all', 'All') },\n { value: 'status', label: t('sales.documents.history.filter.status', 'Status changes') },\n { value: 'action', label: t('sales.documents.history.filter.actions', 'Actions') },\n { value: 'comment', label: t('sales.documents.history.filter.comments', 'Comments') },\n ]\n\n const activeLabel = options.find(o => o.value === filter)?.label\n\n return (\n <div className=\"relative\" ref={ref}>\n <button\n type=\"button\"\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n onClick={() => setOpen(prev => !prev)}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1 text-xs font-medium shadow-sm hover:bg-accent hover:text-accent-foreground transition-colors select-none\"\n >\n <Filter className=\"h-3 w-3\" aria-hidden />\n {t('sales.documents.history.filter.label', 'Filters')}\n {filter !== 'all' && (\n <span className=\"text-muted-foreground\">: {activeLabel}</span>\n )}\n <ChevronDown className={cn('h-3 w-3 transition-transform duration-150', open && 'rotate-180')} aria-hidden />\n </button>\n {open && (\n <div\n role=\"listbox\"\n aria-label={t('sales.documents.history.filter.label', 'Filters')}\n className=\"absolute left-0 top-full mt-1 z-50 w-48 rounded-md border bg-background p-1 shadow-md\"\n >\n {options.map(opt => (\n <button\n key={opt.value}\n type=\"button\"\n role=\"option\"\n aria-selected={filter === opt.value}\n onClick={() => { onChange(opt.value); setOpen(false) }}\n className=\"flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-accent\"\n >\n <Check className={cn('h-3.5 w-3.5 shrink-0', filter === opt.value ? 'opacity-100' : 'opacity-0')} aria-hidden />\n {opt.label}\n </button>\n ))}\n </div>\n )}\n </div>\n )\n}\n\nexport const DocumentHistoryWidget: React.FC<InjectionWidgetComponentProps<unknown, unknown>> = ({ context }) => {\n const t = useT()\n const [entries, setEntries] = React.useState<TimelineEntry[]>([])\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n const [statusMap, setStatusMap] = React.useState<Record<string, StatusOption>>({})\n const [filter, setFilter] = React.useState<FilterKind>('all')\n\n React.useEffect(() => {\n apiCall<{ items?: unknown[] }>('/api/sales/order-statuses?pageSize=100')\n .then((res) => {\n if (res.ok && Array.isArray(res.result?.items)) {\n const map: Record<string, StatusOption> = {}\n for (const item of res.result.items) {\n if (!item || typeof item !== 'object') continue\n const d = item as Record<string, unknown>\n const value = typeof d.value === 'string' ? d.value : null\n if (!value) continue\n map[value] = {\n value,\n label: typeof d.label === 'string' && d.label.length ? d.label : value,\n color: typeof d.color === 'string' && d.color.length ? d.color : null,\n icon: typeof d.icon === 'string' && d.icon.length ? d.icon : null,\n }\n }\n setStatusMap(map)\n }\n })\n .catch(() => {})\n }, [])\n\n React.useEffect(() => {\n if (!isValidContext(context)) {\n setLoading(false)\n setError(t(\"sales.documents.history.error\", \"Failed to load history.\"))\n return\n }\n\n setLoading(true)\n setError(null)\n apiCall<{ items: TimelineEntry[] }>(\n `/api/sales/document-history?kind=${context.kind}&id=${context.record.id}`\n )\n .then((res) => {\n if (res.ok && Array.isArray(res.result?.items)) {\n setEntries(res.result.items)\n } else {\n setError(t(\"sales.documents.history.error\", \"Failed to load history.\"))\n }\n })\n .catch(() => setError(t(\"sales.documents.history.error\", \"Failed to load history.\")))\n .finally(() => setLoading(false))\n }, [context, t])\n\n const filtered = React.useMemo(\n () => filter === 'all' ? entries : entries.filter(e => e.kind === filter),\n [entries, filter]\n )\n\n return (\n <div className=\"space-y-4\">\n {/* Filter dropdown */}\n <div>\n <FilterDropdown filter={filter} onChange={setFilter} />\n </div>\n\n {/* Content */}\n {loading ? (\n <div className=\"flex items-center justify-center h-24\">\n <Spinner />\n </div>\n ) : error ? (\n <div className=\"text-destructive text-sm\">{error}</div>\n ) : !filtered.length ? (\n <div className=\"text-muted-foreground text-sm py-6 text-center\">\n {t(\"sales.documents.history.empty\", \"No history entries yet.\")}\n </div>\n ) : (\n <div className=\"relative\">\n {filtered.map((entry, index) => (\n <TimelineItem\n key={entry.id}\n entry={entry}\n statusMap={statusMap}\n isLast={index === filtered.length - 1}\n />\n ))}\n </div>\n )}\n </div>\n )\n}\n\nexport default DocumentHistoryWidget\n"],
|
|
5
|
-
"mappings": ";AAoEqB,cAyBb,YAzBa;AAlErB,YAAY,WAAW;AACvB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,oBAAoB,sBAAsB;AACnD,SAAS,UAAU;AAEnB,SAAS,gBAAgB,KAAK,eAAe,MAAM,QAAQ,aAAa,aAAa;AA6BrF,MAAM,iBAAiB,CAAC,QACtB,QAAQ,QACR,OAAO,QAAQ,YACf,UAAU,OACV,YAAY,QACV,IAAwB,SAAS,WAAY,IAAwB,SAAS,YAChF,OAAQ,IAAwB,WAAW,YAC1C,IAAwB,WAAW,QACpC,QAAS,IAAwB,UACjC,OAAQ,IAAwB,OAAO,OAAO;AAEhD,MAAM,aAAa;AAAA,EACjB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AACX;AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AACX;AAEA,MAAM,iBAAiB;AAAA,EACrB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAA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inner } from \"@open-mercato/ui/primitives/spinner\"\nimport { useT } from \"@open-mercato/shared/lib/i18n/context\"\nimport { apiCall } from \"@open-mercato/ui/backend/utils/apiCall\"\nimport { formatRelativeTime, formatDateTime } from \"@open-mercato/shared/lib/time\"\nimport { cn } from \"@open-mercato/shared/lib/utils\"\nimport type { InjectionWidgetComponentProps } from '@open-mercato/shared/modules/widgets/injection'\nimport { ArrowRightLeft, Zap, MessageSquare, User, Filter, ChevronDown, Check } from 'lucide-react'\n\nexport type TimelineEntry = {\n id: string\n occurredAt: string\n kind: \"status\" | \"action\" | \"comment\"\n action: string\n actor: { id: string | null; label: string }\n source: \"action_log\" | \"note\"\n metadata?: {\n statusFrom?: string | null\n statusTo?: string | null\n documentKind?: \"order\" | \"quote\"\n commandId?: string\n }\n}\n\ntype StatusOption = {\n value: string\n label: string\n color: string | null\n icon: string | null\n}\n\ntype TimelineContext = {\n kind: \"order\" | \"quote\"\n record: { id: string }\n}\n\nconst isValidContext = (ctx: unknown): ctx is TimelineContext =>\n ctx !== null &&\n typeof ctx === 'object' &&\n 'kind' in ctx &&\n 'record' in ctx &&\n ((ctx as TimelineContext).kind === 'order' || (ctx as TimelineContext).kind === 'quote') &&\n typeof (ctx as TimelineContext).record === 'object' &&\n (ctx as TimelineContext).record !== null &&\n 'id' in (ctx as TimelineContext).record &&\n typeof (ctx as TimelineContext).record.id === 'string'\n\nconst KIND_ICONS = {\n status: ArrowRightLeft,\n action: Zap,\n comment: MessageSquare,\n}\n\nconst KIND_ICON_COLORS = {\n status: 'text-foreground',\n action: 'text-foreground',\n comment: 'text-foreground',\n}\n\nconst KIND_BG_COLORS = {\n status: 'bg-muted',\n action: 'bg-muted',\n comment: 'bg-muted',\n}\n\nfunction StatusDot({ color, className }: { color: string | null | undefined; className?: string }) {\n if (!color) return <span className={cn('h-2.5 w-2.5 rounded-full bg-muted-foreground/40 border border-border inline-flex', className)} />\n return (\n <span\n className={cn('h-2.5 w-2.5 rounded-full border border-border/60 inline-flex', className)}\n style={{ backgroundColor: color }}\n aria-hidden\n />\n )\n}\n\nfunction StatusTransition({\n statusFrom,\n statusTo,\n statusMap,\n}: {\n statusFrom: string | null | undefined\n statusTo: string | null | undefined\n statusMap: Record<string, StatusOption>\n}) {\n const from = statusFrom ? (statusMap[statusFrom] ?? { value: statusFrom, label: statusFrom, color: null, icon: null }) : null\n const to = statusTo ? (statusMap[statusTo] ?? { value: statusTo, label: statusTo, color: null, icon: null }) : null\n\n return (\n <div className=\"flex items-center gap-1.5 flex-wrap\">\n {from ? (\n <span className=\"inline-flex items-center gap-1 text-xs text-muted-foreground\">\n <StatusDot color={from.color} />\n <span>{from.label}</span>\n </span>\n ) : null}\n {from && to ? (\n <ArrowRightLeft className=\"h-3 w-3 text-muted-foreground/60 shrink-0\" />\n ) : null}\n {to ? (\n <span className=\"inline-flex items-center gap-1 text-xs font-medium text-foreground\">\n <StatusDot color={to.color} />\n <span>{to.label}</span>\n </span>\n ) : null}\n </div>\n )\n}\n\nfunction TimelineItem({\n entry,\n statusMap,\n isLast,\n}: {\n entry: TimelineEntry\n statusMap: Record<string, StatusOption>\n isLast: boolean\n}) {\n const KindIcon = KIND_ICONS[entry.kind]\n const relativeTime = formatRelativeTime(entry.occurredAt)\n const absoluteTime = formatDateTime(entry.occurredAt)\n\n const isStatusChange = entry.kind === 'status' && entry.metadata?.statusTo\n\n return (\n <div data-testid=\"timeline-entry\" className=\"relative flex gap-3\">\n {/* Vertical connector line */}\n {!isLast && (\n <div className=\"absolute left-[11px] top-6 bottom-0 w-px bg-border\" aria-hidden />\n )}\n\n {/* Icon circle */}\n <div\n className={cn(\n 'relative z-10 flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-border',\n KIND_BG_COLORS[entry.kind],\n )}\n >\n <KindIcon className={cn('h-3 w-3', KIND_ICON_COLORS[entry.kind])} aria-hidden />\n </div>\n\n {/* Content card */}\n <div className=\"flex-1 pb-4\">\n <div className=\"group rounded-lg border bg-card p-3 space-y-1.5\">\n {/* Header: actor + time */}\n <div className=\"flex items-center justify-between gap-2 flex-wrap\">\n <span className=\"inline-flex items-center gap-1.5 text-xs font-medium text-foreground\">\n <User className=\"h-3 w-3 text-muted-foreground\" aria-hidden />\n {entry.actor.label}\n </span>\n <span\n className=\"text-xs text-muted-foreground\"\n title={absoluteTime ?? undefined}\n >\n {relativeTime ?? absoluteTime}\n </span>\n </div>\n\n {/* Body */}\n {isStatusChange ? (\n <StatusTransition\n statusFrom={entry.metadata?.statusFrom}\n statusTo={entry.metadata?.statusTo}\n statusMap={statusMap}\n />\n ) : (\n <div className=\"text-sm text-foreground\">{entry.action}</div>\n )}\n </div>\n </div>\n </div>\n )\n}\n\ntype FilterKind = 'all' | 'status' | 'action' | 'comment'\n\ntype FilterOption = { value: FilterKind; label: string }\n\nfunction FilterDropdown({ filter, onChange }: { filter: FilterKind; onChange: (kind: FilterKind) => void }) {\n const t = useT()\n const [open, setOpen] = React.useState(false)\n const ref = React.useRef<HTMLDivElement>(null)\n\n React.useEffect(() => {\n if (!open) return\n function onDocClick(e: MouseEvent) {\n if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false)\n }\n function onKey(e: KeyboardEvent) {\n if (e.key === 'Escape') setOpen(false)\n }\n document.addEventListener('mousedown', onDocClick)\n document.addEventListener('keydown', onKey)\n return () => {\n document.removeEventListener('mousedown', onDocClick)\n document.removeEventListener('keydown', onKey)\n }\n }, [open])\n\n const options: FilterOption[] = [\n { value: 'all', label: t('sales.documents.history.filter.all', 'All') },\n { value: 'status', label: t('sales.documents.history.filter.status', 'Status changes') },\n { value: 'action', label: t('sales.documents.history.filter.actions', 'Actions') },\n { value: 'comment', label: t('sales.documents.history.filter.comments', 'Comments') },\n ]\n\n const activeLabel = options.find(o => o.value === filter)?.label\n\n return (\n <div className=\"relative\" ref={ref}>\n <button\n type=\"button\"\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n onClick={() => setOpen(prev => !prev)}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1 text-xs font-medium shadow-sm hover:bg-accent hover:text-accent-foreground transition-colors select-none\"\n >\n <Filter className=\"h-3 w-3\" aria-hidden />\n {t('sales.documents.history.filter.label', 'Filters')}\n {filter !== 'all' && (\n <span className=\"text-muted-foreground\">: {activeLabel}</span>\n )}\n <ChevronDown className={cn('h-3 w-3 transition-transform duration-150', open && 'rotate-180')} aria-hidden />\n </button>\n {open && (\n <div\n role=\"listbox\"\n aria-label={t('sales.documents.history.filter.label', 'Filters')}\n className=\"absolute left-0 top-full mt-1 z-50 w-48 rounded-md border bg-background p-1 shadow-md\"\n >\n {options.map(opt => (\n <button\n key={opt.value}\n type=\"button\"\n role=\"option\"\n aria-selected={filter === opt.value}\n onClick={() => { onChange(opt.value); setOpen(false) }}\n className=\"flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-accent\"\n >\n <Check className={cn('h-3.5 w-3.5 shrink-0', filter === opt.value ? 'opacity-100' : 'opacity-0')} aria-hidden />\n {opt.label}\n </button>\n ))}\n </div>\n )}\n </div>\n )\n}\n\nexport const DocumentHistoryWidget: React.FC<InjectionWidgetComponentProps<unknown, unknown>> = ({ context }) => {\n const t = useT()\n const [entries, setEntries] = React.useState<TimelineEntry[]>([])\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n const [statusMap, setStatusMap] = React.useState<Record<string, StatusOption>>({})\n const [filter, setFilter] = React.useState<FilterKind>('all')\n\n React.useEffect(() => {\n apiCall<{ items?: unknown[] }>('/api/sales/order-statuses?pageSize=100')\n .then((res) => {\n if (res.ok && Array.isArray(res.result?.items)) {\n const map: Record<string, StatusOption> = {}\n for (const item of res.result.items) {\n if (!item || typeof item !== 'object') continue\n const d = item as Record<string, unknown>\n const value = typeof d.value === 'string' ? d.value : null\n if (!value) continue\n map[value] = {\n value,\n label: typeof d.label === 'string' && d.label.length ? d.label : value,\n color: typeof d.color === 'string' && d.color.length ? d.color : null,\n icon: typeof d.icon === 'string' && d.icon.length ? d.icon : null,\n }\n }\n setStatusMap(map)\n }\n })\n .catch(() => {})\n }, [])\n\n React.useEffect(() => {\n if (!isValidContext(context)) {\n setLoading(false)\n setError(t(\"sales.documents.history.error\", \"Failed to load history.\"))\n return\n }\n\n setLoading(true)\n setError(null)\n apiCall<{ items: TimelineEntry[] }>(\n `/api/sales/document-history?kind=${context.kind}&id=${context.record.id}`\n )\n .then((res) => {\n if (res.ok && Array.isArray(res.result?.items)) {\n setEntries(res.result.items)\n } else {\n setError(t(\"sales.documents.history.error\", \"Failed to load history.\"))\n }\n })\n .catch(() => setError(t(\"sales.documents.history.error\", \"Failed to load history.\")))\n .finally(() => setLoading(false))\n }, [context, t])\n\n const filtered = React.useMemo(\n () => filter === 'all' ? entries : entries.filter(e => e.kind === filter),\n [entries, filter]\n )\n\n return (\n <div className=\"space-y-4\">\n {/* Filter dropdown */}\n <div>\n <FilterDropdown filter={filter} onChange={setFilter} />\n </div>\n\n {/* Content */}\n {loading ? (\n <div className=\"flex items-center justify-center h-24\">\n <Spinner />\n </div>\n ) : error ? (\n <div className=\"text-destructive text-sm\">{error}</div>\n ) : !filtered.length ? (\n <div className=\"text-muted-foreground text-sm py-6 text-center\">\n {t(\"sales.documents.history.empty\", \"No history entries yet.\")}\n </div>\n ) : (\n <div className=\"relative\">\n {filtered.map((entry, index) => (\n <TimelineItem\n key={entry.id}\n entry={entry}\n statusMap={statusMap}\n isLast={index === filtered.length - 1}\n />\n ))}\n </div>\n )}\n </div>\n )\n}\n\nexport default DocumentHistoryWidget\n"],
|
|
5
|
+
"mappings": ";AAoEqB,cAyBb,YAzBa;AAlErB,YAAY,WAAW;AACvB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,oBAAoB,sBAAsB;AACnD,SAAS,UAAU;AAEnB,SAAS,gBAAgB,KAAK,eAAe,MAAM,QAAQ,aAAa,aAAa;AA6BrF,MAAM,iBAAiB,CAAC,QACtB,QAAQ,QACR,OAAO,Q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