@open-mercato/core 0.6.7-develop.6669.1.40b669666b → 0.6.7-develop.6671.1.4b925c5096

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.
Files changed (473) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/inventory_balance/index.js +21 -0
  3. package/dist/generated/entities/inventory_balance/index.js.map +7 -0
  4. package/dist/generated/entities/inventory_lot/index.js +19 -0
  5. package/dist/generated/entities/inventory_lot/index.js.map +7 -0
  6. package/dist/generated/entities/inventory_movement/index.js +35 -0
  7. package/dist/generated/entities/inventory_movement/index.js.map +7 -0
  8. package/dist/generated/entities/inventory_reservation/index.js +23 -0
  9. package/dist/generated/entities/inventory_reservation/index.js.map +7 -0
  10. package/dist/generated/entities/product_inventory_profile/index.js +21 -0
  11. package/dist/generated/entities/product_inventory_profile/index.js.map +7 -0
  12. package/dist/generated/entities/sales_order_warehouse_assignment/index.js +11 -0
  13. package/dist/generated/entities/sales_order_warehouse_assignment/index.js.map +7 -0
  14. package/dist/generated/entities/warehouse/index.js +25 -0
  15. package/dist/generated/entities/warehouse/index.js.map +7 -0
  16. package/dist/generated/entities/warehouse_location/index.js +21 -0
  17. package/dist/generated/entities/warehouse_location/index.js.map +7 -0
  18. package/dist/generated/entities/warehouse_zone/index.js +11 -0
  19. package/dist/generated/entities/warehouse_zone/index.js.map +7 -0
  20. package/dist/generated/entities.ids.generated.js +12 -0
  21. package/dist/generated/entities.ids.generated.js.map +2 -2
  22. package/dist/generated/entity-fields-registry.js +98 -0
  23. package/dist/generated/entity-fields-registry.js.map +2 -2
  24. package/dist/modules/auth/backend/roles/page.js +12 -4
  25. package/dist/modules/auth/backend/roles/page.js.map +2 -2
  26. package/dist/modules/auth/lib/backendChrome.js +1 -0
  27. package/dist/modules/auth/lib/backendChrome.js.map +2 -2
  28. package/dist/modules/auth/services/rbacService.js +16 -17
  29. package/dist/modules/auth/services/rbacService.js.map +2 -2
  30. package/dist/modules/catalog/api/products/route.js +3 -0
  31. package/dist/modules/catalog/api/products/route.js.map +2 -2
  32. package/dist/modules/catalog/api/variants/route.js +3 -0
  33. package/dist/modules/catalog/api/variants/route.js.map +2 -2
  34. package/dist/modules/query_index/lib/engine.js +6 -6
  35. package/dist/modules/query_index/lib/engine.js.map +2 -2
  36. package/dist/modules/sales/api/documents/factory.js +1 -0
  37. package/dist/modules/sales/api/documents/factory.js.map +2 -2
  38. package/dist/modules/sales/commands/documents.js +53 -0
  39. package/dist/modules/sales/commands/documents.js.map +2 -2
  40. package/dist/modules/sales/components/documents/ItemsSection.js +51 -2
  41. package/dist/modules/sales/components/documents/ItemsSection.js.map +2 -2
  42. package/dist/modules/sales/events.js +2 -0
  43. package/dist/modules/sales/events.js.map +2 -2
  44. package/dist/modules/sales/widgets/injection/order-items-context.js +11 -0
  45. package/dist/modules/sales/widgets/injection/order-items-context.js.map +7 -0
  46. package/dist/modules/wms/acl.js +18 -0
  47. package/dist/modules/wms/acl.js.map +7 -0
  48. package/dist/modules/wms/analytics.js +11 -0
  49. package/dist/modules/wms/analytics.js.map +7 -0
  50. package/dist/modules/wms/api/dashboard/operational/route.js +80 -0
  51. package/dist/modules/wms/api/dashboard/operational/route.js.map +7 -0
  52. package/dist/modules/wms/api/interceptors.js +90 -0
  53. package/dist/modules/wms/api/interceptors.js.map +7 -0
  54. package/dist/modules/wms/api/inventory/adjust/route.js +51 -0
  55. package/dist/modules/wms/api/inventory/adjust/route.js.map +7 -0
  56. package/dist/modules/wms/api/inventory/allocate/route.js +51 -0
  57. package/dist/modules/wms/api/inventory/allocate/route.js.map +7 -0
  58. package/dist/modules/wms/api/inventory/balances/route.js +172 -0
  59. package/dist/modules/wms/api/inventory/balances/route.js.map +7 -0
  60. package/dist/modules/wms/api/inventory/cycle-count/route.js +52 -0
  61. package/dist/modules/wms/api/inventory/cycle-count/route.js.map +7 -0
  62. package/dist/modules/wms/api/inventory/helpers.js +113 -0
  63. package/dist/modules/wms/api/inventory/helpers.js.map +7 -0
  64. package/dist/modules/wms/api/inventory/import/apply/route.js +46 -0
  65. package/dist/modules/wms/api/inventory/import/apply/route.js.map +7 -0
  66. package/dist/modules/wms/api/inventory/import/helpers.js +195 -0
  67. package/dist/modules/wms/api/inventory/import/helpers.js.map +7 -0
  68. package/dist/modules/wms/api/inventory/import/template/route.js +32 -0
  69. package/dist/modules/wms/api/inventory/import/template/route.js.map +7 -0
  70. package/dist/modules/wms/api/inventory/import/validate/route.js +54 -0
  71. package/dist/modules/wms/api/inventory/import/validate/route.js.map +7 -0
  72. package/dist/modules/wms/api/inventory/move/route.js +51 -0
  73. package/dist/modules/wms/api/inventory/move/route.js.map +7 -0
  74. package/dist/modules/wms/api/inventory/movements/route.js +164 -0
  75. package/dist/modules/wms/api/inventory/movements/route.js.map +7 -0
  76. package/dist/modules/wms/api/inventory/receive/route.js +50 -0
  77. package/dist/modules/wms/api/inventory/receive/route.js.map +7 -0
  78. package/dist/modules/wms/api/inventory/release/route.js +44 -0
  79. package/dist/modules/wms/api/inventory/release/route.js.map +7 -0
  80. package/dist/modules/wms/api/inventory/reservations/route.js +128 -0
  81. package/dist/modules/wms/api/inventory/reservations/route.js.map +7 -0
  82. package/dist/modules/wms/api/inventory/reserve/route.js +59 -0
  83. package/dist/modules/wms/api/inventory/reserve/route.js.map +7 -0
  84. package/dist/modules/wms/api/inventory-profiles/route.js +178 -0
  85. package/dist/modules/wms/api/inventory-profiles/route.js.map +7 -0
  86. package/dist/modules/wms/api/listEnrichers.js +181 -0
  87. package/dist/modules/wms/api/listEnrichers.js.map +7 -0
  88. package/dist/modules/wms/api/listSearch.js +77 -0
  89. package/dist/modules/wms/api/listSearch.js.map +7 -0
  90. package/dist/modules/wms/api/locations/route.js +172 -0
  91. package/dist/modules/wms/api/locations/route.js.map +7 -0
  92. package/dist/modules/wms/api/lots/route.js +204 -0
  93. package/dist/modules/wms/api/lots/route.js.map +7 -0
  94. package/dist/modules/wms/api/openapi.js +27 -0
  95. package/dist/modules/wms/api/openapi.js.map +7 -0
  96. package/dist/modules/wms/api/sales-orders/[salesOrderId]/re-run-reservation/route.js +54 -0
  97. package/dist/modules/wms/api/sales-orders/[salesOrderId]/re-run-reservation/route.js.map +7 -0
  98. package/dist/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.js +279 -0
  99. package/dist/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.js.map +7 -0
  100. package/dist/modules/wms/api/sales-orders/assign-warehouse/route.js +56 -0
  101. package/dist/modules/wms/api/sales-orders/assign-warehouse/route.js.map +7 -0
  102. package/dist/modules/wms/api/sales-orders/unassign-warehouse/route.js +43 -0
  103. package/dist/modules/wms/api/sales-orders/unassign-warehouse/route.js.map +7 -0
  104. package/dist/modules/wms/api/warehouses/route.js +181 -0
  105. package/dist/modules/wms/api/warehouses/route.js.map +7 -0
  106. package/dist/modules/wms/api/zones/route.js +159 -0
  107. package/dist/modules/wms/api/zones/route.js.map +7 -0
  108. package/dist/modules/wms/backend/config/wms/page.js +9 -0
  109. package/dist/modules/wms/backend/config/wms/page.js.map +7 -0
  110. package/dist/modules/wms/backend/config/wms/page.meta.js +18 -0
  111. package/dist/modules/wms/backend/config/wms/page.meta.js.map +7 -0
  112. package/dist/modules/wms/backend/page.js +9 -0
  113. package/dist/modules/wms/backend/page.js.map +7 -0
  114. package/dist/modules/wms/backend/page.meta.js +16 -0
  115. package/dist/modules/wms/backend/page.meta.js.map +7 -0
  116. package/dist/modules/wms/backend/wms/inventory/page.js +9 -0
  117. package/dist/modules/wms/backend/wms/inventory/page.js.map +7 -0
  118. package/dist/modules/wms/backend/wms/inventory/page.meta.js +18 -0
  119. package/dist/modules/wms/backend/wms/inventory/page.meta.js.map +7 -0
  120. package/dist/modules/wms/backend/wms/location/[id]/page.js +9 -0
  121. package/dist/modules/wms/backend/wms/location/[id]/page.js.map +7 -0
  122. package/dist/modules/wms/backend/wms/location/[id]/page.meta.js +18 -0
  123. package/dist/modules/wms/backend/wms/location/[id]/page.meta.js.map +7 -0
  124. package/dist/modules/wms/backend/wms/locations/page.js +10 -0
  125. package/dist/modules/wms/backend/wms/locations/page.js.map +7 -0
  126. package/dist/modules/wms/backend/wms/locations/page.meta.js +18 -0
  127. package/dist/modules/wms/backend/wms/locations/page.meta.js.map +7 -0
  128. package/dist/modules/wms/backend/wms/lot/[id]/page.js +9 -0
  129. package/dist/modules/wms/backend/wms/lot/[id]/page.js.map +7 -0
  130. package/dist/modules/wms/backend/wms/lot/[id]/page.meta.js +18 -0
  131. package/dist/modules/wms/backend/wms/lot/[id]/page.meta.js.map +7 -0
  132. package/dist/modules/wms/backend/wms/lots/page.js +9 -0
  133. package/dist/modules/wms/backend/wms/lots/page.js.map +7 -0
  134. package/dist/modules/wms/backend/wms/lots/page.meta.js +18 -0
  135. package/dist/modules/wms/backend/wms/lots/page.meta.js.map +7 -0
  136. package/dist/modules/wms/backend/wms/movements/page.js +22 -0
  137. package/dist/modules/wms/backend/wms/movements/page.js.map +7 -0
  138. package/dist/modules/wms/backend/wms/movements/page.meta.js +18 -0
  139. package/dist/modules/wms/backend/wms/movements/page.meta.js.map +7 -0
  140. package/dist/modules/wms/backend/wms/reservations/page.js +23 -0
  141. package/dist/modules/wms/backend/wms/reservations/page.js.map +7 -0
  142. package/dist/modules/wms/backend/wms/reservations/page.meta.js +18 -0
  143. package/dist/modules/wms/backend/wms/reservations/page.meta.js.map +7 -0
  144. package/dist/modules/wms/backend/wms/sku/[id]/page.js +9 -0
  145. package/dist/modules/wms/backend/wms/sku/[id]/page.js.map +7 -0
  146. package/dist/modules/wms/backend/wms/sku/[id]/page.meta.js +18 -0
  147. package/dist/modules/wms/backend/wms/sku/[id]/page.meta.js.map +7 -0
  148. package/dist/modules/wms/backend/wms/warehouses/page.js +10 -0
  149. package/dist/modules/wms/backend/wms/warehouses/page.js.map +7 -0
  150. package/dist/modules/wms/backend/wms/warehouses/page.meta.js +18 -0
  151. package/dist/modules/wms/backend/wms/warehouses/page.meta.js.map +7 -0
  152. package/dist/modules/wms/backend/wms/zones/page.js +10 -0
  153. package/dist/modules/wms/backend/wms/zones/page.js.map +7 -0
  154. package/dist/modules/wms/backend/wms/zones/page.meta.js +18 -0
  155. package/dist/modules/wms/backend/wms/zones/page.meta.js.map +7 -0
  156. package/dist/modules/wms/ce.js +80 -0
  157. package/dist/modules/wms/ce.js.map +7 -0
  158. package/dist/modules/wms/cli.js +83 -0
  159. package/dist/modules/wms/cli.js.map +7 -0
  160. package/dist/modules/wms/commands/configuration.js +1519 -0
  161. package/dist/modules/wms/commands/configuration.js.map +7 -0
  162. package/dist/modules/wms/commands/index.js +4 -0
  163. package/dist/modules/wms/commands/index.js.map +7 -0
  164. package/dist/modules/wms/commands/inventory-actions.js +1539 -0
  165. package/dist/modules/wms/commands/inventory-actions.js.map +7 -0
  166. package/dist/modules/wms/commands/sales-order-assignment.js +277 -0
  167. package/dist/modules/wms/commands/sales-order-assignment.js.map +7 -0
  168. package/dist/modules/wms/commands/shared.js +82 -0
  169. package/dist/modules/wms/commands/shared.js.map +7 -0
  170. package/dist/modules/wms/components/backend/AdjustInventoryDialog.js +755 -0
  171. package/dist/modules/wms/components/backend/AdjustInventoryDialog.js.map +7 -0
  172. package/dist/modules/wms/components/backend/ChangeLotStatusDialog.js +269 -0
  173. package/dist/modules/wms/components/backend/ChangeLotStatusDialog.js.map +7 -0
  174. package/dist/modules/wms/components/backend/CycleCountWizardDialog.js +1783 -0
  175. package/dist/modules/wms/components/backend/CycleCountWizardDialog.js.map +7 -0
  176. package/dist/modules/wms/components/backend/ImportInventoryDialog.js +766 -0
  177. package/dist/modules/wms/components/backend/ImportInventoryDialog.js.map +7 -0
  178. package/dist/modules/wms/components/backend/InventoryOperationsSection.js +119 -0
  179. package/dist/modules/wms/components/backend/InventoryOperationsSection.js.map +7 -0
  180. package/dist/modules/wms/components/backend/LocationEditDialog.js +140 -0
  181. package/dist/modules/wms/components/backend/LocationEditDialog.js.map +7 -0
  182. package/dist/modules/wms/components/backend/MoveInventoryDialog.js +791 -0
  183. package/dist/modules/wms/components/backend/MoveInventoryDialog.js.map +7 -0
  184. package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js +656 -0
  185. package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js.map +7 -0
  186. package/dist/modules/wms/components/backend/ReleaseReservationDialog.js +344 -0
  187. package/dist/modules/wms/components/backend/ReleaseReservationDialog.js.map +7 -0
  188. package/dist/modules/wms/components/backend/ReserveInventoryDialog.js +475 -0
  189. package/dist/modules/wms/components/backend/ReserveInventoryDialog.js.map +7 -0
  190. package/dist/modules/wms/components/backend/WmsConfigurationPage.js +1112 -0
  191. package/dist/modules/wms/components/backend/WmsConfigurationPage.js.map +7 -0
  192. package/dist/modules/wms/components/backend/WmsInventoryConsolePage.js +908 -0
  193. package/dist/modules/wms/components/backend/WmsInventoryConsolePage.js.map +7 -0
  194. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +1015 -0
  195. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +7 -0
  196. package/dist/modules/wms/components/backend/WmsLotDetailPage.js +1049 -0
  197. package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +7 -0
  198. package/dist/modules/wms/components/backend/WmsLotsListPage.js +297 -0
  199. package/dist/modules/wms/components/backend/WmsLotsListPage.js.map +7 -0
  200. package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js +757 -0
  201. package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js.map +7 -0
  202. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +975 -0
  203. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +7 -0
  204. package/dist/modules/wms/components/backend/inventoryMutationLoaders.js +710 -0
  205. package/dist/modules/wms/components/backend/inventoryMutationLoaders.js.map +7 -0
  206. package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js +79 -0
  207. package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js.map +7 -0
  208. package/dist/modules/wms/components/backend/useWmsInventoryScopeFromSearchParams.js +24 -0
  209. package/dist/modules/wms/components/backend/useWmsInventoryScopeFromSearchParams.js.map +7 -0
  210. package/dist/modules/wms/components/backend/wmsLookupLoaders.js +55 -0
  211. package/dist/modules/wms/components/backend/wmsLookupLoaders.js.map +7 -0
  212. package/dist/modules/wms/data/enrichers.js +501 -0
  213. package/dist/modules/wms/data/enrichers.js.map +7 -0
  214. package/dist/modules/wms/data/entities.js +467 -0
  215. package/dist/modules/wms/data/entities.js.map +7 -0
  216. package/dist/modules/wms/data/validators.js +399 -0
  217. package/dist/modules/wms/data/validators.js.map +7 -0
  218. package/dist/modules/wms/di.js +27 -0
  219. package/dist/modules/wms/di.js.map +7 -0
  220. package/dist/modules/wms/events.js +42 -0
  221. package/dist/modules/wms/events.js.map +7 -0
  222. package/dist/modules/wms/index.js +17 -0
  223. package/dist/modules/wms/index.js.map +7 -0
  224. package/dist/modules/wms/lib/catalogInventoryProfileIntent.js +54 -0
  225. package/dist/modules/wms/lib/catalogInventoryProfileIntent.js.map +7 -0
  226. package/dist/modules/wms/lib/catalogInventoryProfileSync.js +144 -0
  227. package/dist/modules/wms/lib/catalogInventoryProfileSync.js.map +7 -0
  228. package/dist/modules/wms/lib/expiry.js +29 -0
  229. package/dist/modules/wms/lib/expiry.js.map +7 -0
  230. package/dist/modules/wms/lib/flashMutationError.js +51 -0
  231. package/dist/modules/wms/lib/flashMutationError.js.map +7 -0
  232. package/dist/modules/wms/lib/inventoryDisplayUi.js +188 -0
  233. package/dist/modules/wms/lib/inventoryDisplayUi.js.map +7 -0
  234. package/dist/modules/wms/lib/inventoryIdempotency.js +37 -0
  235. package/dist/modules/wms/lib/inventoryIdempotency.js.map +7 -0
  236. package/dist/modules/wms/lib/inventoryImportCsv.js +173 -0
  237. package/dist/modules/wms/lib/inventoryImportCsv.js.map +7 -0
  238. package/dist/modules/wms/lib/inventoryImportService.js +468 -0
  239. package/dist/modules/wms/lib/inventoryImportService.js.map +7 -0
  240. package/dist/modules/wms/lib/inventoryMutationUi.js +25 -0
  241. package/dist/modules/wms/lib/inventoryMutationUi.js.map +7 -0
  242. package/dist/modules/wms/lib/inventoryPolicy.js +61 -0
  243. package/dist/modules/wms/lib/inventoryPolicy.js.map +7 -0
  244. package/dist/modules/wms/lib/inventoryReconciliation.js +193 -0
  245. package/dist/modules/wms/lib/inventoryReconciliation.js.map +7 -0
  246. package/dist/modules/wms/lib/inventoryTrackingValidation.js +13 -0
  247. package/dist/modules/wms/lib/inventoryTrackingValidation.js.map +7 -0
  248. package/dist/modules/wms/lib/loadOperationalDashboard.js +580 -0
  249. package/dist/modules/wms/lib/loadOperationalDashboard.js.map +7 -0
  250. package/dist/modules/wms/lib/lowStockBalanceFilter.js +49 -0
  251. package/dist/modules/wms/lib/lowStockBalanceFilter.js.map +7 -0
  252. package/dist/modules/wms/lib/primaryWarehousePolicy.js +32 -0
  253. package/dist/modules/wms/lib/primaryWarehousePolicy.js.map +7 -0
  254. package/dist/modules/wms/lib/roleFeatures.js +30 -0
  255. package/dist/modules/wms/lib/roleFeatures.js.map +7 -0
  256. package/dist/modules/wms/lib/salesOrderInventoryAutomation.js +291 -0
  257. package/dist/modules/wms/lib/salesOrderInventoryAutomation.js.map +7 -0
  258. package/dist/modules/wms/lib/salesOrderWarehouseAssignment.js +54 -0
  259. package/dist/modules/wms/lib/salesOrderWarehouseAssignment.js.map +7 -0
  260. package/dist/modules/wms/lib/wmsIntegrationToggles.js +71 -0
  261. package/dist/modules/wms/lib/wmsIntegrationToggles.js.map +7 -0
  262. package/dist/modules/wms/migrations/Migration20260428110546.js +78 -0
  263. package/dist/modules/wms/migrations/Migration20260428110546.js.map +7 -0
  264. package/dist/modules/wms/migrations/Migration20260527120000.js +15 -0
  265. package/dist/modules/wms/migrations/Migration20260527120000.js.map +7 -0
  266. package/dist/modules/wms/migrations/Migration20260527140000.js +37 -0
  267. package/dist/modules/wms/migrations/Migration20260527140000.js.map +7 -0
  268. package/dist/modules/wms/migrations/Migration20260613120000.js +23 -0
  269. package/dist/modules/wms/migrations/Migration20260613120000.js.map +7 -0
  270. package/dist/modules/wms/migrations/Migration20260616090000.js +13 -0
  271. package/dist/modules/wms/migrations/Migration20260616090000.js.map +7 -0
  272. package/dist/modules/wms/migrations/Migration20260707180000.js +15 -0
  273. package/dist/modules/wms/migrations/Migration20260707180000.js.map +7 -0
  274. package/dist/modules/wms/notifications.client.js +18 -0
  275. package/dist/modules/wms/notifications.client.js.map +7 -0
  276. package/dist/modules/wms/notifications.js +53 -0
  277. package/dist/modules/wms/notifications.js.map +7 -0
  278. package/dist/modules/wms/search.js +196 -0
  279. package/dist/modules/wms/search.js.map +7 -0
  280. package/dist/modules/wms/setup.js +30 -0
  281. package/dist/modules/wms/setup.js.map +7 -0
  282. package/dist/modules/wms/subscribers/low-stock-notification.js +40 -0
  283. package/dist/modules/wms/subscribers/low-stock-notification.js.map +7 -0
  284. package/dist/modules/wms/subscribers/reservation-shortfall-notification.js +69 -0
  285. package/dist/modules/wms/subscribers/reservation-shortfall-notification.js.map +7 -0
  286. package/dist/modules/wms/subscribers/sales-order-cancelled-release.js +14 -0
  287. package/dist/modules/wms/subscribers/sales-order-cancelled-release.js.map +7 -0
  288. package/dist/modules/wms/subscribers/sales-order-confirmed-reserve.js +14 -0
  289. package/dist/modules/wms/subscribers/sales-order-confirmed-reserve.js.map +7 -0
  290. package/dist/modules/wms/translations.js +10 -0
  291. package/dist/modules/wms/translations.js.map +7 -0
  292. package/dist/modules/wms/vector.js +9 -0
  293. package/dist/modules/wms/vector.js.map +7 -0
  294. package/dist/modules/wms/widgets/injection/catalog-inventory-profile/widget.js +200 -0
  295. package/dist/modules/wms/widgets/injection/catalog-inventory-profile/widget.js.map +7 -0
  296. package/dist/modules/wms/widgets/injection/order-items-stock-column/widget.js +104 -0
  297. package/dist/modules/wms/widgets/injection/order-items-stock-column/widget.js.map +7 -0
  298. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js +389 -0
  299. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js.map +7 -0
  300. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.js +16 -0
  301. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.js.map +7 -0
  302. package/dist/modules/wms/widgets/injection-table.js +36 -0
  303. package/dist/modules/wms/widgets/injection-table.js.map +7 -0
  304. package/dist/modules/wms/widgets/notifications/WmsLowStockRenderer.js +150 -0
  305. package/dist/modules/wms/widgets/notifications/WmsLowStockRenderer.js.map +7 -0
  306. package/dist/modules/wms/widgets/notifications/WmsReservationShortfallRenderer.js +186 -0
  307. package/dist/modules/wms/widgets/notifications/WmsReservationShortfallRenderer.js.map +7 -0
  308. package/dist/modules/wms/widgets/notifications/index.js +7 -0
  309. package/dist/modules/wms/widgets/notifications/index.js.map +7 -0
  310. package/generated/entities/inventory_balance/index.ts +9 -0
  311. package/generated/entities/inventory_lot/index.ts +8 -0
  312. package/generated/entities/inventory_movement/index.ts +16 -0
  313. package/generated/entities/inventory_reservation/index.ts +10 -0
  314. package/generated/entities/product_inventory_profile/index.ts +9 -0
  315. package/generated/entities/sales_order_warehouse_assignment/index.ts +4 -0
  316. package/generated/entities/warehouse/index.ts +11 -0
  317. package/generated/entities/warehouse_location/index.ts +9 -0
  318. package/generated/entities/warehouse_zone/index.ts +4 -0
  319. package/generated/entities.ids.generated.ts +12 -0
  320. package/generated/entity-fields-registry.ts +98 -0
  321. package/package.json +7 -7
  322. package/src/modules/auth/backend/roles/page.tsx +13 -4
  323. package/src/modules/auth/i18n/de.json +2 -0
  324. package/src/modules/auth/i18n/en.json +2 -0
  325. package/src/modules/auth/i18n/es.json +2 -0
  326. package/src/modules/auth/i18n/pl.json +2 -0
  327. package/src/modules/auth/lib/backendChrome.tsx +1 -0
  328. package/src/modules/auth/services/rbacService.ts +25 -21
  329. package/src/modules/catalog/api/products/route.ts +3 -0
  330. package/src/modules/catalog/api/variants/route.ts +3 -0
  331. package/src/modules/query_index/lib/engine.ts +18 -6
  332. package/src/modules/sales/api/documents/factory.ts +1 -0
  333. package/src/modules/sales/commands/documents.ts +71 -0
  334. package/src/modules/sales/components/documents/ItemsSection.tsx +58 -0
  335. package/src/modules/sales/events.ts +2 -0
  336. package/src/modules/sales/widgets/injection/order-items-context.ts +15 -0
  337. package/src/modules/wms/acl.ts +14 -0
  338. package/src/modules/wms/analytics.ts +9 -0
  339. package/src/modules/wms/api/dashboard/operational/route.ts +83 -0
  340. package/src/modules/wms/api/interceptors.ts +108 -0
  341. package/src/modules/wms/api/inventory/adjust/route.ts +50 -0
  342. package/src/modules/wms/api/inventory/allocate/route.ts +50 -0
  343. package/src/modules/wms/api/inventory/balances/route.ts +178 -0
  344. package/src/modules/wms/api/inventory/cycle-count/route.ts +51 -0
  345. package/src/modules/wms/api/inventory/helpers.ts +128 -0
  346. package/src/modules/wms/api/inventory/import/apply/route.ts +47 -0
  347. package/src/modules/wms/api/inventory/import/helpers.ts +223 -0
  348. package/src/modules/wms/api/inventory/import/template/route.ts +31 -0
  349. package/src/modules/wms/api/inventory/import/validate/route.ts +56 -0
  350. package/src/modules/wms/api/inventory/move/route.ts +50 -0
  351. package/src/modules/wms/api/inventory/movements/route.ts +164 -0
  352. package/src/modules/wms/api/inventory/receive/route.ts +49 -0
  353. package/src/modules/wms/api/inventory/release/route.ts +43 -0
  354. package/src/modules/wms/api/inventory/reservations/route.ts +128 -0
  355. package/src/modules/wms/api/inventory/reserve/route.ts +59 -0
  356. package/src/modules/wms/api/inventory-profiles/route.ts +177 -0
  357. package/src/modules/wms/api/listEnrichers.ts +312 -0
  358. package/src/modules/wms/api/listSearch.ts +121 -0
  359. package/src/modules/wms/api/locations/route.ts +171 -0
  360. package/src/modules/wms/api/lots/route.ts +205 -0
  361. package/src/modules/wms/api/openapi.ts +28 -0
  362. package/src/modules/wms/api/sales-orders/[salesOrderId]/re-run-reservation/route.ts +58 -0
  363. package/src/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.ts +306 -0
  364. package/src/modules/wms/api/sales-orders/assign-warehouse/route.ts +57 -0
  365. package/src/modules/wms/api/sales-orders/unassign-warehouse/route.ts +43 -0
  366. package/src/modules/wms/api/warehouses/route.ts +181 -0
  367. package/src/modules/wms/api/zones/route.ts +158 -0
  368. package/src/modules/wms/backend/config/wms/page.meta.ts +14 -0
  369. package/src/modules/wms/backend/config/wms/page.tsx +5 -0
  370. package/src/modules/wms/backend/page.meta.ts +12 -0
  371. package/src/modules/wms/backend/page.tsx +5 -0
  372. package/src/modules/wms/backend/wms/inventory/page.meta.ts +14 -0
  373. package/src/modules/wms/backend/wms/inventory/page.tsx +5 -0
  374. package/src/modules/wms/backend/wms/location/[id]/page.meta.ts +14 -0
  375. package/src/modules/wms/backend/wms/location/[id]/page.tsx +5 -0
  376. package/src/modules/wms/backend/wms/locations/page.meta.ts +14 -0
  377. package/src/modules/wms/backend/wms/locations/page.tsx +12 -0
  378. package/src/modules/wms/backend/wms/lot/[id]/page.meta.ts +14 -0
  379. package/src/modules/wms/backend/wms/lot/[id]/page.tsx +5 -0
  380. package/src/modules/wms/backend/wms/lots/page.meta.ts +14 -0
  381. package/src/modules/wms/backend/wms/lots/page.tsx +5 -0
  382. package/src/modules/wms/backend/wms/movements/page.meta.ts +14 -0
  383. package/src/modules/wms/backend/wms/movements/page.tsx +23 -0
  384. package/src/modules/wms/backend/wms/reservations/page.meta.ts +14 -0
  385. package/src/modules/wms/backend/wms/reservations/page.tsx +24 -0
  386. package/src/modules/wms/backend/wms/sku/[id]/page.meta.ts +14 -0
  387. package/src/modules/wms/backend/wms/sku/[id]/page.tsx +5 -0
  388. package/src/modules/wms/backend/wms/warehouses/page.meta.ts +14 -0
  389. package/src/modules/wms/backend/wms/warehouses/page.tsx +12 -0
  390. package/src/modules/wms/backend/wms/zones/page.meta.ts +14 -0
  391. package/src/modules/wms/backend/wms/zones/page.tsx +12 -0
  392. package/src/modules/wms/ce.ts +76 -0
  393. package/src/modules/wms/cli.ts +96 -0
  394. package/src/modules/wms/commands/configuration.ts +1844 -0
  395. package/src/modules/wms/commands/index.ts +3 -0
  396. package/src/modules/wms/commands/inventory-actions.ts +1866 -0
  397. package/src/modules/wms/commands/sales-order-assignment.ts +346 -0
  398. package/src/modules/wms/commands/shared.ts +90 -0
  399. package/src/modules/wms/components/backend/AdjustInventoryDialog.tsx +820 -0
  400. package/src/modules/wms/components/backend/ChangeLotStatusDialog.tsx +312 -0
  401. package/src/modules/wms/components/backend/CycleCountWizardDialog.tsx +2007 -0
  402. package/src/modules/wms/components/backend/ImportInventoryDialog.tsx +1018 -0
  403. package/src/modules/wms/components/backend/InventoryOperationsSection.tsx +159 -0
  404. package/src/modules/wms/components/backend/LocationEditDialog.tsx +185 -0
  405. package/src/modules/wms/components/backend/MoveInventoryDialog.tsx +907 -0
  406. package/src/modules/wms/components/backend/ReceiveInventoryDialog.tsx +695 -0
  407. package/src/modules/wms/components/backend/ReleaseReservationDialog.tsx +424 -0
  408. package/src/modules/wms/components/backend/ReserveInventoryDialog.tsx +511 -0
  409. package/src/modules/wms/components/backend/WmsConfigurationPage.tsx +1340 -0
  410. package/src/modules/wms/components/backend/WmsInventoryConsolePage.tsx +1132 -0
  411. package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +1310 -0
  412. package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +1355 -0
  413. package/src/modules/wms/components/backend/WmsLotsListPage.tsx +359 -0
  414. package/src/modules/wms/components/backend/WmsOperationalDashboardPage.tsx +958 -0
  415. package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +1245 -0
  416. package/src/modules/wms/components/backend/inventoryMutationLoaders.ts +960 -0
  417. package/src/modules/wms/components/backend/useWmsInventoryMutationAccess.ts +89 -0
  418. package/src/modules/wms/components/backend/useWmsInventoryScopeFromSearchParams.ts +32 -0
  419. package/src/modules/wms/components/backend/wmsLookupLoaders.ts +78 -0
  420. package/src/modules/wms/data/enrichers.ts +718 -0
  421. package/src/modules/wms/data/entities.ts +436 -0
  422. package/src/modules/wms/data/validators.ts +463 -0
  423. package/src/modules/wms/di.ts +25 -0
  424. package/src/modules/wms/events.ts +41 -0
  425. package/src/modules/wms/i18n/de.json +1051 -0
  426. package/src/modules/wms/i18n/en.json +1051 -0
  427. package/src/modules/wms/i18n/es.json +1051 -0
  428. package/src/modules/wms/i18n/pl.json +1051 -0
  429. package/src/modules/wms/index.ts +15 -0
  430. package/src/modules/wms/lib/catalogInventoryProfileIntent.ts +65 -0
  431. package/src/modules/wms/lib/catalogInventoryProfileSync.ts +199 -0
  432. package/src/modules/wms/lib/expiry.ts +30 -0
  433. package/src/modules/wms/lib/flashMutationError.ts +74 -0
  434. package/src/modules/wms/lib/inventoryDisplayUi.ts +249 -0
  435. package/src/modules/wms/lib/inventoryIdempotency.ts +54 -0
  436. package/src/modules/wms/lib/inventoryImportCsv.ts +212 -0
  437. package/src/modules/wms/lib/inventoryImportService.ts +629 -0
  438. package/src/modules/wms/lib/inventoryMutationUi.ts +21 -0
  439. package/src/modules/wms/lib/inventoryPolicy.ts +111 -0
  440. package/src/modules/wms/lib/inventoryReconciliation.ts +263 -0
  441. package/src/modules/wms/lib/inventoryTrackingValidation.ts +23 -0
  442. package/src/modules/wms/lib/loadOperationalDashboard.ts +776 -0
  443. package/src/modules/wms/lib/lowStockBalanceFilter.ts +74 -0
  444. package/src/modules/wms/lib/primaryWarehousePolicy.ts +46 -0
  445. package/src/modules/wms/lib/roleFeatures.ts +32 -0
  446. package/src/modules/wms/lib/salesOrderInventoryAutomation.ts +390 -0
  447. package/src/modules/wms/lib/salesOrderWarehouseAssignment.ts +78 -0
  448. package/src/modules/wms/lib/wmsIntegrationToggles.ts +81 -0
  449. package/src/modules/wms/migrations/.snapshot-open-mercato.json +2880 -0
  450. package/src/modules/wms/migrations/Migration20260428110546.ts +91 -0
  451. package/src/modules/wms/migrations/Migration20260527120000.ts +15 -0
  452. package/src/modules/wms/migrations/Migration20260527140000.ts +35 -0
  453. package/src/modules/wms/migrations/Migration20260613120000.ts +21 -0
  454. package/src/modules/wms/migrations/Migration20260616090000.ts +11 -0
  455. package/src/modules/wms/migrations/Migration20260707180000.ts +13 -0
  456. package/src/modules/wms/notifications.client.ts +18 -0
  457. package/src/modules/wms/notifications.ts +51 -0
  458. package/src/modules/wms/search.ts +230 -0
  459. package/src/modules/wms/setup.ts +29 -0
  460. package/src/modules/wms/subscribers/low-stock-notification.ts +54 -0
  461. package/src/modules/wms/subscribers/reservation-shortfall-notification.ts +98 -0
  462. package/src/modules/wms/subscribers/sales-order-cancelled-release.ts +21 -0
  463. package/src/modules/wms/subscribers/sales-order-confirmed-reserve.ts +21 -0
  464. package/src/modules/wms/translations.ts +6 -0
  465. package/src/modules/wms/vector.ts +7 -0
  466. package/src/modules/wms/widgets/injection/catalog-inventory-profile/widget.ts +238 -0
  467. package/src/modules/wms/widgets/injection/order-items-stock-column/widget.tsx +153 -0
  468. package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.client.tsx +476 -0
  469. package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.ts +15 -0
  470. package/src/modules/wms/widgets/injection-table.ts +34 -0
  471. package/src/modules/wms/widgets/notifications/WmsLowStockRenderer.tsx +153 -0
  472. package/src/modules/wms/widgets/notifications/WmsReservationShortfallRenderer.tsx +194 -0
  473. package/src/modules/wms/widgets/notifications/index.ts +2 -0
