@dainamite/cpq 0.2.2
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/CHANGELOG.md +70 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +236 -0
- package/README.md +108 -0
- package/dist/modules/cpq/acl.js +30 -0
- package/dist/modules/cpq/acl.js.map +7 -0
- package/dist/modules/cpq/api/_helpers/handleArcError.js +37 -0
- package/dist/modules/cpq/api/_helpers/handleArcError.js.map +7 -0
- package/dist/modules/cpq/api/attribute-options/route.js +47 -0
- package/dist/modules/cpq/api/attribute-options/route.js.map +7 -0
- package/dist/modules/cpq/api/bundle-slots/route.js +101 -0
- package/dist/modules/cpq/api/bundle-slots/route.js.map +7 -0
- package/dist/modules/cpq/api/bundle-tree/route.js +28 -0
- package/dist/modules/cpq/api/bundle-tree/route.js.map +7 -0
- package/dist/modules/cpq/api/context.js +29 -0
- package/dist/modules/cpq/api/context.js.map +7 -0
- package/dist/modules/cpq/api/inventory/assets/route.js +113 -0
- package/dist/modules/cpq/api/inventory/assets/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/assets/status/route.js +35 -0
- package/dist/modules/cpq/api/inventory/assets/status/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/customer/[customerId]/parent-items/route.js +30 -0
- package/dist/modules/cpq/api/inventory/customer/[customerId]/parent-items/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/customer/[customerId]/route.js +31 -0
- package/dist/modules/cpq/api/inventory/customer/[customerId]/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/subscription-items/route.js +99 -0
- package/dist/modules/cpq/api/inventory/subscription-items/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/subscriptions/[subscriptionId]/change-log/route.js +57 -0
- package/dist/modules/cpq/api/inventory/subscriptions/[subscriptionId]/change-log/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/subscriptions/expiring/route.js +62 -0
- package/dist/modules/cpq/api/inventory/subscriptions/expiring/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/subscriptions/route.js +116 -0
- package/dist/modules/cpq/api/inventory/subscriptions/route.js.map +7 -0
- package/dist/modules/cpq/api/inventory/subscriptions/status/route.js +35 -0
- package/dist/modules/cpq/api/inventory/subscriptions/status/route.js.map +7 -0
- package/dist/modules/cpq/api/offering-components/route.js +91 -0
- package/dist/modules/cpq/api/offering-components/route.js.map +7 -0
- package/dist/modules/cpq/api/orders/[orderId]/activate/route.js +39 -0
- package/dist/modules/cpq/api/orders/[orderId]/activate/route.js.map +7 -0
- package/dist/modules/cpq/api/orders/[orderId]/route.js +28 -0
- package/dist/modules/cpq/api/orders/[orderId]/route.js.map +7 -0
- package/dist/modules/cpq/api/orders/[orderId]/status/route.js +38 -0
- package/dist/modules/cpq/api/orders/[orderId]/status/route.js.map +7 -0
- package/dist/modules/cpq/api/orders/route.js +71 -0
- package/dist/modules/cpq/api/orders/route.js.map +7 -0
- package/dist/modules/cpq/api/price-rules/route.js +180 -0
- package/dist/modules/cpq/api/price-rules/route.js.map +7 -0
- package/dist/modules/cpq/api/pricing-table-entries/route.js +142 -0
- package/dist/modules/cpq/api/pricing-table-entries/route.js.map +7 -0
- package/dist/modules/cpq/api/pricing-tables/route.js +179 -0
- package/dist/modules/cpq/api/pricing-tables/route.js.map +7 -0
- package/dist/modules/cpq/api/product-attributes/route.js +160 -0
- package/dist/modules/cpq/api/product-attributes/route.js.map +7 -0
- package/dist/modules/cpq/api/product-charges/route.js +166 -0
- package/dist/modules/cpq/api/product-charges/route.js.map +7 -0
- package/dist/modules/cpq/api/product-offerings/route.js +294 -0
- package/dist/modules/cpq/api/product-offerings/route.js.map +7 -0
- package/dist/modules/cpq/api/product-relationships/route.js +144 -0
- package/dist/modules/cpq/api/product-relationships/route.js.map +7 -0
- package/dist/modules/cpq/api/product-specifications/route.js +292 -0
- package/dist/modules/cpq/api/product-specifications/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/cancel-meta/route.js +71 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/cancel-meta/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/clone/route.js +29 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/clone/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/items/[lineId]/route.js +54 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/items/[lineId]/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/items/route.js +27 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/items/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/merge-meta/route.js +72 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/merge-meta/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/recalculate/route.js +35 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/recalculate/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/route.js +102 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/status/route.js +27 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/status/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/target-subscriptions/[targetId]/route.js +79 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/target-subscriptions/[targetId]/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/target-subscriptions/route.js +95 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/target-subscriptions/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/attributes/route.js +52 -0
- package/dist/modules/cpq/api/quotes/attributes/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/from-subscription/route.js +72 -0
- package/dist/modules/cpq/api/quotes/from-subscription/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/price/route.js +69 -0
- package/dist/modules/cpq/api/quotes/price/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/route.js +97 -0
- package/dist/modules/cpq/api/quotes/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/validate-relationships/route.js +86 -0
- package/dist/modules/cpq/api/quotes/validate-relationships/route.js.map +7 -0
- package/dist/modules/cpq/api/resolveQuotingService.js +7 -0
- package/dist/modules/cpq/api/resolveQuotingService.js.map +7 -0
- package/dist/modules/cpq/api/wizards/resolve/route.js +38 -0
- package/dist/modules/cpq/api/wizards/resolve/route.js.map +7 -0
- package/dist/modules/cpq/api/wizards/route.js +111 -0
- package/dist/modules/cpq/api/wizards/route.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/AssetsTable.js +136 -0
- package/dist/modules/cpq/backend/cpq/inventory/AssetsTable.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/SubscriptionsTable.js +185 -0
- package/dist/modules/cpq/backend/cpq/inventory/SubscriptionsTable.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/assets/[id]/page.js +343 -0
- package/dist/modules/cpq/backend/cpq/inventory/assets/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/assets/[id]/page.meta.js +13 -0
- package/dist/modules/cpq/backend/cpq/inventory/assets/[id]/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/page.js +35 -0
- package/dist/modules/cpq/backend/cpq/inventory/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/inventory/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/shared.js +20 -0
- package/dist/modules/cpq/backend/cpq/inventory/shared.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.js +794 -0
- package/dist/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.meta.js +13 -0
- package/dist/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/offerings/[id]/page.js +917 -0
- package/dist/modules/cpq/backend/cpq/offerings/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/offerings/page.js +405 -0
- package/dist/modules/cpq/backend/cpq/offerings/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/offerings/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/offerings/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/orders/[id]/page.js +677 -0
- package/dist/modules/cpq/backend/cpq/orders/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/orders/page.js +134 -0
- package/dist/modules/cpq/backend/cpq/orders/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/orders/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/orders/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/price-rules/PriceRuleForm.js +272 -0
- package/dist/modules/cpq/backend/cpq/price-rules/PriceRuleForm.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/price-rules/[id]/page.js +407 -0
- package/dist/modules/cpq/backend/cpq/price-rules/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/price-rules/[id]/page.meta.js +13 -0
- package/dist/modules/cpq/backend/cpq/price-rules/[id]/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/price-rules/page.js +211 -0
- package/dist/modules/cpq/backend/cpq/price-rules/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/price-rules/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/price-rules/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/EntriesEditor.js +275 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/EntriesEditor.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/ImportPreview.js +112 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/ImportPreview.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/page.js +492 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/xlsxExport.js +50 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/xlsxExport.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/xlsxImport.js +249 -0
- package/dist/modules/cpq/backend/cpq/pricing/[id]/xlsxImport.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/pricing/page.js +87 -0
- package/dist/modules/cpq/backend/cpq/pricing/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/pricing/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/pricing/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/ArcQuoteConfigurator.js +652 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/ArcQuoteConfigurator.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/page.js +1289 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/page.js +283 -0
- package/dist/modules/cpq/backend/cpq/quotes/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/quotes/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/specifications/[id]/DependsOnRulesEditor.js +214 -0
- package/dist/modules/cpq/backend/cpq/specifications/[id]/DependsOnRulesEditor.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/specifications/[id]/page.js +1399 -0
- package/dist/modules/cpq/backend/cpq/specifications/[id]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/specifications/page.js +148 -0
- package/dist/modules/cpq/backend/cpq/specifications/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/specifications/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/specifications/page.meta.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/wizards/[definitionCode]/detail/page.js +204 -0
- package/dist/modules/cpq/backend/cpq/wizards/[definitionCode]/detail/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/wizards/[definitionCode]/page.js +191 -0
- package/dist/modules/cpq/backend/cpq/wizards/[definitionCode]/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/wizards/page.js +119 -0
- package/dist/modules/cpq/backend/cpq/wizards/page.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/wizards/page.meta.js +18 -0
- package/dist/modules/cpq/backend/cpq/wizards/page.meta.js.map +7 -0
- package/dist/modules/cpq/ce.js +151 -0
- package/dist/modules/cpq/ce.js.map +7 -0
- package/dist/modules/cpq/cli.js +11 -0
- package/dist/modules/cpq/cli.js.map +7 -0
- package/dist/modules/cpq/components/CpqListView.js +265 -0
- package/dist/modules/cpq/components/CpqListView.js.map +7 -0
- package/dist/modules/cpq/components/NumberInput.js +95 -0
- package/dist/modules/cpq/components/NumberInput.js.map +7 -0
- package/dist/modules/cpq/components/StatusPath.js +60 -0
- package/dist/modules/cpq/components/StatusPath.js.map +7 -0
- package/dist/modules/cpq/components/statusMaps.js +66 -0
- package/dist/modules/cpq/components/statusMaps.js.map +7 -0
- package/dist/modules/cpq/components/useCpqRowActions.js +125 -0
- package/dist/modules/cpq/components/useCpqRowActions.js.map +7 -0
- package/dist/modules/cpq/data/entities.js +1556 -0
- package/dist/modules/cpq/data/entities.js.map +7 -0
- package/dist/modules/cpq/data/validators.js +575 -0
- package/dist/modules/cpq/data/validators.js.map +7 -0
- package/dist/modules/cpq/di.js +57 -0
- package/dist/modules/cpq/di.js.map +7 -0
- package/dist/modules/cpq/events.js +50 -0
- package/dist/modules/cpq/events.js.map +7 -0
- package/dist/modules/cpq/index.js +16 -0
- package/dist/modules/cpq/index.js.map +7 -0
- package/dist/modules/cpq/lib/seeds/api.js +32 -0
- package/dist/modules/cpq/lib/seeds/api.js.map +7 -0
- package/dist/modules/cpq/lib/seeds/tenant-provisioning.js +158 -0
- package/dist/modules/cpq/lib/seeds/tenant-provisioning.js.map +7 -0
- package/dist/modules/cpq/lib/seeds.js +6 -0
- package/dist/modules/cpq/lib/seeds.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260220220000_cpq.js +40 -0
- package/dist/modules/cpq/migrations/Migration20260220220000_cpq.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260330000000_cpq_product_domain.js +54 -0
- package/dist/modules/cpq/migrations/Migration20260330000000_cpq_product_domain.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260331000000_cpq_charge_unique_per_offering.js +15 -0
- package/dist/modules/cpq/migrations/Migration20260331000000_cpq_charge_unique_per_offering.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260401000000_cpq_quoting_v2.js +62 -0
- package/dist/modules/cpq/migrations/Migration20260401000000_cpq_quoting_v2.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260402000000_cpq_workflows.js +56 -0
- package/dist/modules/cpq/migrations/Migration20260402000000_cpq_workflows.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260407000000_cpq_pricing_tables_v2.js +26 -0
- package/dist/modules/cpq/migrations/Migration20260407000000_cpq_pricing_tables_v2.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260407100000_cpq_price_rules.js +37 -0
- package/dist/modules/cpq/migrations/Migration20260407100000_cpq_price_rules.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260408000000_cpq_price_rules.js +35 -0
- package/dist/modules/cpq/migrations/Migration20260408000000_cpq_price_rules.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260410000000_cpq_drop_datacentres_inventory.js +21 -0
- package/dist/modules/cpq/migrations/Migration20260410000000_cpq_drop_datacentres_inventory.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260410000000_cpq_wizard_rename.js +46 -0
- package/dist/modules/cpq/migrations/Migration20260410000000_cpq_wizard_rename.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260410100000_cpq_inventory.js +118 -0
- package/dist/modules/cpq/migrations/Migration20260410100000_cpq_inventory.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260411000000_cpq_orders.js +63 -0
- package/dist/modules/cpq/migrations/Migration20260411000000_cpq_orders.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260412000000_cpq_bundled_offerings.js +28 -0
- package/dist/modules/cpq/migrations/Migration20260412000000_cpq_bundled_offerings.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260504064621_cpq_arc.js +36 -0
- package/dist/modules/cpq/migrations/Migration20260504064621_cpq_arc.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260514000000_cpq_spec_merge_retired_deprecated.js +14 -0
- package/dist/modules/cpq/migrations/Migration20260514000000_cpq_spec_merge_retired_deprecated.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260514100000_cpq_offering_merge_retired_deprecated.js +14 -0
- package/dist/modules/cpq/migrations/Migration20260514100000_cpq_offering_merge_retired_deprecated.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260514110000_cpq_list_search_indexes.js +58 -0
- package/dist/modules/cpq/migrations/Migration20260514110000_cpq_list_search_indexes.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20260515000000_cpq_inventory_subscriptions_search_indexes.js +29 -0
- package/dist/modules/cpq/migrations/Migration20260515000000_cpq_inventory_subscriptions_search_indexes.js.map +7 -0
- package/dist/modules/cpq/services/cpqBundleService.js +447 -0
- package/dist/modules/cpq/services/cpqBundleService.js.map +7 -0
- package/dist/modules/cpq/services/cpqInventoryService.js +1371 -0
- package/dist/modules/cpq/services/cpqInventoryService.js.map +7 -0
- package/dist/modules/cpq/services/cpqOrderService.js +901 -0
- package/dist/modules/cpq/services/cpqOrderService.js.map +7 -0
- package/dist/modules/cpq/services/cpqPricingService.js +289 -0
- package/dist/modules/cpq/services/cpqPricingService.js.map +7 -0
- package/dist/modules/cpq/services/cpqProductService.js +204 -0
- package/dist/modules/cpq/services/cpqProductService.js.map +7 -0
- package/dist/modules/cpq/services/cpqQuotingService.js +1867 -0
- package/dist/modules/cpq/services/cpqQuotingService.js.map +7 -0
- package/dist/modules/cpq/services/cpqValidationService.js +234 -0
- package/dist/modules/cpq/services/cpqValidationService.js.map +7 -0
- package/dist/modules/cpq/services/cpqWizardService.js +137 -0
- package/dist/modules/cpq/services/cpqWizardService.js.map +7 -0
- package/dist/modules/cpq/services/types.js +114 -0
- package/dist/modules/cpq/services/types.js.map +7 -0
- package/dist/modules/cpq/setup.js +49 -0
- package/dist/modules/cpq/setup.js.map +7 -0
- package/dist/modules/cpq/subscribers/subscription-amended-log.js +18 -0
- package/dist/modules/cpq/subscribers/subscription-amended-log.js.map +7 -0
- package/dist/modules/cpq/subscribers/subscription-cancelled-log.js +19 -0
- package/dist/modules/cpq/subscribers/subscription-cancelled-log.js.map +7 -0
- package/dist/modules/cpq/subscribers/subscription-merged-log.js +20 -0
- package/dist/modules/cpq/subscribers/subscription-merged-log.js.map +7 -0
- package/dist/modules/cpq/subscribers/subscription-renewed-log.js +18 -0
- package/dist/modules/cpq/subscribers/subscription-renewed-log.js.map +7 -0
- package/dist/modules/cpq/subscribers/subscription-superseded-log.js +18 -0
- package/dist/modules/cpq/subscribers/subscription-superseded-log.js.map +7 -0
- package/dist/modules/cpq/widgets/injection/customer-inventory/widget.client.js +192 -0
- package/dist/modules/cpq/widgets/injection/customer-inventory/widget.client.js.map +7 -0
- package/dist/modules/cpq/widgets/injection/customer-inventory/widget.js +17 -0
- package/dist/modules/cpq/widgets/injection/customer-inventory/widget.js.map +7 -0
- package/dist/modules/cpq/widgets/injection/order-cpq-tab/widget.client.js +79 -0
- package/dist/modules/cpq/widgets/injection/order-cpq-tab/widget.client.js.map +7 -0
- package/dist/modules/cpq/widgets/injection/order-cpq-tab/widget.js +17 -0
- package/dist/modules/cpq/widgets/injection/order-cpq-tab/widget.js.map +7 -0
- package/dist/modules/cpq/widgets/injection/quote-configurator/widget.client.js +181 -0
- package/dist/modules/cpq/widgets/injection/quote-configurator/widget.client.js.map +7 -0
- package/dist/modules/cpq/widgets/injection/quote-configurator/widget.js +17 -0
- package/dist/modules/cpq/widgets/injection/quote-configurator/widget.js.map +7 -0
- package/dist/modules/cpq/widgets/injection-table.js +44 -0
- package/dist/modules/cpq/widgets/injection-table.js.map +7 -0
- package/dist/modules/cpq/workflows/WizardRunner.js +113 -0
- package/dist/modules/cpq/workflows/WizardRunner.js.map +7 -0
- package/dist/modules/cpq/workflows/WizardTrigger.js +116 -0
- package/dist/modules/cpq/workflows/WizardTrigger.js.map +7 -0
- package/dist/modules/cpq/workflows/engine.js +188 -0
- package/dist/modules/cpq/workflows/engine.js.map +7 -0
- package/dist/modules/cpq/workflows/registry.js +16 -0
- package/dist/modules/cpq/workflows/registry.js.map +7 -0
- package/dist/modules/cpq/workflows/steps/CustomerSelectStep.js +119 -0
- package/dist/modules/cpq/workflows/steps/CustomerSelectStep.js.map +7 -0
- package/dist/modules/cpq/workflows/steps/InventorySelectStep.js +24 -0
- package/dist/modules/cpq/workflows/steps/InventorySelectStep.js.map +7 -0
- package/dist/modules/cpq/workflows/steps/ItemListStep.js +115 -0
- package/dist/modules/cpq/workflows/steps/ItemListStep.js.map +7 -0
- package/dist/modules/cpq/workflows/steps/OfferingSelectStep.js +327 -0
- package/dist/modules/cpq/workflows/steps/OfferingSelectStep.js.map +7 -0
- package/dist/modules/cpq/workflows/steps/ProductConfigureStep.js +231 -0
- package/dist/modules/cpq/workflows/steps/ProductConfigureStep.js.map +7 -0
- package/dist/modules/cpq/workflows/steps/ReviewStep.js +152 -0
- package/dist/modules/cpq/workflows/steps/ReviewStep.js.map +7 -0
- package/dist/modules/cpq/workflows/steps/index.js +49 -0
- package/dist/modules/cpq/workflows/steps/index.js.map +7 -0
- package/dist/modules/cpq/workflows/types.js +1 -0
- package/dist/modules/cpq/workflows/types.js.map +7 -0
- package/package.json +150 -0
- package/src/modules/cpq/__integration__/TC-CPQ-001.spec.ts +177 -0
- package/src/modules/cpq/__integration__/TC-CPQ-002.spec.ts +123 -0
- package/src/modules/cpq/__integration__/TC-CPQ-003.spec.ts +115 -0
- package/src/modules/cpq/__integration__/TC-CPQ-004.spec.ts +184 -0
- package/src/modules/cpq/__integration__/TC-CPQ-005.spec.ts +43 -0
- package/src/modules/cpq/__integration__/TC-CPQ-006.spec.ts +87 -0
- package/src/modules/cpq/__integration__/TC-CPQ-007.spec.ts +79 -0
- package/src/modules/cpq/__integration__/TC-CPQ-008.spec.ts +55 -0
- package/src/modules/cpq/__integration__/TC-CPQ-009.spec.ts +45 -0
- package/src/modules/cpq/__integration__/TC-CPQ-010.spec.ts +54 -0
- package/src/modules/cpq/__integration__/TC-CPQ-011.spec.ts +24 -0
- package/src/modules/cpq/__integration__/TC-CPQ-012.spec.ts +62 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-001.spec.ts +52 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-002.spec.ts +65 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-003.spec.ts +107 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-004.spec.ts +74 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-005.spec.ts +86 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-006.spec.ts +79 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-007.spec.ts +63 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-008.spec.ts +62 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-009.spec.ts +62 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-010.spec.ts +59 -0
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-011.spec.ts +128 -0
- package/src/modules/cpq/__integration__/_helpers/cpqArcFixtures.ts +208 -0
- package/src/modules/cpq/__tests__/package-isolation.test.ts +232 -0
- package/src/modules/cpq/acl.ts +26 -0
- package/src/modules/cpq/api/_helpers/__tests__/handleArcError.test.ts +117 -0
- package/src/modules/cpq/api/_helpers/handleArcError.ts +81 -0
- package/src/modules/cpq/api/attribute-options/route.ts +55 -0
- package/src/modules/cpq/api/bundle-slots/route.ts +112 -0
- package/src/modules/cpq/api/bundle-tree/route.ts +31 -0
- package/src/modules/cpq/api/context.ts +39 -0
- package/src/modules/cpq/api/inventory/assets/route.ts +123 -0
- package/src/modules/cpq/api/inventory/assets/status/route.ts +34 -0
- package/src/modules/cpq/api/inventory/customer/[customerId]/parent-items/route.ts +30 -0
- package/src/modules/cpq/api/inventory/customer/[customerId]/route.ts +31 -0
- package/src/modules/cpq/api/inventory/subscription-items/route.ts +107 -0
- package/src/modules/cpq/api/inventory/subscriptions/[subscriptionId]/change-log/route.ts +64 -0
- package/src/modules/cpq/api/inventory/subscriptions/expiring/route.ts +66 -0
- package/src/modules/cpq/api/inventory/subscriptions/route.ts +126 -0
- package/src/modules/cpq/api/inventory/subscriptions/status/route.ts +34 -0
- package/src/modules/cpq/api/offering-components/route.ts +103 -0
- package/src/modules/cpq/api/orders/[orderId]/activate/route.ts +48 -0
- package/src/modules/cpq/api/orders/[orderId]/route.ts +28 -0
- package/src/modules/cpq/api/orders/[orderId]/status/route.ts +38 -0
- package/src/modules/cpq/api/orders/route.ts +77 -0
- package/src/modules/cpq/api/price-rules/route.ts +210 -0
- package/src/modules/cpq/api/pricing-table-entries/route.ts +159 -0
- package/src/modules/cpq/api/pricing-tables/route.ts +202 -0
- package/src/modules/cpq/api/product-attributes/route.ts +175 -0
- package/src/modules/cpq/api/product-charges/route.ts +181 -0
- package/src/modules/cpq/api/product-offerings/route.ts +329 -0
- package/src/modules/cpq/api/product-relationships/route.ts +156 -0
- package/src/modules/cpq/api/product-specifications/route.ts +325 -0
- package/src/modules/cpq/api/quotes/[quoteId]/cancel-meta/route.ts +77 -0
- package/src/modules/cpq/api/quotes/[quoteId]/clone/route.ts +28 -0
- package/src/modules/cpq/api/quotes/[quoteId]/items/[lineId]/route.ts +55 -0
- package/src/modules/cpq/api/quotes/[quoteId]/items/route.ts +26 -0
- package/src/modules/cpq/api/quotes/[quoteId]/merge-meta/route.ts +78 -0
- package/src/modules/cpq/api/quotes/[quoteId]/recalculate/route.ts +34 -0
- package/src/modules/cpq/api/quotes/[quoteId]/route.ts +109 -0
- package/src/modules/cpq/api/quotes/[quoteId]/status/route.ts +26 -0
- package/src/modules/cpq/api/quotes/[quoteId]/target-subscriptions/[targetId]/route.ts +91 -0
- package/src/modules/cpq/api/quotes/[quoteId]/target-subscriptions/route.ts +107 -0
- package/src/modules/cpq/api/quotes/attributes/route.ts +61 -0
- package/src/modules/cpq/api/quotes/from-subscription/route.ts +85 -0
- package/src/modules/cpq/api/quotes/price/route.ts +81 -0
- package/src/modules/cpq/api/quotes/route.ts +114 -0
- package/src/modules/cpq/api/quotes/validate-relationships/route.ts +100 -0
- package/src/modules/cpq/api/resolveQuotingService.ts +11 -0
- package/src/modules/cpq/api/wizards/resolve/route.ts +39 -0
- package/src/modules/cpq/api/wizards/route.ts +127 -0
- package/src/modules/cpq/backend/cpq/inventory/AssetsTable.tsx +166 -0
- package/src/modules/cpq/backend/cpq/inventory/SubscriptionsTable.tsx +251 -0
- package/src/modules/cpq/backend/cpq/inventory/assets/[id]/page.meta.ts +9 -0
- package/src/modules/cpq/backend/cpq/inventory/assets/[id]/page.tsx +440 -0
- package/src/modules/cpq/backend/cpq/inventory/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/inventory/page.tsx +49 -0
- package/src/modules/cpq/backend/cpq/inventory/shared.tsx +32 -0
- package/src/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.meta.ts +9 -0
- package/src/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.tsx +1085 -0
- package/src/modules/cpq/backend/cpq/offerings/[id]/page.tsx +1165 -0
- package/src/modules/cpq/backend/cpq/offerings/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/offerings/page.tsx +468 -0
- package/src/modules/cpq/backend/cpq/orders/[id]/page.tsx +921 -0
- package/src/modules/cpq/backend/cpq/orders/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/orders/page.tsx +182 -0
- package/src/modules/cpq/backend/cpq/price-rules/PriceRuleForm.tsx +310 -0
- package/src/modules/cpq/backend/cpq/price-rules/[id]/page.meta.ts +9 -0
- package/src/modules/cpq/backend/cpq/price-rules/[id]/page.tsx +472 -0
- package/src/modules/cpq/backend/cpq/price-rules/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/price-rules/page.tsx +253 -0
- package/src/modules/cpq/backend/cpq/pricing/[id]/EntriesEditor.tsx +431 -0
- package/src/modules/cpq/backend/cpq/pricing/[id]/ImportPreview.tsx +122 -0
- package/src/modules/cpq/backend/cpq/pricing/[id]/page.tsx +588 -0
- package/src/modules/cpq/backend/cpq/pricing/[id]/xlsxExport.ts +90 -0
- package/src/modules/cpq/backend/cpq/pricing/[id]/xlsxImport.ts +338 -0
- package/src/modules/cpq/backend/cpq/pricing/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/pricing/page.tsx +111 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/_components/ArcQuoteConfigurator.tsx +737 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/page.tsx +1721 -0
- package/src/modules/cpq/backend/cpq/quotes/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/quotes/page.tsx +370 -0
- package/src/modules/cpq/backend/cpq/specifications/[id]/DependsOnRulesEditor.tsx +300 -0
- package/src/modules/cpq/backend/cpq/specifications/[id]/page.tsx +1722 -0
- package/src/modules/cpq/backend/cpq/specifications/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/specifications/page.tsx +191 -0
- package/src/modules/cpq/backend/cpq/wizards/[definitionCode]/detail/page.tsx +319 -0
- package/src/modules/cpq/backend/cpq/wizards/[definitionCode]/page.tsx +234 -0
- package/src/modules/cpq/backend/cpq/wizards/page.meta.ts +16 -0
- package/src/modules/cpq/backend/cpq/wizards/page.tsx +141 -0
- package/src/modules/cpq/ce.ts +150 -0
- package/src/modules/cpq/cli.ts +10 -0
- package/src/modules/cpq/components/CpqListView.tsx +431 -0
- package/src/modules/cpq/components/NumberInput.tsx +166 -0
- package/src/modules/cpq/components/StatusPath.tsx +116 -0
- package/src/modules/cpq/components/statusMaps.ts +148 -0
- package/src/modules/cpq/components/useCpqRowActions.tsx +183 -0
- package/src/modules/cpq/data/__tests__/validators.arc.test.ts +271 -0
- package/src/modules/cpq/data/__tests__/validators.test.ts +782 -0
- package/src/modules/cpq/data/entities.ts +1467 -0
- package/src/modules/cpq/data/validators.ts +663 -0
- package/src/modules/cpq/di.ts +70 -0
- package/src/modules/cpq/events.ts +62 -0
- package/src/modules/cpq/index.ts +15 -0
- package/src/modules/cpq/lib/seeds/__tests__/api.test.ts +86 -0
- package/src/modules/cpq/lib/seeds/__tests__/tenant-provisioning.test.ts +349 -0
- package/src/modules/cpq/lib/seeds/api.ts +119 -0
- package/src/modules/cpq/lib/seeds/tenant-provisioning.ts +239 -0
- package/src/modules/cpq/lib/seeds.ts +18 -0
- package/src/modules/cpq/migrations/.snapshot-open-mercato.json +7473 -0
- package/src/modules/cpq/migrations/Migration20260220220000_cpq.ts +51 -0
- package/src/modules/cpq/migrations/Migration20260330000000_cpq_product_domain.ts +70 -0
- package/src/modules/cpq/migrations/Migration20260331000000_cpq_charge_unique_per_offering.ts +15 -0
- package/src/modules/cpq/migrations/Migration20260401000000_cpq_quoting_v2.ts +73 -0
- package/src/modules/cpq/migrations/Migration20260402000000_cpq_workflows.ts +59 -0
- package/src/modules/cpq/migrations/Migration20260407000000_cpq_pricing_tables_v2.ts +30 -0
- package/src/modules/cpq/migrations/Migration20260407100000_cpq_price_rules.ts +36 -0
- package/src/modules/cpq/migrations/Migration20260408000000_cpq_price_rules.ts +33 -0
- package/src/modules/cpq/migrations/Migration20260410000000_cpq_drop_datacentres_inventory.ts +22 -0
- package/src/modules/cpq/migrations/Migration20260410000000_cpq_wizard_rename.ts +56 -0
- package/src/modules/cpq/migrations/Migration20260410100000_cpq_inventory.ts +118 -0
- package/src/modules/cpq/migrations/Migration20260411000000_cpq_orders.ts +62 -0
- package/src/modules/cpq/migrations/Migration20260412000000_cpq_bundled_offerings.ts +33 -0
- package/src/modules/cpq/migrations/Migration20260504064621_cpq_arc.ts +68 -0
- package/src/modules/cpq/migrations/Migration20260514000000_cpq_spec_merge_retired_deprecated.ts +30 -0
- package/src/modules/cpq/migrations/Migration20260514100000_cpq_offering_merge_retired_deprecated.ts +27 -0
- package/src/modules/cpq/migrations/Migration20260514110000_cpq_list_search_indexes.ts +82 -0
- package/src/modules/cpq/migrations/Migration20260515000000_cpq_inventory_subscriptions_search_indexes.ts +52 -0
- package/src/modules/cpq/services/__tests__/_helpers/mockEm.ts +59 -0
- package/src/modules/cpq/services/__tests__/cpqBundleService.test.ts +661 -0
- package/src/modules/cpq/services/__tests__/cpqInventoryService.arc.test.ts +357 -0
- package/src/modules/cpq/services/__tests__/cpqInventoryService.test.ts +718 -0
- package/src/modules/cpq/services/__tests__/cpqOrderService.test.ts +603 -0
- package/src/modules/cpq/services/__tests__/cpqPricingService.test.ts +1012 -0
- package/src/modules/cpq/services/__tests__/cpqProductService.test.ts +603 -0
- package/src/modules/cpq/services/__tests__/cpqQuotingService.arc.test.ts +143 -0
- package/src/modules/cpq/services/__tests__/cpqQuotingService.test.ts +658 -0
- package/src/modules/cpq/services/__tests__/cpqValidationService.test.ts +811 -0
- package/src/modules/cpq/services/__tests__/cpqWizardService.test.ts +389 -0
- package/src/modules/cpq/services/__tests__/types.test.ts +359 -0
- package/src/modules/cpq/services/cpqBundleService.ts +671 -0
- package/src/modules/cpq/services/cpqInventoryService.ts +1929 -0
- package/src/modules/cpq/services/cpqOrderService.ts +1230 -0
- package/src/modules/cpq/services/cpqPricingService.ts +412 -0
- package/src/modules/cpq/services/cpqProductService.ts +311 -0
- package/src/modules/cpq/services/cpqQuotingService.ts +2638 -0
- package/src/modules/cpq/services/cpqValidationService.ts +323 -0
- package/src/modules/cpq/services/cpqWizardService.ts +204 -0
- package/src/modules/cpq/services/types.ts +303 -0
- package/src/modules/cpq/setup.ts +63 -0
- package/src/modules/cpq/subscribers/subscription-amended-log.ts +20 -0
- package/src/modules/cpq/subscribers/subscription-cancelled-log.ts +19 -0
- package/src/modules/cpq/subscribers/subscription-merged-log.ts +22 -0
- package/src/modules/cpq/subscribers/subscription-renewed-log.ts +18 -0
- package/src/modules/cpq/subscribers/subscription-superseded-log.ts +19 -0
- package/src/modules/cpq/widgets/injection/customer-inventory/widget.client.tsx +339 -0
- package/src/modules/cpq/widgets/injection/customer-inventory/widget.ts +16 -0
- package/src/modules/cpq/widgets/injection/order-cpq-tab/widget.client.tsx +96 -0
- package/src/modules/cpq/widgets/injection/order-cpq-tab/widget.ts +16 -0
- package/src/modules/cpq/widgets/injection/quote-configurator/widget.client.tsx +265 -0
- package/src/modules/cpq/widgets/injection/quote-configurator/widget.ts +16 -0
- package/src/modules/cpq/widgets/injection-table.ts +42 -0
- package/src/modules/cpq/workflows/WizardRunner.tsx +158 -0
- package/src/modules/cpq/workflows/WizardTrigger.tsx +142 -0
- package/src/modules/cpq/workflows/engine.tsx +278 -0
- package/src/modules/cpq/workflows/registry.ts +15 -0
- package/src/modules/cpq/workflows/steps/CustomerSelectStep.tsx +136 -0
- package/src/modules/cpq/workflows/steps/InventorySelectStep.tsx +34 -0
- package/src/modules/cpq/workflows/steps/ItemListStep.tsx +146 -0
- package/src/modules/cpq/workflows/steps/OfferingSelectStep.tsx +438 -0
- package/src/modules/cpq/workflows/steps/ProductConfigureStep.tsx +287 -0
- package/src/modules/cpq/workflows/steps/ReviewStep.tsx +219 -0
- package/src/modules/cpq/workflows/steps/index.ts +51 -0
- package/src/modules/cpq/workflows/types.ts +102 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
4
|
+
import { useParams, useRouter } from 'next/navigation'
|
|
5
|
+
import { Alert } from '@open-mercato/ui/primitives/alert'
|
|
6
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
7
|
+
import { Input } from '@open-mercato/ui/primitives/input'
|
|
8
|
+
import { Tag } from '@open-mercato/ui/primitives/tag'
|
|
9
|
+
import { Download, Trash2, Upload } from 'lucide-react'
|
|
10
|
+
import { EntriesEditor, type Entry } from './EntriesEditor'
|
|
11
|
+
import { exportPricingTableToXlsx } from './xlsxExport'
|
|
12
|
+
import {
|
|
13
|
+
commitImportDiff,
|
|
14
|
+
parsePricingTableXlsx,
|
|
15
|
+
type ImportDiff,
|
|
16
|
+
} from './xlsxImport'
|
|
17
|
+
import { ImportPreview } from './ImportPreview'
|
|
18
|
+
|
|
19
|
+
type Dimension = { key: string; label: string }
|
|
20
|
+
type PriceColumn = { key: string; label: string }
|
|
21
|
+
|
|
22
|
+
type PricingTable = {
|
|
23
|
+
id: string
|
|
24
|
+
code: string
|
|
25
|
+
name: string
|
|
26
|
+
dimensions: Dimension[]
|
|
27
|
+
priceColumns: PriceColumn[]
|
|
28
|
+
currencyCodeList: string[]
|
|
29
|
+
isActive: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const EMPTY_TABLE: PricingTable = {
|
|
33
|
+
id: '',
|
|
34
|
+
code: '',
|
|
35
|
+
name: '',
|
|
36
|
+
dimensions: [],
|
|
37
|
+
priceColumns: [],
|
|
38
|
+
currencyCodeList: ['USD'],
|
|
39
|
+
isActive: true,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
43
|
+
|
|
44
|
+
export default function PricingTableDetailPage(props: { params?: { id?: string } }) {
|
|
45
|
+
const t = useT()
|
|
46
|
+
const router = useRouter()
|
|
47
|
+
const urlParams = useParams()
|
|
48
|
+
const id = (props.params?.id ?? urlParams?.id) as string
|
|
49
|
+
const isNew = id === 'new'
|
|
50
|
+
|
|
51
|
+
const [table, setTable] = React.useState<PricingTable>(EMPTY_TABLE)
|
|
52
|
+
const [entries, setEntries] = React.useState<Entry[]>([])
|
|
53
|
+
const [loading, setLoading] = React.useState(!isNew)
|
|
54
|
+
const [error, setError] = React.useState<string | null>(null)
|
|
55
|
+
const [mode, setMode] = React.useState<'view' | 'edit'>(isNew ? 'edit' : 'view')
|
|
56
|
+
const [draft, setDraft] = React.useState<PricingTable>(EMPTY_TABLE)
|
|
57
|
+
const [saving, setSaving] = React.useState(false)
|
|
58
|
+
|
|
59
|
+
// Import state
|
|
60
|
+
const fileInputRef = React.useRef<HTMLInputElement>(null)
|
|
61
|
+
const [importDiff, setImportDiff] = React.useState<ImportDiff | null>(null)
|
|
62
|
+
const [importApplying, setImportApplying] = React.useState(false)
|
|
63
|
+
|
|
64
|
+
// ─── Load ────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
const load = React.useCallback(async () => {
|
|
67
|
+
if (isNew) return
|
|
68
|
+
if (!id || !UUID_RE.test(id)) {
|
|
69
|
+
setError('Invalid pricing table ID')
|
|
70
|
+
setLoading(false)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
setLoading(true)
|
|
74
|
+
try {
|
|
75
|
+
const res = await fetch(`/api/cpq/pricing-tables?id=${encodeURIComponent(id)}`)
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
setError('Pricing table not found')
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
const data = await res.json()
|
|
81
|
+
const loaded: PricingTable = {
|
|
82
|
+
id: data.id,
|
|
83
|
+
code: data.code,
|
|
84
|
+
name: data.name,
|
|
85
|
+
dimensions: data.dimensions ?? [],
|
|
86
|
+
priceColumns: data.priceColumns ?? [],
|
|
87
|
+
currencyCodeList: data.currencyCodeList ?? ['USD'],
|
|
88
|
+
isActive: data.isActive,
|
|
89
|
+
}
|
|
90
|
+
setTable(loaded)
|
|
91
|
+
setDraft(loaded)
|
|
92
|
+
setEntries(data.entries ?? [])
|
|
93
|
+
} catch (err) {
|
|
94
|
+
console.error('Failed to load pricing table', err)
|
|
95
|
+
setError('Failed to load')
|
|
96
|
+
} finally {
|
|
97
|
+
setLoading(false)
|
|
98
|
+
}
|
|
99
|
+
}, [id, isNew])
|
|
100
|
+
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
void load()
|
|
103
|
+
}, [load])
|
|
104
|
+
|
|
105
|
+
// ─── Config CRUD ────────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
const startEdit = () => {
|
|
108
|
+
setDraft(table)
|
|
109
|
+
setMode('edit')
|
|
110
|
+
setError(null)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const cancelEdit = () => {
|
|
114
|
+
if (isNew) {
|
|
115
|
+
router.push('/backend/cpq/pricing')
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
setDraft(table)
|
|
119
|
+
setMode('view')
|
|
120
|
+
setError(null)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Mirror V-PT-1 from validators.ts so the user gets feedback before the
|
|
124
|
+
// server rejects the payload.
|
|
125
|
+
const configValidationError = React.useMemo(() => {
|
|
126
|
+
if (!draft.code.trim()) return 'Code is required'
|
|
127
|
+
if (!draft.name.trim()) return 'Name is required'
|
|
128
|
+
if (draft.currencyCodeList.length === 0) return 'At least one currency is required'
|
|
129
|
+
const checkList = (items: Array<{ key: string; label: string }>, label: string): string | null => {
|
|
130
|
+
const seen = new Set<string>()
|
|
131
|
+
for (let i = 0; i < items.length; i++) {
|
|
132
|
+
const item = items[i]
|
|
133
|
+
if (!item.key.trim()) return `${label} #${i + 1}: key is required`
|
|
134
|
+
if (!item.label.trim()) return `${label} #${i + 1}: label is required`
|
|
135
|
+
if (seen.has(item.key)) return `${label}: duplicate key "${item.key}"`
|
|
136
|
+
seen.add(item.key)
|
|
137
|
+
}
|
|
138
|
+
return null
|
|
139
|
+
}
|
|
140
|
+
return checkList(draft.dimensions, 'Dimension') ?? checkList(draft.priceColumns, 'Price Column')
|
|
141
|
+
}, [draft])
|
|
142
|
+
|
|
143
|
+
const saveConfig = async () => {
|
|
144
|
+
if (configValidationError) {
|
|
145
|
+
setError(configValidationError)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
setSaving(true)
|
|
149
|
+
setError(null)
|
|
150
|
+
try {
|
|
151
|
+
const payload = {
|
|
152
|
+
code: draft.code,
|
|
153
|
+
name: draft.name,
|
|
154
|
+
dimensions: draft.dimensions,
|
|
155
|
+
priceColumns: draft.priceColumns,
|
|
156
|
+
currencyCodeList: draft.currencyCodeList,
|
|
157
|
+
isActive: draft.isActive,
|
|
158
|
+
}
|
|
159
|
+
const res = await fetch('/api/cpq/pricing-tables', {
|
|
160
|
+
method: isNew ? 'POST' : 'PUT',
|
|
161
|
+
headers: { 'Content-Type': 'application/json' },
|
|
162
|
+
body: JSON.stringify(isNew ? payload : { id, ...payload }),
|
|
163
|
+
})
|
|
164
|
+
if (!res.ok) {
|
|
165
|
+
const body = await res.json().catch(() => ({}))
|
|
166
|
+
setError(body.error ?? `Failed to ${isNew ? 'create' : 'save'} pricing table`)
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
const saved = await res.json()
|
|
170
|
+
if (isNew) {
|
|
171
|
+
router.push(`/backend/cpq/pricing/${saved.id}`)
|
|
172
|
+
} else {
|
|
173
|
+
setTable({ ...draft, id })
|
|
174
|
+
setMode('view')
|
|
175
|
+
}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.error('Failed to save', err)
|
|
178
|
+
setError('Failed to save')
|
|
179
|
+
} finally {
|
|
180
|
+
setSaving(false)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ─── Excel import ──────────────────────────────────────────
|
|
185
|
+
|
|
186
|
+
const handleImportFile = async (file: File) => {
|
|
187
|
+
setError(null)
|
|
188
|
+
const r = await parsePricingTableXlsx(
|
|
189
|
+
file,
|
|
190
|
+
{
|
|
191
|
+
dimensions: table.dimensions,
|
|
192
|
+
priceColumns: table.priceColumns,
|
|
193
|
+
currencyCodeList: table.currencyCodeList,
|
|
194
|
+
},
|
|
195
|
+
entries,
|
|
196
|
+
)
|
|
197
|
+
if (!r.ok) {
|
|
198
|
+
setError(r.error)
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
setImportDiff(r.diff)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const applyImportDiff = async () => {
|
|
205
|
+
if (!importDiff) return
|
|
206
|
+
setImportApplying(true)
|
|
207
|
+
setError(null)
|
|
208
|
+
try {
|
|
209
|
+
const r = await commitImportDiff(table.id, importDiff)
|
|
210
|
+
if (!r.ok) {
|
|
211
|
+
setError(r.error)
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
setImportDiff(null)
|
|
215
|
+
await load()
|
|
216
|
+
} finally {
|
|
217
|
+
setImportApplying(false)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const cancelImport = () => {
|
|
222
|
+
setImportDiff(null)
|
|
223
|
+
if (fileInputRef.current) fileInputRef.current.value = ''
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const deleteTable = async () => {
|
|
227
|
+
if (!window.confirm(t('cpq.pricing.confirmDelete', 'Delete this pricing table and all its entries?'))) return
|
|
228
|
+
try {
|
|
229
|
+
const res = await fetch('/api/cpq/pricing-tables', {
|
|
230
|
+
method: 'DELETE',
|
|
231
|
+
headers: { 'Content-Type': 'application/json' },
|
|
232
|
+
body: JSON.stringify({ id }),
|
|
233
|
+
})
|
|
234
|
+
if (res.ok) {
|
|
235
|
+
router.push('/backend/cpq/pricing')
|
|
236
|
+
} else {
|
|
237
|
+
const body = await res.json().catch(() => ({}))
|
|
238
|
+
setError(body.error ?? 'Failed to delete')
|
|
239
|
+
}
|
|
240
|
+
} catch {
|
|
241
|
+
setError('Failed to delete')
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ─── Render ────────────────────────────────────────────────
|
|
246
|
+
|
|
247
|
+
if (loading) {
|
|
248
|
+
return <div className="text-sm text-muted-foreground">{t('common.loading', 'Loading...')}</div>
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (error && !isNew && !table.id) {
|
|
252
|
+
return (
|
|
253
|
+
<div className="space-y-4">
|
|
254
|
+
<button
|
|
255
|
+
onClick={() => router.push('/backend/cpq/pricing')}
|
|
256
|
+
className="text-sm text-muted-foreground hover:text-foreground"
|
|
257
|
+
>
|
|
258
|
+
← {t('common.back', 'Back')}
|
|
259
|
+
</button>
|
|
260
|
+
<Alert variant="destructive">{error}</Alert>
|
|
261
|
+
</div>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const editing = mode === 'edit'
|
|
266
|
+
const view = editing ? draft : table
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<div className="space-y-6">
|
|
270
|
+
{/* Header */}
|
|
271
|
+
<div className="flex items-center justify-between">
|
|
272
|
+
<div className="flex items-center gap-3">
|
|
273
|
+
<button
|
|
274
|
+
onClick={() => router.push('/backend/cpq/pricing')}
|
|
275
|
+
className="text-sm text-muted-foreground hover:text-foreground"
|
|
276
|
+
>
|
|
277
|
+
← {t('common.back', 'Back')}
|
|
278
|
+
</button>
|
|
279
|
+
<h1 className="text-2xl font-bold">
|
|
280
|
+
{isNew ? t('cpq.pricing.new', 'New Pricing Table') : table.name}
|
|
281
|
+
</h1>
|
|
282
|
+
{!isNew && (
|
|
283
|
+
<Tag variant={table.isActive ? 'success' : 'neutral'} dot>
|
|
284
|
+
{table.isActive ? t('common.active', 'Active') : t('common.inactive', 'Inactive')}
|
|
285
|
+
</Tag>
|
|
286
|
+
)}
|
|
287
|
+
</div>
|
|
288
|
+
{!isNew && mode === 'view' && (
|
|
289
|
+
<div className="flex items-center gap-2">
|
|
290
|
+
<Button
|
|
291
|
+
type="button"
|
|
292
|
+
variant="outline"
|
|
293
|
+
onClick={() => exportPricingTableToXlsx(table, entries)}
|
|
294
|
+
title={t('cpq.pricing.export.tooltip', 'Download this pricing table as an Excel file')}
|
|
295
|
+
>
|
|
296
|
+
<Download className="h-4 w-4 mr-1.5" />
|
|
297
|
+
{t('cpq.pricing.export.button', 'Export to Excel')}
|
|
298
|
+
</Button>
|
|
299
|
+
<Button
|
|
300
|
+
type="button"
|
|
301
|
+
variant="outline"
|
|
302
|
+
onClick={() => fileInputRef.current?.click()}
|
|
303
|
+
title={t('cpq.pricing.import.tooltip', 'Upload an Excel file to add / update / delete entries')}
|
|
304
|
+
disabled={importDiff !== null}
|
|
305
|
+
>
|
|
306
|
+
<Upload className="h-4 w-4 mr-1.5" />
|
|
307
|
+
{t('cpq.pricing.import.button', 'Import from Excel')}
|
|
308
|
+
</Button>
|
|
309
|
+
<input
|
|
310
|
+
ref={fileInputRef}
|
|
311
|
+
type="file"
|
|
312
|
+
accept=".xlsx,.xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
313
|
+
className="hidden"
|
|
314
|
+
onChange={(e) => {
|
|
315
|
+
const file = e.target.files?.[0]
|
|
316
|
+
if (file) void handleImportFile(file)
|
|
317
|
+
// reset so re-uploading the same file fires onChange again
|
|
318
|
+
e.target.value = ''
|
|
319
|
+
}}
|
|
320
|
+
/>
|
|
321
|
+
<Button type="button" onClick={startEdit}>{t('common.edit', 'Edit')}</Button>
|
|
322
|
+
<Button type="button" variant="destructive" onClick={deleteTable}>
|
|
323
|
+
{t('common.delete', 'Delete')}
|
|
324
|
+
</Button>
|
|
325
|
+
</div>
|
|
326
|
+
)}
|
|
327
|
+
</div>
|
|
328
|
+
|
|
329
|
+
{error && <Alert variant="destructive">{error}</Alert>}
|
|
330
|
+
|
|
331
|
+
{/* Excel import preview — shown after a file is parsed, hides until user confirms / cancels */}
|
|
332
|
+
{importDiff && (
|
|
333
|
+
<ImportPreview
|
|
334
|
+
diff={importDiff}
|
|
335
|
+
saving={importApplying}
|
|
336
|
+
onConfirm={applyImportDiff}
|
|
337
|
+
onCancel={cancelImport}
|
|
338
|
+
/>
|
|
339
|
+
)}
|
|
340
|
+
|
|
341
|
+
{/* Configuration section */}
|
|
342
|
+
<div className="rounded-lg border bg-card p-6 space-y-4">
|
|
343
|
+
<h2 className="text-lg font-semibold">Configuration</h2>
|
|
344
|
+
|
|
345
|
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
346
|
+
<ConfigField label="Code" required>
|
|
347
|
+
{editing ? (
|
|
348
|
+
<Input
|
|
349
|
+
value={view.code}
|
|
350
|
+
onChange={(e) => setDraft({ ...draft, code: e.target.value })}
|
|
351
|
+
placeholder="e.g. cloud-connect-pricing"
|
|
352
|
+
/>
|
|
353
|
+
) : (
|
|
354
|
+
<span className="font-mono text-sm">{view.code}</span>
|
|
355
|
+
)}
|
|
356
|
+
</ConfigField>
|
|
357
|
+
<ConfigField label="Name" required>
|
|
358
|
+
{editing ? (
|
|
359
|
+
<Input
|
|
360
|
+
value={view.name}
|
|
361
|
+
onChange={(e) => setDraft({ ...draft, name: e.target.value })}
|
|
362
|
+
placeholder="Cloud Connect Pricing"
|
|
363
|
+
/>
|
|
364
|
+
) : (
|
|
365
|
+
<span className="font-medium text-sm">{view.name}</span>
|
|
366
|
+
)}
|
|
367
|
+
</ConfigField>
|
|
368
|
+
<ConfigField label="Currencies (comma-separated)" required>
|
|
369
|
+
{editing ? (
|
|
370
|
+
<Input
|
|
371
|
+
value={view.currencyCodeList.join(', ')}
|
|
372
|
+
onChange={(e) =>
|
|
373
|
+
setDraft({
|
|
374
|
+
...draft,
|
|
375
|
+
currencyCodeList: e.target.value
|
|
376
|
+
.split(',')
|
|
377
|
+
.map((s) => s.trim().toUpperCase())
|
|
378
|
+
.filter(Boolean),
|
|
379
|
+
})
|
|
380
|
+
}
|
|
381
|
+
placeholder="USD, EUR"
|
|
382
|
+
/>
|
|
383
|
+
) : (
|
|
384
|
+
<span className="text-sm">{view.currencyCodeList.join(', ') || '—'}</span>
|
|
385
|
+
)}
|
|
386
|
+
</ConfigField>
|
|
387
|
+
<ConfigField label="Active">
|
|
388
|
+
{editing ? (
|
|
389
|
+
<label className="flex items-center gap-2 text-sm">
|
|
390
|
+
<input
|
|
391
|
+
type="checkbox"
|
|
392
|
+
checked={view.isActive}
|
|
393
|
+
onChange={(e) => setDraft({ ...draft, isActive: e.target.checked })}
|
|
394
|
+
className="rounded border"
|
|
395
|
+
/>
|
|
396
|
+
{view.isActive ? 'Yes' : 'No'}
|
|
397
|
+
</label>
|
|
398
|
+
) : (
|
|
399
|
+
<span className="text-sm">{view.isActive ? 'Yes' : 'No'}</span>
|
|
400
|
+
)}
|
|
401
|
+
</ConfigField>
|
|
402
|
+
</div>
|
|
403
|
+
|
|
404
|
+
<KeyLabelListEditor
|
|
405
|
+
title="Dimensions"
|
|
406
|
+
description="Lookup keys for matching entries (e.g. region, tier). Leave empty if you use tier ranges only."
|
|
407
|
+
items={view.dimensions}
|
|
408
|
+
editing={editing}
|
|
409
|
+
onChange={(dimensions) => setDraft({ ...draft, dimensions })}
|
|
410
|
+
/>
|
|
411
|
+
|
|
412
|
+
<KeyLabelListEditor
|
|
413
|
+
title="Price Columns"
|
|
414
|
+
description="Each price column becomes a numeric field on every entry. Charges reference one column by its key."
|
|
415
|
+
items={view.priceColumns}
|
|
416
|
+
editing={editing}
|
|
417
|
+
onChange={(priceColumns) => setDraft({ ...draft, priceColumns })}
|
|
418
|
+
/>
|
|
419
|
+
|
|
420
|
+
{editing && (
|
|
421
|
+
<>
|
|
422
|
+
{configValidationError && (
|
|
423
|
+
<Alert variant="destructive">{configValidationError}</Alert>
|
|
424
|
+
)}
|
|
425
|
+
<div className="flex gap-2 pt-2 border-t">
|
|
426
|
+
<Button
|
|
427
|
+
type="button"
|
|
428
|
+
onClick={saveConfig}
|
|
429
|
+
disabled={saving || configValidationError !== null}
|
|
430
|
+
>
|
|
431
|
+
{saving ? 'Saving...' : (isNew ? 'Create Pricing Table' : 'Save')}
|
|
432
|
+
</Button>
|
|
433
|
+
<Button type="button" variant="outline" onClick={cancelEdit} disabled={saving}>
|
|
434
|
+
Cancel
|
|
435
|
+
</Button>
|
|
436
|
+
</div>
|
|
437
|
+
</>
|
|
438
|
+
)}
|
|
439
|
+
</div>
|
|
440
|
+
|
|
441
|
+
{/* Entries section — only when table exists */}
|
|
442
|
+
{!isNew && (
|
|
443
|
+
<EntriesEditor
|
|
444
|
+
table={{
|
|
445
|
+
id: table.id,
|
|
446
|
+
dimensions: table.dimensions,
|
|
447
|
+
priceColumns: table.priceColumns,
|
|
448
|
+
currencyCodeList: table.currencyCodeList,
|
|
449
|
+
}}
|
|
450
|
+
initialEntries={entries}
|
|
451
|
+
onSaved={() => {
|
|
452
|
+
void load()
|
|
453
|
+
}}
|
|
454
|
+
/>
|
|
455
|
+
)}
|
|
456
|
+
</div>
|
|
457
|
+
)
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ─── ConfigField ────────────────────────────────────────────────
|
|
461
|
+
|
|
462
|
+
function ConfigField({
|
|
463
|
+
label,
|
|
464
|
+
required,
|
|
465
|
+
children,
|
|
466
|
+
}: {
|
|
467
|
+
label: string
|
|
468
|
+
required?: boolean
|
|
469
|
+
children: React.ReactNode
|
|
470
|
+
}) {
|
|
471
|
+
return (
|
|
472
|
+
<div>
|
|
473
|
+
<div className="text-muted-foreground text-xs mb-1">
|
|
474
|
+
{label}
|
|
475
|
+
{required && <span className="text-destructive ml-1">*</span>}
|
|
476
|
+
</div>
|
|
477
|
+
<div>{children}</div>
|
|
478
|
+
</div>
|
|
479
|
+
)
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ─── KeyLabelListEditor (dimensions / price columns) ─────────
|
|
483
|
+
|
|
484
|
+
function KeyLabelListEditor({
|
|
485
|
+
title,
|
|
486
|
+
description,
|
|
487
|
+
items,
|
|
488
|
+
editing,
|
|
489
|
+
onChange,
|
|
490
|
+
}: {
|
|
491
|
+
title: string
|
|
492
|
+
description: string
|
|
493
|
+
items: Array<{ key: string; label: string }>
|
|
494
|
+
editing: boolean
|
|
495
|
+
onChange: (next: Array<{ key: string; label: string }>) => void
|
|
496
|
+
}) {
|
|
497
|
+
return (
|
|
498
|
+
<div className="space-y-2">
|
|
499
|
+
<div>
|
|
500
|
+
<div className="text-sm font-medium">{title}</div>
|
|
501
|
+
<p className="text-xs text-muted-foreground">{description}</p>
|
|
502
|
+
</div>
|
|
503
|
+
|
|
504
|
+
{items.length === 0 && !editing && (
|
|
505
|
+
<div className="text-xs text-muted-foreground italic">—</div>
|
|
506
|
+
)}
|
|
507
|
+
|
|
508
|
+
{items.length > 0 && (
|
|
509
|
+
<div className="rounded-md border">
|
|
510
|
+
<table className="w-full text-sm">
|
|
511
|
+
<thead>
|
|
512
|
+
<tr className="border-b bg-muted/30 text-xs">
|
|
513
|
+
<th className="px-3 py-2 text-left font-medium">
|
|
514
|
+
Key {editing && <span className="text-destructive">*</span>}
|
|
515
|
+
</th>
|
|
516
|
+
<th className="px-3 py-2 text-left font-medium">
|
|
517
|
+
Label {editing && <span className="text-destructive">*</span>}
|
|
518
|
+
</th>
|
|
519
|
+
{editing && <th className="px-3 py-2 w-8" aria-label="Actions" />}
|
|
520
|
+
</tr>
|
|
521
|
+
</thead>
|
|
522
|
+
<tbody>
|
|
523
|
+
{items.map((item, idx) => (
|
|
524
|
+
<tr key={idx} className="border-b last:border-0">
|
|
525
|
+
<td className="px-3 py-2">
|
|
526
|
+
{editing ? (
|
|
527
|
+
<Input
|
|
528
|
+
value={item.key}
|
|
529
|
+
onChange={(e) => {
|
|
530
|
+
const next = [...items]
|
|
531
|
+
next[idx] = { ...item, key: e.target.value }
|
|
532
|
+
onChange(next)
|
|
533
|
+
}}
|
|
534
|
+
placeholder="e.g. region"
|
|
535
|
+
className="h-8"
|
|
536
|
+
/>
|
|
537
|
+
) : (
|
|
538
|
+
<span className="font-mono text-xs">{item.key}</span>
|
|
539
|
+
)}
|
|
540
|
+
</td>
|
|
541
|
+
<td className="px-3 py-2">
|
|
542
|
+
{editing ? (
|
|
543
|
+
<Input
|
|
544
|
+
value={item.label}
|
|
545
|
+
onChange={(e) => {
|
|
546
|
+
const next = [...items]
|
|
547
|
+
next[idx] = { ...item, label: e.target.value }
|
|
548
|
+
onChange(next)
|
|
549
|
+
}}
|
|
550
|
+
placeholder="Region"
|
|
551
|
+
className="h-8"
|
|
552
|
+
/>
|
|
553
|
+
) : (
|
|
554
|
+
<span>{item.label}</span>
|
|
555
|
+
)}
|
|
556
|
+
</td>
|
|
557
|
+
{editing && (
|
|
558
|
+
<td className="px-3 py-2">
|
|
559
|
+
<button
|
|
560
|
+
type="button"
|
|
561
|
+
onClick={() => onChange(items.filter((_, i) => i !== idx))}
|
|
562
|
+
className="text-destructive hover:bg-destructive/10 rounded p-1"
|
|
563
|
+
aria-label="Remove"
|
|
564
|
+
>
|
|
565
|
+
<Trash2 className="h-4 w-4" />
|
|
566
|
+
</button>
|
|
567
|
+
</td>
|
|
568
|
+
)}
|
|
569
|
+
</tr>
|
|
570
|
+
))}
|
|
571
|
+
</tbody>
|
|
572
|
+
</table>
|
|
573
|
+
</div>
|
|
574
|
+
)}
|
|
575
|
+
|
|
576
|
+
{editing && (
|
|
577
|
+
<Button
|
|
578
|
+
type="button"
|
|
579
|
+
variant="outline"
|
|
580
|
+
size="sm"
|
|
581
|
+
onClick={() => onChange([...items, { key: '', label: '' }])}
|
|
582
|
+
>
|
|
583
|
+
+ Add {title.slice(0, -1)}
|
|
584
|
+
</Button>
|
|
585
|
+
)}
|
|
586
|
+
</div>
|
|
587
|
+
)
|
|
588
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Browser-side Excel export for pricing tables.
|
|
2
|
+
//
|
|
3
|
+
// Single sheet, dimensions-as-columns per user spec. Tier columns are
|
|
4
|
+
// emitted only when at least one entry is tiered, to keep the file
|
|
5
|
+
// uncluttered for dimensions-only tables. Each price column becomes one
|
|
6
|
+
// numeric column.
|
|
7
|
+
|
|
8
|
+
import * as XLSX from 'xlsx'
|
|
9
|
+
|
|
10
|
+
type Dimension = { key: string; label: string }
|
|
11
|
+
type PriceColumn = { key: string; label: string }
|
|
12
|
+
|
|
13
|
+
type Entry = {
|
|
14
|
+
id: string
|
|
15
|
+
dimensionValues: Record<string, string>
|
|
16
|
+
tierNumber: number | null
|
|
17
|
+
rangeFrom: string | null
|
|
18
|
+
rangeTo: string | null
|
|
19
|
+
currencyCode: string
|
|
20
|
+
prices: Record<string, number>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Table = {
|
|
24
|
+
code: string
|
|
25
|
+
name: string
|
|
26
|
+
dimensions: Dimension[]
|
|
27
|
+
priceColumns: PriceColumn[]
|
|
28
|
+
currencyCodeList: string[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function exportPricingTableToXlsx(table: Table, entries: Entry[]): void {
|
|
32
|
+
const hasTiers = entries.some((e) => e.tierNumber != null)
|
|
33
|
+
|
|
34
|
+
// Column order: id, [tier columns?], dimensions, price columns, currency.
|
|
35
|
+
// The id column is intentionally last-of-leading so it doesn't bury data,
|
|
36
|
+
// but kept exposed so a future re-import can match rows by UUID.
|
|
37
|
+
const headers: string[] = ['id']
|
|
38
|
+
if (hasTiers) {
|
|
39
|
+
headers.push('tier_number', 'range_from', 'range_to')
|
|
40
|
+
}
|
|
41
|
+
for (const d of table.dimensions) headers.push(d.key)
|
|
42
|
+
for (const c of table.priceColumns) headers.push(c.key)
|
|
43
|
+
headers.push('currency_code')
|
|
44
|
+
|
|
45
|
+
const rows: Array<Record<string, unknown>> = entries.map((e) => {
|
|
46
|
+
const row: Record<string, unknown> = { id: e.id }
|
|
47
|
+
if (hasTiers) {
|
|
48
|
+
row.tier_number = e.tierNumber ?? ''
|
|
49
|
+
row.range_from = e.rangeFrom ?? ''
|
|
50
|
+
row.range_to = e.rangeTo ?? ''
|
|
51
|
+
}
|
|
52
|
+
for (const d of table.dimensions) {
|
|
53
|
+
row[d.key] = e.dimensionValues?.[d.key] ?? ''
|
|
54
|
+
}
|
|
55
|
+
for (const c of table.priceColumns) {
|
|
56
|
+
row[c.key] = e.prices?.[c.key] ?? ''
|
|
57
|
+
}
|
|
58
|
+
row.currency_code = e.currencyCode
|
|
59
|
+
return row
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const worksheet = XLSX.utils.json_to_sheet(rows, { header: headers })
|
|
63
|
+
|
|
64
|
+
// Replace technical keys with human labels in the header row so the file
|
|
65
|
+
// reads naturally in Excel. The first row is the only one with labels;
|
|
66
|
+
// keep `id` / tier_* / currency_code as-is because they have no label.
|
|
67
|
+
const labelRow: Record<string, string> = {}
|
|
68
|
+
for (const d of table.dimensions) labelRow[d.key] = d.label
|
|
69
|
+
for (const c of table.priceColumns) labelRow[c.key] = c.label
|
|
70
|
+
XLSX.utils.sheet_add_aoa(
|
|
71
|
+
worksheet,
|
|
72
|
+
[headers.map((h) => labelRow[h] ?? h)],
|
|
73
|
+
{ origin: 'A1' },
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const workbook = XLSX.utils.book_new()
|
|
77
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetSafeName(table.code || table.name || 'Pricing'))
|
|
78
|
+
|
|
79
|
+
const filename = `${slugForFile(table.code || table.name || 'pricing-table')}.xlsx`
|
|
80
|
+
XLSX.writeFile(workbook, filename)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Excel sheet names: max 31 chars, no `[]:*?/\`.
|
|
84
|
+
function sheetSafeName(name: string): string {
|
|
85
|
+
return name.replace(/[\[\]:*?/\\]/g, '_').slice(0, 31)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function slugForFile(name: string): string {
|
|
89
|
+
return name.toLowerCase().replace(/[^a-z0-9-_.]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'pricing-table'
|
|
90
|
+
}
|