@rytass/wms-module-core 0.8.1 → 0.9.0

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 (73) hide show
  1. package/index.cjs.js +1689 -199
  2. package/index.js +11 -1
  3. package/lib/constants/consumption-change-kind.d.ts +17 -0
  4. package/lib/constants/consumption-change-kind.js +20 -0
  5. package/lib/constants/index.d.ts +2 -0
  6. package/lib/constants/operations.d.ts +1 -1
  7. package/lib/constants/operations.js +9 -0
  8. package/lib/constants/order-type.d.ts +30 -0
  9. package/lib/constants/order-type.js +33 -0
  10. package/lib/constants/stock-status.d.ts +4 -1
  11. package/lib/constants/stock-status.js +6 -0
  12. package/lib/core.module.js +87 -3
  13. package/lib/events/index.d.ts +2 -1
  14. package/lib/events/stock-change.subscriber.d.ts +26 -1
  15. package/lib/events/stock-change.subscriber.js +98 -15
  16. package/lib/events/wms-event.tokens.d.ts +2 -0
  17. package/lib/events/wms-event.tokens.js +3 -1
  18. package/lib/events/wms-event.types.d.ts +38 -6
  19. package/lib/events/wms-operation-runner.d.ts +57 -0
  20. package/lib/events/wms-operation-runner.js +101 -0
  21. package/lib/models/extensions/consumption-order/consumption-order-change.entity.d.ts +19 -0
  22. package/lib/models/extensions/consumption-order/consumption-order-change.entity.js +59 -0
  23. package/lib/models/extensions/consumption-order/consumption-order-item.entity.d.ts +26 -0
  24. package/lib/models/extensions/consumption-order/consumption-order-item.entity.js +114 -0
  25. package/lib/models/extensions/consumption-order/consumption-order.entity.d.ts +32 -0
  26. package/lib/models/extensions/consumption-order/consumption-order.entity.js +69 -0
  27. package/lib/models/extensions/consumption-order/index.d.ts +3 -0
  28. package/lib/models/extensions/index.d.ts +4 -0
  29. package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.d.ts +13 -1
  30. package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.js +17 -1
  31. package/lib/models/extensions/order-reference/index.d.ts +1 -0
  32. package/lib/models/extensions/order-reference/order-reference.entity.d.ts +49 -0
  33. package/lib/models/extensions/order-reference/order-reference.entity.js +95 -0
  34. package/lib/models/metadata/batch.entity.d.ts +46 -0
  35. package/lib/models/metadata/batch.entity.js +58 -0
  36. package/lib/models/models.module.js +8 -0
  37. package/lib/services/allocate-inventory-order.service.js +4 -0
  38. package/lib/services/base-order.service.d.ts +18 -3
  39. package/lib/services/base-order.service.js +76 -0
  40. package/lib/services/batch.service.d.ts +17 -0
  41. package/lib/services/batch.service.js +41 -1
  42. package/lib/services/consumption-order.service.d.ts +75 -0
  43. package/lib/services/consumption-order.service.js +504 -0
  44. package/lib/services/hold-inventory-order.service.js +4 -0
  45. package/lib/services/index.d.ts +3 -0
  46. package/lib/services/inventory-count-order.service.js +7 -0
  47. package/lib/services/loader.service.js +4 -0
  48. package/lib/services/location.service.js +4 -0
  49. package/lib/services/material.service.js +4 -0
  50. package/lib/services/merge-batch-order.service.js +4 -0
  51. package/lib/services/order-reference.service.d.ts +50 -0
  52. package/lib/services/order-reference.service.js +136 -0
  53. package/lib/services/quality-inspection-order.service.js +4 -0
  54. package/lib/services/receive-inventory-order.service.js +132 -78
  55. package/lib/services/reclassify-inventory-order.service.js +4 -0
  56. package/lib/services/scrape.service.js +4 -0
  57. package/lib/services/ship-inventory-order.service.js +4 -0
  58. package/lib/services/split-batch-order.service.js +69 -46
  59. package/lib/services/stock.service.js +32 -2
  60. package/lib/services/transfer-customer-order.service.js +4 -0
  61. package/lib/services/transfer-order.service.js +4 -0
  62. package/lib/services/transfer-vendor-order.service.js +4 -0
  63. package/lib/services/unit.service.js +4 -0
  64. package/lib/typings/aggregated-stock.d.ts +6 -0
  65. package/lib/typings/consumption-order.input.d.ts +72 -0
  66. package/lib/typings/core-module-options.d.ts +34 -1
  67. package/lib/typings/custom-change-table.d.ts +70 -0
  68. package/lib/typings/find-stock.input.d.ts +14 -0
  69. package/lib/typings/get-batch.input.d.ts +16 -0
  70. package/lib/typings/index.d.ts +3 -0
  71. package/lib/typings/order-reference.input.d.ts +28 -0
  72. package/lib/typings/split-batch.input.d.ts +11 -0
  73. package/package.json +1 -1