@@ -0,0 +1,776 @@
1
+ import type { EntityManager } from '@mikro-orm/postgresql'
2
+ import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
3
+ import {
4
+ InventoryBalance,
5
+ InventoryLot,
6
+ InventoryMovement,
7
+ InventoryReservation,
8
+ ProductInventoryProfile,
9
+ Warehouse,
10
+ } from '../data/entities'
11
+ import { evaluateLowStock } from './inventoryPolicy'
12
+ import { addUtcDays, EXPIRING_SOON_DAYS, startOfUtcDay } from './expiry'
13
+
14
+ const AGING_RESERVATION_DAYS = 7
15
+ const TREND_DAYS = 7
16
+ const MONTHLY_TREND_MONTHS = 6
17
+ const ACTIVITY_LIMIT = 10
18
+ const EXPIRY_CARD_LIMIT = 5
19
+
20
+ export type OperationalDashboardScope = {
21
+ organizationId: string
22
+ tenantId: string
23
+ warehouseId?: string | null
24
+ }
25
+
26
+ export type OperationalDashboardKpiId =
27
+ | 'lowStock'
28
+ | 'reorderCritical'
29
+ | 'expiringSoon'
30
+ | 'pastDue'
31
+ | 'agingReservations'
32
+ | 'todaysMoves'
33
+
34
+ export type OperationalDashboardKpi = {
35
+ id: OperationalDashboardKpiId
36
+ count: number
37
+ deltaSinceYesterday: number | null
38
+ sparkline: number[]
39
+ }
40
+
41
+ export type OperationalDashboardTrendPoint = {
42
+ month: string
43
+ receive: number
44
+ allocate: number
45
+ }
46
+
47
+ export type OperationalDashboardActivityRow = {
48
+ id: string
49
+ movementType: string
50
+ quantity: number
51
+ variantSku: string | null
52
+ variantId: string
53
+ referenceType: string | null
54
+ referenceId: string | null
55
+ reason: string | null
56
+ reasonCode: string | null
57
+ locationLabel: string
58
+ performedAt: string
59
+ }
60
+
61
+ export type OperationalDashboardExpiryLotRow = {
62
+ id: string
63
+ lotNumber: string
64
+ sku: string
65
+ catalogVariantId: string
66
+ expiresAt: string
67
+ availableQuantity: number
68
+ status: string
69
+ updatedAt: string | null
70
+ category: 'expiringSoon' | 'pastDue'
71
+ }
72
+
73
+ export type OperationalDashboardPayload = {
74
+ lastUpdatedAt: string
75
+ warehouseId: string | null
76
+ kpis: OperationalDashboardKpi[]
77
+ expiryLots: OperationalDashboardExpiryLotRow[]
78
+ monthlyTrends: OperationalDashboardTrendPoint[]
79
+ recentActivity: OperationalDashboardActivityRow[]
80
+ }
81
+
82
+ export class OperationalDashboardWarehouseNotFoundError extends Error {
83
+ readonly warehouseId: string
84
+
85
+ constructor(warehouseId: string) {
86
+ super(`Warehouse ${warehouseId} not found`)
87
+ this.name = 'OperationalDashboardWarehouseNotFoundError'
88
+ this.warehouseId = warehouseId
89
+ }
90
+ }
91
+
92
+ type DecryptionScope = {
93
+ tenantId: string
94
+ organizationId: string
95
+ }
96
+
97
+ type DailyCountRow = {
98
+ day: Date | string
99
+ count: string | number
100
+ }
101
+
102
+ type MonthlyTrendRow = {
103
+ month_start: Date | string
104
+ type: string
105
+ count: string | number
106
+ }
107
+
108
+ export function toOperationalDashboardNumber(value: string | number | null | undefined): number {
109
+ if (typeof value === 'number') return value
110
+ if (typeof value === 'string' && value.trim().length > 0) return Number(value)
111
+ return 0
112
+ }
113
+
114
+ export { addUtcDays, startOfUtcDay } from './expiry'
115
+
116
+ function formatMonthKey(date: Date): string {
117
+ return date.toLocaleString('en-US', { month: 'short', timeZone: 'UTC' })
118
+ }
119
+
120
+ export function buildDailyBuckets(days: number, now: Date): Date[] {
121
+ const today = startOfUtcDay(now)
122
+ const buckets: Date[] = []
123
+ for (let offset = days - 1; offset >= 0; offset -= 1) {
124
+ buckets.push(addUtcDays(today, -offset))
125
+ }
126
+ return buckets
127
+ }
128
+
129
+ export function mapDailyCountsToSparkline(
130
+ dayBuckets: Date[],
131
+ rows: Array<{ day: Date | string; count: string | number }>,
132
+ ): number[] {
133
+ const counts = new Map<number, number>()
134
+ for (const bucket of dayBuckets) {
135
+ counts.set(bucket.getTime(), 0)
136
+ }
137
+ for (const row of rows) {
138
+ const day = startOfUtcDay(row.day instanceof Date ? row.day : new Date(row.day)).getTime()
139
+ if (counts.has(day)) {
140
+ counts.set(day, toOperationalDashboardNumber(row.count))
141
+ }
142
+ }
143
+ return dayBuckets.map((bucket) => counts.get(bucket.getTime()) ?? 0)
144
+ }
145
+
146
+ export function resolveLotAvailableQuantity(
147
+ lotId: string,
148
+ balances: InventoryBalance[],
149
+ warehouseId?: string | null,
150
+ ): number {
151
+ let total = 0
152
+ for (const balance of balances) {
153
+ if (balance.lot?.id !== lotId) continue
154
+ if (warehouseId && balance.warehouse.id !== warehouseId) continue
155
+ const available =
156
+ toOperationalDashboardNumber(balance.quantityOnHand)
157
+ - toOperationalDashboardNumber(balance.quantityReserved)
158
+ - toOperationalDashboardNumber(balance.quantityAllocated)
159
+ if (available > 0) total += available
160
+ }
161
+ return total
162
+ }
163
+
164
+ export function buildExpiryLotRows(
165
+ expiringSoonLots: InventoryLot[],
166
+ pastDueLots: InventoryLot[],
167
+ balances: InventoryBalance[],
168
+ warehouseId?: string | null,
169
+ limit = EXPIRY_CARD_LIMIT,
170
+ ): OperationalDashboardExpiryLotRow[] {
171
+ const expiringRows = expiringSoonLots
172
+ .map((lot) => ({
173
+ lot,
174
+ availableQuantity: resolveLotAvailableQuantity(lot.id, balances, warehouseId),
175
+ }))
176
+ .filter(({ availableQuantity }) => availableQuantity > 0)
177
+ .sort((left, right) => {
178
+ const leftTime = left.lot.expiresAt?.getTime() ?? 0
179
+ const rightTime = right.lot.expiresAt?.getTime() ?? 0
180
+ return leftTime - rightTime
181
+ })
182
+ .slice(0, limit)
183
+ .map(({ lot, availableQuantity }) => ({
184
+ id: lot.id,
185
+ lotNumber: lot.lotNumber,
186
+ sku: lot.sku,
187
+ catalogVariantId: lot.catalogVariantId,
188
+ expiresAt: lot.expiresAt!.toISOString(),
189
+ availableQuantity,
190
+ status: lot.status,
191
+ updatedAt: lot.updatedAt?.toISOString() ?? null,
192
+ category: 'expiringSoon' as const,
193
+ }))
194
+
195
+ const pastDueRows = pastDueLots
196
+ .map((lot) => ({
197
+ lot,
198
+ availableQuantity: resolveLotAvailableQuantity(lot.id, balances, warehouseId),
199
+ }))
200
+ .filter(({ availableQuantity }) => availableQuantity > 0)
201
+ .sort((left, right) => {
202
+ const leftTime = left.lot.expiresAt?.getTime() ?? 0
203
+ const rightTime = right.lot.expiresAt?.getTime() ?? 0
204
+ return leftTime - rightTime
205
+ })
206
+ .slice(0, limit)
207
+ .map(({ lot, availableQuantity }) => ({
208
+ id: lot.id,
209
+ lotNumber: lot.lotNumber,
210
+ sku: lot.sku,
211
+ catalogVariantId: lot.catalogVariantId,
212
+ expiresAt: lot.expiresAt!.toISOString(),
213
+ availableQuantity,
214
+ status: lot.status,
215
+ updatedAt: lot.updatedAt?.toISOString() ?? null,
216
+ category: 'pastDue' as const,
217
+ }))
218
+
219
+ return [...expiringRows, ...pastDueRows]
220
+ }
221
+
222
+ export function computeLowStockCounts(
223
+ profiles: ProductInventoryProfile[],
224
+ balances: InventoryBalance[],
225
+ warehouseId?: string | null,
226
+ ): { lowStockCount: number; reorderCriticalCount: number } {
227
+ const availableByVariantWarehouse = new Map<string, number>()
228
+ for (const balance of balances) {
229
+ const onHand = toOperationalDashboardNumber(balance.quantityOnHand)
230
+ const reserved = toOperationalDashboardNumber(balance.quantityReserved)
231
+ const allocated = toOperationalDashboardNumber(balance.quantityAllocated)
232
+ const available = onHand - reserved - allocated
233
+ const key = `${balance.catalogVariantId}::${balance.warehouse.id}`
234
+ availableByVariantWarehouse.set(key, (availableByVariantWarehouse.get(key) ?? 0) + available)
235
+ }
236
+
237
+ let lowStockCount = 0
238
+ let reorderCriticalCount = 0
239
+ const seenLowStockKeys = new Set<string>()
240
+
241
+ for (const profile of profiles) {
242
+ const variantId = profile.catalogVariantId
243
+ if (!variantId) continue
244
+ const reorderPoint = toOperationalDashboardNumber(profile.reorderPoint)
245
+ const safetyStock = toOperationalDashboardNumber(profile.safetyStock)
246
+ if (reorderPoint <= 0 && safetyStock <= 0) continue
247
+
248
+ const warehouseIds = warehouseId
249
+ ? [warehouseId]
250
+ : Array.from(new Set(balances.map((balance) => balance.warehouse.id)))
251
+
252
+ for (const scopedWarehouseId of warehouseIds) {
253
+ const key = `${variantId}::${scopedWarehouseId}`
254
+ const available = availableByVariantWarehouse.get(key) ?? 0
255
+ const evaluation = evaluateLowStock(
256
+ { reorderPoint: profile.reorderPoint, safetyStock: profile.safetyStock },
257
+ available,
258
+ )
259
+ if (!evaluation) continue
260
+ if (seenLowStockKeys.has(key)) continue
261
+ seenLowStockKeys.add(key)
262
+ lowStockCount += 1
263
+ if (evaluation.state === 'below_safety_stock') {
264
+ reorderCriticalCount += 1
265
+ }
266
+ }
267
+ }
268
+
269
+ return { lowStockCount, reorderCriticalCount }
270
+ }
271
+
272
+ function resolveWarehouseLabel(
273
+ warehouse: Warehouse | undefined,
274
+ warehouseId: string,
275
+ ): string {
276
+ return warehouse?.code?.trim() || warehouse?.name?.trim() || warehouseId
277
+ }
278
+
279
+ function resolveLocationLabel(
280
+ warehouseLabel: string,
281
+ fromCode?: string | null,
282
+ toCode?: string | null,
283
+ ): string {
284
+ if (fromCode && toCode) return `${fromCode} → ${toCode}`
285
+ if (toCode) return `${warehouseLabel} · ${toCode}`
286
+ if (fromCode) return `${warehouseLabel} · ${fromCode}`
287
+ return warehouseLabel
288
+ }
289
+
290
+ function resolveDecryptionScope(scope: OperationalDashboardScope): DecryptionScope {
291
+ return {
292
+ tenantId: scope.tenantId,
293
+ organizationId: scope.organizationId,
294
+ }
295
+ }
296
+
297
+ function appendWarehouseFilter(
298
+ sql: string,
299
+ params: unknown[],
300
+ warehouseId?: string | null,
301
+ ): string {
302
+ if (!warehouseId) return sql
303
+ params.push(warehouseId)
304
+ return `${sql} and warehouse_id = ?`
305
+ }
306
+
307
+ async function loadVariantSkus(
308
+ em: EntityManager,
309
+ scope: OperationalDashboardScope,
310
+ variantIds: string[],
311
+ ): Promise<Map<string, string>> {
312
+ if (variantIds.length === 0) return new Map()
313
+ const rows = await em.getConnection().execute<Array<{ id: string; sku: string | null }>>(
314
+ `select id, sku from catalog_product_variants
315
+ where organization_id = ? and tenant_id = ? and id in (${variantIds.map(() => '?').join(', ')})
316
+ and deleted_at is null`,
317
+ [scope.organizationId, scope.tenantId, ...variantIds],
318
+ )
319
+ const map = new Map<string, string>()
320
+ for (const row of rows) {
321
+ if (row.id && row.sku) map.set(row.id, row.sku)
322
+ }
323
+ return map
324
+ }
325
+
326
+ async function countMovementsBetween(
327
+ em: EntityManager,
328
+ scope: OperationalDashboardScope,
329
+ start: Date,
330
+ end: Date,
331
+ options?: { types?: string[]; quantitySign?: 'negative' },
332
+ ): Promise<number> {
333
+ const params: unknown[] = [scope.organizationId, scope.tenantId, start, end]
334
+ let sql = `
335
+ select count(*)::int as count
336
+ from wms_inventory_movements
337
+ where organization_id = ? and tenant_id = ? and deleted_at is null
338
+ and performed_at >= ? and performed_at < ?
339
+ `
340
+ sql = appendWarehouseFilter(sql, params, scope.warehouseId)
341
+ if (options?.types?.length) {
342
+ sql += ` and type in (${options.types.map(() => '?').join(', ')})`
343
+ params.push(...options.types)
344
+ }
345
+ if (options?.quantitySign === 'negative') {
346
+ sql += ' and quantity < 0'
347
+ }
348
+ const rows = await em.getConnection().execute<Array<{ count: string | number }>>(sql, params)
349
+ return toOperationalDashboardNumber(rows[0]?.count)
350
+ }
351
+
352
+ async function loadMovementDailyCounts(
353
+ em: EntityManager,
354
+ scope: OperationalDashboardScope,
355
+ start: Date,
356
+ options?: { types?: string[]; quantitySign?: 'negative' },
357
+ ): Promise<DailyCountRow[]> {
358
+ const params: unknown[] = [scope.organizationId, scope.tenantId, start]
359
+ let sql = `
360
+ select date_trunc('day', performed_at) as day, count(*)::int as count
361
+ from wms_inventory_movements
362
+ where organization_id = ? and tenant_id = ? and deleted_at is null
363
+ and performed_at >= ?
364
+ `
365
+ sql = appendWarehouseFilter(sql, params, scope.warehouseId)
366
+ if (options?.types?.length) {
367
+ sql += ` and type in (${options.types.map(() => '?').join(', ')})`
368
+ params.push(...options.types)
369
+ }
370
+ if (options?.quantitySign === 'negative') {
371
+ sql += ' and quantity < 0'
372
+ }
373
+ sql += ' group by 1 order by 1'
374
+ return em.getConnection().execute<DailyCountRow[]>(sql, params)
375
+ }
376
+
377
+ async function loadMonthlyMovementTrends(
378
+ em: EntityManager,
379
+ scope: OperationalDashboardScope,
380
+ monthlyStart: Date,
381
+ now: Date,
382
+ ): Promise<OperationalDashboardTrendPoint[]> {
383
+ const params: unknown[] = [scope.organizationId, scope.tenantId, monthlyStart]
384
+ let sql = `
385
+ select date_trunc('month', performed_at) as month_start, type, count(*)::int as count
386
+ from wms_inventory_movements
387
+ where organization_id = ? and tenant_id = ? and deleted_at is null
388
+ and performed_at >= ?
389
+ `
390
+ sql = appendWarehouseFilter(sql, params, scope.warehouseId)
391
+ sql += ' group by 1, 2 order by 1'
392
+
393
+ const rows = await em.getConnection().execute<MonthlyTrendRow[]>(sql, params)
394
+ const monthlyTrendMap = new Map<string, { receive: number; allocate: number }>()
395
+ for (let index = 0; index < MONTHLY_TREND_MONTHS; index += 1) {
396
+ const monthDate = new Date(
397
+ Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - (MONTHLY_TREND_MONTHS - 1 - index), 1),
398
+ )
399
+ monthlyTrendMap.set(formatMonthKey(monthDate), { receive: 0, allocate: 0 })
400
+ }
401
+
402
+ for (const row of rows) {
403
+ const monthDate = row.month_start instanceof Date ? row.month_start : new Date(row.month_start)
404
+ const key = formatMonthKey(monthDate)
405
+ const bucket = monthlyTrendMap.get(key)
406
+ if (!bucket) continue
407
+ if (row.type === 'receipt' || row.type === 'return_receive') {
408
+ bucket.receive += toOperationalDashboardNumber(row.count)
409
+ }
410
+ if (row.type === 'pick' || row.type === 'pack') {
411
+ bucket.allocate += toOperationalDashboardNumber(row.count)
412
+ }
413
+ }
414
+
415
+ return Array.from(monthlyTrendMap.entries()).map(([month, values]) => ({
416
+ month,
417
+ receive: values.receive,
418
+ allocate: values.allocate,
419
+ }))
420
+ }
421
+
422
+ async function loadExpiringSoonDailyCounts(
423
+ em: EntityManager,
424
+ scope: OperationalDashboardScope,
425
+ dayBuckets: Date[],
426
+ ): Promise<DailyCountRow[]> {
427
+ if (dayBuckets.length === 0) return []
428
+ const trendStart = dayBuckets[0]!
429
+ const trendEnd = dayBuckets[dayBuckets.length - 1]!
430
+ const params: unknown[] = [
431
+ trendStart,
432
+ trendEnd,
433
+ scope.organizationId,
434
+ scope.tenantId,
435
+ ]
436
+ let sql = `
437
+ select bucket.day as day, count(distinct l.id)::int as count
438
+ from (
439
+ select generate_series(?::timestamptz, ?::timestamptz, interval '1 day') as day
440
+ ) bucket
441
+ join wms_inventory_lots l
442
+ on l.organization_id = ?
443
+ and l.tenant_id = ?
444
+ and l.deleted_at is null
445
+ and l.status = 'available'
446
+ and l.expires_at is not null
447
+ and l.expires_at >= bucket.day
448
+ and l.expires_at <= bucket.day + interval '${EXPIRING_SOON_DAYS} days'
449
+ `
450
+ if (scope.warehouseId) {
451
+ sql += `
452
+ join wms_inventory_balances b
453
+ on b.lot_id = l.id
454
+ and b.deleted_at is null
455
+ and b.warehouse_id = ?
456
+ `
457
+ params.push(scope.warehouseId)
458
+ }
459
+ sql += ' group by bucket.day order by bucket.day'
460
+ return em.getConnection().execute<DailyCountRow[]>(sql, params)
461
+ }
462
+
463
+ async function loadPastDueLotCount(
464
+ em: EntityManager,
465
+ scope: OperationalDashboardScope,
466
+ todayStart: Date,
467
+ ): Promise<number> {
468
+ const params: unknown[] = [scope.organizationId, scope.tenantId, todayStart]
469
+ let sql = `
470
+ select count(distinct l.id)::int as count
471
+ from wms_inventory_lots l
472
+ join wms_inventory_balances b
473
+ on b.lot_id = l.id
474
+ and b.deleted_at is null
475
+ and (
476
+ coalesce(b.quantity_on_hand, 0)
477
+ - coalesce(b.quantity_reserved, 0)
478
+ - coalesce(b.quantity_allocated, 0)
479
+ ) > 0
480
+ where l.organization_id = ?
481
+ and l.tenant_id = ?
482
+ and l.deleted_at is null
483
+ and l.status = 'available'
484
+ and l.expires_at is not null
485
+ and l.expires_at < ?
486
+ `
487
+ if (scope.warehouseId) {
488
+ sql += ' and b.warehouse_id = ?'
489
+ params.push(scope.warehouseId)
490
+ }
491
+ const rows = await em.getConnection().execute<Array<{ count: string | number }>>(sql, params)
492
+ return toOperationalDashboardNumber(rows[0]?.count)
493
+ }
494
+
495
+ async function loadPastDueDailyCounts(
496
+ em: EntityManager,
497
+ scope: OperationalDashboardScope,
498
+ dayBuckets: Date[],
499
+ ): Promise<DailyCountRow[]> {
500
+ if (dayBuckets.length === 0) return []
501
+ const params: unknown[] = [
502
+ dayBuckets[0]!,
503
+ dayBuckets[dayBuckets.length - 1]!,
504
+ scope.organizationId,
505
+ scope.tenantId,
506
+ ]
507
+ let sql = `
508
+ select bucket.day as day, count(distinct l.id)::int as count
509
+ from (
510
+ select generate_series(?::timestamptz, ?::timestamptz, interval '1 day') as day
511
+ ) bucket
512
+ join wms_inventory_lots l
513
+ on l.organization_id = ?
514
+ and l.tenant_id = ?
515
+ and l.deleted_at is null
516
+ and l.status = 'available'
517
+ and l.expires_at is not null
518
+ and l.expires_at < bucket.day
519
+ join wms_inventory_balances b
520
+ on b.lot_id = l.id
521
+ and b.deleted_at is null
522
+ and (
523
+ coalesce(b.quantity_on_hand, 0)
524
+ - coalesce(b.quantity_reserved, 0)
525
+ - coalesce(b.quantity_allocated, 0)
526
+ ) > 0
527
+ `
528
+ if (scope.warehouseId) {
529
+ sql += ' and b.warehouse_id = ?'
530
+ params.push(scope.warehouseId)
531
+ }
532
+ sql += ' group by bucket.day order by bucket.day'
533
+ return em.getConnection().execute<DailyCountRow[]>(sql, params)
534
+ }
535
+
536
+ async function loadAgingReservationsDailyCounts(
537
+ em: EntityManager,
538
+ scope: OperationalDashboardScope,
539
+ dayBuckets: Date[],
540
+ ): Promise<DailyCountRow[]> {
541
+ if (dayBuckets.length === 0) return []
542
+ const params: unknown[] = [
543
+ dayBuckets[0]!,
544
+ dayBuckets[dayBuckets.length - 1]!,
545
+ scope.organizationId,
546
+ scope.tenantId,
547
+ String(AGING_RESERVATION_DAYS),
548
+ ]
549
+ let sql = `
550
+ select bucket.day as day, count(r.id)::int as count
551
+ from (
552
+ select generate_series(?::timestamptz, ?::timestamptz, interval '1 day') as day
553
+ ) bucket
554
+ join wms_inventory_reservations r
555
+ on r.organization_id = ?
556
+ and r.tenant_id = ?
557
+ and r.deleted_at is null
558
+ and r.status = 'active'
559
+ and r.created_at <= bucket.day - (?::int * interval '1 day')
560
+ `
561
+ sql = appendWarehouseFilter(sql, params, scope.warehouseId)
562
+ sql += ' group by bucket.day order by bucket.day'
563
+ return em.getConnection().execute<DailyCountRow[]>(sql, params)
564
+ }
565
+
566
+ export async function loadOperationalDashboard(
567
+ em: EntityManager,
568
+ scope: OperationalDashboardScope,
569
+ ): Promise<OperationalDashboardPayload> {
570
+ const now = new Date()
571
+ const todayStart = startOfUtcDay(now)
572
+ const tomorrowStart = addUtcDays(todayStart, 1)
573
+ const yesterdayStart = addUtcDays(todayStart, -1)
574
+ const agingCutoff = addUtcDays(todayStart, -AGING_RESERVATION_DAYS)
575
+ const expiringCutoff = addUtcDays(todayStart, EXPIRING_SOON_DAYS)
576
+ const trendStart = addUtcDays(todayStart, -(TREND_DAYS - 1))
577
+ const dayBuckets = buildDailyBuckets(TREND_DAYS, now)
578
+ const decryptionScope = resolveDecryptionScope(scope)
579
+
580
+ const baseScope = {
581
+ organizationId: scope.organizationId,
582
+ tenantId: scope.tenantId,
583
+ deletedAt: null as Date | null,
584
+ }
585
+
586
+ if (scope.warehouseId) {
587
+ const warehouse = await findOneWithDecryption(
588
+ em,
589
+ Warehouse,
590
+ { id: scope.warehouseId, ...baseScope },
591
+ undefined,
592
+ decryptionScope,
593
+ )
594
+ if (!warehouse) {
595
+ throw new OperationalDashboardWarehouseNotFoundError(scope.warehouseId)
596
+ }
597
+ }
598
+
599
+ const warehouseFilter = scope.warehouseId ? { warehouse: scope.warehouseId } : {}
600
+
601
+ const [profiles, balances, expiringSoonLots, pastDueLots, reservations, activityMovements] = await Promise.all([
602
+ findWithDecryption(em, ProductInventoryProfile, baseScope, undefined, decryptionScope),
603
+ findWithDecryption(
604
+ em,
605
+ InventoryBalance,
606
+ { ...baseScope, ...warehouseFilter },
607
+ { populate: ['warehouse', 'location', 'lot'] },
608
+ decryptionScope,
609
+ ),
610
+ findWithDecryption(
611
+ em,
612
+ InventoryLot,
613
+ {
614
+ ...baseScope,
615
+ status: 'available',
616
+ expiresAt: { $ne: null, $gte: todayStart, $lte: expiringCutoff },
617
+ },
618
+ { orderBy: { expiresAt: 'ASC' }, limit: 100 },
619
+ decryptionScope,
620
+ ),
621
+ findWithDecryption(
622
+ em,
623
+ InventoryLot,
624
+ {
625
+ ...baseScope,
626
+ status: 'available',
627
+ expiresAt: { $ne: null, $lt: todayStart },
628
+ },
629
+ { orderBy: { expiresAt: 'ASC' }, limit: 100 },
630
+ decryptionScope,
631
+ ),
632
+ findWithDecryption(
633
+ em,
634
+ InventoryReservation,
635
+ {
636
+ ...baseScope,
637
+ ...warehouseFilter,
638
+ status: 'active',
639
+ createdAt: { $lte: agingCutoff },
640
+ },
641
+ undefined,
642
+ decryptionScope,
643
+ ),
644
+ findWithDecryption(
645
+ em,
646
+ InventoryMovement,
647
+ { ...baseScope, ...warehouseFilter },
648
+ {
649
+ populate: ['warehouse', 'locationFrom', 'locationTo'],
650
+ orderBy: { performedAt: 'DESC' },
651
+ limit: ACTIVITY_LIMIT,
652
+ },
653
+ decryptionScope,
654
+ ),
655
+ ])
656
+
657
+ const { lowStockCount, reorderCriticalCount } = computeLowStockCounts(
658
+ profiles,
659
+ balances,
660
+ scope.warehouseId,
661
+ )
662
+
663
+ const expiringSoonCount = expiringSoonLots.filter(
664
+ (lot) => resolveLotAvailableQuantity(lot.id, balances, scope.warehouseId) > 0,
665
+ ).length
666
+
667
+ const agingReservationsCount = reservations.length
668
+
669
+ const [
670
+ todaysMoveCount,
671
+ yesterdaysMoveCount,
672
+ pastDueCount,
673
+ lowStockSparklineRows,
674
+ reorderCriticalSparklineRows,
675
+ expiringSoonSparklineRows,
676
+ pastDueSparklineRows,
677
+ agingReservationsSparklineRows,
678
+ todaysMovesSparklineRows,
679
+ monthlyTrends,
680
+ ] = await Promise.all([
681
+ countMovementsBetween(em, scope, todayStart, tomorrowStart),
682
+ countMovementsBetween(em, scope, yesterdayStart, todayStart),
683
+ loadPastDueLotCount(em, scope, todayStart),
684
+ loadMovementDailyCounts(em, scope, trendStart, { types: ['adjust'], quantitySign: 'negative' }),
685
+ loadMovementDailyCounts(em, scope, trendStart, { types: ['adjust'], quantitySign: 'negative' }),
686
+ loadExpiringSoonDailyCounts(em, scope, dayBuckets),
687
+ loadPastDueDailyCounts(em, scope, dayBuckets),
688
+ loadAgingReservationsDailyCounts(em, scope, dayBuckets),
689
+ loadMovementDailyCounts(em, scope, trendStart),
690
+ loadMonthlyMovementTrends(
691
+ em,
692
+ scope,
693
+ new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - (MONTHLY_TREND_MONTHS - 1), 1)),
694
+ now,
695
+ ),
696
+ ])
697
+
698
+ const kpis: OperationalDashboardKpi[] = [
699
+ {
700
+ id: 'lowStock',
701
+ count: lowStockCount,
702
+ deltaSinceYesterday: null,
703
+ sparkline: mapDailyCountsToSparkline(dayBuckets, lowStockSparklineRows),
704
+ },
705
+ {
706
+ id: 'reorderCritical',
707
+ count: reorderCriticalCount,
708
+ deltaSinceYesterday: null,
709
+ sparkline: mapDailyCountsToSparkline(dayBuckets, reorderCriticalSparklineRows),
710
+ },
711
+ {
712
+ id: 'expiringSoon',
713
+ count: expiringSoonCount,
714
+ deltaSinceYesterday: null,
715
+ sparkline: mapDailyCountsToSparkline(dayBuckets, expiringSoonSparklineRows),
716
+ },
717
+ {
718
+ id: 'pastDue',
719
+ count: pastDueCount,
720
+ deltaSinceYesterday: null,
721
+ sparkline: mapDailyCountsToSparkline(dayBuckets, pastDueSparklineRows),
722
+ },
723
+ {
724
+ id: 'agingReservations',
725
+ count: agingReservationsCount,
726
+ deltaSinceYesterday: null,
727
+ sparkline: mapDailyCountsToSparkline(dayBuckets, agingReservationsSparklineRows),
728
+ },
729
+ {
730
+ id: 'todaysMoves',
731
+ count: todaysMoveCount,
732
+ deltaSinceYesterday: todaysMoveCount - yesterdaysMoveCount,
733
+ sparkline: mapDailyCountsToSparkline(dayBuckets, todaysMovesSparklineRows),
734
+ },
735
+ ]
736
+
737
+ const variantIds = Array.from(new Set(activityMovements.map((movement) => movement.catalogVariantId)))
738
+ const variantSkus = await loadVariantSkus(em, scope, variantIds)
739
+
740
+ const recentActivity: OperationalDashboardActivityRow[] = activityMovements.map((movement) => {
741
+ const warehouseLabel = resolveWarehouseLabel(movement.warehouse, movement.warehouse.id)
742
+ return {
743
+ id: movement.id,
744
+ movementType: movement.type,
745
+ quantity: toOperationalDashboardNumber(movement.quantity),
746
+ variantSku: variantSkus.get(movement.catalogVariantId) ?? null,
747
+ variantId: movement.catalogVariantId,
748
+ referenceType: movement.referenceType ?? null,
749
+ referenceId: movement.referenceId ?? null,
750
+ reason: movement.reason ?? null,
751
+ reasonCode: movement.reasonCode ?? null,
752
+ locationLabel: resolveLocationLabel(
753
+ warehouseLabel,
754
+ movement.locationFrom?.code,
755
+ movement.locationTo?.code,
756
+ ),
757
+ performedAt: movement.performedAt.toISOString(),
758
+ }
759
+ })
760
+
761
+ const expiryLots = buildExpiryLotRows(
762
+ expiringSoonLots,
763
+ pastDueLots,
764
+ balances,
765
+ scope.warehouseId,
766
+ )
767
+
768
+ return {
769
+ lastUpdatedAt: now.toISOString(),
770
+ warehouseId: scope.warehouseId ?? null,
771
+ kpis,
772
+ expiryLots,
773
+ monthlyTrends,
774
+ recentActivity,
775
+ }
776
+ }