@rytass/wms-module-core 0.5.0 → 0.6.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 (49) hide show
  1. package/README.md +43 -1
  2. package/docs/api-reference.md +32 -1
  3. package/index.cjs.js +963 -5
  4. package/index.js +7 -0
  5. package/lib/constants/index.d.ts +2 -0
  6. package/lib/constants/inventory-count-status.d.ts +19 -0
  7. package/lib/constants/inventory-count-status.js +22 -0
  8. package/lib/constants/operations.d.ts +34 -0
  9. package/lib/constants/operations.js +66 -0
  10. package/lib/constants/stock-status.d.ts +2 -0
  11. package/lib/constants/stock-status.js +4 -0
  12. package/lib/core.module.js +9 -1
  13. package/lib/events/index.d.ts +1 -0
  14. package/lib/events/inventory-count-lock.subscriber.d.ts +38 -0
  15. package/lib/events/inventory-count-lock.subscriber.js +98 -0
  16. package/lib/events/stock-change.subscriber.js +6 -0
  17. package/lib/events/wms-event.types.d.ts +2 -2
  18. package/lib/models/extensions/index.d.ts +3 -0
  19. package/lib/models/extensions/inventory-count-order/inventory-count-order-change.entity.d.ts +20 -0
  20. package/lib/models/extensions/inventory-count-order/inventory-count-order-change.entity.js +50 -0
  21. package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.d.ts +39 -0
  22. package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.js +123 -0
  23. package/lib/models/extensions/inventory-count-order/inventory-count-order.entity.d.ts +50 -0
  24. package/lib/models/extensions/inventory-count-order/inventory-count-order.entity.js +155 -0
  25. package/lib/models/models.module.js +7 -0
  26. package/lib/services/allocate-inventory-order.service.js +3 -0
  27. package/lib/services/batch.service.js +3 -0
  28. package/lib/services/hold-inventory-order.service.js +3 -0
  29. package/lib/services/index.d.ts +1 -0
  30. package/lib/services/inventory-count-order.service.d.ts +143 -0
  31. package/lib/services/inventory-count-order.service.js +521 -0
  32. package/lib/services/loader.service.js +3 -0
  33. package/lib/services/location.service.js +3 -0
  34. package/lib/services/material.service.js +3 -0
  35. package/lib/services/merge-batch-order.service.js +3 -0
  36. package/lib/services/quality-inspection-order.service.js +3 -0
  37. package/lib/services/receive-inventory-order.service.js +3 -0
  38. package/lib/services/reclassify-inventory-order.service.js +3 -0
  39. package/lib/services/scrape.service.js +3 -0
  40. package/lib/services/ship-inventory-order.service.js +3 -0
  41. package/lib/services/split-batch-order.service.js +3 -0
  42. package/lib/services/stock.service.js +3 -0
  43. package/lib/services/transfer-customer-order.service.js +3 -0
  44. package/lib/services/transfer-order.service.js +3 -0
  45. package/lib/services/transfer-vendor-order.service.js +3 -0
  46. package/lib/services/unit.service.js +3 -0
  47. package/lib/services/warehouse-map.service.d.ts +11 -1
  48. package/lib/services/warehouse-map.service.js +13 -4
  49. package/package.json +1 -1