@@ -15,8 +15,18 @@ import type { ChangeType } from '../constants/stock-status';
15
15
  * names and payloads. Wiring is opt-in via `forRootAsync({ beforeHooks,
16
16
  * afterListeners })`; when nothing is configured the whole chain is inert.
17
17
  */
18
- export type WmsOperationEventName = 'receive-inventory-order.created' | 'receive-inventory-order.updated' | 'receive-inventory-order.received' | 'ship-inventory-order.created' | 'ship-inventory-order.updated' | 'ship-inventory-order.shipped' | 'ship-inventory-order.ship-cancelled' | 'transfer-order.created' | 'transfer-order.updated' | 'transfer-order.transferred' | 'transfer-order.transfer-cancelled' | 'hold-inventory-order.created' | 'hold-inventory-order.updated' | 'hold-inventory-order.released' | 'allocate-inventory-order.created' | 'allocate-inventory-order.updated' | 'allocate-inventory-order.deallocated' | 'transfer-vendor-order.created' | 'transfer-vendor-order.updated' | 'transfer-vendor-order.returned' | 'transfer-customer-order.created' | 'transfer-customer-order.updated' | 'transfer-customer-order.returned' | 'quality-inspection-order.inspected' | 'scrape-order.scraped' | 'reclassify-inventory-order.reclassified' | 'batch.merged' | 'batch.splitted' | 'material.created' | 'material.updated' | 'loader.created' | 'loader.batch-created' | 'loader.updated' | 'loader.type-created' | 'loader.type-updated' | 'location.created' | 'location.updated' | 'warehouse-map.updated' | 'inventory-count-order.created' | 'inventory-count-order.updated' | 'inventory-count-order.started' | 'inventory-count-order.counted' | 'inventory-count-order.reset' | 'inventory-count-order.cancelled' | 'inventory-count-order.settled';
19
- export type WmsStockEventName = 'stock.received' | 'stock.in-shipment' | 'stock.shipped' | 'stock.in-transfer' | 'stock.transferred' | 'stock.vendor-transferred' | 'stock.vendor-returned' | 'stock.held' | 'stock.released' | 'stock.customer-held' | 'stock.customer-returned' | 'stock.splitted' | 'stock.merged' | 'stock.allocated' | 'stock.deallocated' | 'stock.reclassified' | 'stock.scraped' | 'stock.inspection-resolved' | 'stock.count-gained' | 'stock.count-lost';
18
+ export type WmsOperationEventName = 'receive-inventory-order.created' | 'receive-inventory-order.updated' | 'receive-inventory-order.received' | 'ship-inventory-order.created' | 'ship-inventory-order.updated' | 'ship-inventory-order.shipped' | 'ship-inventory-order.ship-cancelled' | 'transfer-order.created' | 'transfer-order.updated' | 'transfer-order.transferred' | 'transfer-order.transfer-cancelled' | 'hold-inventory-order.created' | 'hold-inventory-order.updated' | 'hold-inventory-order.released' | 'allocate-inventory-order.created' | 'allocate-inventory-order.updated' | 'allocate-inventory-order.deallocated' | 'transfer-vendor-order.created' | 'transfer-vendor-order.updated' | 'transfer-vendor-order.returned' | 'transfer-customer-order.created' | 'transfer-customer-order.updated' | 'transfer-customer-order.returned' | 'quality-inspection-order.inspected' | 'scrape-order.scraped' | 'reclassify-inventory-order.reclassified' | 'batch.merged' | 'batch.splitted' | 'material.created' | 'material.updated' | 'loader.created' | 'loader.batch-created' | 'loader.updated' | 'loader.type-created' | 'loader.type-updated' | 'location.created' | 'location.updated' | 'warehouse-map.updated' | 'inventory-count-order.created' | 'inventory-count-order.updated' | 'inventory-count-order.started' | 'inventory-count-order.counted' | 'inventory-count-order.reset' | 'inventory-count-order.cancelled' | 'inventory-count-order.settled' | 'consumption-order.created' | 'consumption-order.updated' | 'consumption-order.issued' | 'consumption-order.returned' | 'consumption-order.settled' | 'order-reference.attached' | 'order-reference.detached';
19
+ export type WmsStockEventName = 'stock.received' | 'stock.in-shipment' | 'stock.shipped' | 'stock.in-transfer' | 'stock.transferred' | 'stock.vendor-transferred' | 'stock.vendor-returned' | 'stock.held' | 'stock.released' | 'stock.customer-held' | 'stock.customer-returned' | 'stock.splitted' | 'stock.merged' | 'stock.allocated' | 'stock.deallocated' | 'stock.reclassified' | 'stock.scraped' | 'stock.inspection-resolved' | 'stock.count-gained' | 'stock.count-lost' | 'stock.issued' | 'stock.returned' | 'stock.consumed'
20
+ /**
21
+ * A movement on a change table the host registered through
22
+ * `customChangeTables`, whose kind this package has no name for. The host's
23
+ * own string arrives as `payload.customChangeType`.
24
+ *
25
+ * One event name rather than an open union on purpose: `WmsStockEventName`
26
+ * stays closed, so the typed listener map, the GraphQL `ChangeType` enum and
27
+ * every exhaustive switch a consumer wrote keep working.
28
+ */
29
+ | 'stock.custom';
20
30
  export type WmsEventName = WmsOperationEventName | WmsStockEventName;
