@rytass/wms-module-core 0.5.0 → 0.7.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 +44 -2
- package/docs/api-reference.md +37 -1
- package/docs/integration-guide.md +18 -17
- package/index.cjs.js +1160 -5
- package/index.js +7 -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 +67 -0
- package/lib/constants/stock-status.d.ts +2 -0
- package/lib/constants/stock-status.js +4 -0
- package/lib/core.module.js +9 -1
- 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/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 +48 -0
- package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.js +175 -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/models.module.js +7 -0
- package/lib/services/allocate-inventory-order.service.js +3 -0
- package/lib/services/batch.service.js +3 -0
- package/lib/services/hold-inventory-order.service.js +3 -0
- package/lib/services/index.d.ts +1 -0
- package/lib/services/inventory-count-order.service.d.ts +174 -0
- package/lib/services/inventory-count-order.service.js +641 -0
- package/lib/services/loader.service.js +3 -0
- package/lib/services/location.service.js +3 -0
- package/lib/services/material.service.js +3 -0
- package/lib/services/merge-batch-order.service.js +3 -0
- package/lib/services/quality-inspection-order.service.js +3 -0
- package/lib/services/receive-inventory-order.service.js +3 -0
- package/lib/services/reclassify-inventory-order.service.js +3 -0
- package/lib/services/scrape.service.js +3 -0
- package/lib/services/ship-inventory-order.service.js +3 -0
- package/lib/services/split-batch-order.service.js +3 -0
- package/lib/services/stock.service.js +27 -0
- package/lib/services/transfer-customer-order.service.js +3 -0
- package/lib/services/transfer-order.service.js +3 -0
- package/lib/services/transfer-vendor-order.service.js +3 -0
- package/lib/services/unit.service.js +3 -0
- package/lib/services/warehouse-map.service.d.ts +11 -1
- package/lib/services/warehouse-map.service.js +13 -4
- package/lib/typings/find-stock.input.d.ts +16 -0
- package/package.json +5 -5
|
@@ -0,0 +1,175 @@
|
|
|
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
|
+
// ── Batch attributes, snapshotted when counting starts ─────────────────── //
|
|
49
|
+
//
|
|
50
|
+
// The count sheet shows whether each position was awaiting inspection, held or
|
|
51
|
+
// in transfer, and which vendor / customer / sale order it belonged to. All of
|
|
52
|
+
// those live on the batch, which keeps moving after the count is settled — so
|
|
53
|
+
// they are copied here rather than resolved live. A count completed in June has
|
|
54
|
+
// to keep showing what June looked like, otherwise the sheet stops being an
|
|
55
|
+
// audit record of what was found.
|
|
56
|
+
//
|
|
57
|
+
// Filled by `start()` for scoped lines and by `addItem()` for additions;
|
|
58
|
+
// `null` before counting has started.
|
|
59
|
+
held;
|
|
60
|
+
inShipment;
|
|
61
|
+
/** `null` = 待檢驗, `false` = 檢驗失敗, `true` = passed. */
|
|
62
|
+
inspectionResult;
|
|
63
|
+
transferId;
|
|
64
|
+
vendorId;
|
|
65
|
+
customerId;
|
|
66
|
+
saleId;
|
|
67
|
+
saleSerialId;
|
|
68
|
+
location;
|
|
69
|
+
loader;
|
|
70
|
+
order;
|
|
71
|
+
changes;
|
|
72
|
+
};
|
|
73
|
+
__decorate([
|
|
74
|
+
PrimaryGeneratedColumn('uuid'),
|
|
75
|
+
__metadata("design:type", String)
|
|
76
|
+
], InventoryCountOrderItemEntityClass.prototype, "id", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
Column({ type: 'uuid' }),
|
|
79
|
+
Index(),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], InventoryCountOrderItemEntityClass.prototype, "orderId", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
Column({ type: 'uuid' }),
|
|
84
|
+
Index(),
|
|
85
|
+
__metadata("design:type", String)
|
|
86
|
+
], InventoryCountOrderItemEntityClass.prototype, "materialId", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
Column({ type: 'uuid' }),
|
|
89
|
+
Index(),
|
|
90
|
+
__metadata("design:type", String)
|
|
91
|
+
], InventoryCountOrderItemEntityClass.prototype, "batchId", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
Column({ type: 'uuid', nullable: true }),
|
|
94
|
+
Index(),
|
|
95
|
+
__metadata("design:type", Object)
|
|
96
|
+
], InventoryCountOrderItemEntityClass.prototype, "locationId", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
Column({ type: 'uuid', nullable: true }),
|
|
99
|
+
Index(),
|
|
100
|
+
__metadata("design:type", Object)
|
|
101
|
+
], InventoryCountOrderItemEntityClass.prototype, "loaderId", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
Column({ type: 'uuid', nullable: true }),
|
|
104
|
+
Index(),
|
|
105
|
+
__metadata("design:type", Object)
|
|
106
|
+
], InventoryCountOrderItemEntityClass.prototype, "unitId", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
Column({ type: 'numeric', default: 0 }),
|
|
109
|
+
__metadata("design:type", Number)
|
|
110
|
+
], InventoryCountOrderItemEntityClass.prototype, "bookQuantity", void 0);
|
|
111
|
+
__decorate([
|
|
112
|
+
Column({ type: 'numeric', nullable: true }),
|
|
113
|
+
__metadata("design:type", Object)
|
|
114
|
+
], InventoryCountOrderItemEntityClass.prototype, "countedQuantity", void 0);
|
|
115
|
+
__decorate([
|
|
116
|
+
Column({ type: 'boolean', default: false }),
|
|
117
|
+
__metadata("design:type", Boolean)
|
|
118
|
+
], InventoryCountOrderItemEntityClass.prototype, "isAddition", void 0);
|
|
119
|
+
__decorate([
|
|
120
|
+
Column({ type: 'boolean', nullable: true }),
|
|
121
|
+
__metadata("design:type", Object)
|
|
122
|
+
], InventoryCountOrderItemEntityClass.prototype, "held", void 0);
|
|
123
|
+
__decorate([
|
|
124
|
+
Column({ type: 'boolean', nullable: true }),
|
|
125
|
+
__metadata("design:type", Object)
|
|
126
|
+
], InventoryCountOrderItemEntityClass.prototype, "inShipment", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
Column({ type: 'boolean', nullable: true }),
|
|
129
|
+
__metadata("design:type", Object)
|
|
130
|
+
], InventoryCountOrderItemEntityClass.prototype, "inspectionResult", void 0);
|
|
131
|
+
__decorate([
|
|
132
|
+
Column({ type: 'uuid', nullable: true }),
|
|
133
|
+
__metadata("design:type", Object)
|
|
134
|
+
], InventoryCountOrderItemEntityClass.prototype, "transferId", void 0);
|
|
135
|
+
__decorate([
|
|
136
|
+
Column({ type: 'varchar', nullable: true }),
|
|
137
|
+
__metadata("design:type", Object)
|
|
138
|
+
], InventoryCountOrderItemEntityClass.prototype, "vendorId", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
Column({ type: 'varchar', nullable: true }),
|
|
141
|
+
__metadata("design:type", Object)
|
|
142
|
+
], InventoryCountOrderItemEntityClass.prototype, "customerId", void 0);
|
|
143
|
+
__decorate([
|
|
144
|
+
Column({ type: 'varchar', nullable: true }),
|
|
145
|
+
__metadata("design:type", Object)
|
|
146
|
+
], InventoryCountOrderItemEntityClass.prototype, "saleId", void 0);
|
|
147
|
+
__decorate([
|
|
148
|
+
Column({ type: 'varchar', nullable: true }),
|
|
149
|
+
__metadata("design:type", Object)
|
|
150
|
+
], InventoryCountOrderItemEntityClass.prototype, "saleSerialId", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
ManyToOne('locations'),
|
|
153
|
+
JoinColumn({ name: 'locationId', referencedColumnName: 'id' }),
|
|
154
|
+
__metadata("design:type", LocationEntityClass)
|
|
155
|
+
], InventoryCountOrderItemEntityClass.prototype, "location", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
ManyToOne('loaders'),
|
|
158
|
+
JoinColumn({ name: 'loaderId', referencedColumnName: 'id' }),
|
|
159
|
+
__metadata("design:type", LoadersEntityClass)
|
|
160
|
+
], InventoryCountOrderItemEntityClass.prototype, "loader", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
ManyToOne('inventory_count_orders', (order) => order.items),
|
|
163
|
+
JoinColumn({ name: 'orderId', referencedColumnName: 'id' }),
|
|
164
|
+
__metadata("design:type", InventoryCountOrderEntityClass)
|
|
165
|
+
], InventoryCountOrderItemEntityClass.prototype, "order", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
OneToMany('inventory_count_order_changes', (change) => change.item),
|
|
168
|
+
__metadata("design:type", Array)
|
|
169
|
+
], InventoryCountOrderItemEntityClass.prototype, "changes", void 0);
|
|
170
|
+
InventoryCountOrderItemEntityClass = __decorate([
|
|
171
|
+
Entity('inventory_count_order_items'),
|
|
172
|
+
TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
|
|
173
|
+
], InventoryCountOrderItemEntityClass);
|
|
174
|
+
|
|
175
|
+
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';
|
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,174 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* Filters for the count sheet. All optional; combined with AND.
|
|
21
|
+
*
|
|
22
|
+
* The key filters match on the related entity's human-readable key rather than
|
|
23
|
+
* its id, because that is what the operator types and what the sheet shows.
|
|
24
|
+
* The vendor / customer / sale filters read the line's own snapshot columns, so
|
|
25
|
+
* they keep matching what the sheet displays even after the batch has moved on.
|
|
26
|
+
*/
|
|
27
|
+
export interface FindInventoryCountOrderItemInput {
|
|
28
|
+
readonly materialKey?: string | null;
|
|
29
|
+
readonly materialDescription?: string | null;
|
|
30
|
+
readonly batchKey?: string | null;
|
|
31
|
+
readonly locationKey?: string | null;
|
|
32
|
+
readonly loaderSerialId?: string | null;
|
|
33
|
+
readonly vendorId?: string | null;
|
|
34
|
+
readonly customerId?: string | null;
|
|
35
|
+
readonly saleId?: string | null;
|
|
36
|
+
readonly saleSerialId?: string | null;
|
|
37
|
+
/** Only lines whose counted quantity differs from the books (顯示盤差項目). */
|
|
38
|
+
readonly onlyVariance?: boolean | null;
|
|
39
|
+
readonly offset?: number;
|
|
40
|
+
readonly limit?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface CreateInventoryCountOrderInput {
|
|
43
|
+
readonly name: string;
|
|
44
|
+
/** The base date the settlement is reported under. `YYYY-MM-DD`. */
|
|
45
|
+
readonly countDate: string;
|
|
46
|
+
/** Root locations; every descendant is pulled into the scope. */
|
|
47
|
+
readonly locationIds: readonly string[];
|
|
48
|
+
readonly createdBy?: string | null;
|
|
49
|
+
}
|
|
50
|
+
export interface UpdateInventoryCountOrderInput {
|
|
51
|
+
readonly name?: string;
|
|
52
|
+
readonly countDate?: string;
|
|
53
|
+
readonly locationIds?: readonly string[];
|
|
54
|
+
}
|
|
55
|
+
export interface CountInventoryItemInput {
|
|
56
|
+
readonly itemId: string;
|
|
57
|
+
/** `null` clears the entry — the line goes back to "not counted". */
|
|
58
|
+
readonly countedQuantity: number | null;
|
|
59
|
+
readonly unitId?: string | null;
|
|
60
|
+
}
|
|
61
|
+
export interface AddInventoryCountItemInput {
|
|
62
|
+
readonly materialId: string;
|
|
63
|
+
/** An existing batch key, or a new one — the batch is created on demand. */
|
|
64
|
+
readonly batchKey: string;
|
|
65
|
+
readonly locationId: string;
|
|
66
|
+
readonly loaderId?: string | null;
|
|
67
|
+
readonly countedQuantity: number;
|
|
68
|
+
readonly unitId?: string | null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Inventory counting: compare the ledger against what is physically there, then
|
|
72
|
+
* adjust the ledger to match.
|
|
73
|
+
*
|
|
74
|
+
* The shape follows the "D. 盤點" design flow. Three properties are worth
|
|
75
|
+
* stating up front because everything else follows from them:
|
|
76
|
+
*
|
|
77
|
+
* - **Counting never moves stock between locations.** A line that is in the
|
|
78
|
+
* wrong place is a transfer, not a count; `transfer-order:create` already does
|
|
79
|
+
* that. This service only ever adjusts quantity, up or down, in place.
|
|
80
|
+
* - **Nothing touches stock until settlement.** Counted quantities are working
|
|
81
|
+
* notes ("暫存的對帳資料"); only {@link settle} writes changes, and it does so
|
|
82
|
+
* in a single transaction.
|
|
83
|
+
* - **Starting a count locks its locations.** The book snapshot taken at
|
|
84
|
+
* {@link start} would be worthless if stock kept moving underneath it, so
|
|
85
|
+
* `InventoryCountLockSubscriber` refuses every other stock movement in the
|
|
86
|
+
* scope until the order settles or is cancelled.
|
|
87
|
+
*/
|
|
88
|
+
export declare class InventoryCountOrderService<T extends InventoryCountOrderEntityClass = InventoryCountOrderEntityClass> {
|
|
89
|
+
private readonly dataSource;
|
|
90
|
+
private readonly entities;
|
|
91
|
+
private readonly helperService;
|
|
92
|
+
private readonly materialService;
|
|
93
|
+
private readonly stockService;
|
|
94
|
+
private readonly batchService;
|
|
95
|
+
readonly inventoryCountOrderEntity: EntityTarget<T>;
|
|
96
|
+
private readonly seqPrefix;
|
|
97
|
+
constructor(dataSource: DataSource, entities: WmsEntities, helperService: HelperService, materialService: MaterialService, stockService: StockService, batchService: BatchService, inventoryCountOrderEntity: EntityTarget<T>);
|
|
98
|
+
private getRepositories;
|
|
99
|
+
/**
|
|
100
|
+
* Expand chosen locations into themselves plus every descendant.
|
|
101
|
+
*
|
|
102
|
+
* `LocationEntity` is a plain adjacency list (`parent` / `children`) with no
|
|
103
|
+
* materialised path, so the subtree needs a recursive CTE. It runs once per
|
|
104
|
+
* scope change and the result is stored, precisely so the lock check never has
|
|
105
|
+
* to run it.
|
|
106
|
+
*/
|
|
107
|
+
private expandLocationScope;
|
|
108
|
+
/** Current ledger quantity per physical position inside the scope. */
|
|
109
|
+
private readPositions;
|
|
110
|
+
private positionKey;
|
|
111
|
+
private scopedLocationIds;
|
|
112
|
+
private loadOrderOrFail;
|
|
113
|
+
private assertStatus;
|
|
114
|
+
/**
|
|
115
|
+
* Rebuild the sheet from the current ledger.
|
|
116
|
+
*
|
|
117
|
+
* Called when the scope changes and again when counting starts. Additions
|
|
118
|
+
* (盤盈 lines) are never touched — they describe stock the ledger does not know
|
|
119
|
+
* about, so a rebuild has nothing to say about them.
|
|
120
|
+
*/
|
|
121
|
+
private rebuildItems;
|
|
122
|
+
/** Filters for the list page. All optional; combined with AND. */
|
|
123
|
+
findMany(options: FindInventoryCountOrderInput, manager?: EntityManager): Promise<[InventoryCountOrderEntityClass[], number]>;
|
|
124
|
+
findOne(id: string, manager?: EntityManager): Promise<InventoryCountOrderEntityClass>;
|
|
125
|
+
/**
|
|
126
|
+
* The count sheet, filtered and paginated.
|
|
127
|
+
*
|
|
128
|
+
* Server-side rather than handing the whole sheet to the client: a count over
|
|
129
|
+
* a whole warehouse is thousands of lines, and the operator's job is to narrow
|
|
130
|
+
* to the shelf in front of them.
|
|
131
|
+
*/
|
|
132
|
+
findItems(orderId: string, options?: FindInventoryCountOrderItemInput, manager?: EntityManager): Promise<[InventoryCountOrderItemEntityClass[], number]>;
|
|
133
|
+
create(input: CreateInventoryCountOrderInput, manager?: EntityManager): Promise<T>;
|
|
134
|
+
update(id: string, input: UpdateInventoryCountOrderInput, manager?: EntityManager): Promise<T>;
|
|
135
|
+
/**
|
|
136
|
+
* Freeze the ledger and open the sheet for counting.
|
|
137
|
+
*
|
|
138
|
+
* The rebuild here is the snapshot: from this point `bookQuantity` is what the
|
|
139
|
+
* variance is measured against, and the lock keeps it true.
|
|
140
|
+
*/
|
|
141
|
+
start(id: string, manager?: EntityManager): Promise<T>;
|
|
142
|
+
/** Save counted quantities without touching stock ("暫存結果"). */
|
|
143
|
+
count(id: string, entries: readonly CountInventoryItemInput[], manager?: EntityManager): Promise<T>;
|
|
144
|
+
/**
|
|
145
|
+
* Add a line for stock the ledger has no record of (盤盈).
|
|
146
|
+
*
|
|
147
|
+
* The batch is resolved by key and created when it does not exist, which is
|
|
148
|
+
* what makes "the batch field's default is editable" in the design work.
|
|
149
|
+
*/
|
|
150
|
+
addItem(id: string, input: AddInventoryCountItemInput, manager?: EntityManager): Promise<InventoryCountOrderItemEntityClass>;
|
|
151
|
+
/** Remove an added line. Scoped lines are part of the sheet and never removed. */
|
|
152
|
+
removeItem(id: string, itemId: string, manager?: EntityManager): Promise<T>;
|
|
153
|
+
/**
|
|
154
|
+
* Throw the counting away and start over, without leaving the count.
|
|
155
|
+
*
|
|
156
|
+
* The scope stays locked and the status stays `COUNTING`: the point is a
|
|
157
|
+
* re-measure after something went wrong on the floor, not an abandonment. The
|
|
158
|
+
* book snapshot is deliberately *not* retaken — the lock means it has not
|
|
159
|
+
* moved.
|
|
160
|
+
*/
|
|
161
|
+
reset(id: string, manager?: EntityManager): Promise<T>;
|
|
162
|
+
cancel(id: string, manager?: EntityManager): Promise<T>;
|
|
163
|
+
/**
|
|
164
|
+
* Adjust the ledger to the counted reality ("執行盤差").
|
|
165
|
+
*
|
|
166
|
+
* Runs in one transaction and is awaited end to end, so the mutation
|
|
167
|
+
* interceptor's post-commit guarantee holds: every `stock.count-gained` /
|
|
168
|
+
* `stock.count-lost` event fires only after the adjustments are durable.
|
|
169
|
+
*
|
|
170
|
+
* Uncounted lines are left alone — "not counted" is not "counted as zero", and
|
|
171
|
+
* treating it as zero would wipe out stock nobody looked at.
|
|
172
|
+
*/
|
|
173
|
+
settle(id: string, outerManager?: EntityManager): Promise<T>;
|
|
174
|
+
}
|