@rytass/wms-module-core 0.4.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.
- package/README.md +69 -7
- package/docs/api-reference.md +58 -10
- package/docs/custom-entities.md +105 -68
- package/index.cjs.js +1263 -151
- package/index.js +10 -0
- package/lib/constants/index.d.ts +2 -0
- package/lib/constants/inventory-count-status.d.ts +19 -0
- package/lib/constants/inventory-count-status.js +22 -0
- package/lib/constants/operations.d.ts +34 -0
- package/lib/constants/operations.js +66 -0
- package/lib/constants/stock-status.d.ts +2 -0
- package/lib/constants/stock-status.js +4 -0
- package/lib/core.module.js +91 -30
- package/lib/events/index.d.ts +1 -0
- package/lib/events/inventory-count-lock.subscriber.d.ts +38 -0
- package/lib/events/inventory-count-lock.subscriber.js +98 -0
- package/lib/events/stock-change.subscriber.js +6 -0
- package/lib/events/wms-event.types.d.ts +2 -2
- package/lib/models/extensions/allocate-inventory-order/allocate-inventory-order-item.entity.js +1 -0
- package/lib/models/extensions/hold-inventory-order/hold-inventory-order-item.entity.js +1 -0
- package/lib/models/extensions/index.d.ts +3 -0
- package/lib/models/extensions/inventory-count-order/inventory-count-order-change.entity.d.ts +20 -0
- package/lib/models/extensions/inventory-count-order/inventory-count-order-change.entity.js +50 -0
- package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.d.ts +39 -0
- package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.js +123 -0
- package/lib/models/extensions/inventory-count-order/inventory-count-order.entity.d.ts +50 -0
- package/lib/models/extensions/inventory-count-order/inventory-count-order.entity.js +155 -0
- package/lib/models/extensions/merge-batch-order/merge-batch-order-item.entity.js +1 -0
- package/lib/models/extensions/quality-inspection-order/quality-inspection-order-item.entity.js +1 -0
- package/lib/models/extensions/reclassify-inventory-order/reclassify-inventory-order-item.entity.js +1 -0
- package/lib/models/extensions/scrape-order/scrape-order-item.entity.js +1 -0
- package/lib/models/extensions/split-batch-order/split-batch-order-item.entity.js +1 -0
- package/lib/models/extensions/transfer-customer-order/transfer-customer-order-item.entity.js +1 -0
- package/lib/models/extensions/transfer-order/transfer-order-item.entity.js +1 -0
- package/lib/models/extensions/transfer-vendor-order/transfer-vendor-order-item.entity.js +1 -0
- package/lib/models/index.d.ts +1 -0
- package/lib/models/metadata/index.d.ts +1 -0
- package/lib/models/metadata/order.entity.d.ts +9 -0
- package/lib/models/metadata/order.entity.js +5 -0
- package/lib/models/models.module.js +22 -8
- package/lib/models/wms-entities.d.ts +45 -0
- package/lib/models/wms-entities.js +82 -0
- package/lib/services/allocate-inventory-order.service.d.ts +3 -1
- package/lib/services/allocate-inventory-order.service.js +13 -6
- package/lib/services/batch.service.js +8 -3
- package/lib/services/hold-inventory-order.service.d.ts +3 -1
- package/lib/services/hold-inventory-order.service.js +13 -6
- package/lib/services/index.d.ts +1 -0
- package/lib/services/inventory-count-order.service.d.ts +143 -0
- package/lib/services/inventory-count-order.service.js +521 -0
- package/lib/services/loader.service.js +5 -0
- package/lib/services/location.service.js +5 -0
- package/lib/services/material.service.d.ts +1 -15
- package/lib/services/material.service.js +5 -20
- package/lib/services/merge-batch-order.service.d.ts +3 -1
- package/lib/services/merge-batch-order.service.js +16 -9
- package/lib/services/quality-inspection-order.service.d.ts +3 -1
- package/lib/services/quality-inspection-order.service.js +15 -8
- package/lib/services/receive-inventory-order.service.d.ts +3 -1
- package/lib/services/receive-inventory-order.service.js +18 -11
- package/lib/services/reclassify-inventory-order.service.d.ts +3 -1
- package/lib/services/reclassify-inventory-order.service.js +16 -9
- package/lib/services/scrape.service.d.ts +3 -1
- package/lib/services/scrape.service.js +12 -5
- package/lib/services/ship-inventory-order.service.d.ts +3 -1
- package/lib/services/ship-inventory-order.service.js +21 -14
- package/lib/services/split-batch-order.service.d.ts +3 -1
- package/lib/services/split-batch-order.service.js +16 -9
- package/lib/services/stock.service.d.ts +3 -1
- package/lib/services/stock.service.js +17 -10
- package/lib/services/transfer-customer-order.service.d.ts +3 -1
- package/lib/services/transfer-customer-order.service.js +15 -8
- package/lib/services/transfer-order.service.d.ts +3 -1
- package/lib/services/transfer-order.service.js +14 -7
- package/lib/services/transfer-vendor-order.service.d.ts +3 -1
- package/lib/services/transfer-vendor-order.service.js +15 -8
- package/lib/services/unit.service.js +5 -0
- package/lib/services/warehouse-map.service.d.ts +14 -2
- package/lib/services/warehouse-map.service.js +21 -9
- package/package.json +2 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { __decorate, __param, __metadata } from 'tslib';
|
|
2
|
+
import { Injectable, Inject } from '@nestjs/common';
|
|
3
|
+
import { DataSource } from 'typeorm';
|
|
4
|
+
import { BatchEntity } from './metadata/batch.entity.js';
|
|
5
|
+
import { LocationEntity, WarehouseMapEntity } from './metadata/location.entity.js';
|
|
6
|
+
import { MaterialEntity } from './metadata/material.entity.js';
|
|
7
|
+
import { OrderEntity } from './metadata/order.entity.js';
|
|
8
|
+
import { StockEntity } from './metadata/stock.entity.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The entity classes this package actually reads and writes, after applying the
|
|
12
|
+
* consumer's `WMSBaseModuleOptions` entity overrides.
|
|
13
|
+
*
|
|
14
|
+
* Every overridable entity is bound to a `Symbol` that `WmsModuleCoreModule`
|
|
15
|
+
* resolves from the base module's `PROVIDE_*_ENTITY` tokens. Injecting them one
|
|
16
|
+
* by one works, but most services and resolvers need three or four at once, so
|
|
17
|
+
* this collects them behind a single dependency.
|
|
18
|
+
*
|
|
19
|
+
* Only entities the base module lets a consumer replace are here. Entities this
|
|
20
|
+
* package owns outright — batch groups, loaders, units, every order extension —
|
|
21
|
+
* have no override to follow and are referenced by class directly.
|
|
22
|
+
*/
|
|
23
|
+
let WmsEntities = class WmsEntities {
|
|
24
|
+
material;
|
|
25
|
+
batch;
|
|
26
|
+
location;
|
|
27
|
+
stock;
|
|
28
|
+
order;
|
|
29
|
+
warehouseMap;
|
|
30
|
+
constructor(dataSource, material, batch, location, stock, order, warehouseMap) {
|
|
31
|
+
this.material = material;
|
|
32
|
+
this.batch = batch;
|
|
33
|
+
this.location = location;
|
|
34
|
+
this.stock = stock;
|
|
35
|
+
this.order = order;
|
|
36
|
+
this.warehouseMap = warehouseMap;
|
|
37
|
+
this.assertRegistered(dataSource);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fail during instantiation if an override was never registered with TypeORM.
|
|
41
|
+
*
|
|
42
|
+
* The module cannot register it: `TypeOrmModule.forFeature()` runs while the
|
|
43
|
+
* module graph is assembled, and an override is only known once the options
|
|
44
|
+
* resolve. Registering the built-in class does bring the override's *columns*
|
|
45
|
+
* into the table (TypeORM copies a single-table child's columns into its
|
|
46
|
+
* parent), which makes the omission easy to miss — everything looks right
|
|
47
|
+
* until the first query fails with a bare `EntityMetadataNotFoundError` from
|
|
48
|
+
* somewhere deep in a resolver.
|
|
49
|
+
*
|
|
50
|
+
* This runs in the constructor rather than `onModuleInit` so it lands before
|
|
51
|
+
* any service's own startup work touches the database.
|
|
52
|
+
*/
|
|
53
|
+
assertRegistered(dataSource) {
|
|
54
|
+
const missing = [
|
|
55
|
+
['materialEntity', this.material],
|
|
56
|
+
['batchEntity', this.batch],
|
|
57
|
+
['locationEntity', this.location],
|
|
58
|
+
['stockEntity', this.stock],
|
|
59
|
+
['orderEntity', this.order],
|
|
60
|
+
['warehouseMapEntity', this.warehouseMap],
|
|
61
|
+
].filter(([, entity]) => !dataSource.hasMetadata(entity));
|
|
62
|
+
if (!missing.length)
|
|
63
|
+
return;
|
|
64
|
+
const details = missing
|
|
65
|
+
.map(([option, entity]) => `${option}: ${entity.name}`)
|
|
66
|
+
.join(', ');
|
|
67
|
+
const names = missing.map(([, entity]) => entity.name).join(', ');
|
|
68
|
+
throw new Error(`WmsModuleCoreModule: configured entities are not registered with TypeORM (${details}). Add them to your DataSource "entities", or import TypeOrmModule.forFeature([${names}]) somewhere in your app when using autoLoadEntities.`);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
WmsEntities = __decorate([
|
|
72
|
+
Injectable(),
|
|
73
|
+
__param(1, Inject(MaterialEntity)),
|
|
74
|
+
__param(2, Inject(BatchEntity)),
|
|
75
|
+
__param(3, Inject(LocationEntity)),
|
|
76
|
+
__param(4, Inject(StockEntity)),
|
|
77
|
+
__param(5, Inject(OrderEntity)),
|
|
78
|
+
__param(6, Inject(WarehouseMapEntity)),
|
|
79
|
+
__metadata("design:paramtypes", [DataSource, Object, Object, Object, Object, Object, Object])
|
|
80
|
+
], WmsEntities);
|
|
81
|
+
|
|
82
|
+
export { WmsEntities };
|
|
@@ -7,8 +7,10 @@ import { MaterialService } from './material.service';
|
|
|
7
7
|
import { FindAllocateInventoryOrderInput } from '../typings/find-allocate-inventory-order.input';
|
|
8
8
|
import { BatchService } from './batch.service';
|
|
9
9
|
import { StockService } from './stock.service';
|
|
10
|
+
import { WmsEntities } from '../models/wms-entities';
|
|
10
11
|
export declare class AllocateInventoryOrderService<T extends AllocateInventoryOrderEntityClass = AllocateInventoryOrderEntityClass, K extends AllocateInventoryOrderItemEntityClass = AllocateInventoryOrderItemEntityClass> {
|
|
11
12
|
private readonly dataSource;
|
|
13
|
+
private readonly entities;
|
|
12
14
|
private readonly helperService;
|
|
13
15
|
private readonly materialService;
|
|
14
16
|
private readonly batchService;
|
|
@@ -17,7 +19,7 @@ export declare class AllocateInventoryOrderService<T extends AllocateInventoryOr
|
|
|
17
19
|
readonly allocateInventoryOrderItemEntity: EntityTarget<K>;
|
|
18
20
|
readonly stockEntity: EntityTarget<StockEntityClass>;
|
|
19
21
|
private readonly seqPrefix;
|
|
20
|
-
constructor(dataSource: DataSource, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, allocateInventoryOrderEntity: EntityTarget<T>, allocateInventoryOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
22
|
+
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, allocateInventoryOrderEntity: EntityTarget<T>, allocateInventoryOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
21
23
|
private getRepositories;
|
|
22
24
|
private processAllocateInventoryOrderItems;
|
|
23
25
|
createAllocateInventoryOrder(options: CreateAllocateInventoryOrderInput, manager?: EntityManager): Promise<T>;
|
|
@@ -8,9 +8,11 @@ import '../models/metadata/loader-unit.entity.js';
|
|
|
8
8
|
import '../models/metadata/location.entity.js';
|
|
9
9
|
import '../models/metadata/material.entity.js';
|
|
10
10
|
import '../models/metadata/material-unit.entity.js';
|
|
11
|
+
import '@rytass/wms-base-nestjs-module';
|
|
11
12
|
import '../models/metadata/sale-order.entity.js';
|
|
12
13
|
import { StockEntity } from '../models/metadata/stock.entity.js';
|
|
13
14
|
import '../models/metadata/unit.entity.js';
|
|
15
|
+
import { WmsEntities } from '../models/wms-entities.js';
|
|
14
16
|
import '../models/extensions/receive-inventory-order/receive-inventory-order-item.entity.js';
|
|
15
17
|
import '../models/extensions/receive-inventory-order/receive-inventory-order.entity.js';
|
|
16
18
|
import '../models/extensions/receive-inventory-order/receive-inventory-order-change.entity.js';
|
|
@@ -48,8 +50,10 @@ import '../models/extensions/transfer-customer-order/transfer-customer-order-cha
|
|
|
48
50
|
import '../models/extensions/scrape-order/scrape-order.entity.js';
|
|
49
51
|
import '../models/extensions/scrape-order/scrape-order-item.entity.js';
|
|
50
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';
|
|
51
56
|
import { DataSource, Not, IsNull } from 'typeorm';
|
|
52
|
-
import { OrderEntity } from '@rytass/wms-base-nestjs-module';
|
|
53
57
|
import { HelperService } from './helper.service.js';
|
|
54
58
|
import { MaterialService } from './material.service.js';
|
|
55
59
|
import { BatchService } from './batch.service.js';
|
|
@@ -57,6 +61,7 @@ import { StockService } from './stock.service.js';
|
|
|
57
61
|
|
|
58
62
|
let AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
59
63
|
dataSource;
|
|
64
|
+
entities;
|
|
60
65
|
helperService;
|
|
61
66
|
materialService;
|
|
62
67
|
batchService;
|
|
@@ -65,8 +70,9 @@ let AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
65
70
|
allocateInventoryOrderItemEntity;
|
|
66
71
|
stockEntity;
|
|
67
72
|
seqPrefix = 'AIO';
|
|
68
|
-
constructor(dataSource, helperService, materialService, batchService, stockService, allocateInventoryOrderEntity, allocateInventoryOrderItemEntity, stockEntity) {
|
|
73
|
+
constructor(dataSource, entities, helperService, materialService, batchService, stockService, allocateInventoryOrderEntity, allocateInventoryOrderItemEntity, stockEntity) {
|
|
69
74
|
this.dataSource = dataSource;
|
|
75
|
+
this.entities = entities;
|
|
70
76
|
this.helperService = helperService;
|
|
71
77
|
this.materialService = materialService;
|
|
72
78
|
this.batchService = batchService;
|
|
@@ -80,7 +86,7 @@ let AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
80
86
|
allocateInventoryOrder: manager.getRepository(this.allocateInventoryOrderEntity),
|
|
81
87
|
allocateInventoryOrderItem: manager.getRepository(this.allocateInventoryOrderItemEntity),
|
|
82
88
|
allocateInventoryOrderChange: manager.getRepository(AllocateInventoryOrderChangeEntityClass),
|
|
83
|
-
order: manager.getRepository(
|
|
89
|
+
order: manager.getRepository(this.entities.order),
|
|
84
90
|
stock: manager.getRepository(this.stockEntity),
|
|
85
91
|
};
|
|
86
92
|
}
|
|
@@ -286,10 +292,11 @@ let AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
286
292
|
};
|
|
287
293
|
AllocateInventoryOrderService = __decorate([
|
|
288
294
|
Injectable(),
|
|
289
|
-
__param(
|
|
290
|
-
__param(
|
|
291
|
-
__param(
|
|
295
|
+
__param(6, Inject(AllocateInventoryOrderEntity)),
|
|
296
|
+
__param(7, Inject(AllocateInventoryOrderItemEntity)),
|
|
297
|
+
__param(8, Inject(StockEntity)),
|
|
292
298
|
__metadata("design:paramtypes", [DataSource,
|
|
299
|
+
WmsEntities,
|
|
293
300
|
HelperService,
|
|
294
301
|
MaterialService,
|
|
295
302
|
BatchService,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __param, __metadata } from 'tslib';
|
|
2
2
|
import { Injectable, Inject } from '@nestjs/common';
|
|
3
3
|
import { DataSource, IsNull } from 'typeorm';
|
|
4
|
-
import { BatchEntity
|
|
4
|
+
import { BatchEntity } from '../models/metadata/batch.entity.js';
|
|
5
5
|
import { BatchGroupEntity } from '../models/metadata/batch-group.entity.js';
|
|
6
6
|
import '../models/metadata/loader.entity.js';
|
|
7
7
|
import '../models/metadata/loader-type.entity.js';
|
|
@@ -9,9 +9,11 @@ import '../models/metadata/loader-unit.entity.js';
|
|
|
9
9
|
import '../models/metadata/location.entity.js';
|
|
10
10
|
import '../models/metadata/material.entity.js';
|
|
11
11
|
import '../models/metadata/material-unit.entity.js';
|
|
12
|
+
import '@rytass/wms-base-nestjs-module';
|
|
12
13
|
import '../models/metadata/sale-order.entity.js';
|
|
13
14
|
import '../models/metadata/stock.entity.js';
|
|
14
15
|
import '../models/metadata/unit.entity.js';
|
|
16
|
+
import '../models/wms-entities.js';
|
|
15
17
|
import '../models/extensions/receive-inventory-order/receive-inventory-order-item.entity.js';
|
|
16
18
|
import '../models/extensions/receive-inventory-order/receive-inventory-order.entity.js';
|
|
17
19
|
import '../models/extensions/receive-inventory-order/receive-inventory-order-change.entity.js';
|
|
@@ -49,6 +51,9 @@ import '../models/extensions/transfer-customer-order/transfer-customer-order-cha
|
|
|
49
51
|
import '../models/extensions/scrape-order/scrape-order.entity.js';
|
|
50
52
|
import '../models/extensions/scrape-order/scrape-order-item.entity.js';
|
|
51
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';
|
|
52
57
|
|
|
53
58
|
let BatchService = class BatchService {
|
|
54
59
|
dataSource;
|
|
@@ -120,7 +125,7 @@ let BatchService = class BatchService {
|
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
127
|
async getBatch({ manager = this.dataSource.manager, ...options }) {
|
|
123
|
-
const batchRepository = manager.getRepository(
|
|
128
|
+
const batchRepository = manager.getRepository(this.batchEntity);
|
|
124
129
|
const batchGroupRepository = manager.getRepository(this.batchGroupEntity);
|
|
125
130
|
const unsplittedCondition = {
|
|
126
131
|
saleId: IsNull(),
|
|
@@ -150,7 +155,7 @@ let BatchService = class BatchService {
|
|
|
150
155
|
return batch;
|
|
151
156
|
}
|
|
152
157
|
async splitBatch({ manager = this.dataSource.manager, ...options }) {
|
|
153
|
-
const batchRepository = manager.getRepository(
|
|
158
|
+
const batchRepository = manager.getRepository(this.batchEntity);
|
|
154
159
|
const batch = await batchRepository.findOneOrFail({
|
|
155
160
|
where: { id: options.id },
|
|
156
161
|
relations: ['batchGroup'],
|
|
@@ -7,8 +7,10 @@ import { ReleaseInventoryOrderItemInput } from '../typings/release-inventory-ord
|
|
|
7
7
|
import { MaterialService } from './material.service';
|
|
8
8
|
import { BatchService } from './batch.service';
|
|
9
9
|
import { StockService } from './stock.service';
|
|
10
|
+
import { WmsEntities } from '../models/wms-entities';
|
|
10
11
|
export declare class HoldInventoryOrderService<T extends HoldInventoryOrderEntityClass = HoldInventoryOrderEntityClass, K extends HoldInventoryOrderItemEntityClass = HoldInventoryOrderItemEntityClass> {
|
|
11
12
|
private readonly dataSource;
|
|
13
|
+
private readonly entities;
|
|
12
14
|
private readonly helperService;
|
|
13
15
|
private readonly materialService;
|
|
14
16
|
private readonly batchService;
|
|
@@ -17,7 +19,7 @@ export declare class HoldInventoryOrderService<T extends HoldInventoryOrderEntit
|
|
|
17
19
|
readonly holdInventoryOrderItemEntity: EntityTarget<K>;
|
|
18
20
|
readonly stockEntity: EntityTarget<StockEntityClass>;
|
|
19
21
|
private readonly seqPrefix;
|
|
20
|
-
constructor(dataSource: DataSource, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, holdInventoryOrderEntity: EntityTarget<T>, holdInventoryOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
22
|
+
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, batchService: BatchService, stockService: StockService, holdInventoryOrderEntity: EntityTarget<T>, holdInventoryOrderItemEntity: EntityTarget<K>, stockEntity: EntityTarget<StockEntityClass>);
|
|
21
23
|
private getRepositories;
|
|
22
24
|
private processHoldInventoryOrderItems;
|
|
23
25
|
createHoldInventoryOrder(options: CreateHoldInventoryOrderInput, manager?: EntityManager): Promise<T>;
|
|
@@ -8,9 +8,11 @@ import '../models/metadata/loader-unit.entity.js';
|
|
|
8
8
|
import '../models/metadata/location.entity.js';
|
|
9
9
|
import '../models/metadata/material.entity.js';
|
|
10
10
|
import '../models/metadata/material-unit.entity.js';
|
|
11
|
+
import '@rytass/wms-base-nestjs-module';
|
|
11
12
|
import '../models/metadata/sale-order.entity.js';
|
|
12
13
|
import { StockEntity } from '../models/metadata/stock.entity.js';
|
|
13
14
|
import '../models/metadata/unit.entity.js';
|
|
15
|
+
import { WmsEntities } from '../models/wms-entities.js';
|
|
14
16
|
import '../models/extensions/receive-inventory-order/receive-inventory-order-item.entity.js';
|
|
15
17
|
import '../models/extensions/receive-inventory-order/receive-inventory-order.entity.js';
|
|
16
18
|
import '../models/extensions/receive-inventory-order/receive-inventory-order-change.entity.js';
|
|
@@ -48,15 +50,18 @@ import '../models/extensions/transfer-customer-order/transfer-customer-order-cha
|
|
|
48
50
|
import '../models/extensions/scrape-order/scrape-order.entity.js';
|
|
49
51
|
import '../models/extensions/scrape-order/scrape-order-item.entity.js';
|
|
50
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';
|
|
51
56
|
import { DataSource } from 'typeorm';
|
|
52
57
|
import { HelperService } from './helper.service.js';
|
|
53
|
-
import { OrderEntity } from '@rytass/wms-base-nestjs-module';
|
|
54
58
|
import { MaterialService } from './material.service.js';
|
|
55
59
|
import { BatchService } from './batch.service.js';
|
|
56
60
|
import { StockService } from './stock.service.js';
|
|
57
61
|
|
|
58
62
|
let HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
59
63
|
dataSource;
|
|
64
|
+
entities;
|
|
60
65
|
helperService;
|
|
61
66
|
materialService;
|
|
62
67
|
batchService;
|
|
@@ -65,8 +70,9 @@ let HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
|
65
70
|
holdInventoryOrderItemEntity;
|
|
66
71
|
stockEntity;
|
|
67
72
|
seqPrefix = 'HIO';
|
|
68
|
-
constructor(dataSource, helperService, materialService, batchService, stockService, holdInventoryOrderEntity, holdInventoryOrderItemEntity, stockEntity) {
|
|
73
|
+
constructor(dataSource, entities, helperService, materialService, batchService, stockService, holdInventoryOrderEntity, holdInventoryOrderItemEntity, stockEntity) {
|
|
69
74
|
this.dataSource = dataSource;
|
|
75
|
+
this.entities = entities;
|
|
70
76
|
this.helperService = helperService;
|
|
71
77
|
this.materialService = materialService;
|
|
72
78
|
this.batchService = batchService;
|
|
@@ -81,7 +87,7 @@ let HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
|
81
87
|
holdInventoryOrderItem: manager.getRepository(this.holdInventoryOrderItemEntity),
|
|
82
88
|
holdInventoryOrderChange: manager.getRepository(HoldInventoryOrderChangeEntityClass),
|
|
83
89
|
stock: manager.getRepository(this.stockEntity),
|
|
84
|
-
order: manager.getRepository(
|
|
90
|
+
order: manager.getRepository(this.entities.order),
|
|
85
91
|
};
|
|
86
92
|
}
|
|
87
93
|
async processHoldInventoryOrderItems(items, repos, manager) {
|
|
@@ -272,10 +278,11 @@ let HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
|
272
278
|
};
|
|
273
279
|
HoldInventoryOrderService = __decorate([
|
|
274
280
|
Injectable(),
|
|
275
|
-
__param(
|
|
276
|
-
__param(
|
|
277
|
-
__param(
|
|
281
|
+
__param(6, Inject(HoldInventoryOrderEntity)),
|
|
282
|
+
__param(7, Inject(HoldInventoryOrderItemEntity)),
|
|
283
|
+
__param(8, Inject(StockEntity)),
|
|
278
284
|
__metadata("design:paramtypes", [DataSource,
|
|
285
|
+
WmsEntities,
|
|
279
286
|
HelperService,
|
|
280
287
|
MaterialService,
|
|
281
288
|
BatchService,
|
package/lib/services/index.d.ts
CHANGED
|
@@ -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
|
+
}
|