21
31
  /**
22
32
  * The authenticated identity that performed a mutation, in a host-neutral shape.
@@ -61,8 +71,18 @@ export interface WmsStockEventPayload {
61
71
  readonly itemId: string;
62
72
  /** `change.quantityChanged` — sign carries direction (in: +, out: -). */
63
73
  readonly quantityDelta: number;
64
- /** The resolved `ChangeType` for this stock movement (null for inspection). */
74
+ /**
75
+ * The resolved `ChangeType` for this stock movement. `null` for a quality
76
+ * inspection, which has none, and for a `stock.custom` movement, which
77
+ * carries the host's own name in {@link WmsStockEventPayload.customChangeType}
78
+ * instead.
79
+ */
65
80
  readonly changeType: ChangeType | null;
81
+ /**
82
+ * The host's own change type, present only on `stock.custom`. Opaque: this
83
+ * package never interprets it.
84
+ */
85
+ readonly customChangeType?: string;
66
86
  /** Quality-inspection result, present only on `stock.inspection-resolved`. */
67
87
  readonly inspectionResult?: boolean | null;
68
88
  readonly materialId?: string | null;
@@ -83,13 +103,25 @@ export interface WmsDomainEvent<N extends WmsEventName = WmsEventName> {
83
103
  }
84
104
  /**
85
105
  * Context handed to a before-hook. Runs *before* any DB work, so it sees the
86
- * mutation **intent** (raw GraphQL arguments) rather than a result. Throwing
87
- * vetoes the whole mutation with zero side effects.
106
+ * operation **intent** (the raw arguments) rather than a result. Throwing
107
+ * vetoes the whole operation with zero side effects.
88
108
  */
89
109
  export interface WmsBeforeHookContext<N extends WmsEventName = WmsEventName> {
90
110
  readonly event: N;
91
111
  readonly args: Readonly<Record<string, unknown>>;
92
- readonly executionContext: ExecutionContext;
112
+ /**
113
+ * The NestJS execution context, or `null` when the operation did not arrive
114
+ * through one.
115
+ *
116
+ * A host calling a domain service directly through `WmsOperationRunner` has
117
+ * no execution context to offer, and fabricating one would be worse than
118
+ * admitting it: a hook that reaches into the request would get a lie instead
119
+ * of an obvious `null`. Branch on {@link WmsBeforeHookContext.source} rather
120
+ * than on this field being present.
121
+ */
122
+ readonly executionContext: ExecutionContext | null;
123
+ /** Where the operation came in from. `'host'` means a direct service call. */
124
+ readonly source: 'graphql' | 'host';
93
125
  readonly actor: WmsActor | null;
94
126
  }
95
127
  /** Context handed to an after-listener. Runs post-commit with the event payload. */
