@open-mercato/core 0.4.2-canary-51881f6bf3 → 0.4.2-canary-5f415b8a44
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/workflow_event_trigger/index.js +33 -0
- package/dist/generated/entities/workflow_event_trigger/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +59 -58
- 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/auth/events.js +30 -0
- package/dist/modules/auth/events.js.map +7 -0
- package/dist/modules/business_rules/api/execute/[ruleId]/route.js +145 -0
- package/dist/modules/business_rules/api/execute/[ruleId]/route.js.map +7 -0
- package/dist/modules/business_rules/data/validators.js +34 -0
- package/dist/modules/business_rules/data/validators.js.map +2 -2
- package/dist/modules/business_rules/index.js +21 -1
- package/dist/modules/business_rules/index.js.map +2 -2
- package/dist/modules/business_rules/lib/rule-engine.js +182 -1
- package/dist/modules/business_rules/lib/rule-engine.js.map +2 -2
- package/dist/modules/catalog/events.js +34 -0
- package/dist/modules/catalog/events.js.map +7 -0
- package/dist/modules/customers/events.js +49 -0
- package/dist/modules/customers/events.js.map +7 -0
- package/dist/modules/directory/events.js +23 -0
- package/dist/modules/directory/events.js.map +7 -0
- package/dist/modules/sales/acl.js +1 -0
- package/dist/modules/sales/acl.js.map +2 -2
- package/dist/modules/sales/backend/sales/documents/[id]/page.js +12 -0
- package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +62 -0
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/events.js +63 -0
- package/dist/modules/sales/events.js.map +7 -0
- package/dist/modules/sales/lib/dictionaries.js +3 -0
- package/dist/modules/sales/lib/dictionaries.js.map +2 -2
- package/dist/modules/sales/lib/frontend/documentDataEvents.js +25 -0
- package/dist/modules/sales/lib/frontend/documentDataEvents.js.map +7 -0
- package/dist/modules/workflows/acl.js +2 -0
- package/dist/modules/workflows/acl.js.map +2 -2
- package/dist/modules/workflows/api/instances/route.js +18 -6
- package/dist/modules/workflows/api/instances/route.js.map +2 -2
- package/dist/modules/workflows/api/tasks/route.js +6 -1
- package/dist/modules/workflows/api/tasks/route.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/[id]/page.js +9 -1
- package/dist/modules/workflows/backend/definitions/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/[id]/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/create/page.js +24 -15
- package/dist/modules/workflows/backend/definitions/create/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/create/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/create/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js +150 -132
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/visual-editor/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.js +1 -1
- package/dist/modules/workflows/backend/events/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/instances/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/instances/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.js +1 -1
- package/dist/modules/workflows/backend/tasks/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/page.js +5 -6
- package/dist/modules/workflows/backend/tasks/page.js.map +2 -2
- package/dist/modules/workflows/cli.js +81 -3
- package/dist/modules/workflows/cli.js.map +3 -3
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js +481 -0
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js.map +7 -0
- package/dist/modules/workflows/components/EventTriggersEditor.js +553 -0
- package/dist/modules/workflows/components/EventTriggersEditor.js.map +7 -0
- package/dist/modules/workflows/data/entities.js +64 -1
- package/dist/modules/workflows/data/entities.js.map +2 -2
- package/dist/modules/workflows/data/validators.js +115 -0
- package/dist/modules/workflows/data/validators.js.map +2 -2
- package/dist/modules/workflows/events.js +38 -0
- package/dist/modules/workflows/events.js.map +7 -0
- package/dist/modules/workflows/examples/checkout-demo-definition.json +1 -5
- package/dist/modules/workflows/examples/order-approval-definition.json +257 -0
- package/dist/modules/workflows/examples/order-approval-guard-rules.json +32 -0
- package/dist/modules/workflows/lib/activity-executor.js +75 -13
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/dist/modules/workflows/lib/event-trigger-service.js +308 -0
- package/dist/modules/workflows/lib/event-trigger-service.js.map +7 -0
- package/dist/modules/workflows/lib/graph-utils.js +71 -2
- package/dist/modules/workflows/lib/graph-utils.js.map +2 -2
- package/dist/modules/workflows/lib/seeds.js +22 -5
- package/dist/modules/workflows/lib/seeds.js.map +2 -2
- package/dist/modules/workflows/lib/start-validator.js +33 -23
- package/dist/modules/workflows/lib/start-validator.js.map +2 -2
- package/dist/modules/workflows/lib/transition-handler.js +157 -45
- package/dist/modules/workflows/lib/transition-handler.js.map +3 -3
- package/dist/modules/workflows/migrations/Migration20260123143500.js +36 -0
- package/dist/modules/workflows/migrations/Migration20260123143500.js.map +7 -0
- package/dist/modules/workflows/subscribers/event-trigger.js +78 -0
- package/dist/modules/workflows/subscribers/event-trigger.js.map +7 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.client.js +323 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.client.js.map +7 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.js +17 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.js.map +7 -0
- package/dist/modules/workflows/widgets/injection-table.js +19 -0
- package/dist/modules/workflows/widgets/injection-table.js.map +7 -0
- package/generated/entities/workflow_event_trigger/index.ts +15 -0
- package/generated/entities.ids.generated.ts +59 -58
- package/generated/entity-fields-registry.ts +2 -0
- package/package.json +3 -5
- package/src/modules/auth/events.ts +39 -0
- package/src/modules/business_rules/api/execute/[ruleId]/route.ts +163 -0
- package/src/modules/business_rules/data/validators.ts +40 -0
- package/src/modules/business_rules/index.ts +25 -0
- package/src/modules/business_rules/lib/rule-engine.ts +281 -1
- package/src/modules/catalog/events.ts +45 -0
- package/src/modules/customers/events.ts +63 -0
- package/src/modules/directory/events.ts +31 -0
- package/src/modules/sales/acl.ts +1 -0
- package/src/modules/sales/backend/sales/documents/[id]/page.tsx +16 -0
- package/src/modules/sales/commands/documents.ts +74 -1
- package/src/modules/sales/events.ts +82 -0
- package/src/modules/sales/lib/dictionaries.ts +3 -0
- package/src/modules/sales/lib/frontend/documentDataEvents.ts +28 -0
- package/src/modules/workflows/acl.ts +2 -0
- package/src/modules/workflows/api/instances/route.ts +21 -7
- package/src/modules/workflows/api/tasks/route.ts +7 -1
- package/src/modules/workflows/backend/definitions/[id]/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/[id]/page.tsx +9 -0
- package/src/modules/workflows/backend/definitions/create/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/create/page.tsx +9 -0
- package/src/modules/workflows/backend/definitions/visual-editor/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/visual-editor/page.tsx +21 -3
- package/src/modules/workflows/backend/events/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/events/[id]/page.tsx +1 -1
- package/src/modules/workflows/backend/instances/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/tasks/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/tasks/[id]/page.tsx +1 -1
- package/src/modules/workflows/backend/tasks/page.tsx +5 -6
- package/src/modules/workflows/cli.ts +111 -0
- package/src/modules/workflows/components/DefinitionTriggersEditor.tsx +581 -0
- package/src/modules/workflows/components/EventTriggersEditor.tsx +664 -0
- package/src/modules/workflows/data/entities.ts +124 -0
- package/src/modules/workflows/data/validators.ts +138 -0
- package/src/modules/workflows/events.ts +49 -0
- package/src/modules/workflows/examples/checkout-demo-definition.json +1 -5
- package/src/modules/workflows/examples/order-approval-definition.json +257 -0
- package/src/modules/workflows/examples/order-approval-guard-rules.json +32 -0
- package/src/modules/workflows/i18n/en.json +71 -0
- package/src/modules/workflows/lib/activity-executor.ts +129 -16
- package/src/modules/workflows/lib/event-trigger-service.ts +557 -0
- package/src/modules/workflows/lib/graph-utils.ts +117 -2
- package/src/modules/workflows/lib/seeds.ts +34 -8
- package/src/modules/workflows/lib/start-validator.ts +38 -28
- package/src/modules/workflows/lib/transition-handler.ts +208 -55
- package/src/modules/workflows/migrations/Migration20260123143500.ts +38 -0
- package/src/modules/workflows/subscribers/event-trigger.ts +109 -0
- package/src/modules/workflows/widgets/injection/order-approval/widget.client.tsx +446 -0
- package/src/modules/workflows/widgets/injection/order-approval/widget.ts +16 -0
- package/src/modules/workflows/widgets/injection-table.ts +21 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sales/commands/documents.ts"],
|
|
4
|
-
"sourcesContent": ["// @ts-nocheck\n\nimport { randomUUID } from 'crypto'\nimport { z } from 'zod'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport { emitCrudSideEffects, requireId } from '@open-mercato/shared/lib/commands/helpers'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { EventBus } from '@open-mercato/events'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { deriveResourceFromCommandId, invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { setRecordCustomFields } from '@open-mercato/core/modules/entities/lib/helpers'\nimport { loadCustomFieldValues } from '@open-mercato/shared/lib/crud/custom-fields'\nimport { normalizeCustomFieldValues } from '@open-mercato/shared/lib/custom-fields/normalize'\nimport { E } from '#generated/entities.ids.generated'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport {\n SalesQuote,\n SalesQuoteLine,\n SalesQuoteAdjustment,\n SalesOrder,\n SalesOrderLine,\n SalesOrderAdjustment,\n SalesShipment,\n SalesShipmentItem,\n SalesPayment,\n SalesPaymentAllocation,\n SalesDocumentAddress,\n SalesNote,\n SalesChannel,\n SalesShippingMethod,\n SalesDeliveryWindow,\n SalesPaymentMethod,\n SalesDocumentTag,\n SalesDocumentTagAssignment,\n type SalesLineKind,\n type SalesAdjustmentKind,\n type SalesSettings,\n} from '../data/entities'\nimport { CustomFieldValue } from '@open-mercato/core/modules/entities/data/entities'\nimport {\n CustomerAddress,\n CustomerEntity,\n CustomerPersonProfile,\n} from '../../customers/data/entities'\nimport {\n quoteCreateSchema,\n quoteLineCreateSchema,\n quoteAdjustmentCreateSchema,\n orderCreateSchema,\n orderLineCreateSchema,\n orderAdjustmentCreateSchema,\n type QuoteCreateInput,\n type QuoteLineCreateInput,\n type QuoteAdjustmentCreateInput,\n type OrderCreateInput,\n type OrderLineCreateInput,\n type OrderAdjustmentCreateInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n extractUndoPayload,\n toNumericString,\n} from './shared'\nimport {\n loadShipmentSnapshot,\n restoreShipmentSnapshot,\n type ShipmentSnapshot,\n} from './shipments'\nimport {\n loadPaymentSnapshot,\n restorePaymentSnapshot,\n type PaymentSnapshot,\n} from './payments'\nimport type { SalesCalculationService } from '../services/salesCalculationService'\nimport type { TaxCalculationService } from '../services/taxCalculationService'\nimport type { PaymentMethodContext, ShippingMethodContext } from '../lib/providers'\nimport {\n type SalesLineSnapshot,\n type SalesAdjustmentDraft,\n type SalesLineCalculationResult,\n type SalesDocumentCalculationResult,\n} from '../lib/types'\nimport { resolveDictionaryEntryValue } from '../lib/dictionaries'\nimport { resolveStatusEntryIdByValue } from '../lib/statusHelpers'\nimport { SalesDocumentNumberGenerator } from '../services/salesDocumentNumberGenerator'\nimport { loadSalesSettings } from './settings'\n\ntype DocumentAddressSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n documentId: string\n documentKind: 'order' | 'quote'\n customerAddressId: string | null\n name: string | null\n purpose: string | null\n companyName: 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 buildingNumber: string | null\n flatNumber: string | null\n latitude: number | null\n longitude: number | null\n}\n\ntype NoteSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n contextType: 'order' | 'quote'\n contextId: string\n orderId: string | null\n quoteId: string | null\n body: string\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype TagAssignmentSnapshot = {\n id: string\n tagId: string\n organizationId: string\n tenantId: string\n documentId: string\n documentKind: 'order' | 'quote'\n}\n\ntype QuoteGraphSnapshot = {\n quote: {\n id: string\n organizationId: string\n tenantId: string\n quoteNumber: string\n statusEntryId: string | null\n status: string | null\n customerEntityId: string | null\n customerContactId: string | null\n customerSnapshot: Record<string, unknown> | null\n billingAddressId: string | null\n shippingAddressId: string | null\n billingAddressSnapshot: Record<string, unknown> | null\n shippingAddressSnapshot: Record<string, unknown> | null\n currencyCode: string\n validFrom: string | null\n validUntil: string | null\n comments: string | null\n taxInfo: Record<string, unknown> | null\n shippingMethodId: string | null\n shippingMethodCode: string | null\n deliveryWindowId: string | null\n deliveryWindowCode: string | null\n paymentMethodId: string | null\n paymentMethodCode: string | null\n channelId: string | null\n shippingMethodSnapshot: Record<string, unknown> | null\n deliveryWindowSnapshot: Record<string, unknown> | null\n paymentMethodSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n subtotalNetAmount: string\n subtotalGrossAmount: string\n discountTotalAmount: string\n taxTotalAmount: string\n grandTotalNetAmount: string\n grandTotalGrossAmount: string\n totalsSnapshot: Record<string, unknown> | null\n lineItemCount: number\n }\n lines: QuoteLineSnapshot[]\n adjustments: QuoteAdjustmentSnapshot[]\n addresses: DocumentAddressSnapshot[]\n notes: NoteSnapshot[]\n tags: TagAssignmentSnapshot[]\n}\n\ntype QuoteLineSnapshot = {\n id: string\n lineNumber: number\n kind: string\n statusEntryId: string | null\n status: string | null\n productId: string | null\n productVariantId: string | null\n catalogSnapshot: Record<string, unknown> | null\n name: string | null\n description: string | null\n comment: string | null\n quantity: string\n quantityUnit: string | null\n currencyCode: string\n unitPriceNet: string\n unitPriceGross: string\n discountAmount: string\n discountPercent: string\n taxRate: string\n taxAmount: string\n totalNetAmount: string\n totalGrossAmount: string\n configuration: Record<string, unknown> | null\n promotionCode: string | null\n promotionSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype QuoteAdjustmentSnapshot = {\n id: string\n scope: 'order' | 'line'\n kind: string\n code: string | null\n label: string | null\n calculatorKey: string | null\n promotionId: string | null\n rate: string\n amountNet: string\n amountGross: string\n currencyCode: string | null\n metadata: Record<string, unknown> | null\n position: number\n quoteLineId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype OrderGraphSnapshot = {\n order: {\n id: string\n organizationId: string\n tenantId: string\n orderNumber: string\n statusEntryId: string | null\n status: string | null\n fulfillmentStatusEntryId: string | null\n fulfillmentStatus: string | null\n paymentStatusEntryId: string | null\n paymentStatus: string | null\n customerEntityId: string | null\n customerContactId: string | null\n customerSnapshot: Record<string, unknown> | null\n billingAddressId: string | null\n shippingAddressId: string | null\n billingAddressSnapshot: Record<string, unknown> | null\n shippingAddressSnapshot: Record<string, unknown> | null\n currencyCode: string\n exchangeRate: string | null\n taxStrategyKey: string | null\n discountStrategyKey: string | null\n taxInfo: Record<string, unknown> | null\n shippingMethodId: string | null\n shippingMethodCode: string | null\n deliveryWindowId: string | null\n deliveryWindowCode: string | null\n paymentMethodId: string | null\n paymentMethodCode: string | null\n channelId: string | null\n placedAt: string | null\n expectedDeliveryAt: string | null\n dueAt: string | null\n comments: string | null\n internalNotes: string | null\n shippingMethodSnapshot: Record<string, unknown> | null\n deliveryWindowSnapshot: Record<string, unknown> | null\n paymentMethodSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n subtotalNetAmount: string\n subtotalGrossAmount: string\n discountTotalAmount: string\n taxTotalAmount: string\n shippingNetAmount: string\n shippingGrossAmount: string\n surchargeTotalAmount: string\n grandTotalNetAmount: string\n grandTotalGrossAmount: string\n paidTotalAmount: string\n refundedTotalAmount: string\n outstandingAmount: string\n totalsSnapshot: Record<string, unknown> | null\n lineItemCount: number\n }\n lines: OrderLineSnapshot[]\n adjustments: OrderAdjustmentSnapshot[]\n addresses: DocumentAddressSnapshot[]\n notes: NoteSnapshot[]\n tags: TagAssignmentSnapshot[]\n shipments: ShipmentSnapshot[]\n payments: PaymentSnapshot[]\n}\n\ntype OrderLineSnapshot = {\n id: string\n lineNumber: number\n kind: string\n statusEntryId: string | null\n status: string | null\n productId: string | null\n productVariantId: string | null\n catalogSnapshot: Record<string, unknown> | null\n name: string | null\n description: string | null\n comment: string | null\n quantity: string\n quantityUnit: string | null\n reservedQuantity: string\n fulfilledQuantity: string\n invoicedQuantity: string\n returnedQuantity: string\n currencyCode: string\n unitPriceNet: string\n unitPriceGross: string\n discountAmount: string\n discountPercent: string\n taxRate: string\n taxAmount: string\n totalNetAmount: string\n totalGrossAmount: string\n configuration: Record<string, unknown> | null\n promotionCode: string | null\n promotionSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype OrderAdjustmentSnapshot = {\n id: string\n scope: 'order' | 'line'\n kind: string\n code: string | null\n label: string | null\n calculatorKey: string | null\n promotionId: string | null\n rate: string\n amountNet: string\n amountGross: string\n currencyCode: string | null\n metadata: Record<string, unknown> | null\n position: number\n orderLineId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype OrderUndoPayload = {\n before?: OrderGraphSnapshot | null\n after?: OrderGraphSnapshot | null\n}\n\ntype QuoteUndoPayload = {\n before?: QuoteGraphSnapshot | null\n after?: QuoteGraphSnapshot | null\n}\n\ntype QuoteConvertUndoPayload = {\n quote?: QuoteGraphSnapshot | null\n order?: OrderGraphSnapshot | null\n}\n\nconst currencyCodeSchema = z\n .string()\n .trim()\n .toUpperCase()\n .regex(/^[A-Z]{3}$/, { message: 'currency_code_invalid' })\n\nconst dateOnlySchema = z\n .string()\n .trim()\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/, { message: 'invalid_date' })\n .refine((value) => !Number.isNaN(new Date(value).getTime()), { message: 'invalid_date' })\n\nconst addressSnapshotSchema = z.record(z.string(), z.unknown()).nullable().optional()\n\nexport const documentUpdateSchema = z\n .object({\n id: z.string().uuid(),\n customerEntityId: z.string().uuid().nullable().optional(),\n customerContactId: z.string().uuid().nullable().optional(),\n customerSnapshot: z.record(z.string(), z.unknown()).nullable().optional(),\n metadata: z.record(z.string(), z.unknown()).nullable().optional(),\n customerReference: z.string().nullable().optional(),\n externalReference: z.string().nullable().optional(),\n comment: z.string().nullable().optional(),\n currencyCode: currencyCodeSchema.optional(),\n channelId: z.string().uuid().nullable().optional(),\n statusEntryId: z.string().uuid().nullable().optional(),\n placedAt: z.union([dateOnlySchema, z.null()]).optional(),\n expectedDeliveryAt: z.union([dateOnlySchema, z.null()]).optional(),\n shippingAddressId: z.string().uuid().nullable().optional(),\n billingAddressId: z.string().uuid().nullable().optional(),\n shippingAddressSnapshot: addressSnapshotSchema,\n billingAddressSnapshot: addressSnapshotSchema,\n shippingMethodId: z.string().uuid().nullable().optional(),\n shippingMethodCode: z.string().nullable().optional(),\n shippingMethodSnapshot: z.record(z.string(), z.unknown()).nullable().optional(),\n paymentMethodId: z.string().uuid().nullable().optional(),\n paymentMethodCode: z.string().nullable().optional(),\n paymentMethodSnapshot: z.record(z.string(), z.unknown()).nullable().optional(),\n tags: z.array(z.string().uuid()).optional(),\n customFields: z.record(z.string(), z.unknown()).optional(),\n customFieldSetId: z.string().uuid().nullable().optional(),\n })\n .refine(\n (input) =>\n typeof input.currencyCode === 'string' ||\n input.placedAt !== undefined ||\n input.expectedDeliveryAt !== undefined ||\n input.channelId !== undefined ||\n input.statusEntryId !== undefined ||\n input.shippingAddressId !== undefined ||\n input.billingAddressId !== undefined ||\n input.customerEntityId !== undefined ||\n input.customerContactId !== undefined ||\n input.customerSnapshot !== undefined ||\n input.metadata !== undefined ||\n input.customerReference !== undefined ||\n input.externalReference !== undefined ||\n input.comment !== undefined ||\n input.shippingAddressSnapshot !== undefined ||\n input.billingAddressSnapshot !== undefined ||\n input.shippingMethodId !== undefined ||\n input.shippingMethodCode !== undefined ||\n input.shippingMethodSnapshot !== undefined ||\n input.paymentMethodId !== undefined ||\n input.paymentMethodCode !== undefined ||\n input.paymentMethodSnapshot !== undefined ||\n input.tags !== undefined ||\n input.customFields !== undefined ||\n input.customFieldSetId !== undefined,\n { message: 'update_payload_empty' }\n )\n\nexport type DocumentUpdateInput = z.infer<typeof documentUpdateSchema>\n\ntype DocumentLineCreateInput = QuoteLineCreateInput | OrderLineCreateInput\ntype DocumentAdjustmentCreateInput = QuoteAdjustmentCreateInput | OrderAdjustmentCreateInput\n\nfunction cloneJson<T>(value: T): T {\n if (value === null || value === undefined) return value\n return JSON.parse(JSON.stringify(value)) as T\n}\n\nasync function resolveCustomerSnapshot(\n em: EntityManager,\n organizationId: string,\n tenantId: string,\n customerEntityId?: string | null,\n customerContactId?: string | null\n): Promise<Record<string, unknown> | null> {\n if (!customerEntityId) return null\n const customer = await em.findOne(\n CustomerEntity,\n { id: customerEntityId, organizationId, tenantId },\n { populate: ['personProfile', 'companyProfile'] }\n )\n if (!customer) return null\n\n const contact = customerContactId\n ? await em.findOne(CustomerPersonProfile, {\n id: customerContactId,\n organizationId,\n tenantId,\n })\n : null\n\n return {\n customer: {\n id: customer.id,\n kind: customer.kind,\n displayName: customer.displayName,\n primaryEmail: customer.primaryEmail ?? null,\n primaryPhone: customer.primaryPhone ?? null,\n personProfile: customer.personProfile\n ? {\n id: customer.personProfile.id,\n firstName: customer.personProfile.firstName ?? null,\n lastName: customer.personProfile.lastName ?? null,\n preferredName: customer.personProfile.preferredName ?? null,\n }\n : null,\n companyProfile: customer.companyProfile\n ? {\n id: customer.companyProfile.id,\n legalName: customer.companyProfile.legalName ?? null,\n brandName: customer.companyProfile.brandName ?? null,\n domain: customer.companyProfile.domain ?? null,\n websiteUrl: customer.companyProfile.websiteUrl ?? null,\n }\n : null,\n },\n contact: contact\n ? {\n id: contact.id,\n firstName: contact.firstName ?? null,\n lastName: contact.lastName ?? null,\n preferredName: contact.preferredName ?? null,\n jobTitle: contact.jobTitle ?? null,\n department: contact.department ?? null,\n }\n : null,\n }\n}\n\nasync function resolveAddressSnapshot(\n em: EntityManager,\n organizationId: string,\n tenantId: string,\n addressId?: string | null\n): Promise<Record<string, unknown> | null> {\n if (!addressId) return null\n const address = await em.findOne(CustomerAddress, {\n id: addressId,\n organizationId,\n tenantId,\n })\n if (!address) return null\n\n return {\n id: address.id,\n name: address.name ?? null,\n purpose: address.purpose ?? null,\n companyName: address.companyName ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n buildingNumber: address.buildingNumber ?? null,\n flatNumber: address.flatNumber ?? 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 isPrimary: address.isPrimary,\n }\n}\n\nasync function resolveDocumentReferences(\n em: EntityManager,\n parsed: {\n organizationId: string\n tenantId: string\n customerEntityId?: string | null\n customerContactId?: string | null\n customerSnapshot?: Record<string, unknown> | null\n billingAddressId?: string | null\n shippingAddressId?: string | null\n billingAddressSnapshot?: Record<string, unknown> | null\n shippingAddressSnapshot?: Record<string, unknown> | null\n shippingMethodId?: string | null\n deliveryWindowId?: string | null\n paymentMethodId?: string | null\n }\n): Promise<{\n customerSnapshot: Record<string, unknown> | null\n billingAddressSnapshot: Record<string, unknown> | null\n shippingAddressSnapshot: Record<string, unknown> | null\n shippingMethod: SalesShippingMethod | null\n deliveryWindow: SalesDeliveryWindow | null\n paymentMethod: SalesPaymentMethod | null\n}> {\n const [\n resolvedCustomerSnapshot,\n resolvedBillingSnapshot,\n resolvedShippingSnapshot,\n shippingMethod,\n deliveryWindow,\n paymentMethod,\n ] = await Promise.all([\n parsed.customerSnapshot\n ? Promise.resolve(cloneJson(parsed.customerSnapshot))\n : resolveCustomerSnapshot(\n em,\n parsed.organizationId,\n parsed.tenantId,\n parsed.customerEntityId ?? null,\n parsed.customerContactId ?? null\n ),\n parsed.billingAddressSnapshot\n ? Promise.resolve(cloneJson(parsed.billingAddressSnapshot))\n : resolveAddressSnapshot(\n em,\n parsed.organizationId,\n parsed.tenantId,\n parsed.billingAddressId ?? null\n ),\n parsed.shippingAddressSnapshot\n ? Promise.resolve(cloneJson(parsed.shippingAddressSnapshot))\n : resolveAddressSnapshot(\n em,\n parsed.organizationId,\n parsed.tenantId,\n parsed.shippingAddressId ?? null\n ),\n parsed.shippingMethodId\n ? em.findOne(SalesShippingMethod, {\n id: parsed.shippingMethodId,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n : Promise.resolve(null),\n parsed.deliveryWindowId\n ? em.findOne(SalesDeliveryWindow, {\n id: parsed.deliveryWindowId,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n : Promise.resolve(null),\n parsed.paymentMethodId\n ? em.findOne(SalesPaymentMethod, {\n id: parsed.paymentMethodId,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n : Promise.resolve(null),\n ])\n\n return {\n customerSnapshot: resolvedCustomerSnapshot ? cloneJson(resolvedCustomerSnapshot) : null,\n billingAddressSnapshot: resolvedBillingSnapshot ? cloneJson(resolvedBillingSnapshot) : null,\n shippingAddressSnapshot: resolvedShippingSnapshot ? cloneJson(resolvedShippingSnapshot) : null,\n shippingMethod: shippingMethod ?? null,\n deliveryWindow: deliveryWindow ?? null,\n paymentMethod: paymentMethod ?? null,\n }\n}\n\nfunction normalizeStatusValue(raw: unknown): string | null {\n if (typeof raw !== 'string') return null\n const trimmed = raw.trim()\n return trimmed.length ? trimmed : null\n}\n\nfunction resolveNoteAuthorFromAuth(auth: any): string | null {\n if (!auth || auth.isApiKey) return null\n const sub = typeof auth.sub === 'string' ? auth.sub.trim() : ''\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(sub) ? sub : null\n}\n\nfunction resolveStatusChangeActor(auth: any, translate: any): string {\n const unknownLabel = translate('sales.orders.status_change.actor_unknown', 'unknown user')\n if (!auth) return unknownLabel\n if (auth.isApiKey) {\n const keyName = typeof auth.keyName === 'string' ? auth.keyName.trim() : ''\n const keyId = typeof auth.keyId === 'string' ? auth.keyId.trim() : ''\n const label = keyName || keyId || (typeof auth.sub === 'string' ? auth.sub : '')\n return label\n ? translate('sales.orders.status_change.actor_api_key', 'API key {name}', { name: label })\n : unknownLabel\n }\n const email = typeof auth.email === 'string' ? auth.email.trim() : ''\n if (email) return email\n const sub = typeof auth.sub === 'string' ? auth.sub.trim() : ''\n if (sub) return sub\n return unknownLabel\n}\n\nfunction formatStatusLabel(status: string | null, translate: any): string {\n if (status && status.trim().length) return status.trim()\n return translate('sales.orders.status_change.empty', 'unset')\n}\n\nasync function appendOrderStatusChangeNote({\n em,\n order,\n previousStatus,\n auth,\n}: {\n em: EntityManager\n order: SalesOrder\n previousStatus: string | null\n auth: any\n}): Promise<SalesNote | null> {\n const nextStatus = normalizeStatusValue(order.status)\n if (previousStatus === nextStatus) return null\n const { translate } = await resolveTranslations()\n const body = translate(\n 'sales.orders.status_change.note',\n 'Status changed from {from} to {to} by {actor}.',\n {\n from: formatStatusLabel(previousStatus, translate),\n to: formatStatusLabel(nextStatus, translate),\n actor: resolveStatusChangeActor(auth, translate),\n }\n )\n const note = em.create(SalesNote, {\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n contextType: 'order',\n contextId: order.id,\n order,\n authorUserId: resolveNoteAuthorFromAuth(auth),\n appearanceIcon: null,\n appearanceColor: null,\n body,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n return note\n}\n\nasync function applyDocumentUpdate({\n kind,\n entity,\n input,\n em,\n}: {\n kind: 'order' | 'quote'\n entity: SalesOrder | SalesQuote\n input: DocumentUpdateInput\n em: EntityManager\n}): Promise<void> {\n const organizationId = (entity as any).organizationId as string\n const tenantId = (entity as any).tenantId as string\n const status = typeof (entity as any).status === 'string' ? (entity as any).status : null\n const { translate } = await resolveTranslations()\n\n const wantsCustomerChange =\n input.customerEntityId !== undefined ||\n input.customerContactId !== undefined ||\n input.customerSnapshot !== undefined ||\n input.metadata !== undefined\n const wantsAddressChange =\n input.shippingAddressId !== undefined ||\n input.billingAddressId !== undefined ||\n input.shippingAddressSnapshot !== undefined ||\n input.billingAddressSnapshot !== undefined\n\n let settings: SalesSettings | null = null\n if (kind === 'order' && (wantsCustomerChange || wantsAddressChange)) {\n settings = await loadSalesSettings(em, { organizationId, tenantId })\n }\n\n const guardStatus = (allowed: string[] | null | undefined, errorKey: string, fallback: string) => {\n if (!Array.isArray(allowed)) return\n if (allowed.length === 0) {\n throw new CrudHttpError(400, { error: translate(errorKey, fallback) })\n }\n if (!status || !allowed.includes(status)) {\n throw new CrudHttpError(400, { error: translate(errorKey, fallback) })\n }\n }\n\n if (kind === 'order' && wantsCustomerChange) {\n guardStatus(\n settings?.orderCustomerEditableStatuses ?? null,\n 'sales.orders.edit_customer_blocked',\n 'Editing the customer is blocked for this status.'\n )\n }\n if (kind === 'order' && wantsAddressChange) {\n guardStatus(\n settings?.orderAddressEditableStatuses ?? null,\n 'sales.orders.edit_addresses_blocked',\n 'Editing addresses is blocked for this status.'\n )\n }\n\n if (input.customerEntityId !== undefined) {\n entity.customerEntityId = input.customerEntityId ?? null\n entity.customerSnapshot = await resolveCustomerSnapshot(\n em,\n organizationId,\n tenantId,\n input.customerEntityId,\n input.customerContactId ?? entity.customerContactId ?? null\n )\n entity.customerContactId = input.customerContactId ?? null\n entity.billingAddressId = null\n entity.shippingAddressId = null\n entity.billingAddressSnapshot = null\n entity.shippingAddressSnapshot = null\n }\n if (input.customerContactId !== undefined) {\n entity.customerContactId = input.customerContactId ?? null\n if (entity.customerEntityId) {\n entity.customerSnapshot = await resolveCustomerSnapshot(\n em,\n organizationId,\n tenantId,\n entity.customerEntityId,\n input.customerContactId\n )\n }\n }\n if (input.customerSnapshot !== undefined) {\n entity.customerSnapshot = input.customerSnapshot ?? null\n }\n if (input.metadata !== undefined) {\n entity.metadata = input.metadata ?? null\n }\n if (input.externalReference !== undefined) {\n const normalized = typeof input.externalReference === 'string' ? input.externalReference.trim() : ''\n entity.externalReference = normalized.length ? normalized : null\n }\n if (input.customerReference !== undefined) {\n const normalized = typeof input.customerReference === 'string' ? input.customerReference.trim() : ''\n entity.customerReference = normalized.length ? normalized : null\n }\n if (input.comment !== undefined) {\n const normalized = typeof input.comment === 'string' ? input.comment.trim() : ''\n entity.comments = normalized.length ? normalized : null\n }\n if (typeof input.currencyCode === 'string') {\n entity.currencyCode = input.currencyCode\n }\n if (input.channelId !== undefined) {\n if (input.channelId === null) {\n entity.channelId = null\n } else {\n const channel = await em.findOne(SalesChannel, {\n id: input.channelId,\n organizationId,\n tenantId,\n deletedAt: null,\n })\n if (!channel) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.channelInvalid', 'Selected channel could not be found.') })\n }\n entity.channelId = channel.id\n }\n }\n if (input.statusEntryId !== undefined) {\n const statusValue = await resolveDictionaryEntryValue(em, input.statusEntryId)\n if (input.statusEntryId && !statusValue) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.statusInvalid', 'Selected status could not be found.') })\n }\n ;(entity as any).statusEntryId = input.statusEntryId ?? null\n ;(entity as any).status = statusValue\n }\n if (input.placedAt !== undefined) {\n if (input.placedAt === null) {\n entity.placedAt = null\n } else {\n const parsed = new Date(input.placedAt)\n entity.placedAt = Number.isNaN(parsed.getTime()) ? entity.placedAt : parsed\n }\n }\n if (input.expectedDeliveryAt !== undefined && 'expectedDeliveryAt' in entity) {\n if (input.expectedDeliveryAt === null) {\n (entity as SalesOrder).expectedDeliveryAt = null\n } else {\n const parsed = new Date(input.expectedDeliveryAt)\n ;(entity as SalesOrder).expectedDeliveryAt = Number.isNaN(parsed.getTime())\n ? (entity as SalesOrder).expectedDeliveryAt\n : parsed\n }\n }\n if (input.shippingAddressId !== undefined) {\n entity.shippingAddressId = input.shippingAddressId ?? null\n if (input.shippingAddressSnapshot === undefined) {\n entity.shippingAddressSnapshot = await resolveAddressSnapshot(em, organizationId, tenantId, input.shippingAddressId)\n }\n }\n if (input.billingAddressId !== undefined) {\n entity.billingAddressId = input.billingAddressId ?? null\n if (input.billingAddressSnapshot === undefined) {\n entity.billingAddressSnapshot = await resolveAddressSnapshot(em, organizationId, tenantId, input.billingAddressId)\n }\n }\n if (input.shippingAddressSnapshot !== undefined) {\n entity.shippingAddressSnapshot = input.shippingAddressSnapshot ?? null\n }\n if (input.billingAddressSnapshot !== undefined) {\n entity.billingAddressSnapshot = input.billingAddressSnapshot ?? null\n }\n if (input.shippingMethodId !== undefined || input.shippingMethodSnapshot !== undefined || input.shippingMethodCode !== undefined) {\n let shippingMethod: SalesShippingMethod | null = null\n if (input.shippingMethodId) {\n shippingMethod = await em.findOne(SalesShippingMethod, {\n id: input.shippingMethodId,\n organizationId,\n tenantId,\n deletedAt: null,\n })\n if (!shippingMethod) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.shippingMethodInvalid', 'Selected shipping method could not be found.') })\n }\n }\n ;(entity as any).shippingMethodId = input.shippingMethodId ?? null\n ;(entity as any).shippingMethod = shippingMethod ?? null\n ;(entity as any).shippingMethodCode = input.shippingMethodCode ?? shippingMethod?.code ?? null\n if (input.shippingMethodSnapshot !== undefined) {\n ;(entity as any).shippingMethodSnapshot = input.shippingMethodSnapshot ?? null\n } else {\n ;(entity as any).shippingMethodSnapshot = shippingMethod\n ? {\n id: shippingMethod.id,\n code: shippingMethod.code,\n name: shippingMethod.name,\n description: shippingMethod.description ?? null,\n carrierCode: shippingMethod.carrierCode ?? null,\n providerKey: shippingMethod.providerKey ?? null,\n serviceLevel: shippingMethod.serviceLevel ?? null,\n estimatedTransitDays: shippingMethod.estimatedTransitDays ?? null,\n baseRateNet: shippingMethod.baseRateNet,\n baseRateGross: shippingMethod.baseRateGross,\n currencyCode: shippingMethod.currencyCode ?? null,\n metadata: shippingMethod.metadata ? cloneJson(shippingMethod.metadata) : null,\n providerSettings:\n shippingMethod.metadata && typeof shippingMethod.metadata === 'object'\n ? cloneJson(\n (shippingMethod.metadata as Record<string, unknown>).providerSettings ??\n null\n )\n : null,\n }\n : null\n }\n }\n if (input.paymentMethodId !== undefined || input.paymentMethodSnapshot !== undefined || input.paymentMethodCode !== undefined) {\n let paymentMethod: SalesPaymentMethod | null = null\n if (input.paymentMethodId) {\n paymentMethod = await em.findOne(SalesPaymentMethod, {\n id: input.paymentMethodId,\n organizationId,\n tenantId,\n deletedAt: null,\n })\n if (!paymentMethod) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.paymentMethodInvalid', 'Selected payment method could not be found.') })\n }\n }\n ;(entity as any).paymentMethodId = input.paymentMethodId ?? null\n ;(entity as any).paymentMethod = paymentMethod ?? null\n ;(entity as any).paymentMethodCode = input.paymentMethodCode ?? paymentMethod?.code ?? null\n if (input.paymentMethodSnapshot !== undefined) {\n ;(entity as any).paymentMethodSnapshot = input.paymentMethodSnapshot ?? null\n } else {\n ;(entity as any).paymentMethodSnapshot = paymentMethod\n ? {\n id: paymentMethod.id,\n code: paymentMethod.code,\n name: paymentMethod.name,\n description: paymentMethod.description ?? null,\n providerKey: paymentMethod.providerKey ?? null,\n terms: paymentMethod.terms ?? null,\n metadata: paymentMethod.metadata ? cloneJson(paymentMethod.metadata) : null,\n providerSettings:\n paymentMethod.metadata && typeof paymentMethod.metadata === 'object'\n ? cloneJson(\n (paymentMethod.metadata as Record<string, unknown>).providerSettings ??\n null\n )\n : null,\n }\n : null\n }\n }\n\n if (input.tags !== undefined) {\n await syncSalesDocumentTags(em, {\n documentId: entity.id,\n kind,\n organizationId,\n tenantId,\n tagIds: input.tags,\n })\n }\n\n if (input.customFieldSetId !== undefined) {\n ;(entity as any).customFieldSetId = input.customFieldSetId ?? null\n }\n\n if (input.customFields !== undefined) {\n const values =\n input.customFields && typeof input.customFields === 'object' && !Array.isArray(input.customFields)\n ? (input.customFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: kind === 'order' ? E.sales.sales_order : E.sales.sales_quote,\n recordId: entity.id,\n organizationId,\n tenantId,\n values,\n })\n }\n}\n\nasync function loadQuoteSnapshot(em: EntityManager, id: string): Promise<QuoteGraphSnapshot | null> {\n const quote = await em.findOne(SalesQuote, { id, deletedAt: null })\n if (!quote) return null\n const lines = await em.find(SalesQuoteLine, { quote: quote }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesQuoteAdjustment, { quote: quote }, { orderBy: { position: 'asc' } })\n const [addresses, notes, tags, quoteCustomFields, lineCustomFields, adjustmentCustomFields] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: id, documentKind: 'quote' }),\n em.find(SalesNote, { contextType: 'quote', contextId: id }),\n findWithDecryption(\n em,\n SalesDocumentTagAssignment,\n { documentId: id, documentKind: 'quote' },\n { populate: ['tag'] },\n { tenantId: quote.tenantId, organizationId: quote.organizationId },\n ),\n loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote,\n recordIds: [quote.id],\n tenantIdByRecord: { [quote.id]: quote.tenantId },\n organizationIdByRecord: { [quote.id]: quote.organizationId },\n }),\n lines.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote_line,\n recordIds: lines.map((line) => line.id),\n tenantIdByRecord: Object.fromEntries(lines.map((line) => [line.id, quote.tenantId])),\n organizationIdByRecord: Object.fromEntries(lines.map((line) => [line.id, quote.organizationId])),\n })\n : Promise.resolve({}),\n adjustments.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote_adjustment,\n recordIds: adjustments.map((adj) => adj.id),\n tenantIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, quote.tenantId])),\n organizationIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, quote.organizationId])),\n })\n : Promise.resolve({}),\n ])\n const addressSnapshots: DocumentAddressSnapshot[] = addresses.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: entry.documentId,\n documentKind: 'quote',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n }))\n const noteSnapshots: NoteSnapshot[] = notes.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: entry.contextType as 'order' | 'quote',\n contextId: entry.contextId,\n orderId: entry.order ? (typeof entry.order === 'string' ? entry.order : entry.order.id) : null,\n quoteId: entry.quote ? (typeof entry.quote === 'string' ? entry.quote : entry.quote.id) : null,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n }))\n const tagSnapshots: TagAssignmentSnapshot[] = tags\n .map((assignment) => {\n const tagId =\n typeof assignment.tag === 'string'\n ? assignment.tag\n : assignment.tag?.id ?? (assignment as any)?.tag_id ?? null\n if (!tagId) return null\n return {\n id: assignment.id,\n tagId,\n organizationId: assignment.organizationId,\n tenantId: assignment.tenantId,\n documentId: assignment.documentId,\n documentKind: 'quote',\n }\n })\n .filter((entry): entry is TagAssignmentSnapshot => !!entry)\n\n return {\n quote: {\n id: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteNumber: quote.quoteNumber,\n statusEntryId: quote.statusEntryId ?? null,\n status: quote.status ?? null,\n customerEntityId: quote.customerEntityId ?? null,\n customerContactId: quote.customerContactId ?? null,\n customerSnapshot: quote.customerSnapshot ? cloneJson(quote.customerSnapshot) : null,\n billingAddressId: quote.billingAddressId ?? null,\n shippingAddressId: quote.shippingAddressId ?? null,\n billingAddressSnapshot: quote.billingAddressSnapshot ? cloneJson(quote.billingAddressSnapshot) : null,\n shippingAddressSnapshot: quote.shippingAddressSnapshot ? cloneJson(quote.shippingAddressSnapshot) : null,\n currencyCode: quote.currencyCode,\n validFrom: quote.validFrom ? quote.validFrom.toISOString() : null,\n validUntil: quote.validUntil ? quote.validUntil.toISOString() : null,\n comments: quote.comments ?? null,\n taxInfo: quote.taxInfo ? cloneJson(quote.taxInfo) : null,\n shippingMethodId: quote.shippingMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n deliveryWindowId: quote.deliveryWindowId ?? null,\n deliveryWindowCode: quote.deliveryWindowCode ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n channelId: quote.channelId ?? null,\n shippingMethodSnapshot: quote.shippingMethodSnapshot ? cloneJson(quote.shippingMethodSnapshot) : null,\n deliveryWindowSnapshot: quote.deliveryWindowSnapshot ? cloneJson(quote.deliveryWindowSnapshot) : null,\n paymentMethodSnapshot: quote.paymentMethodSnapshot ? cloneJson(quote.paymentMethodSnapshot) : null,\n metadata: quote.metadata ? cloneJson(quote.metadata) : null,\n customFieldSetId: quote.customFieldSetId ?? null,\n customFields: quoteCustomFields[quote.id] ? cloneJson(quoteCustomFields[quote.id]) : null,\n subtotalNetAmount: quote.subtotalNetAmount,\n subtotalGrossAmount: quote.subtotalGrossAmount,\n discountTotalAmount: quote.discountTotalAmount,\n taxTotalAmount: quote.taxTotalAmount,\n grandTotalNetAmount: quote.grandTotalNetAmount,\n grandTotalGrossAmount: quote.grandTotalGrossAmount,\n totalsSnapshot: quote.totalsSnapshot ? cloneJson(quote.totalsSnapshot) : null,\n lineItemCount: quote.lineItemCount,\n },\n lines: lines.map((line) => ({\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n customFields: lineCustomFields[line.id] ? cloneJson(lineCustomFields[line.id]) : null,\n })),\n adjustments: adjustments.map((adj) => ({\n id: adj.id,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? null,\n label: adj.label ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross,\n currencyCode: adj.currencyCode ?? null,\n metadata: adj.metadata ? cloneJson(adj.metadata) : null,\n position: adj.position,\n quoteLineId: typeof adj.quoteLine === 'string' ? adj.quoteLine : adj.quoteLine?.id ?? null,\n customFields: adjustmentCustomFields[adj.id] ? cloneJson(adjustmentCustomFields[adj.id]) : null,\n })),\n addresses: addressSnapshots,\n notes: noteSnapshots,\n tags: tagSnapshots,\n }\n}\n\nasync function loadOrderSnapshot(em: EntityManager, id: string): Promise<OrderGraphSnapshot | null> {\n const order = await em.findOne(SalesOrder, { id, deletedAt: null })\n if (!order) return null\n const lines = await em.find(SalesOrderLine, { order: order }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesOrderAdjustment, { order: order }, { orderBy: { position: 'asc' } })\n const [addresses, notes, tags, shipments, payments, orderCustomFields, lineCustomFields, adjustmentCustomFields] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: id, documentKind: 'order' }),\n em.find(SalesNote, { contextType: 'order', contextId: id }),\n findWithDecryption(\n em,\n SalesDocumentTagAssignment,\n { documentId: id, documentKind: 'order' },\n { populate: ['tag'] },\n { tenantId: order.tenantId, organizationId: order.organizationId },\n ),\n em.find(SalesShipment, { order: order }),\n em.find(SalesPayment, { order: order }),\n loadCustomFieldValues({\n em,\n entityId: E.sales.sales_order,\n recordIds: [order.id],\n tenantIdByRecord: { [order.id]: order.tenantId },\n organizationIdByRecord: { [order.id]: order.organizationId },\n }),\n lines.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_order_line,\n recordIds: lines.map((line) => line.id),\n tenantIdByRecord: Object.fromEntries(lines.map((line) => [line.id, order.tenantId])),\n organizationIdByRecord: Object.fromEntries(lines.map((line) => [line.id, order.organizationId])),\n })\n : Promise.resolve({}),\n adjustments.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_order_adjustment,\n recordIds: adjustments.map((adj) => adj.id),\n tenantIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, order.tenantId])),\n organizationIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, order.organizationId])),\n })\n : Promise.resolve({}),\n ])\n const shipmentSnapshots = (\n await Promise.all(shipments.map((entry) => loadShipmentSnapshot(em, entry.id)))\n ).filter((entry): entry is ShipmentSnapshot => !!entry)\n const paymentSnapshots = (\n await Promise.all(payments.map((entry) => loadPaymentSnapshot(em, entry.id)))\n ).filter((entry): entry is PaymentSnapshot => !!entry)\n const addressSnapshots: DocumentAddressSnapshot[] = addresses.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: entry.documentId,\n documentKind: 'order',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n }))\n const noteSnapshots: NoteSnapshot[] = notes.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: entry.contextType as 'order' | 'quote',\n contextId: entry.contextId,\n orderId: entry.order ? (typeof entry.order === 'string' ? entry.order : entry.order.id) : null,\n quoteId: entry.quote ? (typeof entry.quote === 'string' ? entry.quote : entry.quote.id) : null,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n }))\n const tagSnapshots: TagAssignmentSnapshot[] = tags\n .map((assignment) => {\n const tagId =\n typeof assignment.tag === 'string'\n ? assignment.tag\n : assignment.tag?.id ?? (assignment as any)?.tag_id ?? null\n if (!tagId) return null\n return {\n id: assignment.id,\n tagId,\n organizationId: assignment.organizationId,\n tenantId: assignment.tenantId,\n documentId: assignment.documentId,\n documentKind: 'order',\n }\n })\n .filter((entry): entry is TagAssignmentSnapshot => !!entry)\n\n return {\n order: {\n id: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderNumber: order.orderNumber,\n statusEntryId: order.statusEntryId ?? null,\n status: order.status ?? null,\n fulfillmentStatusEntryId: order.fulfillmentStatusEntryId ?? null,\n fulfillmentStatus: order.fulfillmentStatus ?? null,\n paymentStatusEntryId: order.paymentStatusEntryId ?? null,\n paymentStatus: order.paymentStatus ?? null,\n customerEntityId: order.customerEntityId ?? null,\n customerContactId: order.customerContactId ?? null,\n customerSnapshot: order.customerSnapshot ? cloneJson(order.customerSnapshot) : null,\n billingAddressId: order.billingAddressId ?? null,\n shippingAddressId: order.shippingAddressId ?? null,\n billingAddressSnapshot: order.billingAddressSnapshot ? cloneJson(order.billingAddressSnapshot) : null,\n shippingAddressSnapshot: order.shippingAddressSnapshot ? cloneJson(order.shippingAddressSnapshot) : null,\n currencyCode: order.currencyCode,\n exchangeRate: order.exchangeRate ?? null,\n taxStrategyKey: order.taxStrategyKey ?? null,\n discountStrategyKey: order.discountStrategyKey ?? null,\n taxInfo: order.taxInfo ? cloneJson(order.taxInfo) : null,\n shippingMethodId: order.shippingMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n deliveryWindowId: order.deliveryWindowId ?? null,\n deliveryWindowCode: order.deliveryWindowCode ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n channelId: order.channelId ?? null,\n placedAt: order.placedAt ? order.placedAt.toISOString() : null,\n expectedDeliveryAt: order.expectedDeliveryAt ? order.expectedDeliveryAt.toISOString() : null,\n dueAt: order.dueAt ? order.dueAt.toISOString() : null,\n comments: order.comments ?? null,\n internalNotes: order.internalNotes ?? null,\n shippingMethodSnapshot: order.shippingMethodSnapshot ? cloneJson(order.shippingMethodSnapshot) : null,\n deliveryWindowSnapshot: order.deliveryWindowSnapshot ? cloneJson(order.deliveryWindowSnapshot) : null,\n paymentMethodSnapshot: order.paymentMethodSnapshot ? cloneJson(order.paymentMethodSnapshot) : null,\n metadata: order.metadata ? cloneJson(order.metadata) : null,\n customFieldSetId: order.customFieldSetId ?? null,\n customFields: orderCustomFields[order.id] ? cloneJson(orderCustomFields[order.id]) : null,\n subtotalNetAmount: order.subtotalNetAmount,\n subtotalGrossAmount: order.subtotalGrossAmount,\n discountTotalAmount: order.discountTotalAmount,\n taxTotalAmount: order.taxTotalAmount,\n shippingNetAmount: order.shippingNetAmount,\n shippingGrossAmount: order.shippingGrossAmount,\n surchargeTotalAmount: order.surchargeTotalAmount,\n grandTotalNetAmount: order.grandTotalNetAmount,\n grandTotalGrossAmount: order.grandTotalGrossAmount,\n paidTotalAmount: order.paidTotalAmount,\n refundedTotalAmount: order.refundedTotalAmount,\n outstandingAmount: order.outstandingAmount,\n totalsSnapshot: order.totalsSnapshot ? cloneJson(order.totalsSnapshot) : null,\n lineItemCount: order.lineItemCount,\n },\n lines: lines.map((line) => ({\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n reservedQuantity: line.reservedQuantity,\n fulfilledQuantity: line.fulfilledQuantity,\n invoicedQuantity: line.invoicedQuantity,\n returnedQuantity: line.returnedQuantity,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n customFields: lineCustomFields[line.id] ? cloneJson(lineCustomFields[line.id]) : null,\n })),\n adjustments: adjustments.map((adj) => ({\n id: adj.id,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? null,\n label: adj.label ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross,\n currencyCode: adj.currencyCode ?? null,\n metadata: adj.metadata ? cloneJson(adj.metadata) : null,\n position: adj.position,\n orderLineId: typeof adj.orderLine === 'string' ? adj.orderLine : adj.orderLine?.id ?? null,\n customFields: adjustmentCustomFields[adj.id] ? cloneJson(adjustmentCustomFields[adj.id]) : null,\n })),\n addresses: addressSnapshots,\n notes: noteSnapshots,\n tags: tagSnapshots,\n shipments: shipmentSnapshots,\n payments: paymentSnapshots,\n }\n}\n\ntype DeletableEntity = { id?: string; organizationId?: string | null; tenantId?: string | null }\n\nasync function queueDeletionSideEffects(\n dataEngine: DataEngine,\n entities: DeletableEntity[] | DeletableEntity | null | undefined,\n entityType: string\n): Promise<void> {\n if (!entities) return\n const list = Array.isArray(entities) ? entities : [entities]\n const tasks: Array<Promise<void>> = []\n for (const entity of list) {\n if (!entity) continue\n const id = typeof entity.id === 'string' ? entity.id : null\n if (!id) continue\n tasks.push(\n emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity,\n identifiers: {\n id,\n organizationId: entity.organizationId ?? null,\n tenantId: entity.tenantId ?? null,\n },\n indexer: { entityType },\n })\n )\n }\n if (tasks.length) await Promise.all(tasks)\n}\n\nfunction toNumeric(value: string | number | null | undefined): number {\n if (typeof value === 'number') return value\n if (typeof value === 'string' && value.trim().length) {\n const parsed = Number(value)\n if (!Number.isNaN(parsed)) return parsed\n }\n return 0\n}\n\nfunction normalizeShippingMethodContext(\n snapshot: Record<string, unknown> | null | undefined,\n id?: string | null,\n code?: string | null,\n currencyCode?: string\n): ShippingMethodContext | null {\n if (!snapshot || typeof snapshot !== 'object') return null\n const metadata = (snapshot as Record<string, unknown>).metadata\n const providerSettings =\n (snapshot as Record<string, unknown>).providerSettings ??\n (metadata && typeof metadata === 'object'\n ? (metadata as Record<string, unknown>).providerSettings ?? null\n : null)\n return {\n id: (snapshot as Record<string, unknown>).id as string | undefined ?? id ?? null,\n code:\n typeof (snapshot as Record<string, unknown>).code === 'string'\n ? ((snapshot as Record<string, unknown>).code as string)\n : code ?? null,\n name:\n typeof (snapshot as Record<string, unknown>).name === 'string'\n ? ((snapshot as Record<string, unknown>).name as string)\n : null,\n providerKey:\n typeof (snapshot as Record<string, unknown>).providerKey === 'string'\n ? ((snapshot as Record<string, unknown>).providerKey as string)\n : null,\n currencyCode:\n typeof (snapshot as Record<string, unknown>).currencyCode === 'string'\n ? ((snapshot as Record<string, unknown>).currencyCode as string)\n : currencyCode ?? null,\n baseRateNet: toNumeric(\n ((snapshot as Record<string, unknown>).baseRateNet ??\n (snapshot as Record<string, unknown>).base_rate_net) as string | number | null\n ),\n baseRateGross: toNumeric(\n ((snapshot as Record<string, unknown>).baseRateGross ??\n (snapshot as Record<string, unknown>).base_rate_gross) as string | number | null\n ),\n metadata:\n metadata && typeof metadata === 'object' ? cloneJson(metadata as Record<string, unknown>) : null,\n providerSettings:\n providerSettings && typeof providerSettings === 'object'\n ? cloneJson(providerSettings as Record<string, unknown>)\n : null,\n }\n}\n\nfunction normalizePaymentMethodContext(\n snapshot: Record<string, unknown> | null | undefined,\n id?: string | null,\n code?: string | null\n): PaymentMethodContext | null {\n if (!snapshot || typeof snapshot !== 'object') return null\n const metadata = (snapshot as Record<string, unknown>).metadata\n const providerSettings =\n (snapshot as Record<string, unknown>).providerSettings ??\n (metadata && typeof metadata === 'object'\n ? (metadata as Record<string, unknown>).providerSettings ?? null\n : null)\n return {\n id: (snapshot as Record<string, unknown>).id as string | undefined ?? id ?? null,\n code:\n typeof (snapshot as Record<string, unknown>).code === 'string'\n ? ((snapshot as Record<string, unknown>).code as string)\n : code ?? null,\n name:\n typeof (snapshot as Record<string, unknown>).name === 'string'\n ? ((snapshot as Record<string, unknown>).name as string)\n : null,\n providerKey:\n typeof (snapshot as Record<string, unknown>).providerKey === 'string'\n ? ((snapshot as Record<string, unknown>).providerKey as string)\n : null,\n terms:\n typeof (snapshot as Record<string, unknown>).terms === 'string'\n ? ((snapshot as Record<string, unknown>).terms as string)\n : null,\n metadata:\n metadata && typeof metadata === 'object' ? cloneJson(metadata as Record<string, unknown>) : null,\n providerSettings:\n providerSettings && typeof providerSettings === 'object'\n ? cloneJson(providerSettings as Record<string, unknown>)\n : null,\n }\n}\n\nfunction buildProviderContext(params: {\n shippingSnapshot?: Record<string, unknown> | null\n paymentSnapshot?: Record<string, unknown> | null\n shippingMethodId?: string | null\n paymentMethodId?: string | null\n shippingMethodCode?: string | null\n paymentMethodCode?: string | null\n currencyCode: string\n}) {\n return {\n shippingMethod: normalizeShippingMethodContext(\n params.shippingSnapshot,\n params.shippingMethodId,\n params.shippingMethodCode,\n params.currencyCode\n ),\n paymentMethod: normalizePaymentMethodContext(\n params.paymentSnapshot,\n params.paymentMethodId,\n params.paymentMethodCode\n ),\n }\n}\n\nfunction buildCalculationContext(params: {\n tenantId: string\n organizationId: string\n currencyCode: string\n shippingSnapshot?: Record<string, unknown> | null\n paymentSnapshot?: Record<string, unknown> | null\n shippingMethodId?: string | null\n paymentMethodId?: string | null\n shippingMethodCode?: string | null\n paymentMethodCode?: string | null\n}) {\n return {\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n currencyCode: params.currencyCode,\n metadata: buildProviderContext({\n shippingSnapshot: params.shippingSnapshot,\n paymentSnapshot: params.paymentSnapshot,\n shippingMethodId: params.shippingMethodId,\n paymentMethodId: params.paymentMethodId,\n shippingMethodCode: params.shippingMethodCode,\n paymentMethodCode: params.paymentMethodCode,\n currencyCode: params.currencyCode,\n }),\n }\n}\n\n\nfunction mapOrderLineEntityToSnapshot(line: SalesOrderLine): SalesLineSnapshot {\n return {\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: toNumeric(line.quantity),\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: toNumeric(line.unitPriceNet),\n unitPriceGross: toNumeric(line.unitPriceGross),\n discountAmount: toNumeric(line.discountAmount),\n discountPercent: toNumeric(line.discountPercent),\n taxRate: toNumeric(line.taxRate),\n taxAmount: toNumeric(line.taxAmount),\n totalNetAmount: toNumeric(line.totalNetAmount),\n totalGrossAmount: toNumeric(line.totalGrossAmount),\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n }\n}\n\nfunction mapQuoteLineEntityToSnapshot(line: SalesQuoteLine): SalesLineSnapshot {\n return {\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: toNumeric(line.quantity),\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: toNumeric(line.unitPriceNet),\n unitPriceGross: toNumeric(line.unitPriceGross),\n discountAmount: toNumeric(line.discountAmount),\n discountPercent: toNumeric(line.discountPercent),\n taxRate: toNumeric(line.taxRate),\n taxAmount: toNumeric(line.taxAmount),\n totalNetAmount: toNumeric(line.totalNetAmount),\n totalGrossAmount: toNumeric(line.totalGrossAmount),\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n }\n}\n\nfunction mapOrderAdjustmentToDraft(adjustment: SalesOrderAdjustment): SalesAdjustmentDraft {\n return {\n id: adjustment.id,\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: toNumeric(adjustment.rate),\n amountNet: toNumeric(adjustment.amountNet),\n amountGross: toNumeric(adjustment.amountGross),\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? 0,\n }\n}\n\nfunction mapQuoteAdjustmentToDraft(adjustment: SalesQuoteAdjustment): SalesAdjustmentDraft {\n return {\n id: adjustment.id,\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: toNumeric(adjustment.rate),\n amountNet: toNumeric(adjustment.amountNet),\n amountGross: toNumeric(adjustment.amountGross),\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? 0,\n }\n}\n\nasync function emitTotalsCalculated(\n eventBus: EventBus | null | undefined,\n payload: {\n documentKind: SalesDocumentKind\n documentId: string\n organizationId: string\n tenantId: string\n customerId?: string | null\n totals: SalesDocumentCalculationResult['totals']\n lineCount: number\n }\n): Promise<void> {\n if (!eventBus) return\n await eventBus.emitEvent('sales.document.totals.calculated', payload)\n}\n\nfunction createLineSnapshotFromInput(\n line: DocumentLineCreateInput,\n lineNumber: number\n): SalesLineSnapshot {\n return {\n lineNumber,\n kind: line.kind ?? 'product',\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: Number(line.quantity ?? 0),\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet ?? null,\n unitPriceGross: line.unitPriceGross ?? null,\n discountAmount: line.discountAmount ?? null,\n discountPercent: line.discountPercent ?? null,\n taxRate: line.taxRate ?? null,\n taxAmount: line.taxAmount ?? null,\n totalNetAmount: line.totalNetAmount ?? null,\n totalGrossAmount: line.totalGrossAmount ?? null,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: 'customFieldSetId' in line ? (line as any).customFieldSetId ?? null : null,\n customFields:\n 'customFields' in line && line.customFields\n ? cloneJson((line as any).customFields)\n : null,\n }\n}\n\nfunction createAdjustmentDraftFromInput(\n adjustment: DocumentAdjustmentCreateInput & { id?: string | null }\n): SalesAdjustmentDraft {\n const lineRef =\n 'quoteLineId' in adjustment\n ? (adjustment as any).quoteLineId\n : (adjustment as any).orderLineId\n if (adjustment.scope === 'line' && lineRef) {\n throw new CrudHttpError(400, { error: 'Line-scoped adjustments are not supported yet.' })\n }\n return {\n id: typeof adjustment.id === 'string' ? adjustment.id : undefined,\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind ?? 'custom',\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: adjustment.rate ?? null,\n amountNet: adjustment.amountNet ?? null,\n amountGross: adjustment.amountGross ?? null,\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? 0,\n }\n}\n\nfunction convertLineCalculationToEntityInput(\n lineResult: SalesLineCalculationResult,\n sourceLine: DocumentLineCreateInput,\n document: { organizationId: string; tenantId: string },\n index: number\n) {\n const line = lineResult.line\n return {\n lineNumber: line.lineNumber ?? index + 1,\n kind: line.kind ?? 'product',\n statusEntryId: sourceLine.statusEntryId ?? null,\n productId: sourceLine.productId ?? null,\n productVariantId: sourceLine.productVariantId ?? null,\n catalogSnapshot: sourceLine.catalogSnapshot ? cloneJson(sourceLine.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: toNumericString(line.quantity) ?? '0',\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet:\n toNumericString(line.unitPriceNet ?? (lineResult.netAmount / Math.max(line.quantity || 1, 1))) ??\n '0',\n unitPriceGross:\n toNumericString(\n line.unitPriceGross ?? (lineResult.grossAmount / Math.max(line.quantity || 1, 1))\n ) ?? '0',\n discountAmount: toNumericString(lineResult.discountAmount) ?? '0',\n discountPercent: toNumericString(line.discountPercent) ?? '0',\n taxRate: toNumericString(line.taxRate) ?? '0',\n taxAmount: toNumericString(lineResult.taxAmount) ?? '0',\n totalNetAmount: toNumericString(lineResult.netAmount) ?? '0',\n totalGrossAmount: toNumericString(lineResult.grossAmount) ?? '0',\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: sourceLine.promotionSnapshot ? cloneJson(sourceLine.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: sourceLine.customFieldSetId ?? null,\n organizationId: document.organizationId,\n tenantId: document.tenantId,\n }\n}\n\nfunction convertAdjustmentResultToEntityInput(\n adjustment: SalesAdjustmentDraft,\n sourceAdjustment: DocumentAdjustmentCreateInput | null,\n document: { organizationId: string; tenantId: string },\n index: number\n) {\n const metadata = adjustment.metadata ? cloneJson(adjustment.metadata) : null\n const resolvedPosition =\n sourceAdjustment?.position ??\n (adjustment.position !== null && adjustment.position !== undefined ? adjustment.position : index)\n return {\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind ?? 'custom',\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: toNumericString(adjustment.rate) ?? '0',\n amountNet: toNumericString(adjustment.amountNet) ?? '0',\n amountGross: toNumericString(adjustment.amountGross ?? adjustment.amountNet) ?? '0',\n currencyCode: adjustment.currencyCode ?? null,\n metadata,\n position: resolvedPosition,\n organizationId: document.organizationId,\n tenantId: document.tenantId,\n }\n}\n\nasync function applyOrderLineResults(params: {\n em: EntityManager\n order: SalesOrder\n calculation: SalesDocumentCalculationResult\n sourceLines: Array<DocumentLineCreateInput & { id?: string }>\n existingLines: SalesOrderLine[]\n}): Promise<void> {\n const { em, order, calculation, sourceLines, existingLines } = params\n const existingMap = new Map(existingLines.map((line) => [line.id, line]))\n const persisted = new Set<string>()\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = sourceLines[index]\n const statusEntryId = (sourceLine as any).statusEntryId ?? null\n const statusValue = await resolveStatus(statusEntryId ?? null)\n const payload = convertLineCalculationToEntityInput(lineResult, sourceLine, order, index)\n const existing = sourceLine.id ? existingMap.get(sourceLine.id) ?? null : null\n const lineEntity =\n existing ??\n em.create(SalesOrderLine, {\n order,\n id: sourceLine.id ?? undefined,\n reservedQuantity: existing?.reservedQuantity ?? '0',\n fulfilledQuantity: existing?.fulfilledQuantity ?? '0',\n invoicedQuantity: existing?.invoicedQuantity ?? '0',\n returnedQuantity: existing?.returnedQuantity ?? '0',\n createdAt: existing?.createdAt ?? new Date(),\n updatedAt: new Date(),\n })\n Object.assign(lineEntity, {\n ...payload,\n order,\n statusEntryId,\n status: statusValue,\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: lineEntity.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n persisted.add(lineEntity.id)\n }\n for (const [id, line] of existingMap.entries()) {\n if (!persisted.has(id)) {\n em.remove(line)\n }\n }\n}\n\nasync function applyQuoteLineResults(params: {\n em: EntityManager\n quote: SalesQuote\n calculation: SalesDocumentCalculationResult\n sourceLines: Array<DocumentLineCreateInput & { id?: string }>\n existingLines: SalesQuoteLine[]\n}): Promise<void> {\n const { em, quote, calculation, sourceLines, existingLines } = params\n const existingMap = new Map(existingLines.map((line) => [line.id, line]))\n const persisted = new Set<string>()\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = sourceLines[index]\n const statusEntryId = (sourceLine as any).statusEntryId ?? null\n const statusValue = await resolveStatus(statusEntryId ?? null)\n const payload = convertLineCalculationToEntityInput(lineResult, sourceLine, quote, index)\n const existing = sourceLine.id ? existingMap.get(sourceLine.id) ?? null : null\n const lineEntity =\n existing ??\n em.create(SalesQuoteLine, {\n quote,\n id: sourceLine.id ?? undefined,\n createdAt: existing?.createdAt ?? new Date(),\n updatedAt: new Date(),\n })\n Object.assign(lineEntity, {\n ...payload,\n quote,\n statusEntryId,\n status: statusValue,\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_line,\n recordId: lineEntity.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n persisted.add(lineEntity.id)\n }\n for (const [id, line] of existingMap.entries()) {\n if (!persisted.has(id)) {\n em.remove(line)\n }\n }\n}\n\nasync function replaceQuoteLines(\n em: EntityManager,\n quote: SalesQuote,\n calculation: SalesDocumentCalculationResult,\n lineInputs: QuoteLineCreateInput[]\n): Promise<void> {\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = lineInputs[index]\n const entityInput = convertLineCalculationToEntityInput(lineResult, sourceLine, quote, index)\n const statusValue = await resolveStatus(sourceLine.statusEntryId ?? null)\n const lineEntity = em.create(SalesQuoteLine, {\n quote,\n ...entityInput,\n status: statusValue,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_line,\n recordId: lineEntity.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n }\n}\n\nasync function replaceQuoteAdjustments(\n em: EntityManager,\n quote: SalesQuote,\n calculation: SalesDocumentCalculationResult,\n adjustmentInputs: QuoteAdjustmentCreateInput[] | null\n): Promise<void> {\n const existing = await em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } })\n const existingMap = new Map<string, SalesQuoteAdjustment>()\n existing.forEach((adj) => existingMap.set(adj.id, adj))\n const seen = new Set<string>()\n const adjustmentDrafts = calculation.adjustments\n for (let index = 0; index < adjustmentDrafts.length; index += 1) {\n const draft = adjustmentDrafts[index]\n const sourceById = adjustmentInputs?.find((adj) => (adj as any).id === draft.id) ?? null\n const source = sourceById ?? (adjustmentInputs ? adjustmentInputs[index] ?? null : null)\n const entityInput = convertAdjustmentResultToEntityInput(draft, source, quote, index)\n const adjustmentId =\n (draft as any).id ??\n (source as any)?.id ??\n randomUUID()\n const existingEntity = existingMap.get(adjustmentId)\n const entity =\n existingEntity ??\n em.create(SalesQuoteAdjustment, {\n id: adjustmentId,\n quote,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n createdAt: new Date(),\n })\n entity.scope = entityInput.scope\n entity.kind = entityInput.kind\n entity.code = entityInput.code ?? null\n entity.label = entityInput.label ?? null\n entity.calculatorKey = entityInput.calculatorKey ?? null\n entity.promotionId = entityInput.promotionId ?? null\n entity.rate = entityInput.rate ?? '0'\n entity.amountNet = entityInput.amountNet ?? '0'\n entity.amountGross = entityInput.amountGross ?? entityInput.amountNet ?? '0'\n entity.currencyCode = entityInput.currencyCode ?? quote.currencyCode\n entity.metadata = entityInput.metadata ?? null\n entity.position = entityInput.position ?? index\n entity.updatedAt = new Date()\n entity.quoteLine = null\n seen.add(adjustmentId)\n if (source?.customFields !== undefined) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_adjustment,\n recordId: adjustmentId,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values:\n source.customFields && typeof source.customFields === 'object'\n ? (source.customFields as Record<string, unknown>)\n : {},\n })\n }\n em.persist(entity)\n }\n\n existing.forEach((adj) => {\n if (!seen.has(adj.id)) {\n em.remove(adj)\n }\n })\n}\n\nasync function replaceOrderLines(\n em: EntityManager,\n order: SalesOrder,\n calculation: SalesDocumentCalculationResult,\n lineInputs: OrderLineCreateInput[]\n): Promise<void> {\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = lineInputs[index]\n const entityInput = convertLineCalculationToEntityInput(lineResult, sourceLine, order, index)\n const statusValue = await resolveStatus(sourceLine.statusEntryId ?? null)\n const lineEntity = em.create(SalesOrderLine, {\n order,\n ...entityInput,\n reservedQuantity: '0',\n fulfilledQuantity: '0',\n invoicedQuantity: '0',\n returnedQuantity: '0',\n status: statusValue,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: lineEntity.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n }\n}\n\nasync function replaceOrderAdjustments(\n em: EntityManager,\n order: SalesOrder,\n calculation: SalesDocumentCalculationResult,\n adjustmentInputs: OrderAdjustmentCreateInput[] | null\n): Promise<void> {\n const existing = await em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } })\n const existingMap = new Map<string, SalesOrderAdjustment>()\n existing.forEach((adj) => existingMap.set(adj.id, adj))\n const seen = new Set<string>()\n const adjustmentDrafts = calculation.adjustments\n for (let index = 0; index < adjustmentDrafts.length; index += 1) {\n const draft = adjustmentDrafts[index]\n const sourceById = adjustmentInputs?.find((adj) => (adj as any).id === draft.id) ?? null\n const source = sourceById ?? (adjustmentInputs ? adjustmentInputs[index] ?? null : null)\n const entityInput = convertAdjustmentResultToEntityInput(draft, source, order, index)\n const adjustmentId =\n (draft as any).id ??\n (source as any)?.id ??\n randomUUID()\n const existingEntity = existingMap.get(adjustmentId)\n const entity =\n existingEntity ??\n em.create(SalesOrderAdjustment, {\n id: adjustmentId,\n order,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n createdAt: new Date(),\n })\n entity.scope = entityInput.scope\n entity.kind = entityInput.kind\n entity.code = entityInput.code ?? null\n entity.label = entityInput.label ?? null\n entity.calculatorKey = entityInput.calculatorKey ?? null\n entity.promotionId = entityInput.promotionId ?? null\n entity.rate = entityInput.rate ?? '0'\n entity.amountNet = entityInput.amountNet ?? '0'\n entity.amountGross = entityInput.amountGross ?? entityInput.amountNet ?? '0'\n entity.currencyCode = entityInput.currencyCode ?? order.currencyCode\n entity.metadata = entityInput.metadata ?? null\n entity.position = entityInput.position ?? index\n entity.updatedAt = new Date()\n entity.orderLine = null\n seen.add(adjustmentId)\n if (source?.customFields !== undefined) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_adjustment,\n recordId: adjustmentId,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values:\n source.customFields && typeof source.customFields === 'object'\n ? (source.customFields as Record<string, unknown>)\n : {},\n })\n }\n em.persist(entity)\n }\n\n existing.forEach((adj) => {\n if (!seen.has(adj.id)) {\n em.remove(adj)\n }\n })\n}\n\nfunction applyQuoteTotals(\n quote: SalesQuote,\n totals: SalesDocumentCalculationResult['totals'],\n lineCount: number\n): void {\n quote.subtotalNetAmount = toNumericString(totals.subtotalNetAmount) ?? '0'\n quote.subtotalGrossAmount = toNumericString(totals.subtotalGrossAmount) ?? '0'\n quote.discountTotalAmount = toNumericString(totals.discountTotalAmount) ?? '0'\n quote.taxTotalAmount = toNumericString(totals.taxTotalAmount) ?? '0'\n quote.grandTotalNetAmount = toNumericString(totals.grandTotalNetAmount) ?? '0'\n quote.grandTotalGrossAmount = toNumericString(totals.grandTotalGrossAmount) ?? '0'\n quote.totalsSnapshot = cloneJson(totals)\n quote.lineItemCount = lineCount\n}\n\nfunction applyOrderTotals(\n order: SalesOrder,\n totals: SalesDocumentCalculationResult['totals'],\n lineCount: number\n): void {\n order.subtotalNetAmount = toNumericString(totals.subtotalNetAmount) ?? '0'\n order.subtotalGrossAmount = toNumericString(totals.subtotalGrossAmount) ?? '0'\n order.discountTotalAmount = toNumericString(totals.discountTotalAmount) ?? '0'\n order.taxTotalAmount = toNumericString(totals.taxTotalAmount) ?? '0'\n order.shippingNetAmount = toNumericString(totals.shippingNetAmount) ?? '0'\n order.shippingGrossAmount = toNumericString(totals.shippingGrossAmount) ?? '0'\n order.surchargeTotalAmount = toNumericString(totals.surchargeTotalAmount) ?? '0'\n order.grandTotalNetAmount = toNumericString(totals.grandTotalNetAmount) ?? '0'\n order.grandTotalGrossAmount = toNumericString(totals.grandTotalGrossAmount) ?? '0'\n order.paidTotalAmount = toNumericString(totals.paidTotalAmount) ?? '0'\n order.refundedTotalAmount = toNumericString(totals.refundedTotalAmount) ?? '0'\n order.outstandingAmount = toNumericString(totals.outstandingAmount) ?? '0'\n order.totalsSnapshot = cloneJson(totals)\n order.lineItemCount = lineCount\n}\n\nfunction normalizePaymentTotal(value: unknown): number {\n if (typeof value === 'number' && Number.isFinite(value)) return Math.max(value, 0)\n if (typeof value === 'string' && value.trim().length) {\n const parsed = Number(value)\n return Number.isFinite(parsed) ? Math.max(parsed, 0) : 0\n }\n return 0\n}\n\nfunction resolveExistingPaymentTotals(order: SalesOrder) {\n return {\n paidTotalAmount: normalizePaymentTotal(order.paidTotalAmount),\n refundedTotalAmount: normalizePaymentTotal(order.refundedTotalAmount),\n }\n}\n\nfunction ensureQuoteScope(ctx: Parameters<typeof ensureTenantScope>[0], organizationId: string, tenantId: string): void {\n ensureTenantScope(ctx, tenantId)\n ensureOrganizationScope(ctx, organizationId)\n}\n\nfunction ensureOrderScope(ctx: Parameters<typeof ensureTenantScope>[0], organizationId: string, tenantId: string): void {\n ensureTenantScope(ctx, tenantId)\n ensureOrganizationScope(ctx, organizationId)\n}\n\n\nfunction normalizeTagIds(tags?: Array<string | null | undefined>): string[] {\n if (!Array.isArray(tags)) return []\n const set = new Set<string>()\n tags.forEach((id) => {\n if (typeof id === 'string' && id.trim().length > 0) set.add(id.trim())\n })\n return Array.from(set)\n}\n\nasync function syncSalesDocumentTags(em: EntityManager, params: {\n documentId: string\n kind: SalesDocumentKind\n organizationId: string\n tenantId: string\n tagIds?: Array<string | null | undefined> | null\n}) {\n if (params.tagIds === undefined) return\n const tagIds = normalizeTagIds(params.tagIds)\n if (tagIds.length === 0) {\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: params.documentId, documentKind: params.kind })\n return\n }\n const tagsInScope = await em.find(SalesDocumentTag, {\n id: { $in: tagIds },\n organizationId: params.organizationId,\n tenantId: params.tenantId,\n })\n if (tagsInScope.length !== tagIds.length) {\n throw new CrudHttpError(400, { error: 'One or more tags not found for this scope' })\n }\n const byId = new Map(tagsInScope.map((tag) => [tag.id, tag]))\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: params.documentId, documentKind: params.kind })\n for (const tagId of tagIds) {\n const tag = byId.get(tagId)\n if (!tag) continue\n const assignment = em.create(SalesDocumentTagAssignment, {\n organizationId: params.organizationId,\n tenantId: params.tenantId,\n documentId: params.documentId,\n documentKind: params.kind,\n tag,\n order: params.kind === 'order' ? em.getReference(SalesOrder, params.documentId) : null,\n quote: params.kind === 'quote' ? em.getReference(SalesQuote, params.documentId) : null,\n })\n em.persist(assignment)\n }\n}\n\nfunction applyQuoteSnapshot(quote: SalesQuote, snapshot: QuoteGraphSnapshot['quote']): void {\n quote.organizationId = snapshot.organizationId\n quote.tenantId = snapshot.tenantId\n quote.quoteNumber = snapshot.quoteNumber\n quote.statusEntryId = snapshot.statusEntryId ?? null\n quote.status = snapshot.status ?? null\n quote.customerEntityId = snapshot.customerEntityId ?? null\n quote.customerContactId = snapshot.customerContactId ?? null\n quote.customerSnapshot = snapshot.customerSnapshot ? cloneJson(snapshot.customerSnapshot) : null\n quote.billingAddressId = snapshot.billingAddressId ?? null\n quote.shippingAddressId = snapshot.shippingAddressId ?? null\n quote.billingAddressSnapshot = snapshot.billingAddressSnapshot ? cloneJson(snapshot.billingAddressSnapshot) : null\n quote.shippingAddressSnapshot = snapshot.shippingAddressSnapshot\n ? cloneJson(snapshot.shippingAddressSnapshot)\n : null\n quote.currencyCode = snapshot.currencyCode\n quote.validFrom = snapshot.validFrom ? new Date(snapshot.validFrom) : null\n quote.validUntil = snapshot.validUntil ? new Date(snapshot.validUntil) : null\n quote.comments = snapshot.comments ?? null\n quote.taxInfo = snapshot.taxInfo ? cloneJson(snapshot.taxInfo) : null\n quote.shippingMethodId = snapshot.shippingMethodId ?? null\n quote.shippingMethodCode = snapshot.shippingMethodCode ?? null\n quote.deliveryWindowId = snapshot.deliveryWindowId ?? null\n quote.deliveryWindowCode = snapshot.deliveryWindowCode ?? null\n quote.paymentMethodId = snapshot.paymentMethodId ?? null\n quote.paymentMethodCode = snapshot.paymentMethodCode ?? null\n quote.shippingMethodSnapshot = snapshot.shippingMethodSnapshot ? cloneJson(snapshot.shippingMethodSnapshot) : null\n quote.deliveryWindowSnapshot = snapshot.deliveryWindowSnapshot\n ? cloneJson(snapshot.deliveryWindowSnapshot)\n : null\n quote.paymentMethodSnapshot = snapshot.paymentMethodSnapshot ? cloneJson(snapshot.paymentMethodSnapshot) : null\n quote.metadata = snapshot.metadata ? cloneJson(snapshot.metadata) : null\n quote.channelId = snapshot.channelId ?? null\n quote.customFieldSetId = snapshot.customFieldSetId ?? null\n quote.subtotalNetAmount = snapshot.subtotalNetAmount\n quote.subtotalGrossAmount = snapshot.subtotalGrossAmount\n quote.discountTotalAmount = snapshot.discountTotalAmount\n quote.taxTotalAmount = snapshot.taxTotalAmount\n quote.grandTotalNetAmount = snapshot.grandTotalNetAmount\n quote.grandTotalGrossAmount = snapshot.grandTotalGrossAmount\n quote.totalsSnapshot = snapshot.totalsSnapshot ? cloneJson(snapshot.totalsSnapshot) : null\n quote.lineItemCount = snapshot.lineItemCount\n}\n\nfunction applyOrderSnapshot(order: SalesOrder, snapshot: OrderGraphSnapshot['order']): void {\n order.organizationId = snapshot.organizationId\n order.tenantId = snapshot.tenantId\n order.orderNumber = snapshot.orderNumber\n order.statusEntryId = snapshot.statusEntryId ?? null\n order.status = snapshot.status ?? null\n order.fulfillmentStatusEntryId = snapshot.fulfillmentStatusEntryId ?? null\n order.fulfillmentStatus = snapshot.fulfillmentStatus ?? null\n order.paymentStatusEntryId = snapshot.paymentStatusEntryId ?? null\n order.paymentStatus = snapshot.paymentStatus ?? null\n order.customerEntityId = snapshot.customerEntityId ?? null\n order.customerContactId = snapshot.customerContactId ?? null\n order.customerSnapshot = snapshot.customerSnapshot ? cloneJson(snapshot.customerSnapshot) : null\n order.billingAddressId = snapshot.billingAddressId ?? null\n order.shippingAddressId = snapshot.shippingAddressId ?? null\n order.billingAddressSnapshot = snapshot.billingAddressSnapshot ? cloneJson(snapshot.billingAddressSnapshot) : null\n order.shippingAddressSnapshot = snapshot.shippingAddressSnapshot\n ? cloneJson(snapshot.shippingAddressSnapshot)\n : null\n order.currencyCode = snapshot.currencyCode\n order.exchangeRate = snapshot.exchangeRate ?? null\n order.taxStrategyKey = snapshot.taxStrategyKey ?? null\n order.discountStrategyKey = snapshot.discountStrategyKey ?? null\n order.taxInfo = snapshot.taxInfo ? cloneJson(snapshot.taxInfo) : null\n order.shippingMethodId = snapshot.shippingMethodId ?? null\n order.shippingMethodCode = snapshot.shippingMethodCode ?? null\n order.deliveryWindowId = snapshot.deliveryWindowId ?? null\n order.deliveryWindowCode = snapshot.deliveryWindowCode ?? null\n order.paymentMethodId = snapshot.paymentMethodId ?? null\n order.paymentMethodCode = snapshot.paymentMethodCode ?? null\n order.channelId = snapshot.channelId ?? null\n order.placedAt = snapshot.placedAt ? new Date(snapshot.placedAt) : null\n order.expectedDeliveryAt = snapshot.expectedDeliveryAt ? new Date(snapshot.expectedDeliveryAt) : null\n order.dueAt = snapshot.dueAt ? new Date(snapshot.dueAt) : null\n order.comments = snapshot.comments ?? null\n order.internalNotes = snapshot.internalNotes ?? null\n order.shippingMethodSnapshot = snapshot.shippingMethodSnapshot ? cloneJson(snapshot.shippingMethodSnapshot) : null\n order.deliveryWindowSnapshot = snapshot.deliveryWindowSnapshot\n ? cloneJson(snapshot.deliveryWindowSnapshot)\n : null\n order.paymentMethodSnapshot = snapshot.paymentMethodSnapshot ? cloneJson(snapshot.paymentMethodSnapshot) : null\n order.metadata = snapshot.metadata ? cloneJson(snapshot.metadata) : null\n order.customFieldSetId = snapshot.customFieldSetId ?? null\n order.subtotalNetAmount = snapshot.subtotalNetAmount\n order.subtotalGrossAmount = snapshot.subtotalGrossAmount\n order.discountTotalAmount = snapshot.discountTotalAmount\n order.taxTotalAmount = snapshot.taxTotalAmount\n order.shippingNetAmount = snapshot.shippingNetAmount\n order.shippingGrossAmount = snapshot.shippingGrossAmount\n order.surchargeTotalAmount = snapshot.surchargeTotalAmount\n order.grandTotalNetAmount = snapshot.grandTotalNetAmount\n order.grandTotalGrossAmount = snapshot.grandTotalGrossAmount\n order.paidTotalAmount = snapshot.paidTotalAmount\n order.refundedTotalAmount = snapshot.refundedTotalAmount\n order.outstandingAmount = snapshot.outstandingAmount\n order.totalsSnapshot = snapshot.totalsSnapshot ? cloneJson(snapshot.totalsSnapshot) : null\n order.lineItemCount = snapshot.lineItemCount\n}\n\nasync function restoreQuoteGraph(\n em: EntityManager,\n snapshot: QuoteGraphSnapshot\n): Promise<SalesQuote> {\n let quote = await em.findOne(SalesQuote, { id: snapshot.quote.id })\n if (!quote) {\n quote = em.create(SalesQuote, {\n id: snapshot.quote.id,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n quoteNumber: snapshot.quote.quoteNumber,\n statusEntryId: snapshot.quote.statusEntryId ?? null,\n status: snapshot.quote.status ?? null,\n customerEntityId: snapshot.quote.customerEntityId ?? null,\n customerContactId: snapshot.quote.customerContactId ?? null,\n customerSnapshot: snapshot.quote.customerSnapshot ? cloneJson(snapshot.quote.customerSnapshot) : null,\n billingAddressId: snapshot.quote.billingAddressId ?? null,\n shippingAddressId: snapshot.quote.shippingAddressId ?? null,\n billingAddressSnapshot: snapshot.quote.billingAddressSnapshot\n ? cloneJson(snapshot.quote.billingAddressSnapshot)\n : null,\n shippingAddressSnapshot: snapshot.quote.shippingAddressSnapshot\n ? cloneJson(snapshot.quote.shippingAddressSnapshot)\n : null,\n currencyCode: snapshot.quote.currencyCode,\n validFrom: snapshot.quote.validFrom ? new Date(snapshot.quote.validFrom) : null,\n validUntil: snapshot.quote.validUntil ? new Date(snapshot.quote.validUntil) : null,\n comments: snapshot.quote.comments ?? null,\n taxInfo: snapshot.quote.taxInfo ? cloneJson(snapshot.quote.taxInfo) : null,\n shippingMethodId: snapshot.quote.shippingMethodId ?? null,\n shippingMethodCode: snapshot.quote.shippingMethodCode ?? null,\n deliveryWindowId: snapshot.quote.deliveryWindowId ?? null,\n deliveryWindowCode: snapshot.quote.deliveryWindowCode ?? null,\n paymentMethodId: snapshot.quote.paymentMethodId ?? null,\n paymentMethodCode: snapshot.quote.paymentMethodCode ?? null,\n shippingMethodSnapshot: snapshot.quote.shippingMethodSnapshot\n ? cloneJson(snapshot.quote.shippingMethodSnapshot)\n : null,\n deliveryWindowSnapshot: snapshot.quote.deliveryWindowSnapshot\n ? cloneJson(snapshot.quote.deliveryWindowSnapshot)\n : null,\n paymentMethodSnapshot: snapshot.quote.paymentMethodSnapshot\n ? cloneJson(snapshot.quote.paymentMethodSnapshot)\n : null,\n metadata: snapshot.quote.metadata ? cloneJson(snapshot.quote.metadata) : null,\n channelId: snapshot.quote.channelId ?? null,\n customFieldSetId: snapshot.quote.customFieldSetId ?? null,\n subtotalNetAmount: snapshot.quote.subtotalNetAmount,\n subtotalGrossAmount: snapshot.quote.subtotalGrossAmount,\n discountTotalAmount: snapshot.quote.discountTotalAmount,\n taxTotalAmount: snapshot.quote.taxTotalAmount,\n grandTotalNetAmount: snapshot.quote.grandTotalNetAmount,\n grandTotalGrossAmount: snapshot.quote.grandTotalGrossAmount,\n totalsSnapshot: snapshot.quote.totalsSnapshot ? cloneJson(snapshot.quote.totalsSnapshot) : null,\n lineItemCount: snapshot.quote.lineItemCount,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(quote)\n }\n applyQuoteSnapshot(quote, snapshot.quote)\n const existingLines = await em.find(SalesQuoteLine, { quote: quote.id }, { fields: ['id'] })\n const existingAdjustments = await em.find(SalesQuoteAdjustment, { quote: quote.id }, { fields: ['id'] })\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_quote, recordId: quote.id })\n if (existingLines.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_quote_line,\n recordId: { $in: existingLines.map((line) => line.id) },\n })\n }\n if (existingAdjustments.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_quote_adjustment,\n recordId: { $in: existingAdjustments.map((adj) => adj.id) },\n })\n }\n const addressSnapshots = Array.isArray(snapshot.addresses) ? snapshot.addresses : []\n const noteSnapshots = Array.isArray(snapshot.notes) ? snapshot.notes : []\n const tagSnapshots = Array.isArray(snapshot.tags) ? snapshot.tags : []\n await em.nativeDelete(SalesDocumentAddress, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesNote, { contextType: 'quote', contextId: quote.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n await em.nativeDelete(SalesQuoteAdjustment, { quote: quote.id })\n\n snapshot.lines.forEach((line) => {\n const lineEntity = em.create(SalesQuoteLine, {\n id: line.id,\n quote,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n lineNumber: line.lineNumber,\n kind: line.kind as SalesLineKind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n })\n\n snapshot.adjustments.forEach((adjustment, index) => {\n const adjustmentEntity = em.create(SalesQuoteAdjustment, {\n id: adjustment.id,\n quote,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n scope: adjustment.scope,\n kind: adjustment.kind as SalesAdjustmentKind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: adjustment.rate,\n amountNet: adjustment.amountNet,\n amountGross: adjustment.amountGross,\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? index,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n adjustmentEntity.quoteLine = null\n em.persist(adjustmentEntity)\n })\n\n addressSnapshots.forEach((entry) => {\n const entity = em.create(SalesDocumentAddress, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: quote.id,\n documentKind: 'quote',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n quote,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n noteSnapshots.forEach((entry) => {\n const entity = em.create(SalesNote, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: 'quote',\n contextId: quote.id,\n order: null,\n quote,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n tagSnapshots.forEach((entry) => {\n const tag = em.getReference(SalesDocumentTag, entry.tagId)\n const assignment = em.create(SalesDocumentTagAssignment, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: quote.id,\n documentKind: 'quote',\n tag,\n quote,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(assignment)\n })\n\n if (snapshot.quote.customFields) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote,\n recordId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(snapshot.quote.customFields),\n })\n }\n for (const line of snapshot.lines) {\n if (!line.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_line,\n recordId: line.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(line.customFields),\n })\n }\n for (const adjustment of snapshot.adjustments) {\n if (!adjustment.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_adjustment,\n recordId: adjustment.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(adjustment.customFields),\n })\n }\n\n return quote\n}\n\nasync function restoreOrderGraph(\n em: EntityManager,\n snapshot: OrderGraphSnapshot\n): Promise<SalesOrder> {\n let order = await em.findOne(SalesOrder, { id: snapshot.order.id })\n if (!order) {\n order = em.create(SalesOrder, {\n id: snapshot.order.id,\n organizationId: snapshot.order.organizationId,\n tenantId: snapshot.order.tenantId,\n orderNumber: snapshot.order.orderNumber,\n statusEntryId: snapshot.order.statusEntryId ?? null,\n status: snapshot.order.status ?? null,\n fulfillmentStatusEntryId: snapshot.order.fulfillmentStatusEntryId ?? null,\n fulfillmentStatus: snapshot.order.fulfillmentStatus ?? null,\n paymentStatusEntryId: snapshot.order.paymentStatusEntryId ?? null,\n paymentStatus: snapshot.order.paymentStatus ?? null,\n customerEntityId: snapshot.order.customerEntityId ?? null,\n customerContactId: snapshot.order.customerContactId ?? null,\n customerSnapshot: snapshot.order.customerSnapshot ? cloneJson(snapshot.order.customerSnapshot) : null,\n billingAddressId: snapshot.order.billingAddressId ?? null,\n shippingAddressId: snapshot.order.shippingAddressId ?? null,\n billingAddressSnapshot: snapshot.order.billingAddressSnapshot\n ? cloneJson(snapshot.order.billingAddressSnapshot)\n : null,\n shippingAddressSnapshot: snapshot.order.shippingAddressSnapshot\n ? cloneJson(snapshot.order.shippingAddressSnapshot)\n : null,\n currencyCode: snapshot.order.currencyCode,\n exchangeRate: snapshot.order.exchangeRate ?? null,\n taxStrategyKey: snapshot.order.taxStrategyKey ?? null,\n discountStrategyKey: snapshot.order.discountStrategyKey ?? null,\n taxInfo: snapshot.order.taxInfo ? cloneJson(snapshot.order.taxInfo) : null,\n shippingMethodId: snapshot.order.shippingMethodId ?? null,\n shippingMethodCode: snapshot.order.shippingMethodCode ?? null,\n deliveryWindowId: snapshot.order.deliveryWindowId ?? null,\n deliveryWindowCode: snapshot.order.deliveryWindowCode ?? null,\n paymentMethodId: snapshot.order.paymentMethodId ?? null,\n paymentMethodCode: snapshot.order.paymentMethodCode ?? null,\n channelId: snapshot.order.channelId ?? null,\n placedAt: snapshot.order.placedAt ? new Date(snapshot.order.placedAt) : null,\n expectedDeliveryAt: snapshot.order.expectedDeliveryAt ? new Date(snapshot.order.expectedDeliveryAt) : null,\n dueAt: snapshot.order.dueAt ? new Date(snapshot.order.dueAt) : null,\n comments: snapshot.order.comments ?? null,\n internalNotes: snapshot.order.internalNotes ?? null,\n shippingMethodSnapshot: snapshot.order.shippingMethodSnapshot\n ? cloneJson(snapshot.order.shippingMethodSnapshot)\n : null,\n deliveryWindowSnapshot: snapshot.order.deliveryWindowSnapshot\n ? cloneJson(snapshot.order.deliveryWindowSnapshot)\n : null,\n paymentMethodSnapshot: snapshot.order.paymentMethodSnapshot\n ? cloneJson(snapshot.order.paymentMethodSnapshot)\n : null,\n metadata: snapshot.order.metadata ? cloneJson(snapshot.order.metadata) : null,\n customFieldSetId: snapshot.order.customFieldSetId ?? null,\n subtotalNetAmount: snapshot.order.subtotalNetAmount,\n subtotalGrossAmount: snapshot.order.subtotalGrossAmount,\n discountTotalAmount: snapshot.order.discountTotalAmount,\n taxTotalAmount: snapshot.order.taxTotalAmount,\n shippingNetAmount: snapshot.order.shippingNetAmount,\n shippingGrossAmount: snapshot.order.shippingGrossAmount,\n surchargeTotalAmount: snapshot.order.surchargeTotalAmount,\n grandTotalNetAmount: snapshot.order.grandTotalNetAmount,\n grandTotalGrossAmount: snapshot.order.grandTotalGrossAmount,\n paidTotalAmount: snapshot.order.paidTotalAmount,\n refundedTotalAmount: snapshot.order.refundedTotalAmount,\n outstandingAmount: snapshot.order.outstandingAmount,\n totalsSnapshot: snapshot.order.totalsSnapshot ? cloneJson(snapshot.order.totalsSnapshot) : null,\n lineItemCount: snapshot.order.lineItemCount,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n }\n applyOrderSnapshot(order, snapshot.order)\n const existingLines = await em.find(SalesOrderLine, { order: order.id }, { fields: ['id'] })\n const existingAdjustments = await em.find(SalesOrderAdjustment, { order: order.id }, { fields: ['id'] })\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_order, recordId: order.id })\n if (existingLines.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_order_line,\n recordId: { $in: existingLines.map((line) => line.id) },\n })\n }\n if (existingAdjustments.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_order_adjustment,\n recordId: { $in: existingAdjustments.map((adj) => adj.id) },\n })\n }\n const addressSnapshots = Array.isArray(snapshot.addresses) ? snapshot.addresses : []\n const noteSnapshots = Array.isArray(snapshot.notes) ? snapshot.notes : []\n const tagSnapshots = Array.isArray(snapshot.tags) ? snapshot.tags : []\n const shipmentSnapshots = Array.isArray(snapshot.shipments) ? snapshot.shipments : []\n const paymentSnapshots = Array.isArray(snapshot.payments) ? snapshot.payments : []\n const existingShipments = await em.find(SalesShipment, { order: order.id })\n const shipmentIds = existingShipments.map((entry) => entry.id)\n if (shipmentIds.length) {\n await em.nativeDelete(SalesShipmentItem, { shipment: { $in: shipmentIds } })\n await em.nativeDelete(SalesShipment, { id: { $in: shipmentIds } })\n existingShipments.forEach((entry) => em.getUnitOfWork().unsetIdentity(entry))\n }\n await em.nativeDelete(SalesPaymentAllocation, { order: order.id })\n await em.nativeDelete(SalesPayment, { order: order.id })\n await em.nativeDelete(SalesDocumentAddress, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesNote, { contextType: 'order', contextId: order.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesOrderAdjustment, { order: order.id })\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n\n snapshot.lines.forEach((line) => {\n const lineEntity = em.create(SalesOrderLine, {\n id: line.id,\n order,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n lineNumber: line.lineNumber,\n kind: line.kind as SalesLineKind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n reservedQuantity: line.reservedQuantity,\n fulfilledQuantity: line.fulfilledQuantity,\n invoicedQuantity: line.invoicedQuantity,\n returnedQuantity: line.returnedQuantity,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n })\n\n snapshot.adjustments.forEach((adjustment, index) => {\n const adjustmentEntity = em.create(SalesOrderAdjustment, {\n id: adjustment.id,\n order,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n scope: adjustment.scope,\n kind: adjustment.kind as SalesAdjustmentKind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: adjustment.rate,\n amountNet: adjustment.amountNet,\n amountGross: adjustment.amountGross,\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? index,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n adjustmentEntity.orderLine = null\n em.persist(adjustmentEntity)\n })\n\n addressSnapshots.forEach((entry) => {\n const entity = em.create(SalesDocumentAddress, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: order.id,\n documentKind: 'order',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n order,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n noteSnapshots.forEach((entry) => {\n const entity = em.create(SalesNote, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: 'order',\n contextId: order.id,\n order,\n quote: null,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n tagSnapshots.forEach((entry) => {\n const tag = em.getReference(SalesDocumentTag, entry.tagId)\n const assignment = em.create(SalesDocumentTagAssignment, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: order.id,\n documentKind: 'order',\n tag,\n order,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(assignment)\n })\n\n if (snapshot.order.customFields) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order,\n recordId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(snapshot.order.customFields),\n })\n }\n for (const line of snapshot.lines) {\n if (!line.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: line.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(line.customFields),\n })\n }\n for (const adjustment of snapshot.adjustments) {\n if (!adjustment.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_adjustment,\n recordId: adjustment.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(adjustment.customFields),\n })\n }\n\n for (const shipment of shipmentSnapshots) {\n await restoreShipmentSnapshot(em, shipment)\n }\n\n for (const payment of paymentSnapshots) {\n await restorePaymentSnapshot(em, payment)\n }\n\n return order\n}\n\nconst createQuoteCommand: CommandHandler<QuoteCreateInput, { quoteId: string }> = {\n id: 'sales.quotes.create',\n async execute(rawInput, ctx) {\n const generator = ctx.container.resolve('salesDocumentNumberGenerator') as SalesDocumentNumberGenerator\n const initial = quoteCreateSchema.parse(rawInput ?? {})\n const quoteNumber =\n typeof initial.quoteNumber === 'string' && initial.quoteNumber.trim().length\n ? initial.quoteNumber.trim()\n : (\n await generator.generate({\n kind: 'quote',\n organizationId: initial.organizationId,\n tenantId: initial.tenantId,\n })\n ).number\n const parsed = quoteCreateSchema.parse({ ...initial, quoteNumber })\n const ensuredQuoteNumber = parsed.quoteNumber ?? quoteNumber\n if (!ensuredQuoteNumber) {\n throw new CrudHttpError(400, { error: 'Quote number is required.' })\n }\n ensureQuoteScope(ctx, parsed.organizationId, parsed.tenantId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const {\n customerSnapshot: resolvedCustomerSnapshot,\n billingAddressSnapshot: resolvedBillingSnapshot,\n shippingAddressSnapshot: resolvedShippingSnapshot,\n shippingMethod,\n deliveryWindow,\n paymentMethod,\n } = await resolveDocumentReferences(em, parsed)\n const quoteStatus = await resolveDictionaryEntryValue(em, parsed.statusEntryId ?? null)\n const quote = em.create(SalesQuote, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n quoteNumber: ensuredQuoteNumber,\n statusEntryId: parsed.statusEntryId ?? null,\n status: quoteStatus,\n customerEntityId: parsed.customerEntityId ?? null,\n customerContactId: parsed.customerContactId ?? null,\n customerSnapshot: resolvedCustomerSnapshot ? cloneJson(resolvedCustomerSnapshot) : null,\n billingAddressId: parsed.billingAddressId ?? null,\n shippingAddressId: parsed.shippingAddressId ?? null,\n billingAddressSnapshot: resolvedBillingSnapshot ? cloneJson(resolvedBillingSnapshot) : null,\n shippingAddressSnapshot: resolvedShippingSnapshot ? cloneJson(resolvedShippingSnapshot) : null,\n currencyCode: parsed.currencyCode,\n validFrom: parsed.validFrom ?? null,\n validUntil: parsed.validUntil ?? null,\n comments: parsed.comments ?? null,\n taxInfo: parsed.taxInfo ? cloneJson(parsed.taxInfo) : null,\n shippingMethodId: parsed.shippingMethodId ?? null,\n shippingMethod: shippingMethod ?? null,\n shippingMethodCode: parsed.shippingMethodCode ?? shippingMethod?.code ?? null,\n deliveryWindowId: parsed.deliveryWindowId ?? null,\n deliveryWindow: deliveryWindow ?? null,\n deliveryWindowCode: parsed.deliveryWindowCode ?? deliveryWindow?.code ?? null,\n paymentMethodId: parsed.paymentMethodId ?? null,\n paymentMethod: paymentMethod ?? null,\n paymentMethodCode: parsed.paymentMethodCode ?? paymentMethod?.code ?? null,\n shippingMethodSnapshot: parsed.shippingMethodSnapshot\n ? cloneJson(parsed.shippingMethodSnapshot)\n : shippingMethod\n ? {\n id: shippingMethod.id,\n code: shippingMethod.code,\n name: shippingMethod.name,\n description: shippingMethod.description ?? null,\n carrierCode: shippingMethod.carrierCode ?? null,\n providerKey: shippingMethod.providerKey ?? null,\n serviceLevel: shippingMethod.serviceLevel ?? null,\n estimatedTransitDays: shippingMethod.estimatedTransitDays ?? null,\n baseRateNet: shippingMethod.baseRateNet,\n baseRateGross: shippingMethod.baseRateGross,\n currencyCode: shippingMethod.currencyCode ?? null,\n metadata: shippingMethod.metadata ? cloneJson(shippingMethod.metadata) : null,\n providerSettings:\n shippingMethod.metadata && typeof shippingMethod.metadata === 'object'\n ? cloneJson(\n (shippingMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n deliveryWindowSnapshot: parsed.deliveryWindowSnapshot\n ? cloneJson(parsed.deliveryWindowSnapshot)\n : deliveryWindow\n ? {\n id: deliveryWindow.id,\n code: deliveryWindow.code,\n name: deliveryWindow.name,\n description: deliveryWindow.description ?? null,\n leadTimeDays: deliveryWindow.leadTimeDays ?? null,\n cutoffTime: deliveryWindow.cutoffTime ?? null,\n timezone: deliveryWindow.timezone ?? null,\n }\n : null,\n paymentMethodSnapshot: parsed.paymentMethodSnapshot\n ? cloneJson(parsed.paymentMethodSnapshot)\n : paymentMethod\n ? {\n id: paymentMethod.id,\n code: paymentMethod.code,\n name: paymentMethod.name,\n description: paymentMethod.description ?? null,\n providerKey: paymentMethod.providerKey ?? null,\n terms: paymentMethod.terms ?? null,\n metadata: paymentMethod.metadata ? cloneJson(paymentMethod.metadata) : null,\n providerSettings:\n paymentMethod.metadata && typeof paymentMethod.metadata === 'object'\n ? cloneJson(\n (paymentMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n metadata: parsed.metadata ? cloneJson(parsed.metadata) : null,\n channelId: parsed.channelId ?? null,\n customFieldSetId: parsed.customFieldSetId ?? null,\n subtotalNetAmount: '0',\n subtotalGrossAmount: '0',\n discountTotalAmount: '0',\n taxTotalAmount: '0',\n grandTotalNetAmount: '0',\n grandTotalGrossAmount: '0',\n lineItemCount: 0,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(quote)\n\n const lineInputs = (parsed.lines ?? []).map((line, index) =>\n quoteLineCreateSchema.parse({\n ...line,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n })\n )\n const adjustmentInputs = parsed.adjustments\n ? parsed.adjustments.map((adj) =>\n quoteAdjustmentCreateSchema.parse({\n ...adj,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n quoteId: quote.id,\n })\n )\n : null\n\n const lineSnapshots: SalesLineSnapshot[] = lineInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts: SalesAdjustmentDraft[] = adjustmentInputs\n ? adjustmentInputs.map((adj) => createAdjustmentDraftFromInput(adj))\n : []\n\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n\n await replaceQuoteLines(em, quote, calculation, lineInputs)\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await syncSalesDocumentTags(em, {\n documentId: quote.id,\n kind: 'quote',\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n tagIds: parsed.tags,\n })\n await em.flush()\n\n return { quoteId: quote.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.create', 'Create sales quote'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotAfter: after,\n payload: {\n undo: {\n after,\n } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: after.quote.id })\n if (!quote) return\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n await em.nativeDelete(SalesQuoteAdjustment, { quote: quote.id })\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n em.remove(quote)\n await em.flush()\n },\n}\n\nconst deleteQuoteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string }\n> = {\n id: 'sales.quotes.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Quote id is required')\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadQuoteSnapshot(em, id)\n if (snapshot) {\n ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Quote id is required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const [addresses, notes, tags, adjustments, lines] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: quote.id, documentKind: 'quote' }),\n em.find(SalesNote, { contextType: 'quote', contextId: quote.id }),\n em.find(SalesDocumentTagAssignment, { documentId: quote.id, documentKind: 'quote' }),\n em.find(SalesQuoteAdjustment, { quote: quote.id }),\n em.find(SalesQuoteLine, { quote: quote.id }),\n ])\n await em.nativeDelete(SalesDocumentAddress, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesNote, { contextType: 'quote', contextId: quote.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesQuoteAdjustment, { quote: quote.id })\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n em.remove(quote)\n await em.flush()\n const dataEngine = ctx.container.resolve<DataEngine>('dataEngine')\n await Promise.all([\n queueDeletionSideEffects(dataEngine, quote, E.sales.sales_quote),\n queueDeletionSideEffects(dataEngine, lines, E.sales.sales_quote_line),\n queueDeletionSideEffects(dataEngine, adjustments, E.sales.sales_quote_adjustment),\n queueDeletionSideEffects(dataEngine, addresses, E.sales.sales_document_address),\n queueDeletionSideEffects(dataEngine, notes, E.sales.sales_note),\n queueDeletionSideEffects(dataEngine, tags, E.sales.sales_document_tag_assignment),\n ])\n return { quoteId: id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.delete', 'Delete sales quote'),\n resourceKind: 'sales.quote',\n resourceId: before.quote.id,\n tenantId: before.quote.tenantId,\n organizationId: before.quote.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst updateQuoteCommand: CommandHandler<DocumentUpdateInput, { quote: SalesQuote }> = {\n id: 'sales.quotes.update',\n async prepare(input, ctx) {\n const parsed = documentUpdateSchema.parse(input ?? {})\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadQuoteSnapshot(em, parsed.id)\n if (snapshot) {\n ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = documentUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.id, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const shouldInvalidateSentToken = (quote.status ?? null) === 'sent'\n if (shouldInvalidateSentToken) {\n quote.acceptanceToken = null\n quote.sentAt = null\n }\n const shouldRecalculateTotals =\n parsed.shippingMethodId !== undefined ||\n parsed.shippingMethodSnapshot !== undefined ||\n parsed.shippingMethodCode !== undefined ||\n parsed.paymentMethodId !== undefined ||\n parsed.paymentMethodSnapshot !== undefined ||\n parsed.paymentMethodCode !== undefined ||\n parsed.currencyCode !== undefined\n await applyDocumentUpdate({ kind: 'quote', entity: quote, input: parsed, em })\n if (shouldInvalidateSentToken) {\n quote.status = 'draft'\n quote.statusEntryId = await resolveStatusEntryIdByValue(em, {\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n value: 'draft',\n })\n }\n if (shouldRecalculateTotals) {\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = adjustments.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? quote.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n }\n quote.updatedAt = new Date()\n await em.flush()\n const resourceKind = deriveResourceFromCommandId(updateQuoteCommand.id) ?? 'sales.quote'\n await invalidateCrudCache(\n ctx.container,\n resourceKind,\n { id: quote.id, organizationId: quote.organizationId, tenantId: quote.tenantId },\n ctx.auth?.tenantId ?? null,\n 'updated'\n )\n return { quote }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadQuoteSnapshot(em, result.quote.id)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.update', 'Update sales quote'),\n resourceKind: 'sales.quote',\n resourceId: result.quote.id,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: {\n before,\n after,\n } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst updateOrderCommand: CommandHandler<DocumentUpdateInput, { order: SalesOrder }> = {\n id: 'sales.orders.update',\n async prepare(input, ctx) {\n const parsed = documentUpdateSchema.parse(input ?? {})\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadOrderSnapshot(em, parsed.id)\n if (snapshot) {\n ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = documentUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.id, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n const previousStatus = normalizeStatusValue(order.status)\n let statusChangeNote: SalesNote | null = null\n const shouldRecalculateTotals =\n parsed.shippingMethodId !== undefined ||\n parsed.shippingMethodSnapshot !== undefined ||\n parsed.shippingMethodCode !== undefined ||\n parsed.paymentMethodId !== undefined ||\n parsed.paymentMethodSnapshot !== undefined ||\n parsed.paymentMethodCode !== undefined ||\n parsed.currencyCode !== undefined\n await applyDocumentUpdate({ kind: 'order', entity: order, input: parsed, em })\n if (shouldRecalculateTotals) {\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = adjustments.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? order.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n }\n statusChangeNote = await appendOrderStatusChangeNote({\n em,\n order,\n previousStatus,\n auth: ctx.auth ?? null,\n })\n order.updatedAt = new Date()\n await em.flush()\n if (statusChangeNote) {\n const dataEngine = ctx.container.resolve('dataEngine')\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: statusChangeNote,\n identifiers: {\n id: statusChangeNote.id,\n organizationId: statusChangeNote.organizationId,\n tenantId: statusChangeNote.tenantId,\n },\n indexer: { entityType: E.sales.sales_note },\n })\n }\n const resourceKind = deriveResourceFromCommandId(updateOrderCommand.id) ?? 'sales.order'\n await invalidateCrudCache(\n ctx.container,\n resourceKind,\n { id: order.id, organizationId: order.organizationId, tenantId: order.tenantId },\n ctx.auth?.tenantId ?? null,\n 'updated'\n )\n return { order }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadOrderSnapshot(em, result.order.id)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.update', 'Update sales order'),\n resourceKind: 'sales.order',\n resourceId: result.order.id,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: {\n before,\n after,\n } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst createOrderCommand: CommandHandler<OrderCreateInput, { orderId: string }> = {\n id: 'sales.orders.create',\n async execute(rawInput, ctx) {\n const generator = ctx.container.resolve('salesDocumentNumberGenerator') as SalesDocumentNumberGenerator\n const initial = orderCreateSchema.parse(rawInput ?? {})\n const orderNumber =\n typeof initial.orderNumber === 'string' && initial.orderNumber.trim().length\n ? initial.orderNumber.trim()\n : (\n await generator.generate({\n kind: 'order',\n organizationId: initial.organizationId,\n tenantId: initial.tenantId,\n })\n ).number\n const parsed = orderCreateSchema.parse({ ...initial, orderNumber })\n const ensuredOrderNumber = parsed.orderNumber ?? orderNumber\n if (!ensuredOrderNumber) {\n throw new CrudHttpError(400, { error: 'Order number is required.' })\n }\n ensureOrderScope(ctx, parsed.organizationId, parsed.tenantId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const [status, fulfillmentStatus, paymentStatus] = await Promise.all([\n resolveDictionaryEntryValue(em, parsed.statusEntryId ?? null),\n resolveDictionaryEntryValue(em, parsed.fulfillmentStatusEntryId ?? null),\n resolveDictionaryEntryValue(em, parsed.paymentStatusEntryId ?? null),\n ])\n const {\n customerSnapshot: resolvedCustomerSnapshot,\n billingAddressSnapshot: resolvedBillingSnapshot,\n shippingAddressSnapshot: resolvedShippingSnapshot,\n shippingMethod,\n deliveryWindow,\n paymentMethod,\n } = await resolveDocumentReferences(em, parsed)\n\n const order = em.create(SalesOrder, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n orderNumber: ensuredOrderNumber,\n statusEntryId: parsed.statusEntryId ?? null,\n status,\n fulfillmentStatusEntryId: parsed.fulfillmentStatusEntryId ?? null,\n fulfillmentStatus,\n paymentStatusEntryId: parsed.paymentStatusEntryId ?? null,\n paymentStatus,\n customerEntityId: parsed.customerEntityId ?? null,\n customerContactId: parsed.customerContactId ?? null,\n customerSnapshot: resolvedCustomerSnapshot ? cloneJson(resolvedCustomerSnapshot) : null,\n billingAddressId: parsed.billingAddressId ?? null,\n shippingAddressId: parsed.shippingAddressId ?? null,\n billingAddressSnapshot: resolvedBillingSnapshot ? cloneJson(resolvedBillingSnapshot) : null,\n shippingAddressSnapshot: resolvedShippingSnapshot ? cloneJson(resolvedShippingSnapshot) : null,\n currencyCode: parsed.currencyCode,\n exchangeRate:\n typeof parsed.exchangeRate === 'number' ? toNumericString(parsed.exchangeRate) : null,\n taxStrategyKey: parsed.taxStrategyKey ?? null,\n discountStrategyKey: parsed.discountStrategyKey ?? null,\n taxInfo: parsed.taxInfo ? cloneJson(parsed.taxInfo) : null,\n shippingMethodId: parsed.shippingMethodId ?? null,\n shippingMethod: shippingMethod ?? null,\n shippingMethodCode: parsed.shippingMethodCode ?? shippingMethod?.code ?? null,\n deliveryWindowId: parsed.deliveryWindowId ?? null,\n deliveryWindow: deliveryWindow ?? null,\n deliveryWindowCode: parsed.deliveryWindowCode ?? deliveryWindow?.code ?? null,\n paymentMethodId: parsed.paymentMethodId ?? null,\n paymentMethod: paymentMethod ?? null,\n paymentMethodCode: parsed.paymentMethodCode ?? paymentMethod?.code ?? null,\n channelId: parsed.channelId ?? null,\n placedAt: parsed.placedAt ?? null,\n expectedDeliveryAt: parsed.expectedDeliveryAt ?? null,\n dueAt: parsed.dueAt ?? null,\n comments: parsed.comments ?? null,\n internalNotes: parsed.internalNotes ?? null,\n shippingMethodSnapshot: parsed.shippingMethodSnapshot\n ? cloneJson(parsed.shippingMethodSnapshot)\n : shippingMethod\n ? {\n id: shippingMethod.id,\n code: shippingMethod.code,\n name: shippingMethod.name,\n description: shippingMethod.description ?? null,\n carrierCode: shippingMethod.carrierCode ?? null,\n providerKey: shippingMethod.providerKey ?? null,\n serviceLevel: shippingMethod.serviceLevel ?? null,\n estimatedTransitDays: shippingMethod.estimatedTransitDays ?? null,\n baseRateNet: shippingMethod.baseRateNet,\n baseRateGross: shippingMethod.baseRateGross,\n currencyCode: shippingMethod.currencyCode ?? null,\n metadata: shippingMethod.metadata ? cloneJson(shippingMethod.metadata) : null,\n providerSettings:\n shippingMethod.metadata && typeof shippingMethod.metadata === 'object'\n ? cloneJson(\n (shippingMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n deliveryWindowSnapshot: parsed.deliveryWindowSnapshot\n ? cloneJson(parsed.deliveryWindowSnapshot)\n : deliveryWindow\n ? {\n id: deliveryWindow.id,\n code: deliveryWindow.code,\n name: deliveryWindow.name,\n description: deliveryWindow.description ?? null,\n leadTimeDays: deliveryWindow.leadTimeDays ?? null,\n cutoffTime: deliveryWindow.cutoffTime ?? null,\n timezone: deliveryWindow.timezone ?? null,\n }\n : null,\n paymentMethodSnapshot: parsed.paymentMethodSnapshot\n ? cloneJson(parsed.paymentMethodSnapshot)\n : paymentMethod\n ? {\n id: paymentMethod.id,\n code: paymentMethod.code,\n name: paymentMethod.name,\n description: paymentMethod.description ?? null,\n providerKey: paymentMethod.providerKey ?? null,\n terms: paymentMethod.terms ?? null,\n metadata: paymentMethod.metadata ? cloneJson(paymentMethod.metadata) : null,\n providerSettings:\n paymentMethod.metadata && typeof paymentMethod.metadata === 'object'\n ? cloneJson(\n (paymentMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n metadata: parsed.metadata ? cloneJson(parsed.metadata) : null,\n customFieldSetId: parsed.customFieldSetId ?? null,\n subtotalNetAmount: '0',\n subtotalGrossAmount: '0',\n discountTotalAmount: '0',\n taxTotalAmount: '0',\n shippingNetAmount: '0',\n shippingGrossAmount: '0',\n surchargeTotalAmount: '0',\n grandTotalNetAmount: '0',\n grandTotalGrossAmount: '0',\n paidTotalAmount: '0',\n refundedTotalAmount: '0',\n outstandingAmount: '0',\n lineItemCount: 0,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n\n const lineInputs = (parsed.lines ?? []).map((line, index) =>\n orderLineCreateSchema.parse({\n ...line,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n })\n )\n const adjustmentInputs = parsed.adjustments\n ? parsed.adjustments.map((adj) =>\n orderAdjustmentCreateSchema.parse({\n ...adj,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n orderId: order.id,\n })\n )\n : null\n\n const lineSnapshots: SalesLineSnapshot[] = lineInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts: SalesAdjustmentDraft[] = adjustmentInputs\n ? adjustmentInputs.map((adj) => createAdjustmentDraftFromInput(adj))\n : []\n\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n\n await replaceOrderLines(em, order, calculation, lineInputs)\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await syncSalesDocumentTags(em, {\n documentId: order.id,\n kind: 'order',\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n tagIds: parsed.tags,\n })\n await em.flush()\n\n return { orderId: order.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ result, snapshots }) => {\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.create', 'Create sales order'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotAfter: after,\n payload: {\n undo: {\n after,\n } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: after.order.id })\n if (!order) return\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n await em.nativeDelete(SalesOrderAdjustment, { order: order.id })\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n em.remove(order)\n await em.flush()\n },\n}\n\nconst deleteOrderCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string }\n> = {\n id: 'sales.orders.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Order id is required')\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadOrderSnapshot(em, id)\n if (snapshot) {\n ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Order id is required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n const shipments = await em.find(SalesShipment, { order: order.id })\n const shipmentIds = shipments.map((entry) => entry.id)\n const [shipmentItems, payments, paymentAllocations, addresses, notes, tags, adjustments, lines] = await Promise.all([\n shipmentIds.length ? em.find(SalesShipmentItem, { shipment: { $in: shipmentIds } }) : Promise.resolve([]),\n em.find(SalesPayment, { order: order.id }),\n em.find(SalesPaymentAllocation, { order: order.id }),\n em.find(SalesDocumentAddress, { documentId: order.id, documentKind: 'order' }),\n em.find(SalesNote, { contextType: 'order', contextId: order.id }),\n em.find(SalesDocumentTagAssignment, { documentId: order.id, documentKind: 'order' }),\n em.find(SalesOrderAdjustment, { order: order.id }),\n em.find(SalesOrderLine, { order: order.id }),\n ])\n if (shipmentIds.length) {\n await em.nativeDelete(SalesShipmentItem, { shipment: { $in: shipmentIds } })\n await em.nativeDelete(SalesShipment, { id: { $in: shipmentIds } })\n }\n await em.nativeDelete(SalesPaymentAllocation, { order: order.id })\n await em.nativeDelete(SalesPayment, { order: order.id })\n await em.nativeDelete(SalesDocumentAddress, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesNote, { contextType: 'order', contextId: order.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesOrderAdjustment, { order: order.id })\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n em.remove(order)\n await em.flush()\n const dataEngine = ctx.container.resolve<DataEngine>('dataEngine')\n await Promise.all([\n queueDeletionSideEffects(dataEngine, order, E.sales.sales_order),\n queueDeletionSideEffects(dataEngine, lines, E.sales.sales_order_line),\n queueDeletionSideEffects(dataEngine, adjustments, E.sales.sales_order_adjustment),\n queueDeletionSideEffects(dataEngine, shipments, E.sales.sales_shipment),\n queueDeletionSideEffects(dataEngine, shipmentItems, E.sales.sales_shipment_item),\n queueDeletionSideEffects(dataEngine, payments, E.sales.sales_payment),\n queueDeletionSideEffects(dataEngine, paymentAllocations, E.sales.sales_payment_allocation),\n queueDeletionSideEffects(dataEngine, addresses, E.sales.sales_document_address),\n queueDeletionSideEffects(dataEngine, notes, E.sales.sales_note),\n queueDeletionSideEffects(dataEngine, tags, E.sales.sales_document_tag_assignment),\n ])\n return { orderId: id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.delete', 'Delete sales order'),\n resourceKind: 'sales.order',\n resourceId: before.order.id,\n tenantId: before.order.tenantId,\n organizationId: before.order.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteConvertToOrderSchema = z.object({\n quoteId: z.string().uuid(),\n orderId: z.string().uuid().optional(),\n orderNumber: z.string().trim().max(191).optional(),\n})\n\nconst convertQuoteToOrderCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string }\n> = {\n id: 'sales.quotes.convert_to_order',\n async prepare(input, ctx) {\n const parsed = quoteConvertToOrderSchema.safeParse(input ?? {})\n const quoteId = parsed.success ? parsed.data.quoteId : typeof (input as any)?.quoteId === 'string' ? (input as any).quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const payload = quoteConvertToOrderSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: payload.quoteId, deletedAt: null })\n const { translate } = await resolveTranslations()\n if (!quote) throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const snapshot = await loadQuoteSnapshot(em, payload.quoteId)\n if (!snapshot) throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n const orderId = payload.orderId ?? quote.id\n const existingOrder = await em.findOne(SalesOrder, { id: orderId, deletedAt: null })\n if (existingOrder) {\n throw new CrudHttpError(409, { error: translate('sales.documents.detail.convertExists', 'Order already exists for this quote.') })\n }\n\n const generator = ctx.container.resolve('salesDocumentNumberGenerator') as SalesDocumentNumberGenerator\n const generatedNumber =\n snapshot.quote.quoteNumber && snapshot.quote.quoteNumber.trim().length\n ? snapshot.quote.quoteNumber\n : (\n await generator.generate({\n kind: 'order',\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n })\n ).number\n const orderNumber =\n typeof payload.orderNumber === 'string' && payload.orderNumber.trim().length\n ? payload.orderNumber.trim()\n : generatedNumber\n\n const [quoteCustomFields, quoteLineCustomFields] = await Promise.all([\n loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote,\n recordIds: [snapshot.quote.id],\n tenantIdByRecord: { [snapshot.quote.id]: snapshot.quote.tenantId },\n organizationIdByRecord: { [snapshot.quote.id]: snapshot.quote.organizationId },\n }),\n snapshot.lines.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote_line,\n recordIds: snapshot.lines.map((line) => line.id),\n tenantIdByRecord: Object.fromEntries(snapshot.lines.map((line) => [line.id, snapshot.quote.tenantId])),\n organizationIdByRecord: Object.fromEntries(snapshot.lines.map((line) => [line.id, snapshot.quote.organizationId])),\n })\n : Promise.resolve({}),\n ])\n\n const order = em.create(SalesOrder, {\n id: orderId,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n orderNumber,\n statusEntryId: snapshot.quote.statusEntryId ?? null,\n status: snapshot.quote.status ?? null,\n fulfillmentStatusEntryId: null,\n fulfillmentStatus: null,\n paymentStatusEntryId: null,\n paymentStatus: null,\n customerEntityId: snapshot.quote.customerEntityId ?? null,\n customerContactId: snapshot.quote.customerContactId ?? null,\n customerSnapshot: snapshot.quote.customerSnapshot ? cloneJson(snapshot.quote.customerSnapshot) : null,\n billingAddressId: snapshot.quote.billingAddressId ?? null,\n shippingAddressId: snapshot.quote.shippingAddressId ?? null,\n billingAddressSnapshot: snapshot.quote.billingAddressSnapshot ? cloneJson(snapshot.quote.billingAddressSnapshot) : null,\n shippingAddressSnapshot: snapshot.quote.shippingAddressSnapshot ? cloneJson(snapshot.quote.shippingAddressSnapshot) : null,\n currencyCode: snapshot.quote.currencyCode,\n exchangeRate: null,\n taxStrategyKey: null,\n discountStrategyKey: null,\n taxInfo: snapshot.quote.taxInfo ? cloneJson(snapshot.quote.taxInfo) : null,\n shippingMethodId: snapshot.quote.shippingMethodId ?? null,\n shippingMethodCode: snapshot.quote.shippingMethodCode ?? null,\n deliveryWindowId: snapshot.quote.deliveryWindowId ?? null,\n deliveryWindowCode: snapshot.quote.deliveryWindowCode ?? null,\n paymentMethodId: snapshot.quote.paymentMethodId ?? null,\n paymentMethodCode: snapshot.quote.paymentMethodCode ?? null,\n channelId: snapshot.quote.channelId ?? null,\n placedAt: snapshot.quote.validFrom ? new Date(snapshot.quote.validFrom) : quote.createdAt,\n expectedDeliveryAt: snapshot.quote.validUntil ? new Date(snapshot.quote.validUntil) : null,\n dueAt: null,\n comments: snapshot.quote.comments ?? null,\n internalNotes: null,\n shippingMethodSnapshot: snapshot.quote.shippingMethodSnapshot ? cloneJson(snapshot.quote.shippingMethodSnapshot) : null,\n deliveryWindowSnapshot: snapshot.quote.deliveryWindowSnapshot ? cloneJson(snapshot.quote.deliveryWindowSnapshot) : null,\n paymentMethodSnapshot: snapshot.quote.paymentMethodSnapshot ? cloneJson(snapshot.quote.paymentMethodSnapshot) : null,\n metadata: snapshot.quote.metadata ? cloneJson(snapshot.quote.metadata) : null,\n customFieldSetId: snapshot.quote.customFieldSetId ?? null,\n subtotalNetAmount: snapshot.quote.subtotalNetAmount,\n subtotalGrossAmount: snapshot.quote.subtotalGrossAmount,\n discountTotalAmount: snapshot.quote.discountTotalAmount,\n taxTotalAmount: snapshot.quote.taxTotalAmount,\n shippingNetAmount: '0',\n shippingGrossAmount: '0',\n surchargeTotalAmount: '0',\n grandTotalNetAmount: snapshot.quote.grandTotalNetAmount,\n grandTotalGrossAmount: snapshot.quote.grandTotalGrossAmount,\n paidTotalAmount: '0',\n refundedTotalAmount: '0',\n outstandingAmount: snapshot.quote.grandTotalGrossAmount,\n totalsSnapshot: snapshot.quote.totalsSnapshot ? cloneJson(snapshot.quote.totalsSnapshot) : null,\n lineItemCount: snapshot.quote.lineItemCount,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n\n const orderLineMap = new Map<string, SalesOrderLine>()\n snapshot.lines.forEach((line, index) => {\n const orderLine = em.create(SalesOrderLine, {\n id: line.id,\n order,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n lineNumber: line.lineNumber ?? index + 1,\n kind: line.kind as SalesLineKind,\n statusEntryId: (line as any).statusEntryId ?? null,\n status: (line as any).status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n reservedQuantity: '0',\n fulfilledQuantity: '0',\n invoicedQuantity: '0',\n returnedQuantity: '0',\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(orderLine)\n orderLineMap.set(orderLine.id, orderLine)\n })\n\n snapshot.adjustments.forEach((adj, index) => {\n const orderLineId = adj.quoteLineId ?? null\n const orderLine = orderLineId ? orderLineMap.get(orderLineId) ?? null : null\n const entity = em.create(SalesOrderAdjustment, {\n id: adj.id,\n order,\n orderLine: orderLine ?? null,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n scope: adj.scope,\n kind: adj.kind as SalesAdjustmentKind,\n code: adj.code ?? null,\n label: adj.label ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross,\n currencyCode: adj.currencyCode ?? null,\n metadata: adj.metadata ? cloneJson(adj.metadata) : null,\n position: adj.position ?? index,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n const [addresses, notes, tags] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: snapshot.quote.id, documentKind: 'quote' }),\n em.find(SalesNote, { contextType: 'quote', contextId: snapshot.quote.id }),\n em.find(SalesDocumentTagAssignment, { documentId: snapshot.quote.id, documentKind: 'quote' }),\n ])\n addresses.forEach((entry) => {\n entry.documentKind = 'order'\n entry.documentId = order.id\n entry.order = order\n entry.quote = null\n entry.updatedAt = new Date()\n })\n notes.forEach((note) => {\n note.contextType = 'order'\n note.contextId = order.id\n note.order = order\n note.quote = null\n note.updatedAt = new Date()\n })\n tags.forEach((assignment) => {\n assignment.documentKind = 'order'\n assignment.documentId = order.id\n assignment.order = order\n assignment.quote = null\n assignment.updatedAt = new Date()\n })\n\n const documentCustomValues = quoteCustomFields[snapshot.quote.id]\n if (documentCustomValues && Object.keys(documentCustomValues).length) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order,\n recordId: order.id,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n values: documentCustomValues,\n })\n }\n const lineCustomEntries = quoteLineCustomFields as Record<string, Record<string, unknown>>\n if (lineCustomEntries && Object.keys(lineCustomEntries).length) {\n for (const [lineId, values] of Object.entries(lineCustomEntries)) {\n if (!values || !Object.keys(values).length) continue\n if (!orderLineMap.has(lineId)) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: lineId,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n values,\n })\n }\n }\n\n await em.nativeDelete(SalesQuoteAdjustment, { quote: snapshot.quote.id })\n await em.nativeDelete(SalesQuoteLine, { quote: snapshot.quote.id })\n em.remove(quote)\n await em.flush()\n\n return { orderId: order.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.convert', 'Convert quote to order'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: before.quote.tenantId,\n organizationId: before.quote.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n payload: {\n undo: { quote: before, order: after ?? null } satisfies QuoteConvertUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteConvertUndoPayload>(logEntry)\n const quoteSnapshot = payload?.quote\n const orderSnapshot = payload?.order\n if (!quoteSnapshot) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, quoteSnapshot.quote.organizationId, quoteSnapshot.quote.tenantId)\n if (orderSnapshot) {\n const orderId = orderSnapshot.order.id\n const orderLineIds = orderSnapshot.lines.map((line) => line.id)\n const existingOrder = await em.findOne(SalesOrder, { id: orderId })\n if (existingOrder) {\n const shipments = await em.find(SalesShipment, { order: orderId })\n const shipmentIds = shipments.map((entry) => entry.id)\n if (shipmentIds.length) {\n await em.nativeDelete(SalesShipmentItem, { shipment: { $in: shipmentIds } })\n await em.nativeDelete(SalesShipment, { id: { $in: shipmentIds } })\n }\n await em.nativeDelete(SalesPaymentAllocation, { order: orderId })\n await em.nativeDelete(SalesPayment, { order: orderId })\n await em.nativeDelete(SalesDocumentAddress, { documentId: orderId, documentKind: 'order' })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: orderId, documentKind: 'order' })\n await em.nativeDelete(SalesOrderAdjustment, { order: orderId })\n await em.nativeDelete(SalesOrderLine, { order: orderId })\n em.remove(existingOrder)\n }\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_order, recordId: orderId })\n if (orderLineIds.length) {\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_order_line, recordId: { $in: orderLineIds } as any })\n }\n }\n const noteIds = quoteSnapshot.notes.map((note) => note.id)\n if (noteIds.length) {\n await em.nativeDelete(SalesNote, { id: { $in: noteIds } })\n }\n await restoreQuoteGraph(em, quoteSnapshot)\n await em.flush()\n },\n}\n\nconst orderLineUpsertSchema = orderLineCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst orderLineDeleteSchema = z.object({\n id: z.string().uuid(),\n orderId: z.string().uuid(),\n})\n\nconst quoteLineUpsertSchema = quoteLineCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst quoteLineDeleteSchema = z.object({\n id: z.string().uuid(),\n quoteId: z.string().uuid(),\n})\n\nconst orderAdjustmentUpsertSchema = orderAdjustmentCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst orderAdjustmentDeleteSchema = z.object({\n id: z.string().uuid(),\n orderId: z.string().uuid(),\n})\n\nconst quoteAdjustmentUpsertSchema = quoteAdjustmentCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst quoteAdjustmentDeleteSchema = z.object({\n id: z.string().uuid(),\n quoteId: z.string().uuid(),\n})\n\nconst orderLineUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; lineId: string }\n> = {\n id: 'sales.orders.lines.upsert',\n async prepare(input, ctx) {\n console.log('PREPARE ORDER LINE UPSERT', input, ctx)\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = orderLineUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const existingSnapshot = parsed.id ? lineSnapshots.find((line) => line.id === parsed.id) ?? null : null\n const priceMode = parsed.priceMode === 'gross' ? 'gross' : parsed.priceMode === 'net' ? 'net' : null\n let unitPriceNet = parsed.unitPriceNet ?? existingSnapshot?.unitPriceNet ?? null\n let unitPriceGross = parsed.unitPriceGross ?? existingSnapshot?.unitPriceGross ?? null\n let taxRate = parsed.taxRate ?? existingSnapshot?.taxRate ?? null\n if (priceMode && (unitPriceNet === null || unitPriceGross === null)) {\n let taxService: TaxCalculationService | null = null\n try {\n taxService = ctx.container.resolve('taxCalculationService') as TaxCalculationService\n } catch {\n taxService = null\n }\n if (taxService) {\n const taxResult = await taxService.calculateUnitAmounts({\n amount:\n priceMode === 'gross'\n ? unitPriceGross ?? unitPriceNet ?? 0\n : unitPriceNet ?? unitPriceGross ?? 0,\n mode: priceMode,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n taxRateId: parsed.taxRateId ?? undefined,\n taxRate: taxRate ?? undefined,\n })\n unitPriceNet = unitPriceNet ?? taxResult.netAmount\n unitPriceGross = unitPriceGross ?? taxResult.grossAmount\n taxRate = taxResult.taxRate ?? taxRate\n }\n }\n\n const metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? { ...parsed.metadata }\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : {}\n if (parsed.priceId) metadata.priceId = parsed.priceId\n if (priceMode) metadata.priceMode = priceMode\n\n const statusEntryId = parsed.statusEntryId ?? (existingSnapshot as any)?.statusEntryId ?? null\n const lineId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n const updatedSnapshot: SalesLineSnapshot & { statusEntryId?: string | null; catalogSnapshot?: Record<string, unknown> | null; promotionSnapshot?: Record<string, unknown> | null } = {\n id: lineId,\n lineNumber: parsed.lineNumber ?? existingSnapshot?.lineNumber ?? lineSnapshots.length + 1,\n kind: parsed.kind ?? existingSnapshot?.kind ?? 'product',\n productId: parsed.productId ?? existingSnapshot?.productId ?? null,\n productVariantId: parsed.productVariantId ?? existingSnapshot?.productVariantId ?? null,\n name: parsed.name ?? existingSnapshot?.name ?? null,\n description: parsed.description ?? existingSnapshot?.description ?? null,\n comment: parsed.comment ?? existingSnapshot?.comment ?? null,\n quantity: Number(parsed.quantity ?? existingSnapshot?.quantity ?? 0),\n quantityUnit: parsed.quantityUnit ?? existingSnapshot?.quantityUnit ?? null,\n currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? order.currencyCode,\n unitPriceNet: unitPriceNet ?? 0,\n unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,\n discountAmount: parsed.discountAmount ?? existingSnapshot?.discountAmount ?? 0,\n discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,\n taxRate: taxRate ?? 0,\n taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,\n totalNetAmount: parsed.totalNetAmount ?? existingSnapshot?.totalNetAmount ?? null,\n totalGrossAmount: parsed.totalGrossAmount ?? existingSnapshot?.totalGrossAmount ?? null,\n configuration: parsed.configuration ?? existingSnapshot?.configuration ?? null,\n promotionCode: parsed.promotionCode ?? existingSnapshot?.promotionCode ?? null,\n metadata,\n customFieldSetId: parsed.customFieldSetId ?? existingSnapshot?.customFieldSetId ?? null,\n customFields:\n parsed.customFields && typeof parsed.customFields === 'object'\n ? cloneJson(parsed.customFields)\n : (existingSnapshot as any)?.customFields ?? null,\n }\n ;(updatedSnapshot as any).statusEntryId = statusEntryId\n ;(updatedSnapshot as any).catalogSnapshot =\n parsed.catalogSnapshot ?? (existingSnapshot as any)?.catalogSnapshot ?? null\n ;(updatedSnapshot as any).promotionSnapshot =\n parsed.promotionSnapshot ?? (existingSnapshot as any)?.promotionSnapshot ?? null\n\n let nextLines = parsed.id\n ? lineSnapshots.map((line) => (line.id === parsed.id ? updatedSnapshot : line))\n : [...lineSnapshots, updatedSnapshot]\n nextLines = nextLines\n .sort((a, b) => (a.lineNumber ?? 0) - (b.lineNumber ?? 0))\n .map((line, index) => ({ ...line, lineNumber: index + 1 }))\n\n const sourceInputs = nextLines.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines: SalesLineSnapshot[] = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n await applyOrderLineResults({\n em,\n order,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, lineId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.lines.upsert', 'Upsert order line'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst orderLineDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; lineId: string }\n> = {\n id: 'sales.orders.lines.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const { translate } = await resolveTranslations()\n const parsed = orderLineDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n const shipmentCount = await em.count(SalesShipmentItem, {\n orderLine: parsed.id,\n shipment: { deletedAt: null },\n })\n if (shipmentCount > 0) {\n throw new CrudHttpError(409, {\n error: translate(\n 'sales.documents.items.errorDeleteShipped',\n 'Cannot delete a line that has shipped items.'\n ),\n })\n }\n const existingLines = await em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } })\n const filtered = existingLines.filter((line) => line.id !== parsed.id)\n if (filtered.length === existingLines.length) {\n throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n }\n const sourceInputs = filtered.map((line, index) => ({\n ...mapOrderLineEntityToSnapshot(line),\n statusEntryId: line.statusEntryId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: index + 1,\n }))\n const calcLines = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n await applyOrderLineResults({\n em,\n order,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, lineId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.lines.delete', 'Delete order line'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteLineUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; lineId: string }\n> = {\n id: 'sales.quotes.lines.upsert',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteLineUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const existingSnapshot = parsed.id ? lineSnapshots.find((line) => line.id === parsed.id) ?? null : null\n const priceMode = parsed.priceMode === 'gross' ? 'gross' : parsed.priceMode === 'net' ? 'net' : null\n let unitPriceNet = parsed.unitPriceNet ?? existingSnapshot?.unitPriceNet ?? null\n let unitPriceGross = parsed.unitPriceGross ?? existingSnapshot?.unitPriceGross ?? null\n let taxRate = parsed.taxRate ?? existingSnapshot?.taxRate ?? null\n if (priceMode && (unitPriceNet === null || unitPriceGross === null)) {\n let taxService: TaxCalculationService | null = null\n try {\n taxService = ctx.container.resolve('taxCalculationService') as TaxCalculationService\n } catch {\n taxService = null\n }\n if (taxService) {\n const taxResult = await taxService.calculateUnitAmounts({\n amount:\n priceMode === 'gross'\n ? unitPriceGross ?? unitPriceNet ?? 0\n : unitPriceNet ?? unitPriceGross ?? 0,\n mode: priceMode,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n taxRateId: parsed.taxRateId ?? undefined,\n taxRate: taxRate ?? undefined,\n })\n unitPriceNet = unitPriceNet ?? taxResult.netAmount\n unitPriceGross = unitPriceGross ?? taxResult.grossAmount\n taxRate = taxResult.taxRate ?? taxRate\n }\n }\n const metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? { ...parsed.metadata }\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : {}\n if (parsed.priceId) metadata.priceId = parsed.priceId\n if (priceMode) metadata.priceMode = priceMode\n\n const statusEntryId = parsed.statusEntryId ?? (existingSnapshot as any)?.statusEntryId ?? null\n const lineId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n const updatedSnapshot: SalesLineSnapshot & { statusEntryId?: string | null; catalogSnapshot?: Record<string, unknown> | null; promotionSnapshot?: Record<string, unknown> | null } = {\n id: lineId,\n lineNumber: parsed.lineNumber ?? existingSnapshot?.lineNumber ?? lineSnapshots.length + 1,\n kind: parsed.kind ?? existingSnapshot?.kind ?? 'product',\n productId: parsed.productId ?? existingSnapshot?.productId ?? null,\n productVariantId: parsed.productVariantId ?? existingSnapshot?.productVariantId ?? null,\n name: parsed.name ?? existingSnapshot?.name ?? null,\n description: parsed.description ?? existingSnapshot?.description ?? null,\n comment: parsed.comment ?? existingSnapshot?.comment ?? null,\n quantity: Number(parsed.quantity ?? existingSnapshot?.quantity ?? 0),\n quantityUnit: parsed.quantityUnit ?? existingSnapshot?.quantityUnit ?? null,\n currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? quote.currencyCode,\n unitPriceNet: unitPriceNet ?? 0,\n unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,\n discountAmount: parsed.discountAmount ?? existingSnapshot?.discountAmount ?? 0,\n discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,\n taxRate: taxRate ?? 0,\n taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,\n totalNetAmount: parsed.totalNetAmount ?? existingSnapshot?.totalNetAmount ?? null,\n totalGrossAmount: parsed.totalGrossAmount ?? existingSnapshot?.totalGrossAmount ?? null,\n configuration: parsed.configuration ?? existingSnapshot?.configuration ?? null,\n promotionCode: parsed.promotionCode ?? existingSnapshot?.promotionCode ?? null,\n metadata,\n customFieldSetId: parsed.customFieldSetId ?? existingSnapshot?.customFieldSetId ?? null,\n customFields:\n parsed.customFields && typeof parsed.customFields === 'object'\n ? cloneJson(parsed.customFields)\n : (existingSnapshot as any)?.customFields ?? null,\n }\n ;(updatedSnapshot as any).statusEntryId = statusEntryId\n ;(updatedSnapshot as any).catalogSnapshot =\n parsed.catalogSnapshot ?? (existingSnapshot as any)?.catalogSnapshot ?? null\n ;(updatedSnapshot as any).promotionSnapshot =\n parsed.promotionSnapshot ?? (existingSnapshot as any)?.promotionSnapshot ?? null\n\n let nextLines = parsed.id\n ? lineSnapshots.map((line) => (line.id === parsed.id ? updatedSnapshot : line))\n : [...lineSnapshots, updatedSnapshot]\n nextLines = nextLines\n .sort((a, b) => (a.lineNumber ?? 0) - (b.lineNumber ?? 0))\n .map((line, index) => ({ ...line, lineNumber: index + 1 }))\n\n const sourceInputs = nextLines.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines: SalesLineSnapshot[] = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n await applyQuoteLineResults({\n em,\n quote,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, lineId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.lines.upsert', 'Upsert quote line'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteLineDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; lineId: string }\n> = {\n id: 'sales.quotes.lines.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteLineDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const existingLines = await em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } })\n const filtered = existingLines.filter((line) => line.id !== parsed.id)\n if (filtered.length === existingLines.length) {\n throw new CrudHttpError(404, { error: 'Quote line not found' })\n }\n const sourceInputs = filtered.map((line, index) => ({\n ...mapQuoteLineEntityToSnapshot(line),\n statusEntryId: line.statusEntryId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: index + 1,\n }))\n const calcLines = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n await applyQuoteLineResults({\n em,\n quote,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, lineId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.lines.delete', 'Delete quote line'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst orderAdjustmentUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; adjustmentId: string }\n> = {\n id: 'sales.orders.adjustments.upsert',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = orderAdjustmentUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n if (parsed.scope === 'line') {\n throw new CrudHttpError(400, { error: 'Line-scoped adjustments are not supported yet.' })\n }\n\n const [existingLines, existingAdjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const adjustmentDrafts = existingAdjustments.map(mapOrderAdjustmentToDraft)\n const existingSnapshot = parsed.id ? adjustmentDrafts.find((adj) => adj.id === parsed.id) ?? null : null\n const adjustmentId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n let metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? cloneJson(parsed.metadata)\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : null\n const calculatorKey = parsed.calculatorKey ?? existingSnapshot?.calculatorKey ?? null\n if (\n parsed.id &&\n calculatorKey &&\n (calculatorKey.startsWith('shipping-provider:') || calculatorKey.startsWith('payment-provider:'))\n ) {\n metadata = { ...(metadata ?? {}), manualOverride: true }\n }\n let nextAdjustments = parsed.id\n ? adjustmentDrafts.map((adj) =>\n adj.id === parsed.id\n ? {\n ...adj,\n id: adjustmentId,\n scope: parsed.scope ?? adj.scope ?? 'order',\n kind: parsed.kind ?? adj.kind ?? 'custom',\n code: parsed.code ?? adj.code ?? null,\n label: parsed.label ?? adj.label ?? null,\n calculatorKey: parsed.calculatorKey ?? adj.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? adj.promotionId ?? null,\n rate: parsed.rate ?? adj.rate ?? null,\n amountNet: parsed.amountNet ?? adj.amountNet ?? null,\n amountGross: parsed.amountGross ?? adj.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? adj.currencyCode ?? order.currencyCode,\n metadata,\n customFields:\n parsed.customFields !== undefined\n ? parsed.customFields\n : (adj as any).customFields ?? null,\n position: parsed.position ?? adj.position ?? adjustmentDrafts.length,\n }\n : adj\n )\n : [\n ...adjustmentDrafts,\n {\n id: adjustmentId,\n scope: parsed.scope ?? 'order',\n kind: parsed.kind ?? 'custom',\n code: parsed.code ?? null,\n label: parsed.label ?? null,\n calculatorKey: parsed.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? null,\n rate: parsed.rate ?? null,\n amountNet: parsed.amountNet ?? null,\n amountGross: parsed.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? order.currencyCode,\n metadata,\n customFields: parsed.customFields ?? null,\n position: parsed.position ?? adjustmentDrafts.length,\n },\n ]\n\n nextAdjustments = nextAdjustments\n .sort((a, b) => (a.position ?? 0) - (b.position ?? 0))\n .map((adj, index) => ({ ...adj, position: adj.position ?? index }))\n\n const sourceLines = lineSnapshots.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines = sourceLines.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: nextAdjustments,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n const adjustmentInputs = nextAdjustments.map((adj, index) => ({\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? order.currencyCode,\n metadata: adj.metadata ?? undefined,\n customFields: (adj as any).customFields ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n order.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, adjustmentId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.adjustments.upsert', 'Upsert order adjustment'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst orderAdjustmentDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; adjustmentId: string }\n> = {\n id: 'sales.orders.adjustments.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = orderAdjustmentDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const filtered = adjustments.filter((adj) => adj.id !== parsed.id)\n if (filtered.length === adjustments.length) {\n throw new CrudHttpError(404, { error: 'Adjustment not found' })\n }\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = filtered.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? order.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n order.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, adjustmentId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.adjustments.delete', 'Delete order adjustment'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteAdjustmentUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; adjustmentId: string }\n> = {\n id: 'sales.quotes.adjustments.upsert',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteAdjustmentUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n if (parsed.scope === 'line') {\n throw new CrudHttpError(400, { error: 'Line-scoped adjustments are not supported yet.' })\n }\n\n const [existingLines, existingAdjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const adjustmentDrafts = existingAdjustments.map(mapQuoteAdjustmentToDraft)\n const existingSnapshot = parsed.id ? adjustmentDrafts.find((adj) => adj.id === parsed.id) ?? null : null\n const adjustmentId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n let metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? cloneJson(parsed.metadata)\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : null\n const calculatorKey = parsed.calculatorKey ?? existingSnapshot?.calculatorKey ?? null\n if (\n parsed.id &&\n calculatorKey &&\n (calculatorKey.startsWith('shipping-provider:') || calculatorKey.startsWith('payment-provider:'))\n ) {\n metadata = { ...(metadata ?? {}), manualOverride: true }\n }\n let nextAdjustments = parsed.id\n ? adjustmentDrafts.map((adj) =>\n adj.id === parsed.id\n ? {\n ...adj,\n id: adjustmentId,\n scope: parsed.scope ?? adj.scope ?? 'order',\n kind: parsed.kind ?? adj.kind ?? 'custom',\n code: parsed.code ?? adj.code ?? null,\n label: parsed.label ?? adj.label ?? null,\n calculatorKey: parsed.calculatorKey ?? adj.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? adj.promotionId ?? null,\n rate: parsed.rate ?? adj.rate ?? null,\n amountNet: parsed.amountNet ?? adj.amountNet ?? null,\n amountGross: parsed.amountGross ?? adj.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? adj.currencyCode ?? quote.currencyCode,\n metadata,\n customFields:\n parsed.customFields !== undefined\n ? parsed.customFields\n : (adj as any).customFields ?? null,\n position: parsed.position ?? adj.position ?? adjustmentDrafts.length,\n }\n : adj\n )\n : [\n ...adjustmentDrafts,\n {\n id: adjustmentId,\n scope: parsed.scope ?? 'order',\n kind: parsed.kind ?? 'custom',\n code: parsed.code ?? null,\n label: parsed.label ?? null,\n calculatorKey: parsed.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? null,\n rate: parsed.rate ?? null,\n amountNet: parsed.amountNet ?? null,\n amountGross: parsed.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? quote.currencyCode,\n metadata,\n customFields: parsed.customFields ?? null,\n position: parsed.position ?? adjustmentDrafts.length,\n },\n ]\n\n nextAdjustments = nextAdjustments\n .sort((a, b) => (a.position ?? 0) - (b.position ?? 0))\n .map((adj, index) => ({ ...adj, position: adj.position ?? index }))\n\n const sourceLines = lineSnapshots.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines = sourceLines.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: nextAdjustments,\n context: calculationContext,\n })\n const adjustmentInputs = nextAdjustments.map((adj, index) => ({\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? quote.currencyCode,\n metadata: adj.metadata ?? undefined,\n customFields: (adj as any).customFields ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n quote.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, adjustmentId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.adjustments.upsert', 'Upsert quote adjustment'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteAdjustmentDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; adjustmentId: string }\n> = {\n id: 'sales.quotes.adjustments.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteAdjustmentDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const filtered = adjustments.filter((adj) => adj.id !== parsed.id)\n if (filtered.length === adjustments.length) {\n throw new CrudHttpError(404, { error: 'Adjustment not found' })\n }\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = filtered.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? quote.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n quote.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, adjustmentId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.adjustments.delete', 'Delete quote adjustment'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nregisterCommand(updateQuoteCommand)\nregisterCommand(createQuoteCommand)\nregisterCommand(deleteQuoteCommand)\nregisterCommand(convertQuoteToOrderCommand)\nregisterCommand(updateOrderCommand)\nregisterCommand(createOrderCommand)\nregisterCommand(deleteOrderCommand)\nregisterCommand(orderLineUpsertCommand)\nregisterCommand(orderLineDeleteCommand)\nregisterCommand(quoteLineUpsertCommand)\nregisterCommand(quoteLineDeleteCommand)\nregisterCommand(orderAdjustmentUpsertCommand)\nregisterCommand(orderAdjustmentDeleteCommand)\nregisterCommand(quoteAdjustmentUpsertCommand)\nregisterCommand(quoteAdjustmentDeleteCommand)\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,kBAAkB;AAC3B,SAAS,SAAS;AAClB,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB,iBAAiB;AAI/C,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B,2BAA2B;AACjE,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AAC3C,SAAS,SAAS;AAClB,SAAS,0BAA0B;AACnC;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,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAUP,SAAS,mCAAmC;AAC5C,SAAS,mCAAmC;AAE5C,SAAS,yBAAyB;AAuRlC,MAAM,qBAAqB,EACxB,OAAO,EACP,KAAK,EACL,YAAY,EACZ,MAAM,cAAc,EAAE,SAAS,wBAAwB,CAAC;AAE3D,MAAM,iBAAiB,EACpB,OAAO,EACP,KAAK,EACL,MAAM,uBAAuB,EAAE,SAAS,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A,QACP,MAAM,EAAE,QAAQ,MAAM;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAAA,EACA,MAAM,OAAO,EAAE,UAAU,IAAI,MAAM;AACjC,UAAM,UAAU,mBAAqC,QAAQ;AAC7D,UAAM,SAAS,SAAS;AACxB,QAAI,CAAC,OAAQ;AACb,UAAM,KAAM,IAAI,UAAU,QAAQ,IAAI,EAAoB,KAAK;AAC/D,qBAAiB,KAAK,OAAO,MAAM,gBAAgB,OAAO,MAAM,QAAQ;AACxE,UAAM,kBAAkB,IAAI,MAAM;AAClC,UAAM,GAAG,MAAM;AAAA,EACjB;AACF;AAEA,gBAAgB,kBAAkB;AAClC,gBAAgB,kBAAkB;AAClC,gBAAgB,kBAAkB;AAClC,gBAAgB,0BAA0B;AAC1C,gBAAgB,kBAAkB;AAClC,gBAAgB,kBAAkB;AAClC,gBAAgB,kBAAkB;AAClC,gBAAgB,sBAAsB;AACtC,gBAAgB,sBAAsB;AACtC,gBAAgB,sBAAsB;AACtC,gBAAgB,sBAAsB;AACtC,gBAAgB,4BAA4B;AAC5C,gBAAgB,4BAA4B;AAC5C,gBAAgB,4BAA4B;AAC5C,gBAAgB,4BAA4B;",
|
|
4
|
+
"sourcesContent": ["// @ts-nocheck\n\nimport { randomUUID } from 'crypto'\nimport { z } from 'zod'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport { emitCrudSideEffects, requireId, type CrudEventsConfig } from '@open-mercato/shared/lib/commands/helpers'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { EventBus } from '@open-mercato/events'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { deriveResourceFromCommandId, invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { setRecordCustomFields } from '@open-mercato/core/modules/entities/lib/helpers'\nimport { loadCustomFieldValues } from '@open-mercato/shared/lib/crud/custom-fields'\nimport { normalizeCustomFieldValues } from '@open-mercato/shared/lib/custom-fields/normalize'\nimport { E } from '#generated/entities.ids.generated'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport {\n SalesQuote,\n SalesQuoteLine,\n SalesQuoteAdjustment,\n SalesOrder,\n SalesOrderLine,\n SalesOrderAdjustment,\n SalesShipment,\n SalesShipmentItem,\n SalesPayment,\n SalesPaymentAllocation,\n SalesDocumentAddress,\n SalesNote,\n SalesChannel,\n SalesShippingMethod,\n SalesDeliveryWindow,\n SalesPaymentMethod,\n SalesDocumentTag,\n SalesDocumentTagAssignment,\n type SalesLineKind,\n type SalesAdjustmentKind,\n type SalesSettings,\n} from '../data/entities'\nimport { CustomFieldValue } from '@open-mercato/core/modules/entities/data/entities'\nimport {\n CustomerAddress,\n CustomerEntity,\n CustomerPersonProfile,\n} from '../../customers/data/entities'\nimport {\n quoteCreateSchema,\n quoteLineCreateSchema,\n quoteAdjustmentCreateSchema,\n orderCreateSchema,\n orderLineCreateSchema,\n orderAdjustmentCreateSchema,\n type QuoteCreateInput,\n type QuoteLineCreateInput,\n type QuoteAdjustmentCreateInput,\n type OrderCreateInput,\n type OrderLineCreateInput,\n type OrderAdjustmentCreateInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n extractUndoPayload,\n toNumericString,\n} from './shared'\nimport {\n loadShipmentSnapshot,\n restoreShipmentSnapshot,\n type ShipmentSnapshot,\n} from './shipments'\nimport {\n loadPaymentSnapshot,\n restorePaymentSnapshot,\n type PaymentSnapshot,\n} from './payments'\nimport type { SalesCalculationService } from '../services/salesCalculationService'\nimport type { TaxCalculationService } from '../services/taxCalculationService'\nimport type { PaymentMethodContext, ShippingMethodContext } from '../lib/providers'\nimport {\n type SalesLineSnapshot,\n type SalesAdjustmentDraft,\n type SalesLineCalculationResult,\n type SalesDocumentCalculationResult,\n} from '../lib/types'\nimport { resolveDictionaryEntryValue } from '../lib/dictionaries'\nimport { resolveStatusEntryIdByValue } from '../lib/statusHelpers'\nimport { SalesDocumentNumberGenerator } from '../services/salesDocumentNumberGenerator'\nimport { loadSalesSettings } from './settings'\n\n// CRUD events configuration for workflow triggers\nconst orderCrudEvents: CrudEventsConfig<SalesOrder> = {\n module: 'sales',\n entity: 'orders',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\nconst quoteCrudEvents: CrudEventsConfig<SalesQuote> = {\n module: 'sales',\n entity: 'quotes',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\ntype DocumentAddressSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n documentId: string\n documentKind: 'order' | 'quote'\n customerAddressId: string | null\n name: string | null\n purpose: string | null\n companyName: 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 buildingNumber: string | null\n flatNumber: string | null\n latitude: number | null\n longitude: number | null\n}\n\ntype NoteSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n contextType: 'order' | 'quote'\n contextId: string\n orderId: string | null\n quoteId: string | null\n body: string\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype TagAssignmentSnapshot = {\n id: string\n tagId: string\n organizationId: string\n tenantId: string\n documentId: string\n documentKind: 'order' | 'quote'\n}\n\ntype QuoteGraphSnapshot = {\n quote: {\n id: string\n organizationId: string\n tenantId: string\n quoteNumber: string\n statusEntryId: string | null\n status: string | null\n customerEntityId: string | null\n customerContactId: string | null\n customerSnapshot: Record<string, unknown> | null\n billingAddressId: string | null\n shippingAddressId: string | null\n billingAddressSnapshot: Record<string, unknown> | null\n shippingAddressSnapshot: Record<string, unknown> | null\n currencyCode: string\n validFrom: string | null\n validUntil: string | null\n comments: string | null\n taxInfo: Record<string, unknown> | null\n shippingMethodId: string | null\n shippingMethodCode: string | null\n deliveryWindowId: string | null\n deliveryWindowCode: string | null\n paymentMethodId: string | null\n paymentMethodCode: string | null\n channelId: string | null\n shippingMethodSnapshot: Record<string, unknown> | null\n deliveryWindowSnapshot: Record<string, unknown> | null\n paymentMethodSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n subtotalNetAmount: string\n subtotalGrossAmount: string\n discountTotalAmount: string\n taxTotalAmount: string\n grandTotalNetAmount: string\n grandTotalGrossAmount: string\n totalsSnapshot: Record<string, unknown> | null\n lineItemCount: number\n }\n lines: QuoteLineSnapshot[]\n adjustments: QuoteAdjustmentSnapshot[]\n addresses: DocumentAddressSnapshot[]\n notes: NoteSnapshot[]\n tags: TagAssignmentSnapshot[]\n}\n\ntype QuoteLineSnapshot = {\n id: string\n lineNumber: number\n kind: string\n statusEntryId: string | null\n status: string | null\n productId: string | null\n productVariantId: string | null\n catalogSnapshot: Record<string, unknown> | null\n name: string | null\n description: string | null\n comment: string | null\n quantity: string\n quantityUnit: string | null\n currencyCode: string\n unitPriceNet: string\n unitPriceGross: string\n discountAmount: string\n discountPercent: string\n taxRate: string\n taxAmount: string\n totalNetAmount: string\n totalGrossAmount: string\n configuration: Record<string, unknown> | null\n promotionCode: string | null\n promotionSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype QuoteAdjustmentSnapshot = {\n id: string\n scope: 'order' | 'line'\n kind: string\n code: string | null\n label: string | null\n calculatorKey: string | null\n promotionId: string | null\n rate: string\n amountNet: string\n amountGross: string\n currencyCode: string | null\n metadata: Record<string, unknown> | null\n position: number\n quoteLineId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype OrderGraphSnapshot = {\n order: {\n id: string\n organizationId: string\n tenantId: string\n orderNumber: string\n statusEntryId: string | null\n status: string | null\n fulfillmentStatusEntryId: string | null\n fulfillmentStatus: string | null\n paymentStatusEntryId: string | null\n paymentStatus: string | null\n customerEntityId: string | null\n customerContactId: string | null\n customerSnapshot: Record<string, unknown> | null\n billingAddressId: string | null\n shippingAddressId: string | null\n billingAddressSnapshot: Record<string, unknown> | null\n shippingAddressSnapshot: Record<string, unknown> | null\n currencyCode: string\n exchangeRate: string | null\n taxStrategyKey: string | null\n discountStrategyKey: string | null\n taxInfo: Record<string, unknown> | null\n shippingMethodId: string | null\n shippingMethodCode: string | null\n deliveryWindowId: string | null\n deliveryWindowCode: string | null\n paymentMethodId: string | null\n paymentMethodCode: string | null\n channelId: string | null\n placedAt: string | null\n expectedDeliveryAt: string | null\n dueAt: string | null\n comments: string | null\n internalNotes: string | null\n shippingMethodSnapshot: Record<string, unknown> | null\n deliveryWindowSnapshot: Record<string, unknown> | null\n paymentMethodSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n subtotalNetAmount: string\n subtotalGrossAmount: string\n discountTotalAmount: string\n taxTotalAmount: string\n shippingNetAmount: string\n shippingGrossAmount: string\n surchargeTotalAmount: string\n grandTotalNetAmount: string\n grandTotalGrossAmount: string\n paidTotalAmount: string\n refundedTotalAmount: string\n outstandingAmount: string\n totalsSnapshot: Record<string, unknown> | null\n lineItemCount: number\n }\n lines: OrderLineSnapshot[]\n adjustments: OrderAdjustmentSnapshot[]\n addresses: DocumentAddressSnapshot[]\n notes: NoteSnapshot[]\n tags: TagAssignmentSnapshot[]\n shipments: ShipmentSnapshot[]\n payments: PaymentSnapshot[]\n}\n\ntype OrderLineSnapshot = {\n id: string\n lineNumber: number\n kind: string\n statusEntryId: string | null\n status: string | null\n productId: string | null\n productVariantId: string | null\n catalogSnapshot: Record<string, unknown> | null\n name: string | null\n description: string | null\n comment: string | null\n quantity: string\n quantityUnit: string | null\n reservedQuantity: string\n fulfilledQuantity: string\n invoicedQuantity: string\n returnedQuantity: string\n currencyCode: string\n unitPriceNet: string\n unitPriceGross: string\n discountAmount: string\n discountPercent: string\n taxRate: string\n taxAmount: string\n totalNetAmount: string\n totalGrossAmount: string\n configuration: Record<string, unknown> | null\n promotionCode: string | null\n promotionSnapshot: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n customFieldSetId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype OrderAdjustmentSnapshot = {\n id: string\n scope: 'order' | 'line'\n kind: string\n code: string | null\n label: string | null\n calculatorKey: string | null\n promotionId: string | null\n rate: string\n amountNet: string\n amountGross: string\n currencyCode: string | null\n metadata: Record<string, unknown> | null\n position: number\n orderLineId: string | null\n customFields: Record<string, unknown> | null\n}\n\ntype OrderUndoPayload = {\n before?: OrderGraphSnapshot | null\n after?: OrderGraphSnapshot | null\n}\n\ntype QuoteUndoPayload = {\n before?: QuoteGraphSnapshot | null\n after?: QuoteGraphSnapshot | null\n}\n\ntype QuoteConvertUndoPayload = {\n quote?: QuoteGraphSnapshot | null\n order?: OrderGraphSnapshot | null\n}\n\nconst currencyCodeSchema = z\n .string()\n .trim()\n .toUpperCase()\n .regex(/^[A-Z]{3}$/, { message: 'currency_code_invalid' })\n\nconst dateOnlySchema = z\n .string()\n .trim()\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/, { message: 'invalid_date' })\n .refine((value) => !Number.isNaN(new Date(value).getTime()), { message: 'invalid_date' })\n\nconst addressSnapshotSchema = z.record(z.string(), z.unknown()).nullable().optional()\n\nexport const documentUpdateSchema = z\n .object({\n id: z.string().uuid(),\n customerEntityId: z.string().uuid().nullable().optional(),\n customerContactId: z.string().uuid().nullable().optional(),\n customerSnapshot: z.record(z.string(), z.unknown()).nullable().optional(),\n metadata: z.record(z.string(), z.unknown()).nullable().optional(),\n customerReference: z.string().nullable().optional(),\n externalReference: z.string().nullable().optional(),\n comment: z.string().nullable().optional(),\n currencyCode: currencyCodeSchema.optional(),\n channelId: z.string().uuid().nullable().optional(),\n statusEntryId: z.string().uuid().nullable().optional(),\n placedAt: z.union([dateOnlySchema, z.null()]).optional(),\n expectedDeliveryAt: z.union([dateOnlySchema, z.null()]).optional(),\n shippingAddressId: z.string().uuid().nullable().optional(),\n billingAddressId: z.string().uuid().nullable().optional(),\n shippingAddressSnapshot: addressSnapshotSchema,\n billingAddressSnapshot: addressSnapshotSchema,\n shippingMethodId: z.string().uuid().nullable().optional(),\n shippingMethodCode: z.string().nullable().optional(),\n shippingMethodSnapshot: z.record(z.string(), z.unknown()).nullable().optional(),\n paymentMethodId: z.string().uuid().nullable().optional(),\n paymentMethodCode: z.string().nullable().optional(),\n paymentMethodSnapshot: z.record(z.string(), z.unknown()).nullable().optional(),\n tags: z.array(z.string().uuid()).optional(),\n customFields: z.record(z.string(), z.unknown()).optional(),\n customFieldSetId: z.string().uuid().nullable().optional(),\n })\n .refine(\n (input) =>\n typeof input.currencyCode === 'string' ||\n input.placedAt !== undefined ||\n input.expectedDeliveryAt !== undefined ||\n input.channelId !== undefined ||\n input.statusEntryId !== undefined ||\n input.shippingAddressId !== undefined ||\n input.billingAddressId !== undefined ||\n input.customerEntityId !== undefined ||\n input.customerContactId !== undefined ||\n input.customerSnapshot !== undefined ||\n input.metadata !== undefined ||\n input.customerReference !== undefined ||\n input.externalReference !== undefined ||\n input.comment !== undefined ||\n input.shippingAddressSnapshot !== undefined ||\n input.billingAddressSnapshot !== undefined ||\n input.shippingMethodId !== undefined ||\n input.shippingMethodCode !== undefined ||\n input.shippingMethodSnapshot !== undefined ||\n input.paymentMethodId !== undefined ||\n input.paymentMethodCode !== undefined ||\n input.paymentMethodSnapshot !== undefined ||\n input.tags !== undefined ||\n input.customFields !== undefined ||\n input.customFieldSetId !== undefined,\n { message: 'update_payload_empty' }\n )\n\nexport type DocumentUpdateInput = z.infer<typeof documentUpdateSchema>\n\ntype DocumentLineCreateInput = QuoteLineCreateInput | OrderLineCreateInput\ntype DocumentAdjustmentCreateInput = QuoteAdjustmentCreateInput | OrderAdjustmentCreateInput\n\nfunction cloneJson<T>(value: T): T {\n if (value === null || value === undefined) return value\n return JSON.parse(JSON.stringify(value)) as T\n}\n\nasync function resolveCustomerSnapshot(\n em: EntityManager,\n organizationId: string,\n tenantId: string,\n customerEntityId?: string | null,\n customerContactId?: string | null\n): Promise<Record<string, unknown> | null> {\n if (!customerEntityId) return null\n const customer = await em.findOne(\n CustomerEntity,\n { id: customerEntityId, organizationId, tenantId },\n { populate: ['personProfile', 'companyProfile'] }\n )\n if (!customer) return null\n\n const contact = customerContactId\n ? await em.findOne(CustomerPersonProfile, {\n id: customerContactId,\n organizationId,\n tenantId,\n })\n : null\n\n return {\n customer: {\n id: customer.id,\n kind: customer.kind,\n displayName: customer.displayName,\n primaryEmail: customer.primaryEmail ?? null,\n primaryPhone: customer.primaryPhone ?? null,\n personProfile: customer.personProfile\n ? {\n id: customer.personProfile.id,\n firstName: customer.personProfile.firstName ?? null,\n lastName: customer.personProfile.lastName ?? null,\n preferredName: customer.personProfile.preferredName ?? null,\n }\n : null,\n companyProfile: customer.companyProfile\n ? {\n id: customer.companyProfile.id,\n legalName: customer.companyProfile.legalName ?? null,\n brandName: customer.companyProfile.brandName ?? null,\n domain: customer.companyProfile.domain ?? null,\n websiteUrl: customer.companyProfile.websiteUrl ?? null,\n }\n : null,\n },\n contact: contact\n ? {\n id: contact.id,\n firstName: contact.firstName ?? null,\n lastName: contact.lastName ?? null,\n preferredName: contact.preferredName ?? null,\n jobTitle: contact.jobTitle ?? null,\n department: contact.department ?? null,\n }\n : null,\n }\n}\n\nasync function resolveAddressSnapshot(\n em: EntityManager,\n organizationId: string,\n tenantId: string,\n addressId?: string | null\n): Promise<Record<string, unknown> | null> {\n if (!addressId) return null\n const address = await em.findOne(CustomerAddress, {\n id: addressId,\n organizationId,\n tenantId,\n })\n if (!address) return null\n\n return {\n id: address.id,\n name: address.name ?? null,\n purpose: address.purpose ?? null,\n companyName: address.companyName ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n buildingNumber: address.buildingNumber ?? null,\n flatNumber: address.flatNumber ?? 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 isPrimary: address.isPrimary,\n }\n}\n\nasync function resolveDocumentReferences(\n em: EntityManager,\n parsed: {\n organizationId: string\n tenantId: string\n customerEntityId?: string | null\n customerContactId?: string | null\n customerSnapshot?: Record<string, unknown> | null\n billingAddressId?: string | null\n shippingAddressId?: string | null\n billingAddressSnapshot?: Record<string, unknown> | null\n shippingAddressSnapshot?: Record<string, unknown> | null\n shippingMethodId?: string | null\n deliveryWindowId?: string | null\n paymentMethodId?: string | null\n }\n): Promise<{\n customerSnapshot: Record<string, unknown> | null\n billingAddressSnapshot: Record<string, unknown> | null\n shippingAddressSnapshot: Record<string, unknown> | null\n shippingMethod: SalesShippingMethod | null\n deliveryWindow: SalesDeliveryWindow | null\n paymentMethod: SalesPaymentMethod | null\n}> {\n const [\n resolvedCustomerSnapshot,\n resolvedBillingSnapshot,\n resolvedShippingSnapshot,\n shippingMethod,\n deliveryWindow,\n paymentMethod,\n ] = await Promise.all([\n parsed.customerSnapshot\n ? Promise.resolve(cloneJson(parsed.customerSnapshot))\n : resolveCustomerSnapshot(\n em,\n parsed.organizationId,\n parsed.tenantId,\n parsed.customerEntityId ?? null,\n parsed.customerContactId ?? null\n ),\n parsed.billingAddressSnapshot\n ? Promise.resolve(cloneJson(parsed.billingAddressSnapshot))\n : resolveAddressSnapshot(\n em,\n parsed.organizationId,\n parsed.tenantId,\n parsed.billingAddressId ?? null\n ),\n parsed.shippingAddressSnapshot\n ? Promise.resolve(cloneJson(parsed.shippingAddressSnapshot))\n : resolveAddressSnapshot(\n em,\n parsed.organizationId,\n parsed.tenantId,\n parsed.shippingAddressId ?? null\n ),\n parsed.shippingMethodId\n ? em.findOne(SalesShippingMethod, {\n id: parsed.shippingMethodId,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n : Promise.resolve(null),\n parsed.deliveryWindowId\n ? em.findOne(SalesDeliveryWindow, {\n id: parsed.deliveryWindowId,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n : Promise.resolve(null),\n parsed.paymentMethodId\n ? em.findOne(SalesPaymentMethod, {\n id: parsed.paymentMethodId,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n : Promise.resolve(null),\n ])\n\n return {\n customerSnapshot: resolvedCustomerSnapshot ? cloneJson(resolvedCustomerSnapshot) : null,\n billingAddressSnapshot: resolvedBillingSnapshot ? cloneJson(resolvedBillingSnapshot) : null,\n shippingAddressSnapshot: resolvedShippingSnapshot ? cloneJson(resolvedShippingSnapshot) : null,\n shippingMethod: shippingMethod ?? null,\n deliveryWindow: deliveryWindow ?? null,\n paymentMethod: paymentMethod ?? null,\n }\n}\n\nfunction normalizeStatusValue(raw: unknown): string | null {\n if (typeof raw !== 'string') return null\n const trimmed = raw.trim()\n return trimmed.length ? trimmed : null\n}\n\nfunction resolveNoteAuthorFromAuth(auth: any): string | null {\n if (!auth || auth.isApiKey) return null\n const sub = typeof auth.sub === 'string' ? auth.sub.trim() : ''\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(sub) ? sub : null\n}\n\nfunction resolveStatusChangeActor(auth: any, translate: any): string {\n const unknownLabel = translate('sales.orders.status_change.actor_unknown', 'unknown user')\n if (!auth) return unknownLabel\n if (auth.isApiKey) {\n const keyName = typeof auth.keyName === 'string' ? auth.keyName.trim() : ''\n const keyId = typeof auth.keyId === 'string' ? auth.keyId.trim() : ''\n const label = keyName || keyId || (typeof auth.sub === 'string' ? auth.sub : '')\n return label\n ? translate('sales.orders.status_change.actor_api_key', 'API key {name}', { name: label })\n : unknownLabel\n }\n const email = typeof auth.email === 'string' ? auth.email.trim() : ''\n if (email) return email\n const sub = typeof auth.sub === 'string' ? auth.sub.trim() : ''\n if (sub) return sub\n return unknownLabel\n}\n\nfunction formatStatusLabel(status: string | null, translate: any): string {\n if (status && status.trim().length) return status.trim()\n return translate('sales.orders.status_change.empty', 'unset')\n}\n\nasync function appendOrderStatusChangeNote({\n em,\n order,\n previousStatus,\n auth,\n}: {\n em: EntityManager\n order: SalesOrder\n previousStatus: string | null\n auth: any\n}): Promise<SalesNote | null> {\n const nextStatus = normalizeStatusValue(order.status)\n if (previousStatus === nextStatus) return null\n const { translate } = await resolveTranslations()\n const body = translate(\n 'sales.orders.status_change.note',\n 'Status changed from {from} to {to} by {actor}.',\n {\n from: formatStatusLabel(previousStatus, translate),\n to: formatStatusLabel(nextStatus, translate),\n actor: resolveStatusChangeActor(auth, translate),\n }\n )\n const note = em.create(SalesNote, {\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n contextType: 'order',\n contextId: order.id,\n order,\n authorUserId: resolveNoteAuthorFromAuth(auth),\n appearanceIcon: null,\n appearanceColor: null,\n body,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n return note\n}\n\nasync function applyDocumentUpdate({\n kind,\n entity,\n input,\n em,\n}: {\n kind: 'order' | 'quote'\n entity: SalesOrder | SalesQuote\n input: DocumentUpdateInput\n em: EntityManager\n}): Promise<void> {\n const organizationId = (entity as any).organizationId as string\n const tenantId = (entity as any).tenantId as string\n const status = typeof (entity as any).status === 'string' ? (entity as any).status : null\n const { translate } = await resolveTranslations()\n\n const wantsCustomerChange =\n input.customerEntityId !== undefined ||\n input.customerContactId !== undefined ||\n input.customerSnapshot !== undefined ||\n input.metadata !== undefined\n const wantsAddressChange =\n input.shippingAddressId !== undefined ||\n input.billingAddressId !== undefined ||\n input.shippingAddressSnapshot !== undefined ||\n input.billingAddressSnapshot !== undefined\n\n let settings: SalesSettings | null = null\n if (kind === 'order' && (wantsCustomerChange || wantsAddressChange)) {\n settings = await loadSalesSettings(em, { organizationId, tenantId })\n }\n\n const guardStatus = (allowed: string[] | null | undefined, errorKey: string, fallback: string) => {\n if (!Array.isArray(allowed)) return\n if (allowed.length === 0) {\n throw new CrudHttpError(400, { error: translate(errorKey, fallback) })\n }\n if (!status || !allowed.includes(status)) {\n throw new CrudHttpError(400, { error: translate(errorKey, fallback) })\n }\n }\n\n if (kind === 'order' && wantsCustomerChange) {\n guardStatus(\n settings?.orderCustomerEditableStatuses ?? null,\n 'sales.orders.edit_customer_blocked',\n 'Editing the customer is blocked for this status.'\n )\n }\n if (kind === 'order' && wantsAddressChange) {\n guardStatus(\n settings?.orderAddressEditableStatuses ?? null,\n 'sales.orders.edit_addresses_blocked',\n 'Editing addresses is blocked for this status.'\n )\n }\n\n if (input.customerEntityId !== undefined) {\n entity.customerEntityId = input.customerEntityId ?? null\n entity.customerSnapshot = await resolveCustomerSnapshot(\n em,\n organizationId,\n tenantId,\n input.customerEntityId,\n input.customerContactId ?? entity.customerContactId ?? null\n )\n entity.customerContactId = input.customerContactId ?? null\n entity.billingAddressId = null\n entity.shippingAddressId = null\n entity.billingAddressSnapshot = null\n entity.shippingAddressSnapshot = null\n }\n if (input.customerContactId !== undefined) {\n entity.customerContactId = input.customerContactId ?? null\n if (entity.customerEntityId) {\n entity.customerSnapshot = await resolveCustomerSnapshot(\n em,\n organizationId,\n tenantId,\n entity.customerEntityId,\n input.customerContactId\n )\n }\n }\n if (input.customerSnapshot !== undefined) {\n entity.customerSnapshot = input.customerSnapshot ?? null\n }\n if (input.metadata !== undefined) {\n entity.metadata = input.metadata ?? null\n }\n if (input.externalReference !== undefined) {\n const normalized = typeof input.externalReference === 'string' ? input.externalReference.trim() : ''\n entity.externalReference = normalized.length ? normalized : null\n }\n if (input.customerReference !== undefined) {\n const normalized = typeof input.customerReference === 'string' ? input.customerReference.trim() : ''\n entity.customerReference = normalized.length ? normalized : null\n }\n if (input.comment !== undefined) {\n const normalized = typeof input.comment === 'string' ? input.comment.trim() : ''\n entity.comments = normalized.length ? normalized : null\n }\n if (typeof input.currencyCode === 'string') {\n entity.currencyCode = input.currencyCode\n }\n if (input.channelId !== undefined) {\n if (input.channelId === null) {\n entity.channelId = null\n } else {\n const channel = await em.findOne(SalesChannel, {\n id: input.channelId,\n organizationId,\n tenantId,\n deletedAt: null,\n })\n if (!channel) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.channelInvalid', 'Selected channel could not be found.') })\n }\n entity.channelId = channel.id\n }\n }\n if (input.statusEntryId !== undefined) {\n const statusValue = await resolveDictionaryEntryValue(em, input.statusEntryId)\n if (input.statusEntryId && !statusValue) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.statusInvalid', 'Selected status could not be found.') })\n }\n ;(entity as any).statusEntryId = input.statusEntryId ?? null\n ;(entity as any).status = statusValue\n }\n if (input.placedAt !== undefined) {\n if (input.placedAt === null) {\n entity.placedAt = null\n } else {\n const parsed = new Date(input.placedAt)\n entity.placedAt = Number.isNaN(parsed.getTime()) ? entity.placedAt : parsed\n }\n }\n if (input.expectedDeliveryAt !== undefined && 'expectedDeliveryAt' in entity) {\n if (input.expectedDeliveryAt === null) {\n (entity as SalesOrder).expectedDeliveryAt = null\n } else {\n const parsed = new Date(input.expectedDeliveryAt)\n ;(entity as SalesOrder).expectedDeliveryAt = Number.isNaN(parsed.getTime())\n ? (entity as SalesOrder).expectedDeliveryAt\n : parsed\n }\n }\n if (input.shippingAddressId !== undefined) {\n entity.shippingAddressId = input.shippingAddressId ?? null\n if (input.shippingAddressSnapshot === undefined) {\n entity.shippingAddressSnapshot = await resolveAddressSnapshot(em, organizationId, tenantId, input.shippingAddressId)\n }\n }\n if (input.billingAddressId !== undefined) {\n entity.billingAddressId = input.billingAddressId ?? null\n if (input.billingAddressSnapshot === undefined) {\n entity.billingAddressSnapshot = await resolveAddressSnapshot(em, organizationId, tenantId, input.billingAddressId)\n }\n }\n if (input.shippingAddressSnapshot !== undefined) {\n entity.shippingAddressSnapshot = input.shippingAddressSnapshot ?? null\n }\n if (input.billingAddressSnapshot !== undefined) {\n entity.billingAddressSnapshot = input.billingAddressSnapshot ?? null\n }\n if (input.shippingMethodId !== undefined || input.shippingMethodSnapshot !== undefined || input.shippingMethodCode !== undefined) {\n let shippingMethod: SalesShippingMethod | null = null\n if (input.shippingMethodId) {\n shippingMethod = await em.findOne(SalesShippingMethod, {\n id: input.shippingMethodId,\n organizationId,\n tenantId,\n deletedAt: null,\n })\n if (!shippingMethod) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.shippingMethodInvalid', 'Selected shipping method could not be found.') })\n }\n }\n ;(entity as any).shippingMethodId = input.shippingMethodId ?? null\n ;(entity as any).shippingMethod = shippingMethod ?? null\n ;(entity as any).shippingMethodCode = input.shippingMethodCode ?? shippingMethod?.code ?? null\n if (input.shippingMethodSnapshot !== undefined) {\n ;(entity as any).shippingMethodSnapshot = input.shippingMethodSnapshot ?? null\n } else {\n ;(entity as any).shippingMethodSnapshot = shippingMethod\n ? {\n id: shippingMethod.id,\n code: shippingMethod.code,\n name: shippingMethod.name,\n description: shippingMethod.description ?? null,\n carrierCode: shippingMethod.carrierCode ?? null,\n providerKey: shippingMethod.providerKey ?? null,\n serviceLevel: shippingMethod.serviceLevel ?? null,\n estimatedTransitDays: shippingMethod.estimatedTransitDays ?? null,\n baseRateNet: shippingMethod.baseRateNet,\n baseRateGross: shippingMethod.baseRateGross,\n currencyCode: shippingMethod.currencyCode ?? null,\n metadata: shippingMethod.metadata ? cloneJson(shippingMethod.metadata) : null,\n providerSettings:\n shippingMethod.metadata && typeof shippingMethod.metadata === 'object'\n ? cloneJson(\n (shippingMethod.metadata as Record<string, unknown>).providerSettings ??\n null\n )\n : null,\n }\n : null\n }\n }\n if (input.paymentMethodId !== undefined || input.paymentMethodSnapshot !== undefined || input.paymentMethodCode !== undefined) {\n let paymentMethod: SalesPaymentMethod | null = null\n if (input.paymentMethodId) {\n paymentMethod = await em.findOne(SalesPaymentMethod, {\n id: input.paymentMethodId,\n organizationId,\n tenantId,\n deletedAt: null,\n })\n if (!paymentMethod) {\n throw new CrudHttpError(400, { error: translate('sales.documents.detail.paymentMethodInvalid', 'Selected payment method could not be found.') })\n }\n }\n ;(entity as any).paymentMethodId = input.paymentMethodId ?? null\n ;(entity as any).paymentMethod = paymentMethod ?? null\n ;(entity as any).paymentMethodCode = input.paymentMethodCode ?? paymentMethod?.code ?? null\n if (input.paymentMethodSnapshot !== undefined) {\n ;(entity as any).paymentMethodSnapshot = input.paymentMethodSnapshot ?? null\n } else {\n ;(entity as any).paymentMethodSnapshot = paymentMethod\n ? {\n id: paymentMethod.id,\n code: paymentMethod.code,\n name: paymentMethod.name,\n description: paymentMethod.description ?? null,\n providerKey: paymentMethod.providerKey ?? null,\n terms: paymentMethod.terms ?? null,\n metadata: paymentMethod.metadata ? cloneJson(paymentMethod.metadata) : null,\n providerSettings:\n paymentMethod.metadata && typeof paymentMethod.metadata === 'object'\n ? cloneJson(\n (paymentMethod.metadata as Record<string, unknown>).providerSettings ??\n null\n )\n : null,\n }\n : null\n }\n }\n\n if (input.tags !== undefined) {\n await syncSalesDocumentTags(em, {\n documentId: entity.id,\n kind,\n organizationId,\n tenantId,\n tagIds: input.tags,\n })\n }\n\n if (input.customFieldSetId !== undefined) {\n ;(entity as any).customFieldSetId = input.customFieldSetId ?? null\n }\n\n if (input.customFields !== undefined) {\n const values =\n input.customFields && typeof input.customFields === 'object' && !Array.isArray(input.customFields)\n ? (input.customFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: kind === 'order' ? E.sales.sales_order : E.sales.sales_quote,\n recordId: entity.id,\n organizationId,\n tenantId,\n values,\n })\n }\n}\n\nasync function loadQuoteSnapshot(em: EntityManager, id: string): Promise<QuoteGraphSnapshot | null> {\n const quote = await em.findOne(SalesQuote, { id, deletedAt: null })\n if (!quote) return null\n const lines = await em.find(SalesQuoteLine, { quote: quote }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesQuoteAdjustment, { quote: quote }, { orderBy: { position: 'asc' } })\n const [addresses, notes, tags, quoteCustomFields, lineCustomFields, adjustmentCustomFields] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: id, documentKind: 'quote' }),\n em.find(SalesNote, { contextType: 'quote', contextId: id }),\n findWithDecryption(\n em,\n SalesDocumentTagAssignment,\n { documentId: id, documentKind: 'quote' },\n { populate: ['tag'] },\n { tenantId: quote.tenantId, organizationId: quote.organizationId },\n ),\n loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote,\n recordIds: [quote.id],\n tenantIdByRecord: { [quote.id]: quote.tenantId },\n organizationIdByRecord: { [quote.id]: quote.organizationId },\n }),\n lines.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote_line,\n recordIds: lines.map((line) => line.id),\n tenantIdByRecord: Object.fromEntries(lines.map((line) => [line.id, quote.tenantId])),\n organizationIdByRecord: Object.fromEntries(lines.map((line) => [line.id, quote.organizationId])),\n })\n : Promise.resolve({}),\n adjustments.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote_adjustment,\n recordIds: adjustments.map((adj) => adj.id),\n tenantIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, quote.tenantId])),\n organizationIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, quote.organizationId])),\n })\n : Promise.resolve({}),\n ])\n const addressSnapshots: DocumentAddressSnapshot[] = addresses.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: entry.documentId,\n documentKind: 'quote',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n }))\n const noteSnapshots: NoteSnapshot[] = notes.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: entry.contextType as 'order' | 'quote',\n contextId: entry.contextId,\n orderId: entry.order ? (typeof entry.order === 'string' ? entry.order : entry.order.id) : null,\n quoteId: entry.quote ? (typeof entry.quote === 'string' ? entry.quote : entry.quote.id) : null,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n }))\n const tagSnapshots: TagAssignmentSnapshot[] = tags\n .map((assignment) => {\n const tagId =\n typeof assignment.tag === 'string'\n ? assignment.tag\n : assignment.tag?.id ?? (assignment as any)?.tag_id ?? null\n if (!tagId) return null\n return {\n id: assignment.id,\n tagId,\n organizationId: assignment.organizationId,\n tenantId: assignment.tenantId,\n documentId: assignment.documentId,\n documentKind: 'quote',\n }\n })\n .filter((entry): entry is TagAssignmentSnapshot => !!entry)\n\n return {\n quote: {\n id: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteNumber: quote.quoteNumber,\n statusEntryId: quote.statusEntryId ?? null,\n status: quote.status ?? null,\n customerEntityId: quote.customerEntityId ?? null,\n customerContactId: quote.customerContactId ?? null,\n customerSnapshot: quote.customerSnapshot ? cloneJson(quote.customerSnapshot) : null,\n billingAddressId: quote.billingAddressId ?? null,\n shippingAddressId: quote.shippingAddressId ?? null,\n billingAddressSnapshot: quote.billingAddressSnapshot ? cloneJson(quote.billingAddressSnapshot) : null,\n shippingAddressSnapshot: quote.shippingAddressSnapshot ? cloneJson(quote.shippingAddressSnapshot) : null,\n currencyCode: quote.currencyCode,\n validFrom: quote.validFrom ? quote.validFrom.toISOString() : null,\n validUntil: quote.validUntil ? quote.validUntil.toISOString() : null,\n comments: quote.comments ?? null,\n taxInfo: quote.taxInfo ? cloneJson(quote.taxInfo) : null,\n shippingMethodId: quote.shippingMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n deliveryWindowId: quote.deliveryWindowId ?? null,\n deliveryWindowCode: quote.deliveryWindowCode ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n channelId: quote.channelId ?? null,\n shippingMethodSnapshot: quote.shippingMethodSnapshot ? cloneJson(quote.shippingMethodSnapshot) : null,\n deliveryWindowSnapshot: quote.deliveryWindowSnapshot ? cloneJson(quote.deliveryWindowSnapshot) : null,\n paymentMethodSnapshot: quote.paymentMethodSnapshot ? cloneJson(quote.paymentMethodSnapshot) : null,\n metadata: quote.metadata ? cloneJson(quote.metadata) : null,\n customFieldSetId: quote.customFieldSetId ?? null,\n customFields: quoteCustomFields[quote.id] ? cloneJson(quoteCustomFields[quote.id]) : null,\n subtotalNetAmount: quote.subtotalNetAmount,\n subtotalGrossAmount: quote.subtotalGrossAmount,\n discountTotalAmount: quote.discountTotalAmount,\n taxTotalAmount: quote.taxTotalAmount,\n grandTotalNetAmount: quote.grandTotalNetAmount,\n grandTotalGrossAmount: quote.grandTotalGrossAmount,\n totalsSnapshot: quote.totalsSnapshot ? cloneJson(quote.totalsSnapshot) : null,\n lineItemCount: quote.lineItemCount,\n },\n lines: lines.map((line) => ({\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n customFields: lineCustomFields[line.id] ? cloneJson(lineCustomFields[line.id]) : null,\n })),\n adjustments: adjustments.map((adj) => ({\n id: adj.id,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? null,\n label: adj.label ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross,\n currencyCode: adj.currencyCode ?? null,\n metadata: adj.metadata ? cloneJson(adj.metadata) : null,\n position: adj.position,\n quoteLineId: typeof adj.quoteLine === 'string' ? adj.quoteLine : adj.quoteLine?.id ?? null,\n customFields: adjustmentCustomFields[adj.id] ? cloneJson(adjustmentCustomFields[adj.id]) : null,\n })),\n addresses: addressSnapshots,\n notes: noteSnapshots,\n tags: tagSnapshots,\n }\n}\n\nasync function loadOrderSnapshot(em: EntityManager, id: string): Promise<OrderGraphSnapshot | null> {\n const order = await em.findOne(SalesOrder, { id, deletedAt: null })\n if (!order) return null\n const lines = await em.find(SalesOrderLine, { order: order }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesOrderAdjustment, { order: order }, { orderBy: { position: 'asc' } })\n const [addresses, notes, tags, shipments, payments, orderCustomFields, lineCustomFields, adjustmentCustomFields] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: id, documentKind: 'order' }),\n em.find(SalesNote, { contextType: 'order', contextId: id }),\n findWithDecryption(\n em,\n SalesDocumentTagAssignment,\n { documentId: id, documentKind: 'order' },\n { populate: ['tag'] },\n { tenantId: order.tenantId, organizationId: order.organizationId },\n ),\n em.find(SalesShipment, { order: order }),\n em.find(SalesPayment, { order: order }),\n loadCustomFieldValues({\n em,\n entityId: E.sales.sales_order,\n recordIds: [order.id],\n tenantIdByRecord: { [order.id]: order.tenantId },\n organizationIdByRecord: { [order.id]: order.organizationId },\n }),\n lines.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_order_line,\n recordIds: lines.map((line) => line.id),\n tenantIdByRecord: Object.fromEntries(lines.map((line) => [line.id, order.tenantId])),\n organizationIdByRecord: Object.fromEntries(lines.map((line) => [line.id, order.organizationId])),\n })\n : Promise.resolve({}),\n adjustments.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_order_adjustment,\n recordIds: adjustments.map((adj) => adj.id),\n tenantIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, order.tenantId])),\n organizationIdByRecord: Object.fromEntries(adjustments.map((adj) => [adj.id, order.organizationId])),\n })\n : Promise.resolve({}),\n ])\n const shipmentSnapshots = (\n await Promise.all(shipments.map((entry) => loadShipmentSnapshot(em, entry.id)))\n ).filter((entry): entry is ShipmentSnapshot => !!entry)\n const paymentSnapshots = (\n await Promise.all(payments.map((entry) => loadPaymentSnapshot(em, entry.id)))\n ).filter((entry): entry is PaymentSnapshot => !!entry)\n const addressSnapshots: DocumentAddressSnapshot[] = addresses.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: entry.documentId,\n documentKind: 'order',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n }))\n const noteSnapshots: NoteSnapshot[] = notes.map((entry) => ({\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: entry.contextType as 'order' | 'quote',\n contextId: entry.contextId,\n orderId: entry.order ? (typeof entry.order === 'string' ? entry.order : entry.order.id) : null,\n quoteId: entry.quote ? (typeof entry.quote === 'string' ? entry.quote : entry.quote.id) : null,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n }))\n const tagSnapshots: TagAssignmentSnapshot[] = tags\n .map((assignment) => {\n const tagId =\n typeof assignment.tag === 'string'\n ? assignment.tag\n : assignment.tag?.id ?? (assignment as any)?.tag_id ?? null\n if (!tagId) return null\n return {\n id: assignment.id,\n tagId,\n organizationId: assignment.organizationId,\n tenantId: assignment.tenantId,\n documentId: assignment.documentId,\n documentKind: 'order',\n }\n })\n .filter((entry): entry is TagAssignmentSnapshot => !!entry)\n\n return {\n order: {\n id: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderNumber: order.orderNumber,\n statusEntryId: order.statusEntryId ?? null,\n status: order.status ?? null,\n fulfillmentStatusEntryId: order.fulfillmentStatusEntryId ?? null,\n fulfillmentStatus: order.fulfillmentStatus ?? null,\n paymentStatusEntryId: order.paymentStatusEntryId ?? null,\n paymentStatus: order.paymentStatus ?? null,\n customerEntityId: order.customerEntityId ?? null,\n customerContactId: order.customerContactId ?? null,\n customerSnapshot: order.customerSnapshot ? cloneJson(order.customerSnapshot) : null,\n billingAddressId: order.billingAddressId ?? null,\n shippingAddressId: order.shippingAddressId ?? null,\n billingAddressSnapshot: order.billingAddressSnapshot ? cloneJson(order.billingAddressSnapshot) : null,\n shippingAddressSnapshot: order.shippingAddressSnapshot ? cloneJson(order.shippingAddressSnapshot) : null,\n currencyCode: order.currencyCode,\n exchangeRate: order.exchangeRate ?? null,\n taxStrategyKey: order.taxStrategyKey ?? null,\n discountStrategyKey: order.discountStrategyKey ?? null,\n taxInfo: order.taxInfo ? cloneJson(order.taxInfo) : null,\n shippingMethodId: order.shippingMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n deliveryWindowId: order.deliveryWindowId ?? null,\n deliveryWindowCode: order.deliveryWindowCode ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n channelId: order.channelId ?? null,\n placedAt: order.placedAt ? order.placedAt.toISOString() : null,\n expectedDeliveryAt: order.expectedDeliveryAt ? order.expectedDeliveryAt.toISOString() : null,\n dueAt: order.dueAt ? order.dueAt.toISOString() : null,\n comments: order.comments ?? null,\n internalNotes: order.internalNotes ?? null,\n shippingMethodSnapshot: order.shippingMethodSnapshot ? cloneJson(order.shippingMethodSnapshot) : null,\n deliveryWindowSnapshot: order.deliveryWindowSnapshot ? cloneJson(order.deliveryWindowSnapshot) : null,\n paymentMethodSnapshot: order.paymentMethodSnapshot ? cloneJson(order.paymentMethodSnapshot) : null,\n metadata: order.metadata ? cloneJson(order.metadata) : null,\n customFieldSetId: order.customFieldSetId ?? null,\n customFields: orderCustomFields[order.id] ? cloneJson(orderCustomFields[order.id]) : null,\n subtotalNetAmount: order.subtotalNetAmount,\n subtotalGrossAmount: order.subtotalGrossAmount,\n discountTotalAmount: order.discountTotalAmount,\n taxTotalAmount: order.taxTotalAmount,\n shippingNetAmount: order.shippingNetAmount,\n shippingGrossAmount: order.shippingGrossAmount,\n surchargeTotalAmount: order.surchargeTotalAmount,\n grandTotalNetAmount: order.grandTotalNetAmount,\n grandTotalGrossAmount: order.grandTotalGrossAmount,\n paidTotalAmount: order.paidTotalAmount,\n refundedTotalAmount: order.refundedTotalAmount,\n outstandingAmount: order.outstandingAmount,\n totalsSnapshot: order.totalsSnapshot ? cloneJson(order.totalsSnapshot) : null,\n lineItemCount: order.lineItemCount,\n },\n lines: lines.map((line) => ({\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n reservedQuantity: line.reservedQuantity,\n fulfilledQuantity: line.fulfilledQuantity,\n invoicedQuantity: line.invoicedQuantity,\n returnedQuantity: line.returnedQuantity,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n customFields: lineCustomFields[line.id] ? cloneJson(lineCustomFields[line.id]) : null,\n })),\n adjustments: adjustments.map((adj) => ({\n id: adj.id,\n scope: adj.scope,\n kind: adj.kind,\n code: adj.code ?? null,\n label: adj.label ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross,\n currencyCode: adj.currencyCode ?? null,\n metadata: adj.metadata ? cloneJson(adj.metadata) : null,\n position: adj.position,\n orderLineId: typeof adj.orderLine === 'string' ? adj.orderLine : adj.orderLine?.id ?? null,\n customFields: adjustmentCustomFields[adj.id] ? cloneJson(adjustmentCustomFields[adj.id]) : null,\n })),\n addresses: addressSnapshots,\n notes: noteSnapshots,\n tags: tagSnapshots,\n shipments: shipmentSnapshots,\n payments: paymentSnapshots,\n }\n}\n\ntype DeletableEntity = { id?: string; organizationId?: string | null; tenantId?: string | null }\n\nasync function queueDeletionSideEffects(\n dataEngine: DataEngine,\n entities: DeletableEntity[] | DeletableEntity | null | undefined,\n entityType: string\n): Promise<void> {\n if (!entities) return\n const list = Array.isArray(entities) ? entities : [entities]\n const tasks: Array<Promise<void>> = []\n for (const entity of list) {\n if (!entity) continue\n const id = typeof entity.id === 'string' ? entity.id : null\n if (!id) continue\n tasks.push(\n emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity,\n identifiers: {\n id,\n organizationId: entity.organizationId ?? null,\n tenantId: entity.tenantId ?? null,\n },\n indexer: { entityType },\n })\n )\n }\n if (tasks.length) await Promise.all(tasks)\n}\n\nfunction toNumeric(value: string | number | null | undefined): number {\n if (typeof value === 'number') return value\n if (typeof value === 'string' && value.trim().length) {\n const parsed = Number(value)\n if (!Number.isNaN(parsed)) return parsed\n }\n return 0\n}\n\nfunction normalizeShippingMethodContext(\n snapshot: Record<string, unknown> | null | undefined,\n id?: string | null,\n code?: string | null,\n currencyCode?: string\n): ShippingMethodContext | null {\n if (!snapshot || typeof snapshot !== 'object') return null\n const metadata = (snapshot as Record<string, unknown>).metadata\n const providerSettings =\n (snapshot as Record<string, unknown>).providerSettings ??\n (metadata && typeof metadata === 'object'\n ? (metadata as Record<string, unknown>).providerSettings ?? null\n : null)\n return {\n id: (snapshot as Record<string, unknown>).id as string | undefined ?? id ?? null,\n code:\n typeof (snapshot as Record<string, unknown>).code === 'string'\n ? ((snapshot as Record<string, unknown>).code as string)\n : code ?? null,\n name:\n typeof (snapshot as Record<string, unknown>).name === 'string'\n ? ((snapshot as Record<string, unknown>).name as string)\n : null,\n providerKey:\n typeof (snapshot as Record<string, unknown>).providerKey === 'string'\n ? ((snapshot as Record<string, unknown>).providerKey as string)\n : null,\n currencyCode:\n typeof (snapshot as Record<string, unknown>).currencyCode === 'string'\n ? ((snapshot as Record<string, unknown>).currencyCode as string)\n : currencyCode ?? null,\n baseRateNet: toNumeric(\n ((snapshot as Record<string, unknown>).baseRateNet ??\n (snapshot as Record<string, unknown>).base_rate_net) as string | number | null\n ),\n baseRateGross: toNumeric(\n ((snapshot as Record<string, unknown>).baseRateGross ??\n (snapshot as Record<string, unknown>).base_rate_gross) as string | number | null\n ),\n metadata:\n metadata && typeof metadata === 'object' ? cloneJson(metadata as Record<string, unknown>) : null,\n providerSettings:\n providerSettings && typeof providerSettings === 'object'\n ? cloneJson(providerSettings as Record<string, unknown>)\n : null,\n }\n}\n\nfunction normalizePaymentMethodContext(\n snapshot: Record<string, unknown> | null | undefined,\n id?: string | null,\n code?: string | null\n): PaymentMethodContext | null {\n if (!snapshot || typeof snapshot !== 'object') return null\n const metadata = (snapshot as Record<string, unknown>).metadata\n const providerSettings =\n (snapshot as Record<string, unknown>).providerSettings ??\n (metadata && typeof metadata === 'object'\n ? (metadata as Record<string, unknown>).providerSettings ?? null\n : null)\n return {\n id: (snapshot as Record<string, unknown>).id as string | undefined ?? id ?? null,\n code:\n typeof (snapshot as Record<string, unknown>).code === 'string'\n ? ((snapshot as Record<string, unknown>).code as string)\n : code ?? null,\n name:\n typeof (snapshot as Record<string, unknown>).name === 'string'\n ? ((snapshot as Record<string, unknown>).name as string)\n : null,\n providerKey:\n typeof (snapshot as Record<string, unknown>).providerKey === 'string'\n ? ((snapshot as Record<string, unknown>).providerKey as string)\n : null,\n terms:\n typeof (snapshot as Record<string, unknown>).terms === 'string'\n ? ((snapshot as Record<string, unknown>).terms as string)\n : null,\n metadata:\n metadata && typeof metadata === 'object' ? cloneJson(metadata as Record<string, unknown>) : null,\n providerSettings:\n providerSettings && typeof providerSettings === 'object'\n ? cloneJson(providerSettings as Record<string, unknown>)\n : null,\n }\n}\n\nfunction buildProviderContext(params: {\n shippingSnapshot?: Record<string, unknown> | null\n paymentSnapshot?: Record<string, unknown> | null\n shippingMethodId?: string | null\n paymentMethodId?: string | null\n shippingMethodCode?: string | null\n paymentMethodCode?: string | null\n currencyCode: string\n}) {\n return {\n shippingMethod: normalizeShippingMethodContext(\n params.shippingSnapshot,\n params.shippingMethodId,\n params.shippingMethodCode,\n params.currencyCode\n ),\n paymentMethod: normalizePaymentMethodContext(\n params.paymentSnapshot,\n params.paymentMethodId,\n params.paymentMethodCode\n ),\n }\n}\n\nfunction buildCalculationContext(params: {\n tenantId: string\n organizationId: string\n currencyCode: string\n shippingSnapshot?: Record<string, unknown> | null\n paymentSnapshot?: Record<string, unknown> | null\n shippingMethodId?: string | null\n paymentMethodId?: string | null\n shippingMethodCode?: string | null\n paymentMethodCode?: string | null\n}) {\n return {\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n currencyCode: params.currencyCode,\n metadata: buildProviderContext({\n shippingSnapshot: params.shippingSnapshot,\n paymentSnapshot: params.paymentSnapshot,\n shippingMethodId: params.shippingMethodId,\n paymentMethodId: params.paymentMethodId,\n shippingMethodCode: params.shippingMethodCode,\n paymentMethodCode: params.paymentMethodCode,\n currencyCode: params.currencyCode,\n }),\n }\n}\n\n\nfunction mapOrderLineEntityToSnapshot(line: SalesOrderLine): SalesLineSnapshot {\n return {\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: toNumeric(line.quantity),\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: toNumeric(line.unitPriceNet),\n unitPriceGross: toNumeric(line.unitPriceGross),\n discountAmount: toNumeric(line.discountAmount),\n discountPercent: toNumeric(line.discountPercent),\n taxRate: toNumeric(line.taxRate),\n taxAmount: toNumeric(line.taxAmount),\n totalNetAmount: toNumeric(line.totalNetAmount),\n totalGrossAmount: toNumeric(line.totalGrossAmount),\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n }\n}\n\nfunction mapQuoteLineEntityToSnapshot(line: SalesQuoteLine): SalesLineSnapshot {\n return {\n id: line.id,\n lineNumber: line.lineNumber,\n kind: line.kind,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: toNumeric(line.quantity),\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: toNumeric(line.unitPriceNet),\n unitPriceGross: toNumeric(line.unitPriceGross),\n discountAmount: toNumeric(line.discountAmount),\n discountPercent: toNumeric(line.discountPercent),\n taxRate: toNumeric(line.taxRate),\n taxAmount: toNumeric(line.taxAmount),\n totalNetAmount: toNumeric(line.totalNetAmount),\n totalGrossAmount: toNumeric(line.totalGrossAmount),\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n }\n}\n\nfunction mapOrderAdjustmentToDraft(adjustment: SalesOrderAdjustment): SalesAdjustmentDraft {\n return {\n id: adjustment.id,\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: toNumeric(adjustment.rate),\n amountNet: toNumeric(adjustment.amountNet),\n amountGross: toNumeric(adjustment.amountGross),\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? 0,\n }\n}\n\nfunction mapQuoteAdjustmentToDraft(adjustment: SalesQuoteAdjustment): SalesAdjustmentDraft {\n return {\n id: adjustment.id,\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: toNumeric(adjustment.rate),\n amountNet: toNumeric(adjustment.amountNet),\n amountGross: toNumeric(adjustment.amountGross),\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? 0,\n }\n}\n\nasync function emitTotalsCalculated(\n eventBus: EventBus | null | undefined,\n payload: {\n documentKind: SalesDocumentKind\n documentId: string\n organizationId: string\n tenantId: string\n customerId?: string | null\n totals: SalesDocumentCalculationResult['totals']\n lineCount: number\n }\n): Promise<void> {\n if (!eventBus) return\n await eventBus.emitEvent('sales.document.totals.calculated', payload)\n}\n\nfunction createLineSnapshotFromInput(\n line: DocumentLineCreateInput,\n lineNumber: number\n): SalesLineSnapshot {\n return {\n lineNumber,\n kind: line.kind ?? 'product',\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: Number(line.quantity ?? 0),\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet ?? null,\n unitPriceGross: line.unitPriceGross ?? null,\n discountAmount: line.discountAmount ?? null,\n discountPercent: line.discountPercent ?? null,\n taxRate: line.taxRate ?? null,\n taxAmount: line.taxAmount ?? null,\n totalNetAmount: line.totalNetAmount ?? null,\n totalGrossAmount: line.totalGrossAmount ?? null,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: 'customFieldSetId' in line ? (line as any).customFieldSetId ?? null : null,\n customFields:\n 'customFields' in line && line.customFields\n ? cloneJson((line as any).customFields)\n : null,\n }\n}\n\nfunction createAdjustmentDraftFromInput(\n adjustment: DocumentAdjustmentCreateInput & { id?: string | null }\n): SalesAdjustmentDraft {\n const lineRef =\n 'quoteLineId' in adjustment\n ? (adjustment as any).quoteLineId\n : (adjustment as any).orderLineId\n if (adjustment.scope === 'line' && lineRef) {\n throw new CrudHttpError(400, { error: 'Line-scoped adjustments are not supported yet.' })\n }\n return {\n id: typeof adjustment.id === 'string' ? adjustment.id : undefined,\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind ?? 'custom',\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: adjustment.rate ?? null,\n amountNet: adjustment.amountNet ?? null,\n amountGross: adjustment.amountGross ?? null,\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? 0,\n }\n}\n\nfunction convertLineCalculationToEntityInput(\n lineResult: SalesLineCalculationResult,\n sourceLine: DocumentLineCreateInput,\n document: { organizationId: string; tenantId: string },\n index: number\n) {\n const line = lineResult.line\n return {\n lineNumber: line.lineNumber ?? index + 1,\n kind: line.kind ?? 'product',\n statusEntryId: sourceLine.statusEntryId ?? null,\n productId: sourceLine.productId ?? null,\n productVariantId: sourceLine.productVariantId ?? null,\n catalogSnapshot: sourceLine.catalogSnapshot ? cloneJson(sourceLine.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: toNumericString(line.quantity) ?? '0',\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet:\n toNumericString(line.unitPriceNet ?? (lineResult.netAmount / Math.max(line.quantity || 1, 1))) ??\n '0',\n unitPriceGross:\n toNumericString(\n line.unitPriceGross ?? (lineResult.grossAmount / Math.max(line.quantity || 1, 1))\n ) ?? '0',\n discountAmount: toNumericString(lineResult.discountAmount) ?? '0',\n discountPercent: toNumericString(line.discountPercent) ?? '0',\n taxRate: toNumericString(line.taxRate) ?? '0',\n taxAmount: toNumericString(lineResult.taxAmount) ?? '0',\n totalNetAmount: toNumericString(lineResult.netAmount) ?? '0',\n totalGrossAmount: toNumericString(lineResult.grossAmount) ?? '0',\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: sourceLine.promotionSnapshot ? cloneJson(sourceLine.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: sourceLine.customFieldSetId ?? null,\n organizationId: document.organizationId,\n tenantId: document.tenantId,\n }\n}\n\nfunction convertAdjustmentResultToEntityInput(\n adjustment: SalesAdjustmentDraft,\n sourceAdjustment: DocumentAdjustmentCreateInput | null,\n document: { organizationId: string; tenantId: string },\n index: number\n) {\n const metadata = adjustment.metadata ? cloneJson(adjustment.metadata) : null\n const resolvedPosition =\n sourceAdjustment?.position ??\n (adjustment.position !== null && adjustment.position !== undefined ? adjustment.position : index)\n return {\n scope: adjustment.scope ?? 'order',\n kind: adjustment.kind ?? 'custom',\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: toNumericString(adjustment.rate) ?? '0',\n amountNet: toNumericString(adjustment.amountNet) ?? '0',\n amountGross: toNumericString(adjustment.amountGross ?? adjustment.amountNet) ?? '0',\n currencyCode: adjustment.currencyCode ?? null,\n metadata,\n position: resolvedPosition,\n organizationId: document.organizationId,\n tenantId: document.tenantId,\n }\n}\n\nasync function applyOrderLineResults(params: {\n em: EntityManager\n order: SalesOrder\n calculation: SalesDocumentCalculationResult\n sourceLines: Array<DocumentLineCreateInput & { id?: string }>\n existingLines: SalesOrderLine[]\n}): Promise<void> {\n const { em, order, calculation, sourceLines, existingLines } = params\n const existingMap = new Map(existingLines.map((line) => [line.id, line]))\n const persisted = new Set<string>()\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = sourceLines[index]\n const statusEntryId = (sourceLine as any).statusEntryId ?? null\n const statusValue = await resolveStatus(statusEntryId ?? null)\n const payload = convertLineCalculationToEntityInput(lineResult, sourceLine, order, index)\n const existing = sourceLine.id ? existingMap.get(sourceLine.id) ?? null : null\n const lineEntity =\n existing ??\n em.create(SalesOrderLine, {\n order,\n id: sourceLine.id ?? undefined,\n reservedQuantity: existing?.reservedQuantity ?? '0',\n fulfilledQuantity: existing?.fulfilledQuantity ?? '0',\n invoicedQuantity: existing?.invoicedQuantity ?? '0',\n returnedQuantity: existing?.returnedQuantity ?? '0',\n createdAt: existing?.createdAt ?? new Date(),\n updatedAt: new Date(),\n })\n Object.assign(lineEntity, {\n ...payload,\n order,\n statusEntryId,\n status: statusValue,\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: lineEntity.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n persisted.add(lineEntity.id)\n }\n for (const [id, line] of existingMap.entries()) {\n if (!persisted.has(id)) {\n em.remove(line)\n }\n }\n}\n\nasync function applyQuoteLineResults(params: {\n em: EntityManager\n quote: SalesQuote\n calculation: SalesDocumentCalculationResult\n sourceLines: Array<DocumentLineCreateInput & { id?: string }>\n existingLines: SalesQuoteLine[]\n}): Promise<void> {\n const { em, quote, calculation, sourceLines, existingLines } = params\n const existingMap = new Map(existingLines.map((line) => [line.id, line]))\n const persisted = new Set<string>()\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = sourceLines[index]\n const statusEntryId = (sourceLine as any).statusEntryId ?? null\n const statusValue = await resolveStatus(statusEntryId ?? null)\n const payload = convertLineCalculationToEntityInput(lineResult, sourceLine, quote, index)\n const existing = sourceLine.id ? existingMap.get(sourceLine.id) ?? null : null\n const lineEntity =\n existing ??\n em.create(SalesQuoteLine, {\n quote,\n id: sourceLine.id ?? undefined,\n createdAt: existing?.createdAt ?? new Date(),\n updatedAt: new Date(),\n })\n Object.assign(lineEntity, {\n ...payload,\n quote,\n statusEntryId,\n status: statusValue,\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_line,\n recordId: lineEntity.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n persisted.add(lineEntity.id)\n }\n for (const [id, line] of existingMap.entries()) {\n if (!persisted.has(id)) {\n em.remove(line)\n }\n }\n}\n\nasync function replaceQuoteLines(\n em: EntityManager,\n quote: SalesQuote,\n calculation: SalesDocumentCalculationResult,\n lineInputs: QuoteLineCreateInput[]\n): Promise<void> {\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = lineInputs[index]\n const entityInput = convertLineCalculationToEntityInput(lineResult, sourceLine, quote, index)\n const statusValue = await resolveStatus(sourceLine.statusEntryId ?? null)\n const lineEntity = em.create(SalesQuoteLine, {\n quote,\n ...entityInput,\n status: statusValue,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_line,\n recordId: lineEntity.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n }\n}\n\nasync function replaceQuoteAdjustments(\n em: EntityManager,\n quote: SalesQuote,\n calculation: SalesDocumentCalculationResult,\n adjustmentInputs: QuoteAdjustmentCreateInput[] | null\n): Promise<void> {\n const existing = await em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } })\n const existingMap = new Map<string, SalesQuoteAdjustment>()\n existing.forEach((adj) => existingMap.set(adj.id, adj))\n const seen = new Set<string>()\n const adjustmentDrafts = calculation.adjustments\n for (let index = 0; index < adjustmentDrafts.length; index += 1) {\n const draft = adjustmentDrafts[index]\n const sourceById = adjustmentInputs?.find((adj) => (adj as any).id === draft.id) ?? null\n const source = sourceById ?? (adjustmentInputs ? adjustmentInputs[index] ?? null : null)\n const entityInput = convertAdjustmentResultToEntityInput(draft, source, quote, index)\n const adjustmentId =\n (draft as any).id ??\n (source as any)?.id ??\n randomUUID()\n const existingEntity = existingMap.get(adjustmentId)\n const entity =\n existingEntity ??\n em.create(SalesQuoteAdjustment, {\n id: adjustmentId,\n quote,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n createdAt: new Date(),\n })\n entity.scope = entityInput.scope\n entity.kind = entityInput.kind\n entity.code = entityInput.code ?? null\n entity.label = entityInput.label ?? null\n entity.calculatorKey = entityInput.calculatorKey ?? null\n entity.promotionId = entityInput.promotionId ?? null\n entity.rate = entityInput.rate ?? '0'\n entity.amountNet = entityInput.amountNet ?? '0'\n entity.amountGross = entityInput.amountGross ?? entityInput.amountNet ?? '0'\n entity.currencyCode = entityInput.currencyCode ?? quote.currencyCode\n entity.metadata = entityInput.metadata ?? null\n entity.position = entityInput.position ?? index\n entity.updatedAt = new Date()\n entity.quoteLine = null\n seen.add(adjustmentId)\n if (source?.customFields !== undefined) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_adjustment,\n recordId: adjustmentId,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values:\n source.customFields && typeof source.customFields === 'object'\n ? (source.customFields as Record<string, unknown>)\n : {},\n })\n }\n em.persist(entity)\n }\n\n existing.forEach((adj) => {\n if (!seen.has(adj.id)) {\n em.remove(adj)\n }\n })\n}\n\nasync function replaceOrderLines(\n em: EntityManager,\n order: SalesOrder,\n calculation: SalesDocumentCalculationResult,\n lineInputs: OrderLineCreateInput[]\n): Promise<void> {\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n const statusCache = new Map<string, string | null>()\n const resolveStatus = async (entryId?: string | null) => {\n if (!entryId) return null\n if (statusCache.has(entryId)) return statusCache.get(entryId) ?? null\n const value = await resolveDictionaryEntryValue(em, entryId)\n statusCache.set(entryId, value)\n return value\n }\n for (let index = 0; index < calculation.lines.length; index += 1) {\n const lineResult = calculation.lines[index]\n const sourceLine = lineInputs[index]\n const entityInput = convertLineCalculationToEntityInput(lineResult, sourceLine, order, index)\n const statusValue = await resolveStatus(sourceLine.statusEntryId ?? null)\n const lineEntity = em.create(SalesOrderLine, {\n order,\n ...entityInput,\n reservedQuantity: '0',\n fulfilledQuantity: '0',\n invoicedQuantity: '0',\n returnedQuantity: '0',\n status: statusValue,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n const rawCustomFields = (sourceLine as any).customFields\n if (rawCustomFields !== undefined && rawCustomFields !== null) {\n const customValues =\n rawCustomFields && typeof rawCustomFields === 'object'\n ? (rawCustomFields as Record<string, unknown>)\n : {}\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: lineEntity.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(customValues),\n })\n }\n }\n}\n\nasync function replaceOrderAdjustments(\n em: EntityManager,\n order: SalesOrder,\n calculation: SalesDocumentCalculationResult,\n adjustmentInputs: OrderAdjustmentCreateInput[] | null\n): Promise<void> {\n const existing = await em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } })\n const existingMap = new Map<string, SalesOrderAdjustment>()\n existing.forEach((adj) => existingMap.set(adj.id, adj))\n const seen = new Set<string>()\n const adjustmentDrafts = calculation.adjustments\n for (let index = 0; index < adjustmentDrafts.length; index += 1) {\n const draft = adjustmentDrafts[index]\n const sourceById = adjustmentInputs?.find((adj) => (adj as any).id === draft.id) ?? null\n const source = sourceById ?? (adjustmentInputs ? adjustmentInputs[index] ?? null : null)\n const entityInput = convertAdjustmentResultToEntityInput(draft, source, order, index)\n const adjustmentId =\n (draft as any).id ??\n (source as any)?.id ??\n randomUUID()\n const existingEntity = existingMap.get(adjustmentId)\n const entity =\n existingEntity ??\n em.create(SalesOrderAdjustment, {\n id: adjustmentId,\n order,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n createdAt: new Date(),\n })\n entity.scope = entityInput.scope\n entity.kind = entityInput.kind\n entity.code = entityInput.code ?? null\n entity.label = entityInput.label ?? null\n entity.calculatorKey = entityInput.calculatorKey ?? null\n entity.promotionId = entityInput.promotionId ?? null\n entity.rate = entityInput.rate ?? '0'\n entity.amountNet = entityInput.amountNet ?? '0'\n entity.amountGross = entityInput.amountGross ?? entityInput.amountNet ?? '0'\n entity.currencyCode = entityInput.currencyCode ?? order.currencyCode\n entity.metadata = entityInput.metadata ?? null\n entity.position = entityInput.position ?? index\n entity.updatedAt = new Date()\n entity.orderLine = null\n seen.add(adjustmentId)\n if (source?.customFields !== undefined) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_adjustment,\n recordId: adjustmentId,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values:\n source.customFields && typeof source.customFields === 'object'\n ? (source.customFields as Record<string, unknown>)\n : {},\n })\n }\n em.persist(entity)\n }\n\n existing.forEach((adj) => {\n if (!seen.has(adj.id)) {\n em.remove(adj)\n }\n })\n}\n\nfunction applyQuoteTotals(\n quote: SalesQuote,\n totals: SalesDocumentCalculationResult['totals'],\n lineCount: number\n): void {\n quote.subtotalNetAmount = toNumericString(totals.subtotalNetAmount) ?? '0'\n quote.subtotalGrossAmount = toNumericString(totals.subtotalGrossAmount) ?? '0'\n quote.discountTotalAmount = toNumericString(totals.discountTotalAmount) ?? '0'\n quote.taxTotalAmount = toNumericString(totals.taxTotalAmount) ?? '0'\n quote.grandTotalNetAmount = toNumericString(totals.grandTotalNetAmount) ?? '0'\n quote.grandTotalGrossAmount = toNumericString(totals.grandTotalGrossAmount) ?? '0'\n quote.totalsSnapshot = cloneJson(totals)\n quote.lineItemCount = lineCount\n}\n\nfunction applyOrderTotals(\n order: SalesOrder,\n totals: SalesDocumentCalculationResult['totals'],\n lineCount: number\n): void {\n order.subtotalNetAmount = toNumericString(totals.subtotalNetAmount) ?? '0'\n order.subtotalGrossAmount = toNumericString(totals.subtotalGrossAmount) ?? '0'\n order.discountTotalAmount = toNumericString(totals.discountTotalAmount) ?? '0'\n order.taxTotalAmount = toNumericString(totals.taxTotalAmount) ?? '0'\n order.shippingNetAmount = toNumericString(totals.shippingNetAmount) ?? '0'\n order.shippingGrossAmount = toNumericString(totals.shippingGrossAmount) ?? '0'\n order.surchargeTotalAmount = toNumericString(totals.surchargeTotalAmount) ?? '0'\n order.grandTotalNetAmount = toNumericString(totals.grandTotalNetAmount) ?? '0'\n order.grandTotalGrossAmount = toNumericString(totals.grandTotalGrossAmount) ?? '0'\n order.paidTotalAmount = toNumericString(totals.paidTotalAmount) ?? '0'\n order.refundedTotalAmount = toNumericString(totals.refundedTotalAmount) ?? '0'\n order.outstandingAmount = toNumericString(totals.outstandingAmount) ?? '0'\n order.totalsSnapshot = cloneJson(totals)\n order.lineItemCount = lineCount\n}\n\nfunction normalizePaymentTotal(value: unknown): number {\n if (typeof value === 'number' && Number.isFinite(value)) return Math.max(value, 0)\n if (typeof value === 'string' && value.trim().length) {\n const parsed = Number(value)\n return Number.isFinite(parsed) ? Math.max(parsed, 0) : 0\n }\n return 0\n}\n\nfunction resolveExistingPaymentTotals(order: SalesOrder) {\n return {\n paidTotalAmount: normalizePaymentTotal(order.paidTotalAmount),\n refundedTotalAmount: normalizePaymentTotal(order.refundedTotalAmount),\n }\n}\n\nfunction ensureQuoteScope(ctx: Parameters<typeof ensureTenantScope>[0], organizationId: string, tenantId: string): void {\n ensureTenantScope(ctx, tenantId)\n ensureOrganizationScope(ctx, organizationId)\n}\n\nfunction ensureOrderScope(ctx: Parameters<typeof ensureTenantScope>[0], organizationId: string, tenantId: string): void {\n ensureTenantScope(ctx, tenantId)\n ensureOrganizationScope(ctx, organizationId)\n}\n\n\nfunction normalizeTagIds(tags?: Array<string | null | undefined>): string[] {\n if (!Array.isArray(tags)) return []\n const set = new Set<string>()\n tags.forEach((id) => {\n if (typeof id === 'string' && id.trim().length > 0) set.add(id.trim())\n })\n return Array.from(set)\n}\n\nasync function syncSalesDocumentTags(em: EntityManager, params: {\n documentId: string\n kind: SalesDocumentKind\n organizationId: string\n tenantId: string\n tagIds?: Array<string | null | undefined> | null\n}) {\n if (params.tagIds === undefined) return\n const tagIds = normalizeTagIds(params.tagIds)\n if (tagIds.length === 0) {\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: params.documentId, documentKind: params.kind })\n return\n }\n const tagsInScope = await em.find(SalesDocumentTag, {\n id: { $in: tagIds },\n organizationId: params.organizationId,\n tenantId: params.tenantId,\n })\n if (tagsInScope.length !== tagIds.length) {\n throw new CrudHttpError(400, { error: 'One or more tags not found for this scope' })\n }\n const byId = new Map(tagsInScope.map((tag) => [tag.id, tag]))\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: params.documentId, documentKind: params.kind })\n for (const tagId of tagIds) {\n const tag = byId.get(tagId)\n if (!tag) continue\n const assignment = em.create(SalesDocumentTagAssignment, {\n organizationId: params.organizationId,\n tenantId: params.tenantId,\n documentId: params.documentId,\n documentKind: params.kind,\n tag,\n order: params.kind === 'order' ? em.getReference(SalesOrder, params.documentId) : null,\n quote: params.kind === 'quote' ? em.getReference(SalesQuote, params.documentId) : null,\n })\n em.persist(assignment)\n }\n}\n\nfunction applyQuoteSnapshot(quote: SalesQuote, snapshot: QuoteGraphSnapshot['quote']): void {\n quote.organizationId = snapshot.organizationId\n quote.tenantId = snapshot.tenantId\n quote.quoteNumber = snapshot.quoteNumber\n quote.statusEntryId = snapshot.statusEntryId ?? null\n quote.status = snapshot.status ?? null\n quote.customerEntityId = snapshot.customerEntityId ?? null\n quote.customerContactId = snapshot.customerContactId ?? null\n quote.customerSnapshot = snapshot.customerSnapshot ? cloneJson(snapshot.customerSnapshot) : null\n quote.billingAddressId = snapshot.billingAddressId ?? null\n quote.shippingAddressId = snapshot.shippingAddressId ?? null\n quote.billingAddressSnapshot = snapshot.billingAddressSnapshot ? cloneJson(snapshot.billingAddressSnapshot) : null\n quote.shippingAddressSnapshot = snapshot.shippingAddressSnapshot\n ? cloneJson(snapshot.shippingAddressSnapshot)\n : null\n quote.currencyCode = snapshot.currencyCode\n quote.validFrom = snapshot.validFrom ? new Date(snapshot.validFrom) : null\n quote.validUntil = snapshot.validUntil ? new Date(snapshot.validUntil) : null\n quote.comments = snapshot.comments ?? null\n quote.taxInfo = snapshot.taxInfo ? cloneJson(snapshot.taxInfo) : null\n quote.shippingMethodId = snapshot.shippingMethodId ?? null\n quote.shippingMethodCode = snapshot.shippingMethodCode ?? null\n quote.deliveryWindowId = snapshot.deliveryWindowId ?? null\n quote.deliveryWindowCode = snapshot.deliveryWindowCode ?? null\n quote.paymentMethodId = snapshot.paymentMethodId ?? null\n quote.paymentMethodCode = snapshot.paymentMethodCode ?? null\n quote.shippingMethodSnapshot = snapshot.shippingMethodSnapshot ? cloneJson(snapshot.shippingMethodSnapshot) : null\n quote.deliveryWindowSnapshot = snapshot.deliveryWindowSnapshot\n ? cloneJson(snapshot.deliveryWindowSnapshot)\n : null\n quote.paymentMethodSnapshot = snapshot.paymentMethodSnapshot ? cloneJson(snapshot.paymentMethodSnapshot) : null\n quote.metadata = snapshot.metadata ? cloneJson(snapshot.metadata) : null\n quote.channelId = snapshot.channelId ?? null\n quote.customFieldSetId = snapshot.customFieldSetId ?? null\n quote.subtotalNetAmount = snapshot.subtotalNetAmount\n quote.subtotalGrossAmount = snapshot.subtotalGrossAmount\n quote.discountTotalAmount = snapshot.discountTotalAmount\n quote.taxTotalAmount = snapshot.taxTotalAmount\n quote.grandTotalNetAmount = snapshot.grandTotalNetAmount\n quote.grandTotalGrossAmount = snapshot.grandTotalGrossAmount\n quote.totalsSnapshot = snapshot.totalsSnapshot ? cloneJson(snapshot.totalsSnapshot) : null\n quote.lineItemCount = snapshot.lineItemCount\n}\n\nfunction applyOrderSnapshot(order: SalesOrder, snapshot: OrderGraphSnapshot['order']): void {\n order.organizationId = snapshot.organizationId\n order.tenantId = snapshot.tenantId\n order.orderNumber = snapshot.orderNumber\n order.statusEntryId = snapshot.statusEntryId ?? null\n order.status = snapshot.status ?? null\n order.fulfillmentStatusEntryId = snapshot.fulfillmentStatusEntryId ?? null\n order.fulfillmentStatus = snapshot.fulfillmentStatus ?? null\n order.paymentStatusEntryId = snapshot.paymentStatusEntryId ?? null\n order.paymentStatus = snapshot.paymentStatus ?? null\n order.customerEntityId = snapshot.customerEntityId ?? null\n order.customerContactId = snapshot.customerContactId ?? null\n order.customerSnapshot = snapshot.customerSnapshot ? cloneJson(snapshot.customerSnapshot) : null\n order.billingAddressId = snapshot.billingAddressId ?? null\n order.shippingAddressId = snapshot.shippingAddressId ?? null\n order.billingAddressSnapshot = snapshot.billingAddressSnapshot ? cloneJson(snapshot.billingAddressSnapshot) : null\n order.shippingAddressSnapshot = snapshot.shippingAddressSnapshot\n ? cloneJson(snapshot.shippingAddressSnapshot)\n : null\n order.currencyCode = snapshot.currencyCode\n order.exchangeRate = snapshot.exchangeRate ?? null\n order.taxStrategyKey = snapshot.taxStrategyKey ?? null\n order.discountStrategyKey = snapshot.discountStrategyKey ?? null\n order.taxInfo = snapshot.taxInfo ? cloneJson(snapshot.taxInfo) : null\n order.shippingMethodId = snapshot.shippingMethodId ?? null\n order.shippingMethodCode = snapshot.shippingMethodCode ?? null\n order.deliveryWindowId = snapshot.deliveryWindowId ?? null\n order.deliveryWindowCode = snapshot.deliveryWindowCode ?? null\n order.paymentMethodId = snapshot.paymentMethodId ?? null\n order.paymentMethodCode = snapshot.paymentMethodCode ?? null\n order.channelId = snapshot.channelId ?? null\n order.placedAt = snapshot.placedAt ? new Date(snapshot.placedAt) : null\n order.expectedDeliveryAt = snapshot.expectedDeliveryAt ? new Date(snapshot.expectedDeliveryAt) : null\n order.dueAt = snapshot.dueAt ? new Date(snapshot.dueAt) : null\n order.comments = snapshot.comments ?? null\n order.internalNotes = snapshot.internalNotes ?? null\n order.shippingMethodSnapshot = snapshot.shippingMethodSnapshot ? cloneJson(snapshot.shippingMethodSnapshot) : null\n order.deliveryWindowSnapshot = snapshot.deliveryWindowSnapshot\n ? cloneJson(snapshot.deliveryWindowSnapshot)\n : null\n order.paymentMethodSnapshot = snapshot.paymentMethodSnapshot ? cloneJson(snapshot.paymentMethodSnapshot) : null\n order.metadata = snapshot.metadata ? cloneJson(snapshot.metadata) : null\n order.customFieldSetId = snapshot.customFieldSetId ?? null\n order.subtotalNetAmount = snapshot.subtotalNetAmount\n order.subtotalGrossAmount = snapshot.subtotalGrossAmount\n order.discountTotalAmount = snapshot.discountTotalAmount\n order.taxTotalAmount = snapshot.taxTotalAmount\n order.shippingNetAmount = snapshot.shippingNetAmount\n order.shippingGrossAmount = snapshot.shippingGrossAmount\n order.surchargeTotalAmount = snapshot.surchargeTotalAmount\n order.grandTotalNetAmount = snapshot.grandTotalNetAmount\n order.grandTotalGrossAmount = snapshot.grandTotalGrossAmount\n order.paidTotalAmount = snapshot.paidTotalAmount\n order.refundedTotalAmount = snapshot.refundedTotalAmount\n order.outstandingAmount = snapshot.outstandingAmount\n order.totalsSnapshot = snapshot.totalsSnapshot ? cloneJson(snapshot.totalsSnapshot) : null\n order.lineItemCount = snapshot.lineItemCount\n}\n\nasync function restoreQuoteGraph(\n em: EntityManager,\n snapshot: QuoteGraphSnapshot\n): Promise<SalesQuote> {\n let quote = await em.findOne(SalesQuote, { id: snapshot.quote.id })\n if (!quote) {\n quote = em.create(SalesQuote, {\n id: snapshot.quote.id,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n quoteNumber: snapshot.quote.quoteNumber,\n statusEntryId: snapshot.quote.statusEntryId ?? null,\n status: snapshot.quote.status ?? null,\n customerEntityId: snapshot.quote.customerEntityId ?? null,\n customerContactId: snapshot.quote.customerContactId ?? null,\n customerSnapshot: snapshot.quote.customerSnapshot ? cloneJson(snapshot.quote.customerSnapshot) : null,\n billingAddressId: snapshot.quote.billingAddressId ?? null,\n shippingAddressId: snapshot.quote.shippingAddressId ?? null,\n billingAddressSnapshot: snapshot.quote.billingAddressSnapshot\n ? cloneJson(snapshot.quote.billingAddressSnapshot)\n : null,\n shippingAddressSnapshot: snapshot.quote.shippingAddressSnapshot\n ? cloneJson(snapshot.quote.shippingAddressSnapshot)\n : null,\n currencyCode: snapshot.quote.currencyCode,\n validFrom: snapshot.quote.validFrom ? new Date(snapshot.quote.validFrom) : null,\n validUntil: snapshot.quote.validUntil ? new Date(snapshot.quote.validUntil) : null,\n comments: snapshot.quote.comments ?? null,\n taxInfo: snapshot.quote.taxInfo ? cloneJson(snapshot.quote.taxInfo) : null,\n shippingMethodId: snapshot.quote.shippingMethodId ?? null,\n shippingMethodCode: snapshot.quote.shippingMethodCode ?? null,\n deliveryWindowId: snapshot.quote.deliveryWindowId ?? null,\n deliveryWindowCode: snapshot.quote.deliveryWindowCode ?? null,\n paymentMethodId: snapshot.quote.paymentMethodId ?? null,\n paymentMethodCode: snapshot.quote.paymentMethodCode ?? null,\n shippingMethodSnapshot: snapshot.quote.shippingMethodSnapshot\n ? cloneJson(snapshot.quote.shippingMethodSnapshot)\n : null,\n deliveryWindowSnapshot: snapshot.quote.deliveryWindowSnapshot\n ? cloneJson(snapshot.quote.deliveryWindowSnapshot)\n : null,\n paymentMethodSnapshot: snapshot.quote.paymentMethodSnapshot\n ? cloneJson(snapshot.quote.paymentMethodSnapshot)\n : null,\n metadata: snapshot.quote.metadata ? cloneJson(snapshot.quote.metadata) : null,\n channelId: snapshot.quote.channelId ?? null,\n customFieldSetId: snapshot.quote.customFieldSetId ?? null,\n subtotalNetAmount: snapshot.quote.subtotalNetAmount,\n subtotalGrossAmount: snapshot.quote.subtotalGrossAmount,\n discountTotalAmount: snapshot.quote.discountTotalAmount,\n taxTotalAmount: snapshot.quote.taxTotalAmount,\n grandTotalNetAmount: snapshot.quote.grandTotalNetAmount,\n grandTotalGrossAmount: snapshot.quote.grandTotalGrossAmount,\n totalsSnapshot: snapshot.quote.totalsSnapshot ? cloneJson(snapshot.quote.totalsSnapshot) : null,\n lineItemCount: snapshot.quote.lineItemCount,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(quote)\n }\n applyQuoteSnapshot(quote, snapshot.quote)\n const existingLines = await em.find(SalesQuoteLine, { quote: quote.id }, { fields: ['id'] })\n const existingAdjustments = await em.find(SalesQuoteAdjustment, { quote: quote.id }, { fields: ['id'] })\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_quote, recordId: quote.id })\n if (existingLines.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_quote_line,\n recordId: { $in: existingLines.map((line) => line.id) },\n })\n }\n if (existingAdjustments.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_quote_adjustment,\n recordId: { $in: existingAdjustments.map((adj) => adj.id) },\n })\n }\n const addressSnapshots = Array.isArray(snapshot.addresses) ? snapshot.addresses : []\n const noteSnapshots = Array.isArray(snapshot.notes) ? snapshot.notes : []\n const tagSnapshots = Array.isArray(snapshot.tags) ? snapshot.tags : []\n await em.nativeDelete(SalesDocumentAddress, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesNote, { contextType: 'quote', contextId: quote.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n await em.nativeDelete(SalesQuoteAdjustment, { quote: quote.id })\n\n snapshot.lines.forEach((line) => {\n const lineEntity = em.create(SalesQuoteLine, {\n id: line.id,\n quote,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n lineNumber: line.lineNumber,\n kind: line.kind as SalesLineKind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n })\n\n snapshot.adjustments.forEach((adjustment, index) => {\n const adjustmentEntity = em.create(SalesQuoteAdjustment, {\n id: adjustment.id,\n quote,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n scope: adjustment.scope,\n kind: adjustment.kind as SalesAdjustmentKind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: adjustment.rate,\n amountNet: adjustment.amountNet,\n amountGross: adjustment.amountGross,\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? index,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n adjustmentEntity.quoteLine = null\n em.persist(adjustmentEntity)\n })\n\n addressSnapshots.forEach((entry) => {\n const entity = em.create(SalesDocumentAddress, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: quote.id,\n documentKind: 'quote',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n quote,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n noteSnapshots.forEach((entry) => {\n const entity = em.create(SalesNote, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: 'quote',\n contextId: quote.id,\n order: null,\n quote,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n tagSnapshots.forEach((entry) => {\n const tag = em.getReference(SalesDocumentTag, entry.tagId)\n const assignment = em.create(SalesDocumentTagAssignment, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: quote.id,\n documentKind: 'quote',\n tag,\n quote,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(assignment)\n })\n\n if (snapshot.quote.customFields) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote,\n recordId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(snapshot.quote.customFields),\n })\n }\n for (const line of snapshot.lines) {\n if (!line.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_line,\n recordId: line.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(line.customFields),\n })\n }\n for (const adjustment of snapshot.adjustments) {\n if (!adjustment.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_quote_adjustment,\n recordId: adjustment.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n values: normalizeCustomFieldValues(adjustment.customFields),\n })\n }\n\n return quote\n}\n\nasync function restoreOrderGraph(\n em: EntityManager,\n snapshot: OrderGraphSnapshot\n): Promise<SalesOrder> {\n let order = await em.findOne(SalesOrder, { id: snapshot.order.id })\n if (!order) {\n order = em.create(SalesOrder, {\n id: snapshot.order.id,\n organizationId: snapshot.order.organizationId,\n tenantId: snapshot.order.tenantId,\n orderNumber: snapshot.order.orderNumber,\n statusEntryId: snapshot.order.statusEntryId ?? null,\n status: snapshot.order.status ?? null,\n fulfillmentStatusEntryId: snapshot.order.fulfillmentStatusEntryId ?? null,\n fulfillmentStatus: snapshot.order.fulfillmentStatus ?? null,\n paymentStatusEntryId: snapshot.order.paymentStatusEntryId ?? null,\n paymentStatus: snapshot.order.paymentStatus ?? null,\n customerEntityId: snapshot.order.customerEntityId ?? null,\n customerContactId: snapshot.order.customerContactId ?? null,\n customerSnapshot: snapshot.order.customerSnapshot ? cloneJson(snapshot.order.customerSnapshot) : null,\n billingAddressId: snapshot.order.billingAddressId ?? null,\n shippingAddressId: snapshot.order.shippingAddressId ?? null,\n billingAddressSnapshot: snapshot.order.billingAddressSnapshot\n ? cloneJson(snapshot.order.billingAddressSnapshot)\n : null,\n shippingAddressSnapshot: snapshot.order.shippingAddressSnapshot\n ? cloneJson(snapshot.order.shippingAddressSnapshot)\n : null,\n currencyCode: snapshot.order.currencyCode,\n exchangeRate: snapshot.order.exchangeRate ?? null,\n taxStrategyKey: snapshot.order.taxStrategyKey ?? null,\n discountStrategyKey: snapshot.order.discountStrategyKey ?? null,\n taxInfo: snapshot.order.taxInfo ? cloneJson(snapshot.order.taxInfo) : null,\n shippingMethodId: snapshot.order.shippingMethodId ?? null,\n shippingMethodCode: snapshot.order.shippingMethodCode ?? null,\n deliveryWindowId: snapshot.order.deliveryWindowId ?? null,\n deliveryWindowCode: snapshot.order.deliveryWindowCode ?? null,\n paymentMethodId: snapshot.order.paymentMethodId ?? null,\n paymentMethodCode: snapshot.order.paymentMethodCode ?? null,\n channelId: snapshot.order.channelId ?? null,\n placedAt: snapshot.order.placedAt ? new Date(snapshot.order.placedAt) : null,\n expectedDeliveryAt: snapshot.order.expectedDeliveryAt ? new Date(snapshot.order.expectedDeliveryAt) : null,\n dueAt: snapshot.order.dueAt ? new Date(snapshot.order.dueAt) : null,\n comments: snapshot.order.comments ?? null,\n internalNotes: snapshot.order.internalNotes ?? null,\n shippingMethodSnapshot: snapshot.order.shippingMethodSnapshot\n ? cloneJson(snapshot.order.shippingMethodSnapshot)\n : null,\n deliveryWindowSnapshot: snapshot.order.deliveryWindowSnapshot\n ? cloneJson(snapshot.order.deliveryWindowSnapshot)\n : null,\n paymentMethodSnapshot: snapshot.order.paymentMethodSnapshot\n ? cloneJson(snapshot.order.paymentMethodSnapshot)\n : null,\n metadata: snapshot.order.metadata ? cloneJson(snapshot.order.metadata) : null,\n customFieldSetId: snapshot.order.customFieldSetId ?? null,\n subtotalNetAmount: snapshot.order.subtotalNetAmount,\n subtotalGrossAmount: snapshot.order.subtotalGrossAmount,\n discountTotalAmount: snapshot.order.discountTotalAmount,\n taxTotalAmount: snapshot.order.taxTotalAmount,\n shippingNetAmount: snapshot.order.shippingNetAmount,\n shippingGrossAmount: snapshot.order.shippingGrossAmount,\n surchargeTotalAmount: snapshot.order.surchargeTotalAmount,\n grandTotalNetAmount: snapshot.order.grandTotalNetAmount,\n grandTotalGrossAmount: snapshot.order.grandTotalGrossAmount,\n paidTotalAmount: snapshot.order.paidTotalAmount,\n refundedTotalAmount: snapshot.order.refundedTotalAmount,\n outstandingAmount: snapshot.order.outstandingAmount,\n totalsSnapshot: snapshot.order.totalsSnapshot ? cloneJson(snapshot.order.totalsSnapshot) : null,\n lineItemCount: snapshot.order.lineItemCount,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n }\n applyOrderSnapshot(order, snapshot.order)\n const existingLines = await em.find(SalesOrderLine, { order: order.id }, { fields: ['id'] })\n const existingAdjustments = await em.find(SalesOrderAdjustment, { order: order.id }, { fields: ['id'] })\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_order, recordId: order.id })\n if (existingLines.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_order_line,\n recordId: { $in: existingLines.map((line) => line.id) },\n })\n }\n if (existingAdjustments.length) {\n await em.nativeDelete(CustomFieldValue, {\n entityId: E.sales.sales_order_adjustment,\n recordId: { $in: existingAdjustments.map((adj) => adj.id) },\n })\n }\n const addressSnapshots = Array.isArray(snapshot.addresses) ? snapshot.addresses : []\n const noteSnapshots = Array.isArray(snapshot.notes) ? snapshot.notes : []\n const tagSnapshots = Array.isArray(snapshot.tags) ? snapshot.tags : []\n const shipmentSnapshots = Array.isArray(snapshot.shipments) ? snapshot.shipments : []\n const paymentSnapshots = Array.isArray(snapshot.payments) ? snapshot.payments : []\n const existingShipments = await em.find(SalesShipment, { order: order.id })\n const shipmentIds = existingShipments.map((entry) => entry.id)\n if (shipmentIds.length) {\n await em.nativeDelete(SalesShipmentItem, { shipment: { $in: shipmentIds } })\n await em.nativeDelete(SalesShipment, { id: { $in: shipmentIds } })\n existingShipments.forEach((entry) => em.getUnitOfWork().unsetIdentity(entry))\n }\n await em.nativeDelete(SalesPaymentAllocation, { order: order.id })\n await em.nativeDelete(SalesPayment, { order: order.id })\n await em.nativeDelete(SalesDocumentAddress, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesNote, { contextType: 'order', contextId: order.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesOrderAdjustment, { order: order.id })\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n\n snapshot.lines.forEach((line) => {\n const lineEntity = em.create(SalesOrderLine, {\n id: line.id,\n order,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n lineNumber: line.lineNumber,\n kind: line.kind as SalesLineKind,\n statusEntryId: line.statusEntryId ?? null,\n status: line.status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n reservedQuantity: line.reservedQuantity,\n fulfilledQuantity: line.fulfilledQuantity,\n invoicedQuantity: line.invoicedQuantity,\n returnedQuantity: line.returnedQuantity,\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(lineEntity)\n })\n\n snapshot.adjustments.forEach((adjustment, index) => {\n const adjustmentEntity = em.create(SalesOrderAdjustment, {\n id: adjustment.id,\n order,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n scope: adjustment.scope,\n kind: adjustment.kind as SalesAdjustmentKind,\n code: adjustment.code ?? null,\n label: adjustment.label ?? null,\n calculatorKey: adjustment.calculatorKey ?? null,\n promotionId: adjustment.promotionId ?? null,\n rate: adjustment.rate,\n amountNet: adjustment.amountNet,\n amountGross: adjustment.amountGross,\n currencyCode: adjustment.currencyCode ?? null,\n metadata: adjustment.metadata ? cloneJson(adjustment.metadata) : null,\n position: adjustment.position ?? index,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n adjustmentEntity.orderLine = null\n em.persist(adjustmentEntity)\n })\n\n addressSnapshots.forEach((entry) => {\n const entity = em.create(SalesDocumentAddress, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: order.id,\n documentKind: 'order',\n customerAddressId: entry.customerAddressId ?? null,\n name: entry.name ?? null,\n purpose: entry.purpose ?? null,\n companyName: entry.companyName ?? null,\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 buildingNumber: entry.buildingNumber ?? null,\n flatNumber: entry.flatNumber ?? null,\n latitude: entry.latitude ?? null,\n longitude: entry.longitude ?? null,\n order,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n noteSnapshots.forEach((entry) => {\n const entity = em.create(SalesNote, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n contextType: 'order',\n contextId: order.id,\n order,\n quote: null,\n body: entry.body,\n authorUserId: entry.authorUserId ?? null,\n appearanceIcon: entry.appearanceIcon ?? null,\n appearanceColor: entry.appearanceColor ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n tagSnapshots.forEach((entry) => {\n const tag = em.getReference(SalesDocumentTag, entry.tagId)\n const assignment = em.create(SalesDocumentTagAssignment, {\n id: entry.id,\n organizationId: entry.organizationId,\n tenantId: entry.tenantId,\n documentId: order.id,\n documentKind: 'order',\n tag,\n order,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(assignment)\n })\n\n if (snapshot.order.customFields) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order,\n recordId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(snapshot.order.customFields),\n })\n }\n for (const line of snapshot.lines) {\n if (!line.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: line.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(line.customFields),\n })\n }\n for (const adjustment of snapshot.adjustments) {\n if (!adjustment.customFields) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_adjustment,\n recordId: adjustment.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n values: normalizeCustomFieldValues(adjustment.customFields),\n })\n }\n\n for (const shipment of shipmentSnapshots) {\n await restoreShipmentSnapshot(em, shipment)\n }\n\n for (const payment of paymentSnapshots) {\n await restorePaymentSnapshot(em, payment)\n }\n\n return order\n}\n\nconst createQuoteCommand: CommandHandler<QuoteCreateInput, { quoteId: string }> = {\n id: 'sales.quotes.create',\n async execute(rawInput, ctx) {\n const generator = ctx.container.resolve('salesDocumentNumberGenerator') as SalesDocumentNumberGenerator\n const initial = quoteCreateSchema.parse(rawInput ?? {})\n const quoteNumber =\n typeof initial.quoteNumber === 'string' && initial.quoteNumber.trim().length\n ? initial.quoteNumber.trim()\n : (\n await generator.generate({\n kind: 'quote',\n organizationId: initial.organizationId,\n tenantId: initial.tenantId,\n })\n ).number\n const parsed = quoteCreateSchema.parse({ ...initial, quoteNumber })\n const ensuredQuoteNumber = parsed.quoteNumber ?? quoteNumber\n if (!ensuredQuoteNumber) {\n throw new CrudHttpError(400, { error: 'Quote number is required.' })\n }\n ensureQuoteScope(ctx, parsed.organizationId, parsed.tenantId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const {\n customerSnapshot: resolvedCustomerSnapshot,\n billingAddressSnapshot: resolvedBillingSnapshot,\n shippingAddressSnapshot: resolvedShippingSnapshot,\n shippingMethod,\n deliveryWindow,\n paymentMethod,\n } = await resolveDocumentReferences(em, parsed)\n const quoteStatus = await resolveDictionaryEntryValue(em, parsed.statusEntryId ?? null)\n const quote = em.create(SalesQuote, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n quoteNumber: ensuredQuoteNumber,\n statusEntryId: parsed.statusEntryId ?? null,\n status: quoteStatus,\n customerEntityId: parsed.customerEntityId ?? null,\n customerContactId: parsed.customerContactId ?? null,\n customerSnapshot: resolvedCustomerSnapshot ? cloneJson(resolvedCustomerSnapshot) : null,\n billingAddressId: parsed.billingAddressId ?? null,\n shippingAddressId: parsed.shippingAddressId ?? null,\n billingAddressSnapshot: resolvedBillingSnapshot ? cloneJson(resolvedBillingSnapshot) : null,\n shippingAddressSnapshot: resolvedShippingSnapshot ? cloneJson(resolvedShippingSnapshot) : null,\n currencyCode: parsed.currencyCode,\n validFrom: parsed.validFrom ?? null,\n validUntil: parsed.validUntil ?? null,\n comments: parsed.comments ?? null,\n taxInfo: parsed.taxInfo ? cloneJson(parsed.taxInfo) : null,\n shippingMethodId: parsed.shippingMethodId ?? null,\n shippingMethod: shippingMethod ?? null,\n shippingMethodCode: parsed.shippingMethodCode ?? shippingMethod?.code ?? null,\n deliveryWindowId: parsed.deliveryWindowId ?? null,\n deliveryWindow: deliveryWindow ?? null,\n deliveryWindowCode: parsed.deliveryWindowCode ?? deliveryWindow?.code ?? null,\n paymentMethodId: parsed.paymentMethodId ?? null,\n paymentMethod: paymentMethod ?? null,\n paymentMethodCode: parsed.paymentMethodCode ?? paymentMethod?.code ?? null,\n shippingMethodSnapshot: parsed.shippingMethodSnapshot\n ? cloneJson(parsed.shippingMethodSnapshot)\n : shippingMethod\n ? {\n id: shippingMethod.id,\n code: shippingMethod.code,\n name: shippingMethod.name,\n description: shippingMethod.description ?? null,\n carrierCode: shippingMethod.carrierCode ?? null,\n providerKey: shippingMethod.providerKey ?? null,\n serviceLevel: shippingMethod.serviceLevel ?? null,\n estimatedTransitDays: shippingMethod.estimatedTransitDays ?? null,\n baseRateNet: shippingMethod.baseRateNet,\n baseRateGross: shippingMethod.baseRateGross,\n currencyCode: shippingMethod.currencyCode ?? null,\n metadata: shippingMethod.metadata ? cloneJson(shippingMethod.metadata) : null,\n providerSettings:\n shippingMethod.metadata && typeof shippingMethod.metadata === 'object'\n ? cloneJson(\n (shippingMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n deliveryWindowSnapshot: parsed.deliveryWindowSnapshot\n ? cloneJson(parsed.deliveryWindowSnapshot)\n : deliveryWindow\n ? {\n id: deliveryWindow.id,\n code: deliveryWindow.code,\n name: deliveryWindow.name,\n description: deliveryWindow.description ?? null,\n leadTimeDays: deliveryWindow.leadTimeDays ?? null,\n cutoffTime: deliveryWindow.cutoffTime ?? null,\n timezone: deliveryWindow.timezone ?? null,\n }\n : null,\n paymentMethodSnapshot: parsed.paymentMethodSnapshot\n ? cloneJson(parsed.paymentMethodSnapshot)\n : paymentMethod\n ? {\n id: paymentMethod.id,\n code: paymentMethod.code,\n name: paymentMethod.name,\n description: paymentMethod.description ?? null,\n providerKey: paymentMethod.providerKey ?? null,\n terms: paymentMethod.terms ?? null,\n metadata: paymentMethod.metadata ? cloneJson(paymentMethod.metadata) : null,\n providerSettings:\n paymentMethod.metadata && typeof paymentMethod.metadata === 'object'\n ? cloneJson(\n (paymentMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n metadata: parsed.metadata ? cloneJson(parsed.metadata) : null,\n channelId: parsed.channelId ?? null,\n customFieldSetId: parsed.customFieldSetId ?? null,\n subtotalNetAmount: '0',\n subtotalGrossAmount: '0',\n discountTotalAmount: '0',\n taxTotalAmount: '0',\n grandTotalNetAmount: '0',\n grandTotalGrossAmount: '0',\n lineItemCount: 0,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(quote)\n\n const lineInputs = (parsed.lines ?? []).map((line, index) =>\n quoteLineCreateSchema.parse({\n ...line,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n })\n )\n const adjustmentInputs = parsed.adjustments\n ? parsed.adjustments.map((adj) =>\n quoteAdjustmentCreateSchema.parse({\n ...adj,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n quoteId: quote.id,\n })\n )\n : null\n\n const lineSnapshots: SalesLineSnapshot[] = lineInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts: SalesAdjustmentDraft[] = adjustmentInputs\n ? adjustmentInputs.map((adj) => createAdjustmentDraftFromInput(adj))\n : []\n\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n\n await replaceQuoteLines(em, quote, calculation, lineInputs)\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await syncSalesDocumentTags(em, {\n documentId: quote.id,\n kind: 'quote',\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n tagIds: parsed.tags,\n })\n await em.flush()\n\n // Emit CRUD side effects to trigger workflow event listeners\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: quote,\n identifiers: {\n id: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n },\n events: quoteCrudEvents,\n indexer: { entityType: E.sales.sales_quote },\n })\n\n // Invalidate cache\n const resourceKind = deriveResourceFromCommandId(createQuoteCommand.id) ?? 'sales.quote'\n await invalidateCrudCache(\n ctx.container,\n resourceKind,\n { id: quote.id, organizationId: quote.organizationId, tenantId: quote.tenantId },\n ctx.auth?.tenantId ?? null,\n 'created'\n )\n\n return { quoteId: quote.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.create', 'Create sales quote'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotAfter: after,\n payload: {\n undo: {\n after,\n } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: after.quote.id })\n if (!quote) return\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n await em.nativeDelete(SalesQuoteAdjustment, { quote: quote.id })\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n em.remove(quote)\n await em.flush()\n },\n}\n\nconst deleteQuoteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string }\n> = {\n id: 'sales.quotes.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Quote id is required')\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadQuoteSnapshot(em, id)\n if (snapshot) {\n ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Quote id is required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const [addresses, notes, tags, adjustments, lines] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: quote.id, documentKind: 'quote' }),\n em.find(SalesNote, { contextType: 'quote', contextId: quote.id }),\n em.find(SalesDocumentTagAssignment, { documentId: quote.id, documentKind: 'quote' }),\n em.find(SalesQuoteAdjustment, { quote: quote.id }),\n em.find(SalesQuoteLine, { quote: quote.id }),\n ])\n await em.nativeDelete(SalesDocumentAddress, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesNote, { contextType: 'quote', contextId: quote.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: quote.id, documentKind: 'quote' })\n await em.nativeDelete(SalesQuoteAdjustment, { quote: quote.id })\n await em.nativeDelete(SalesQuoteLine, { quote: quote.id })\n em.remove(quote)\n await em.flush()\n const dataEngine = ctx.container.resolve<DataEngine>('dataEngine')\n await Promise.all([\n queueDeletionSideEffects(dataEngine, quote, E.sales.sales_quote),\n queueDeletionSideEffects(dataEngine, lines, E.sales.sales_quote_line),\n queueDeletionSideEffects(dataEngine, adjustments, E.sales.sales_quote_adjustment),\n queueDeletionSideEffects(dataEngine, addresses, E.sales.sales_document_address),\n queueDeletionSideEffects(dataEngine, notes, E.sales.sales_note),\n queueDeletionSideEffects(dataEngine, tags, E.sales.sales_document_tag_assignment),\n ])\n return { quoteId: id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.delete', 'Delete sales quote'),\n resourceKind: 'sales.quote',\n resourceId: before.quote.id,\n tenantId: before.quote.tenantId,\n organizationId: before.quote.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst updateQuoteCommand: CommandHandler<DocumentUpdateInput, { quote: SalesQuote }> = {\n id: 'sales.quotes.update',\n async prepare(input, ctx) {\n const parsed = documentUpdateSchema.parse(input ?? {})\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadQuoteSnapshot(em, parsed.id)\n if (snapshot) {\n ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = documentUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.id, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const shouldInvalidateSentToken = (quote.status ?? null) === 'sent'\n if (shouldInvalidateSentToken) {\n quote.acceptanceToken = null\n quote.sentAt = null\n }\n const shouldRecalculateTotals =\n parsed.shippingMethodId !== undefined ||\n parsed.shippingMethodSnapshot !== undefined ||\n parsed.shippingMethodCode !== undefined ||\n parsed.paymentMethodId !== undefined ||\n parsed.paymentMethodSnapshot !== undefined ||\n parsed.paymentMethodCode !== undefined ||\n parsed.currencyCode !== undefined\n await applyDocumentUpdate({ kind: 'quote', entity: quote, input: parsed, em })\n if (shouldInvalidateSentToken) {\n quote.status = 'draft'\n quote.statusEntryId = await resolveStatusEntryIdByValue(em, {\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n value: 'draft',\n })\n }\n if (shouldRecalculateTotals) {\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = adjustments.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? quote.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n }\n quote.updatedAt = new Date()\n await em.flush()\n const resourceKind = deriveResourceFromCommandId(updateQuoteCommand.id) ?? 'sales.quote'\n await invalidateCrudCache(\n ctx.container,\n resourceKind,\n { id: quote.id, organizationId: quote.organizationId, tenantId: quote.tenantId },\n ctx.auth?.tenantId ?? null,\n 'updated'\n )\n return { quote }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadQuoteSnapshot(em, result.quote.id)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.update', 'Update sales quote'),\n resourceKind: 'sales.quote',\n resourceId: result.quote.id,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: {\n before,\n after,\n } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst updateOrderCommand: CommandHandler<DocumentUpdateInput, { order: SalesOrder }> = {\n id: 'sales.orders.update',\n async prepare(input, ctx) {\n const parsed = documentUpdateSchema.parse(input ?? {})\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadOrderSnapshot(em, parsed.id)\n if (snapshot) {\n ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = documentUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.id, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n const previousStatus = normalizeStatusValue(order.status)\n let statusChangeNote: SalesNote | null = null\n const shouldRecalculateTotals =\n parsed.shippingMethodId !== undefined ||\n parsed.shippingMethodSnapshot !== undefined ||\n parsed.shippingMethodCode !== undefined ||\n parsed.paymentMethodId !== undefined ||\n parsed.paymentMethodSnapshot !== undefined ||\n parsed.paymentMethodCode !== undefined ||\n parsed.currencyCode !== undefined\n await applyDocumentUpdate({ kind: 'order', entity: order, input: parsed, em })\n if (shouldRecalculateTotals) {\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = adjustments.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? order.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n }\n statusChangeNote = await appendOrderStatusChangeNote({\n em,\n order,\n previousStatus,\n auth: ctx.auth ?? null,\n })\n order.updatedAt = new Date()\n await em.flush()\n if (statusChangeNote) {\n const dataEngine = ctx.container.resolve('dataEngine')\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: statusChangeNote,\n identifiers: {\n id: statusChangeNote.id,\n organizationId: statusChangeNote.organizationId,\n tenantId: statusChangeNote.tenantId,\n },\n indexer: { entityType: E.sales.sales_note },\n })\n }\n const resourceKind = deriveResourceFromCommandId(updateOrderCommand.id) ?? 'sales.order'\n await invalidateCrudCache(\n ctx.container,\n resourceKind,\n { id: order.id, organizationId: order.organizationId, tenantId: order.tenantId },\n ctx.auth?.tenantId ?? null,\n 'updated'\n )\n return { order }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadOrderSnapshot(em, result.order.id)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.update', 'Update sales order'),\n resourceKind: 'sales.order',\n resourceId: result.order.id,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: {\n before,\n after,\n } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst createOrderCommand: CommandHandler<OrderCreateInput, { orderId: string }> = {\n id: 'sales.orders.create',\n async execute(rawInput, ctx) {\n const generator = ctx.container.resolve('salesDocumentNumberGenerator') as SalesDocumentNumberGenerator\n const initial = orderCreateSchema.parse(rawInput ?? {})\n const orderNumber =\n typeof initial.orderNumber === 'string' && initial.orderNumber.trim().length\n ? initial.orderNumber.trim()\n : (\n await generator.generate({\n kind: 'order',\n organizationId: initial.organizationId,\n tenantId: initial.tenantId,\n })\n ).number\n const parsed = orderCreateSchema.parse({ ...initial, orderNumber })\n const ensuredOrderNumber = parsed.orderNumber ?? orderNumber\n if (!ensuredOrderNumber) {\n throw new CrudHttpError(400, { error: 'Order number is required.' })\n }\n ensureOrderScope(ctx, parsed.organizationId, parsed.tenantId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const [status, fulfillmentStatus, paymentStatus] = await Promise.all([\n resolveDictionaryEntryValue(em, parsed.statusEntryId ?? null),\n resolveDictionaryEntryValue(em, parsed.fulfillmentStatusEntryId ?? null),\n resolveDictionaryEntryValue(em, parsed.paymentStatusEntryId ?? null),\n ])\n const {\n customerSnapshot: resolvedCustomerSnapshot,\n billingAddressSnapshot: resolvedBillingSnapshot,\n shippingAddressSnapshot: resolvedShippingSnapshot,\n shippingMethod,\n deliveryWindow,\n paymentMethod,\n } = await resolveDocumentReferences(em, parsed)\n\n const order = em.create(SalesOrder, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n orderNumber: ensuredOrderNumber,\n statusEntryId: parsed.statusEntryId ?? null,\n status,\n fulfillmentStatusEntryId: parsed.fulfillmentStatusEntryId ?? null,\n fulfillmentStatus,\n paymentStatusEntryId: parsed.paymentStatusEntryId ?? null,\n paymentStatus,\n customerEntityId: parsed.customerEntityId ?? null,\n customerContactId: parsed.customerContactId ?? null,\n customerSnapshot: resolvedCustomerSnapshot ? cloneJson(resolvedCustomerSnapshot) : null,\n billingAddressId: parsed.billingAddressId ?? null,\n shippingAddressId: parsed.shippingAddressId ?? null,\n billingAddressSnapshot: resolvedBillingSnapshot ? cloneJson(resolvedBillingSnapshot) : null,\n shippingAddressSnapshot: resolvedShippingSnapshot ? cloneJson(resolvedShippingSnapshot) : null,\n currencyCode: parsed.currencyCode,\n exchangeRate:\n typeof parsed.exchangeRate === 'number' ? toNumericString(parsed.exchangeRate) : null,\n taxStrategyKey: parsed.taxStrategyKey ?? null,\n discountStrategyKey: parsed.discountStrategyKey ?? null,\n taxInfo: parsed.taxInfo ? cloneJson(parsed.taxInfo) : null,\n shippingMethodId: parsed.shippingMethodId ?? null,\n shippingMethod: shippingMethod ?? null,\n shippingMethodCode: parsed.shippingMethodCode ?? shippingMethod?.code ?? null,\n deliveryWindowId: parsed.deliveryWindowId ?? null,\n deliveryWindow: deliveryWindow ?? null,\n deliveryWindowCode: parsed.deliveryWindowCode ?? deliveryWindow?.code ?? null,\n paymentMethodId: parsed.paymentMethodId ?? null,\n paymentMethod: paymentMethod ?? null,\n paymentMethodCode: parsed.paymentMethodCode ?? paymentMethod?.code ?? null,\n channelId: parsed.channelId ?? null,\n placedAt: parsed.placedAt ?? null,\n expectedDeliveryAt: parsed.expectedDeliveryAt ?? null,\n dueAt: parsed.dueAt ?? null,\n comments: parsed.comments ?? null,\n internalNotes: parsed.internalNotes ?? null,\n shippingMethodSnapshot: parsed.shippingMethodSnapshot\n ? cloneJson(parsed.shippingMethodSnapshot)\n : shippingMethod\n ? {\n id: shippingMethod.id,\n code: shippingMethod.code,\n name: shippingMethod.name,\n description: shippingMethod.description ?? null,\n carrierCode: shippingMethod.carrierCode ?? null,\n providerKey: shippingMethod.providerKey ?? null,\n serviceLevel: shippingMethod.serviceLevel ?? null,\n estimatedTransitDays: shippingMethod.estimatedTransitDays ?? null,\n baseRateNet: shippingMethod.baseRateNet,\n baseRateGross: shippingMethod.baseRateGross,\n currencyCode: shippingMethod.currencyCode ?? null,\n metadata: shippingMethod.metadata ? cloneJson(shippingMethod.metadata) : null,\n providerSettings:\n shippingMethod.metadata && typeof shippingMethod.metadata === 'object'\n ? cloneJson(\n (shippingMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n deliveryWindowSnapshot: parsed.deliveryWindowSnapshot\n ? cloneJson(parsed.deliveryWindowSnapshot)\n : deliveryWindow\n ? {\n id: deliveryWindow.id,\n code: deliveryWindow.code,\n name: deliveryWindow.name,\n description: deliveryWindow.description ?? null,\n leadTimeDays: deliveryWindow.leadTimeDays ?? null,\n cutoffTime: deliveryWindow.cutoffTime ?? null,\n timezone: deliveryWindow.timezone ?? null,\n }\n : null,\n paymentMethodSnapshot: parsed.paymentMethodSnapshot\n ? cloneJson(parsed.paymentMethodSnapshot)\n : paymentMethod\n ? {\n id: paymentMethod.id,\n code: paymentMethod.code,\n name: paymentMethod.name,\n description: paymentMethod.description ?? null,\n providerKey: paymentMethod.providerKey ?? null,\n terms: paymentMethod.terms ?? null,\n metadata: paymentMethod.metadata ? cloneJson(paymentMethod.metadata) : null,\n providerSettings:\n paymentMethod.metadata && typeof paymentMethod.metadata === 'object'\n ? cloneJson(\n (paymentMethod.metadata as Record<string, unknown>).providerSettings ?? null\n )\n : null,\n }\n : null,\n metadata: parsed.metadata ? cloneJson(parsed.metadata) : null,\n customFieldSetId: parsed.customFieldSetId ?? null,\n subtotalNetAmount: '0',\n subtotalGrossAmount: '0',\n discountTotalAmount: '0',\n taxTotalAmount: '0',\n shippingNetAmount: '0',\n shippingGrossAmount: '0',\n surchargeTotalAmount: '0',\n grandTotalNetAmount: '0',\n grandTotalGrossAmount: '0',\n paidTotalAmount: '0',\n refundedTotalAmount: '0',\n outstandingAmount: '0',\n lineItemCount: 0,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n\n const lineInputs = (parsed.lines ?? []).map((line, index) =>\n orderLineCreateSchema.parse({\n ...line,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n })\n )\n const adjustmentInputs = parsed.adjustments\n ? parsed.adjustments.map((adj) =>\n orderAdjustmentCreateSchema.parse({\n ...adj,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n orderId: order.id,\n })\n )\n : null\n\n const lineSnapshots: SalesLineSnapshot[] = lineInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts: SalesAdjustmentDraft[] = adjustmentInputs\n ? adjustmentInputs.map((adj) => createAdjustmentDraftFromInput(adj))\n : []\n\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: lineSnapshots,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n\n await replaceOrderLines(em, order, calculation, lineInputs)\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await syncSalesDocumentTags(em, {\n documentId: order.id,\n kind: 'order',\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n tagIds: parsed.tags,\n })\n await em.flush()\n\n // Emit CRUD side effects to trigger workflow event listeners\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: order,\n identifiers: {\n id: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n },\n events: orderCrudEvents,\n indexer: { entityType: E.sales.sales_order },\n })\n\n // Invalidate cache\n const resourceKind = deriveResourceFromCommandId(createOrderCommand.id) ?? 'sales.order'\n await invalidateCrudCache(\n ctx.container,\n resourceKind,\n { id: order.id, organizationId: order.organizationId, tenantId: order.tenantId },\n ctx.auth?.tenantId ?? null,\n 'created'\n )\n\n return { orderId: order.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ result, snapshots }) => {\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.create', 'Create sales order'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotAfter: after,\n payload: {\n undo: {\n after,\n } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: after.order.id })\n if (!order) return\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n await em.nativeDelete(SalesOrderAdjustment, { order: order.id })\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n em.remove(order)\n await em.flush()\n },\n}\n\nconst deleteOrderCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string }\n> = {\n id: 'sales.orders.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Order id is required')\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadOrderSnapshot(em, id)\n if (snapshot) {\n ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n }\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Order id is required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n const shipments = await em.find(SalesShipment, { order: order.id })\n const shipmentIds = shipments.map((entry) => entry.id)\n const [shipmentItems, payments, paymentAllocations, addresses, notes, tags, adjustments, lines] = await Promise.all([\n shipmentIds.length ? em.find(SalesShipmentItem, { shipment: { $in: shipmentIds } }) : Promise.resolve([]),\n em.find(SalesPayment, { order: order.id }),\n em.find(SalesPaymentAllocation, { order: order.id }),\n em.find(SalesDocumentAddress, { documentId: order.id, documentKind: 'order' }),\n em.find(SalesNote, { contextType: 'order', contextId: order.id }),\n em.find(SalesDocumentTagAssignment, { documentId: order.id, documentKind: 'order' }),\n em.find(SalesOrderAdjustment, { order: order.id }),\n em.find(SalesOrderLine, { order: order.id }),\n ])\n if (shipmentIds.length) {\n await em.nativeDelete(SalesShipmentItem, { shipment: { $in: shipmentIds } })\n await em.nativeDelete(SalesShipment, { id: { $in: shipmentIds } })\n }\n await em.nativeDelete(SalesPaymentAllocation, { order: order.id })\n await em.nativeDelete(SalesPayment, { order: order.id })\n await em.nativeDelete(SalesDocumentAddress, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesNote, { contextType: 'order', contextId: order.id })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: order.id, documentKind: 'order' })\n await em.nativeDelete(SalesOrderAdjustment, { order: order.id })\n await em.nativeDelete(SalesOrderLine, { order: order.id })\n em.remove(order)\n await em.flush()\n const dataEngine = ctx.container.resolve<DataEngine>('dataEngine')\n await Promise.all([\n queueDeletionSideEffects(dataEngine, order, E.sales.sales_order),\n queueDeletionSideEffects(dataEngine, lines, E.sales.sales_order_line),\n queueDeletionSideEffects(dataEngine, adjustments, E.sales.sales_order_adjustment),\n queueDeletionSideEffects(dataEngine, shipments, E.sales.sales_shipment),\n queueDeletionSideEffects(dataEngine, shipmentItems, E.sales.sales_shipment_item),\n queueDeletionSideEffects(dataEngine, payments, E.sales.sales_payment),\n queueDeletionSideEffects(dataEngine, paymentAllocations, E.sales.sales_payment_allocation),\n queueDeletionSideEffects(dataEngine, addresses, E.sales.sales_document_address),\n queueDeletionSideEffects(dataEngine, notes, E.sales.sales_note),\n queueDeletionSideEffects(dataEngine, tags, E.sales.sales_document_tag_assignment),\n ])\n return { orderId: id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.delete', 'Delete sales order'),\n resourceKind: 'sales.order',\n resourceId: before.order.id,\n tenantId: before.order.tenantId,\n organizationId: before.order.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteConvertToOrderSchema = z.object({\n quoteId: z.string().uuid(),\n orderId: z.string().uuid().optional(),\n orderNumber: z.string().trim().max(191).optional(),\n})\n\nconst convertQuoteToOrderCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string }\n> = {\n id: 'sales.quotes.convert_to_order',\n async prepare(input, ctx) {\n const parsed = quoteConvertToOrderSchema.safeParse(input ?? {})\n const quoteId = parsed.success ? parsed.data.quoteId : typeof (input as any)?.quoteId === 'string' ? (input as any).quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const payload = quoteConvertToOrderSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: payload.quoteId, deletedAt: null })\n const { translate } = await resolveTranslations()\n if (!quote) throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const snapshot = await loadQuoteSnapshot(em, payload.quoteId)\n if (!snapshot) throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n const orderId = payload.orderId ?? quote.id\n const existingOrder = await em.findOne(SalesOrder, { id: orderId, deletedAt: null })\n if (existingOrder) {\n throw new CrudHttpError(409, { error: translate('sales.documents.detail.convertExists', 'Order already exists for this quote.') })\n }\n\n const generator = ctx.container.resolve('salesDocumentNumberGenerator') as SalesDocumentNumberGenerator\n const generatedNumber =\n snapshot.quote.quoteNumber && snapshot.quote.quoteNumber.trim().length\n ? snapshot.quote.quoteNumber\n : (\n await generator.generate({\n kind: 'order',\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n })\n ).number\n const orderNumber =\n typeof payload.orderNumber === 'string' && payload.orderNumber.trim().length\n ? payload.orderNumber.trim()\n : generatedNumber\n\n const [quoteCustomFields, quoteLineCustomFields] = await Promise.all([\n loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote,\n recordIds: [snapshot.quote.id],\n tenantIdByRecord: { [snapshot.quote.id]: snapshot.quote.tenantId },\n organizationIdByRecord: { [snapshot.quote.id]: snapshot.quote.organizationId },\n }),\n snapshot.lines.length\n ? loadCustomFieldValues({\n em,\n entityId: E.sales.sales_quote_line,\n recordIds: snapshot.lines.map((line) => line.id),\n tenantIdByRecord: Object.fromEntries(snapshot.lines.map((line) => [line.id, snapshot.quote.tenantId])),\n organizationIdByRecord: Object.fromEntries(snapshot.lines.map((line) => [line.id, snapshot.quote.organizationId])),\n })\n : Promise.resolve({}),\n ])\n\n const order = em.create(SalesOrder, {\n id: orderId,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n orderNumber,\n statusEntryId: snapshot.quote.statusEntryId ?? null,\n status: snapshot.quote.status ?? null,\n fulfillmentStatusEntryId: null,\n fulfillmentStatus: null,\n paymentStatusEntryId: null,\n paymentStatus: null,\n customerEntityId: snapshot.quote.customerEntityId ?? null,\n customerContactId: snapshot.quote.customerContactId ?? null,\n customerSnapshot: snapshot.quote.customerSnapshot ? cloneJson(snapshot.quote.customerSnapshot) : null,\n billingAddressId: snapshot.quote.billingAddressId ?? null,\n shippingAddressId: snapshot.quote.shippingAddressId ?? null,\n billingAddressSnapshot: snapshot.quote.billingAddressSnapshot ? cloneJson(snapshot.quote.billingAddressSnapshot) : null,\n shippingAddressSnapshot: snapshot.quote.shippingAddressSnapshot ? cloneJson(snapshot.quote.shippingAddressSnapshot) : null,\n currencyCode: snapshot.quote.currencyCode,\n exchangeRate: null,\n taxStrategyKey: null,\n discountStrategyKey: null,\n taxInfo: snapshot.quote.taxInfo ? cloneJson(snapshot.quote.taxInfo) : null,\n shippingMethodId: snapshot.quote.shippingMethodId ?? null,\n shippingMethodCode: snapshot.quote.shippingMethodCode ?? null,\n deliveryWindowId: snapshot.quote.deliveryWindowId ?? null,\n deliveryWindowCode: snapshot.quote.deliveryWindowCode ?? null,\n paymentMethodId: snapshot.quote.paymentMethodId ?? null,\n paymentMethodCode: snapshot.quote.paymentMethodCode ?? null,\n channelId: snapshot.quote.channelId ?? null,\n placedAt: snapshot.quote.validFrom ? new Date(snapshot.quote.validFrom) : quote.createdAt,\n expectedDeliveryAt: snapshot.quote.validUntil ? new Date(snapshot.quote.validUntil) : null,\n dueAt: null,\n comments: snapshot.quote.comments ?? null,\n internalNotes: null,\n shippingMethodSnapshot: snapshot.quote.shippingMethodSnapshot ? cloneJson(snapshot.quote.shippingMethodSnapshot) : null,\n deliveryWindowSnapshot: snapshot.quote.deliveryWindowSnapshot ? cloneJson(snapshot.quote.deliveryWindowSnapshot) : null,\n paymentMethodSnapshot: snapshot.quote.paymentMethodSnapshot ? cloneJson(snapshot.quote.paymentMethodSnapshot) : null,\n metadata: snapshot.quote.metadata ? cloneJson(snapshot.quote.metadata) : null,\n customFieldSetId: snapshot.quote.customFieldSetId ?? null,\n subtotalNetAmount: snapshot.quote.subtotalNetAmount,\n subtotalGrossAmount: snapshot.quote.subtotalGrossAmount,\n discountTotalAmount: snapshot.quote.discountTotalAmount,\n taxTotalAmount: snapshot.quote.taxTotalAmount,\n shippingNetAmount: '0',\n shippingGrossAmount: '0',\n surchargeTotalAmount: '0',\n grandTotalNetAmount: snapshot.quote.grandTotalNetAmount,\n grandTotalGrossAmount: snapshot.quote.grandTotalGrossAmount,\n paidTotalAmount: '0',\n refundedTotalAmount: '0',\n outstandingAmount: snapshot.quote.grandTotalGrossAmount,\n totalsSnapshot: snapshot.quote.totalsSnapshot ? cloneJson(snapshot.quote.totalsSnapshot) : null,\n lineItemCount: snapshot.quote.lineItemCount,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(order)\n\n const orderLineMap = new Map<string, SalesOrderLine>()\n snapshot.lines.forEach((line, index) => {\n const orderLine = em.create(SalesOrderLine, {\n id: line.id,\n order,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n lineNumber: line.lineNumber ?? index + 1,\n kind: line.kind as SalesLineKind,\n statusEntryId: (line as any).statusEntryId ?? null,\n status: (line as any).status ?? null,\n productId: line.productId ?? null,\n productVariantId: line.productVariantId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n name: line.name ?? null,\n description: line.description ?? null,\n comment: line.comment ?? null,\n quantity: line.quantity,\n quantityUnit: line.quantityUnit ?? null,\n reservedQuantity: '0',\n fulfilledQuantity: '0',\n invoicedQuantity: '0',\n returnedQuantity: '0',\n currencyCode: line.currencyCode,\n unitPriceNet: line.unitPriceNet,\n unitPriceGross: line.unitPriceGross,\n discountAmount: line.discountAmount,\n discountPercent: line.discountPercent,\n taxRate: line.taxRate,\n taxAmount: line.taxAmount,\n totalNetAmount: line.totalNetAmount,\n totalGrossAmount: line.totalGrossAmount,\n configuration: line.configuration ? cloneJson(line.configuration) : null,\n promotionCode: line.promotionCode ?? null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n metadata: line.metadata ? cloneJson(line.metadata) : null,\n customFieldSetId: line.customFieldSetId ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(orderLine)\n orderLineMap.set(orderLine.id, orderLine)\n })\n\n snapshot.adjustments.forEach((adj, index) => {\n const orderLineId = adj.quoteLineId ?? null\n const orderLine = orderLineId ? orderLineMap.get(orderLineId) ?? null : null\n const entity = em.create(SalesOrderAdjustment, {\n id: adj.id,\n order,\n orderLine: orderLine ?? null,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n scope: adj.scope,\n kind: adj.kind as SalesAdjustmentKind,\n code: adj.code ?? null,\n label: adj.label ?? null,\n calculatorKey: adj.calculatorKey ?? null,\n promotionId: adj.promotionId ?? null,\n rate: adj.rate,\n amountNet: adj.amountNet,\n amountGross: adj.amountGross,\n currencyCode: adj.currencyCode ?? null,\n metadata: adj.metadata ? cloneJson(adj.metadata) : null,\n position: adj.position ?? index,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(entity)\n })\n\n const [addresses, notes, tags] = await Promise.all([\n em.find(SalesDocumentAddress, { documentId: snapshot.quote.id, documentKind: 'quote' }),\n em.find(SalesNote, { contextType: 'quote', contextId: snapshot.quote.id }),\n em.find(SalesDocumentTagAssignment, { documentId: snapshot.quote.id, documentKind: 'quote' }),\n ])\n addresses.forEach((entry) => {\n entry.documentKind = 'order'\n entry.documentId = order.id\n entry.order = order\n entry.quote = null\n entry.updatedAt = new Date()\n })\n notes.forEach((note) => {\n note.contextType = 'order'\n note.contextId = order.id\n note.order = order\n note.quote = null\n note.updatedAt = new Date()\n })\n tags.forEach((assignment) => {\n assignment.documentKind = 'order'\n assignment.documentId = order.id\n assignment.order = order\n assignment.quote = null\n assignment.updatedAt = new Date()\n })\n\n const documentCustomValues = quoteCustomFields[snapshot.quote.id]\n if (documentCustomValues && Object.keys(documentCustomValues).length) {\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order,\n recordId: order.id,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n values: documentCustomValues,\n })\n }\n const lineCustomEntries = quoteLineCustomFields as Record<string, Record<string, unknown>>\n if (lineCustomEntries && Object.keys(lineCustomEntries).length) {\n for (const [lineId, values] of Object.entries(lineCustomEntries)) {\n if (!values || !Object.keys(values).length) continue\n if (!orderLineMap.has(lineId)) continue\n await setRecordCustomFields(em, {\n entityId: E.sales.sales_order_line,\n recordId: lineId,\n organizationId: snapshot.quote.organizationId,\n tenantId: snapshot.quote.tenantId,\n values,\n })\n }\n }\n\n await em.nativeDelete(SalesQuoteAdjustment, { quote: snapshot.quote.id })\n await em.nativeDelete(SalesQuoteLine, { quote: snapshot.quote.id })\n em.remove(quote)\n await em.flush()\n\n return { orderId: order.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.convert', 'Convert quote to order'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: before.quote.tenantId,\n organizationId: before.quote.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n payload: {\n undo: { quote: before, order: after ?? null } satisfies QuoteConvertUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteConvertUndoPayload>(logEntry)\n const quoteSnapshot = payload?.quote\n const orderSnapshot = payload?.order\n if (!quoteSnapshot) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, quoteSnapshot.quote.organizationId, quoteSnapshot.quote.tenantId)\n if (orderSnapshot) {\n const orderId = orderSnapshot.order.id\n const orderLineIds = orderSnapshot.lines.map((line) => line.id)\n const existingOrder = await em.findOne(SalesOrder, { id: orderId })\n if (existingOrder) {\n const shipments = await em.find(SalesShipment, { order: orderId })\n const shipmentIds = shipments.map((entry) => entry.id)\n if (shipmentIds.length) {\n await em.nativeDelete(SalesShipmentItem, { shipment: { $in: shipmentIds } })\n await em.nativeDelete(SalesShipment, { id: { $in: shipmentIds } })\n }\n await em.nativeDelete(SalesPaymentAllocation, { order: orderId })\n await em.nativeDelete(SalesPayment, { order: orderId })\n await em.nativeDelete(SalesDocumentAddress, { documentId: orderId, documentKind: 'order' })\n await em.nativeDelete(SalesDocumentTagAssignment, { documentId: orderId, documentKind: 'order' })\n await em.nativeDelete(SalesOrderAdjustment, { order: orderId })\n await em.nativeDelete(SalesOrderLine, { order: orderId })\n em.remove(existingOrder)\n }\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_order, recordId: orderId })\n if (orderLineIds.length) {\n await em.nativeDelete(CustomFieldValue, { entityId: E.sales.sales_order_line, recordId: { $in: orderLineIds } as any })\n }\n }\n const noteIds = quoteSnapshot.notes.map((note) => note.id)\n if (noteIds.length) {\n await em.nativeDelete(SalesNote, { id: { $in: noteIds } })\n }\n await restoreQuoteGraph(em, quoteSnapshot)\n await em.flush()\n },\n}\n\nconst orderLineUpsertSchema = orderLineCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst orderLineDeleteSchema = z.object({\n id: z.string().uuid(),\n orderId: z.string().uuid(),\n})\n\nconst quoteLineUpsertSchema = quoteLineCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst quoteLineDeleteSchema = z.object({\n id: z.string().uuid(),\n quoteId: z.string().uuid(),\n})\n\nconst orderAdjustmentUpsertSchema = orderAdjustmentCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst orderAdjustmentDeleteSchema = z.object({\n id: z.string().uuid(),\n orderId: z.string().uuid(),\n})\n\nconst quoteAdjustmentUpsertSchema = quoteAdjustmentCreateSchema.extend({ id: z.string().uuid().optional() })\n\nconst quoteAdjustmentDeleteSchema = z.object({\n id: z.string().uuid(),\n quoteId: z.string().uuid(),\n})\n\nconst orderLineUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; lineId: string }\n> = {\n id: 'sales.orders.lines.upsert',\n async prepare(input, ctx) {\n console.log('PREPARE ORDER LINE UPSERT', input, ctx)\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = orderLineUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const existingSnapshot = parsed.id ? lineSnapshots.find((line) => line.id === parsed.id) ?? null : null\n const priceMode = parsed.priceMode === 'gross' ? 'gross' : parsed.priceMode === 'net' ? 'net' : null\n let unitPriceNet = parsed.unitPriceNet ?? existingSnapshot?.unitPriceNet ?? null\n let unitPriceGross = parsed.unitPriceGross ?? existingSnapshot?.unitPriceGross ?? null\n let taxRate = parsed.taxRate ?? existingSnapshot?.taxRate ?? null\n if (priceMode && (unitPriceNet === null || unitPriceGross === null)) {\n let taxService: TaxCalculationService | null = null\n try {\n taxService = ctx.container.resolve('taxCalculationService') as TaxCalculationService\n } catch {\n taxService = null\n }\n if (taxService) {\n const taxResult = await taxService.calculateUnitAmounts({\n amount:\n priceMode === 'gross'\n ? unitPriceGross ?? unitPriceNet ?? 0\n : unitPriceNet ?? unitPriceGross ?? 0,\n mode: priceMode,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n taxRateId: parsed.taxRateId ?? undefined,\n taxRate: taxRate ?? undefined,\n })\n unitPriceNet = unitPriceNet ?? taxResult.netAmount\n unitPriceGross = unitPriceGross ?? taxResult.grossAmount\n taxRate = taxResult.taxRate ?? taxRate\n }\n }\n\n const metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? { ...parsed.metadata }\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : {}\n if (parsed.priceId) metadata.priceId = parsed.priceId\n if (priceMode) metadata.priceMode = priceMode\n\n const statusEntryId = parsed.statusEntryId ?? (existingSnapshot as any)?.statusEntryId ?? null\n const lineId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n const updatedSnapshot: SalesLineSnapshot & { statusEntryId?: string | null; catalogSnapshot?: Record<string, unknown> | null; promotionSnapshot?: Record<string, unknown> | null } = {\n id: lineId,\n lineNumber: parsed.lineNumber ?? existingSnapshot?.lineNumber ?? lineSnapshots.length + 1,\n kind: parsed.kind ?? existingSnapshot?.kind ?? 'product',\n productId: parsed.productId ?? existingSnapshot?.productId ?? null,\n productVariantId: parsed.productVariantId ?? existingSnapshot?.productVariantId ?? null,\n name: parsed.name ?? existingSnapshot?.name ?? null,\n description: parsed.description ?? existingSnapshot?.description ?? null,\n comment: parsed.comment ?? existingSnapshot?.comment ?? null,\n quantity: Number(parsed.quantity ?? existingSnapshot?.quantity ?? 0),\n quantityUnit: parsed.quantityUnit ?? existingSnapshot?.quantityUnit ?? null,\n currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? order.currencyCode,\n unitPriceNet: unitPriceNet ?? 0,\n unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,\n discountAmount: parsed.discountAmount ?? existingSnapshot?.discountAmount ?? 0,\n discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,\n taxRate: taxRate ?? 0,\n taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,\n totalNetAmount: parsed.totalNetAmount ?? existingSnapshot?.totalNetAmount ?? null,\n totalGrossAmount: parsed.totalGrossAmount ?? existingSnapshot?.totalGrossAmount ?? null,\n configuration: parsed.configuration ?? existingSnapshot?.configuration ?? null,\n promotionCode: parsed.promotionCode ?? existingSnapshot?.promotionCode ?? null,\n metadata,\n customFieldSetId: parsed.customFieldSetId ?? existingSnapshot?.customFieldSetId ?? null,\n customFields:\n parsed.customFields && typeof parsed.customFields === 'object'\n ? cloneJson(parsed.customFields)\n : (existingSnapshot as any)?.customFields ?? null,\n }\n ;(updatedSnapshot as any).statusEntryId = statusEntryId\n ;(updatedSnapshot as any).catalogSnapshot =\n parsed.catalogSnapshot ?? (existingSnapshot as any)?.catalogSnapshot ?? null\n ;(updatedSnapshot as any).promotionSnapshot =\n parsed.promotionSnapshot ?? (existingSnapshot as any)?.promotionSnapshot ?? null\n\n let nextLines = parsed.id\n ? lineSnapshots.map((line) => (line.id === parsed.id ? updatedSnapshot : line))\n : [...lineSnapshots, updatedSnapshot]\n nextLines = nextLines\n .sort((a, b) => (a.lineNumber ?? 0) - (b.lineNumber ?? 0))\n .map((line, index) => ({ ...line, lineNumber: index + 1 }))\n\n const sourceInputs = nextLines.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines: SalesLineSnapshot[] = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n await applyOrderLineResults({\n em,\n order,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, lineId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.lines.upsert', 'Upsert order line'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst orderLineDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; lineId: string }\n> = {\n id: 'sales.orders.lines.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const { translate } = await resolveTranslations()\n const parsed = orderLineDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n const shipmentCount = await em.count(SalesShipmentItem, {\n orderLine: parsed.id,\n shipment: { deletedAt: null },\n })\n if (shipmentCount > 0) {\n throw new CrudHttpError(409, {\n error: translate(\n 'sales.documents.items.errorDeleteShipped',\n 'Cannot delete a line that has shipped items.'\n ),\n })\n }\n const existingLines = await em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } })\n const filtered = existingLines.filter((line) => line.id !== parsed.id)\n if (filtered.length === existingLines.length) {\n throw new CrudHttpError(404, { error: translate('sales.documents.detail.error', 'Document not found or inaccessible.') })\n }\n const sourceInputs = filtered.map((line, index) => ({\n ...mapOrderLineEntityToSnapshot(line),\n statusEntryId: line.statusEntryId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: index + 1,\n }))\n const calcLines = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n await applyOrderLineResults({\n em,\n order,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, lineId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.lines.delete', 'Delete order line'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteLineUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; lineId: string }\n> = {\n id: 'sales.quotes.lines.upsert',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteLineUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const existingSnapshot = parsed.id ? lineSnapshots.find((line) => line.id === parsed.id) ?? null : null\n const priceMode = parsed.priceMode === 'gross' ? 'gross' : parsed.priceMode === 'net' ? 'net' : null\n let unitPriceNet = parsed.unitPriceNet ?? existingSnapshot?.unitPriceNet ?? null\n let unitPriceGross = parsed.unitPriceGross ?? existingSnapshot?.unitPriceGross ?? null\n let taxRate = parsed.taxRate ?? existingSnapshot?.taxRate ?? null\n if (priceMode && (unitPriceNet === null || unitPriceGross === null)) {\n let taxService: TaxCalculationService | null = null\n try {\n taxService = ctx.container.resolve('taxCalculationService') as TaxCalculationService\n } catch {\n taxService = null\n }\n if (taxService) {\n const taxResult = await taxService.calculateUnitAmounts({\n amount:\n priceMode === 'gross'\n ? unitPriceGross ?? unitPriceNet ?? 0\n : unitPriceNet ?? unitPriceGross ?? 0,\n mode: priceMode,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n taxRateId: parsed.taxRateId ?? undefined,\n taxRate: taxRate ?? undefined,\n })\n unitPriceNet = unitPriceNet ?? taxResult.netAmount\n unitPriceGross = unitPriceGross ?? taxResult.grossAmount\n taxRate = taxResult.taxRate ?? taxRate\n }\n }\n const metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? { ...parsed.metadata }\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : {}\n if (parsed.priceId) metadata.priceId = parsed.priceId\n if (priceMode) metadata.priceMode = priceMode\n\n const statusEntryId = parsed.statusEntryId ?? (existingSnapshot as any)?.statusEntryId ?? null\n const lineId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n const updatedSnapshot: SalesLineSnapshot & { statusEntryId?: string | null; catalogSnapshot?: Record<string, unknown> | null; promotionSnapshot?: Record<string, unknown> | null } = {\n id: lineId,\n lineNumber: parsed.lineNumber ?? existingSnapshot?.lineNumber ?? lineSnapshots.length + 1,\n kind: parsed.kind ?? existingSnapshot?.kind ?? 'product',\n productId: parsed.productId ?? existingSnapshot?.productId ?? null,\n productVariantId: parsed.productVariantId ?? existingSnapshot?.productVariantId ?? null,\n name: parsed.name ?? existingSnapshot?.name ?? null,\n description: parsed.description ?? existingSnapshot?.description ?? null,\n comment: parsed.comment ?? existingSnapshot?.comment ?? null,\n quantity: Number(parsed.quantity ?? existingSnapshot?.quantity ?? 0),\n quantityUnit: parsed.quantityUnit ?? existingSnapshot?.quantityUnit ?? null,\n currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? quote.currencyCode,\n unitPriceNet: unitPriceNet ?? 0,\n unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,\n discountAmount: parsed.discountAmount ?? existingSnapshot?.discountAmount ?? 0,\n discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,\n taxRate: taxRate ?? 0,\n taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,\n totalNetAmount: parsed.totalNetAmount ?? existingSnapshot?.totalNetAmount ?? null,\n totalGrossAmount: parsed.totalGrossAmount ?? existingSnapshot?.totalGrossAmount ?? null,\n configuration: parsed.configuration ?? existingSnapshot?.configuration ?? null,\n promotionCode: parsed.promotionCode ?? existingSnapshot?.promotionCode ?? null,\n metadata,\n customFieldSetId: parsed.customFieldSetId ?? existingSnapshot?.customFieldSetId ?? null,\n customFields:\n parsed.customFields && typeof parsed.customFields === 'object'\n ? cloneJson(parsed.customFields)\n : (existingSnapshot as any)?.customFields ?? null,\n }\n ;(updatedSnapshot as any).statusEntryId = statusEntryId\n ;(updatedSnapshot as any).catalogSnapshot =\n parsed.catalogSnapshot ?? (existingSnapshot as any)?.catalogSnapshot ?? null\n ;(updatedSnapshot as any).promotionSnapshot =\n parsed.promotionSnapshot ?? (existingSnapshot as any)?.promotionSnapshot ?? null\n\n let nextLines = parsed.id\n ? lineSnapshots.map((line) => (line.id === parsed.id ? updatedSnapshot : line))\n : [...lineSnapshots, updatedSnapshot]\n nextLines = nextLines\n .sort((a, b) => (a.lineNumber ?? 0) - (b.lineNumber ?? 0))\n .map((line, index) => ({ ...line, lineNumber: index + 1 }))\n\n const sourceInputs = nextLines.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines: SalesLineSnapshot[] = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n await applyQuoteLineResults({\n em,\n quote,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, lineId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.lines.upsert', 'Upsert quote line'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteLineDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; lineId: string }\n> = {\n id: 'sales.quotes.lines.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteLineDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n const existingLines = await em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } })\n const adjustments = await em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } })\n const filtered = existingLines.filter((line) => line.id !== parsed.id)\n if (filtered.length === existingLines.length) {\n throw new CrudHttpError(404, { error: 'Quote line not found' })\n }\n const sourceInputs = filtered.map((line, index) => ({\n ...mapQuoteLineEntityToSnapshot(line),\n statusEntryId: line.statusEntryId ?? null,\n catalogSnapshot: line.catalogSnapshot ? cloneJson(line.catalogSnapshot) : null,\n promotionSnapshot: line.promotionSnapshot ? cloneJson(line.promotionSnapshot) : null,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: index + 1,\n }))\n const calcLines = sourceInputs.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const adjustmentDrafts = adjustments.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n await applyQuoteLineResults({\n em,\n quote,\n calculation,\n sourceLines: sourceInputs,\n existingLines,\n })\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, lineId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.lines.delete', 'Delete quote line'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst orderAdjustmentUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; adjustmentId: string }\n> = {\n id: 'sales.orders.adjustments.upsert',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = orderAdjustmentUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n if (parsed.scope === 'line') {\n throw new CrudHttpError(400, { error: 'Line-scoped adjustments are not supported yet.' })\n }\n\n const [existingLines, existingAdjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const adjustmentDrafts = existingAdjustments.map(mapOrderAdjustmentToDraft)\n const existingSnapshot = parsed.id ? adjustmentDrafts.find((adj) => adj.id === parsed.id) ?? null : null\n const adjustmentId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n let metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? cloneJson(parsed.metadata)\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : null\n const calculatorKey = parsed.calculatorKey ?? existingSnapshot?.calculatorKey ?? null\n if (\n parsed.id &&\n calculatorKey &&\n (calculatorKey.startsWith('shipping-provider:') || calculatorKey.startsWith('payment-provider:'))\n ) {\n metadata = { ...(metadata ?? {}), manualOverride: true }\n }\n let nextAdjustments = parsed.id\n ? adjustmentDrafts.map((adj) =>\n adj.id === parsed.id\n ? {\n ...adj,\n id: adjustmentId,\n scope: parsed.scope ?? adj.scope ?? 'order',\n kind: parsed.kind ?? adj.kind ?? 'custom',\n code: parsed.code ?? adj.code ?? null,\n label: parsed.label ?? adj.label ?? null,\n calculatorKey: parsed.calculatorKey ?? adj.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? adj.promotionId ?? null,\n rate: parsed.rate ?? adj.rate ?? null,\n amountNet: parsed.amountNet ?? adj.amountNet ?? null,\n amountGross: parsed.amountGross ?? adj.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? adj.currencyCode ?? order.currencyCode,\n metadata,\n customFields:\n parsed.customFields !== undefined\n ? parsed.customFields\n : (adj as any).customFields ?? null,\n position: parsed.position ?? adj.position ?? adjustmentDrafts.length,\n }\n : adj\n )\n : [\n ...adjustmentDrafts,\n {\n id: adjustmentId,\n scope: parsed.scope ?? 'order',\n kind: parsed.kind ?? 'custom',\n code: parsed.code ?? null,\n label: parsed.label ?? null,\n calculatorKey: parsed.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? null,\n rate: parsed.rate ?? null,\n amountNet: parsed.amountNet ?? null,\n amountGross: parsed.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? order.currencyCode,\n metadata,\n customFields: parsed.customFields ?? null,\n position: parsed.position ?? adjustmentDrafts.length,\n },\n ]\n\n nextAdjustments = nextAdjustments\n .sort((a, b) => (a.position ?? 0) - (b.position ?? 0))\n .map((adj, index) => ({ ...adj, position: adj.position ?? index }))\n\n const sourceLines = lineSnapshots.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines = sourceLines.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: nextAdjustments,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n const adjustmentInputs = nextAdjustments.map((adj, index) => ({\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? order.currencyCode,\n metadata: adj.metadata ?? undefined,\n customFields: (adj as any).customFields ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n order.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, adjustmentId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.adjustments.upsert', 'Upsert order adjustment'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst orderAdjustmentDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { orderId: string; adjustmentId: string }\n> = {\n id: 'sales.orders.adjustments.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const orderId = typeof raw.orderId === 'string' ? raw.orderId : null\n if (!orderId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadOrderSnapshot(em, orderId)\n if (snapshot) ensureOrderScope(ctx, snapshot.order.organizationId, snapshot.order.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = orderAdjustmentDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const order = await em.findOne(SalesOrder, { id: parsed.orderId, deletedAt: null })\n if (!order) throw new CrudHttpError(404, { error: 'Sales order not found' })\n ensureOrderScope(ctx, order.organizationId, order.tenantId)\n\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesOrderLine, { order }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesOrderAdjustment, { order }, { orderBy: { position: 'asc' } }),\n ])\n const filtered = adjustments.filter((adj) => adj.id !== parsed.id)\n if (filtered.length === adjustments.length) {\n throw new CrudHttpError(404, { error: 'Adjustment not found' })\n }\n const lineSnapshots = existingLines.map(mapOrderLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = filtered.map(mapOrderAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: order.tenantId,\n organizationId: order.organizationId,\n currencyCode: order.currencyCode,\n shippingSnapshot: order.shippingMethodSnapshot,\n paymentSnapshot: order.paymentMethodSnapshot,\n shippingMethodId: order.shippingMethodId ?? null,\n paymentMethodId: order.paymentMethodId ?? null,\n shippingMethodCode: order.shippingMethodCode ?? null,\n paymentMethodCode: order.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'order',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n existingTotals: resolveExistingPaymentTotals(order),\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n orderId: order.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? order.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceOrderAdjustments(em, order, calculation, adjustmentInputs)\n applyOrderTotals(order, calculation.totals, calculation.lines.length)\n order.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'order',\n documentId: order.id,\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n customerId: order.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { orderId: order.id, adjustmentId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadOrderSnapshot(em, result.orderId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as OrderGraphSnapshot | undefined\n const after = snapshots.after as OrderGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.orders.adjustments.delete', 'Delete order adjustment'),\n resourceKind: 'sales.order',\n resourceId: result.orderId,\n tenantId: after.order.tenantId,\n organizationId: after.order.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies OrderUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<OrderUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureOrderScope(ctx, before.order.organizationId, before.order.tenantId)\n await restoreOrderGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteAdjustmentUpsertCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; adjustmentId: string }\n> = {\n id: 'sales.quotes.adjustments.upsert',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteAdjustmentUpsertSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n if (parsed.scope === 'line') {\n throw new CrudHttpError(400, { error: 'Line-scoped adjustments are not supported yet.' })\n }\n\n const [existingLines, existingAdjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const adjustmentDrafts = existingAdjustments.map(mapQuoteAdjustmentToDraft)\n const existingSnapshot = parsed.id ? adjustmentDrafts.find((adj) => adj.id === parsed.id) ?? null : null\n const adjustmentId = parsed.id ?? existingSnapshot?.id ?? randomUUID()\n let metadata =\n typeof parsed.metadata === 'object' && parsed.metadata\n ? cloneJson(parsed.metadata)\n : existingSnapshot?.metadata\n ? cloneJson(existingSnapshot.metadata)\n : null\n const calculatorKey = parsed.calculatorKey ?? existingSnapshot?.calculatorKey ?? null\n if (\n parsed.id &&\n calculatorKey &&\n (calculatorKey.startsWith('shipping-provider:') || calculatorKey.startsWith('payment-provider:'))\n ) {\n metadata = { ...(metadata ?? {}), manualOverride: true }\n }\n let nextAdjustments = parsed.id\n ? adjustmentDrafts.map((adj) =>\n adj.id === parsed.id\n ? {\n ...adj,\n id: adjustmentId,\n scope: parsed.scope ?? adj.scope ?? 'order',\n kind: parsed.kind ?? adj.kind ?? 'custom',\n code: parsed.code ?? adj.code ?? null,\n label: parsed.label ?? adj.label ?? null,\n calculatorKey: parsed.calculatorKey ?? adj.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? adj.promotionId ?? null,\n rate: parsed.rate ?? adj.rate ?? null,\n amountNet: parsed.amountNet ?? adj.amountNet ?? null,\n amountGross: parsed.amountGross ?? adj.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? adj.currencyCode ?? quote.currencyCode,\n metadata,\n customFields:\n parsed.customFields !== undefined\n ? parsed.customFields\n : (adj as any).customFields ?? null,\n position: parsed.position ?? adj.position ?? adjustmentDrafts.length,\n }\n : adj\n )\n : [\n ...adjustmentDrafts,\n {\n id: adjustmentId,\n scope: parsed.scope ?? 'order',\n kind: parsed.kind ?? 'custom',\n code: parsed.code ?? null,\n label: parsed.label ?? null,\n calculatorKey: parsed.calculatorKey ?? null,\n promotionId: parsed.promotionId ?? null,\n rate: parsed.rate ?? null,\n amountNet: parsed.amountNet ?? null,\n amountGross: parsed.amountGross ?? null,\n currencyCode: parsed.currencyCode ?? quote.currencyCode,\n metadata,\n customFields: parsed.customFields ?? null,\n position: parsed.position ?? adjustmentDrafts.length,\n },\n ]\n\n nextAdjustments = nextAdjustments\n .sort((a, b) => (a.position ?? 0) - (b.position ?? 0))\n .map((adj, index) => ({ ...adj, position: adj.position ?? index }))\n\n const sourceLines = lineSnapshots.map((line, index) => ({\n ...line,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n }))\n const calcLines = sourceLines.map((line, index) =>\n createLineSnapshotFromInput(line, line.lineNumber ?? index + 1)\n )\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: nextAdjustments,\n context: calculationContext,\n })\n const adjustmentInputs = nextAdjustments.map((adj, index) => ({\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? quote.currencyCode,\n metadata: adj.metadata ?? undefined,\n customFields: (adj as any).customFields ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n quote.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, adjustmentId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.adjustments.upsert', 'Upsert quote adjustment'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nconst quoteAdjustmentDeleteCommand: CommandHandler<\n { body?: Record<string, unknown>; query?: Record<string, unknown> },\n { quoteId: string; adjustmentId: string }\n> = {\n id: 'sales.quotes.adjustments.delete',\n async prepare(input, ctx) {\n const raw = (input?.body as Record<string, unknown> | undefined) ?? {}\n const quoteId = typeof raw.quoteId === 'string' ? raw.quoteId : null\n if (!quoteId) return {}\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadQuoteSnapshot(em, quoteId)\n if (snapshot) ensureQuoteScope(ctx, snapshot.quote.organizationId, snapshot.quote.tenantId)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const parsed = quoteAdjustmentDeleteSchema.parse((input?.body as Record<string, unknown> | undefined) ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const quote = await em.findOne(SalesQuote, { id: parsed.quoteId, deletedAt: null })\n if (!quote) throw new CrudHttpError(404, { error: 'Sales quote not found' })\n ensureQuoteScope(ctx, quote.organizationId, quote.tenantId)\n\n const [existingLines, adjustments] = await Promise.all([\n em.find(SalesQuoteLine, { quote }, { orderBy: { lineNumber: 'asc' } }),\n em.find(SalesQuoteAdjustment, { quote }, { orderBy: { position: 'asc' } }),\n ])\n const filtered = adjustments.filter((adj) => adj.id !== parsed.id)\n if (filtered.length === adjustments.length) {\n throw new CrudHttpError(404, { error: 'Adjustment not found' })\n }\n const lineSnapshots = existingLines.map(mapQuoteLineEntityToSnapshot)\n const calcLines = lineSnapshots.map((line, index) =>\n createLineSnapshotFromInput(\n {\n ...line,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n lineNumber: line.lineNumber ?? index + 1,\n statusEntryId: (line as any).statusEntryId ?? null,\n catalogSnapshot: (line as any).catalogSnapshot ?? null,\n promotionSnapshot: (line as any).promotionSnapshot ?? null,\n },\n line.lineNumber ?? index + 1\n )\n )\n const adjustmentDrafts = filtered.map(mapQuoteAdjustmentToDraft)\n const salesCalculationService = ctx.container.resolve<SalesCalculationService>('salesCalculationService')\n const calculationContext = buildCalculationContext({\n tenantId: quote.tenantId,\n organizationId: quote.organizationId,\n currencyCode: quote.currencyCode,\n shippingSnapshot: quote.shippingMethodSnapshot,\n paymentSnapshot: quote.paymentMethodSnapshot,\n shippingMethodId: quote.shippingMethodId ?? null,\n paymentMethodId: quote.paymentMethodId ?? null,\n shippingMethodCode: quote.shippingMethodCode ?? null,\n paymentMethodCode: quote.paymentMethodCode ?? null,\n })\n const calculation = await salesCalculationService.calculateDocumentTotals({\n documentKind: 'quote',\n lines: calcLines,\n adjustments: adjustmentDrafts,\n context: calculationContext,\n })\n const adjustmentInputs = adjustmentDrafts.map((adj, index) => ({\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n quoteId: quote.id,\n scope: adj.scope ?? 'order',\n kind: adj.kind ?? 'custom',\n code: adj.code ?? undefined,\n label: adj.label ?? undefined,\n calculatorKey: adj.calculatorKey ?? undefined,\n promotionId: adj.promotionId ?? undefined,\n rate: adj.rate ?? undefined,\n amountNet: adj.amountNet ?? undefined,\n amountGross: adj.amountGross ?? undefined,\n currencyCode: adj.currencyCode ?? quote.currencyCode,\n metadata: adj.metadata ?? undefined,\n position: adj.position ?? index,\n }))\n await replaceQuoteAdjustments(em, quote, calculation, adjustmentInputs)\n applyQuoteTotals(quote, calculation.totals, calculation.lines.length)\n quote.updatedAt = new Date()\n let eventBus: EventBus | null = null\n try {\n eventBus = ctx.container.resolve('eventBus') as EventBus\n } catch {\n eventBus = null\n }\n await emitTotalsCalculated(eventBus, {\n documentKind: 'quote',\n documentId: quote.id,\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n customerId: quote.customerEntityId ?? null,\n totals: calculation.totals,\n lineCount: calculation.lines.length,\n })\n await em.flush()\n return { quoteId: quote.id, adjustmentId: parsed.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadQuoteSnapshot(em, result.quoteId)\n },\n buildLog: async ({ snapshots, result }) => {\n const before = snapshots.before as QuoteGraphSnapshot | undefined\n const after = snapshots.after as QuoteGraphSnapshot | undefined\n if (!after) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.quotes.adjustments.delete', 'Delete quote adjustment'),\n resourceKind: 'sales.quote',\n resourceId: result.quoteId,\n tenantId: after.quote.tenantId,\n organizationId: after.quote.organizationId,\n snapshotBefore: before ?? null,\n snapshotAfter: after,\n payload: {\n undo: { before, after } satisfies QuoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<QuoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n ensureQuoteScope(ctx, before.quote.organizationId, before.quote.tenantId)\n await restoreQuoteGraph(em, before)\n await em.flush()\n },\n}\n\nregisterCommand(updateQuoteCommand)\nregisterCommand(createQuoteCommand)\nregisterCommand(deleteQuoteCommand)\nregisterCommand(convertQuoteToOrderCommand)\nregisterCommand(updateOrderCommand)\nregisterCommand(createOrderCommand)\nregisterCommand(deleteOrderCommand)\nregisterCommand(orderLineUpsertCommand)\nregisterCommand(orderLineDeleteCommand)\nregisterCommand(quoteLineUpsertCommand)\nregisterCommand(quoteLineDeleteCommand)\nregisterCommand(orderAdjustmentUpsertCommand)\nregisterCommand(orderAdjustmentDeleteCommand)\nregisterCommand(quoteAdjustmentUpsertCommand)\nregisterCommand(quoteAdjustmentD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