@rytass/wms-module-core 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/docs/README.md +2 -2
- package/docs/api-reference.md +129 -10
- package/docs/host-integration.md +172 -0
- package/docs/integration-guide.md +84 -43
- package/index.cjs.js +2462 -1658
- package/index.d.ts +2 -0
- package/lib/events/inventory-count-lock.subscriber.d.ts +17 -5
- package/lib/models/metadata/index.d.ts +1 -0
- package/lib/models/metadata/sequence.entity.d.ts +9 -0
- package/lib/models/models.module.d.ts +7 -0
- package/lib/services/allocate-inventory-order.service.d.ts +3 -3
- package/lib/services/batch.service.d.ts +13 -1
- package/lib/services/consumption-order.service.d.ts +6 -6
- package/lib/services/helper.service.d.ts +10 -4
- package/lib/services/hold-inventory-order.service.d.ts +3 -3
- package/lib/services/index.d.ts +1 -0
- package/lib/services/inventory-count-order.service.d.ts +28 -9
- package/lib/services/loader.service.d.ts +11 -3
- package/lib/services/material.service.d.ts +1 -1
- package/lib/services/merge-batch-order.service.d.ts +2 -2
- package/lib/services/quality-inspection-order.service.d.ts +1 -1
- package/lib/services/receive-inventory-order.service.d.ts +4 -4
- package/lib/services/reclassify-inventory-order.service.d.ts +2 -2
- package/lib/services/scrape.service.d.ts +1 -1
- package/lib/services/sequence.service.d.ts +58 -0
- package/lib/services/ship-inventory-order.service.d.ts +6 -6
- package/lib/services/split-batch-order.service.d.ts +2 -2
- package/lib/services/stock.service.d.ts +48 -2
- package/lib/services/transfer-customer-order.service.d.ts +3 -3
- package/lib/services/transfer-order.service.d.ts +7 -5
- package/lib/services/transfer-vendor-order.service.d.ts +3 -3
- package/lib/table-prefix/logical-table-name.d.ts +21 -0
- package/lib/table-prefix/table-prefix.d.ts +30 -0
- package/lib/typings/core-module-options.d.ts +31 -0
- package/lib/typings/create-transfer-order.input.d.ts +2 -0
- package/lib/typings/index.d.ts +20 -0
- package/lib/utils/run-in-transaction.d.ts +23 -0
- package/lib/utils/table-path.d.ts +13 -0
- package/package.json +3 -12
- package/index.d.mts +0 -6
- package/index.mjs +0 -98
- package/lib/constants/consumption-change-kind.mjs +0 -20
- package/lib/constants/inventory-count-status.mjs +0 -22
- package/lib/constants/operations.mjs +0 -76
- package/lib/constants/order-type.mjs +0 -33
- package/lib/constants/stock-status.mjs +0 -61
- package/lib/core.module.mjs +0 -287
- package/lib/events/dispatch-scope.mjs +0 -29
- package/lib/events/inventory-count-lock.subscriber.mjs +0 -98
- package/lib/events/stock-change.subscriber.mjs +0 -252
- package/lib/events/wms-event.collector.mjs +0 -22
- package/lib/events/wms-event.dispatcher.mjs +0 -63
- package/lib/events/wms-event.tokens.mjs +0 -12
- package/lib/events/wms-operation-runner.mjs +0 -101
- package/lib/models/extensions/allocate-inventory-order/allocate-inventory-order-change.entity.mjs +0 -40
- package/lib/models/extensions/allocate-inventory-order/allocate-inventory-order-item.entity.mjs +0 -104
- package/lib/models/extensions/allocate-inventory-order/allocate-inventory-order.entity.mjs +0 -33
- package/lib/models/extensions/consumption-order/consumption-order-change.entity.mjs +0 -59
- package/lib/models/extensions/consumption-order/consumption-order-item.entity.mjs +0 -114
- package/lib/models/extensions/consumption-order/consumption-order.entity.mjs +0 -69
- package/lib/models/extensions/hold-inventory-order/hold-inventory-order-change.entity.mjs +0 -40
- package/lib/models/extensions/hold-inventory-order/hold-inventory-order-item.entity.mjs +0 -98
- package/lib/models/extensions/hold-inventory-order/hold-inventory-order.entity.mjs +0 -43
- package/lib/models/extensions/inventory-count-order/inventory-count-order-change.entity.mjs +0 -50
- package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.mjs +0 -191
- package/lib/models/extensions/inventory-count-order/inventory-count-order.entity.mjs +0 -155
- package/lib/models/extensions/merge-batch-order/merge-batch-order-change.entity.mjs +0 -40
- package/lib/models/extensions/merge-batch-order/merge-batch-order-item.entity.mjs +0 -75
- package/lib/models/extensions/merge-batch-order/merge-batch-order.entity.mjs +0 -33
- package/lib/models/extensions/order-reference/order-reference.entity.mjs +0 -95
- package/lib/models/extensions/quality-inspection-order/quality-inspection-order-change.entity.mjs +0 -45
- package/lib/models/extensions/quality-inspection-order/quality-inspection-order-item.entity.mjs +0 -94
- package/lib/models/extensions/quality-inspection-order/quality-inspection-order.entity.mjs +0 -38
- package/lib/models/extensions/receive-inventory-order/receive-inventory-order-change.entity.mjs +0 -46
- package/lib/models/extensions/receive-inventory-order/receive-inventory-order-item.entity.mjs +0 -89
- package/lib/models/extensions/receive-inventory-order/receive-inventory-order.entity.mjs +0 -57
- package/lib/models/extensions/reclassify-inventory-order/reclassify-inventory-order-change.entity.mjs +0 -40
- package/lib/models/extensions/reclassify-inventory-order/reclassify-inventory-order-item.entity.mjs +0 -75
- package/lib/models/extensions/reclassify-inventory-order/reclassify-inventory-order.entity.mjs +0 -33
- package/lib/models/extensions/scrape-order/scrape-order-change.entity.mjs +0 -40
- package/lib/models/extensions/scrape-order/scrape-order-item.entity.mjs +0 -94
- package/lib/models/extensions/scrape-order/scrape-order.entity.mjs +0 -33
- package/lib/models/extensions/ship-inventory-order/ship-inventory-order-change.entity.mjs +0 -46
- package/lib/models/extensions/ship-inventory-order/ship-inventory-order-item.entity.mjs +0 -90
- package/lib/models/extensions/ship-inventory-order/ship-inventory-order-reference.entity.mjs +0 -65
- package/lib/models/extensions/ship-inventory-order/ship-inventory-order.entity.mjs +0 -56
- package/lib/models/extensions/split-batch-order/split-batch-order-change.entity.mjs +0 -40
- package/lib/models/extensions/split-batch-order/split-batch-order-item.entity.mjs +0 -75
- package/lib/models/extensions/split-batch-order/split-batch-order.entity.mjs +0 -33
- package/lib/models/extensions/transfer-customer-order/transfer-customer-order-change.entity.mjs +0 -40
- package/lib/models/extensions/transfer-customer-order/transfer-customer-order-item.entity.mjs +0 -99
- package/lib/models/extensions/transfer-customer-order/transfer-customer-order.entity.mjs +0 -33
- package/lib/models/extensions/transfer-order/transfer-order-change.entity.mjs +0 -40
- package/lib/models/extensions/transfer-order/transfer-order-item.entity.mjs +0 -109
- package/lib/models/extensions/transfer-order/transfer-order.entity.mjs +0 -53
- package/lib/models/extensions/transfer-vendor-order/transfer-vendor-order-change.entity.mjs +0 -40
- package/lib/models/extensions/transfer-vendor-order/transfer-vendor-order-item.entity.mjs +0 -99
- package/lib/models/extensions/transfer-vendor-order/transfer-vendor-order.entity.mjs +0 -33
- package/lib/models/metadata/batch-group.entity.mjs +0 -31
- package/lib/models/metadata/batch.entity.mjs +0 -131
- package/lib/models/metadata/loader-type.entity.mjs +0 -43
- package/lib/models/metadata/loader-unit.entity.mjs +0 -21
- package/lib/models/metadata/loader.entity.mjs +0 -98
- package/lib/models/metadata/location.entity.mjs +0 -28
- package/lib/models/metadata/material-unit.entity.mjs +0 -51
- package/lib/models/metadata/material.entity.mjs +0 -28
- package/lib/models/metadata/order.entity.mjs +0 -5
- package/lib/models/metadata/sale-order.entity.mjs +0 -21
- package/lib/models/metadata/stock.entity.mjs +0 -29
- package/lib/models/metadata/unit.entity.mjs +0 -21
- package/lib/models/models.module.mjs +0 -158
- package/lib/models/wms-entities.mjs +0 -82
- package/lib/services/allocate-inventory-order.service.mjs +0 -310
- package/lib/services/base-order.service.mjs +0 -76
- package/lib/services/batch.service.mjs +0 -272
- package/lib/services/consumption-order.service.mjs +0 -504
- package/lib/services/helper.service.mjs +0 -28
- package/lib/services/hold-inventory-order.service.mjs +0 -296
- package/lib/services/inventory-count-order.service.mjs +0 -648
- package/lib/services/loader.service.mjs +0 -291
- package/lib/services/location.service.mjs +0 -139
- package/lib/services/material.service.mjs +0 -181
- package/lib/services/merge-batch-order.service.mjs +0 -206
- package/lib/services/order-reference.service.mjs +0 -136
- package/lib/services/quality-inspection-order.service.mjs +0 -146
- package/lib/services/receive-inventory-order.service.mjs +0 -468
- package/lib/services/reclassify-inventory-order.service.mjs +0 -192
- package/lib/services/sale-order.service.mjs +0 -20
- package/lib/services/scrape.service.mjs +0 -150
- package/lib/services/ship-inventory-order.service.mjs +0 -610
- package/lib/services/split-batch-order.service.mjs +0 -191
- package/lib/services/stock.service.mjs +0 -559
- package/lib/services/transfer-customer-order.service.mjs +0 -290
- package/lib/services/transfer-order.service.mjs +0 -641
- package/lib/services/transfer-vendor-order.service.mjs +0 -290
- package/lib/services/unit.service.mjs +0 -76
- package/lib/services/warehouse-map.service.mjs +0 -50
- package/lib/typings/core-module-options.mjs +0 -3
- package/lib/typings/find-receive-inventory-order.input.mjs +0 -9
- package/lib/typings/find-ship-inventory-order.input.mjs +0 -9
package/index.d.ts
CHANGED
|
@@ -21,6 +21,17 @@ import { DataSource, type EntitySubscriberInterface, type InsertEvent } from 'ty
|
|
|
21
21
|
* covered too — which is exactly the case that matters, because a host with
|
|
22
22
|
* its own inbound flow does precisely that.
|
|
23
23
|
*
|
|
24
|
+
* Both ends of a movement are checked
|
|
25
|
+
* -----------------------------------
|
|
26
|
+
* A transfer item names a source (`locationId`) and a destination
|
|
27
|
+
* (`targetLocationId`), and completing it writes stock at the destination. A
|
|
28
|
+
* change row cannot tell a reservation from a completion — both are an item id
|
|
29
|
+
* and a signed quantity — so any change on an item whose source *or*
|
|
30
|
+
* destination is locked is refused. The cost is that a transfer *into* a counted
|
|
31
|
+
* location cannot be reserved or cancelled either while the count runs. That is
|
|
32
|
+
* the conservative side to err on: stock arriving on a counted shelf is exactly
|
|
33
|
+
* the movement the snapshot cannot absorb.
|
|
34
|
+
*
|
|
24
35
|
* The check costs one indexed lookup per change row. That is deliberate: caching
|
|
25
36
|
* the locked set would open a window right after `start()` in which a movement
|
|
26
37
|
* slips through, and a lock with a window is not a lock.
|
|
@@ -29,10 +40,11 @@ export declare class InventoryCountLockSubscriber implements EntitySubscriberInt
|
|
|
29
40
|
constructor(dataSource: DataSource);
|
|
30
41
|
beforeInsert(event: InsertEvent<unknown>): Promise<void>;
|
|
31
42
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `itemId` or still as the item object,
|
|
35
|
-
* row, so both are accepted.
|
|
43
|
+
* Every location the change ultimately touches — the item's own and, for a
|
|
44
|
+
* transfer, the one it is headed to. `beforeInsert` may see the relation
|
|
45
|
+
* either already flattened to `itemId` or still as the item object,
|
|
46
|
+
* depending on how the caller built the row, so both are accepted.
|
|
36
47
|
*/
|
|
37
|
-
private
|
|
48
|
+
private resolveLocationIds;
|
|
49
|
+
private resolveItem;
|
|
38
50
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const SequenceEntity: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* One counter per row, for `sequenceStorage: 'table'`. `key` is the counter's
|
|
4
|
+
* name (`TO_20261102`, `P_SEQ`, …), `value` the last number handed out.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SequenceEntityClass {
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every entity class this package declares, for `withWmsTablePrefix`: the
|
|
3
|
+
* prefix is applied by class identity, never by table-name string, so a host
|
|
4
|
+
* entity that happens to share a class or table name with one of ours is left
|
|
5
|
+
* alone.
|
|
6
|
+
*/
|
|
7
|
+
export declare const WMS_MODULE_ENTITY_CLASSES: readonly (new () => object)[];
|
|
1
8
|
export declare const ResolvedEntitiesProviders: {
|
|
2
9
|
provide: symbol;
|
|
3
10
|
useValue: new () => object;
|
|
@@ -22,10 +22,10 @@ export declare class AllocateInventoryOrderService<T extends AllocateInventoryOr
|
|
|
22
22
|
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, allocateInventoryOrderEntity: EntityTarget<T>, allocateInventoryOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
23
23
|
private getRepositories;
|
|
24
24
|
private processAllocateInventoryOrderItems;
|
|
25
|
-
createAllocateInventoryOrder(options: CreateAllocateInventoryOrderInput,
|
|
26
|
-
updateAllocateInventoryOrder({ id, manager, ...options }: UpdateAllocateInventoryOrderInput & {
|
|
25
|
+
createAllocateInventoryOrder(options: CreateAllocateInventoryOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
26
|
+
updateAllocateInventoryOrder({ id, manager: outerManager, ...options }: UpdateAllocateInventoryOrderInput & {
|
|
27
27
|
manager?: EntityManager;
|
|
28
28
|
}): Promise<T>;
|
|
29
|
-
deallocate(options: DeallocateInventoryOrderItemInput | DeallocateInventoryOrderItemInput[],
|
|
29
|
+
deallocate(options: DeallocateInventoryOrderItemInput | DeallocateInventoryOrderItemInput[], outerManager?: EntityManager): Promise<T>;
|
|
30
30
|
findMany(options: FindAllocateInventoryOrderInput): Promise<[T[], number]>;
|
|
31
31
|
}
|
|
@@ -39,9 +39,21 @@ export declare class BatchService<T extends BatchEntityClass = BatchEntityClass>
|
|
|
39
39
|
getBatch({ manager, ...options }: GetBatchInput & {
|
|
40
40
|
manager?: EntityManager;
|
|
41
41
|
}): Promise<T>;
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Find or create the sibling of batch `id` in its group that carries the
|
|
44
|
+
* requested state.
|
|
45
|
+
*
|
|
46
|
+
* Serialised per batch group with a transaction-scoped advisory lock, so two
|
|
47
|
+
* concurrent splits asking for the same state find one sibling rather than
|
|
48
|
+
* both creating one. Runs in the caller's transaction when given one (the lock
|
|
49
|
+
* is then held to its commit) and in a transaction of its own otherwise.
|
|
50
|
+
* Take stock locks before calling this, never after: the two are always
|
|
51
|
+
* acquired in that order.
|
|
52
|
+
*/
|
|
53
|
+
splitBatch({ manager: outerManager, ...options }: {
|
|
43
54
|
id: string;
|
|
44
55
|
manager?: EntityManager;
|
|
45
56
|
} & SplitBatchInput): Promise<BatchEntityClass>;
|
|
57
|
+
private splitBatchLocked;
|
|
46
58
|
findMany(options: FindBatchInput<T>): Promise<[BatchGroupEntityClass[], number]>;
|
|
47
59
|
}
|
|
@@ -34,14 +34,14 @@ export declare class ConsumptionOrderService<T extends ConsumptionOrderEntityCla
|
|
|
34
34
|
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, stockService: StockService, consumptionOrderEntity: EntityTarget<T>, consumptionOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
35
35
|
private getRepositories;
|
|
36
36
|
private itemRow;
|
|
37
|
-
createConsumptionOrder(options: CreateConsumptionOrderInput): Promise<T>;
|
|
37
|
+
createConsumptionOrder(options: CreateConsumptionOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
38
38
|
/**
|
|
39
39
|
* Replace the order's lines. Refused once anything has moved: the changes
|
|
40
40
|
* point at items, so swapping the items out from under them would leave the
|
|
41
41
|
* ledger describing lines that no longer exist.
|
|
42
42
|
*/
|
|
43
|
-
updateConsumptionOrder(options: UpdateConsumptionOrderInput): Promise<T>;
|
|
44
|
-
removeConsumptionOrder(id: string): Promise<boolean>;
|
|
43
|
+
updateConsumptionOrder(options: UpdateConsumptionOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
44
|
+
removeConsumptionOrder(id: string, outerManager?: EntityManager): Promise<boolean>;
|
|
45
45
|
/**
|
|
46
46
|
* How much of each line has moved, **in base units**.
|
|
47
47
|
*
|
|
@@ -60,11 +60,11 @@ export declare class ConsumptionOrderService<T extends ConsumptionOrderEntityCla
|
|
|
60
60
|
* Hand material to the process: it leaves the source location and appears at
|
|
61
61
|
* the consuming one. Nothing about the batch changes.
|
|
62
62
|
*/
|
|
63
|
-
issue(options: ConsumptionOrderActionInput): Promise<boolean>;
|
|
63
|
+
issue(options: ConsumptionOrderActionInput, manager?: EntityManager): Promise<boolean>;
|
|
64
64
|
/** Take back material the process did not use. */
|
|
65
|
-
return(options: ConsumptionOrderActionInput): Promise<boolean>;
|
|
65
|
+
return(options: ConsumptionOrderActionInput, manager?: EntityManager): Promise<boolean>;
|
|
66
66
|
/** Close out material the process used up: it leaves inventory. */
|
|
67
|
-
settle(options: ConsumptionOrderActionInput): Promise<boolean>;
|
|
67
|
+
settle(options: ConsumptionOrderActionInput, manager?: EntityManager): Promise<boolean>;
|
|
68
68
|
private act;
|
|
69
69
|
/** `amount` is in base units; `act` has already converted. */
|
|
70
70
|
private writeMovement;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { WmsSequenceService } from './sequence.service';
|
|
2
3
|
export declare class HelperService {
|
|
3
|
-
private readonly
|
|
4
|
-
constructor(
|
|
5
|
-
|
|
4
|
+
private readonly sequenceService;
|
|
5
|
+
constructor(sequenceService: WmsSequenceService);
|
|
6
|
+
/**
|
|
7
|
+
* The next order key for `prefix` today: `yyyyMMdd` and a four-digit daily
|
|
8
|
+
* serial. Counted by `WmsSequenceService` under `<prefix>_<yyyyMMdd>`, the
|
|
9
|
+
* name the sequence has always had, so an existing deployment carries on.
|
|
10
|
+
*/
|
|
11
|
+
getSeq(prefix: string, manager?: EntityManager): Promise<string>;
|
|
6
12
|
}
|
|
@@ -22,10 +22,10 @@ export declare class HoldInventoryOrderService<T extends HoldInventoryOrderEntit
|
|
|
22
22
|
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, holdInventoryOrderEntity: EntityTarget<T>, holdInventoryOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
23
23
|
private getRepositories;
|
|
24
24
|
private processHoldInventoryOrderItems;
|
|
25
|
-
createHoldInventoryOrder(options: CreateHoldInventoryOrderInput,
|
|
26
|
-
updateHoldInventoryOrder({ id, manager, ...options }: UpdateHoldInventoryOrderInput & {
|
|
25
|
+
createHoldInventoryOrder(options: CreateHoldInventoryOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
26
|
+
updateHoldInventoryOrder({ id, manager: outerManager, ...options }: UpdateHoldInventoryOrderInput & {
|
|
27
27
|
manager?: EntityManager;
|
|
28
28
|
}): Promise<T>;
|
|
29
29
|
findMany(options: FindHoldInventoryOrderInput): Promise<[T[], number]>;
|
|
30
|
-
release(options: ReleaseInventoryOrderItemInput | ReleaseInventoryOrderItemInput[],
|
|
30
|
+
release(options: ReleaseInventoryOrderItemInput | ReleaseInventoryOrderItemInput[], outerManager?: EntityManager): Promise<T>;
|
|
31
31
|
}
|
package/lib/services/index.d.ts
CHANGED
|
@@ -95,6 +95,15 @@ export declare class InventoryCountOrderService<T extends InventoryCountOrderEnt
|
|
|
95
95
|
readonly inventoryCountOrderEntity: EntityTarget<T>;
|
|
96
96
|
private readonly seqPrefix;
|
|
97
97
|
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, stockService: StockService, batchService: BatchService, inventoryCountOrderEntity: EntityTarget<T>);
|
|
98
|
+
/**
|
|
99
|
+
* Run `work` inside the caller's transaction when there is one, otherwise
|
|
100
|
+
* open one. Every mutating method goes through here: a count is several rows
|
|
101
|
+
* across three tables, and a failure halfway — a scope row that would not
|
|
102
|
+
* save, a sheet rebuild that threw — must leave nothing behind. It is also
|
|
103
|
+
* what lets the event guarantee hold for a direct service call: the
|
|
104
|
+
* post-commit flush keys off the outermost transaction, and this is it.
|
|
105
|
+
*/
|
|
106
|
+
private inTransaction;
|
|
98
107
|
private getRepositories;
|
|
99
108
|
/**
|
|
100
109
|
* Expand chosen locations into themselves plus every descendant.
|
|
@@ -130,26 +139,28 @@ export declare class InventoryCountOrderService<T extends InventoryCountOrderEnt
|
|
|
130
139
|
* to the shelf in front of them.
|
|
131
140
|
*/
|
|
132
141
|
findItems(orderId: string, options?: FindInventoryCountOrderItemInput, manager?: EntityManager): Promise<[InventoryCountOrderItemEntityClass[], number]>;
|
|
133
|
-
create(input: CreateInventoryCountOrderInput,
|
|
134
|
-
update(id: string, input: UpdateInventoryCountOrderInput,
|
|
142
|
+
create(input: CreateInventoryCountOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
143
|
+
update(id: string, input: UpdateInventoryCountOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
135
144
|
/**
|
|
136
145
|
* Freeze the ledger and open the sheet for counting.
|
|
137
146
|
*
|
|
138
147
|
* The rebuild here is the snapshot: from this point `bookQuantity` is what the
|
|
139
|
-
* variance is measured against, and the lock keeps it true.
|
|
148
|
+
* variance is measured against, and the lock keeps it true. Snapshot and
|
|
149
|
+
* status flip commit together, so there is never a moment with the lock on
|
|
150
|
+
* and stale books behind it, or fresh books and no lock.
|
|
140
151
|
*/
|
|
141
|
-
start(id: string,
|
|
152
|
+
start(id: string, outerManager?: EntityManager): Promise<T>;
|
|
142
153
|
/** Save counted quantities without touching stock ("暫存結果"). */
|
|
143
|
-
count(id: string, entries: readonly CountInventoryItemInput[],
|
|
154
|
+
count(id: string, entries: readonly CountInventoryItemInput[], outerManager?: EntityManager): Promise<T>;
|
|
144
155
|
/**
|
|
145
156
|
* Add a line for stock the ledger has no record of (盤盈).
|
|
146
157
|
*
|
|
147
158
|
* The batch is resolved by key and created when it does not exist, which is
|
|
148
159
|
* what makes "the batch field's default is editable" in the design work.
|
|
149
160
|
*/
|
|
150
|
-
addItem(id: string, input: AddInventoryCountItemInput,
|
|
161
|
+
addItem(id: string, input: AddInventoryCountItemInput, outerManager?: EntityManager): Promise<InventoryCountOrderItemEntityClass>;
|
|
151
162
|
/** Remove an added line. Scoped lines are part of the sheet and never removed. */
|
|
152
|
-
removeItem(id: string, itemId: string,
|
|
163
|
+
removeItem(id: string, itemId: string, outerManager?: EntityManager): Promise<T>;
|
|
153
164
|
/**
|
|
154
165
|
* Throw the counting away and start over, without leaving the count.
|
|
155
166
|
*
|
|
@@ -158,8 +169,8 @@ export declare class InventoryCountOrderService<T extends InventoryCountOrderEnt
|
|
|
158
169
|
* book snapshot is deliberately *not* retaken — the lock means it has not
|
|
159
170
|
* moved.
|
|
160
171
|
*/
|
|
161
|
-
reset(id: string,
|
|
162
|
-
cancel(id: string,
|
|
172
|
+
reset(id: string, outerManager?: EntityManager): Promise<T>;
|
|
173
|
+
cancel(id: string, outerManager?: EntityManager): Promise<T>;
|
|
163
174
|
/**
|
|
164
175
|
* Adjust the ledger to the counted reality ("執行盤差").
|
|
165
176
|
*
|
|
@@ -169,6 +180,14 @@ export declare class InventoryCountOrderService<T extends InventoryCountOrderEnt
|
|
|
169
180
|
*
|
|
170
181
|
* Uncounted lines are left alone — "not counted" is not "counted as zero", and
|
|
171
182
|
* treating it as zero would wipe out stock nobody looked at.
|
|
183
|
+
*
|
|
184
|
+
* Before anything is written, the snapshot is checked against the live
|
|
185
|
+
* ledger. The lock makes the two equal by construction; if they differ,
|
|
186
|
+
* something wrote around the lock — a direct `stocks` insert, a path with no
|
|
187
|
+
* change row — and settling would post a variance against books that no
|
|
188
|
+
* longer exist. Refusing is the only safe answer.
|
|
172
189
|
*/
|
|
173
190
|
settle(id: string, outerManager?: EntityManager): Promise<T>;
|
|
191
|
+
/** Every scoped line's `bookQuantity` must still equal the ledger. */
|
|
192
|
+
private assertSnapshotHolds;
|
|
174
193
|
}
|
|
@@ -4,6 +4,8 @@ import { LoaderTypeEntityClass } from '../models/metadata/loader-type.entity';
|
|
|
4
4
|
import { CreateLoaderInput, UpdateLoaderInput } from '../typings/create-loader.input';
|
|
5
5
|
import { CreateLoaderTypeInput, UpdateLoaderTypeInput } from '../typings/create-loader-type.input';
|
|
6
6
|
import { FindLoaderInput, FindLoaderTypeInput } from '../typings/find-loader.input';
|
|
7
|
+
import { WmsSequenceService } from './sequence.service';
|
|
8
|
+
import { WmsEntities } from '../models/wms-entities';
|
|
7
9
|
import { LoaderUnitEntityClass } from '../models';
|
|
8
10
|
/**
|
|
9
11
|
* Service for managing loaders and their types
|
|
@@ -13,6 +15,8 @@ import { LoaderUnitEntityClass } from '../models';
|
|
|
13
15
|
*/
|
|
14
16
|
export declare class LoaderService<T extends LoadersEntityClass = LoadersEntityClass, K extends LoaderTypeEntityClass = LoaderTypeEntityClass> {
|
|
15
17
|
private readonly dataSource;
|
|
18
|
+
private readonly sequenceService;
|
|
19
|
+
private readonly entities;
|
|
16
20
|
readonly loaderEntity: EntityTarget<T>;
|
|
17
21
|
readonly loaderTypeEntity: EntityTarget<K>;
|
|
18
22
|
readonly loaderUnitEntity: EntityTarget<LoaderUnitEntityClass>;
|
|
@@ -20,11 +24,11 @@ export declare class LoaderService<T extends LoadersEntityClass = LoadersEntityC
|
|
|
20
24
|
readonly loaderTypeRepository: Repository<K>;
|
|
21
25
|
readonly loaderUnitRepository: Repository<LoaderUnitEntityClass>;
|
|
22
26
|
readonly loaderSerialMaxDigits = 4;
|
|
23
|
-
constructor(dataSource: DataSource, loaderEntity: EntityTarget<T>, loaderTypeEntity: EntityTarget<K>, loaderUnitEntity: EntityTarget<LoaderUnitEntityClass>);
|
|
24
|
-
createLoader({ manager, ...options }: CreateLoaderInput & {
|
|
27
|
+
constructor(dataSource: DataSource, sequenceService: WmsSequenceService, entities: WmsEntities, loaderEntity: EntityTarget<T>, loaderTypeEntity: EntityTarget<K>, loaderUnitEntity: EntityTarget<LoaderUnitEntityClass>);
|
|
28
|
+
createLoader({ manager: outerManager, ...options }: CreateLoaderInput & {
|
|
25
29
|
manager?: EntityManager;
|
|
26
30
|
}): Promise<T[]>;
|
|
27
|
-
createBatchLoaders({ options, manager, }: {
|
|
31
|
+
createBatchLoaders({ options, manager: outerManager, }: {
|
|
28
32
|
options: CreateLoaderInput[];
|
|
29
33
|
manager?: EntityManager;
|
|
30
34
|
}): Promise<T[]>;
|
|
@@ -37,6 +41,10 @@ export declare class LoaderService<T extends LoadersEntityClass = LoadersEntityC
|
|
|
37
41
|
updateLoaderType({ id, manager, ...options }: UpdateLoaderTypeInput & {
|
|
38
42
|
manager?: EntityManager;
|
|
39
43
|
}): Promise<K>;
|
|
44
|
+
/**
|
|
45
|
+
* Reserve `count` consecutive loader serial numbers for loader type `prefix`
|
|
46
|
+
* and return the first. Counted by `WmsSequenceService` under `<prefix>_SEQ`.
|
|
47
|
+
*/
|
|
40
48
|
getSeq(prefix: string, count: number, manager?: EntityManager, maxDigits?: number): Promise<number>;
|
|
41
49
|
findManyLoaders(options: FindLoaderInput<T>): Promise<[T[], number]>;
|
|
42
50
|
findManyLoaderTypes(options: FindLoaderTypeInput<K>): Promise<[K[], number]>;
|
|
@@ -16,7 +16,7 @@ export declare class MaterialService<T extends MaterialEntityClass = MaterialEnt
|
|
|
16
16
|
readonly materialRepository: Repository<T>;
|
|
17
17
|
readonly materialUnitRepository: Repository<K>;
|
|
18
18
|
constructor(dataSource: DataSource, materialEntity: EntityTarget<T>, materialUnitEntity: EntityTarget<K>);
|
|
19
|
-
getConversionFactor(materialId: string, unitId?: string): Promise<number>;
|
|
19
|
+
getConversionFactor(materialId: string, unitId?: string, manager?: EntityManager): Promise<number>;
|
|
20
20
|
createMaterial({ manager, ...options }: CreateMaterialInput & {
|
|
21
21
|
manager?: EntityManager;
|
|
22
22
|
}): Promise<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MergeBatchOrderEntityClass, MergeBatchOrderItemEntityClass } from '../models';
|
|
2
|
-
import { DataSource, EntityTarget } from 'typeorm';
|
|
2
|
+
import { DataSource, EntityManager, EntityTarget } from 'typeorm';
|
|
3
3
|
import { MergeBatchInput } from '../typings/merge-batch.input';
|
|
4
4
|
import { MaterialService } from './material.service';
|
|
5
5
|
import { BatchService } from './batch.service';
|
|
@@ -17,5 +17,5 @@ export declare class MergeBatchOrderService<T extends MergeBatchOrderEntityClass
|
|
|
17
17
|
readonly mergeBatchOrderItemEntity: EntityTarget<K>;
|
|
18
18
|
private readonly seqPrefix;
|
|
19
19
|
constructor(dataSource: DataSource, entities: WmsEntities, materialService: MaterialService, batchService: BatchService, helperService: HelperService, stockService: StockService, mergeBatchOrderEntity: EntityTarget<T>, mergeBatchOrderItemEntity: EntityTarget<K>);
|
|
20
|
-
merge(options: MergeBatchInput): Promise<T>;
|
|
20
|
+
merge(options: MergeBatchInput, outerManager?: EntityManager): Promise<T>;
|
|
21
21
|
}
|
|
@@ -14,7 +14,7 @@ export declare class QualityInspectionOrderService<T extends QualityInspectionOr
|
|
|
14
14
|
private readonly materialService;
|
|
15
15
|
private readonly stockService;
|
|
16
16
|
constructor(dataSource: DataSource, entities: WmsEntities, qualityInspectionOrderEntity: EntityTarget<T>, qualityInspectionOrderItemEntity: EntityTarget<K>, batchService: BatchService, materialService: MaterialService, stockService: StockService);
|
|
17
|
-
inspect({ manager, options, }: {
|
|
17
|
+
inspect({ manager: outerManager, options, }: {
|
|
18
18
|
manager?: EntityManager;
|
|
19
19
|
options: CreateInspectionOrderInput;
|
|
20
20
|
}): Promise<T>;
|
|
@@ -27,17 +27,17 @@ export declare class ReceiveInventoryOrderService<T extends ReceiveInventoryOrde
|
|
|
27
27
|
readonly selectQueryBuilder: (alias: string) => SelectQueryBuilder<T>;
|
|
28
28
|
constructor(dataSource: DataSource, entities: WmsEntities, materialService: MaterialService, batchService: BatchService, helperService: HelperService, stockService: StockService, receiveInventoryOrderEntity: EntityTarget<T>, receiveInventoryOrderItemEntity: EntityTarget<K>);
|
|
29
29
|
private processReceiveInventoryOrderItems;
|
|
30
|
-
createReceiveInventoryOrder({ manager, ...options }: CreateReceiveInventoryOrderInput & {
|
|
30
|
+
createReceiveInventoryOrder({ manager: outerManager, ...options }: CreateReceiveInventoryOrderInput & {
|
|
31
31
|
manager?: EntityManager;
|
|
32
32
|
}): Promise<T>;
|
|
33
33
|
/**
|
|
34
34
|
* Update a receive inventory order and its items
|
|
35
35
|
* update existing item when id is provided, otherwise create new item, remove behaviour controlled by removedAt field
|
|
36
36
|
*/
|
|
37
|
-
updateReceiveInventoryOrder({ id, manager, ...options }: UpdateReceiveInventoryOrderInput & {
|
|
37
|
+
updateReceiveInventoryOrder({ id, manager: outerManager, ...options }: UpdateReceiveInventoryOrderInput & {
|
|
38
38
|
manager?: EntityManager;
|
|
39
39
|
}): Promise<T>;
|
|
40
|
-
removeReceiveInventoryOrder(id: string): Promise<boolean>;
|
|
40
|
+
removeReceiveInventoryOrder(id: string, manager?: EntityManager): Promise<boolean>;
|
|
41
41
|
findMany(options: FindReceiveInventoryOrderInput<T>): Promise<[T[], number]>;
|
|
42
|
-
receive(options: ReceiveInventoryOrderInput[] | ReceiveInventoryOrderInput): Promise<boolean>;
|
|
42
|
+
receive(options: ReceiveInventoryOrderInput[] | ReceiveInventoryOrderInput, outerManager?: EntityManager): Promise<boolean>;
|
|
43
43
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReclassifyInventoryOrderEntityClass, ReclassifyInventoryOrderItemEntityClass } from '../models';
|
|
2
|
-
import { DataSource, EntityTarget } from 'typeorm';
|
|
2
|
+
import { DataSource, EntityManager, EntityTarget } from 'typeorm';
|
|
3
3
|
import { ReclassifyInventoryOrderInput } from '../typings/reclassify-inventory-order.input';
|
|
4
4
|
import { MaterialService } from './material.service';
|
|
5
5
|
import { BatchService } from './batch.service';
|
|
@@ -17,5 +17,5 @@ export declare class ReclassifyInventoryOrderService<T extends ReclassifyInvento
|
|
|
17
17
|
readonly reclassifyInventoryOrderItemEntity: EntityTarget<K>;
|
|
18
18
|
private readonly seqPrefix;
|
|
19
19
|
constructor(dataSource: DataSource, entities: WmsEntities, materialService: MaterialService, batchService: BatchService, helperService: HelperService, stockService: StockService, reclassifyInventoryOrderEntity: EntityTarget<T>, reclassifyInventoryOrderItemEntity: EntityTarget<K>);
|
|
20
|
-
reclassify(options: ReclassifyInventoryOrderInput): Promise<T>;
|
|
20
|
+
reclassify(options: ReclassifyInventoryOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
21
21
|
}
|
|
@@ -16,5 +16,5 @@ export declare class ScrapeService<T extends ScrapeOrderEntityClass = ScrapeOrde
|
|
|
16
16
|
private readonly seqPrefix;
|
|
17
17
|
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, stockService: StockService, scrapeOrderEntity: EntityTarget<T>, stockEntity: EntityTarget<StockEntityClass>);
|
|
18
18
|
private getRepositories;
|
|
19
|
-
scrape(items: ScrapeInput[],
|
|
19
|
+
scrape(items: ScrapeInput[], outerManager?: EntityManager): Promise<T>;
|
|
20
20
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DataSource, EntityManager } from 'typeorm';
|
|
2
|
+
import { type WmsModuleCoreModuleOptions } from '../typings/core-module-options';
|
|
3
|
+
/**
|
|
4
|
+
* Hands out the numbers behind order keys and loader serials.
|
|
5
|
+
*
|
|
6
|
+
* `reserve(name, count)` returns the first of `count` **consecutive** numbers
|
|
7
|
+
* nobody else has been or will be given, inside the caller's transaction when
|
|
8
|
+
* there is one. It never lets a statement fail on purpose, so it is safe in a
|
|
9
|
+
* transaction (#185: the old loader path probed with `CURRVAL` and caught the
|
|
10
|
+
* error, which aborts a PostgreSQL transaction, and `CURRVAL` is per session,
|
|
11
|
+
* so pooled connections reissued each other's serials).
|
|
12
|
+
*
|
|
13
|
+
* Storage follows `sequenceStorage` — see `WmsModuleCoreModuleOptions`.
|
|
14
|
+
*/
|
|
15
|
+
export declare class WmsSequenceService {
|
|
16
|
+
private readonly dataSource;
|
|
17
|
+
private readonly options;
|
|
18
|
+
/**
|
|
19
|
+
* Sequences seen to exist. Probing and creating need a connection of their
|
|
20
|
+
* own (see `reserveSequence`), and borrowing one on every reservation meant a
|
|
21
|
+
* pool full of transactions that each wanted a number could not get the
|
|
22
|
+
* second connection any of them was waiting on. A sequence is never dropped
|
|
23
|
+
* by this package, so once seen it is remembered for the process.
|
|
24
|
+
*/
|
|
25
|
+
private readonly knownSequences;
|
|
26
|
+
constructor(dataSource: DataSource, options: WmsModuleCoreModuleOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Reserve `count` numbers of counter `name` and return the first.
|
|
29
|
+
*
|
|
30
|
+
* @param consecutive the run must be gap-free and uninterrupted (loader
|
|
31
|
+
* serials). Every reservation of a counter that is ever reserved this way
|
|
32
|
+
* must pass it, or a lone `nextval` could land inside someone else's run.
|
|
33
|
+
* @param maxValue the last number the counter may hand out. A reservation
|
|
34
|
+
* that would run past it is refused **before** the counter moves: a
|
|
35
|
+
* PostgreSQL sequence does not roll back, and a host that catches the error
|
|
36
|
+
* and commits anyway would otherwise keep the advance in table mode too.
|
|
37
|
+
* Implies `consecutive`, since the check reads the counter before moving it.
|
|
38
|
+
*/
|
|
39
|
+
reserve(name: string, count?: number, manager?: EntityManager, { maxValue, consecutive, }?: {
|
|
40
|
+
readonly consecutive?: boolean;
|
|
41
|
+
readonly maxValue?: number;
|
|
42
|
+
}): Promise<number>;
|
|
43
|
+
/**
|
|
44
|
+
* One statement, atomic whatever the session: the row lock it takes is held
|
|
45
|
+
* to commit, so concurrent callers of one counter queue rather than collide,
|
|
46
|
+
* and a rollback takes the increment back with it.
|
|
47
|
+
*/
|
|
48
|
+
private reserveRow;
|
|
49
|
+
/**
|
|
50
|
+
* A single number is one `nextval`, atomic across sessions -- order keys
|
|
51
|
+
* need nothing more. A consecutive run (loader serials) is `nextval` then
|
|
52
|
+
* `setval`, two statements another session could slip a `nextval` between,
|
|
53
|
+
* so every reservation of a counter that hands out runs holds that counter's
|
|
54
|
+
* transaction-scoped lock. Transaction-scoped on purpose: a session lock
|
|
55
|
+
* would outlive a failed statement on a pooled connection.
|
|
56
|
+
*/
|
|
57
|
+
private reserveSequence;
|
|
58
|
+
}
|
|
@@ -30,33 +30,33 @@ export declare class ShipInventoryOrderService<T extends ShipInventoryOrderEntit
|
|
|
30
30
|
constructor(dataSource: DataSource, entities: WmsEntities, materialService: MaterialService, batchService: BatchService, stockService: StockService, shipInventoryOrderEntity: EntityTarget<T>, shipInventoryOrderItemEntity: EntityTarget<K>, shipInventoryOrderReferenceEntity: EntityTarget<ShipInventoryOrderReferenceEntityClass>, saleOrderEntity: EntityTarget<SaleOrderEntityClass>);
|
|
31
31
|
private processShipInventoryOrderReferences;
|
|
32
32
|
private processShipInventoryOrderItems;
|
|
33
|
-
createShipInventoryOrder({ manager, ...options }: CreateShipInventoryOrderInput & {
|
|
33
|
+
createShipInventoryOrder({ manager: outerManager, ...options }: CreateShipInventoryOrderInput & {
|
|
34
34
|
manager?: EntityManager;
|
|
35
35
|
}): Promise<T>;
|
|
36
36
|
/**
|
|
37
37
|
* Update a ship inventory order and its items
|
|
38
38
|
* update existing item when id is provided, otherwise create new item, remove behaviour controlled by removedAt field
|
|
39
39
|
*/
|
|
40
|
-
updateShipInventoryOrder({ id, manager, ...options }: UpdateShipInventoryOrderInput & {
|
|
40
|
+
updateShipInventoryOrder({ id, manager: outerManager, ...options }: UpdateShipInventoryOrderInput & {
|
|
41
41
|
manager?: EntityManager;
|
|
42
42
|
}): Promise<T>;
|
|
43
43
|
/**
|
|
44
44
|
* Remove a ship inventory order
|
|
45
45
|
* Automatically cancels all remaining prepared (but not shipped) items to release stock
|
|
46
46
|
*/
|
|
47
|
-
removeShipInventoryOrder(id: string): Promise<boolean>;
|
|
47
|
+
removeShipInventoryOrder(id: string, outerManager?: EntityManager): Promise<boolean>;
|
|
48
48
|
/**
|
|
49
49
|
* Internal cancel method that accepts a manager for transaction support
|
|
50
50
|
*/
|
|
51
51
|
private cancelShipInternal;
|
|
52
52
|
findMany(options: FindShipInventoryOrderInput<T>): Promise<[T[], number]>;
|
|
53
|
-
addShipInventoryOrderItems(options: CreateShipInventoryOrderItemsInput,
|
|
54
|
-
ship(options: ShipInventoryOrderInput[] | ShipInventoryOrderInput): Promise<boolean>;
|
|
53
|
+
addShipInventoryOrderItems(options: CreateShipInventoryOrderItemsInput, outerManager?: EntityManager): Promise<T>;
|
|
54
|
+
ship(options: ShipInventoryOrderInput[] | ShipInventoryOrderInput, outerManager?: EntityManager): Promise<boolean>;
|
|
55
55
|
/**
|
|
56
56
|
* Cancel prepared ship inventory order items
|
|
57
57
|
* Reverses the prepare step by moving stock from IN_SHIPMENT back to FREE
|
|
58
58
|
* Can only cancel prepared quantity that hasn't been shipped yet
|
|
59
59
|
* If quantity is not provided, cancels all remaining cancellable quantity
|
|
60
60
|
*/
|
|
61
|
-
cancelShip(options: CancelShipInventoryOrderInput[] | CancelShipInventoryOrderInput): Promise<boolean>;
|
|
61
|
+
cancelShip(options: CancelShipInventoryOrderInput[] | CancelShipInventoryOrderInput, outerManager?: EntityManager): Promise<boolean>;
|
|
62
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SplitBatchOrderEntityClass, SplitBatchOrderItemEntityClass } from '../models';
|
|
2
|
-
import { DataSource, EntityTarget } from 'typeorm';
|
|
2
|
+
import { DataSource, EntityManager, EntityTarget } from 'typeorm';
|
|
3
3
|
import { SplitBatchInput } from '../typings/split-batch.input';
|
|
4
4
|
import { MaterialService } from './material.service';
|
|
5
5
|
import { BatchService } from './batch.service';
|
|
@@ -17,5 +17,5 @@ export declare class SplitBatchOrderService<T extends SplitBatchOrderEntityClass
|
|
|
17
17
|
readonly splitBatchOrderItemEntity: EntityTarget<K>;
|
|
18
18
|
private readonly seqPrefix;
|
|
19
19
|
constructor(dataSource: DataSource, entities: WmsEntities, materialService: MaterialService, batchService: BatchService, helperService: HelperService, stockService: StockService, splitBatchOrderEntity: EntityTarget<T>, splitBatchOrderItemEntity: EntityTarget<K>);
|
|
20
|
-
split(options: SplitBatchInput): Promise<T>;
|
|
20
|
+
split(options: SplitBatchInput, outerManager?: EntityManager): Promise<T>;
|
|
21
21
|
}
|
|
@@ -27,14 +27,60 @@ export declare class StockService<T extends StockEntityClass = StockEntityClass,
|
|
|
27
27
|
status: StockStatus;
|
|
28
28
|
};
|
|
29
29
|
constructor(dataSource: DataSource, entities: WmsEntities, stockEntity: EntityTarget<T>, materialEntity: new () => K, coreOptions: WmsModuleCoreModuleOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Resolve -- and unless `seedDefaults: false`, create -- the default loader
|
|
32
|
+
* type, location and loader every movement without an explicit one lands on.
|
|
33
|
+
*
|
|
34
|
+
* Idempotent across instances: the find-or-create runs in one transaction
|
|
35
|
+
* holding a transaction-scoped advisory lock, so pods starting together queue
|
|
36
|
+
* on it and the second finds what the first created instead of inserting a
|
|
37
|
+
* duplicate default (the keys carry no unique constraint to stop it).
|
|
38
|
+
*/
|
|
30
39
|
onModuleInit(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* `tablePrefix` is a check, not a setting: the prefix has to be applied
|
|
42
|
+
* before the DataSource initialised, which is long before this module's
|
|
43
|
+
* options resolve. Read back the table the stock entity really landed in.
|
|
44
|
+
*/
|
|
45
|
+
private assertTablePrefix;
|
|
31
46
|
resolveLoaderId(loaderId: string | null | undefined): string;
|
|
32
47
|
resolveLocationId(locationId: string | null | undefined): string;
|
|
33
48
|
private pipeSelectOptionsToQueryBuilder;
|
|
34
49
|
findMany(options: FindStockInput<T>): Promise<[T[], number]>;
|
|
35
50
|
findManyGroupedByMaterialId(options: FindStockInput<T>): Promise<[K[], number]>;
|
|
36
51
|
findAggregatedStock(options: Omit<AggregatedStock, 'quantity'>, manager?: EntityManager): Promise<AggregatedStock | undefined>;
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Take the transaction-scoped stock locks for `slots`, deduplicated and in a
|
|
54
|
+
* fixed order (materialId, then batchId, compared as strings), so two
|
|
55
|
+
* operations locking overlapping sets acquire them in the same order.
|
|
56
|
+
*
|
|
57
|
+
* The lock is per **(material, batch)**, not per full slot. A deduction
|
|
58
|
+
* check filters on material and batch always, but on location and loader
|
|
59
|
+
* only when the caller names them, so a finer key would let a check that
|
|
60
|
+
* spans locations and one that names a location run side by side over the
|
|
61
|
+
* same rows. Coarser is the only key that is right for every caller.
|
|
62
|
+
*
|
|
63
|
+
* Refuses outright what it cannot protect, rather than returning as if it
|
|
64
|
+
* had: a manager outside a transaction (in autocommit the lock is released
|
|
65
|
+
* by the statement that took it, before the sum it was meant to guard), and
|
|
66
|
+
* a slot without a material or batch (no key to lock -- the check that
|
|
67
|
+
* followed would sum unlocked and could oversell).
|
|
68
|
+
*/
|
|
69
|
+
lockStockSlots(slots: readonly {
|
|
70
|
+
readonly materialId?: string | null;
|
|
71
|
+
readonly batchId?: string | null;
|
|
72
|
+
}[], manager: EntityManager): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Refuse a deduction the shelf cannot cover.
|
|
75
|
+
*
|
|
76
|
+
* Locks the (material, batch) first and only then sums, so of two
|
|
77
|
+
* transactions deducting the same stock the second waits for the first to
|
|
78
|
+
* commit and then sees its deduction (the unlocked sum let both pass
|
|
79
|
+
* and oversold). That relies on READ COMMITTED, PostgreSQL's default: under
|
|
80
|
+
* REPEATABLE READ or SERIALIZABLE the second transaction's snapshot predates
|
|
81
|
+
* the first commit and the sum is stale even after the wait.
|
|
82
|
+
*/
|
|
83
|
+
validateStockAvailability(params: ValidateStockDeductionParams, manager: EntityManager): Promise<void>;
|
|
84
|
+
findAggregatedStocks(options: FindStockInput<T>, manager?: EntityManager): Promise<[AggregatedStock[], number]>;
|
|
39
85
|
findChangeLogs(options: FindStockInput<T>): Promise<[ChangeLog[], number]>;
|
|
40
86
|
}
|
|
@@ -29,9 +29,9 @@ export declare class TransferCustomerOrderService<T extends TransferCustomerOrde
|
|
|
29
29
|
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, transferCustomerOrderEntity: EntityTarget<T>, transferCustomerOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
30
30
|
private getRepositories;
|
|
31
31
|
private processTransferCustomerOrderItems;
|
|
32
|
-
createTransferCustomerOrder(options: CreateTransferCustomerOrderInput,
|
|
33
|
-
updateTransferCustomerOrder({ id, manager, ...options }: UpdateTransferCustomerOrderInput & {
|
|
32
|
+
createTransferCustomerOrder(options: CreateTransferCustomerOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
33
|
+
updateTransferCustomerOrder({ id, manager: outerManager, ...options }: UpdateTransferCustomerOrderInput & {
|
|
34
34
|
manager?: EntityManager;
|
|
35
35
|
}): Promise<T>;
|
|
36
|
-
returnTransferCustomerOrder(options: TransferCustomerOrderItemInput | TransferCustomerOrderItemInput[],
|
|
36
|
+
returnTransferCustomerOrder(options: TransferCustomerOrderItemInput | TransferCustomerOrderItemInput[], outerManager?: EntityManager): Promise<T>;
|
|
37
37
|
}
|
|
@@ -27,7 +27,7 @@ export declare class TransferOrderService<T extends TransferOrderEntityClass = T
|
|
|
27
27
|
* Process transfer order items (create transfer records and update stock)
|
|
28
28
|
*/
|
|
29
29
|
private processTransferOrderItems;
|
|
30
|
-
cancelTransfer(options: CancelTransferOrderInput[] | CancelTransferOrderInput): Promise<boolean>;
|
|
30
|
+
cancelTransfer(options: CancelTransferOrderInput[] | CancelTransferOrderInput, manager?: EntityManager): Promise<boolean>;
|
|
31
31
|
/**
|
|
32
32
|
* Internal cancel method that accepts a manager for transaction support
|
|
33
33
|
*/
|
|
@@ -36,11 +36,13 @@ export declare class TransferOrderService<T extends TransferOrderEntityClass = T
|
|
|
36
36
|
* Remove a transfer order
|
|
37
37
|
* Automatically cancels all remaining pending transfers to release stock
|
|
38
38
|
*/
|
|
39
|
-
removeTransferOrder(id: string): Promise<boolean>;
|
|
40
|
-
createTransferOrder(options: CreateTransferOrderInput,
|
|
41
|
-
|
|
39
|
+
removeTransferOrder(id: string, outerManager?: EntityManager): Promise<boolean>;
|
|
40
|
+
createTransferOrder(options: CreateTransferOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
41
|
+
private createTransferOrderInternal;
|
|
42
|
+
updateTransferOrder({ manager: outerManager, ...input }: UpdateTransferOrderInput & {
|
|
42
43
|
manager?: EntityManager;
|
|
43
44
|
}): Promise<T>;
|
|
45
|
+
private updateTransferOrderInternal;
|
|
44
46
|
findMany(options: FindTransferOrderInput): Promise<[T[], number]>;
|
|
45
|
-
transfer(options: TransferOrderInput[] | TransferOrderInput): Promise<boolean>;
|
|
47
|
+
transfer(options: TransferOrderInput[] | TransferOrderInput, outerManager?: EntityManager): Promise<boolean>;
|
|
46
48
|
}
|
|
@@ -29,9 +29,9 @@ export declare class TransferVendorOrderService<T extends TransferVendorOrderEnt
|
|
|
29
29
|
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, transferVendorOrderEntity: EntityTarget<T>, transferVendorOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
30
30
|
private getRepositories;
|
|
31
31
|
private processTransferVendorOrderItems;
|
|
32
|
-
createTransferVendorOrder(options: CreateTransferVendorOrderInput,
|
|
33
|
-
updateTransferVendorOrder({ id, manager, ...options }: UpdateTransferVendorOrderInput & {
|
|
32
|
+
createTransferVendorOrder(options: CreateTransferVendorOrderInput, outerManager?: EntityManager): Promise<T>;
|
|
33
|
+
updateTransferVendorOrder({ id, manager: outerManager, ...options }: UpdateTransferVendorOrderInput & {
|
|
34
34
|
manager?: EntityManager;
|
|
35
35
|
}): Promise<T>;
|
|
36
|
-
returnTransferVendorOrder(options: TransferVendorOrderItemInput | TransferVendorOrderItemInput[],
|
|
36
|
+
returnTransferVendorOrder(options: TransferVendorOrderItemInput | TransferVendorOrderItemInput[], outerManager?: EntityManager): Promise<T>;
|
|
37
37
|
}
|