@@ -0,0 +1,57 @@
1
+ import { type ExecutionContext } from '@nestjs/common';
2
+ import { WmsEventDispatcher } from './wms-event.dispatcher';
3
+ import type { WmsActor, WmsOperationEventName } from './wms-event.types';
4
+ export interface WmsOperationRunOptions {
5
+ /**
6
+ * The operation event to emit once the operation resolves. Omit to open a
7
+ * dispatch scope without an operation event — the shape a host wants when it
8
+ * calls a domain service directly and only cares that the `stock.*` events
9
+ * that service collects are flushed.
10
+ */
11
+ readonly event?: WmsOperationEventName;
12
+ /** The operation's intent, handed to the before-hook and the event payload. */
13
+ readonly args?: Readonly<Record<string, unknown>>;
14
+ /** Who performed it. `null` when the host does not track an actor. */
15
+ readonly actor?: WmsActor | null;
16
+ /** Override how the event's correlation id is derived from the result. */
17
+ readonly resolveId?: (result: unknown, args: Readonly<Record<string, unknown>>) => string | null;
18
+ /**
19
+ * The NestJS execution context, when there is one. `null` for a host calling
20
+ * a service directly — which is why {@link WmsBeforeHookContext} declares it
21
+ * nullable.
22
+ */
23
+ readonly executionContext?: ExecutionContext | null;
24
+ }
25
+ /**
26
+ * Runs one WMS operation with the full event guarantee, from any caller.
27
+ *
28
+ * The four steps — before-hook (a throw vetoes, before any DB work), the
29
+ * operation itself, the operation event, and a single post-commit flush of
30
+ * everything the services collected on the way — used to live inside
31
+ * `WmsMutationInterceptor`, which meant they only happened for callers coming
32
+ * in through GraphQL. A host driving the warehouse from its own code path got
33
+ * no hooks, no actor and no events: `StockChangeSubscriber` still collected
34
+ * them, but with no scope open there was nothing to collect into and nobody to
35
+ * flush.
36
+ *
37
+ * That is the case that matters. A host with its own inbound flow calls the
38
+ * domain services directly, and `InventoryCountLockSubscriber` already goes out
39
+ * of its way to cover exactly that caller.
40
+ *
41
+ * The interceptor now delegates here, so the two paths cannot drift.
42
+ *
43
+ * ```ts
44
+ * await runner.run(
45
+ * { event: 'transfer-order.transferred', args: { orderId }, actor },
46
+ * () => transferOrderService.transfer(orderId),
47
+ * );
48
+ * ```
49
+ *
50
+ * Nesting is safe: an inner call joins the outer scope and only the outermost
51
+ * one flushes, so a host may wrap a service that itself runs operations.
52
+ */
53
+ export declare class WmsOperationRunner {
54
+ private readonly dispatcher;
55
+ constructor(dispatcher: WmsEventDispatcher);
56
+ run<T>(options: WmsOperationRunOptions, operation: () => Promise<T>): Promise<T>;
57
+ }
@@ -0,0 +1,101 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Injectable } from '@nestjs/common';
3
+ import { runInDispatchScope, collectToScope } from './dispatch-scope.js';
4
+ import { WmsEventDispatcher } from './wms-event.dispatcher.js';
5
+
6
+ /**
7
+ * Derive the operation event's correlation id from whatever the operation
8
+ * returned, falling back to an `id` argument. Action operations that return a
9
+ * bare `boolean` land on the argument.
10
+ */
11
+ const defaultResolveId = (result, args) => {
12
+ if (result &&
13
+ typeof result === 'object' &&
14
+ 'id' in result &&
15
+ typeof result.id === 'string') {
16
+ return result.id;
17
+ }
18
+ const argId = args['id'];
19
+ return typeof argId === 'string' ? argId : null;
20
+ };
21
+ /**
22
+ * Runs one WMS operation with the full event guarantee, from any caller.
23
+ *
24
+ * The four steps — before-hook (a throw vetoes, before any DB work), the
25
+ * operation itself, the operation event, and a single post-commit flush of
26
+ * everything the services collected on the way — used to live inside
27
+ * `WmsMutationInterceptor`, which meant they only happened for callers coming
28
+ * in through GraphQL. A host driving the warehouse from its own code path got
29
+ * no hooks, no actor and no events: `StockChangeSubscriber` still collected
30
+ * them, but with no scope open there was nothing to collect into and nobody to
31
+ * flush.
32
+ *
33
+ * That is the case that matters. A host with its own inbound flow calls the
34
+ * domain services directly, and `InventoryCountLockSubscriber` already goes out
35
+ * of its way to cover exactly that caller.
36
+ *
37
+ * The interceptor now delegates here, so the two paths cannot drift.
38
+ *
39
+ * ```ts
40
+ * await runner.run(
41
+ * { event: 'transfer-order.transferred', args: { orderId }, actor },
42
+ * () => transferOrderService.transfer(orderId),
43
+ * );
44
+ * ```
45
+ *
46
+ * Nesting is safe: an inner call joins the outer scope and only the outermost
47
+ * one flushes, so a host may wrap a service that itself runs operations.
48
+ */
49
+ let WmsOperationRunner = class WmsOperationRunner {
50
+ dispatcher;
51
+ constructor(dispatcher) {
52
+ this.dispatcher = dispatcher;
53
+ }
54
+ async run(options, operation) {
55
+ // Nothing wired: run the operation and skip the machinery entirely, the way
56
+ // the interceptor always has. `collectToScope` is already a no-op outside a
57
+ // scope, so the services behave identically.
58
+ if (!this.dispatcher.isActive()) {
59
+ return operation();
60
+ }
61
+ const args = options.args ?? {};
62
+ const actor = options.actor ?? null;
63
+ if (options.event) {
64
+ // Before any DB work, so a throw vetoes with zero side effects.
65
+ await this.dispatcher.runBeforeHook({
66
+ event: options.event,
67
+ args,
68
+ executionContext: options.executionContext ?? null,
69
+ source: options.executionContext ? 'graphql' : 'host',
70
+ actor,
71
+ });
72
+ }
73
+ const { result, events } = await runInDispatchScope(async () => {
74
+ const operationResult = await operation();
75
+ if (options.event) {
76
+ const resolveId = options.resolveId ?? defaultResolveId;
77
+ const operationEvent = {
78
+ name: options.event,
79
+ payload: {
80
+ id: resolveId(operationResult, args),
81
+ result: operationResult,
82
+ args,
83
+ actor,
84
+ },
85
+ };
86
+ collectToScope(operationEvent);
87
+ }
88
+ return operationResult;
89
+ });
90
+ if (events) {
91
+ await this.dispatcher.flush(events);
92
+ }
93
+ return result;
94
+ }
95
+ };
96
+ WmsOperationRunner = __decorate([
97
+ Injectable(),
98
+ __metadata("design:paramtypes", [WmsEventDispatcher])
99
+ ], WmsOperationRunner);
100
+
101
+ export { WmsOperationRunner };
@@ -0,0 +1,19 @@
1
+ import { OrderEntity } from '@rytass/wms-base-nestjs-module';
2
+ import { ConsumptionChangeKind } from '../../../constants/consumption-change-kind';
3
+ import { ConsumptionOrderItemEntityClass } from './consumption-order-item.entity';
4
+ export declare const ConsumptionOrderChangeEntity: unique symbol;
5
+ export declare class ConsumptionOrderChangeEntityClass {
6
+ id: string;
7
+ itemId: string;
8
+ /** Positive for an issue, negative for a return or a settlement. */
9
+ quantityChanged: number;
10
+ /**
11
+ * Which of the three actions wrote this row. A return and a settlement are
12
+ * both negative, so the sign cannot carry it -- see
13
+ * {@link ConsumptionChangeKind}.
14
+ */
15
+ kind: ConsumptionChangeKind;
16
+ createdAt: Date;
17
+ order: OrderEntity;
18
+ item: ConsumptionOrderItemEntityClass;
19
+ }
@@ -0,0 +1,59 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { OrderEntity } from '@rytass/wms-base-nestjs-module';
3
+ import { PrimaryGeneratedColumn, Column, Index, CreateDateColumn, OneToOne, JoinColumn, ManyToOne, Entity } from 'typeorm';
4
+ import '../../../constants/consumption-change-kind.js';
5
+ import { ConsumptionOrderItemEntityClass } from './consumption-order-item.entity.js';
6
+
7
+ const ConsumptionOrderChangeEntity = Symbol('ConsumptionOrderChangeEntity');
8
+ let ConsumptionOrderChangeEntityClass = class ConsumptionOrderChangeEntityClass {
9
+ id;
10
+ itemId;
11
+ /** Positive for an issue, negative for a return or a settlement. */
12
+ quantityChanged;
13
+ /**
14
+ * Which of the three actions wrote this row. A return and a settlement are
15
+ * both negative, so the sign cannot carry it -- see
16
+ * {@link ConsumptionChangeKind}.
17
+ */
18
+ kind;
19
+ createdAt;
20
+ order;
21
+ item;
22
+ };
23
+ __decorate([
24
+ PrimaryGeneratedColumn('uuid'),
25
+ __metadata("design:type", String)
26
+ ], ConsumptionOrderChangeEntityClass.prototype, "id", void 0);
27
+ __decorate([
28
+ Column({ type: 'uuid' }),
29
+ Index(),
30
+ __metadata("design:type", String)
31
+ ], ConsumptionOrderChangeEntityClass.prototype, "itemId", void 0);
32
+ __decorate([
33
+ Column({ type: 'numeric' }),
34
+ __metadata("design:type", Number)
35
+ ], ConsumptionOrderChangeEntityClass.prototype, "quantityChanged", void 0);
36
+ __decorate([
37
+ Column({ type: 'varchar' }),
38
+ Index(),
39
+ __metadata("design:type", String)
40
+ ], ConsumptionOrderChangeEntityClass.prototype, "kind", void 0);
41
+ __decorate([
42
+ CreateDateColumn({ type: 'timestamptz' }),
43
+ __metadata("design:type", Date)
44
+ ], ConsumptionOrderChangeEntityClass.prototype, "createdAt", void 0);
45
+ __decorate([
46
+ OneToOne('orders'),
47
+ JoinColumn({ name: 'id', referencedColumnName: 'id' }),
48
+ __metadata("design:type", OrderEntity)
49
+ ], ConsumptionOrderChangeEntityClass.prototype, "order", void 0);
50
+ __decorate([
51
+ ManyToOne('consumption_order_items', (item) => item.changes),
52
+ JoinColumn({ name: 'itemId', referencedColumnName: 'id' }),
53
+ __metadata("design:type", ConsumptionOrderItemEntityClass)
54
+ ], ConsumptionOrderChangeEntityClass.prototype, "item", void 0);
55
+ ConsumptionOrderChangeEntityClass = __decorate([
56
+ Entity('consumption_order_changes')
57
+ ], ConsumptionOrderChangeEntityClass);
58
+
59
+ export { ConsumptionOrderChangeEntity, ConsumptionOrderChangeEntityClass };
@@ -0,0 +1,26 @@
1
+ import { LoadersEntityClass, LocationEntityClass } from '../../metadata';
2
+ import { ConsumptionOrderEntityClass } from './consumption-order.entity';
3
+ import { ConsumptionOrderChangeEntityClass } from './consumption-order-change.entity';
4
+ export declare const ConsumptionOrderItemEntity: unique symbol;
5
+ export declare class ConsumptionOrderItemEntityClass {
6
+ id: string;
7
+ materialId: string;
8
+ batchId: string;
9
+ /** Where the material is issued from. */
10
+ locationId: string;
11
+ loaderId: string | null;
12
+ unitId: string | null;
13
+ targetConsumedQuantity: number;
14
+ /**
15
+ * Where the material sits while the process holds it. An ordinary location;
16
+ * the host decides which of its own means "in the hands of a process".
17
+ */
18
+ targetLocationId: string | null;
19
+ targetLoaderId: string | null;
20
+ orderId: string;
21
+ removedAt: Date | null;
22
+ location: LocationEntityClass;
23
+ loader: LoadersEntityClass;
24
+ order: ConsumptionOrderEntityClass;
25
+ changes: ConsumptionOrderChangeEntityClass[];
26
+ }
@@ -0,0 +1,114 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { PrimaryGeneratedColumn, Column, Index, ManyToOne, JoinColumn, OneToMany, Entity, TableInheritance } from 'typeorm';
3
+ import '../../metadata/batch.entity.js';
4
+ import '../../metadata/batch-group.entity.js';
5
+ import { LoadersEntityClass } from '../../metadata/loader.entity.js';
6
+ import '../../metadata/loader-type.entity.js';
7
+ import '../../metadata/loader-unit.entity.js';
8
+ import { LocationEntityClass } from '../../metadata/location.entity.js';
9
+ import '../../metadata/material.entity.js';
10
+ import '../../metadata/material-unit.entity.js';
11
+ import '@rytass/wms-base-nestjs-module';
12
+ import '../../metadata/sale-order.entity.js';
13
+ import '../../metadata/stock.entity.js';
14
+ import '../../metadata/unit.entity.js';
15
+ import { ConsumptionOrderEntityClass } from './consumption-order.entity.js';
16
+
17
+ const ConsumptionOrderItemEntity = Symbol('ConsumptionOrderItemEntity');
18
+ let ConsumptionOrderItemEntityClass = class ConsumptionOrderItemEntityClass {
19
+ id;
20
+ materialId;
21
+ batchId;
22
+ /** Where the material is issued from. */
23
+ locationId;
24
+ loaderId;
25
+ unitId;
26
+ targetConsumedQuantity;
27
+ /**
28
+ * Where the material sits while the process holds it. An ordinary location;
29
+ * the host decides which of its own means "in the hands of a process".
30
+ */
31
+ targetLocationId;
32
+ targetLoaderId;
33
+ orderId;
34
+ removedAt;
35
+ location;
36
+ loader;
37
+ order;
38
+ changes;
39
+ };
40
+ __decorate([
41
+ PrimaryGeneratedColumn('uuid'),
42
+ __metadata("design:type", String)
43
+ ], ConsumptionOrderItemEntityClass.prototype, "id", void 0);
44
+ __decorate([
45
+ Column({ type: 'uuid' }),
46
+ Index(),
47
+ __metadata("design:type", String)
48
+ ], ConsumptionOrderItemEntityClass.prototype, "materialId", void 0);
49
+ __decorate([
50
+ Column({ type: 'uuid' }),
51
+ Index(),
52
+ __metadata("design:type", String)
53
+ ], ConsumptionOrderItemEntityClass.prototype, "batchId", void 0);
54
+ __decorate([
55
+ Column({ type: 'uuid' }),
56
+ Index(),
57
+ __metadata("design:type", String)
58
+ ], ConsumptionOrderItemEntityClass.prototype, "locationId", void 0);
59
+ __decorate([
60
+ Column({ type: 'uuid', nullable: true }),
61
+ __metadata("design:type", Object)
62
+ ], ConsumptionOrderItemEntityClass.prototype, "loaderId", void 0);
63
+ __decorate([
64
+ Column({ type: 'uuid', nullable: true }),
65
+ __metadata("design:type", Object)
66
+ ], ConsumptionOrderItemEntityClass.prototype, "unitId", void 0);
67
+ __decorate([
68
+ Column({ type: 'numeric' }),
69
+ __metadata("design:type", Number)
70
+ ], ConsumptionOrderItemEntityClass.prototype, "targetConsumedQuantity", void 0);
71
+ __decorate([
72
+ Column({ type: 'uuid', nullable: true }),
73
+ Index(),
74
+ __metadata("design:type", Object)
75
+ ], ConsumptionOrderItemEntityClass.prototype, "targetLocationId", void 0);
76
+ __decorate([
77
+ Column({ type: 'uuid', nullable: true }),
78
+ Index(),
79
+ __metadata("design:type", Object)
80
+ ], ConsumptionOrderItemEntityClass.prototype, "targetLoaderId", void 0);
81
+ __decorate([
82
+ Column({ type: 'uuid' }),
83
+ Index(),
84
+ __metadata("design:type", String)
85
+ ], ConsumptionOrderItemEntityClass.prototype, "orderId", void 0);
86
+ __decorate([
87
+ Column({ type: 'timestamptz', nullable: true }),
88
+ __metadata("design:type", Object)
89
+ ], ConsumptionOrderItemEntityClass.prototype, "removedAt", void 0);
90
+ __decorate([
91
+ ManyToOne('locations'),
92
+ JoinColumn({ name: 'locationId', referencedColumnName: 'id' }),
93
+ __metadata("design:type", LocationEntityClass)
94
+ ], ConsumptionOrderItemEntityClass.prototype, "location", void 0);
95
+ __decorate([
96
+ ManyToOne('loaders'),
97
+ JoinColumn({ name: 'loaderId', referencedColumnName: 'id' }),
98
+ __metadata("design:type", LoadersEntityClass)
99
+ ], ConsumptionOrderItemEntityClass.prototype, "loader", void 0);
100
+ __decorate([
101
+ ManyToOne('consumption_orders', (entity) => entity.items),
102
+ JoinColumn({ name: 'orderId', referencedColumnName: 'id' }),
103
+ __metadata("design:type", ConsumptionOrderEntityClass)
104
+ ], ConsumptionOrderItemEntityClass.prototype, "order", void 0);
105
+ __decorate([
106
+ OneToMany('consumption_order_changes', (change) => change.item),
107
+ __metadata("design:type", Array)
108
+ ], ConsumptionOrderItemEntityClass.prototype, "changes", void 0);
109
+ ConsumptionOrderItemEntityClass = __decorate([
110
+ Entity('consumption_order_items'),
111
+ TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
112
+ ], ConsumptionOrderItemEntityClass);
113
+
114
+ export { ConsumptionOrderItemEntity, ConsumptionOrderItemEntityClass };
@@ -0,0 +1,32 @@
1
+ import { ConsumptionOrderItemEntityClass } from './consumption-order-item.entity';
2
+ export declare const ConsumptionOrderEntity: unique symbol;
3
+ /**
4
+ * Material handed to a process that consumes it.
5
+ *
6
+ * One order covers the whole life of that handover: issue material out to a
7
+ * consuming location, take back what was not used, and settle what was. Three
8
+ * actions on one document rather than three documents, which is the grammar
9
+ * every other stateful order here already uses -- hold/release, allocate/
10
+ * deallocate and transfer/cancel are each a single order too.
11
+ *
12
+ * Nothing about it is specific to manufacturing. "Give stock to a process that
13
+ * eats some of it, possibly returns the rest, and may produce something else"
14
+ * is equally a subcontract, a repair job, a teardown, or a kitchen prep list.
15
+ * What the process *is* belongs in `order_references`.
16
+ *
17
+ * The consuming location is an ordinary location, and material sitting there is
18
+ * ordinary `FREE` stock. There is no work-in-progress status: status in this
19
+ * model is a flag on the batch, so a status would force every partial issue to
20
+ * split a child batch off, and a batch key per issue is a worse answer than a
21
+ * location. `excludeLocationIds` is how a stock report leaves that location
22
+ * out.
23
+ */
24
+ export declare class ConsumptionOrderEntityClass {
25
+ id: string;
26
+ key: string;
27
+ description: string | null;
28
+ createdBy: string | null;
29
+ removedAt: Date | null;
30
+ createdAt: Date;
31
+ items: ConsumptionOrderItemEntityClass[];
32
+ }
@@ -0,0 +1,69 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { PrimaryGeneratedColumn, Column, Index, CreateDateColumn, OneToMany, Entity, TableInheritance } from 'typeorm';
3
+
4
+ const ConsumptionOrderEntity = Symbol('ConsumptionOrderEntity');
5
+ /**
6
+ * Material handed to a process that consumes it.
7
+ *
8
+ * One order covers the whole life of that handover: issue material out to a
9
+ * consuming location, take back what was not used, and settle what was. Three
10
+ * actions on one document rather than three documents, which is the grammar
11
+ * every other stateful order here already uses -- hold/release, allocate/
12
+ * deallocate and transfer/cancel are each a single order too.
13
+ *
14
+ * Nothing about it is specific to manufacturing. "Give stock to a process that
15
+ * eats some of it, possibly returns the rest, and may produce something else"
16
+ * is equally a subcontract, a repair job, a teardown, or a kitchen prep list.
17
+ * What the process *is* belongs in `order_references`.
18
+ *
19
+ * The consuming location is an ordinary location, and material sitting there is
20
+ * ordinary `FREE` stock. There is no work-in-progress status: status in this
21
+ * model is a flag on the batch, so a status would force every partial issue to
22
+ * split a child batch off, and a batch key per issue is a worse answer than a
23
+ * location. `excludeLocationIds` is how a stock report leaves that location
24
+ * out.
25
+ */
26
+ let ConsumptionOrderEntityClass = class ConsumptionOrderEntityClass {
27
+ id;
28
+ key;
29
+ description;
30
+ createdBy;
31
+ removedAt;
32
+ createdAt;
33
+ items;
34
+ };
35
+ __decorate([
36
+ PrimaryGeneratedColumn('uuid'),
37
+ __metadata("design:type", String)
38
+ ], ConsumptionOrderEntityClass.prototype, "id", void 0);
39
+ __decorate([
40
+ Column({ type: 'varchar', unique: true }),
41
+ Index(),
42
+ __metadata("design:type", String)
43
+ ], ConsumptionOrderEntityClass.prototype, "key", void 0);
44
+ __decorate([
45
+ Column({ type: 'text', nullable: true }),
46
+ __metadata("design:type", Object)
47
+ ], ConsumptionOrderEntityClass.prototype, "description", void 0);
48
+ __decorate([
49
+ Column({ type: 'varchar', nullable: true }),
50
+ __metadata("design:type", Object)
51
+ ], ConsumptionOrderEntityClass.prototype, "createdBy", void 0);
52
+ __decorate([
53
+ Column({ type: 'timestamptz', nullable: true }),
54
+ __metadata("design:type", Object)
55
+ ], ConsumptionOrderEntityClass.prototype, "removedAt", void 0);
56
+ __decorate([
57
+ CreateDateColumn({ type: 'timestamptz' }),
58
+ __metadata("design:type", Date)
59
+ ], ConsumptionOrderEntityClass.prototype, "createdAt", void 0);
60
+ __decorate([
61
+ OneToMany('consumption_order_items', (entity) => entity.order),
62
+ __metadata("design:type", Array)
63
+ ], ConsumptionOrderEntityClass.prototype, "items", void 0);
64
+ ConsumptionOrderEntityClass = __decorate([
65
+ Entity('consumption_orders'),
66
+ TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
67
+ ], ConsumptionOrderEntityClass);
68
+
69
+ export { ConsumptionOrderEntity, ConsumptionOrderEntityClass };
@@ -0,0 +1,3 @@
1
+ export * from './consumption-order.entity';
2
+ export * from './consumption-order-item.entity';
3
+ export * from './consumption-order-change.entity';
@@ -38,3 +38,7 @@ export * from './scrape-order/scrape-order-change.entity';
38
38
  export * from './inventory-count-order/inventory-count-order.entity';