@@ -0,0 +1,123 @@
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 { InventoryCountOrderEntityClass } from './inventory-count-order.entity.js';
16
+
17
+ const InventoryCountOrderItemEntity = Symbol('InventoryCountOrderItemEntity');
18
+ /**
19
+ * One line of the count sheet.
20
+ *
21
+ * Two flavours share the table, told apart by {@link isAddition}:
22
+ *
23
+ * - a **scoped line**, expanded from the order's locations when the order is
24
+ * created. `bookQuantity` is the snapshot taken at "開始盤點".
25
+ * - an **addition** (盤盈), added by hand during counting for stock the books do
26
+ * not know about at all. `bookQuantity` is `0` by definition, and it is the
27
+ * only flavour a user may delete.
28
+ */
29
+ let InventoryCountOrderItemEntityClass = class InventoryCountOrderItemEntityClass {
30
+ id;
31
+ orderId;
32
+ materialId;
33
+ batchId;
34
+ locationId;
35
+ loaderId;
36
+ /**
37
+ * The unit the counted quantity is expressed in; `null` means the material's
38
+ * base unit. Settlement converts through the material's conversion factor
39
+ * before comparing with {@link bookQuantity}, which is always in base units.
40
+ */
41
+ unitId;
42
+ /** Ledger quantity in base units, frozen when counting started. */
43
+ bookQuantity;
44
+ /** What was actually found, in {@link unitId}. `null` until someone counts. */
45
+ countedQuantity;
46
+ /** `true` for a line added during counting for unbooked stock (盤盈). */
47
+ isAddition;
48
+ location;
49
+ loader;
50
+ order;
51
+ changes;
52
+ };
53
+ __decorate([
54
+ PrimaryGeneratedColumn('uuid'),
55
+ __metadata("design:type", String)
56
+ ], InventoryCountOrderItemEntityClass.prototype, "id", void 0);
57
+ __decorate([
58
+ Column({ type: 'uuid' }),
59
+ Index(),
60
+ __metadata("design:type", String)
61
+ ], InventoryCountOrderItemEntityClass.prototype, "orderId", void 0);
62
+ __decorate([
63
+ Column({ type: 'uuid' }),
64
+ Index(),
65
+ __metadata("design:type", String)
66
+ ], InventoryCountOrderItemEntityClass.prototype, "materialId", void 0);
67
+ __decorate([
68
+ Column({ type: 'uuid' }),
69
+ Index(),
70
+ __metadata("design:type", String)
71
+ ], InventoryCountOrderItemEntityClass.prototype, "batchId", void 0);
72
+ __decorate([
73
+ Column({ type: 'uuid', nullable: true }),
74
+ Index(),
75
+ __metadata("design:type", Object)
76
+ ], InventoryCountOrderItemEntityClass.prototype, "locationId", void 0);
77
+ __decorate([
78
+ Column({ type: 'uuid', nullable: true }),
79
+ Index(),
80
+ __metadata("design:type", Object)
81
+ ], InventoryCountOrderItemEntityClass.prototype, "loaderId", void 0);
82
+ __decorate([
83
+ Column({ type: 'uuid', nullable: true }),
84
+ Index(),
85
+ __metadata("design:type", Object)
86
+ ], InventoryCountOrderItemEntityClass.prototype, "unitId", void 0);
87
+ __decorate([
88
+ Column({ type: 'numeric', default: 0 }),
89
+ __metadata("design:type", Number)
90
+ ], InventoryCountOrderItemEntityClass.prototype, "bookQuantity", void 0);
91
+ __decorate([
92
+ Column({ type: 'numeric', nullable: true }),
93
+ __metadata("design:type", Object)
94
+ ], InventoryCountOrderItemEntityClass.prototype, "countedQuantity", void 0);
95
+ __decorate([
96
+ Column({ type: 'boolean', default: false }),
97
+ __metadata("design:type", Boolean)
98
+ ], InventoryCountOrderItemEntityClass.prototype, "isAddition", void 0);
99
+ __decorate([
100
+ ManyToOne('locations'),
101
+ JoinColumn({ name: 'locationId', referencedColumnName: 'id' }),
102
+ __metadata("design:type", LocationEntityClass)
103
+ ], InventoryCountOrderItemEntityClass.prototype, "location", void 0);
104
+ __decorate([
105
+ ManyToOne('loaders'),
106
+ JoinColumn({ name: 'loaderId', referencedColumnName: 'id' }),
107
+ __metadata("design:type", LoadersEntityClass)
108
+ ], InventoryCountOrderItemEntityClass.prototype, "loader", void 0);
109
+ __decorate([
110
+ ManyToOne('inventory_count_orders', (order) => order.items),
111
+ JoinColumn({ name: 'orderId', referencedColumnName: 'id' }),
112
+ __metadata("design:type", InventoryCountOrderEntityClass)
113
+ ], InventoryCountOrderItemEntityClass.prototype, "order", void 0);
114
+ __decorate([
115
+ OneToMany('inventory_count_order_changes', (change) => change.item),
116
+ __metadata("design:type", Array)
117
+ ], InventoryCountOrderItemEntityClass.prototype, "changes", void 0);
118
+ InventoryCountOrderItemEntityClass = __decorate([
119
+ Entity('inventory_count_order_items'),
120
+ TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
121
+ ], InventoryCountOrderItemEntityClass);
122
+
123
+ export { InventoryCountOrderItemEntity, InventoryCountOrderItemEntityClass };
@@ -0,0 +1,50 @@
1
+ import { LocationEntityClass } from '../../metadata';
2
+ import { InventoryCountStatus } from '../../../constants/inventory-count-status';
3
+ import { InventoryCountOrderItemEntityClass } from './inventory-count-order-item.entity';
4
+ export declare const InventoryCountOrderEntity: unique symbol;
5
+ export declare class InventoryCountOrderEntityClass {
6
+ id: string;
7
+ key: string;
8
+ name: string;
9
+ /**
10
+ * The count's base date, chosen when the order is created.
11
+ *
12
+ * It is the *business* date of the whole exercise: the settlement's stock
13
+ * adjustments are reported under this date, not under the day someone happened
14
+ * to press "執行盤差". `createdAt` keeps the real wall-clock time for auditing,
15
+ * so the two never have to lie for each other.
16
+ */
17
+ countDate: string;
18
+ status: InventoryCountStatus;
19
+ /** Who created the order, in whatever id space the host uses. */
20
+ createdBy: string | null;
21
+ /** When counting started — the moment `bookQuantity` was snapshotted. */
22
+ startedAt: Date | null;
23
+ /** When the variance was settled. */
24
+ settledAt: Date | null;
25
+ cancelledAt: Date | null;
26
+ createdAt: Date;
27
+ items: InventoryCountOrderItemEntityClass[];
28
+ locations: InventoryCountOrderLocationEntityClass[];
29
+ }
30
+ export declare const InventoryCountOrderLocationEntity: unique symbol;
31
+ /**
32
+ * One row per location in the order's scope, **already expanded** to include
33
+ * every descendant of the locations the user picked.
34
+ *
35
+ * The scope is materialised at creation instead of being recomputed from the
36
+ * chosen roots because it is read on the hot path: while an order is counting,
37
+ * every single stock movement in the system has to ask "is this location
38
+ * locked?". `LocationEntity` is a plain `parent`/`children` adjacency list with
39
+ * no materialised path, so answering that from the tree would mean a recursive
40
+ * CTE per movement.
41
+ */
42
+ export declare class InventoryCountOrderLocationEntityClass {
43
+ id: string;
44
+ orderId: string;
45
+ locationId: string;
46
+ /** `true` for the locations the user picked, `false` for descendants. */
47
+ isRoot: boolean;
48
+ order: InventoryCountOrderEntityClass;
49
+ location: LocationEntityClass;
50
+ }
@@ -0,0 +1,155 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { PrimaryGeneratedColumn, Column, Index, CreateDateColumn, OneToMany, Entity, TableInheritance, ManyToOne, JoinColumn } from 'typeorm';
3
+ import '../../metadata/batch.entity.js';
4
+ import '../../metadata/batch-group.entity.js';
5
+ import '../../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 { InventoryCountStatus } from '../../../constants/inventory-count-status.js';
16
+
17
+ const InventoryCountOrderEntity = Symbol('InventoryCountOrderEntity');
18
+ let InventoryCountOrderEntityClass = class InventoryCountOrderEntityClass {
19
+ id;
20
+ key;
21
+ name;
22
+ /**
23
+ * The count's base date, chosen when the order is created.
24
+ *
25
+ * It is the *business* date of the whole exercise: the settlement's stock
26
+ * adjustments are reported under this date, not under the day someone happened
27
+ * to press "執行盤差". `createdAt` keeps the real wall-clock time for auditing,
28
+ * so the two never have to lie for each other.
29
+ */
30
+ countDate;
31
+ status;
32
+ /** Who created the order, in whatever id space the host uses. */
33
+ createdBy;
34
+ /** When counting started — the moment `bookQuantity` was snapshotted. */
35
+ startedAt;
36
+ /** When the variance was settled. */
37
+ settledAt;
38
+ cancelledAt;
39
+ createdAt;
40
+ items;
41
+ locations;
42
+ };
43
+ __decorate([
44
+ PrimaryGeneratedColumn('uuid'),
45
+ __metadata("design:type", String)
46
+ ], InventoryCountOrderEntityClass.prototype, "id", void 0);
47
+ __decorate([
48
+ Column({ type: 'varchar', unique: true }),
49
+ Index(),
50
+ __metadata("design:type", String)
51
+ ], InventoryCountOrderEntityClass.prototype, "key", void 0);
52
+ __decorate([
53
+ Column({ type: 'varchar' }),
54
+ __metadata("design:type", String)
55
+ ], InventoryCountOrderEntityClass.prototype, "name", void 0);
56
+ __decorate([
57
+ Column({ type: 'date' }),
58
+ Index(),
59
+ __metadata("design:type", String)
60
+ ], InventoryCountOrderEntityClass.prototype, "countDate", void 0);
61
+ __decorate([
62
+ Column({
63
+ type: 'enum',
64
+ enum: InventoryCountStatus,
65
+ default: InventoryCountStatus.PENDING,
66
+ }),
67
+ Index(),
68
+ __metadata("design:type", String)
69
+ ], InventoryCountOrderEntityClass.prototype, "status", void 0);
70
+ __decorate([
71
+ Column({ type: 'varchar', nullable: true }),
72
+ __metadata("design:type", Object)
73
+ ], InventoryCountOrderEntityClass.prototype, "createdBy", void 0);
74
+ __decorate([
75
+ Column({ type: 'timestamptz', nullable: true }),
76
+ __metadata("design:type", Object)
77
+ ], InventoryCountOrderEntityClass.prototype, "startedAt", void 0);
78
+ __decorate([
79
+ Column({ type: 'timestamptz', nullable: true }),
80
+ __metadata("design:type", Object)
81
+ ], InventoryCountOrderEntityClass.prototype, "settledAt", void 0);
82
+ __decorate([
83
+ Column({ type: 'timestamptz', nullable: true }),
84
+ __metadata("design:type", Object)
85
+ ], InventoryCountOrderEntityClass.prototype, "cancelledAt", void 0);
86
+ __decorate([
87
+ CreateDateColumn({ type: 'timestamptz' }),
88
+ __metadata("design:type", Date)
89
+ ], InventoryCountOrderEntityClass.prototype, "createdAt", void 0);
90
+ __decorate([
91
+ OneToMany('inventory_count_order_items', (item) => item.order),
92
+ __metadata("design:type", Array)
93
+ ], InventoryCountOrderEntityClass.prototype, "items", void 0);
94
+ __decorate([
95
+ OneToMany('inventory_count_order_locations', (scope) => scope.order),
96
+ __metadata("design:type", Array)
97
+ ], InventoryCountOrderEntityClass.prototype, "locations", void 0);
98
+ InventoryCountOrderEntityClass = __decorate([
99
+ Entity('inventory_count_orders'),
100
+ TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
101
+ ], InventoryCountOrderEntityClass);
102
+ const InventoryCountOrderLocationEntity = Symbol('InventoryCountOrderLocationEntity');
103
+ /**
104
+ * One row per location in the order's scope, **already expanded** to include
105
+ * every descendant of the locations the user picked.
106
+ *
107
+ * The scope is materialised at creation instead of being recomputed from the
108
+ * chosen roots because it is read on the hot path: while an order is counting,
109
+ * every single stock movement in the system has to ask "is this location
110
+ * locked?". `LocationEntity` is a plain `parent`/`children` adjacency list with
111
+ * no materialised path, so answering that from the tree would mean a recursive
112
+ * CTE per movement.
113
+ */
114
+ let InventoryCountOrderLocationEntityClass = class InventoryCountOrderLocationEntityClass {
115
+ id;
116
+ orderId;
117
+ locationId;
118
+ /** `true` for the locations the user picked, `false` for descendants. */
119
+ isRoot;
120
+ order;
121
+ location;
122
+ };
123
+ __decorate([
124
+ PrimaryGeneratedColumn('uuid'),
125
+ __metadata("design:type", String)
126
+ ], InventoryCountOrderLocationEntityClass.prototype, "id", void 0);
127
+ __decorate([
128
+ Column({ type: 'uuid' }),
129
+ Index(),
130
+ __metadata("design:type", String)
131
+ ], InventoryCountOrderLocationEntityClass.prototype, "orderId", void 0);
132
+ __decorate([
133
+ Column({ type: 'uuid' }),
134
+ Index(),
135
+ __metadata("design:type", String)
136
+ ], InventoryCountOrderLocationEntityClass.prototype, "locationId", void 0);
137
+ __decorate([
138
+ Column({ type: 'boolean', default: false }),
139
+ __metadata("design:type", Boolean)
140
+ ], InventoryCountOrderLocationEntityClass.prototype, "isRoot", void 0);
141
+ __decorate([
142
+ ManyToOne('inventory_count_orders', (order) => order.locations),
143
+ JoinColumn({ name: 'orderId', referencedColumnName: 'id' }),
144
+ __metadata("design:type", InventoryCountOrderEntityClass)
145
+ ], InventoryCountOrderLocationEntityClass.prototype, "order", void 0);
146
+ __decorate([
147
+ ManyToOne('locations'),
148
+ JoinColumn({ name: 'locationId', referencedColumnName: 'id' }),
149
+ __metadata("design:type", LocationEntityClass)
150
+ ], InventoryCountOrderLocationEntityClass.prototype, "location", void 0);
151
+ InventoryCountOrderLocationEntityClass = __decorate([
152
+ Entity('inventory_count_order_locations')
153
+ ], InventoryCountOrderLocationEntityClass);
154
+
155
+ export { InventoryCountOrderEntity, InventoryCountOrderEntityClass, InventoryCountOrderLocationEntity, InventoryCountOrderLocationEntityClass };
@@ -52,6 +52,9 @@ import { TransferCustomerOrderChangeEntity, TransferCustomerOrderChangeEntityCla
52
52
  import { ScrapeOrderEntity, ScrapeOrderEntityClass } from './extensions/scrape-order/scrape-order.entity.js';
53
53
  import { ScrapeOrderItemEntity, ScrapeOrderItemEntityClass } from './extensions/scrape-order/scrape-order-item.entity.js';
54
54
  import { ScrapeOrderChangeEntity, ScrapeOrderChangeEntityClass } from './extensions/scrape-order/scrape-order-change.entity.js';
55
+ import { InventoryCountOrderEntity, InventoryCountOrderEntityClass, InventoryCountOrderLocationEntity, InventoryCountOrderLocationEntityClass } from './extensions/inventory-count-order/inventory-count-order.entity.js';
56
+ import { InventoryCountOrderItemEntity, InventoryCountOrderItemEntityClass } from './extensions/inventory-count-order/inventory-count-order-item.entity.js';
57
+ import { InventoryCountOrderChangeEntity, InventoryCountOrderChangeEntityClass } from './extensions/inventory-count-order/inventory-count-order-change.entity.js';
55
58
 
56
59
  const entities = [
57
60
  [UnitEntity, UnitEntityClass],
@@ -106,6 +109,10 @@ const entities = [
106
109
  [ScrapeOrderEntity, ScrapeOrderEntityClass],
107
110
  [ScrapeOrderItemEntity, ScrapeOrderItemEntityClass],
108
111
  [ScrapeOrderChangeEntity, ScrapeOrderChangeEntityClass],
112
+ [InventoryCountOrderEntity, InventoryCountOrderEntityClass],
113
+ [InventoryCountOrderLocationEntity, InventoryCountOrderLocationEntityClass],
114
+ [InventoryCountOrderItemEntity, InventoryCountOrderItemEntityClass],
115
+ [InventoryCountOrderChangeEntity, InventoryCountOrderChangeEntityClass],
109
116
  ];
110
117
  /**
111
118
  * The overridable entities are deliberately absent: `WmsModuleCoreModule` binds
@@ -50,6 +50,9 @@ import '../models/extensions/transfer-customer-order/transfer-customer-order-cha
50
50
  import '../models/extensions/scrape-order/scrape-order.entity.js';
51
51
  import '../models/extensions/scrape-order/scrape-order-item.entity.js';
52
52
  import '../models/extensions/scrape-order/scrape-order-change.entity.js';
53
+ import '../models/extensions/inventory-count-order/inventory-count-order.entity.js';
54
+ import '../models/extensions/inventory-count-order/inventory-count-order-item.entity.js';
55
+ import '../models/extensions/inventory-count-order/inventory-count-order-change.entity.js';
53
56
  import { DataSource, Not, IsNull } from 'typeorm';
54
57
  import { HelperService } from './helper.service.js';
55
58
  import { MaterialService } from './material.service.js';
@@ -51,6 +51,9 @@ import '../models/extensions/transfer-customer-order/transfer-customer-order-cha
51
51
  import '../models/extensions/scrape-order/scrape-order.entity.js';
52
52
  import '../models/extensions/scrape-order/scrape-order-item.entity.js';
53
53
  import '../models/extensions/scrape-order/scrape-order-change.entity.js';
54
+ import '../models/extensions/inventory-count-order/inventory-count-order.entity.js';
55
+ import '../models/extensions/inventory-count-order/inventory-count-order-item.entity.js';
56
+ import '../models/extensions/inventory-count-order/inventory-count-order-change.entity.js';
54
57
 
55
58
  let BatchService = class BatchService {
56
59
  dataSource;
@@ -50,6 +50,9 @@ import '../models/extensions/transfer-customer-order/transfer-customer-order-cha
50
50
  import '../models/extensions/scrape-order/scrape-order.entity.js';
51
51
  import '../models/extensions/scrape-order/scrape-order-item.entity.js';
52
52
  import '../models/extensions/scrape-order/scrape-order-change.entity.js';
53
+ import '../models/extensions/inventory-count-order/inventory-count-order.entity.js';
54
+ import '../models/extensions/inventory-count-order/inventory-count-order-item.entity.js';
55
+ import '../models/extensions/inventory-count-order/inventory-count-order-change.entity.js';
53
56
  import { DataSource } from 'typeorm';
54
57
  import { HelperService } from './helper.service.js';
55
58
  import { MaterialService } from './material.service.js';
@@ -17,6 +17,7 @@ export * from './quality-inspection-order.service';
17
17
  export * from './transfer-customer-order.service';
18
18
  export * from './hold-inventory-order.service';
19
19
  export * from './sale-order.service';
20
+ export * from './inventory-count-order.service';
20
21
  export * from './scrape.service';
21
22
  export * from './warehouse-map.service';
22
23
  export * from './helper.service';
@@ -0,0 +1,143 @@
1
+ import { DataSource, EntityManager, EntityTarget } from 'typeorm';
2
+ import { InventoryCountStatus } from '../constants/inventory-count-status';
3
+ import { InventoryCountOrderEntityClass, InventoryCountOrderItemEntityClass } from '../models';
4
+ import { WmsEntities } from '../models/wms-entities';
5
+ import { BatchService } from './batch.service';
6
+ import { HelperService } from './helper.service';
7
+ import { MaterialService } from './material.service';
8
+ import { StockService } from './stock.service';
9
+ export interface FindInventoryCountOrderInput {
10
+ readonly name?: string | null;
11
+ readonly statuses?: readonly InventoryCountStatus[] | null;
12
+ readonly createdBy?: string | null;
13
+ readonly countDateFrom?: string | null;
14
+ readonly countDateTo?: string | null;
15
+ readonly locationIds?: readonly string[] | null;
16
+ readonly offset?: number;
17
+ readonly limit?: number;
18
+ }
19
+ export interface CreateInventoryCountOrderInput {
20
+ readonly name: string;
21
+ /** The base date the settlement is reported under. `YYYY-MM-DD`. */
22
+ readonly countDate: string;
23
+ /** Root locations; every descendant is pulled into the scope. */
24
+ readonly locationIds: readonly string[];
25
+ readonly createdBy?: string | null;
26
+ }
27
+ export interface UpdateInventoryCountOrderInput {
28
+ readonly name?: string;
29
+ readonly countDate?: string;
30
+ readonly locationIds?: readonly string[];
31
+ }
32
+ export interface CountInventoryItemInput {
33
+ readonly itemId: string;
34
+ /** `null` clears the entry — the line goes back to "not counted". */
35
+ readonly countedQuantity: number | null;
36
+ readonly unitId?: string | null;
37
+ }
38
+ export interface AddInventoryCountItemInput {
39
+ readonly materialId: string;
40
+ /** An existing batch key, or a new one — the batch is created on demand. */
41
+ readonly batchKey: string;
42
+ readonly locationId: string;
43
+ readonly loaderId?: string | null;
44
+ readonly countedQuantity: number;
45
+ readonly unitId?: string | null;
46
+ }
47
+ /**
48
+ * Inventory counting: compare the ledger against what is physically there, then
49
+ * adjust the ledger to match.
50
+ *
51
+ * The shape follows the "D. 盤點" design flow. Three properties are worth
52
+ * stating up front because everything else follows from them:
53
+ *
54
+ * - **Counting never moves stock between locations.** A line that is in the
55
+ * wrong place is a transfer, not a count; `transfer-order:create` already does
56
+ * that. This service only ever adjusts quantity, up or down, in place.
57
+ * - **Nothing touches stock until settlement.** Counted quantities are working
58
+ * notes ("暫存的對帳資料"); only {@link settle} writes changes, and it does so
59
+ * in a single transaction.
60
+ * - **Starting a count locks its locations.** The book snapshot taken at
61
+ * {@link start} would be worthless if stock kept moving underneath it, so
62
+ * `InventoryCountLockSubscriber` refuses every other stock movement in the
63
+ * scope until the order settles or is cancelled.
64
+ */
65
+ export declare class InventoryCountOrderService<T extends InventoryCountOrderEntityClass = InventoryCountOrderEntityClass> {
66
+ private readonly dataSource;
67
+ private readonly entities;
68
+ private readonly helperService;
69
+ private readonly materialService;
70
+ private readonly stockService;
71
+ private readonly batchService;
72
+ readonly inventoryCountOrderEntity: EntityTarget<T>;
73
+ private readonly seqPrefix;
74
+ constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, stockService: StockService, batchService: BatchService, inventoryCountOrderEntity: EntityTarget<T>);
75
+ private getRepositories;
76
+ /**
77
+ * Expand chosen locations into themselves plus every descendant.
78
+ *
79
+ * `LocationEntity` is a plain adjacency list (`parent` / `children`) with no
80
+ * materialised path, so the subtree needs a recursive CTE. It runs once per
81
+ * scope change and the result is stored, precisely so the lock check never has
82
+ * to run it.
83
+ */
84
+ private expandLocationScope;
85
+ /** Current ledger quantity per physical position inside the scope. */
86
+ private readPositions;
87
+ private positionKey;
88
+ private scopedLocationIds;
89
+ private loadOrderOrFail;
90
+ private assertStatus;
91
+ /**
92
+ * Rebuild the sheet from the current ledger.
93
+ *
94
+ * Called when the scope changes and again when counting starts. Additions
95
+ * (盤盈 lines) are never touched — they describe stock the ledger does not know
96
+ * about, so a rebuild has nothing to say about them.
97
+ */
98
+ private rebuildItems;
99
+ /** Filters for the list page. All optional; combined with AND. */
100
+ findMany(options: FindInventoryCountOrderInput, manager?: EntityManager): Promise<[InventoryCountOrderEntityClass[], number]>;
101
+ findOne(id: string, manager?: EntityManager): Promise<InventoryCountOrderEntityClass>;
102
+ create(input: CreateInventoryCountOrderInput, manager?: EntityManager): Promise<T>;
103
+ update(id: string, input: UpdateInventoryCountOrderInput, manager?: EntityManager): Promise<T>;
104
+ /**
105
+ * Freeze the ledger and open the sheet for counting.
106
+ *
107
+ * The rebuild here is the snapshot: from this point `bookQuantity` is what the
108
+ * variance is measured against, and the lock keeps it true.
109
+ */
110
+ start(id: string, manager?: EntityManager): Promise<T>;
111
+ /** Save counted quantities without touching stock ("暫存結果"). */
112
+ count(id: string, entries: readonly CountInventoryItemInput[], manager?: EntityManager): Promise<T>;
113
+ /**
114
+ * Add a line for stock the ledger has no record of (盤盈).
115
+ *
116
+ * The batch is resolved by key and created when it does not exist, which is
117
+ * what makes "the batch field's default is editable" in the design work.
118
+ */
119
+ addItem(id: string, input: AddInventoryCountItemInput, manager?: EntityManager): Promise<InventoryCountOrderItemEntityClass>;
120
+ /** Remove an added line. Scoped lines are part of the sheet and never removed. */
121
+ removeItem(id: string, itemId: string, manager?: EntityManager): Promise<T>;
122
+ /**
123
+ * Throw the counting away and start over, without leaving the count.
124
+ *
125
+ * The scope stays locked and the status stays `COUNTING`: the point is a
126
+ * re-measure after something went wrong on the floor, not an abandonment. The
127
+ * book snapshot is deliberately *not* retaken — the lock means it has not
128
+ * moved.
129
+ */
130
+ reset(id: string, manager?: EntityManager): Promise<T>;
131
+ cancel(id: string, manager?: EntityManager): Promise<T>;
132
+ /**
133
+ * Adjust the ledger to the counted reality ("執行盤差").
134
+ *
135
+ * Runs in one transaction and is awaited end to end, so the mutation
136
+ * interceptor's post-commit guarantee holds: every `stock.count-gained` /
137
+ * `stock.count-lost` event fires only after the adjustments are durable.
138
+ *
139
+ * Uncounted lines are left alone — "not counted" is not "counted as zero", and
140
+ * treating it as zero would wipe out stock nobody looked at.
141
+ */
142
+ settle(id: string, outerManager?: EntityManager): Promise<T>;
143
+ }