@open-mercato/core 0.6.7-develop.6669.1.40b669666b → 0.6.7-develop.6670.1.4efa7961c6
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/.turbo/turbo-build.log +2 -2
- package/dist/generated/entities/inventory_balance/index.js +21 -0
- package/dist/generated/entities/inventory_balance/index.js.map +7 -0
- package/dist/generated/entities/inventory_lot/index.js +19 -0
- package/dist/generated/entities/inventory_lot/index.js.map +7 -0
- package/dist/generated/entities/inventory_movement/index.js +35 -0
- package/dist/generated/entities/inventory_movement/index.js.map +7 -0
- package/dist/generated/entities/inventory_reservation/index.js +23 -0
- package/dist/generated/entities/inventory_reservation/index.js.map +7 -0
- package/dist/generated/entities/product_inventory_profile/index.js +21 -0
- package/dist/generated/entities/product_inventory_profile/index.js.map +7 -0
- package/dist/generated/entities/sales_order_warehouse_assignment/index.js +11 -0
- package/dist/generated/entities/sales_order_warehouse_assignment/index.js.map +7 -0
- package/dist/generated/entities/warehouse/index.js +25 -0
- package/dist/generated/entities/warehouse/index.js.map +7 -0
- package/dist/generated/entities/warehouse_location/index.js +21 -0
- package/dist/generated/entities/warehouse_location/index.js.map +7 -0
- package/dist/generated/entities/warehouse_zone/index.js +11 -0
- package/dist/generated/entities/warehouse_zone/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +12 -0
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +98 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/auth/backend/roles/page.js +12 -4
- package/dist/modules/auth/backend/roles/page.js.map +2 -2
- package/dist/modules/auth/lib/backendChrome.js +1 -0
- package/dist/modules/auth/lib/backendChrome.js.map +2 -2
- package/dist/modules/auth/services/rbacService.js +16 -17
- package/dist/modules/auth/services/rbacService.js.map +2 -2
- package/dist/modules/catalog/api/products/route.js +3 -0
- package/dist/modules/catalog/api/products/route.js.map +2 -2
- package/dist/modules/catalog/api/variants/route.js +3 -0
- package/dist/modules/catalog/api/variants/route.js.map +2 -2
- package/dist/modules/query_index/lib/engine.js +6 -6
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/sales/api/documents/factory.js +1 -0
- package/dist/modules/sales/api/documents/factory.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +53 -0
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/components/documents/ItemsSection.js +51 -2
- package/dist/modules/sales/components/documents/ItemsSection.js.map +2 -2
- package/dist/modules/sales/events.js +2 -0
- package/dist/modules/sales/events.js.map +2 -2
- package/dist/modules/sales/widgets/injection/order-items-context.js +11 -0
- package/dist/modules/sales/widgets/injection/order-items-context.js.map +7 -0
- package/dist/modules/wms/acl.js +18 -0
- package/dist/modules/wms/acl.js.map +7 -0
- package/dist/modules/wms/analytics.js +11 -0
- package/dist/modules/wms/analytics.js.map +7 -0
- package/dist/modules/wms/api/dashboard/operational/route.js +80 -0
- package/dist/modules/wms/api/dashboard/operational/route.js.map +7 -0
- package/dist/modules/wms/api/interceptors.js +90 -0
- package/dist/modules/wms/api/interceptors.js.map +7 -0
- package/dist/modules/wms/api/inventory/adjust/route.js +51 -0
- package/dist/modules/wms/api/inventory/adjust/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/allocate/route.js +51 -0
- package/dist/modules/wms/api/inventory/allocate/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/balances/route.js +172 -0
- package/dist/modules/wms/api/inventory/balances/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/cycle-count/route.js +52 -0
- package/dist/modules/wms/api/inventory/cycle-count/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/helpers.js +113 -0
- package/dist/modules/wms/api/inventory/helpers.js.map +7 -0
- package/dist/modules/wms/api/inventory/import/apply/route.js +46 -0
- package/dist/modules/wms/api/inventory/import/apply/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/import/helpers.js +195 -0
- package/dist/modules/wms/api/inventory/import/helpers.js.map +7 -0
- package/dist/modules/wms/api/inventory/import/template/route.js +32 -0
- package/dist/modules/wms/api/inventory/import/template/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/import/validate/route.js +54 -0
- package/dist/modules/wms/api/inventory/import/validate/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/move/route.js +51 -0
- package/dist/modules/wms/api/inventory/move/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/movements/route.js +164 -0
- package/dist/modules/wms/api/inventory/movements/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/receive/route.js +50 -0
- package/dist/modules/wms/api/inventory/receive/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/release/route.js +44 -0
- package/dist/modules/wms/api/inventory/release/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/reservations/route.js +128 -0
- package/dist/modules/wms/api/inventory/reservations/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/reserve/route.js +59 -0
- package/dist/modules/wms/api/inventory/reserve/route.js.map +7 -0
- package/dist/modules/wms/api/inventory-profiles/route.js +178 -0
- package/dist/modules/wms/api/inventory-profiles/route.js.map +7 -0
- package/dist/modules/wms/api/listEnrichers.js +181 -0
- package/dist/modules/wms/api/listEnrichers.js.map +7 -0
- package/dist/modules/wms/api/listSearch.js +77 -0
- package/dist/modules/wms/api/listSearch.js.map +7 -0
- package/dist/modules/wms/api/locations/route.js +172 -0
- package/dist/modules/wms/api/locations/route.js.map +7 -0
- package/dist/modules/wms/api/lots/route.js +204 -0
- package/dist/modules/wms/api/lots/route.js.map +7 -0
- package/dist/modules/wms/api/openapi.js +27 -0
- package/dist/modules/wms/api/openapi.js.map +7 -0
- package/dist/modules/wms/api/sales-orders/[salesOrderId]/re-run-reservation/route.js +54 -0
- package/dist/modules/wms/api/sales-orders/[salesOrderId]/re-run-reservation/route.js.map +7 -0
- package/dist/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.js +279 -0
- package/dist/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.js.map +7 -0
- package/dist/modules/wms/api/sales-orders/assign-warehouse/route.js +56 -0
- package/dist/modules/wms/api/sales-orders/assign-warehouse/route.js.map +7 -0
- package/dist/modules/wms/api/sales-orders/unassign-warehouse/route.js +43 -0
- package/dist/modules/wms/api/sales-orders/unassign-warehouse/route.js.map +7 -0
- package/dist/modules/wms/api/warehouses/route.js +181 -0
- package/dist/modules/wms/api/warehouses/route.js.map +7 -0
- package/dist/modules/wms/api/zones/route.js +159 -0
- package/dist/modules/wms/api/zones/route.js.map +7 -0
- package/dist/modules/wms/backend/config/wms/page.js +9 -0
- package/dist/modules/wms/backend/config/wms/page.js.map +7 -0
- package/dist/modules/wms/backend/config/wms/page.meta.js +18 -0
- package/dist/modules/wms/backend/config/wms/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/page.js +9 -0
- package/dist/modules/wms/backend/page.js.map +7 -0
- package/dist/modules/wms/backend/page.meta.js +16 -0
- package/dist/modules/wms/backend/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/inventory/page.js +9 -0
- package/dist/modules/wms/backend/wms/inventory/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/inventory/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/inventory/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/location/[id]/page.js +9 -0
- package/dist/modules/wms/backend/wms/location/[id]/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/location/[id]/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/location/[id]/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/locations/page.js +10 -0
- package/dist/modules/wms/backend/wms/locations/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/locations/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/locations/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/lot/[id]/page.js +9 -0
- package/dist/modules/wms/backend/wms/lot/[id]/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/lot/[id]/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/lot/[id]/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/lots/page.js +9 -0
- package/dist/modules/wms/backend/wms/lots/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/lots/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/lots/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/movements/page.js +22 -0
- package/dist/modules/wms/backend/wms/movements/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/movements/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/movements/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/reservations/page.js +23 -0
- package/dist/modules/wms/backend/wms/reservations/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/reservations/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/reservations/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/sku/[id]/page.js +9 -0
- package/dist/modules/wms/backend/wms/sku/[id]/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/sku/[id]/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/sku/[id]/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/warehouses/page.js +10 -0
- package/dist/modules/wms/backend/wms/warehouses/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/warehouses/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/warehouses/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/zones/page.js +10 -0
- package/dist/modules/wms/backend/wms/zones/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/zones/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/zones/page.meta.js.map +7 -0
- package/dist/modules/wms/ce.js +80 -0
- package/dist/modules/wms/ce.js.map +7 -0
- package/dist/modules/wms/cli.js +83 -0
- package/dist/modules/wms/cli.js.map +7 -0
- package/dist/modules/wms/commands/configuration.js +1519 -0
- package/dist/modules/wms/commands/configuration.js.map +7 -0
- package/dist/modules/wms/commands/index.js +4 -0
- package/dist/modules/wms/commands/index.js.map +7 -0
- package/dist/modules/wms/commands/inventory-actions.js +1539 -0
- package/dist/modules/wms/commands/inventory-actions.js.map +7 -0
- package/dist/modules/wms/commands/sales-order-assignment.js +277 -0
- package/dist/modules/wms/commands/sales-order-assignment.js.map +7 -0
- package/dist/modules/wms/commands/shared.js +82 -0
- package/dist/modules/wms/commands/shared.js.map +7 -0
- package/dist/modules/wms/components/backend/AdjustInventoryDialog.js +755 -0
- package/dist/modules/wms/components/backend/AdjustInventoryDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/ChangeLotStatusDialog.js +269 -0
- package/dist/modules/wms/components/backend/ChangeLotStatusDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/CycleCountWizardDialog.js +1783 -0
- package/dist/modules/wms/components/backend/CycleCountWizardDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/ImportInventoryDialog.js +766 -0
- package/dist/modules/wms/components/backend/ImportInventoryDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/InventoryOperationsSection.js +119 -0
- package/dist/modules/wms/components/backend/InventoryOperationsSection.js.map +7 -0
- package/dist/modules/wms/components/backend/LocationEditDialog.js +140 -0
- package/dist/modules/wms/components/backend/LocationEditDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/MoveInventoryDialog.js +791 -0
- package/dist/modules/wms/components/backend/MoveInventoryDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js +656 -0
- package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/ReleaseReservationDialog.js +344 -0
- package/dist/modules/wms/components/backend/ReleaseReservationDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/ReserveInventoryDialog.js +475 -0
- package/dist/modules/wms/components/backend/ReserveInventoryDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsConfigurationPage.js +1112 -0
- package/dist/modules/wms/components/backend/WmsConfigurationPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsInventoryConsolePage.js +908 -0
- package/dist/modules/wms/components/backend/WmsInventoryConsolePage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +1015 -0
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js +1049 -0
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsLotsListPage.js +297 -0
- package/dist/modules/wms/components/backend/WmsLotsListPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js +757 -0
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +975 -0
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +7 -0
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js +710 -0
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js.map +7 -0
- package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js +79 -0
- package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js.map +7 -0
- package/dist/modules/wms/components/backend/useWmsInventoryScopeFromSearchParams.js +24 -0
- package/dist/modules/wms/components/backend/useWmsInventoryScopeFromSearchParams.js.map +7 -0
- package/dist/modules/wms/components/backend/wmsLookupLoaders.js +55 -0
- package/dist/modules/wms/components/backend/wmsLookupLoaders.js.map +7 -0
- package/dist/modules/wms/data/enrichers.js +501 -0
- package/dist/modules/wms/data/enrichers.js.map +7 -0
- package/dist/modules/wms/data/entities.js +467 -0
- package/dist/modules/wms/data/entities.js.map +7 -0
- package/dist/modules/wms/data/validators.js +399 -0
- package/dist/modules/wms/data/validators.js.map +7 -0
- package/dist/modules/wms/di.js +27 -0
- package/dist/modules/wms/di.js.map +7 -0
- package/dist/modules/wms/events.js +42 -0
- package/dist/modules/wms/events.js.map +7 -0
- package/dist/modules/wms/index.js +17 -0
- package/dist/modules/wms/index.js.map +7 -0
- package/dist/modules/wms/lib/catalogInventoryProfileIntent.js +54 -0
- package/dist/modules/wms/lib/catalogInventoryProfileIntent.js.map +7 -0
- package/dist/modules/wms/lib/catalogInventoryProfileSync.js +144 -0
- package/dist/modules/wms/lib/catalogInventoryProfileSync.js.map +7 -0
- package/dist/modules/wms/lib/expiry.js +29 -0
- package/dist/modules/wms/lib/expiry.js.map +7 -0
- package/dist/modules/wms/lib/flashMutationError.js +51 -0
- package/dist/modules/wms/lib/flashMutationError.js.map +7 -0
- package/dist/modules/wms/lib/inventoryDisplayUi.js +188 -0
- package/dist/modules/wms/lib/inventoryDisplayUi.js.map +7 -0
- package/dist/modules/wms/lib/inventoryIdempotency.js +37 -0
- package/dist/modules/wms/lib/inventoryIdempotency.js.map +7 -0
- package/dist/modules/wms/lib/inventoryImportCsv.js +173 -0
- package/dist/modules/wms/lib/inventoryImportCsv.js.map +7 -0
- package/dist/modules/wms/lib/inventoryImportService.js +468 -0
- package/dist/modules/wms/lib/inventoryImportService.js.map +7 -0
- package/dist/modules/wms/lib/inventoryMutationUi.js +25 -0
- package/dist/modules/wms/lib/inventoryMutationUi.js.map +7 -0
- package/dist/modules/wms/lib/inventoryPolicy.js +61 -0
- package/dist/modules/wms/lib/inventoryPolicy.js.map +7 -0
- package/dist/modules/wms/lib/inventoryReconciliation.js +193 -0
- package/dist/modules/wms/lib/inventoryReconciliation.js.map +7 -0
- package/dist/modules/wms/lib/inventoryTrackingValidation.js +13 -0
- package/dist/modules/wms/lib/inventoryTrackingValidation.js.map +7 -0
- package/dist/modules/wms/lib/loadOperationalDashboard.js +580 -0
- package/dist/modules/wms/lib/loadOperationalDashboard.js.map +7 -0
- package/dist/modules/wms/lib/lowStockBalanceFilter.js +49 -0
- package/dist/modules/wms/lib/lowStockBalanceFilter.js.map +7 -0
- package/dist/modules/wms/lib/primaryWarehousePolicy.js +32 -0
- package/dist/modules/wms/lib/primaryWarehousePolicy.js.map +7 -0
- package/dist/modules/wms/lib/roleFeatures.js +30 -0
- package/dist/modules/wms/lib/roleFeatures.js.map +7 -0
- package/dist/modules/wms/lib/salesOrderInventoryAutomation.js +291 -0
- package/dist/modules/wms/lib/salesOrderInventoryAutomation.js.map +7 -0
- package/dist/modules/wms/lib/salesOrderWarehouseAssignment.js +54 -0
- package/dist/modules/wms/lib/salesOrderWarehouseAssignment.js.map +7 -0
- package/dist/modules/wms/lib/wmsIntegrationToggles.js +71 -0
- package/dist/modules/wms/lib/wmsIntegrationToggles.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260428110546.js +78 -0
- package/dist/modules/wms/migrations/Migration20260428110546.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260527120000.js +15 -0
- package/dist/modules/wms/migrations/Migration20260527120000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260527140000.js +37 -0
- package/dist/modules/wms/migrations/Migration20260527140000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260613120000.js +23 -0
- package/dist/modules/wms/migrations/Migration20260613120000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260616090000.js +13 -0
- package/dist/modules/wms/migrations/Migration20260616090000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260707180000.js +15 -0
- package/dist/modules/wms/migrations/Migration20260707180000.js.map +7 -0
- package/dist/modules/wms/notifications.client.js +18 -0
- package/dist/modules/wms/notifications.client.js.map +7 -0
- package/dist/modules/wms/notifications.js +53 -0
- package/dist/modules/wms/notifications.js.map +7 -0
- package/dist/modules/wms/search.js +196 -0
- package/dist/modules/wms/search.js.map +7 -0
- package/dist/modules/wms/setup.js +30 -0
- package/dist/modules/wms/setup.js.map +7 -0
- package/dist/modules/wms/subscribers/low-stock-notification.js +40 -0
- package/dist/modules/wms/subscribers/low-stock-notification.js.map +7 -0
- package/dist/modules/wms/subscribers/reservation-shortfall-notification.js +69 -0
- package/dist/modules/wms/subscribers/reservation-shortfall-notification.js.map +7 -0
- package/dist/modules/wms/subscribers/sales-order-cancelled-release.js +14 -0
- package/dist/modules/wms/subscribers/sales-order-cancelled-release.js.map +7 -0
- package/dist/modules/wms/subscribers/sales-order-confirmed-reserve.js +14 -0
- package/dist/modules/wms/subscribers/sales-order-confirmed-reserve.js.map +7 -0
- package/dist/modules/wms/translations.js +10 -0
- package/dist/modules/wms/translations.js.map +7 -0
- package/dist/modules/wms/vector.js +9 -0
- package/dist/modules/wms/vector.js.map +7 -0
- package/dist/modules/wms/widgets/injection/catalog-inventory-profile/widget.js +200 -0
- package/dist/modules/wms/widgets/injection/catalog-inventory-profile/widget.js.map +7 -0
- package/dist/modules/wms/widgets/injection/order-items-stock-column/widget.js +104 -0
- package/dist/modules/wms/widgets/injection/order-items-stock-column/widget.js.map +7 -0
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js +389 -0
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js.map +7 -0
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.js +16 -0
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.js.map +7 -0
- package/dist/modules/wms/widgets/injection-table.js +36 -0
- package/dist/modules/wms/widgets/injection-table.js.map +7 -0
- package/dist/modules/wms/widgets/notifications/WmsLowStockRenderer.js +150 -0
- package/dist/modules/wms/widgets/notifications/WmsLowStockRenderer.js.map +7 -0
- package/dist/modules/wms/widgets/notifications/WmsReservationShortfallRenderer.js +186 -0
- package/dist/modules/wms/widgets/notifications/WmsReservationShortfallRenderer.js.map +7 -0
- package/dist/modules/wms/widgets/notifications/index.js +7 -0
- package/dist/modules/wms/widgets/notifications/index.js.map +7 -0
- package/generated/entities/inventory_balance/index.ts +9 -0
- package/generated/entities/inventory_lot/index.ts +8 -0
- package/generated/entities/inventory_movement/index.ts +16 -0
- package/generated/entities/inventory_reservation/index.ts +10 -0
- package/generated/entities/product_inventory_profile/index.ts +9 -0
- package/generated/entities/sales_order_warehouse_assignment/index.ts +4 -0
- package/generated/entities/warehouse/index.ts +11 -0
- package/generated/entities/warehouse_location/index.ts +9 -0
- package/generated/entities/warehouse_zone/index.ts +4 -0
- package/generated/entities.ids.generated.ts +12 -0
- package/generated/entity-fields-registry.ts +98 -0
- package/package.json +7 -7
- package/src/modules/auth/backend/roles/page.tsx +13 -4
- package/src/modules/auth/i18n/de.json +2 -0
- package/src/modules/auth/i18n/en.json +2 -0
- package/src/modules/auth/i18n/es.json +2 -0
- package/src/modules/auth/i18n/pl.json +2 -0
- package/src/modules/auth/lib/backendChrome.tsx +1 -0
- package/src/modules/auth/services/rbacService.ts +25 -21
- package/src/modules/catalog/api/products/route.ts +3 -0
- package/src/modules/catalog/api/variants/route.ts +3 -0
- package/src/modules/query_index/lib/engine.ts +18 -6
- package/src/modules/sales/api/documents/factory.ts +1 -0
- package/src/modules/sales/commands/documents.ts +71 -0
- package/src/modules/sales/components/documents/ItemsSection.tsx +58 -0
- package/src/modules/sales/events.ts +2 -0
- package/src/modules/sales/widgets/injection/order-items-context.ts +15 -0
- package/src/modules/wms/acl.ts +14 -0
- package/src/modules/wms/analytics.ts +9 -0
- package/src/modules/wms/api/dashboard/operational/route.ts +83 -0
- package/src/modules/wms/api/interceptors.ts +108 -0
- package/src/modules/wms/api/inventory/adjust/route.ts +50 -0
- package/src/modules/wms/api/inventory/allocate/route.ts +50 -0
- package/src/modules/wms/api/inventory/balances/route.ts +178 -0
- package/src/modules/wms/api/inventory/cycle-count/route.ts +51 -0
- package/src/modules/wms/api/inventory/helpers.ts +128 -0
- package/src/modules/wms/api/inventory/import/apply/route.ts +47 -0
- package/src/modules/wms/api/inventory/import/helpers.ts +223 -0
- package/src/modules/wms/api/inventory/import/template/route.ts +31 -0
- package/src/modules/wms/api/inventory/import/validate/route.ts +56 -0
- package/src/modules/wms/api/inventory/move/route.ts +50 -0
- package/src/modules/wms/api/inventory/movements/route.ts +164 -0
- package/src/modules/wms/api/inventory/receive/route.ts +49 -0
- package/src/modules/wms/api/inventory/release/route.ts +43 -0
- package/src/modules/wms/api/inventory/reservations/route.ts +128 -0
- package/src/modules/wms/api/inventory/reserve/route.ts +59 -0
- package/src/modules/wms/api/inventory-profiles/route.ts +177 -0
- package/src/modules/wms/api/listEnrichers.ts +312 -0
- package/src/modules/wms/api/listSearch.ts +121 -0
- package/src/modules/wms/api/locations/route.ts +171 -0
- package/src/modules/wms/api/lots/route.ts +205 -0
- package/src/modules/wms/api/openapi.ts +28 -0
- package/src/modules/wms/api/sales-orders/[salesOrderId]/re-run-reservation/route.ts +58 -0
- package/src/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.ts +306 -0
- package/src/modules/wms/api/sales-orders/assign-warehouse/route.ts +57 -0
- package/src/modules/wms/api/sales-orders/unassign-warehouse/route.ts +43 -0
- package/src/modules/wms/api/warehouses/route.ts +181 -0
- package/src/modules/wms/api/zones/route.ts +158 -0
- package/src/modules/wms/backend/config/wms/page.meta.ts +14 -0
- package/src/modules/wms/backend/config/wms/page.tsx +5 -0
- package/src/modules/wms/backend/page.meta.ts +12 -0
- package/src/modules/wms/backend/page.tsx +5 -0
- package/src/modules/wms/backend/wms/inventory/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/inventory/page.tsx +5 -0
- package/src/modules/wms/backend/wms/location/[id]/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/location/[id]/page.tsx +5 -0
- package/src/modules/wms/backend/wms/locations/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/locations/page.tsx +12 -0
- package/src/modules/wms/backend/wms/lot/[id]/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/lot/[id]/page.tsx +5 -0
- package/src/modules/wms/backend/wms/lots/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/lots/page.tsx +5 -0
- package/src/modules/wms/backend/wms/movements/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/movements/page.tsx +23 -0
- package/src/modules/wms/backend/wms/reservations/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/reservations/page.tsx +24 -0
- package/src/modules/wms/backend/wms/sku/[id]/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/sku/[id]/page.tsx +5 -0
- package/src/modules/wms/backend/wms/warehouses/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/warehouses/page.tsx +12 -0
- package/src/modules/wms/backend/wms/zones/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/zones/page.tsx +12 -0
- package/src/modules/wms/ce.ts +76 -0
- package/src/modules/wms/cli.ts +96 -0
- package/src/modules/wms/commands/configuration.ts +1844 -0
- package/src/modules/wms/commands/index.ts +3 -0
- package/src/modules/wms/commands/inventory-actions.ts +1866 -0
- package/src/modules/wms/commands/sales-order-assignment.ts +346 -0
- package/src/modules/wms/commands/shared.ts +90 -0
- package/src/modules/wms/components/backend/AdjustInventoryDialog.tsx +820 -0
- package/src/modules/wms/components/backend/ChangeLotStatusDialog.tsx +312 -0
- package/src/modules/wms/components/backend/CycleCountWizardDialog.tsx +2007 -0
- package/src/modules/wms/components/backend/ImportInventoryDialog.tsx +1018 -0
- package/src/modules/wms/components/backend/InventoryOperationsSection.tsx +159 -0
- package/src/modules/wms/components/backend/LocationEditDialog.tsx +185 -0
- package/src/modules/wms/components/backend/MoveInventoryDialog.tsx +907 -0
- package/src/modules/wms/components/backend/ReceiveInventoryDialog.tsx +695 -0
- package/src/modules/wms/components/backend/ReleaseReservationDialog.tsx +424 -0
- package/src/modules/wms/components/backend/ReserveInventoryDialog.tsx +511 -0
- package/src/modules/wms/components/backend/WmsConfigurationPage.tsx +1340 -0
- package/src/modules/wms/components/backend/WmsInventoryConsolePage.tsx +1132 -0
- package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +1310 -0
- package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +1355 -0
- package/src/modules/wms/components/backend/WmsLotsListPage.tsx +359 -0
- package/src/modules/wms/components/backend/WmsOperationalDashboardPage.tsx +958 -0
- package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +1245 -0
- package/src/modules/wms/components/backend/inventoryMutationLoaders.ts +960 -0
- package/src/modules/wms/components/backend/useWmsInventoryMutationAccess.ts +89 -0
- package/src/modules/wms/components/backend/useWmsInventoryScopeFromSearchParams.ts +32 -0
- package/src/modules/wms/components/backend/wmsLookupLoaders.ts +78 -0
- package/src/modules/wms/data/enrichers.ts +718 -0
- package/src/modules/wms/data/entities.ts +436 -0
- package/src/modules/wms/data/validators.ts +463 -0
- package/src/modules/wms/di.ts +25 -0
- package/src/modules/wms/events.ts +41 -0
- package/src/modules/wms/i18n/de.json +1051 -0
- package/src/modules/wms/i18n/en.json +1051 -0
- package/src/modules/wms/i18n/es.json +1051 -0
- package/src/modules/wms/i18n/pl.json +1051 -0
- package/src/modules/wms/index.ts +15 -0
- package/src/modules/wms/lib/catalogInventoryProfileIntent.ts +65 -0
- package/src/modules/wms/lib/catalogInventoryProfileSync.ts +199 -0
- package/src/modules/wms/lib/expiry.ts +30 -0
- package/src/modules/wms/lib/flashMutationError.ts +74 -0
- package/src/modules/wms/lib/inventoryDisplayUi.ts +249 -0
- package/src/modules/wms/lib/inventoryIdempotency.ts +54 -0
- package/src/modules/wms/lib/inventoryImportCsv.ts +212 -0
- package/src/modules/wms/lib/inventoryImportService.ts +629 -0
- package/src/modules/wms/lib/inventoryMutationUi.ts +21 -0
- package/src/modules/wms/lib/inventoryPolicy.ts +111 -0
- package/src/modules/wms/lib/inventoryReconciliation.ts +263 -0
- package/src/modules/wms/lib/inventoryTrackingValidation.ts +23 -0
- package/src/modules/wms/lib/loadOperationalDashboard.ts +776 -0
- package/src/modules/wms/lib/lowStockBalanceFilter.ts +74 -0
- package/src/modules/wms/lib/primaryWarehousePolicy.ts +46 -0
- package/src/modules/wms/lib/roleFeatures.ts +32 -0
- package/src/modules/wms/lib/salesOrderInventoryAutomation.ts +390 -0
- package/src/modules/wms/lib/salesOrderWarehouseAssignment.ts +78 -0
- package/src/modules/wms/lib/wmsIntegrationToggles.ts +81 -0
- package/src/modules/wms/migrations/.snapshot-open-mercato.json +2880 -0
- package/src/modules/wms/migrations/Migration20260428110546.ts +91 -0
- package/src/modules/wms/migrations/Migration20260527120000.ts +15 -0
- package/src/modules/wms/migrations/Migration20260527140000.ts +35 -0
- package/src/modules/wms/migrations/Migration20260613120000.ts +21 -0
- package/src/modules/wms/migrations/Migration20260616090000.ts +11 -0
- package/src/modules/wms/migrations/Migration20260707180000.ts +13 -0
- package/src/modules/wms/notifications.client.ts +18 -0
- package/src/modules/wms/notifications.ts +51 -0
- package/src/modules/wms/search.ts +230 -0
- package/src/modules/wms/setup.ts +29 -0
- package/src/modules/wms/subscribers/low-stock-notification.ts +54 -0
- package/src/modules/wms/subscribers/reservation-shortfall-notification.ts +98 -0
- package/src/modules/wms/subscribers/sales-order-cancelled-release.ts +21 -0
- package/src/modules/wms/subscribers/sales-order-confirmed-reserve.ts +21 -0
- package/src/modules/wms/translations.ts +6 -0
- package/src/modules/wms/vector.ts +7 -0
- package/src/modules/wms/widgets/injection/catalog-inventory-profile/widget.ts +238 -0
- package/src/modules/wms/widgets/injection/order-items-stock-column/widget.tsx +153 -0
- package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.client.tsx +476 -0
- package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.ts +15 -0
- package/src/modules/wms/widgets/injection-table.ts +34 -0
- package/src/modules/wms/widgets/notifications/WmsLowStockRenderer.tsx +153 -0
- package/src/modules/wms/widgets/notifications/WmsReservationShortfallRenderer.tsx +194 -0
- package/src/modules/wms/widgets/notifications/index.ts +2 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
3
|
+
import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
|
|
4
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
5
|
+
import type { QueryEngine } from '@open-mercato/shared/lib/query/types'
|
|
6
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
7
|
+
import { E } from '#generated/entities.ids.generated'
|
|
8
|
+
import {
|
|
9
|
+
InventoryBalance,
|
|
10
|
+
InventoryLot,
|
|
11
|
+
Warehouse,
|
|
12
|
+
WarehouseLocation,
|
|
13
|
+
} from '../data/entities'
|
|
14
|
+
import type {
|
|
15
|
+
InventoryImportApplyInput,
|
|
16
|
+
InventoryImportApplyRowInput,
|
|
17
|
+
InventoryImportMode,
|
|
18
|
+
InventoryImportValidateInput,
|
|
19
|
+
} from '../data/validators'
|
|
20
|
+
import { ensureOrganizationScope, ensureTenantScope } from '../commands/shared'
|
|
21
|
+
import type { InventoryImportRawRow } from './inventoryImportCsv'
|
|
22
|
+
|
|
23
|
+
type ImportScope = {
|
|
24
|
+
tenantId: string
|
|
25
|
+
organizationId: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type ResolvedImportRow = {
|
|
29
|
+
rowNumber: number
|
|
30
|
+
warehouseId: string
|
|
31
|
+
warehouseCode: string
|
|
32
|
+
locationId: string
|
|
33
|
+
locationCode: string
|
|
34
|
+
catalogVariantId: string
|
|
35
|
+
sku: string
|
|
36
|
+
quantity: number
|
|
37
|
+
lotId?: string
|
|
38
|
+
lotNumber?: string
|
|
39
|
+
serialNumber?: string
|
|
40
|
+
currentOnHand: number
|
|
41
|
+
delta: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type InventoryImportRowResult = {
|
|
45
|
+
rowNumber: number
|
|
46
|
+
status: 'valid' | 'error' | 'warning' | 'skip'
|
|
47
|
+
errors: string[]
|
|
48
|
+
warnings: string[]
|
|
49
|
+
input: InventoryImportRawRow
|
|
50
|
+
resolved?: ResolvedImportRow
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type InventoryImportValidationResult = {
|
|
54
|
+
ok: boolean
|
|
55
|
+
importBatchId: string
|
|
56
|
+
summary: {
|
|
57
|
+
totalRows: number
|
|
58
|
+
validRows: number
|
|
59
|
+
errorRows: number
|
|
60
|
+
warningRows: number
|
|
61
|
+
skipRows: number
|
|
62
|
+
}
|
|
63
|
+
rows: InventoryImportRowResult[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type InventoryImportApplyResult = {
|
|
67
|
+
ok: boolean
|
|
68
|
+
importBatchId: string
|
|
69
|
+
summary: {
|
|
70
|
+
applied: number
|
|
71
|
+
skipped: number
|
|
72
|
+
failed: number
|
|
73
|
+
}
|
|
74
|
+
rows: Array<{
|
|
75
|
+
rowNumber: number
|
|
76
|
+
status: 'applied' | 'skipped' | 'failed'
|
|
77
|
+
movementId?: string
|
|
78
|
+
error?: string
|
|
79
|
+
}>
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function toNumber(value: unknown): number {
|
|
83
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value
|
|
84
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
85
|
+
const parsed = Number(value)
|
|
86
|
+
if (Number.isFinite(parsed)) return parsed
|
|
87
|
+
}
|
|
88
|
+
return 0
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function buildBucketKey(input: {
|
|
92
|
+
warehouseId: string
|
|
93
|
+
locationId: string
|
|
94
|
+
catalogVariantId: string
|
|
95
|
+
lotId?: string | null
|
|
96
|
+
serialNumber?: string | null
|
|
97
|
+
}): string {
|
|
98
|
+
return [
|
|
99
|
+
input.warehouseId,
|
|
100
|
+
input.locationId,
|
|
101
|
+
input.catalogVariantId,
|
|
102
|
+
input.lotId ?? '',
|
|
103
|
+
input.serialNumber ?? '',
|
|
104
|
+
].join('::')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function resolveWarehouse(
|
|
108
|
+
em: EntityManager,
|
|
109
|
+
scope: ImportScope,
|
|
110
|
+
row: InventoryImportRawRow,
|
|
111
|
+
): Promise<{ id: string; code: string } | null> {
|
|
112
|
+
if (row.warehouseId) {
|
|
113
|
+
const warehouse = await findOneWithDecryption(
|
|
114
|
+
em,
|
|
115
|
+
Warehouse,
|
|
116
|
+
{ id: row.warehouseId, deletedAt: null },
|
|
117
|
+
undefined,
|
|
118
|
+
scope,
|
|
119
|
+
)
|
|
120
|
+
if (!warehouse) return null
|
|
121
|
+
return { id: warehouse.id, code: warehouse.code }
|
|
122
|
+
}
|
|
123
|
+
const code = row.warehouseCode?.trim()
|
|
124
|
+
if (!code) return null
|
|
125
|
+
const warehouse = await findOneWithDecryption(
|
|
126
|
+
em,
|
|
127
|
+
Warehouse,
|
|
128
|
+
{ code, deletedAt: null },
|
|
129
|
+
undefined,
|
|
130
|
+
scope,
|
|
131
|
+
)
|
|
132
|
+
if (!warehouse) return null
|
|
133
|
+
return { id: warehouse.id, code: warehouse.code }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function resolveLocation(
|
|
137
|
+
em: EntityManager,
|
|
138
|
+
scope: ImportScope,
|
|
139
|
+
warehouseId: string,
|
|
140
|
+
row: InventoryImportRawRow,
|
|
141
|
+
): Promise<{ id: string; code: string } | null> {
|
|
142
|
+
if (row.locationId) {
|
|
143
|
+
const location = await findOneWithDecryption(
|
|
144
|
+
em,
|
|
145
|
+
WarehouseLocation,
|
|
146
|
+
{ id: row.locationId, deletedAt: null },
|
|
147
|
+
undefined,
|
|
148
|
+
scope,
|
|
149
|
+
)
|
|
150
|
+
if (!location) return null
|
|
151
|
+
const locationWarehouseId =
|
|
152
|
+
typeof location.warehouse === 'string' ? location.warehouse : location.warehouse.id
|
|
153
|
+
if (locationWarehouseId !== warehouseId) return null
|
|
154
|
+
return { id: location.id, code: location.code }
|
|
155
|
+
}
|
|
156
|
+
const code = row.locationCode?.trim()
|
|
157
|
+
if (!code) return null
|
|
158
|
+
const location = await findOneWithDecryption(
|
|
159
|
+
em,
|
|
160
|
+
WarehouseLocation,
|
|
161
|
+
{ warehouse: warehouseId, code, deletedAt: null },
|
|
162
|
+
undefined,
|
|
163
|
+
scope,
|
|
164
|
+
)
|
|
165
|
+
if (!location) return null
|
|
166
|
+
return { id: location.id, code: location.code }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
type ResolvedCatalogVariant = { id: string; sku: string }
|
|
170
|
+
|
|
171
|
+
type VariantResolveResult =
|
|
172
|
+
| { status: 'found'; variant: ResolvedCatalogVariant }
|
|
173
|
+
| { status: 'failed'; code: 'catalog_variant_not_found' | 'sku_not_found' | 'sku_ambiguous' }
|
|
174
|
+
|
|
175
|
+
async function resolveVariantBySku(
|
|
176
|
+
queryEngine: QueryEngine,
|
|
177
|
+
scope: ImportScope,
|
|
178
|
+
sku: string,
|
|
179
|
+
): Promise<VariantResolveResult> {
|
|
180
|
+
const normalizedSku = sku.trim()
|
|
181
|
+
if (!normalizedSku) return { status: 'failed', code: 'sku_not_found' }
|
|
182
|
+
const result = await queryEngine.query<{ id?: string | null; sku?: string | null }>(
|
|
183
|
+
E.catalog.catalog_product_variant,
|
|
184
|
+
{
|
|
185
|
+
tenantId: scope.tenantId,
|
|
186
|
+
organizationId: scope.organizationId,
|
|
187
|
+
filters: { sku: { $eq: normalizedSku } },
|
|
188
|
+
fields: ['id', 'sku'],
|
|
189
|
+
page: { page: 1, pageSize: 2 },
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
const items = result.items ?? []
|
|
193
|
+
if (items.length === 0) return { status: 'failed', code: 'sku_not_found' }
|
|
194
|
+
if (items.length > 1) return { status: 'failed', code: 'sku_ambiguous' }
|
|
195
|
+
const id = items[0]?.id
|
|
196
|
+
if (typeof id !== 'string' || !id) return { status: 'failed', code: 'sku_not_found' }
|
|
197
|
+
return {
|
|
198
|
+
status: 'found',
|
|
199
|
+
variant: { id, sku: items[0]?.sku?.trim() || normalizedSku },
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function resolveVariant(
|
|
204
|
+
queryEngine: QueryEngine,
|
|
205
|
+
scope: ImportScope,
|
|
206
|
+
row: InventoryImportRawRow,
|
|
207
|
+
): Promise<VariantResolveResult> {
|
|
208
|
+
if (row.catalogVariantId?.trim()) {
|
|
209
|
+
const result = await queryEngine.query<{ id?: string | null; sku?: string | null }>(
|
|
210
|
+
E.catalog.catalog_product_variant,
|
|
211
|
+
{
|
|
212
|
+
tenantId: scope.tenantId,
|
|
213
|
+
organizationId: scope.organizationId,
|
|
214
|
+
filters: { id: { $eq: row.catalogVariantId.trim() } },
|
|
215
|
+
fields: ['id', 'sku'],
|
|
216
|
+
page: { page: 1, pageSize: 1 },
|
|
217
|
+
},
|
|
218
|
+
)
|
|
219
|
+
const item = result.items?.[0]
|
|
220
|
+
if (!item?.id) return { status: 'failed', code: 'catalog_variant_not_found' }
|
|
221
|
+
return {
|
|
222
|
+
status: 'found',
|
|
223
|
+
variant: { id: item.id, sku: item.sku?.trim() || row.sku?.trim() || item.id },
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const sku = row.sku?.trim()
|
|
227
|
+
if (!sku) return { status: 'failed', code: 'sku_not_found' }
|
|
228
|
+
return resolveVariantBySku(queryEngine, scope, sku)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function resolveLot(
|
|
232
|
+
em: EntityManager,
|
|
233
|
+
scope: ImportScope,
|
|
234
|
+
catalogVariantId: string,
|
|
235
|
+
row: InventoryImportRawRow,
|
|
236
|
+
): Promise<{ id: string; lotNumber: string } | null> {
|
|
237
|
+
if (row.lotId) {
|
|
238
|
+
const lot = await findOneWithDecryption(
|
|
239
|
+
em,
|
|
240
|
+
InventoryLot,
|
|
241
|
+
{ id: row.lotId, deletedAt: null },
|
|
242
|
+
undefined,
|
|
243
|
+
scope,
|
|
244
|
+
)
|
|
245
|
+
if (!lot || lot.catalogVariantId !== catalogVariantId) return null
|
|
246
|
+
return { id: lot.id, lotNumber: lot.lotNumber }
|
|
247
|
+
}
|
|
248
|
+
const lotNumber = row.lotNumber?.trim()
|
|
249
|
+
if (!lotNumber) return null
|
|
250
|
+
const lot = await findOneWithDecryption(
|
|
251
|
+
em,
|
|
252
|
+
InventoryLot,
|
|
253
|
+
{ catalogVariantId, lotNumber, deletedAt: null },
|
|
254
|
+
undefined,
|
|
255
|
+
scope,
|
|
256
|
+
)
|
|
257
|
+
if (!lot) return null
|
|
258
|
+
return { id: lot.id, lotNumber: lot.lotNumber }
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function loadCurrentOnHand(
|
|
262
|
+
em: EntityManager,
|
|
263
|
+
scope: ImportScope,
|
|
264
|
+
input: {
|
|
265
|
+
warehouseId: string
|
|
266
|
+
locationId: string
|
|
267
|
+
catalogVariantId: string
|
|
268
|
+
lotId?: string
|
|
269
|
+
serialNumber?: string
|
|
270
|
+
},
|
|
271
|
+
): Promise<number> {
|
|
272
|
+
const balance = await findOneWithDecryption(
|
|
273
|
+
em,
|
|
274
|
+
InventoryBalance,
|
|
275
|
+
{
|
|
276
|
+
warehouse: input.warehouseId,
|
|
277
|
+
location: input.locationId,
|
|
278
|
+
catalogVariantId: input.catalogVariantId,
|
|
279
|
+
lot: input.lotId ?? null,
|
|
280
|
+
serialNumber: input.serialNumber ?? null,
|
|
281
|
+
deletedAt: null,
|
|
282
|
+
},
|
|
283
|
+
undefined,
|
|
284
|
+
scope,
|
|
285
|
+
)
|
|
286
|
+
return balance ? toNumber(balance.quantityOnHand) : 0
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function verifyApplyRowDeltas(
|
|
290
|
+
em: EntityManager,
|
|
291
|
+
scope: ImportScope,
|
|
292
|
+
mode: InventoryImportMode,
|
|
293
|
+
rows: InventoryImportApplyRowInput[],
|
|
294
|
+
): Promise<InventoryImportApplyRowInput[]> {
|
|
295
|
+
if (mode === 'additive') {
|
|
296
|
+
// Additive mode: the delta posted to the ledger always equals the row's
|
|
297
|
+
// quantity (the amount received), regardless of the current on-hand balance.
|
|
298
|
+
return rows.map((row) => {
|
|
299
|
+
if (Math.abs(row.quantity - row.delta) > 0.000001) {
|
|
300
|
+
throw new CrudHttpError(400, {
|
|
301
|
+
error: 'import_delta_tampering',
|
|
302
|
+
rowNumber: row.rowNumber,
|
|
303
|
+
expectedDelta: row.quantity,
|
|
304
|
+
providedDelta: row.delta,
|
|
305
|
+
})
|
|
306
|
+
}
|
|
307
|
+
return row
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
// Reconcile mode (opt-in, requires the "reconcile to exact balance" checkbox):
|
|
311
|
+
// quantity is the target on-hand balance, so the delta must be recalculated
|
|
312
|
+
// against the current balance to guard against staleness between validate/apply.
|
|
313
|
+
const recalculated: InventoryImportApplyRowInput[] = []
|
|
314
|
+
for (const row of rows) {
|
|
315
|
+
const currentOnHand = await loadCurrentOnHand(em, scope, {
|
|
316
|
+
warehouseId: row.warehouseId,
|
|
317
|
+
locationId: row.locationId,
|
|
318
|
+
catalogVariantId: row.catalogVariantId,
|
|
319
|
+
lotId: row.lotId,
|
|
320
|
+
serialNumber: row.serialNumber,
|
|
321
|
+
})
|
|
322
|
+
const serverDelta = row.quantity - currentOnHand
|
|
323
|
+
if (Math.abs(serverDelta - row.delta) > 0.000001) {
|
|
324
|
+
throw new CrudHttpError(400, {
|
|
325
|
+
error: 'import_delta_tampering',
|
|
326
|
+
rowNumber: row.rowNumber,
|
|
327
|
+
expectedDelta: serverDelta,
|
|
328
|
+
providedDelta: row.delta,
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
recalculated.push({ ...row, delta: serverDelta })
|
|
332
|
+
}
|
|
333
|
+
return recalculated
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export async function validateInventoryImport(
|
|
337
|
+
ctx: CommandRuntimeContext,
|
|
338
|
+
input: InventoryImportValidateInput,
|
|
339
|
+
): Promise<InventoryImportValidationResult> {
|
|
340
|
+
ensureTenantScope(ctx, input.tenantId)
|
|
341
|
+
ensureOrganizationScope(ctx, input.organizationId)
|
|
342
|
+
const mode: InventoryImportMode = input.mode ?? 'additive'
|
|
343
|
+
const scope: ImportScope = {
|
|
344
|
+
tenantId: input.tenantId,
|
|
345
|
+
organizationId: input.organizationId,
|
|
346
|
+
}
|
|
347
|
+
const em = ctx.container.resolve('em') as EntityManager
|
|
348
|
+
const queryEngine = ctx.container.resolve('queryEngine') as QueryEngine
|
|
349
|
+
const importBatchId = input.importBatchId ?? randomUUID()
|
|
350
|
+
const seenBuckets = new Map<string, number>()
|
|
351
|
+
const rows: InventoryImportRowResult[] = []
|
|
352
|
+
|
|
353
|
+
for (let index = 0; index < input.rows.length; index += 1) {
|
|
354
|
+
const raw = input.rows[index]
|
|
355
|
+
const rowNumber = index + 1
|
|
356
|
+
const errors: string[] = []
|
|
357
|
+
const warnings: string[] = []
|
|
358
|
+
|
|
359
|
+
const quantity = toNumber(raw.quantity)
|
|
360
|
+
if (raw.quantity === undefined || raw.quantity.trim().length === 0) {
|
|
361
|
+
errors.push('quantity_required')
|
|
362
|
+
} else if (!Number.isFinite(quantity) || quantity < 0) {
|
|
363
|
+
errors.push('quantity_invalid')
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const hasWarehouse = Boolean(raw.warehouseId?.trim() || raw.warehouseCode?.trim())
|
|
367
|
+
const hasLocation = Boolean(raw.locationId?.trim() || raw.locationCode?.trim())
|
|
368
|
+
const hasVariant = Boolean(raw.catalogVariantId?.trim() || raw.sku?.trim())
|
|
369
|
+
|
|
370
|
+
if (!hasWarehouse) errors.push('warehouse_required')
|
|
371
|
+
if (!hasLocation) errors.push('location_required')
|
|
372
|
+
if (!hasVariant) errors.push('sku_required')
|
|
373
|
+
|
|
374
|
+
if (errors.length > 0) {
|
|
375
|
+
rows.push({ rowNumber, status: 'error', errors, warnings, input: raw })
|
|
376
|
+
continue
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const warehouse = await resolveWarehouse(em, scope, raw)
|
|
380
|
+
if (!warehouse) {
|
|
381
|
+
errors.push('warehouse_not_found')
|
|
382
|
+
rows.push({ rowNumber, status: 'error', errors, warnings, input: raw })
|
|
383
|
+
continue
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const location = await resolveLocation(em, scope, warehouse.id, raw)
|
|
387
|
+
if (!location) {
|
|
388
|
+
errors.push('location_not_found')
|
|
389
|
+
rows.push({ rowNumber, status: 'error', errors, warnings, input: raw })
|
|
390
|
+
continue
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const variantResult = await resolveVariant(queryEngine, scope, raw)
|
|
394
|
+
if (variantResult.status === 'failed') {
|
|
395
|
+
errors.push(variantResult.code)
|
|
396
|
+
rows.push({ rowNumber, status: 'error', errors, warnings, input: raw })
|
|
397
|
+
continue
|
|
398
|
+
}
|
|
399
|
+
const variant = variantResult.variant
|
|
400
|
+
|
|
401
|
+
let lot: { id: string; lotNumber: string } | null = null
|
|
402
|
+
if (raw.lotId?.trim() || raw.lotNumber?.trim()) {
|
|
403
|
+
lot = await resolveLot(em, scope, variant.id, raw)
|
|
404
|
+
if (!lot) {
|
|
405
|
+
errors.push('lot_not_found')
|
|
406
|
+
rows.push({ rowNumber, status: 'error', errors, warnings, input: raw })
|
|
407
|
+
continue
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const serialNumber = raw.serialNumber?.trim() || undefined
|
|
412
|
+
const currentOnHand = await loadCurrentOnHand(em, scope, {
|
|
413
|
+
warehouseId: warehouse.id,
|
|
414
|
+
locationId: location.id,
|
|
415
|
+
catalogVariantId: variant.id,
|
|
416
|
+
lotId: lot?.id,
|
|
417
|
+
serialNumber,
|
|
418
|
+
})
|
|
419
|
+
const bucketKey = buildBucketKey({
|
|
420
|
+
warehouseId: warehouse.id,
|
|
421
|
+
locationId: location.id,
|
|
422
|
+
catalogVariantId: variant.id,
|
|
423
|
+
lotId: lot?.id,
|
|
424
|
+
serialNumber,
|
|
425
|
+
})
|
|
426
|
+
const duplicateRow = seenBuckets.get(bucketKey)
|
|
427
|
+
if (duplicateRow) {
|
|
428
|
+
if (input.skipDuplicates) {
|
|
429
|
+
warnings.push('duplicate_row')
|
|
430
|
+
warnings.push(`duplicate_of_row_${duplicateRow}`)
|
|
431
|
+
rows.push({
|
|
432
|
+
rowNumber,
|
|
433
|
+
status: 'skip',
|
|
434
|
+
errors,
|
|
435
|
+
warnings,
|
|
436
|
+
input: raw,
|
|
437
|
+
resolved: {
|
|
438
|
+
rowNumber,
|
|
439
|
+
warehouseId: warehouse.id,
|
|
440
|
+
warehouseCode: warehouse.code,
|
|
441
|
+
locationId: location.id,
|
|
442
|
+
locationCode: location.code,
|
|
443
|
+
catalogVariantId: variant.id,
|
|
444
|
+
sku: variant.sku,
|
|
445
|
+
quantity,
|
|
446
|
+
lotId: lot?.id,
|
|
447
|
+
lotNumber: lot?.lotNumber,
|
|
448
|
+
serialNumber,
|
|
449
|
+
currentOnHand,
|
|
450
|
+
delta: 0,
|
|
451
|
+
},
|
|
452
|
+
})
|
|
453
|
+
continue
|
|
454
|
+
}
|
|
455
|
+
errors.push('duplicate_row')
|
|
456
|
+
warnings.push(`duplicate_of_row_${duplicateRow}`)
|
|
457
|
+
rows.push({ rowNumber, status: 'error', errors, warnings, input: raw })
|
|
458
|
+
continue
|
|
459
|
+
}
|
|
460
|
+
seenBuckets.set(bucketKey, rowNumber)
|
|
461
|
+
|
|
462
|
+
// Additive mode (default): quantity is the amount to receive into this bucket,
|
|
463
|
+
// so the delta never depends on currentOnHand. Reconcile mode (opt-in) treats
|
|
464
|
+
// quantity as the target on-hand balance instead, so it can also reduce stock.
|
|
465
|
+
const delta = mode === 'additive' ? quantity : quantity - currentOnHand
|
|
466
|
+
|
|
467
|
+
if (mode === 'reconcile') {
|
|
468
|
+
if (delta < 0 && currentOnHand < Math.abs(delta) - 0.000001) {
|
|
469
|
+
warnings.push('insufficient_available_for_negative_delta')
|
|
470
|
+
}
|
|
471
|
+
if (currentOnHand > 0 && Math.sign(delta) !== 0) {
|
|
472
|
+
warnings.push('overwriting_existing_balance')
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (Math.abs(delta) < 0.000001) {
|
|
477
|
+
rows.push({
|
|
478
|
+
rowNumber,
|
|
479
|
+
status: 'skip',
|
|
480
|
+
errors,
|
|
481
|
+
warnings,
|
|
482
|
+
input: raw,
|
|
483
|
+
resolved: {
|
|
484
|
+
rowNumber,
|
|
485
|
+
warehouseId: warehouse.id,
|
|
486
|
+
warehouseCode: warehouse.code,
|
|
487
|
+
locationId: location.id,
|
|
488
|
+
locationCode: location.code,
|
|
489
|
+
catalogVariantId: variant.id,
|
|
490
|
+
sku: variant.sku,
|
|
491
|
+
quantity,
|
|
492
|
+
lotId: lot?.id,
|
|
493
|
+
lotNumber: lot?.lotNumber,
|
|
494
|
+
serialNumber,
|
|
495
|
+
currentOnHand,
|
|
496
|
+
delta: 0,
|
|
497
|
+
},
|
|
498
|
+
})
|
|
499
|
+
continue
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
rows.push({
|
|
503
|
+
rowNumber,
|
|
504
|
+
status: warnings.length > 0 ? 'warning' : 'valid',
|
|
505
|
+
errors,
|
|
506
|
+
warnings,
|
|
507
|
+
input: raw,
|
|
508
|
+
resolved: {
|
|
509
|
+
rowNumber,
|
|
510
|
+
warehouseId: warehouse.id,
|
|
511
|
+
warehouseCode: warehouse.code,
|
|
512
|
+
locationId: location.id,
|
|
513
|
+
locationCode: location.code,
|
|
514
|
+
catalogVariantId: variant.id,
|
|
515
|
+
sku: variant.sku,
|
|
516
|
+
quantity,
|
|
517
|
+
lotId: lot?.id,
|
|
518
|
+
lotNumber: lot?.lotNumber,
|
|
519
|
+
serialNumber,
|
|
520
|
+
currentOnHand,
|
|
521
|
+
delta,
|
|
522
|
+
},
|
|
523
|
+
})
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const errorRows = rows.filter((row) => row.status === 'error').length
|
|
527
|
+
const warningRows = rows.filter((row) => row.status === 'warning').length
|
|
528
|
+
const skipRows = rows.filter((row) => row.status === 'skip').length
|
|
529
|
+
const validRows = rows.filter((row) => row.status === 'valid' || row.status === 'warning').length
|
|
530
|
+
|
|
531
|
+
return {
|
|
532
|
+
ok: errorRows === 0,
|
|
533
|
+
importBatchId,
|
|
534
|
+
summary: {
|
|
535
|
+
totalRows: rows.length,
|
|
536
|
+
validRows,
|
|
537
|
+
errorRows,
|
|
538
|
+
warningRows,
|
|
539
|
+
skipRows,
|
|
540
|
+
},
|
|
541
|
+
rows,
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export async function applyInventoryImport(
|
|
546
|
+
ctx: CommandRuntimeContext,
|
|
547
|
+
input: InventoryImportApplyInput,
|
|
548
|
+
): Promise<InventoryImportApplyResult> {
|
|
549
|
+
ensureTenantScope(ctx, input.tenantId)
|
|
550
|
+
ensureOrganizationScope(ctx, input.organizationId)
|
|
551
|
+
const mode: InventoryImportMode = input.mode ?? 'additive'
|
|
552
|
+
const commandBus = ctx.container.resolve('commandBus') as CommandBus
|
|
553
|
+
const em = ctx.container.resolve('em') as EntityManager
|
|
554
|
+
const scope: ImportScope = {
|
|
555
|
+
tenantId: input.tenantId,
|
|
556
|
+
organizationId: input.organizationId,
|
|
557
|
+
}
|
|
558
|
+
const applyRows = await verifyApplyRowDeltas(em, scope, mode, input.rows)
|
|
559
|
+
const resultRows: InventoryImportApplyResult['rows'] = []
|
|
560
|
+
let applied = 0
|
|
561
|
+
let skipped = 0
|
|
562
|
+
let failed = 0
|
|
563
|
+
|
|
564
|
+
for (const row of applyRows) {
|
|
565
|
+
if (Math.abs(row.delta) < 0.000001) {
|
|
566
|
+
skipped += 1
|
|
567
|
+
resultRows.push({ rowNumber: row.rowNumber, status: 'skipped' })
|
|
568
|
+
continue
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
try {
|
|
572
|
+
const execution = await commandBus.execute('wms.inventory.adjust', {
|
|
573
|
+
input: {
|
|
574
|
+
organizationId: input.organizationId,
|
|
575
|
+
tenantId: input.tenantId,
|
|
576
|
+
warehouseId: row.warehouseId,
|
|
577
|
+
locationId: row.locationId,
|
|
578
|
+
catalogVariantId: row.catalogVariantId,
|
|
579
|
+
lotId: row.lotId,
|
|
580
|
+
serialNumber: row.serialNumber,
|
|
581
|
+
delta: row.delta,
|
|
582
|
+
reason: input.reason,
|
|
583
|
+
referenceType: 'manual' as const,
|
|
584
|
+
referenceId: randomUUID(),
|
|
585
|
+
performedBy: input.performedBy,
|
|
586
|
+
metadata: {
|
|
587
|
+
importBatchId: input.importBatchId,
|
|
588
|
+
importRowNumber: row.rowNumber,
|
|
589
|
+
source: 'csv_import',
|
|
590
|
+
...(mode === 'reconcile' ? { targetQuantity: row.quantity } : {}),
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
ctx,
|
|
594
|
+
})
|
|
595
|
+
applied += 1
|
|
596
|
+
resultRows.push({
|
|
597
|
+
rowNumber: row.rowNumber,
|
|
598
|
+
status: 'applied',
|
|
599
|
+
movementId: (execution.result as { movementId?: string }).movementId,
|
|
600
|
+
})
|
|
601
|
+
} catch (error) {
|
|
602
|
+
failed += 1
|
|
603
|
+
const message =
|
|
604
|
+
error instanceof CrudHttpError
|
|
605
|
+
? String((error.body as { error?: unknown })?.error ?? 'apply_failed')
|
|
606
|
+
: 'apply_failed'
|
|
607
|
+
resultRows.push({
|
|
608
|
+
rowNumber: row.rowNumber,
|
|
609
|
+
status: 'failed',
|
|
610
|
+
error: message,
|
|
611
|
+
})
|
|
612
|
+
if (!input.continueOnError) {
|
|
613
|
+
throw new CrudHttpError(409, {
|
|
614
|
+
error: 'import_apply_partial_failure',
|
|
615
|
+
importBatchId: input.importBatchId,
|
|
616
|
+
summary: { applied, skipped, failed },
|
|
617
|
+
rows: resultRows,
|
|
618
|
+
})
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
return {
|
|
624
|
+
ok: failed === 0,
|
|
625
|
+
importBatchId: input.importBatchId,
|
|
626
|
+
summary: { applied, skipped, failed },
|
|
627
|
+
rows: resultRows,
|
|
628
|
+
}
|
|
629
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function parseInventoryQuantity(value: string | number | null | undefined): number {
|
|
2
|
+
if (value == null || value === '') return 0
|
|
3
|
+
const parsed = typeof value === 'number' ? value : Number(value)
|
|
4
|
+
return Number.isFinite(parsed) ? parsed : 0
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function computeCycleCountVariance(systemOnHand: number, countedQuantity: number): number {
|
|
8
|
+
return countedQuantity - systemOnHand
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function formatSignedQuantity(value: number): string {
|
|
12
|
+
if (value > 0) return `+${value}`
|
|
13
|
+
return String(value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function buildInventoryMutationReferenceId(): string {
|
|
17
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
18
|
+
return crypto.randomUUID()
|
|
19
|
+
}
|
|
20
|
+
return `00000000-0000-4000-8000-${Date.now().toString(16).padStart(12, '0').slice(-12)}`
|
|
21
|
+
}
|