39
39
  export * from './inventory-count-order/inventory-count-order-item.entity';
40
40
  export * from './inventory-count-order/inventory-count-order-change.entity';
41
+ export * from './consumption-order/consumption-order.entity';
42
+ export * from './consumption-order/consumption-order-item.entity';
43
+ export * from './consumption-order/consumption-order-change.entity';
44
+ export * from './order-reference/order-reference.entity';
@@ -34,8 +34,20 @@ export declare class InventoryCountOrderItemEntityClass {
34
34
  isAddition: boolean;
35
35
  held: boolean | null;
36
36
  inShipment: boolean | null;
37
- /** `null` = 待檢驗, `false` = 檢驗失敗, `true` = passed. */
37
+ /**
38
+ * `false` = 檢驗失敗, `true` = passed, `null` = not inspected.
39
+ *
40
+ * `null` on its own does **not** mean 待檢驗: it is the resting state of
41
+ * almost every batch in the warehouse. Pair it with
42
+ * {@link InventoryCountOrderItemEntityClass.requiresInspection}.
43
+ */
38
44
  inspectionResult: boolean | null;
45
+ /**
46
+ * Whether anybody had asked for this position to be inspected when the count
47
+ * started. Snapshotted for the same reason as the flags around it, and needed
48
+ * because `inspectionResult IS NULL` alone would mark the whole sheet 待檢驗.
49
+ */
50
+ requiresInspection: boolean | null;
39
51
  transferId: string | null;
40
52
  vendorId: string | null;
41
53
  customerId: string | null;
@@ -58,8 +58,20 @@ let InventoryCountOrderItemEntityClass = class InventoryCountOrderItemEntityClas
58
58
  // `null` before counting has started.
59
59
  held;
60
60
  inShipment;
61
- /** `null` = 待檢驗, `false` = 檢驗失敗, `true` = passed. */
61
+ /**
62
+ * `false` = 檢驗失敗, `true` = passed, `null` = not inspected.
63
+ *
64
+ * `null` on its own does **not** mean 待檢驗: it is the resting state of
65
+ * almost every batch in the warehouse. Pair it with
66
+ * {@link InventoryCountOrderItemEntityClass.requiresInspection}.
67
+ */
62
68
  inspectionResult;
69
+ /**
70
+ * Whether anybody had asked for this position to be inspected when the count
71
+ * started. Snapshotted for the same reason as the flags around it, and needed
72
+ * because `inspectionResult IS NULL` alone would mark the whole sheet 待檢驗.
73
+ */
74
+ requiresInspection;
63
75
  transferId;
64
76
  vendorId;
65
77
  customerId;
@@ -128,6 +140,10 @@ __decorate([
128
140
  Column({ type: 'boolean', nullable: true }),
129
141
  __metadata("design:type", Object)
130
142
  ], InventoryCountOrderItemEntityClass.prototype, "inspectionResult", void 0);
143
+ __decorate([
144
+ Column({ type: 'boolean', nullable: true }),
145
+ __metadata("design:type", Object)
146
+ ], InventoryCountOrderItemEntityClass.prototype, "requiresInspection", void 0);
131
147
  __decorate([
132
148
  Column({ type: 'uuid', nullable: true }),
133
149
  __metadata("design:type", Object)
@@ -0,0 +1 @@
1
+ export * from './order-reference.entity';