@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
package/index.cjs.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
4
|
var common = require('@nestjs/common');
|
|
5
5
|
var wmsBaseNestjsModule = require('@rytass/wms-base-nestjs-module');
|
|
6
|
+
var warehouseMap_entity = require('@rytass/wms-base-nestjs-module/models/warehouse-map.entity');
|
|
6
7
|
var typeorm$1 = require('@nestjs/typeorm');
|
|
7
8
|
var node_async_hooks = require('node:async_hooks');
|
|
8
|
-
var warehouseMap_entity = require('@rytass/wms-base-nestjs-module/models/warehouse-map.entity');
|
|
9
9
|
var typeorm = require('typeorm');
|
|
10
10
|
var luxon = require('luxon');
|
|
11
11
|
|
|
@@ -387,6 +387,8 @@ exports.MaterialUnitEntityClass = tslib.__decorate([
|
|
|
387
387
|
typeorm.TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
|
|
388
388
|
], exports.MaterialUnitEntityClass);
|
|
389
389
|
|
|
390
|
+
const OrderEntity = Symbol('OrderEntity');
|
|
391
|
+
|
|
390
392
|
const SaleOrderEntity = Symbol('SaleOrderEntity');
|
|
391
393
|
exports.SaleOrderEntityClass = class SaleOrderEntityClass {
|
|
392
394
|
id;
|
|
@@ -450,6 +452,10 @@ exports.ChangeType = void 0;
|
|
|
450
452
|
ChangeType["DEALLOCATED"] = "DEALLOCATED";
|
|
451
453
|
// reclassify-inventory-order-change.entity.ts
|
|
452
454
|
ChangeType["RECLASSIFIED"] = "RECLASSIFIED";
|
|
455
|
+
// inventory-count-order-change.entity.ts, change > 0
|
|
456
|
+
ChangeType["COUNT_GAINED"] = "COUNT_GAINED";
|
|
457
|
+
// inventory-count-order-change.entity.ts, change < 0
|
|
458
|
+
ChangeType["COUNT_LOST"] = "COUNT_LOST";
|
|
453
459
|
// scrape-order-change.entity.ts
|
|
454
460
|
ChangeType["SCRAPED"] = "SCRAPED";
|
|
455
461
|
})(exports.ChangeType || (exports.ChangeType = {}));
|
|
@@ -2341,6 +2347,315 @@ exports.ScrapeOrderChangeEntityClass = tslib.__decorate([
|
|
|
2341
2347
|
typeorm.Entity('scrape_order_changes')
|
|
2342
2348
|
], exports.ScrapeOrderChangeEntityClass);
|
|
2343
2349
|
|
|
2350
|
+
/**
|
|
2351
|
+
* The lifecycle of an inventory count order, matching the four states the
|
|
2352
|
+
* design shows on the list page.
|
|
2353
|
+
*
|
|
2354
|
+
* Only `COUNTING` accepts counted quantities, and only `COUNTING` locks the
|
|
2355
|
+
* scoped locations; `COMPLETED` is reached exclusively by settling the variance,
|
|
2356
|
+
* so an order that was counted but never settled stays `COUNTING` for as long as
|
|
2357
|
+
* it takes.
|
|
2358
|
+
*/
|
|
2359
|
+
exports.InventoryCountStatus = void 0;
|
|
2360
|
+
(function (InventoryCountStatus) {
|
|
2361
|
+
/** 尚未執行 — created, scope fixed, nothing counted, nothing locked. */
|
|
2362
|
+
InventoryCountStatus["PENDING"] = "PENDING";
|
|
2363
|
+
/** 盤點中 — book quantities snapshotted and the scoped locations locked. */
|
|
2364
|
+
InventoryCountStatus["COUNTING"] = "COUNTING";
|
|
2365
|
+
/** 已完成 — the variance was settled and stock adjusted. */
|
|
2366
|
+
InventoryCountStatus["COMPLETED"] = "COMPLETED";
|
|
2367
|
+
/** 已取消 — abandoned from either PENDING or COUNTING; nothing adjusted. */
|
|
2368
|
+
InventoryCountStatus["CANCELLED"] = "CANCELLED";
|
|
2369
|
+
})(exports.InventoryCountStatus || (exports.InventoryCountStatus = {}));
|
|
2370
|
+
|
|
2371
|
+
const InventoryCountOrderEntity = Symbol('InventoryCountOrderEntity');
|
|
2372
|
+
exports.InventoryCountOrderEntityClass = class InventoryCountOrderEntityClass {
|
|
2373
|
+
id;
|
|
2374
|
+
key;
|
|
2375
|
+
name;
|
|
2376
|
+
/**
|
|
2377
|
+
* The count's base date, chosen when the order is created.
|
|
2378
|
+
*
|
|
2379
|
+
* It is the *business* date of the whole exercise: the settlement's stock
|
|
2380
|
+
* adjustments are reported under this date, not under the day someone happened
|
|
2381
|
+
* to press "執行盤差". `createdAt` keeps the real wall-clock time for auditing,
|
|
2382
|
+
* so the two never have to lie for each other.
|
|
2383
|
+
*/
|
|
2384
|
+
countDate;
|
|
2385
|
+
status;
|
|
2386
|
+
/** Who created the order, in whatever id space the host uses. */
|
|
2387
|
+
createdBy;
|
|
2388
|
+
/** When counting started — the moment `bookQuantity` was snapshotted. */
|
|
2389
|
+
startedAt;
|
|
2390
|
+
/** When the variance was settled. */
|
|
2391
|
+
settledAt;
|
|
2392
|
+
cancelledAt;
|
|
2393
|
+
createdAt;
|
|
2394
|
+
items;
|
|
2395
|
+
locations;
|
|
2396
|
+
};
|
|
2397
|
+
tslib.__decorate([
|
|
2398
|
+
typeorm.PrimaryGeneratedColumn('uuid'),
|
|
2399
|
+
tslib.__metadata("design:type", String)
|
|
2400
|
+
], exports.InventoryCountOrderEntityClass.prototype, "id", void 0);
|
|
2401
|
+
tslib.__decorate([
|
|
2402
|
+
typeorm.Column({ type: 'varchar', unique: true }),
|
|
2403
|
+
typeorm.Index(),
|
|
2404
|
+
tslib.__metadata("design:type", String)
|
|
2405
|
+
], exports.InventoryCountOrderEntityClass.prototype, "key", void 0);
|
|
2406
|
+
tslib.__decorate([
|
|
2407
|
+
typeorm.Column({ type: 'varchar' }),
|
|
2408
|
+
tslib.__metadata("design:type", String)
|
|
2409
|
+
], exports.InventoryCountOrderEntityClass.prototype, "name", void 0);
|
|
2410
|
+
tslib.__decorate([
|
|
2411
|
+
typeorm.Column({ type: 'date' }),
|
|
2412
|
+
typeorm.Index(),
|
|
2413
|
+
tslib.__metadata("design:type", String)
|
|
2414
|
+
], exports.InventoryCountOrderEntityClass.prototype, "countDate", void 0);
|
|
2415
|
+
tslib.__decorate([
|
|
2416
|
+
typeorm.Column({
|
|
2417
|
+
type: 'enum',
|
|
2418
|
+
enum: exports.InventoryCountStatus,
|
|
2419
|
+
default: exports.InventoryCountStatus.PENDING,
|
|
2420
|
+
}),
|
|
2421
|
+
typeorm.Index(),
|
|
2422
|
+
tslib.__metadata("design:type", String)
|
|
2423
|
+
], exports.InventoryCountOrderEntityClass.prototype, "status", void 0);
|
|
2424
|
+
tslib.__decorate([
|
|
2425
|
+
typeorm.Column({ type: 'varchar', nullable: true }),
|
|
2426
|
+
tslib.__metadata("design:type", Object)
|
|
2427
|
+
], exports.InventoryCountOrderEntityClass.prototype, "createdBy", void 0);
|
|
2428
|
+
tslib.__decorate([
|
|
2429
|
+
typeorm.Column({ type: 'timestamptz', nullable: true }),
|
|
2430
|
+
tslib.__metadata("design:type", Object)
|
|
2431
|
+
], exports.InventoryCountOrderEntityClass.prototype, "startedAt", void 0);
|
|
2432
|
+
tslib.__decorate([
|
|
2433
|
+
typeorm.Column({ type: 'timestamptz', nullable: true }),
|
|
2434
|
+
tslib.__metadata("design:type", Object)
|
|
2435
|
+
], exports.InventoryCountOrderEntityClass.prototype, "settledAt", void 0);
|
|
2436
|
+
tslib.__decorate([
|
|
2437
|
+
typeorm.Column({ type: 'timestamptz', nullable: true }),
|
|
2438
|
+
tslib.__metadata("design:type", Object)
|
|
2439
|
+
], exports.InventoryCountOrderEntityClass.prototype, "cancelledAt", void 0);
|
|
2440
|
+
tslib.__decorate([
|
|
2441
|
+
typeorm.CreateDateColumn({ type: 'timestamptz' }),
|
|
2442
|
+
tslib.__metadata("design:type", Date)
|
|
2443
|
+
], exports.InventoryCountOrderEntityClass.prototype, "createdAt", void 0);
|
|
2444
|
+
tslib.__decorate([
|
|
2445
|
+
typeorm.OneToMany('inventory_count_order_items', (item) => item.order),
|
|
2446
|
+
tslib.__metadata("design:type", Array)
|
|
2447
|
+
], exports.InventoryCountOrderEntityClass.prototype, "items", void 0);
|
|
2448
|
+
tslib.__decorate([
|
|
2449
|
+
typeorm.OneToMany('inventory_count_order_locations', (scope) => scope.order),
|
|
2450
|
+
tslib.__metadata("design:type", Array)
|
|
2451
|
+
], exports.InventoryCountOrderEntityClass.prototype, "locations", void 0);
|
|
2452
|
+
exports.InventoryCountOrderEntityClass = tslib.__decorate([
|
|
2453
|
+
typeorm.Entity('inventory_count_orders'),
|
|
2454
|
+
typeorm.TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
|
|
2455
|
+
], exports.InventoryCountOrderEntityClass);
|
|
2456
|
+
const InventoryCountOrderLocationEntity = Symbol('InventoryCountOrderLocationEntity');
|
|
2457
|
+
/**
|
|
2458
|
+
* One row per location in the order's scope, **already expanded** to include
|
|
2459
|
+
* every descendant of the locations the user picked.
|
|
2460
|
+
*
|
|
2461
|
+
* The scope is materialised at creation instead of being recomputed from the
|
|
2462
|
+
* chosen roots because it is read on the hot path: while an order is counting,
|
|
2463
|
+
* every single stock movement in the system has to ask "is this location
|
|
2464
|
+
* locked?". `LocationEntity` is a plain `parent`/`children` adjacency list with
|
|
2465
|
+
* no materialised path, so answering that from the tree would mean a recursive
|
|
2466
|
+
* CTE per movement.
|
|
2467
|
+
*/
|
|
2468
|
+
exports.InventoryCountOrderLocationEntityClass = class InventoryCountOrderLocationEntityClass {
|
|
2469
|
+
id;
|
|
2470
|
+
orderId;
|
|
2471
|
+
locationId;
|
|
2472
|
+
/** `true` for the locations the user picked, `false` for descendants. */
|
|
2473
|
+
isRoot;
|
|
2474
|
+
order;
|
|
2475
|
+
location;
|
|
2476
|
+
};
|
|
2477
|
+
tslib.__decorate([
|
|
2478
|
+
typeorm.PrimaryGeneratedColumn('uuid'),
|
|
2479
|
+
tslib.__metadata("design:type", String)
|
|
2480
|
+
], exports.InventoryCountOrderLocationEntityClass.prototype, "id", void 0);
|
|
2481
|
+
tslib.__decorate([
|
|
2482
|
+
typeorm.Column({ type: 'uuid' }),
|
|
2483
|
+
typeorm.Index(),
|
|
2484
|
+
tslib.__metadata("design:type", String)
|
|
2485
|
+
], exports.InventoryCountOrderLocationEntityClass.prototype, "orderId", void 0);
|
|
2486
|
+
tslib.__decorate([
|
|
2487
|
+
typeorm.Column({ type: 'uuid' }),
|
|
2488
|
+
typeorm.Index(),
|
|
2489
|
+
tslib.__metadata("design:type", String)
|
|
2490
|
+
], exports.InventoryCountOrderLocationEntityClass.prototype, "locationId", void 0);
|
|
2491
|
+
tslib.__decorate([
|
|
2492
|
+
typeorm.Column({ type: 'boolean', default: false }),
|
|
2493
|
+
tslib.__metadata("design:type", Boolean)
|
|
2494
|
+
], exports.InventoryCountOrderLocationEntityClass.prototype, "isRoot", void 0);
|
|
2495
|
+
tslib.__decorate([
|
|
2496
|
+
typeorm.ManyToOne('inventory_count_orders', (order) => order.locations),
|
|
2497
|
+
typeorm.JoinColumn({ name: 'orderId', referencedColumnName: 'id' }),
|
|
2498
|
+
tslib.__metadata("design:type", exports.InventoryCountOrderEntityClass)
|
|
2499
|
+
], exports.InventoryCountOrderLocationEntityClass.prototype, "order", void 0);
|
|
2500
|
+
tslib.__decorate([
|
|
2501
|
+
typeorm.ManyToOne('locations'),
|
|
2502
|
+
typeorm.JoinColumn({ name: 'locationId', referencedColumnName: 'id' }),
|
|
2503
|
+
tslib.__metadata("design:type", exports.LocationEntityClass)
|
|
2504
|
+
], exports.InventoryCountOrderLocationEntityClass.prototype, "location", void 0);
|
|
2505
|
+
exports.InventoryCountOrderLocationEntityClass = tslib.__decorate([
|
|
2506
|
+
typeorm.Entity('inventory_count_order_locations')
|
|
2507
|
+
], exports.InventoryCountOrderLocationEntityClass);
|
|
2508
|
+
|
|
2509
|
+
const InventoryCountOrderItemEntity = Symbol('InventoryCountOrderItemEntity');
|
|
2510
|
+
/**
|
|
2511
|
+
* One line of the count sheet.
|
|
2512
|
+
*
|
|
2513
|
+
* Two flavours share the table, told apart by {@link isAddition}:
|
|
2514
|
+
*
|
|
2515
|
+
* - a **scoped line**, expanded from the order's locations when the order is
|
|
2516
|
+
* created. `bookQuantity` is the snapshot taken at "開始盤點".
|
|
2517
|
+
* - an **addition** (盤盈), added by hand during counting for stock the books do
|
|
2518
|
+
* not know about at all. `bookQuantity` is `0` by definition, and it is the
|
|
2519
|
+
* only flavour a user may delete.
|
|
2520
|
+
*/
|
|
2521
|
+
exports.InventoryCountOrderItemEntityClass = class InventoryCountOrderItemEntityClass {
|
|
2522
|
+
id;
|
|
2523
|
+
orderId;
|
|
2524
|
+
materialId;
|
|
2525
|
+
batchId;
|
|
2526
|
+
locationId;
|
|
2527
|
+
loaderId;
|
|
2528
|
+
/**
|
|
2529
|
+
* The unit the counted quantity is expressed in; `null` means the material's
|
|
2530
|
+
* base unit. Settlement converts through the material's conversion factor
|
|
2531
|
+
* before comparing with {@link bookQuantity}, which is always in base units.
|
|
2532
|
+
*/
|
|
2533
|
+
unitId;
|
|
2534
|
+
/** Ledger quantity in base units, frozen when counting started. */
|
|
2535
|
+
bookQuantity;
|
|
2536
|
+
/** What was actually found, in {@link unitId}. `null` until someone counts. */
|
|
2537
|
+
countedQuantity;
|
|
2538
|
+
/** `true` for a line added during counting for unbooked stock (盤盈). */
|
|
2539
|
+
isAddition;
|
|
2540
|
+
location;
|
|
2541
|
+
loader;
|
|
2542
|
+
order;
|
|
2543
|
+
changes;
|
|
2544
|
+
};
|
|
2545
|
+
tslib.__decorate([
|
|
2546
|
+
typeorm.PrimaryGeneratedColumn('uuid'),
|
|
2547
|
+
tslib.__metadata("design:type", String)
|
|
2548
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "id", void 0);
|
|
2549
|
+
tslib.__decorate([
|
|
2550
|
+
typeorm.Column({ type: 'uuid' }),
|
|
2551
|
+
typeorm.Index(),
|
|
2552
|
+
tslib.__metadata("design:type", String)
|
|
2553
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "orderId", void 0);
|
|
2554
|
+
tslib.__decorate([
|
|
2555
|
+
typeorm.Column({ type: 'uuid' }),
|
|
2556
|
+
typeorm.Index(),
|
|
2557
|
+
tslib.__metadata("design:type", String)
|
|
2558
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "materialId", void 0);
|
|
2559
|
+
tslib.__decorate([
|
|
2560
|
+
typeorm.Column({ type: 'uuid' }),
|
|
2561
|
+
typeorm.Index(),
|
|
2562
|
+
tslib.__metadata("design:type", String)
|
|
2563
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "batchId", void 0);
|
|
2564
|
+
tslib.__decorate([
|
|
2565
|
+
typeorm.Column({ type: 'uuid', nullable: true }),
|
|
2566
|
+
typeorm.Index(),
|
|
2567
|
+
tslib.__metadata("design:type", Object)
|
|
2568
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "locationId", void 0);
|
|
2569
|
+
tslib.__decorate([
|
|
2570
|
+
typeorm.Column({ type: 'uuid', nullable: true }),
|
|
2571
|
+
typeorm.Index(),
|
|
2572
|
+
tslib.__metadata("design:type", Object)
|
|
2573
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "loaderId", void 0);
|
|
2574
|
+
tslib.__decorate([
|
|
2575
|
+
typeorm.Column({ type: 'uuid', nullable: true }),
|
|
2576
|
+
typeorm.Index(),
|
|
2577
|
+
tslib.__metadata("design:type", Object)
|
|
2578
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "unitId", void 0);
|
|
2579
|
+
tslib.__decorate([
|
|
2580
|
+
typeorm.Column({ type: 'numeric', default: 0 }),
|
|
2581
|
+
tslib.__metadata("design:type", Number)
|
|
2582
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "bookQuantity", void 0);
|
|
2583
|
+
tslib.__decorate([
|
|
2584
|
+
typeorm.Column({ type: 'numeric', nullable: true }),
|
|
2585
|
+
tslib.__metadata("design:type", Object)
|
|
2586
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "countedQuantity", void 0);
|
|
2587
|
+
tslib.__decorate([
|
|
2588
|
+
typeorm.Column({ type: 'boolean', default: false }),
|
|
2589
|
+
tslib.__metadata("design:type", Boolean)
|
|
2590
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "isAddition", void 0);
|
|
2591
|
+
tslib.__decorate([
|
|
2592
|
+
typeorm.ManyToOne('locations'),
|
|
2593
|
+
typeorm.JoinColumn({ name: 'locationId', referencedColumnName: 'id' }),
|
|
2594
|
+
tslib.__metadata("design:type", exports.LocationEntityClass)
|
|
2595
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "location", void 0);
|
|
2596
|
+
tslib.__decorate([
|
|
2597
|
+
typeorm.ManyToOne('loaders'),
|
|
2598
|
+
typeorm.JoinColumn({ name: 'loaderId', referencedColumnName: 'id' }),
|
|
2599
|
+
tslib.__metadata("design:type", exports.LoadersEntityClass)
|
|
2600
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "loader", void 0);
|
|
2601
|
+
tslib.__decorate([
|
|
2602
|
+
typeorm.ManyToOne('inventory_count_orders', (order) => order.items),
|
|
2603
|
+
typeorm.JoinColumn({ name: 'orderId', referencedColumnName: 'id' }),
|
|
2604
|
+
tslib.__metadata("design:type", exports.InventoryCountOrderEntityClass)
|
|
2605
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "order", void 0);
|
|
2606
|
+
tslib.__decorate([
|
|
2607
|
+
typeorm.OneToMany('inventory_count_order_changes', (change) => change.item),
|
|
2608
|
+
tslib.__metadata("design:type", Array)
|
|
2609
|
+
], exports.InventoryCountOrderItemEntityClass.prototype, "changes", void 0);
|
|
2610
|
+
exports.InventoryCountOrderItemEntityClass = tslib.__decorate([
|
|
2611
|
+
typeorm.Entity('inventory_count_order_items'),
|
|
2612
|
+
typeorm.TableInheritance({ column: { type: 'varchar', name: 'entityName' } })
|
|
2613
|
+
], exports.InventoryCountOrderItemEntityClass);
|
|
2614
|
+
|
|
2615
|
+
const InventoryCountOrderChangeEntity = Symbol('InventoryCountOrderChangeEntity');
|
|
2616
|
+
/**
|
|
2617
|
+
* The stock movement a settled count line produced.
|
|
2618
|
+
*
|
|
2619
|
+
* `quantityChanged` carries the sign, exactly like every other `*_order_change`
|
|
2620
|
+
* table: positive is a surplus (盤盈), negative a shortage (盤虧).
|
|
2621
|
+
* `StockChangeSubscriber` reads the sign to pick between `stock.count-gained`
|
|
2622
|
+
* and `stock.count-lost`, so nothing here has to emit events itself.
|
|
2623
|
+
*
|
|
2624
|
+
* Lines whose count matched the books produce no row at all.
|
|
2625
|
+
*/
|
|
2626
|
+
exports.InventoryCountOrderChangeEntityClass = class InventoryCountOrderChangeEntityClass {
|
|
2627
|
+
id;
|
|
2628
|
+
itemId;
|
|
2629
|
+
quantityChanged;
|
|
2630
|
+
order;
|
|
2631
|
+
item;
|
|
2632
|
+
};
|
|
2633
|
+
tslib.__decorate([
|
|
2634
|
+
typeorm.PrimaryGeneratedColumn('uuid'),
|
|
2635
|
+
tslib.__metadata("design:type", String)
|
|
2636
|
+
], exports.InventoryCountOrderChangeEntityClass.prototype, "id", void 0);
|
|
2637
|
+
tslib.__decorate([
|
|
2638
|
+
typeorm.Column({ type: 'uuid' }),
|
|
2639
|
+
tslib.__metadata("design:type", String)
|
|
2640
|
+
], exports.InventoryCountOrderChangeEntityClass.prototype, "itemId", void 0);
|
|
2641
|
+
tslib.__decorate([
|
|
2642
|
+
typeorm.Column({ type: 'numeric' }),
|
|
2643
|
+
tslib.__metadata("design:type", Number)
|
|
2644
|
+
], exports.InventoryCountOrderChangeEntityClass.prototype, "quantityChanged", void 0);
|
|
2645
|
+
tslib.__decorate([
|
|
2646
|
+
typeorm.OneToOne('orders'),
|
|
2647
|
+
typeorm.JoinColumn({ name: 'id', referencedColumnName: 'id' }),
|
|
2648
|
+
tslib.__metadata("design:type", wmsBaseNestjsModule.OrderEntity)
|
|
2649
|
+
], exports.InventoryCountOrderChangeEntityClass.prototype, "order", void 0);
|
|
2650
|
+
tslib.__decorate([
|
|
2651
|
+
typeorm.ManyToOne('inventory_count_order_items', (item) => item.changes),
|
|
2652
|
+
typeorm.JoinColumn({ name: 'itemId', referencedColumnName: 'id' }),
|
|
2653
|
+
tslib.__metadata("design:type", exports.InventoryCountOrderItemEntityClass)
|
|
2654
|
+
], exports.InventoryCountOrderChangeEntityClass.prototype, "item", void 0);
|
|
2655
|
+
exports.InventoryCountOrderChangeEntityClass = tslib.__decorate([
|
|
2656
|
+
typeorm.Entity('inventory_count_order_changes')
|
|
2657
|
+
], exports.InventoryCountOrderChangeEntityClass);
|
|
2658
|
+
|
|
2344
2659
|
const entities = [
|
|
2345
2660
|
[UnitEntity, exports.UnitEntityClass],
|
|
2346
2661
|
[MaterialEntity, exports.MaterialEntityClass],
|
|
@@ -2394,18 +2709,28 @@ const entities = [
|
|
|
2394
2709
|
[ScrapeOrderEntity, exports.ScrapeOrderEntityClass],
|
|
2395
2710
|
[ScrapeOrderItemEntity, exports.ScrapeOrderItemEntityClass],
|
|
2396
2711
|
[ScrapeOrderChangeEntity, exports.ScrapeOrderChangeEntityClass],
|
|
2712
|
+
[InventoryCountOrderEntity, exports.InventoryCountOrderEntityClass],
|
|
2713
|
+
[InventoryCountOrderLocationEntity, exports.InventoryCountOrderLocationEntityClass],
|
|
2714
|
+
[InventoryCountOrderItemEntity, exports.InventoryCountOrderItemEntityClass],
|
|
2715
|
+
[InventoryCountOrderChangeEntity, exports.InventoryCountOrderChangeEntityClass],
|
|
2397
2716
|
];
|
|
2398
2717
|
/**
|
|
2399
|
-
*
|
|
2400
|
-
*
|
|
2401
|
-
* importing `WMSBaseModule` can read. Binding
|
|
2402
|
-
* live bindings for one token, and the loser would be
|
|
2403
|
-
* injector happened to reach first.
|
|
2718
|
+
* The overridable entities are deliberately absent: `WmsModuleCoreModule` binds
|
|
2719
|
+
* each of them to whatever the matching `WMSBaseModuleOptions` entity resolved
|
|
2720
|
+
* to, which only a module importing `WMSBaseModule` can read. Binding them here
|
|
2721
|
+
* as well would leave two live bindings for one token, and the loser would be
|
|
2722
|
+
* whichever module the injector happened to reach first.
|
|
2404
2723
|
*
|
|
2405
|
-
*
|
|
2406
|
-
* root of the single-table hierarchy a consumer's override extends.
|
|
2724
|
+
* Their classes stay in `entities` above so TypeORM still registers them — each
|
|
2725
|
+
* is the root of the single-table hierarchy a consumer's override extends.
|
|
2407
2726
|
*/
|
|
2408
|
-
const EXTERNALLY_BOUND_ENTITIES = new Set([
|
|
2727
|
+
const EXTERNALLY_BOUND_ENTITIES = new Set([
|
|
2728
|
+
MaterialEntity,
|
|
2729
|
+
BatchEntity,
|
|
2730
|
+
LocationEntity,
|
|
2731
|
+
StockEntity,
|
|
2732
|
+
WarehouseMapEntity,
|
|
2733
|
+
]);
|
|
2409
2734
|
const ResolvedEntitiesProviders = entities
|
|
2410
2735
|
.filter(([token]) => !EXTERNALLY_BOUND_ENTITIES.has(token))
|
|
2411
2736
|
.map(([token, entity]) => ({
|
|
@@ -2422,8 +2747,81 @@ ModelsModule = tslib.__decorate([
|
|
|
2422
2747
|
})
|
|
2423
2748
|
], ModelsModule);
|
|
2424
2749
|
|
|
2750
|
+
/**
|
|
2751
|
+
* The entity classes this package actually reads and writes, after applying the
|
|
2752
|
+
* consumer's `WMSBaseModuleOptions` entity overrides.
|
|
2753
|
+
*
|
|
2754
|
+
* Every overridable entity is bound to a `Symbol` that `WmsModuleCoreModule`
|
|
2755
|
+
* resolves from the base module's `PROVIDE_*_ENTITY` tokens. Injecting them one
|
|
2756
|
+
* by one works, but most services and resolvers need three or four at once, so
|
|
2757
|
+
* this collects them behind a single dependency.
|
|
2758
|
+
*
|
|
2759
|
+
* Only entities the base module lets a consumer replace are here. Entities this
|
|
2760
|
+
* package owns outright — batch groups, loaders, units, every order extension —
|
|
2761
|
+
* have no override to follow and are referenced by class directly.
|
|
2762
|
+
*/
|
|
2763
|
+
exports.WmsEntities = class WmsEntities {
|
|
2764
|
+
material;
|
|
2765
|
+
batch;
|
|
2766
|
+
location;
|
|
2767
|
+
stock;
|
|
2768
|
+
order;
|
|
2769
|
+
warehouseMap;
|
|
2770
|
+
constructor(dataSource, material, batch, location, stock, order, warehouseMap) {
|
|
2771
|
+
this.material = material;
|
|
2772
|
+
this.batch = batch;
|
|
2773
|
+
this.location = location;
|
|
2774
|
+
this.stock = stock;
|
|
2775
|
+
this.order = order;
|
|
2776
|
+
this.warehouseMap = warehouseMap;
|
|
2777
|
+
this.assertRegistered(dataSource);
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2780
|
+
* Fail during instantiation if an override was never registered with TypeORM.
|
|
2781
|
+
*
|
|
2782
|
+
* The module cannot register it: `TypeOrmModule.forFeature()` runs while the
|
|
2783
|
+
* module graph is assembled, and an override is only known once the options
|
|
2784
|
+
* resolve. Registering the built-in class does bring the override's *columns*
|
|
2785
|
+
* into the table (TypeORM copies a single-table child's columns into its
|
|
2786
|
+
* parent), which makes the omission easy to miss — everything looks right
|
|
2787
|
+
* until the first query fails with a bare `EntityMetadataNotFoundError` from
|
|
2788
|
+
* somewhere deep in a resolver.
|
|
2789
|
+
*
|
|
2790
|
+
* This runs in the constructor rather than `onModuleInit` so it lands before
|
|
2791
|
+
* any service's own startup work touches the database.
|
|
2792
|
+
*/
|
|
2793
|
+
assertRegistered(dataSource) {
|
|
2794
|
+
const missing = [
|
|
2795
|
+
['materialEntity', this.material],
|
|
2796
|
+
['batchEntity', this.batch],
|
|
2797
|
+
['locationEntity', this.location],
|
|
2798
|
+
['stockEntity', this.stock],
|
|
2799
|
+
['orderEntity', this.order],
|
|
2800
|
+
['warehouseMapEntity', this.warehouseMap],
|
|
2801
|
+
].filter(([, entity]) => !dataSource.hasMetadata(entity));
|
|
2802
|
+
if (!missing.length)
|
|
2803
|
+
return;
|
|
2804
|
+
const details = missing
|
|
2805
|
+
.map(([option, entity]) => `${option}: ${entity.name}`)
|
|
2806
|
+
.join(', ');
|
|
2807
|
+
const names = missing.map(([, entity]) => entity.name).join(', ');
|
|
2808
|
+
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.`);
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
exports.WmsEntities = tslib.__decorate([
|
|
2812
|
+
common.Injectable(),
|
|
2813
|
+
tslib.__param(1, common.Inject(MaterialEntity)),
|
|
2814
|
+
tslib.__param(2, common.Inject(BatchEntity)),
|
|
2815
|
+
tslib.__param(3, common.Inject(LocationEntity)),
|
|
2816
|
+
tslib.__param(4, common.Inject(StockEntity)),
|
|
2817
|
+
tslib.__param(5, common.Inject(OrderEntity)),
|
|
2818
|
+
tslib.__param(6, common.Inject(WarehouseMapEntity)),
|
|
2819
|
+
tslib.__metadata("design:paramtypes", [typeorm.DataSource, Object, Object, Object, Object, Object, Object])
|
|
2820
|
+
], exports.WmsEntities);
|
|
2821
|
+
|
|
2425
2822
|
exports.StockService = class StockService {
|
|
2426
2823
|
dataSource;
|
|
2824
|
+
entities;
|
|
2427
2825
|
stockEntity;
|
|
2428
2826
|
materialEntity;
|
|
2429
2827
|
coreOptions;
|
|
@@ -2445,8 +2843,9 @@ exports.StockService = class StockService {
|
|
|
2445
2843
|
status: status,
|
|
2446
2844
|
};
|
|
2447
2845
|
};
|
|
2448
|
-
constructor(dataSource, stockEntity, materialEntity, coreOptions) {
|
|
2846
|
+
constructor(dataSource, entities, stockEntity, materialEntity, coreOptions) {
|
|
2449
2847
|
this.dataSource = dataSource;
|
|
2848
|
+
this.entities = entities;
|
|
2450
2849
|
this.stockEntity = stockEntity;
|
|
2451
2850
|
this.materialEntity = materialEntity;
|
|
2452
2851
|
this.coreOptions = coreOptions;
|
|
@@ -2486,7 +2885,7 @@ exports.StockService = class StockService {
|
|
|
2486
2885
|
}
|
|
2487
2886
|
async onModuleInit() {
|
|
2488
2887
|
const loaderTypeRepo = this.dataSource.getRepository(exports.LoaderTypeEntityClass);
|
|
2489
|
-
const locationRepo = this.dataSource.getRepository(
|
|
2888
|
+
const locationRepo = this.dataSource.getRepository(this.entities.location);
|
|
2490
2889
|
const loaderRepo = this.dataSource.getRepository(exports.LoadersEntityClass);
|
|
2491
2890
|
// Ensure default loader type exists
|
|
2492
2891
|
let loaderType = await loaderTypeRepo.findOneBy({
|
|
@@ -2615,11 +3014,11 @@ exports.StockService = class StockService {
|
|
|
2615
3014
|
materialKey: `%${options.materialKey}%`,
|
|
2616
3015
|
});
|
|
2617
3016
|
if (options.batchKey)
|
|
2618
|
-
queryBuilder.innerJoin(
|
|
3017
|
+
queryBuilder.innerJoin(this.entities.batch, 'bk', 'bk.id = stock."batchId" AND bk.key ILIKE :batchKey', {
|
|
2619
3018
|
batchKey: `%${options.batchKey}%`,
|
|
2620
3019
|
});
|
|
2621
3020
|
if (options.locationKey)
|
|
2622
|
-
queryBuilder.innerJoin(
|
|
3021
|
+
queryBuilder.innerJoin(this.entities.location, 'lk', 'lk.id = stock."locationId" AND lk.key ILIKE :locationKey', {
|
|
2623
3022
|
locationKey: `%${options.locationKey}%`,
|
|
2624
3023
|
});
|
|
2625
3024
|
if (options.loaderKey)
|
|
@@ -2844,10 +3243,11 @@ exports.StockService = class StockService {
|
|
|
2844
3243
|
};
|
|
2845
3244
|
exports.StockService = tslib.__decorate([
|
|
2846
3245
|
common.Injectable(),
|
|
2847
|
-
tslib.__param(
|
|
2848
|
-
tslib.__param(
|
|
2849
|
-
tslib.__param(
|
|
2850
|
-
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
3246
|
+
tslib.__param(2, common.Inject(StockEntity)),
|
|
3247
|
+
tslib.__param(3, common.Inject(MaterialEntity)),
|
|
3248
|
+
tslib.__param(4, common.Inject(WMS_CORE_MODULE_OPTIONS)),
|
|
3249
|
+
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
3250
|
+
exports.WmsEntities, Object, Function, Object])
|
|
2851
3251
|
], exports.StockService);
|
|
2852
3252
|
|
|
2853
3253
|
/**
|
|
@@ -3098,26 +3498,6 @@ exports.MaterialService = class MaterialService {
|
|
|
3098
3498
|
this.materialRepository = this.dataSource.getRepository(this.materialEntity);
|
|
3099
3499
|
this.materialUnitRepository = this.dataSource.getRepository(this.materialUnitEntity);
|
|
3100
3500
|
}
|
|
3101
|
-
/**
|
|
3102
|
-
* Fail at boot if the configured `materialEntity` was never registered with
|
|
3103
|
-
* TypeORM.
|
|
3104
|
-
*
|
|
3105
|
-
* The module cannot register it: `TypeOrmModule.forFeature()` runs while the
|
|
3106
|
-
* module graph is assembled, and the entity is only known once the options
|
|
3107
|
-
* resolve. Registering the base class does bring the override's *columns* into
|
|
3108
|
-
* the `materials` schema (TypeORM copies a single-table child's columns into
|
|
3109
|
-
* its parent), which makes the omission easy to miss — everything looks right
|
|
3110
|
-
* until the first query fails with a bare `EntityMetadataNotFoundError` from
|
|
3111
|
-
* somewhere deep in a resolver.
|
|
3112
|
-
*/
|
|
3113
|
-
onModuleInit() {
|
|
3114
|
-
if (this.dataSource.hasMetadata(this.materialEntity))
|
|
3115
|
-
return;
|
|
3116
|
-
const name = typeof this.materialEntity === 'function'
|
|
3117
|
-
? this.materialEntity.name
|
|
3118
|
-
: String(this.materialEntity);
|
|
3119
|
-
throw new Error(`WmsModuleCoreModule: the configured materialEntity "${name}" is not registered with TypeORM. Add it to your DataSource "entities", or import TypeOrmModule.forFeature([${name}]) somewhere in your app when using autoLoadEntities.`);
|
|
3120
|
-
}
|
|
3121
3501
|
async getConversionFactor(materialId, unitId) {
|
|
3122
3502
|
const materialUnitRepository = this.dataSource.getRepository(this.materialUnitEntity);
|
|
3123
3503
|
if (!unitId)
|
|
@@ -3288,7 +3668,7 @@ exports.BatchService = class BatchService {
|
|
|
3288
3668
|
}
|
|
3289
3669
|
}
|
|
3290
3670
|
async getBatch({ manager = this.dataSource.manager, ...options }) {
|
|
3291
|
-
const batchRepository = manager.getRepository(
|
|
3671
|
+
const batchRepository = manager.getRepository(this.batchEntity);
|
|
3292
3672
|
const batchGroupRepository = manager.getRepository(this.batchGroupEntity);
|
|
3293
3673
|
const unsplittedCondition = {
|
|
3294
3674
|
saleId: typeorm.IsNull(),
|
|
@@ -3318,7 +3698,7 @@ exports.BatchService = class BatchService {
|
|
|
3318
3698
|
return batch;
|
|
3319
3699
|
}
|
|
3320
3700
|
async splitBatch({ manager = this.dataSource.manager, ...options }) {
|
|
3321
|
-
const batchRepository = manager.getRepository(
|
|
3701
|
+
const batchRepository = manager.getRepository(this.batchEntity);
|
|
3322
3702
|
const batch = await batchRepository.findOneOrFail({
|
|
3323
3703
|
where: { id: options.id },
|
|
3324
3704
|
relations: ['batchGroup'],
|
|
@@ -3413,6 +3793,7 @@ exports.HelperService = tslib.__decorate([
|
|
|
3413
3793
|
*/
|
|
3414
3794
|
exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
3415
3795
|
dataSource;
|
|
3796
|
+
entities;
|
|
3416
3797
|
materialService;
|
|
3417
3798
|
batchService;
|
|
3418
3799
|
helperService;
|
|
@@ -3420,8 +3801,9 @@ exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
3420
3801
|
receiveInventoryOrderEntity;
|
|
3421
3802
|
receiveInventoryOrderItemEntity;
|
|
3422
3803
|
selectQueryBuilder;
|
|
3423
|
-
constructor(dataSource, materialService, batchService, helperService, stockService, receiveInventoryOrderEntity, receiveInventoryOrderItemEntity) {
|
|
3804
|
+
constructor(dataSource, entities, materialService, batchService, helperService, stockService, receiveInventoryOrderEntity, receiveInventoryOrderItemEntity) {
|
|
3424
3805
|
this.dataSource = dataSource;
|
|
3806
|
+
this.entities = entities;
|
|
3425
3807
|
this.materialService = materialService;
|
|
3426
3808
|
this.batchService = batchService;
|
|
3427
3809
|
this.helperService = helperService;
|
|
@@ -3472,7 +3854,7 @@ exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
3472
3854
|
}
|
|
3473
3855
|
processReceiveInventoryOrderItems(items, orderId, manager) {
|
|
3474
3856
|
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
3475
|
-
const locationRepository = manager.getRepository(
|
|
3857
|
+
const locationRepository = manager.getRepository(this.entities.location);
|
|
3476
3858
|
const loaderRepository = manager.getRepository(exports.LoadersEntityClass);
|
|
3477
3859
|
return items.reduce(async (accPromise, item) => {
|
|
3478
3860
|
const acc = await accPromise;
|
|
@@ -3517,7 +3899,7 @@ exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
3517
3899
|
}, Promise.resolve([]));
|
|
3518
3900
|
}
|
|
3519
3901
|
async createReceiveInventoryOrder({ manager = this.dataSource.manager, ...options }) {
|
|
3520
|
-
const orderRepository = manager.getRepository(
|
|
3902
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
3521
3903
|
const receiveInventoryOrderRepository = manager.getRepository(this.receiveInventoryOrderEntity);
|
|
3522
3904
|
const receiveInventoryOrderItemRepository = manager.getRepository(this.receiveInventoryOrderItemEntity);
|
|
3523
3905
|
// create base order
|
|
@@ -3651,10 +4033,10 @@ exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
3651
4033
|
return this.dataSource.transaction(async (manager) => {
|
|
3652
4034
|
const changeRepository = manager.getRepository(exports.ReceiveInventoryOrderChangeEntityClass);
|
|
3653
4035
|
const itemRepository = manager.getRepository(this.receiveInventoryOrderItemEntity);
|
|
3654
|
-
const orderRepository = manager.getRepository(
|
|
3655
|
-
const locationRepository = manager.getRepository(
|
|
4036
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
4037
|
+
const locationRepository = manager.getRepository(this.entities.location);
|
|
3656
4038
|
const loaderRepository = manager.getRepository(exports.LoadersEntityClass);
|
|
3657
|
-
const stockRepository = manager.getRepository(
|
|
4039
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
3658
4040
|
const items = await itemRepository.find({
|
|
3659
4041
|
where: { id: typeorm.In(options.map((o) => o.itemId)) },
|
|
3660
4042
|
relations: ['changes'],
|
|
@@ -3744,9 +4126,10 @@ exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
3744
4126
|
};
|
|
3745
4127
|
exports.ReceiveInventoryOrderService = tslib.__decorate([
|
|
3746
4128
|
common.Injectable(),
|
|
3747
|
-
tslib.__param(
|
|
3748
|
-
tslib.__param(
|
|
4129
|
+
tslib.__param(6, common.Inject(ReceiveInventoryOrderEntity)),
|
|
4130
|
+
tslib.__param(7, common.Inject(ReceiveInventoryOrderItemEntity)),
|
|
3749
4131
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
4132
|
+
exports.WmsEntities,
|
|
3750
4133
|
exports.MaterialService,
|
|
3751
4134
|
exports.BatchService,
|
|
3752
4135
|
exports.HelperService,
|
|
@@ -3761,6 +4144,7 @@ exports.ReceiveInventoryOrderService = tslib.__decorate([
|
|
|
3761
4144
|
*/
|
|
3762
4145
|
exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
3763
4146
|
dataSource;
|
|
4147
|
+
entities;
|
|
3764
4148
|
materialService;
|
|
3765
4149
|
batchService;
|
|
3766
4150
|
stockService;
|
|
@@ -3769,8 +4153,9 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
3769
4153
|
shipInventoryOrderReferenceEntity;
|
|
3770
4154
|
saleOrderEntity;
|
|
3771
4155
|
selectQueryBuilder;
|
|
3772
|
-
constructor(dataSource, materialService, batchService, stockService, shipInventoryOrderEntity, shipInventoryOrderItemEntity, shipInventoryOrderReferenceEntity, saleOrderEntity) {
|
|
4156
|
+
constructor(dataSource, entities, materialService, batchService, stockService, shipInventoryOrderEntity, shipInventoryOrderItemEntity, shipInventoryOrderReferenceEntity, saleOrderEntity) {
|
|
3773
4157
|
this.dataSource = dataSource;
|
|
4158
|
+
this.entities = entities;
|
|
3774
4159
|
this.materialService = materialService;
|
|
3775
4160
|
this.batchService = batchService;
|
|
3776
4161
|
this.stockService = stockService;
|
|
@@ -3843,8 +4228,8 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
3843
4228
|
async processShipInventoryOrderItems(items, manager) {
|
|
3844
4229
|
const shipInventoryOrderItemRepository = manager.getRepository(this.shipInventoryOrderItemEntity);
|
|
3845
4230
|
const shipInventoryOrderChangeRepository = manager.getRepository(exports.ShipInventoryOrderChangeEntityClass);
|
|
3846
|
-
const orderRepository = manager.getRepository(
|
|
3847
|
-
const stockRepository = manager.getRepository(
|
|
4231
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
4232
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
3848
4233
|
await Promise.all(items.map(async (data) => {
|
|
3849
4234
|
// Ensure required fields are present
|
|
3850
4235
|
if (!data.batchId || !data.materialId)
|
|
@@ -3895,7 +4280,7 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
3895
4280
|
}));
|
|
3896
4281
|
}
|
|
3897
4282
|
async createShipInventoryOrder({ manager = this.dataSource.manager, ...options }) {
|
|
3898
|
-
const orderRepository = manager.getRepository(
|
|
4283
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
3899
4284
|
const shipInventoryOrderRepository = manager.getRepository(this.shipInventoryOrderEntity);
|
|
3900
4285
|
const shipInventoryOrderReferenceRepository = manager.getRepository(this.shipInventoryOrderReferenceEntity);
|
|
3901
4286
|
// create base order
|
|
@@ -4055,8 +4440,8 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
4055
4440
|
async cancelShipInternal(options, manager) {
|
|
4056
4441
|
const changeRepository = manager.getRepository(exports.ShipInventoryOrderChangeEntityClass);
|
|
4057
4442
|
const itemRepository = manager.getRepository(this.shipInventoryOrderItemEntity);
|
|
4058
|
-
const orderRepository = manager.getRepository(
|
|
4059
|
-
const stockRepository = manager.getRepository(
|
|
4443
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
4444
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
4060
4445
|
const items = await itemRepository.find({
|
|
4061
4446
|
where: { id: typeorm.In(options.map((o) => o.itemId)) },
|
|
4062
4447
|
relations: ['changes'],
|
|
@@ -4212,8 +4597,8 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
4212
4597
|
return this.dataSource.transaction(async (manager) => {
|
|
4213
4598
|
const changeRepository = manager.getRepository(exports.ShipInventoryOrderChangeEntityClass);
|
|
4214
4599
|
const itemRepository = manager.getRepository(this.shipInventoryOrderItemEntity);
|
|
4215
|
-
const orderRepository = manager.getRepository(
|
|
4216
|
-
const stockRepository = manager.getRepository(
|
|
4600
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
4601
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
4217
4602
|
const items = await itemRepository.find({
|
|
4218
4603
|
where: { id: typeorm.In(options.map((option) => option.itemId)) },
|
|
4219
4604
|
relations: ['changes'],
|
|
@@ -4284,11 +4669,12 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
4284
4669
|
};
|
|
4285
4670
|
exports.ShipInventoryOrderService = tslib.__decorate([
|
|
4286
4671
|
common.Injectable(),
|
|
4287
|
-
tslib.__param(
|
|
4288
|
-
tslib.__param(
|
|
4289
|
-
tslib.__param(
|
|
4290
|
-
tslib.__param(
|
|
4672
|
+
tslib.__param(5, common.Inject(ShipInventoryOrderEntity)),
|
|
4673
|
+
tslib.__param(6, common.Inject(ShipInventoryOrderItemEntity)),
|
|
4674
|
+
tslib.__param(7, common.Inject(ShipInventoryOrderReferenceEntity)),
|
|
4675
|
+
tslib.__param(8, common.Inject(SaleOrderEntity)),
|
|
4291
4676
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
4677
|
+
exports.WmsEntities,
|
|
4292
4678
|
exports.MaterialService,
|
|
4293
4679
|
exports.BatchService,
|
|
4294
4680
|
exports.StockService, Object, Object, Object, Object])
|
|
@@ -4387,6 +4773,7 @@ exports.UnitService = tslib.__decorate([
|
|
|
4387
4773
|
|
|
4388
4774
|
exports.TransferOrderService = class TransferOrderService {
|
|
4389
4775
|
dataSource;
|
|
4776
|
+
entities;
|
|
4390
4777
|
helperService;
|
|
4391
4778
|
materialService;
|
|
4392
4779
|
batchService;
|
|
@@ -4396,8 +4783,9 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
4396
4783
|
stockEntity;
|
|
4397
4784
|
seqPrefix = 'TO';
|
|
4398
4785
|
transferOrderRepository;
|
|
4399
|
-
constructor(dataSource, helperService, materialService, batchService, stockService, transferOrderEntity, transferOrderItemEntity, stockEntity) {
|
|
4786
|
+
constructor(dataSource, entities, helperService, materialService, batchService, stockService, transferOrderEntity, transferOrderItemEntity, stockEntity) {
|
|
4400
4787
|
this.dataSource = dataSource;
|
|
4788
|
+
this.entities = entities;
|
|
4401
4789
|
this.helperService = helperService;
|
|
4402
4790
|
this.materialService = materialService;
|
|
4403
4791
|
this.batchService = batchService;
|
|
@@ -4412,7 +4800,7 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
4412
4800
|
transferOrder: manager.getRepository(this.transferOrderEntity),
|
|
4413
4801
|
transferOrderItem: manager.getRepository(this.transferOrderItemEntity),
|
|
4414
4802
|
transferOrderChange: manager.getRepository(exports.TransferOrderChangeEntityClass),
|
|
4415
|
-
order: manager.getRepository(
|
|
4803
|
+
order: manager.getRepository(this.entities.order),
|
|
4416
4804
|
stock: manager.getRepository(this.stockEntity),
|
|
4417
4805
|
loader: manager.getRepository(exports.LoadersEntityClass),
|
|
4418
4806
|
};
|
|
@@ -4890,7 +5278,7 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
4890
5278
|
manager,
|
|
4891
5279
|
});
|
|
4892
5280
|
// Record the transfer change
|
|
4893
|
-
const base = await manager.getRepository(
|
|
5281
|
+
const base = await manager.getRepository(this.entities.order).save({});
|
|
4894
5282
|
// Availability check at the IN_TRANSFER coord — must have ≥ qty to drain
|
|
4895
5283
|
await this.stockService.validateStockAvailability({
|
|
4896
5284
|
materialId: item.materialId,
|
|
@@ -4948,10 +5336,11 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
4948
5336
|
};
|
|
4949
5337
|
exports.TransferOrderService = tslib.__decorate([
|
|
4950
5338
|
common.Injectable(),
|
|
4951
|
-
tslib.__param(
|
|
4952
|
-
tslib.__param(
|
|
4953
|
-
tslib.__param(
|
|
5339
|
+
tslib.__param(6, common.Inject(TransferOrderEntity)),
|
|
5340
|
+
tslib.__param(7, common.Inject(TransferOrderItemEntity)),
|
|
5341
|
+
tslib.__param(8, common.Inject(StockEntity)),
|
|
4954
5342
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
5343
|
+
exports.WmsEntities,
|
|
4955
5344
|
exports.HelperService,
|
|
4956
5345
|
exports.MaterialService,
|
|
4957
5346
|
exports.BatchService,
|
|
@@ -4960,6 +5349,7 @@ exports.TransferOrderService = tslib.__decorate([
|
|
|
4960
5349
|
|
|
4961
5350
|
exports.HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
4962
5351
|
dataSource;
|
|
5352
|
+
entities;
|
|
4963
5353
|
helperService;
|
|
4964
5354
|
materialService;
|
|
4965
5355
|
batchService;
|
|
@@ -4968,8 +5358,9 @@ exports.HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
|
4968
5358
|
holdInventoryOrderItemEntity;
|
|
4969
5359
|
stockEntity;
|
|
4970
5360
|
seqPrefix = 'HIO';
|
|
4971
|
-
constructor(dataSource, helperService, materialService, batchService, stockService, holdInventoryOrderEntity, holdInventoryOrderItemEntity, stockEntity) {
|
|
5361
|
+
constructor(dataSource, entities, helperService, materialService, batchService, stockService, holdInventoryOrderEntity, holdInventoryOrderItemEntity, stockEntity) {
|
|
4972
5362
|
this.dataSource = dataSource;
|
|
5363
|
+
this.entities = entities;
|
|
4973
5364
|
this.helperService = helperService;
|
|
4974
5365
|
this.materialService = materialService;
|
|
4975
5366
|
this.batchService = batchService;
|
|
@@ -4984,7 +5375,7 @@ exports.HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
|
4984
5375
|
holdInventoryOrderItem: manager.getRepository(this.holdInventoryOrderItemEntity),
|
|
4985
5376
|
holdInventoryOrderChange: manager.getRepository(exports.HoldInventoryOrderChangeEntityClass),
|
|
4986
5377
|
stock: manager.getRepository(this.stockEntity),
|
|
4987
|
-
order: manager.getRepository(
|
|
5378
|
+
order: manager.getRepository(this.entities.order),
|
|
4988
5379
|
};
|
|
4989
5380
|
}
|
|
4990
5381
|
async processHoldInventoryOrderItems(items, repos, manager) {
|
|
@@ -5175,10 +5566,11 @@ exports.HoldInventoryOrderService = class HoldInventoryOrderService {
|
|
|
5175
5566
|
};
|
|
5176
5567
|
exports.HoldInventoryOrderService = tslib.__decorate([
|
|
5177
5568
|
common.Injectable(),
|
|
5178
|
-
tslib.__param(
|
|
5179
|
-
tslib.__param(
|
|
5180
|
-
tslib.__param(
|
|
5569
|
+
tslib.__param(6, common.Inject(HoldInventoryOrderEntity)),
|
|
5570
|
+
tslib.__param(7, common.Inject(HoldInventoryOrderItemEntity)),
|
|
5571
|
+
tslib.__param(8, common.Inject(StockEntity)),
|
|
5181
5572
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
5573
|
+
exports.WmsEntities,
|
|
5182
5574
|
exports.HelperService,
|
|
5183
5575
|
exports.MaterialService,
|
|
5184
5576
|
exports.BatchService,
|
|
@@ -5187,6 +5579,7 @@ exports.HoldInventoryOrderService = tslib.__decorate([
|
|
|
5187
5579
|
|
|
5188
5580
|
exports.AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
5189
5581
|
dataSource;
|
|
5582
|
+
entities;
|
|
5190
5583
|
helperService;
|
|
5191
5584
|
materialService;
|
|
5192
5585
|
batchService;
|
|
@@ -5195,8 +5588,9 @@ exports.AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
5195
5588
|
allocateInventoryOrderItemEntity;
|
|
5196
5589
|
stockEntity;
|
|
5197
5590
|
seqPrefix = 'AIO';
|
|
5198
|
-
constructor(dataSource, helperService, materialService, batchService, stockService, allocateInventoryOrderEntity, allocateInventoryOrderItemEntity, stockEntity) {
|
|
5591
|
+
constructor(dataSource, entities, helperService, materialService, batchService, stockService, allocateInventoryOrderEntity, allocateInventoryOrderItemEntity, stockEntity) {
|
|
5199
5592
|
this.dataSource = dataSource;
|
|
5593
|
+
this.entities = entities;
|
|
5200
5594
|
this.helperService = helperService;
|
|
5201
5595
|
this.materialService = materialService;
|
|
5202
5596
|
this.batchService = batchService;
|
|
@@ -5210,7 +5604,7 @@ exports.AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
5210
5604
|
allocateInventoryOrder: manager.getRepository(this.allocateInventoryOrderEntity),
|
|
5211
5605
|
allocateInventoryOrderItem: manager.getRepository(this.allocateInventoryOrderItemEntity),
|
|
5212
5606
|
allocateInventoryOrderChange: manager.getRepository(exports.AllocateInventoryOrderChangeEntityClass),
|
|
5213
|
-
order: manager.getRepository(
|
|
5607
|
+
order: manager.getRepository(this.entities.order),
|
|
5214
5608
|
stock: manager.getRepository(this.stockEntity),
|
|
5215
5609
|
};
|
|
5216
5610
|
}
|
|
@@ -5416,10 +5810,11 @@ exports.AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
5416
5810
|
};
|
|
5417
5811
|
exports.AllocateInventoryOrderService = tslib.__decorate([
|
|
5418
5812
|
common.Injectable(),
|
|
5419
|
-
tslib.__param(
|
|
5420
|
-
tslib.__param(
|
|
5421
|
-
tslib.__param(
|
|
5813
|
+
tslib.__param(6, common.Inject(AllocateInventoryOrderEntity)),
|
|
5814
|
+
tslib.__param(7, common.Inject(AllocateInventoryOrderItemEntity)),
|
|
5815
|
+
tslib.__param(8, common.Inject(StockEntity)),
|
|
5422
5816
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
5817
|
+
exports.WmsEntities,
|
|
5423
5818
|
exports.HelperService,
|
|
5424
5819
|
exports.MaterialService,
|
|
5425
5820
|
exports.BatchService,
|
|
@@ -5428,6 +5823,7 @@ exports.AllocateInventoryOrderService = tslib.__decorate([
|
|
|
5428
5823
|
|
|
5429
5824
|
exports.SplitBatchOrderService = class SplitBatchOrderService {
|
|
5430
5825
|
dataSource;
|
|
5826
|
+
entities;
|
|
5431
5827
|
materialService;
|
|
5432
5828
|
batchService;
|
|
5433
5829
|
helperService;
|
|
@@ -5435,8 +5831,9 @@ exports.SplitBatchOrderService = class SplitBatchOrderService {
|
|
|
5435
5831
|
splitBatchOrderEntity;
|
|
5436
5832
|
splitBatchOrderItemEntity;
|
|
5437
5833
|
seqPrefix = 'SBO';
|
|
5438
|
-
constructor(dataSource, materialService, batchService, helperService, stockService, splitBatchOrderEntity, splitBatchOrderItemEntity) {
|
|
5834
|
+
constructor(dataSource, entities, materialService, batchService, helperService, stockService, splitBatchOrderEntity, splitBatchOrderItemEntity) {
|
|
5439
5835
|
this.dataSource = dataSource;
|
|
5836
|
+
this.entities = entities;
|
|
5440
5837
|
this.materialService = materialService;
|
|
5441
5838
|
this.batchService = batchService;
|
|
5442
5839
|
this.helperService = helperService;
|
|
@@ -5449,9 +5846,9 @@ exports.SplitBatchOrderService = class SplitBatchOrderService {
|
|
|
5449
5846
|
const splitBatchOrderRepository = manager.getRepository(this.splitBatchOrderEntity);
|
|
5450
5847
|
const splitBatchOrderItemRepository = manager.getRepository(this.splitBatchOrderItemEntity);
|
|
5451
5848
|
const splitBatchOrderChangeRepository = manager.getRepository(exports.SplitBatchOrderChangeEntityClass);
|
|
5452
|
-
const orderRepository = manager.getRepository(
|
|
5453
|
-
const stockRepository = manager.getRepository(
|
|
5454
|
-
const batchRepository = manager.getRepository(
|
|
5849
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
5850
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
5851
|
+
const batchRepository = manager.getRepository(this.entities.batch);
|
|
5455
5852
|
// Get original batch information
|
|
5456
5853
|
const originalBatch = await batchRepository.findOneOrFail({
|
|
5457
5854
|
where: { id: options.batchId },
|
|
@@ -5520,9 +5917,10 @@ exports.SplitBatchOrderService = class SplitBatchOrderService {
|
|
|
5520
5917
|
};
|
|
5521
5918
|
exports.SplitBatchOrderService = tslib.__decorate([
|
|
5522
5919
|
common.Injectable(),
|
|
5523
|
-
tslib.__param(
|
|
5524
|
-
tslib.__param(
|
|
5920
|
+
tslib.__param(6, common.Inject(SplitBatchOrderEntity)),
|
|
5921
|
+
tslib.__param(7, common.Inject(SplitBatchOrderItemEntity)),
|
|
5525
5922
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
5923
|
+
exports.WmsEntities,
|
|
5526
5924
|
exports.MaterialService,
|
|
5527
5925
|
exports.BatchService,
|
|
5528
5926
|
exports.HelperService,
|
|
@@ -5531,6 +5929,7 @@ exports.SplitBatchOrderService = tslib.__decorate([
|
|
|
5531
5929
|
|
|
5532
5930
|
exports.MergeBatchOrderService = class MergeBatchOrderService {
|
|
5533
5931
|
dataSource;
|
|
5932
|
+
entities;
|
|
5534
5933
|
materialService;
|
|
5535
5934
|
batchService;
|
|
5536
5935
|
helperService;
|
|
@@ -5538,8 +5937,9 @@ exports.MergeBatchOrderService = class MergeBatchOrderService {
|
|
|
5538
5937
|
mergeBatchOrderEntity;
|
|
5539
5938
|
mergeBatchOrderItemEntity;
|
|
5540
5939
|
seqPrefix = 'MBO';
|
|
5541
|
-
constructor(dataSource, materialService, batchService, helperService, stockService, mergeBatchOrderEntity, mergeBatchOrderItemEntity) {
|
|
5940
|
+
constructor(dataSource, entities, materialService, batchService, helperService, stockService, mergeBatchOrderEntity, mergeBatchOrderItemEntity) {
|
|
5542
5941
|
this.dataSource = dataSource;
|
|
5942
|
+
this.entities = entities;
|
|
5543
5943
|
this.materialService = materialService;
|
|
5544
5944
|
this.batchService = batchService;
|
|
5545
5945
|
this.helperService = helperService;
|
|
@@ -5552,9 +5952,9 @@ exports.MergeBatchOrderService = class MergeBatchOrderService {
|
|
|
5552
5952
|
const mergeBatchOrderRepository = manager.getRepository(this.mergeBatchOrderEntity);
|
|
5553
5953
|
const mergeBatchOrderItemRepository = manager.getRepository(this.mergeBatchOrderItemEntity);
|
|
5554
5954
|
const mergeBatchOrderChangeRepository = manager.getRepository(exports.MergeBatchOrderChangeEntityClass);
|
|
5555
|
-
const orderRepository = manager.getRepository(
|
|
5556
|
-
const stockRepository = manager.getRepository(
|
|
5557
|
-
const batchRepository = manager.getRepository(
|
|
5955
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
5956
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
5957
|
+
const batchRepository = manager.getRepository(this.entities.batch);
|
|
5558
5958
|
// Verify all source batches have identical metadata (except key and groupId)
|
|
5559
5959
|
const sourceBatches = await batchRepository.find({
|
|
5560
5960
|
where: { id: typeorm.In(options.items.map((item) => item.batchId)) },
|
|
@@ -5657,9 +6057,10 @@ exports.MergeBatchOrderService = class MergeBatchOrderService {
|
|
|
5657
6057
|
};
|
|
5658
6058
|
exports.MergeBatchOrderService = tslib.__decorate([
|
|
5659
6059
|
common.Injectable(),
|
|
5660
|
-
tslib.__param(
|
|
5661
|
-
tslib.__param(
|
|
6060
|
+
tslib.__param(6, common.Inject(MergeBatchOrderEntity)),
|
|
6061
|
+
tslib.__param(7, common.Inject(MergeBatchOrderItemEntity)),
|
|
5662
6062
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
6063
|
+
exports.WmsEntities,
|
|
5663
6064
|
exports.MaterialService,
|
|
5664
6065
|
exports.BatchService,
|
|
5665
6066
|
exports.HelperService,
|
|
@@ -5668,6 +6069,7 @@ exports.MergeBatchOrderService = tslib.__decorate([
|
|
|
5668
6069
|
|
|
5669
6070
|
exports.ReclassifyInventoryOrderService = class ReclassifyInventoryOrderService {
|
|
5670
6071
|
dataSource;
|
|
6072
|
+
entities;
|
|
5671
6073
|
materialService;
|
|
5672
6074
|
batchService;
|
|
5673
6075
|
helperService;
|
|
@@ -5675,8 +6077,9 @@ exports.ReclassifyInventoryOrderService = class ReclassifyInventoryOrderService
|
|
|
5675
6077
|
reclassifyInventoryOrderEntity;
|
|
5676
6078
|
reclassifyInventoryOrderItemEntity;
|
|
5677
6079
|
seqPrefix = 'RCO';
|
|
5678
|
-
constructor(dataSource, materialService, batchService, helperService, stockService, reclassifyInventoryOrderEntity, reclassifyInventoryOrderItemEntity) {
|
|
6080
|
+
constructor(dataSource, entities, materialService, batchService, helperService, stockService, reclassifyInventoryOrderEntity, reclassifyInventoryOrderItemEntity) {
|
|
5679
6081
|
this.dataSource = dataSource;
|
|
6082
|
+
this.entities = entities;
|
|
5680
6083
|
this.materialService = materialService;
|
|
5681
6084
|
this.batchService = batchService;
|
|
5682
6085
|
this.helperService = helperService;
|
|
@@ -5689,9 +6092,9 @@ exports.ReclassifyInventoryOrderService = class ReclassifyInventoryOrderService
|
|
|
5689
6092
|
const reclassifyOrderRepository = manager.getRepository(this.reclassifyInventoryOrderEntity);
|
|
5690
6093
|
const reclassifyOrderItemRepository = manager.getRepository(this.reclassifyInventoryOrderItemEntity);
|
|
5691
6094
|
const reclassifyOrderChangeRepository = manager.getRepository(exports.ReclassifyInventoryOrderChangeEntityClass);
|
|
5692
|
-
const orderRepository = manager.getRepository(
|
|
5693
|
-
const stockRepository = manager.getRepository(
|
|
5694
|
-
const batchRepository = manager.getRepository(
|
|
6095
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
6096
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
6097
|
+
const batchRepository = manager.getRepository(this.entities.batch);
|
|
5695
6098
|
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
5696
6099
|
// Ensure new material exists
|
|
5697
6100
|
const material = await materialRepository.findOneOrFail({
|
|
@@ -5780,9 +6183,10 @@ exports.ReclassifyInventoryOrderService = class ReclassifyInventoryOrderService
|
|
|
5780
6183
|
};
|
|
5781
6184
|
exports.ReclassifyInventoryOrderService = tslib.__decorate([
|
|
5782
6185
|
common.Injectable(),
|
|
5783
|
-
tslib.__param(
|
|
5784
|
-
tslib.__param(
|
|
6186
|
+
tslib.__param(6, common.Inject(ReclassifyInventoryOrderEntity)),
|
|
6187
|
+
tslib.__param(7, common.Inject(ReclassifyInventoryOrderItemEntity)),
|
|
5785
6188
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
6189
|
+
exports.WmsEntities,
|
|
5786
6190
|
exports.MaterialService,
|
|
5787
6191
|
exports.BatchService,
|
|
5788
6192
|
exports.HelperService,
|
|
@@ -5791,6 +6195,7 @@ exports.ReclassifyInventoryOrderService = tslib.__decorate([
|
|
|
5791
6195
|
|
|
5792
6196
|
exports.TransferVendorOrderService = class TransferVendorOrderService {
|
|
5793
6197
|
dataSource;
|
|
6198
|
+
entities;
|
|
5794
6199
|
helperService;
|
|
5795
6200
|
materialService;
|
|
5796
6201
|
batchService;
|
|
@@ -5799,8 +6204,9 @@ exports.TransferVendorOrderService = class TransferVendorOrderService {
|
|
|
5799
6204
|
transferVendorOrderItemEntity;
|
|
5800
6205
|
stockEntity;
|
|
5801
6206
|
seqPrefix = 'TVO';
|
|
5802
|
-
constructor(dataSource, helperService, materialService, batchService, stockService, transferVendorOrderEntity, transferVendorOrderItemEntity, stockEntity) {
|
|
6207
|
+
constructor(dataSource, entities, helperService, materialService, batchService, stockService, transferVendorOrderEntity, transferVendorOrderItemEntity, stockEntity) {
|
|
5803
6208
|
this.dataSource = dataSource;
|
|
6209
|
+
this.entities = entities;
|
|
5804
6210
|
this.helperService = helperService;
|
|
5805
6211
|
this.materialService = materialService;
|
|
5806
6212
|
this.batchService = batchService;
|
|
@@ -5814,9 +6220,9 @@ exports.TransferVendorOrderService = class TransferVendorOrderService {
|
|
|
5814
6220
|
transferVendorOrder: manager.getRepository(this.transferVendorOrderEntity),
|
|
5815
6221
|
transferVendorOrderItem: manager.getRepository(this.transferVendorOrderItemEntity),
|
|
5816
6222
|
transferVendorOrderChange: manager.getRepository(exports.TransferVendorOrderChangeEntityClass),
|
|
5817
|
-
order: manager.getRepository(
|
|
6223
|
+
order: manager.getRepository(this.entities.order),
|
|
5818
6224
|
stock: manager.getRepository(this.stockEntity),
|
|
5819
|
-
location: manager.getRepository(
|
|
6225
|
+
location: manager.getRepository(this.entities.location),
|
|
5820
6226
|
loader: manager.getRepository(exports.LoadersEntityClass),
|
|
5821
6227
|
};
|
|
5822
6228
|
}
|
|
@@ -6000,10 +6406,11 @@ exports.TransferVendorOrderService = class TransferVendorOrderService {
|
|
|
6000
6406
|
};
|
|
6001
6407
|
exports.TransferVendorOrderService = tslib.__decorate([
|
|
6002
6408
|
common.Injectable(),
|
|
6003
|
-
tslib.__param(
|
|
6004
|
-
tslib.__param(
|
|
6005
|
-
tslib.__param(
|
|
6409
|
+
tslib.__param(6, common.Inject(TransferVendorOrderEntity)),
|
|
6410
|
+
tslib.__param(7, common.Inject(TransferVendorOrderItemEntity)),
|
|
6411
|
+
tslib.__param(8, common.Inject(StockEntity)),
|
|
6006
6412
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
6413
|
+
exports.WmsEntities,
|
|
6007
6414
|
exports.HelperService,
|
|
6008
6415
|
exports.MaterialService,
|
|
6009
6416
|
exports.BatchService,
|
|
@@ -6012,13 +6419,15 @@ exports.TransferVendorOrderService = tslib.__decorate([
|
|
|
6012
6419
|
|
|
6013
6420
|
exports.QualityInspectionOrderService = class QualityInspectionOrderService {
|
|
6014
6421
|
dataSource;
|
|
6422
|
+
entities;
|
|
6015
6423
|
qualityInspectionOrderEntity;
|
|
6016
6424
|
qualityInspectionOrderItemEntity;
|
|
6017
6425
|
batchService;
|
|
6018
6426
|
materialService;
|
|
6019
6427
|
stockService;
|
|
6020
|
-
constructor(dataSource, qualityInspectionOrderEntity, qualityInspectionOrderItemEntity, batchService, materialService, stockService) {
|
|
6428
|
+
constructor(dataSource, entities, qualityInspectionOrderEntity, qualityInspectionOrderItemEntity, batchService, materialService, stockService) {
|
|
6021
6429
|
this.dataSource = dataSource;
|
|
6430
|
+
this.entities = entities;
|
|
6022
6431
|
this.qualityInspectionOrderEntity = qualityInspectionOrderEntity;
|
|
6023
6432
|
this.qualityInspectionOrderItemEntity = qualityInspectionOrderItemEntity;
|
|
6024
6433
|
this.batchService = batchService;
|
|
@@ -6026,11 +6435,11 @@ exports.QualityInspectionOrderService = class QualityInspectionOrderService {
|
|
|
6026
6435
|
this.stockService = stockService;
|
|
6027
6436
|
}
|
|
6028
6437
|
async inspect({ manager = this.dataSource.manager, options, }) {
|
|
6029
|
-
const orderRepository = manager.getRepository(
|
|
6438
|
+
const orderRepository = manager.getRepository(this.entities.order);
|
|
6030
6439
|
const qualityInspectionOrderRepository = manager.getRepository(this.qualityInspectionOrderEntity);
|
|
6031
6440
|
const qualityInspectionOrderItemRepository = manager.getRepository(this.qualityInspectionOrderItemEntity);
|
|
6032
6441
|
const qualityInspectionOrderChangeRepository = manager.getRepository(exports.QualityInspectionOrderChangeEntityClass);
|
|
6033
|
-
const stockRepository = manager.getRepository(
|
|
6442
|
+
const stockRepository = manager.getRepository(this.entities.stock);
|
|
6034
6443
|
const order = await qualityInspectionOrderRepository.save(qualityInspectionOrderRepository.create({
|
|
6035
6444
|
key: options.key,
|
|
6036
6445
|
note: options.note,
|
|
@@ -6081,15 +6490,17 @@ exports.QualityInspectionOrderService = class QualityInspectionOrderService {
|
|
|
6081
6490
|
};
|
|
6082
6491
|
exports.QualityInspectionOrderService = tslib.__decorate([
|
|
6083
6492
|
common.Injectable(),
|
|
6084
|
-
tslib.__param(
|
|
6085
|
-
tslib.__param(
|
|
6086
|
-
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
6493
|
+
tslib.__param(2, common.Inject(QualityInspectionOrderEntity)),
|
|
6494
|
+
tslib.__param(3, common.Inject(QualityInspectionOrderItemEntity)),
|
|
6495
|
+
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
6496
|
+
exports.WmsEntities, Object, Object, exports.BatchService,
|
|
6087
6497
|
exports.MaterialService,
|
|
6088
6498
|
exports.StockService])
|
|
6089
6499
|
], exports.QualityInspectionOrderService);
|
|
6090
6500
|
|
|
6091
6501
|
exports.TransferCustomerOrderService = class TransferCustomerOrderService {
|
|
6092
6502
|
dataSource;
|
|
6503
|
+
entities;
|
|
6093
6504
|
helperService;
|
|
6094
6505
|
materialService;
|
|
6095
6506
|
batchService;
|
|
@@ -6098,8 +6509,9 @@ exports.TransferCustomerOrderService = class TransferCustomerOrderService {
|
|
|
6098
6509
|
transferCustomerOrderItemEntity;
|
|
6099
6510
|
stockEntity;
|
|
6100
6511
|
seqPrefix = 'TCO';
|
|
6101
|
-
constructor(dataSource, helperService, materialService, batchService, stockService, transferCustomerOrderEntity, transferCustomerOrderItemEntity, stockEntity) {
|
|
6512
|
+
constructor(dataSource, entities, helperService, materialService, batchService, stockService, transferCustomerOrderEntity, transferCustomerOrderItemEntity, stockEntity) {
|
|
6102
6513
|
this.dataSource = dataSource;
|
|
6514
|
+
this.entities = entities;
|
|
6103
6515
|
this.helperService = helperService;
|
|
6104
6516
|
this.materialService = materialService;
|
|
6105
6517
|
this.batchService = batchService;
|
|
@@ -6113,9 +6525,9 @@ exports.TransferCustomerOrderService = class TransferCustomerOrderService {
|
|
|
6113
6525
|
transferCustomerOrder: manager.getRepository(this.transferCustomerOrderEntity),
|
|
6114
6526
|
transferCustomerOrderItem: manager.getRepository(this.transferCustomerOrderItemEntity),
|
|
6115
6527
|
transferCustomerOrderChange: manager.getRepository(exports.TransferCustomerOrderChangeEntityClass),
|
|
6116
|
-
order: manager.getRepository(
|
|
6528
|
+
order: manager.getRepository(this.entities.order),
|
|
6117
6529
|
stock: manager.getRepository(this.stockEntity),
|
|
6118
|
-
location: manager.getRepository(
|
|
6530
|
+
location: manager.getRepository(this.entities.location),
|
|
6119
6531
|
loader: manager.getRepository(exports.LoadersEntityClass),
|
|
6120
6532
|
};
|
|
6121
6533
|
}
|
|
@@ -6299,10 +6711,11 @@ exports.TransferCustomerOrderService = class TransferCustomerOrderService {
|
|
|
6299
6711
|
};
|
|
6300
6712
|
exports.TransferCustomerOrderService = tslib.__decorate([
|
|
6301
6713
|
common.Injectable(),
|
|
6302
|
-
tslib.__param(
|
|
6303
|
-
tslib.__param(
|
|
6304
|
-
tslib.__param(
|
|
6714
|
+
tslib.__param(6, common.Inject(TransferCustomerOrderEntity)),
|
|
6715
|
+
tslib.__param(7, common.Inject(TransferCustomerOrderItemEntity)),
|
|
6716
|
+
tslib.__param(8, common.Inject(StockEntity)),
|
|
6305
6717
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
6718
|
+
exports.WmsEntities,
|
|
6306
6719
|
exports.HelperService,
|
|
6307
6720
|
exports.MaterialService,
|
|
6308
6721
|
exports.BatchService,
|
|
@@ -6323,16 +6736,476 @@ exports.SaleOrderService = tslib.__decorate([
|
|
|
6323
6736
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource])
|
|
6324
6737
|
], exports.SaleOrderService);
|
|
6325
6738
|
|
|
6739
|
+
/**
|
|
6740
|
+
* Inventory counting: compare the ledger against what is physically there, then
|
|
6741
|
+
* adjust the ledger to match.
|
|
6742
|
+
*
|
|
6743
|
+
* The shape follows the "D. 盤點" design flow. Three properties are worth
|
|
6744
|
+
* stating up front because everything else follows from them:
|
|
6745
|
+
*
|
|
6746
|
+
* - **Counting never moves stock between locations.** A line that is in the
|
|
6747
|
+
* wrong place is a transfer, not a count; `transfer-order:create` already does
|
|
6748
|
+
* that. This service only ever adjusts quantity, up or down, in place.
|
|
6749
|
+
* - **Nothing touches stock until settlement.** Counted quantities are working
|
|
6750
|
+
* notes ("暫存的對帳資料"); only {@link settle} writes changes, and it does so
|
|
6751
|
+
* in a single transaction.
|
|
6752
|
+
* - **Starting a count locks its locations.** The book snapshot taken at
|
|
6753
|
+
* {@link start} would be worthless if stock kept moving underneath it, so
|
|
6754
|
+
* `InventoryCountLockSubscriber` refuses every other stock movement in the
|
|
6755
|
+
* scope until the order settles or is cancelled.
|
|
6756
|
+
*/
|
|
6757
|
+
exports.InventoryCountOrderService = class InventoryCountOrderService {
|
|
6758
|
+
dataSource;
|
|
6759
|
+
entities;
|
|
6760
|
+
helperService;
|
|
6761
|
+
materialService;
|
|
6762
|
+
stockService;
|
|
6763
|
+
batchService;
|
|
6764
|
+
inventoryCountOrderEntity;
|
|
6765
|
+
seqPrefix = 'ICO';
|
|
6766
|
+
constructor(dataSource, entities, helperService, materialService, stockService, batchService, inventoryCountOrderEntity) {
|
|
6767
|
+
this.dataSource = dataSource;
|
|
6768
|
+
this.entities = entities;
|
|
6769
|
+
this.helperService = helperService;
|
|
6770
|
+
this.materialService = materialService;
|
|
6771
|
+
this.stockService = stockService;
|
|
6772
|
+
this.batchService = batchService;
|
|
6773
|
+
this.inventoryCountOrderEntity = inventoryCountOrderEntity;
|
|
6774
|
+
}
|
|
6775
|
+
getRepositories(manager) {
|
|
6776
|
+
return {
|
|
6777
|
+
order: manager.getRepository(this.inventoryCountOrderEntity),
|
|
6778
|
+
scope: manager.getRepository(exports.InventoryCountOrderLocationEntityClass),
|
|
6779
|
+
item: manager.getRepository(exports.InventoryCountOrderItemEntityClass),
|
|
6780
|
+
change: manager.getRepository(exports.InventoryCountOrderChangeEntityClass),
|
|
6781
|
+
baseOrder: manager.getRepository(this.entities.order),
|
|
6782
|
+
stock: manager.getRepository(this.entities.stock),
|
|
6783
|
+
};
|
|
6784
|
+
}
|
|
6785
|
+
/**
|
|
6786
|
+
* Expand chosen locations into themselves plus every descendant.
|
|
6787
|
+
*
|
|
6788
|
+
* `LocationEntity` is a plain adjacency list (`parent` / `children`) with no
|
|
6789
|
+
* materialised path, so the subtree needs a recursive CTE. It runs once per
|
|
6790
|
+
* scope change and the result is stored, precisely so the lock check never has
|
|
6791
|
+
* to run it.
|
|
6792
|
+
*/
|
|
6793
|
+
async expandLocationScope(rootIds, manager) {
|
|
6794
|
+
if (!rootIds.length) {
|
|
6795
|
+
return [];
|
|
6796
|
+
}
|
|
6797
|
+
const table = manager.getRepository(this.entities.location).metadata
|
|
6798
|
+
.tableName;
|
|
6799
|
+
const rows = await manager.query(`WITH RECURSIVE subtree AS (
|
|
6800
|
+
SELECT id FROM "${table}" WHERE id = ANY($1)
|
|
6801
|
+
UNION
|
|
6802
|
+
SELECT child.id
|
|
6803
|
+
FROM "${table}" child
|
|
6804
|
+
JOIN subtree parent ON child."parentId" = parent.id
|
|
6805
|
+
)
|
|
6806
|
+
SELECT id FROM subtree`, [[...rootIds]]);
|
|
6807
|
+
const roots = new Set(rootIds);
|
|
6808
|
+
return rows.map(({ id }) => ({ id, isRoot: roots.has(id) }));
|
|
6809
|
+
}
|
|
6810
|
+
/** Current ledger quantity per physical position inside the scope. */
|
|
6811
|
+
async readPositions(locationIds, manager) {
|
|
6812
|
+
if (!locationIds.length) {
|
|
6813
|
+
return [];
|
|
6814
|
+
}
|
|
6815
|
+
// Through the repository, not raw SQL on the table: the stock entity is
|
|
6816
|
+
// overridable, and the repository is what applies the right
|
|
6817
|
+
// single-table-inheritance discriminator.
|
|
6818
|
+
const rows = await manager
|
|
6819
|
+
.getRepository(this.entities.stock)
|
|
6820
|
+
.createQueryBuilder('stock')
|
|
6821
|
+
.select('stock.materialId', 'materialId')
|
|
6822
|
+
.addSelect('stock.batchId', 'batchId')
|
|
6823
|
+
.addSelect('stock.locationId', 'locationId')
|
|
6824
|
+
.addSelect('stock.loaderId', 'loaderId')
|
|
6825
|
+
.addSelect('SUM(stock.quantity)', 'quantity')
|
|
6826
|
+
.where('stock.locationId IN (:...locationIds)', {
|
|
6827
|
+
locationIds: [...locationIds],
|
|
6828
|
+
})
|
|
6829
|
+
.groupBy('stock.materialId')
|
|
6830
|
+
.addGroupBy('stock.batchId')
|
|
6831
|
+
.addGroupBy('stock.locationId')
|
|
6832
|
+
.addGroupBy('stock.loaderId')
|
|
6833
|
+
.having('SUM(stock.quantity) > 0')
|
|
6834
|
+
.getRawMany();
|
|
6835
|
+
return rows.map((row) => ({
|
|
6836
|
+
materialId: row.materialId,
|
|
6837
|
+
batchId: row.batchId,
|
|
6838
|
+
locationId: row.locationId,
|
|
6839
|
+
loaderId: row.loaderId,
|
|
6840
|
+
quantity: Number(row.quantity),
|
|
6841
|
+
}));
|
|
6842
|
+
}
|
|
6843
|
+
positionKey(position) {
|
|
6844
|
+
return [
|
|
6845
|
+
position.materialId,
|
|
6846
|
+
position.batchId,
|
|
6847
|
+
position.locationId ?? '',
|
|
6848
|
+
position.loaderId ?? '',
|
|
6849
|
+
].join('|');
|
|
6850
|
+
}
|
|
6851
|
+
async scopedLocationIds(orderId, manager) {
|
|
6852
|
+
const rows = await this.getRepositories(manager).scope.find({
|
|
6853
|
+
where: { orderId },
|
|
6854
|
+
select: { locationId: true },
|
|
6855
|
+
});
|
|
6856
|
+
return rows.map(({ locationId }) => locationId);
|
|
6857
|
+
}
|
|
6858
|
+
async loadOrderOrFail(id, manager) {
|
|
6859
|
+
const order = await this.getRepositories(manager).order.findOneBy({ id });
|
|
6860
|
+
if (!order) {
|
|
6861
|
+
throw new common.NotFoundException(`Inventory count order ${id} not found`);
|
|
6862
|
+
}
|
|
6863
|
+
return order;
|
|
6864
|
+
}
|
|
6865
|
+
assertStatus(order, allowed) {
|
|
6866
|
+
if (!allowed.includes(order.status)) {
|
|
6867
|
+
throw new common.BadRequestException(`Inventory count order ${order.id} is ${order.status}; this operation requires ${allowed.join(' or ')}`);
|
|
6868
|
+
}
|
|
6869
|
+
}
|
|
6870
|
+
/**
|
|
6871
|
+
* Rebuild the sheet from the current ledger.
|
|
6872
|
+
*
|
|
6873
|
+
* Called when the scope changes and again when counting starts. Additions
|
|
6874
|
+
* (盤盈 lines) are never touched — they describe stock the ledger does not know
|
|
6875
|
+
* about, so a rebuild has nothing to say about them.
|
|
6876
|
+
*/
|
|
6877
|
+
async rebuildItems(orderId, manager) {
|
|
6878
|
+
const repos = this.getRepositories(manager);
|
|
6879
|
+
const locationIds = await this.scopedLocationIds(orderId, manager);
|
|
6880
|
+
const positions = await this.readPositions(locationIds, manager);
|
|
6881
|
+
const existing = await repos.item.find({
|
|
6882
|
+
where: { orderId, isAddition: false },
|
|
6883
|
+
});
|
|
6884
|
+
const byKey = new Map(existing.map((item) => [this.positionKey(item), item]));
|
|
6885
|
+
const seen = new Set();
|
|
6886
|
+
for (const position of positions) {
|
|
6887
|
+
const key = this.positionKey(position);
|
|
6888
|
+
seen.add(key);
|
|
6889
|
+
const item = byKey.get(key);
|
|
6890
|
+
if (item) {
|
|
6891
|
+
item.bookQuantity = position.quantity;
|
|
6892
|
+
await repos.item.save(item);
|
|
6893
|
+
continue;
|
|
6894
|
+
}
|
|
6895
|
+
await repos.item.save(repos.item.create({
|
|
6896
|
+
orderId,
|
|
6897
|
+
materialId: position.materialId,
|
|
6898
|
+
batchId: position.batchId,
|
|
6899
|
+
locationId: position.locationId,
|
|
6900
|
+
loaderId: position.loaderId,
|
|
6901
|
+
bookQuantity: position.quantity,
|
|
6902
|
+
countedQuantity: null,
|
|
6903
|
+
unitId: null,
|
|
6904
|
+
isAddition: false,
|
|
6905
|
+
}));
|
|
6906
|
+
}
|
|
6907
|
+
// A position that emptied out between two rebuilds is no longer on the
|
|
6908
|
+
// sheet; it cannot be counted and would settle to a meaningless zero.
|
|
6909
|
+
const stale = existing.filter((item) => !seen.has(this.positionKey(item)));
|
|
6910
|
+
if (stale.length) {
|
|
6911
|
+
await repos.item.delete({ id: typeorm.In(stale.map(({ id }) => id)) });
|
|
6912
|
+
}
|
|
6913
|
+
}
|
|
6914
|
+
/** Filters for the list page. All optional; combined with AND. */
|
|
6915
|
+
async findMany(options, manager = this.dataSource.manager) {
|
|
6916
|
+
const query = this.getRepositories(manager)
|
|
6917
|
+
// The alias is lowercase and is deliberately not `order`. `order` is a
|
|
6918
|
+
// PostgreSQL reserved word, so the raw fragments below would render
|
|
6919
|
+
// `order."countDate"` and fail to parse; and a camelCase alias would be
|
|
6920
|
+
// emitted quoted by the query builder while the unquoted references here
|
|
6921
|
+
// fold to lowercase, so the two would never match.
|
|
6922
|
+
.order.createQueryBuilder('count_order')
|
|
6923
|
+
.orderBy('count_order."countDate"', 'DESC')
|
|
6924
|
+
.addOrderBy('count_order."createdAt"', 'DESC');
|
|
6925
|
+
if (options.name) {
|
|
6926
|
+
query.andWhere('count_order.name ILIKE :name', {
|
|
6927
|
+
name: `%${options.name}%`,
|
|
6928
|
+
});
|
|
6929
|
+
}
|
|
6930
|
+
if (options.statuses?.length) {
|
|
6931
|
+
query.andWhere('count_order.status IN (:...statuses)', {
|
|
6932
|
+
statuses: options.statuses,
|
|
6933
|
+
});
|
|
6934
|
+
}
|
|
6935
|
+
if (options.createdBy) {
|
|
6936
|
+
query.andWhere('count_order."createdBy" = :createdBy', {
|
|
6937
|
+
createdBy: options.createdBy,
|
|
6938
|
+
});
|
|
6939
|
+
}
|
|
6940
|
+
if (options.countDateFrom) {
|
|
6941
|
+
query.andWhere('count_order."countDate" >= :from', {
|
|
6942
|
+
from: options.countDateFrom,
|
|
6943
|
+
});
|
|
6944
|
+
}
|
|
6945
|
+
if (options.countDateTo) {
|
|
6946
|
+
query.andWhere('count_order."countDate" <= :to', {
|
|
6947
|
+
to: options.countDateTo,
|
|
6948
|
+
});
|
|
6949
|
+
}
|
|
6950
|
+
if (options.locationIds?.length) {
|
|
6951
|
+
// Scope membership, not the roots the user picked: a count of a whole
|
|
6952
|
+
// aisle should surface when filtering by any shelf inside it.
|
|
6953
|
+
query.andWhere(`EXISTS (
|
|
6954
|
+
SELECT 1 FROM inventory_count_order_locations scope
|
|
6955
|
+
WHERE scope."orderId" = count_order.id
|
|
6956
|
+
AND scope."locationId" IN (:...locationIds)
|
|
6957
|
+
)`, { locationIds: options.locationIds });
|
|
6958
|
+
}
|
|
6959
|
+
if (options.offset !== undefined && options.offset >= 0) {
|
|
6960
|
+
query.skip(options.offset);
|
|
6961
|
+
}
|
|
6962
|
+
if (options.limit !== undefined && options.limit > 0) {
|
|
6963
|
+
query.take(options.limit);
|
|
6964
|
+
}
|
|
6965
|
+
return query.getManyAndCount();
|
|
6966
|
+
}
|
|
6967
|
+
async findOne(id, manager = this.dataSource.manager) {
|
|
6968
|
+
return this.loadOrderOrFail(id, manager);
|
|
6969
|
+
}
|
|
6970
|
+
async create(input, manager = this.dataSource.manager) {
|
|
6971
|
+
if (!input.locationIds.length) {
|
|
6972
|
+
throw new common.BadRequestException('An inventory count needs at least one location in scope');
|
|
6973
|
+
}
|
|
6974
|
+
const repos = this.getRepositories(manager);
|
|
6975
|
+
const key = await this.helperService.getSeq(this.seqPrefix, manager);
|
|
6976
|
+
const order = await repos.order.save(repos.order.create({
|
|
6977
|
+
key,
|
|
6978
|
+
name: input.name,
|
|
6979
|
+
countDate: input.countDate,
|
|
6980
|
+
status: exports.InventoryCountStatus.PENDING,
|
|
6981
|
+
createdBy: input.createdBy ?? null,
|
|
6982
|
+
}));
|
|
6983
|
+
const scope = await this.expandLocationScope(input.locationIds, manager);
|
|
6984
|
+
await repos.scope.save(scope.map(({ id, isRoot }) => repos.scope.create({ orderId: order.id, locationId: id, isRoot })));
|
|
6985
|
+
await this.rebuildItems(order.id, manager);
|
|
6986
|
+
return order;
|
|
6987
|
+
}
|
|
6988
|
+
async update(id, input, manager = this.dataSource.manager) {
|
|
6989
|
+
const repos = this.getRepositories(manager);
|
|
6990
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
6991
|
+
// The design keeps the info panel editable only while nothing has been
|
|
6992
|
+
// counted; afterwards the sheet is already anchored to this scope and date.
|
|
6993
|
+
this.assertStatus(order, [exports.InventoryCountStatus.PENDING]);
|
|
6994
|
+
if (input.name !== undefined)
|
|
6995
|
+
order.name = input.name;
|
|
6996
|
+
if (input.countDate !== undefined)
|
|
6997
|
+
order.countDate = input.countDate;
|
|
6998
|
+
await repos.order.save(order);
|
|
6999
|
+
if (input.locationIds) {
|
|
7000
|
+
if (!input.locationIds.length) {
|
|
7001
|
+
throw new common.BadRequestException('An inventory count needs at least one location in scope');
|
|
7002
|
+
}
|
|
7003
|
+
await repos.scope.delete({ orderId: id });
|
|
7004
|
+
const scope = await this.expandLocationScope(input.locationIds, manager);
|
|
7005
|
+
await repos.scope.save(scope.map(({ id: locationId, isRoot }) => repos.scope.create({ orderId: id, locationId, isRoot })));
|
|
7006
|
+
await this.rebuildItems(id, manager);
|
|
7007
|
+
}
|
|
7008
|
+
return order;
|
|
7009
|
+
}
|
|
7010
|
+
/**
|
|
7011
|
+
* Freeze the ledger and open the sheet for counting.
|
|
7012
|
+
*
|
|
7013
|
+
* The rebuild here is the snapshot: from this point `bookQuantity` is what the
|
|
7014
|
+
* variance is measured against, and the lock keeps it true.
|
|
7015
|
+
*/
|
|
7016
|
+
async start(id, manager = this.dataSource.manager) {
|
|
7017
|
+
const repos = this.getRepositories(manager);
|
|
7018
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
7019
|
+
this.assertStatus(order, [exports.InventoryCountStatus.PENDING]);
|
|
7020
|
+
await this.rebuildItems(id, manager);
|
|
7021
|
+
order.status = exports.InventoryCountStatus.COUNTING;
|
|
7022
|
+
order.startedAt = new Date();
|
|
7023
|
+
await repos.order.save(order);
|
|
7024
|
+
return order;
|
|
7025
|
+
}
|
|
7026
|
+
/** Save counted quantities without touching stock ("暫存結果"). */
|
|
7027
|
+
async count(id, entries, manager = this.dataSource.manager) {
|
|
7028
|
+
const repos = this.getRepositories(manager);
|
|
7029
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
7030
|
+
this.assertStatus(order, [exports.InventoryCountStatus.COUNTING]);
|
|
7031
|
+
if (!entries.length) {
|
|
7032
|
+
return order;
|
|
7033
|
+
}
|
|
7034
|
+
const items = await repos.item.find({
|
|
7035
|
+
where: { orderId: id, id: typeorm.In(entries.map(({ itemId }) => itemId)) },
|
|
7036
|
+
});
|
|
7037
|
+
const byId = new Map(items.map((item) => [item.id, item]));
|
|
7038
|
+
for (const entry of entries) {
|
|
7039
|
+
const item = byId.get(entry.itemId);
|
|
7040
|
+
if (!item) {
|
|
7041
|
+
throw new common.NotFoundException(`Item ${entry.itemId} does not belong to inventory count order ${id}`);
|
|
7042
|
+
}
|
|
7043
|
+
if (entry.countedQuantity !== null &&
|
|
7044
|
+
(!Number.isFinite(entry.countedQuantity) || entry.countedQuantity < 0)) {
|
|
7045
|
+
throw new common.BadRequestException(`Counted quantity for item ${entry.itemId} must be a non-negative number`);
|
|
7046
|
+
}
|
|
7047
|
+
item.countedQuantity = entry.countedQuantity;
|
|
7048
|
+
if (entry.unitId !== undefined) {
|
|
7049
|
+
item.unitId = entry.unitId;
|
|
7050
|
+
}
|
|
7051
|
+
await repos.item.save(item);
|
|
7052
|
+
}
|
|
7053
|
+
return order;
|
|
7054
|
+
}
|
|
7055
|
+
/**
|
|
7056
|
+
* Add a line for stock the ledger has no record of (盤盈).
|
|
7057
|
+
*
|
|
7058
|
+
* The batch is resolved by key and created when it does not exist, which is
|
|
7059
|
+
* what makes "the batch field's default is editable" in the design work.
|
|
7060
|
+
*/
|
|
7061
|
+
async addItem(id, input, manager = this.dataSource.manager) {
|
|
7062
|
+
const repos = this.getRepositories(manager);
|
|
7063
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
7064
|
+
this.assertStatus(order, [exports.InventoryCountStatus.COUNTING]);
|
|
7065
|
+
if (!Number.isFinite(input.countedQuantity) || input.countedQuantity <= 0) {
|
|
7066
|
+
throw new common.BadRequestException('An added inventory count line needs a positive counted quantity');
|
|
7067
|
+
}
|
|
7068
|
+
const scoped = await this.scopedLocationIds(id, manager);
|
|
7069
|
+
// Settlement writes stock at this location, so it has to be one the order
|
|
7070
|
+
// locked — otherwise the count would adjust a position other operations are
|
|
7071
|
+
// still free to move.
|
|
7072
|
+
if (!scoped.includes(input.locationId)) {
|
|
7073
|
+
throw new common.BadRequestException(`Location ${input.locationId} is outside the scope of inventory count order ${id}`);
|
|
7074
|
+
}
|
|
7075
|
+
const batch = await this.batchService.getBatch({
|
|
7076
|
+
key: input.batchKey,
|
|
7077
|
+
materialId: input.materialId,
|
|
7078
|
+
manager,
|
|
7079
|
+
});
|
|
7080
|
+
return repos.item.save(repos.item.create({
|
|
7081
|
+
orderId: id,
|
|
7082
|
+
materialId: input.materialId,
|
|
7083
|
+
batchId: batch.id,
|
|
7084
|
+
locationId: input.locationId,
|
|
7085
|
+
loaderId: input.loaderId ?? null,
|
|
7086
|
+
unitId: input.unitId ?? null,
|
|
7087
|
+
bookQuantity: 0,
|
|
7088
|
+
countedQuantity: input.countedQuantity,
|
|
7089
|
+
isAddition: true,
|
|
7090
|
+
}));
|
|
7091
|
+
}
|
|
7092
|
+
/** Remove an added line. Scoped lines are part of the sheet and never removed. */
|
|
7093
|
+
async removeItem(id, itemId, manager = this.dataSource.manager) {
|
|
7094
|
+
const repos = this.getRepositories(manager);
|
|
7095
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
7096
|
+
this.assertStatus(order, [exports.InventoryCountStatus.COUNTING]);
|
|
7097
|
+
const item = await repos.item.findOneBy({ id: itemId, orderId: id });
|
|
7098
|
+
if (!item) {
|
|
7099
|
+
throw new common.NotFoundException(`Item ${itemId} does not belong to inventory count order ${id}`);
|
|
7100
|
+
}
|
|
7101
|
+
if (!item.isAddition) {
|
|
7102
|
+
throw new common.BadRequestException(`Item ${itemId} came from the counted scope and cannot be removed`);
|
|
7103
|
+
}
|
|
7104
|
+
await repos.item.delete({ id: itemId });
|
|
7105
|
+
return order;
|
|
7106
|
+
}
|
|
7107
|
+
/**
|
|
7108
|
+
* Throw the counting away and start over, without leaving the count.
|
|
7109
|
+
*
|
|
7110
|
+
* The scope stays locked and the status stays `COUNTING`: the point is a
|
|
7111
|
+
* re-measure after something went wrong on the floor, not an abandonment. The
|
|
7112
|
+
* book snapshot is deliberately *not* retaken — the lock means it has not
|
|
7113
|
+
* moved.
|
|
7114
|
+
*/
|
|
7115
|
+
async reset(id, manager = this.dataSource.manager) {
|
|
7116
|
+
const repos = this.getRepositories(manager);
|
|
7117
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
7118
|
+
this.assertStatus(order, [exports.InventoryCountStatus.COUNTING]);
|
|
7119
|
+
await repos.item.delete({ orderId: id, isAddition: true });
|
|
7120
|
+
await repos.item.update({ orderId: id }, { countedQuantity: null, unitId: null });
|
|
7121
|
+
return order;
|
|
7122
|
+
}
|
|
7123
|
+
async cancel(id, manager = this.dataSource.manager) {
|
|
7124
|
+
const repos = this.getRepositories(manager);
|
|
7125
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
7126
|
+
this.assertStatus(order, [
|
|
7127
|
+
exports.InventoryCountStatus.PENDING,
|
|
7128
|
+
exports.InventoryCountStatus.COUNTING,
|
|
7129
|
+
]);
|
|
7130
|
+
order.status = exports.InventoryCountStatus.CANCELLED;
|
|
7131
|
+
order.cancelledAt = new Date();
|
|
7132
|
+
await repos.order.save(order);
|
|
7133
|
+
return order;
|
|
7134
|
+
}
|
|
7135
|
+
/**
|
|
7136
|
+
* Adjust the ledger to the counted reality ("執行盤差").
|
|
7137
|
+
*
|
|
7138
|
+
* Runs in one transaction and is awaited end to end, so the mutation
|
|
7139
|
+
* interceptor's post-commit guarantee holds: every `stock.count-gained` /
|
|
7140
|
+
* `stock.count-lost` event fires only after the adjustments are durable.
|
|
7141
|
+
*
|
|
7142
|
+
* Uncounted lines are left alone — "not counted" is not "counted as zero", and
|
|
7143
|
+
* treating it as zero would wipe out stock nobody looked at.
|
|
7144
|
+
*/
|
|
7145
|
+
async settle(id, outerManager) {
|
|
7146
|
+
const run = async (manager) => {
|
|
7147
|
+
const repos = this.getRepositories(manager);
|
|
7148
|
+
const order = await this.loadOrderOrFail(id, manager);
|
|
7149
|
+
this.assertStatus(order, [exports.InventoryCountStatus.COUNTING]);
|
|
7150
|
+
const items = await repos.item.find({ where: { orderId: id } });
|
|
7151
|
+
for (const item of items) {
|
|
7152
|
+
if (item.countedQuantity === null) {
|
|
7153
|
+
continue;
|
|
7154
|
+
}
|
|
7155
|
+
const conversionFactor = await this.materialService.getConversionFactor(item.materialId, item.unitId ?? undefined);
|
|
7156
|
+
const counted = Number(item.countedQuantity) * conversionFactor;
|
|
7157
|
+
const delta = counted - Number(item.bookQuantity);
|
|
7158
|
+
if (delta === 0) {
|
|
7159
|
+
continue;
|
|
7160
|
+
}
|
|
7161
|
+
const baseOrder = await repos.baseOrder.save({});
|
|
7162
|
+
await repos.change.save(repos.change.create({
|
|
7163
|
+
item,
|
|
7164
|
+
order: baseOrder,
|
|
7165
|
+
quantityChanged: delta,
|
|
7166
|
+
}));
|
|
7167
|
+
await repos.stock.save(repos.stock.create({
|
|
7168
|
+
orderId: baseOrder.id,
|
|
7169
|
+
materialId: item.materialId,
|
|
7170
|
+
batchId: item.batchId,
|
|
7171
|
+
locationId: this.stockService.resolveLocationId(item.locationId),
|
|
7172
|
+
loaderId: this.stockService.resolveLoaderId(item.loaderId),
|
|
7173
|
+
quantity: delta,
|
|
7174
|
+
}));
|
|
7175
|
+
}
|
|
7176
|
+
order.status = exports.InventoryCountStatus.COMPLETED;
|
|
7177
|
+
order.settledAt = new Date();
|
|
7178
|
+
await repos.order.save(order);
|
|
7179
|
+
return order;
|
|
7180
|
+
};
|
|
7181
|
+
return outerManager
|
|
7182
|
+
? run(outerManager)
|
|
7183
|
+
: this.dataSource.transaction((manager) => run(manager));
|
|
7184
|
+
}
|
|
7185
|
+
};
|
|
7186
|
+
exports.InventoryCountOrderService = tslib.__decorate([
|
|
7187
|
+
common.Injectable(),
|
|
7188
|
+
tslib.__param(6, common.Inject(InventoryCountOrderEntity)),
|
|
7189
|
+
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
7190
|
+
exports.WmsEntities,
|
|
7191
|
+
exports.HelperService,
|
|
7192
|
+
exports.MaterialService,
|
|
7193
|
+
exports.StockService,
|
|
7194
|
+
exports.BatchService, Object])
|
|
7195
|
+
], exports.InventoryCountOrderService);
|
|
7196
|
+
|
|
6326
7197
|
exports.ScrapeService = class ScrapeService {
|
|
6327
7198
|
dataSource;
|
|
7199
|
+
entities;
|
|
6328
7200
|
helperService;
|
|
6329
7201
|
materialService;
|
|
6330
7202
|
stockService;
|
|
6331
7203
|
scrapeOrderEntity;
|
|
6332
7204
|
stockEntity;
|
|
6333
7205
|
seqPrefix = 'SCR';
|
|
6334
|
-
constructor(dataSource, helperService, materialService, stockService, scrapeOrderEntity, stockEntity) {
|
|
7206
|
+
constructor(dataSource, entities, helperService, materialService, stockService, scrapeOrderEntity, stockEntity) {
|
|
6335
7207
|
this.dataSource = dataSource;
|
|
7208
|
+
this.entities = entities;
|
|
6336
7209
|
this.helperService = helperService;
|
|
6337
7210
|
this.materialService = materialService;
|
|
6338
7211
|
this.stockService = stockService;
|
|
@@ -6344,7 +7217,7 @@ exports.ScrapeService = class ScrapeService {
|
|
|
6344
7217
|
scrapeOrder: manager.getRepository(this.scrapeOrderEntity),
|
|
6345
7218
|
scrapeOrderItem: manager.getRepository(exports.ScrapeOrderItemEntityClass),
|
|
6346
7219
|
scrapeOrderChange: manager.getRepository(exports.ScrapeOrderChangeEntityClass),
|
|
6347
|
-
order: manager.getRepository(
|
|
7220
|
+
order: manager.getRepository(this.entities.order),
|
|
6348
7221
|
stock: manager.getRepository(this.stockEntity),
|
|
6349
7222
|
};
|
|
6350
7223
|
}
|
|
@@ -6397,9 +7270,10 @@ exports.ScrapeService = class ScrapeService {
|
|
|
6397
7270
|
};
|
|
6398
7271
|
exports.ScrapeService = tslib.__decorate([
|
|
6399
7272
|
common.Injectable(),
|
|
6400
|
-
tslib.__param(
|
|
6401
|
-
tslib.__param(
|
|
7273
|
+
tslib.__param(5, common.Inject(ScrapeOrderEntity)),
|
|
7274
|
+
tslib.__param(6, common.Inject(StockEntity)),
|
|
6402
7275
|
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
7276
|
+
exports.WmsEntities,
|
|
6403
7277
|
exports.HelperService,
|
|
6404
7278
|
exports.MaterialService,
|
|
6405
7279
|
exports.StockService, Object, Object])
|
|
@@ -6407,20 +7281,31 @@ exports.ScrapeService = tslib.__decorate([
|
|
|
6407
7281
|
|
|
6408
7282
|
exports.WarehouseMapDataService = class WarehouseMapDataService {
|
|
6409
7283
|
dataSource;
|
|
7284
|
+
entities;
|
|
6410
7285
|
defaultMapDataKey = 'DEFAULT_MAP_DATA_KEY';
|
|
6411
7286
|
warehouseMapDataRepository;
|
|
6412
|
-
constructor(dataSource) {
|
|
7287
|
+
constructor(dataSource, entities) {
|
|
6413
7288
|
this.dataSource = dataSource;
|
|
6414
|
-
this.
|
|
6415
|
-
|
|
7289
|
+
this.entities = entities;
|
|
7290
|
+
this.warehouseMapDataRepository = this.dataSource.getRepository(this.entities.warehouseMap);
|
|
6416
7291
|
}
|
|
6417
|
-
|
|
6418
|
-
|
|
7292
|
+
/**
|
|
7293
|
+
* Seed the default map row.
|
|
7294
|
+
*
|
|
7295
|
+
* `async` on purpose: Nest awaits a returned promise, so bootstrap does not
|
|
7296
|
+
* complete until the seed transaction has committed. Firing it off without
|
|
7297
|
+
* awaiting used to leave a transaction in flight after `app.init()` resolved
|
|
7298
|
+
* — an app that shut down promptly (a test, a short-lived worker) destroyed
|
|
7299
|
+
* the pool underneath it and the rejection surfaced as an unhandled
|
|
7300
|
+
* `QueryFailedError: Connection terminated` that killed the process.
|
|
7301
|
+
*/
|
|
7302
|
+
async onApplicationBootstrap() {
|
|
7303
|
+
await this.dataSource.transaction(async (manager) => {
|
|
6419
7304
|
const defaultMapData = await manager
|
|
6420
|
-
.getRepository(
|
|
7305
|
+
.getRepository(this.entities.warehouseMap)
|
|
6421
7306
|
.findOneBy({ id: this.defaultMapDataKey });
|
|
6422
7307
|
if (!defaultMapData) {
|
|
6423
|
-
await manager.getRepository(
|
|
7308
|
+
await manager.getRepository(this.entities.warehouseMap).save(manager.getRepository(this.entities.warehouseMap).create({
|
|
6424
7309
|
id: this.defaultMapDataKey,
|
|
6425
7310
|
mapData: {
|
|
6426
7311
|
id: this.defaultMapDataKey,
|
|
@@ -6434,7 +7319,8 @@ exports.WarehouseMapDataService = class WarehouseMapDataService {
|
|
|
6434
7319
|
};
|
|
6435
7320
|
exports.WarehouseMapDataService = tslib.__decorate([
|
|
6436
7321
|
common.Injectable(),
|
|
6437
|
-
tslib.__metadata("design:paramtypes", [typeorm.DataSource
|
|
7322
|
+
tslib.__metadata("design:paramtypes", [typeorm.DataSource,
|
|
7323
|
+
exports.WmsEntities])
|
|
6438
7324
|
], exports.WarehouseMapDataService);
|
|
6439
7325
|
|
|
6440
7326
|
/** DI token holding the resolved {@link WmsEventModuleOptions}. */
|
|
@@ -6481,6 +7367,10 @@ const TABLE_TO_CHANGE_TYPE = new Map([
|
|
|
6481
7367
|
['merge_batch_order_changes', () => exports.ChangeType.MERGED],
|
|
6482
7368
|
['reclassify_inventory_order_changes', () => exports.ChangeType.RECLASSIFIED],
|
|
6483
7369
|
['scrape_order_changes', () => exports.ChangeType.SCRAPED],
|
|
7370
|
+
[
|
|
7371
|
+
'inventory_count_order_changes',
|
|
7372
|
+
(q) => (q > 0 ? exports.ChangeType.COUNT_GAINED : exports.ChangeType.COUNT_LOST),
|
|
7373
|
+
],
|
|
6484
7374
|
]);
|
|
6485
7375
|
const CHANGE_TYPE_TO_EVENT = {
|
|
6486
7376
|
[exports.ChangeType.RECEIVED]: 'stock.received',
|
|
@@ -6500,6 +7390,8 @@ const CHANGE_TYPE_TO_EVENT = {
|
|
|
6500
7390
|
[exports.ChangeType.DEALLOCATED]: 'stock.deallocated',
|
|
6501
7391
|
[exports.ChangeType.RECLASSIFIED]: 'stock.reclassified',
|
|
6502
7392
|
[exports.ChangeType.SCRAPED]: 'stock.scraped',
|
|
7393
|
+
[exports.ChangeType.COUNT_GAINED]: 'stock.count-gained',
|
|
7394
|
+
[exports.ChangeType.COUNT_LOST]: 'stock.count-lost',
|
|
6503
7395
|
};
|
|
6504
7396
|
const QUALITY_INSPECTION_TABLE = 'quality_inspection_order_changes';
|
|
6505
7397
|
/**
|
|
@@ -6600,36 +7492,175 @@ StockChangeSubscriber = tslib.__decorate([
|
|
|
6600
7492
|
exports.WmsEventCollector, Object])
|
|
6601
7493
|
], StockChangeSubscriber);
|
|
6602
7494
|
|
|
7495
|
+
/** The count's own settlement writes here; it must never lock itself out. */
|
|
7496
|
+
const INVENTORY_COUNT_CHANGE_TABLE = 'inventory_count_order_changes';
|
|
7497
|
+
/**
|
|
7498
|
+
* Refuse stock movements in locations a running inventory count has locked.
|
|
7499
|
+
*
|
|
7500
|
+
* Starting a count snapshots the ledger for its scope. That snapshot is what the
|
|
7501
|
+
* variance is measured against, so it has to stay true: if a transfer or a
|
|
7502
|
+
* shipment moved stock in the meantime, settlement would post the difference
|
|
7503
|
+
* between "what we counted" and "what the books said an hour ago" — silently
|
|
7504
|
+
* writing off someone else's legitimate movement.
|
|
7505
|
+
*
|
|
7506
|
+
* Why a subscriber rather than a check in each service
|
|
7507
|
+
* ---------------------------------------------------
|
|
7508
|
+
* Every stock movement in this package, without exception, ends in a row on some
|
|
7509
|
+
* `*_order_change` table — that is the same property `StockChangeSubscriber`
|
|
7510
|
+
* relies on to collect `stock.*` events without touching a single service. Doing
|
|
7511
|
+
* the lock check at the same choke point means:
|
|
7512
|
+
*
|
|
7513
|
+
* - the twelve domain services stay untouched;
|
|
7514
|
+
* - any future path that writes a change row is covered automatically;
|
|
7515
|
+
* - a consumer calling a service **directly**, bypassing the resolvers, is
|
|
7516
|
+
* covered too — which is exactly the case that matters, because a host with
|
|
7517
|
+
* its own inbound flow does precisely that.
|
|
7518
|
+
*
|
|
7519
|
+
* The check costs one indexed lookup per change row. That is deliberate: caching
|
|
7520
|
+
* the locked set would open a window right after `start()` in which a movement
|
|
7521
|
+
* slips through, and a lock with a window is not a lock.
|
|
7522
|
+
*/
|
|
7523
|
+
exports.InventoryCountLockSubscriber = class InventoryCountLockSubscriber {
|
|
7524
|
+
constructor(dataSource) {
|
|
7525
|
+
dataSource.subscribers.push(this);
|
|
7526
|
+
}
|
|
7527
|
+
async beforeInsert(event) {
|
|
7528
|
+
const tableName = event.metadata.tableName;
|
|
7529
|
+
if (tableName === INVENTORY_COUNT_CHANGE_TABLE ||
|
|
7530
|
+
!tableName.endsWith('_order_changes')) {
|
|
7531
|
+
return;
|
|
7532
|
+
}
|
|
7533
|
+
const locationId = await this.resolveLocationId(event);
|
|
7534
|
+
if (!locationId) {
|
|
7535
|
+
// split / merge / reclassify items carry no location. They still move
|
|
7536
|
+
// stock, but only within a position the caller already named elsewhere;
|
|
7537
|
+
// there is nothing to match against the scope here.
|
|
7538
|
+
return;
|
|
7539
|
+
}
|
|
7540
|
+
const locks = await event.manager.query(`SELECT o."key"
|
|
7541
|
+
FROM inventory_count_order_locations l
|
|
7542
|
+
JOIN inventory_count_orders o ON o.id = l."orderId"
|
|
7543
|
+
WHERE l."locationId" = $1
|
|
7544
|
+
AND o.status = 'COUNTING'
|
|
7545
|
+
LIMIT 1`, [locationId]);
|
|
7546
|
+
if (!locks.length) {
|
|
7547
|
+
return;
|
|
7548
|
+
}
|
|
7549
|
+
// Naming the order is the difference between an operator who can go and
|
|
7550
|
+
// settle the count and one who just sees "denied".
|
|
7551
|
+
throw new common.ConflictException(`Location ${locationId} is locked by inventory count order ${locks[0].key}; finish or cancel that count before moving this stock.`);
|
|
7552
|
+
}
|
|
7553
|
+
/**
|
|
7554
|
+
* The location the change ultimately touches, taken from the change's order
|
|
7555
|
+
* item. `beforeInsert` may see the relation either already flattened to
|
|
7556
|
+
* `itemId` or still as the item object, depending on how the caller built the
|
|
7557
|
+
* row, so both are accepted.
|
|
7558
|
+
*/
|
|
7559
|
+
async resolveLocationId(event) {
|
|
7560
|
+
const entity = event.entity;
|
|
7561
|
+
if (!entity) {
|
|
7562
|
+
return null;
|
|
7563
|
+
}
|
|
7564
|
+
if (entity.item && entity.item.locationId !== undefined) {
|
|
7565
|
+
return entity.item.locationId;
|
|
7566
|
+
}
|
|
7567
|
+
const itemId = entity.itemId ?? entity.item?.id;
|
|
7568
|
+
if (!itemId) {
|
|
7569
|
+
return null;
|
|
7570
|
+
}
|
|
7571
|
+
const itemRelation = event.metadata.relations.find((relation) => relation.propertyName === 'item');
|
|
7572
|
+
if (!itemRelation) {
|
|
7573
|
+
return null;
|
|
7574
|
+
}
|
|
7575
|
+
const item = await event.manager
|
|
7576
|
+
.getRepository(itemRelation.inverseEntityMetadata.target)
|
|
7577
|
+
.findOne({ where: { id: itemId } });
|
|
7578
|
+
return item?.locationId ?? null;
|
|
7579
|
+
}
|
|
7580
|
+
};
|
|
7581
|
+
exports.InventoryCountLockSubscriber = tslib.__decorate([
|
|
7582
|
+
common.Injectable(),
|
|
7583
|
+
tslib.__param(0, typeorm$1.InjectDataSource()),
|
|
7584
|
+
tslib.__metadata("design:paramtypes", [typeorm.DataSource])
|
|
7585
|
+
], exports.InventoryCountLockSubscriber);
|
|
7586
|
+
|
|
6603
7587
|
var WmsModuleCoreModule_1;
|
|
6604
7588
|
/**
|
|
6605
|
-
*
|
|
6606
|
-
*
|
|
6607
|
-
* `MaterialEntityClass`.
|
|
7589
|
+
* The entity Symbols a consumer can rebind, each paired with the base module's
|
|
7590
|
+
* token carrying their replacement and the class it falls back to.
|
|
6608
7591
|
*
|
|
6609
|
-
*
|
|
6610
|
-
*
|
|
6611
|
-
*
|
|
6612
|
-
*
|
|
6613
|
-
*
|
|
6614
|
-
*
|
|
6615
|
-
* base module resolved: both are derived from the same option.
|
|
7592
|
+
* These Symbols are how the whole package reaches an entity — no service,
|
|
7593
|
+
* DataLoader or query imports the class directly — so rebinding one here swaps
|
|
7594
|
+
* that entity everywhere at once. Resolution happens at injection time, from
|
|
7595
|
+
* tokens `WMSBaseModule` derives from its own options, which means an override
|
|
7596
|
+
* may arrive from `forRoot` or from an async options factory alike and cannot
|
|
7597
|
+
* drift from the repository the base module resolved: both come from one option.
|
|
6616
7598
|
*/
|
|
6617
|
-
const
|
|
6618
|
-
|
|
7599
|
+
const OVERRIDABLE_ENTITIES = [
|
|
7600
|
+
{
|
|
7601
|
+
option: 'materialEntity',
|
|
7602
|
+
token: MaterialEntity,
|
|
7603
|
+
provide: wmsBaseNestjsModule.PROVIDE_MATERIAL_ENTITY,
|
|
7604
|
+
fallback: exports.MaterialEntityClass,
|
|
7605
|
+
requires: 'description / baseUnit / isActive',
|
|
7606
|
+
},
|
|
7607
|
+
{
|
|
7608
|
+
option: 'batchEntity',
|
|
7609
|
+
token: BatchEntity,
|
|
7610
|
+
provide: wmsBaseNestjsModule.PROVIDE_BATCH_ENTITY,
|
|
7611
|
+
fallback: exports.BatchEntityClass,
|
|
7612
|
+
},
|
|
7613
|
+
{
|
|
7614
|
+
option: 'locationEntity',
|
|
7615
|
+
token: LocationEntity,
|
|
7616
|
+
provide: wmsBaseNestjsModule.PROVIDE_LOCATION_ENTITY,
|
|
7617
|
+
fallback: exports.LocationEntityClass,
|
|
7618
|
+
requires: 'description / isActive',
|
|
7619
|
+
},
|
|
7620
|
+
{
|
|
7621
|
+
option: 'stockEntity',
|
|
7622
|
+
token: StockEntity,
|
|
7623
|
+
provide: wmsBaseNestjsModule.PROVIDE_STOCK_ENTITY,
|
|
7624
|
+
fallback: exports.StockEntityClass,
|
|
7625
|
+
requires: 'loaderId / rollbackedAt',
|
|
7626
|
+
},
|
|
7627
|
+
{
|
|
7628
|
+
option: 'orderEntity',
|
|
7629
|
+
token: OrderEntity,
|
|
7630
|
+
provide: wmsBaseNestjsModule.PROVIDE_ORDER_ENTITY,
|
|
7631
|
+
fallback: wmsBaseNestjsModule.OrderEntity,
|
|
7632
|
+
},
|
|
7633
|
+
{
|
|
7634
|
+
option: 'warehouseMapEntity',
|
|
7635
|
+
token: WarehouseMapEntity,
|
|
7636
|
+
provide: wmsBaseNestjsModule.PROVIDE_WAREHOUSE_MAP_ENTITY,
|
|
7637
|
+
fallback: warehouseMap_entity.WarehouseMapEntity,
|
|
7638
|
+
},
|
|
7639
|
+
];
|
|
7640
|
+
const entityProviders = OVERRIDABLE_ENTITIES.map(({ option, token, provide, fallback, requires }) => ({
|
|
7641
|
+
provide: token,
|
|
6619
7642
|
useFactory: (configured) => {
|
|
6620
|
-
if (!configured)
|
|
6621
|
-
return
|
|
6622
|
-
// `WMSBaseModuleOptions` only asks for a child of the base
|
|
6623
|
-
//
|
|
6624
|
-
//
|
|
6625
|
-
//
|
|
6626
|
-
//
|
|
6627
|
-
if (!(configured.prototype instanceof
|
|
6628
|
-
throw new Error(`WmsModuleCoreModule:
|
|
7643
|
+
if (!configured || configured === fallback)
|
|
7644
|
+
return fallback;
|
|
7645
|
+
// `WMSBaseModuleOptions` only asks for a child of the *base* entity, but
|
|
7646
|
+
// this package reads the columns its own subclass adds. TypeScript's
|
|
7647
|
+
// structural typing happily accepts a sibling that never declares them,
|
|
7648
|
+
// which then surfaces as a missing column mid-query — a much worse error
|
|
7649
|
+
// to work backwards from than this one.
|
|
7650
|
+
if (!(configured.prototype instanceof fallback))
|
|
7651
|
+
throw new Error(`WmsModuleCoreModule: ${option} "${configured.name}" must extend ${fallback.name} (a @ChildEntity() of it)${requires
|
|
7652
|
+
? `. @rytass/wms-module-core reads ${requires} from it, which the base entity does not declare`
|
|
7653
|
+
: ''}.`);
|
|
6629
7654
|
return configured;
|
|
6630
7655
|
},
|
|
6631
|
-
inject: [
|
|
6632
|
-
};
|
|
7656
|
+
inject: [provide],
|
|
7657
|
+
}));
|
|
7658
|
+
/** Bound after {@link entityProviders}, since it reads every one of them. */
|
|
7659
|
+
const resolvedEntityProviders = [...entityProviders, exports.WmsEntities];
|
|
7660
|
+
const exportedEntityTokens = [
|
|
7661
|
+
...OVERRIDABLE_ENTITIES.map(({ token }) => token),
|
|
7662
|
+
exports.WmsEntities,
|
|
7663
|
+
];
|
|
6633
7664
|
const exportDependencies = [
|
|
6634
7665
|
exports.LoaderService,
|
|
6635
7666
|
exports.MaterialService,
|
|
@@ -6650,6 +7681,7 @@ const exportDependencies = [
|
|
|
6650
7681
|
exports.MergeBatchOrderService,
|
|
6651
7682
|
exports.ReclassifyInventoryOrderService,
|
|
6652
7683
|
exports.ScrapeService,
|
|
7684
|
+
exports.InventoryCountOrderService,
|
|
6653
7685
|
exports.QualityInspectionOrderService,
|
|
6654
7686
|
exports.WarehouseMapDataService,
|
|
6655
7687
|
];
|
|
@@ -6662,15 +7694,19 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule
|
|
|
6662
7694
|
providers: [
|
|
6663
7695
|
...exportDependencies,
|
|
6664
7696
|
StockChangeSubscriber,
|
|
6665
|
-
|
|
7697
|
+
exports.InventoryCountLockSubscriber,
|
|
7698
|
+
...resolvedEntityProviders,
|
|
6666
7699
|
{ provide: WMS_CORE_MODULE_OPTIONS, useValue: coreOptions },
|
|
6667
|
-
{
|
|
7700
|
+
{
|
|
7701
|
+
provide: WMS_STOCK_ENRICH,
|
|
7702
|
+
useValue: !!coreOptions.enrichStockEvents,
|
|
7703
|
+
},
|
|
6668
7704
|
],
|
|
6669
7705
|
exports: [
|
|
6670
7706
|
...exportDependencies,
|
|
6671
7707
|
coreModule,
|
|
6672
7708
|
ModelsModule,
|
|
6673
|
-
|
|
7709
|
+
...exportedEntityTokens,
|
|
6674
7710
|
WMS_CORE_MODULE_OPTIONS,
|
|
6675
7711
|
],
|
|
6676
7712
|
};
|
|
@@ -6684,7 +7720,8 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule
|
|
|
6684
7720
|
providers: [
|
|
6685
7721
|
...exportDependencies,
|
|
6686
7722
|
StockChangeSubscriber,
|
|
6687
|
-
|
|
7723
|
+
exports.InventoryCountLockSubscriber,
|
|
7724
|
+
...resolvedEntityProviders,
|
|
6688
7725
|
{
|
|
6689
7726
|
provide: WMS_CORE_MODULE_OPTIONS,
|
|
6690
7727
|
useValue: {
|
|
@@ -6699,7 +7736,7 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule
|
|
|
6699
7736
|
...exportDependencies,
|
|
6700
7737
|
coreModule,
|
|
6701
7738
|
ModelsModule,
|
|
6702
|
-
|
|
7739
|
+
...exportedEntityTokens,
|
|
6703
7740
|
WMS_CORE_MODULE_OPTIONS,
|
|
6704
7741
|
],
|
|
6705
7742
|
};
|
|
@@ -6711,6 +7748,71 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = tslib.__decorate([
|
|
|
6711
7748
|
})
|
|
6712
7749
|
], exports.WmsModuleCoreModule);
|
|
6713
7750
|
|
|
7751
|
+
/**
|
|
7752
|
+
* Runtime counterpart of {@link WmsOperationName}. Iterate it to build a UI, to
|
|
7753
|
+
* diff against a host's own allow-list, or to assert the invariant above.
|
|
7754
|
+
*/
|
|
7755
|
+
const WMS_OPERATION_NAMES = [
|
|
7756
|
+
'allocate-inventory-order:create',
|
|
7757
|
+
'allocate-inventory-order:deallocate',
|
|
7758
|
+
'allocate-inventory-order:read',
|
|
7759
|
+
'allocate-inventory-order:update',
|
|
7760
|
+
'batch:merge',
|
|
7761
|
+
'batch:read',
|
|
7762
|
+
'batch:split',
|
|
7763
|
+
'hold-inventory-order:create',
|
|
7764
|
+
'hold-inventory-order:read',
|
|
7765
|
+
'hold-inventory-order:release',
|
|
7766
|
+
'hold-inventory-order:update',
|
|
7767
|
+
'inventory-count-order:add-item',
|
|
7768
|
+
'inventory-count-order:cancel',
|
|
7769
|
+
'inventory-count-order:count',
|
|
7770
|
+
'inventory-count-order:create',
|
|
7771
|
+
'inventory-count-order:read',
|
|
7772
|
+
'inventory-count-order:remove-item',
|
|
7773
|
+
'inventory-count-order:reset',
|
|
7774
|
+
'inventory-count-order:settle',
|
|
7775
|
+
'inventory-count-order:start',
|
|
7776
|
+
'inventory-count-order:update',
|
|
7777
|
+
'loader:create',
|
|
7778
|
+
'loader:read',
|
|
7779
|
+
'loader:update',
|
|
7780
|
+
'location:create',
|
|
7781
|
+
'location:read',
|
|
7782
|
+
'location:update',
|
|
7783
|
+
'material:create',
|
|
7784
|
+
'material:read',
|
|
7785
|
+
'material:update',
|
|
7786
|
+
'quality-inspection-order:inspect',
|
|
7787
|
+
'receive-inventory-order:create',
|
|
7788
|
+
'receive-inventory-order:read',
|
|
7789
|
+
'receive-inventory-order:receive',
|
|
7790
|
+
'receive-inventory-order:update',
|
|
7791
|
+
'reclassify-inventory-order:reclassify',
|
|
7792
|
+
'sale-order:read',
|
|
7793
|
+
'scrape-order:scrape',
|
|
7794
|
+
'ship-inventory-order:cancel',
|
|
7795
|
+
'ship-inventory-order:create',
|
|
7796
|
+
'ship-inventory-order:read',
|
|
7797
|
+
'ship-inventory-order:ship',
|
|
7798
|
+
'ship-inventory-order:update',
|
|
7799
|
+
'stock:read',
|
|
7800
|
+
'transfer-customer-order:create',
|
|
7801
|
+
'transfer-customer-order:return',
|
|
7802
|
+
'transfer-customer-order:update',
|
|
7803
|
+
'transfer-order:cancel',
|
|
7804
|
+
'transfer-order:create',
|
|
7805
|
+
'transfer-order:read',
|
|
7806
|
+
'transfer-order:transfer',
|
|
7807
|
+
'transfer-order:update',
|
|
7808
|
+
'transfer-vendor-order:create',
|
|
7809
|
+
'transfer-vendor-order:return',
|
|
7810
|
+
'transfer-vendor-order:update',
|
|
7811
|
+
'unit:read',
|
|
7812
|
+
'warehouse-map:read',
|
|
7813
|
+
'warehouse-map:update',
|
|
7814
|
+
];
|
|
7815
|
+
|
|
6714
7816
|
var WmsEventDispatcher_1;
|
|
6715
7817
|
/**
|
|
6716
7818
|
* Central event dispatcher. Runs consumer before-hooks (which may veto) and,
|
|
@@ -6769,6 +7871,10 @@ exports.WmsEventDispatcher = WmsEventDispatcher_1 = tslib.__decorate([
|
|
|
6769
7871
|
tslib.__metadata("design:paramtypes", [Object, Object])
|
|
6770
7872
|
], exports.WmsEventDispatcher);
|
|
6771
7873
|
|
|
7874
|
+
Object.defineProperty(exports, "OrderEntityClass", {
|
|
7875
|
+
enumerable: true,
|
|
7876
|
+
get: function () { return wmsBaseNestjsModule.OrderEntity; }
|
|
7877
|
+
});
|
|
6772
7878
|
exports.AllocateInventoryOrderChangeEntity = AllocateInventoryOrderChangeEntity;
|
|
6773
7879
|
exports.AllocateInventoryOrderEntity = AllocateInventoryOrderEntity;
|
|
6774
7880
|
exports.AllocateInventoryOrderItemEntity = AllocateInventoryOrderItemEntity;
|
|
@@ -6777,6 +7883,10 @@ exports.BatchGroupEntity = BatchGroupEntity;
|
|
|
6777
7883
|
exports.HoldInventoryOrderChangeEntity = HoldInventoryOrderChangeEntity;
|
|
6778
7884
|
exports.HoldInventoryOrderEntity = HoldInventoryOrderEntity;
|
|
6779
7885
|
exports.HoldInventoryOrderItemEntity = HoldInventoryOrderItemEntity;
|
|
7886
|
+
exports.InventoryCountOrderChangeEntity = InventoryCountOrderChangeEntity;
|
|
7887
|
+
exports.InventoryCountOrderEntity = InventoryCountOrderEntity;
|
|
7888
|
+
exports.InventoryCountOrderItemEntity = InventoryCountOrderItemEntity;
|
|
7889
|
+
exports.InventoryCountOrderLocationEntity = InventoryCountOrderLocationEntity;
|
|
6780
7890
|
exports.LoaderTypeEntity = LoaderTypeEntity;
|
|
6781
7891
|
exports.LoaderUnitEntity = LoaderUnitEntity;
|
|
6782
7892
|
exports.LoadersEntity = LoadersEntity;
|
|
@@ -6786,6 +7896,7 @@ exports.MaterialUnitEntity = MaterialUnitEntity;
|
|
|
6786
7896
|
exports.MergeBatchOrderChangeEntity = MergeBatchOrderChangeEntity;
|
|
6787
7897
|
exports.MergeBatchOrderEntity = MergeBatchOrderEntity;
|
|
6788
7898
|
exports.MergeBatchOrderItemEntity = MergeBatchOrderItemEntity;
|
|
7899
|
+
exports.OrderEntity = OrderEntity;
|
|
6789
7900
|
exports.QualityInspectionOrderChangeEntity = QualityInspectionOrderChangeEntity;
|
|
6790
7901
|
exports.QualityInspectionOrderEntity = QualityInspectionOrderEntity;
|
|
6791
7902
|
exports.QualityInspectionOrderItemEntity = QualityInspectionOrderItemEntity;
|
|
@@ -6821,6 +7932,7 @@ exports.WMS_ACTOR_EXTRACTOR = WMS_ACTOR_EXTRACTOR;
|
|
|
6821
7932
|
exports.WMS_CORE_MODULE_OPTIONS = WMS_CORE_MODULE_OPTIONS;
|
|
6822
7933
|
exports.WMS_EVENT_EMITTER_BRIDGE = WMS_EVENT_EMITTER_BRIDGE;
|
|
6823
7934
|
exports.WMS_EVENT_OPTIONS = WMS_EVENT_OPTIONS;
|
|
7935
|
+
exports.WMS_OPERATION_NAMES = WMS_OPERATION_NAMES;
|
|
6824
7936
|
exports.WMS_STOCK_ENRICH = WMS_STOCK_ENRICH;
|
|
6825
7937
|
exports.WarehouseMapEntity = WarehouseMapEntity;
|
|
6826
7938
|
exports.collectToScope = collectToScope;
|