@things-factory/sales-base 4.0.10 → 4.0.14
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/dist-server/constants/order.js +9 -1
- package/dist-server/constants/order.js.map +1 -1
- package/dist-server/constants/validation-error-code.js +2 -1
- package/dist-server/constants/validation-error-code.js.map +1 -1
- package/dist-server/controllers/ecommerce/sellercraft-controller.js +3 -3
- package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js +21 -0
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-query.js +74 -77
- package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
- package/dist-server/service/delivery-order/delivery-order-query.js +21 -5
- package/dist-server/service/delivery-order/delivery-order-query.js.map +1 -1
- package/dist-server/service/goods-receival-note/goods-receival-note-query.js +93 -43
- package/dist-server/service/goods-receival-note/goods-receival-note-query.js.map +1 -1
- package/dist-server/service/index.js +4 -0
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/manifest/index.js +9 -0
- package/dist-server/service/manifest/index.js.map +1 -0
- package/dist-server/service/manifest/manifest-mutation.js +111 -0
- package/dist-server/service/manifest/manifest-mutation.js.map +1 -0
- package/dist-server/service/manifest/manifest-query.js +128 -0
- package/dist-server/service/manifest/manifest-query.js.map +1 -0
- package/dist-server/service/manifest/manifest-type.js +125 -0
- package/dist-server/service/manifest/manifest-type.js.map +1 -0
- package/dist-server/service/manifest/manifest.js +122 -0
- package/dist-server/service/manifest/manifest.js.map +1 -0
- package/dist-server/service/order-inventory/order-inventory-mutation.js +24 -0
- package/dist-server/service/order-inventory/order-inventory-mutation.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-query.js +20 -19
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-types.js +17 -13
- package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory.js +24 -2
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
- package/dist-server/service/others/other-query.js +1 -0
- package/dist-server/service/others/other-query.js.map +1 -1
- package/dist-server/service/others/other-types.js +4 -0
- package/dist-server/service/others/other-types.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +393 -1
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +160 -0
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-types.js +34 -2
- package/dist-server/service/release-good/release-good-types.js.map +1 -1
- package/dist-server/service/release-good/release-good.js +28 -1
- package/dist-server/service/release-good/release-good.js.map +1 -1
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-mutation.js +110 -30
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-mutation.js.map +1 -1
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-query.js +94 -21
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-query.js.map +1 -1
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-type.js +144 -1
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-type.js.map +1 -1
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.js +17 -7
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.js.map +1 -1
- package/dist-server/utils/inventory-util.js +26 -7
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/dist-server/utils/order-no-generator.js +35 -31
- package/dist-server/utils/order-no-generator.js.map +1 -1
- package/package.json +12 -12
- package/server/constants/index.ts +1 -1
- package/server/constants/order.ts +10 -0
- package/server/constants/validation-error-code.ts +3 -2
- package/server/controllers/ecommerce/sellercraft-controller.ts +4 -3
- package/server/service/arrival-notice/arrival-notice-mutation.ts +20 -0
- package/server/service/arrival-notice/arrival-notice-query.ts +82 -78
- package/server/service/delivery-order/delivery-order-query.ts +26 -7
- package/server/service/goods-receival-note/goods-receival-note-query.ts +116 -53
- package/server/service/index.ts +4 -0
- package/server/service/manifest/index.ts +6 -0
- package/server/service/manifest/manifest-mutation.ts +102 -0
- package/server/service/manifest/manifest-query.ts +99 -0
- package/server/service/manifest/manifest-type.ts +78 -0
- package/server/service/manifest/manifest.ts +103 -0
- package/server/service/order-inventory/order-inventory-mutation.ts +26 -1
- package/server/service/order-inventory/order-inventory-query.ts +17 -18
- package/server/service/order-inventory/order-inventory-types.ts +15 -10
- package/server/service/order-inventory/order-inventory.ts +24 -5
- package/server/service/others/other-query.ts +2 -6
- package/server/service/others/other-types.ts +3 -0
- package/server/service/release-good/release-good-mutation.ts +557 -0
- package/server/service/release-good/release-good-query.ts +197 -2
- package/server/service/release-good/release-good-types.ts +31 -7
- package/server/service/release-good/release-good.ts +26 -0
- package/server/service/reverse-kitting-order/reverse-kitting-order-mutation.ts +145 -35
- package/server/service/reverse-kitting-order/reverse-kitting-order-query.ts +103 -19
- package/server/service/reverse-kitting-order/reverse-kitting-order-type.ts +106 -1
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.ts +31 -14
- package/server/utils/inventory-util.ts +30 -7
- package/server/utils/order-no-generator.ts +43 -36
- package/dist-server/middlewares/index.js +0 -1
- package/dist-server/middlewares/index.js.map +0 -1
- package/server/middlewares/index.ts +0 -0
|
@@ -4,12 +4,19 @@ import { EntityManager, getRepository, In, Repository, SelectQueryBuilder } from
|
|
|
4
4
|
|
|
5
5
|
import { Attachment } from '@things-factory/attachment-base'
|
|
6
6
|
import { User } from '@things-factory/auth-base'
|
|
7
|
-
import { Bizplace, getMyBizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
7
|
+
import { Bizplace, getCompanyBizplace, getMyBizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
8
8
|
import { Product } from '@things-factory/product-base'
|
|
9
9
|
import { buildQuery, Domain, Filter, ListParam, Pagination, Sorting } from '@things-factory/shell'
|
|
10
10
|
import { Inventory } from '@things-factory/warehouse-base'
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
InventoryInfos,
|
|
14
|
+
NewReleaseGood,
|
|
15
|
+
OrderInventory,
|
|
16
|
+
ReleasableInventoryList,
|
|
17
|
+
ReleaseGoodList,
|
|
18
|
+
ShippingOrder
|
|
19
|
+
} from '../'
|
|
13
20
|
import { ATTACHMENT_TYPE, ORDER_INVENTORY_STATUS, ORDER_STATUS } from '../../constants'
|
|
14
21
|
import { ReleaseGood } from './release-good'
|
|
15
22
|
|
|
@@ -463,6 +470,129 @@ export class ReleaseGoodQuery {
|
|
|
463
470
|
}
|
|
464
471
|
}
|
|
465
472
|
|
|
473
|
+
@Directive('@transaction')
|
|
474
|
+
@Query(returns => [ReleaseGood])
|
|
475
|
+
async bulkReleaseGoodsAvailableItems(
|
|
476
|
+
@Ctx() context: any,
|
|
477
|
+
@Arg('rawReleaseGoods', type => [NewReleaseGood], { nullable: true }) rawReleaseGoods: NewReleaseGood[],
|
|
478
|
+
@Arg('bizplaceId', type => String) bizplaceId: string
|
|
479
|
+
): Promise<ReleaseGood[]> {
|
|
480
|
+
const { domain, tx } = context.state
|
|
481
|
+
const companyBizplaceId: Bizplace = await getCompanyBizplace(null, null, bizplaceId)
|
|
482
|
+
|
|
483
|
+
if (!rawReleaseGoods) return
|
|
484
|
+
|
|
485
|
+
const json_oi = JSON.stringify(
|
|
486
|
+
rawReleaseGoods.map(raw => {
|
|
487
|
+
return {
|
|
488
|
+
sku: raw.sku,
|
|
489
|
+
packing_type: raw.packingType,
|
|
490
|
+
packing_size: raw.packingSize,
|
|
491
|
+
uom: raw.uom,
|
|
492
|
+
release_qty: raw.releaseQty
|
|
493
|
+
}
|
|
494
|
+
})
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
await tx.query(
|
|
498
|
+
`
|
|
499
|
+
CREATE TEMP TABLE temp_order_products(
|
|
500
|
+
product_id VARCHAR(50),
|
|
501
|
+
sku VARCHAR(150),
|
|
502
|
+
packing_type VARCHAR(50),
|
|
503
|
+
packing_size INT,
|
|
504
|
+
uom VARCHAR(10),
|
|
505
|
+
release_qty INT
|
|
506
|
+
);
|
|
507
|
+
`
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
await tx.query(
|
|
511
|
+
`
|
|
512
|
+
INSERT INTO temp_order_products
|
|
513
|
+
SELECT p.id AS product_id, js.sku,
|
|
514
|
+
CASE WHEN js.packing_type NOTNULL AND js.packing_size NOTNULL THEN js.packing_type ELSE pd.packing_type END,
|
|
515
|
+
CASE WHEN js.packing_type NOTNULL AND js.packing_size NOTNULL THEN js.packing_size ELSE pd.packing_size END,
|
|
516
|
+
CASE WHEN js.uom NOTNULL THEN js.uom ELSE pd.uom END,
|
|
517
|
+
js.release_qty
|
|
518
|
+
FROM JSON_POPULATE_RECORDSET(NULL::temp_order_products,'${json_oi}') js
|
|
519
|
+
LEFT JOIN products p ON js.sku = p.sku AND p.bizplace_id = $1
|
|
520
|
+
LEFT JOIN product_details pd ON p.id = pd.product_id AND pd.is_default = TRUE;
|
|
521
|
+
`,
|
|
522
|
+
[companyBizplaceId.id]
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
let availableItems = await tx.query(
|
|
526
|
+
`
|
|
527
|
+
SELECT i.product_id, foo.sku, i.batch_id, i.packing_type, i.packing_size, i.uom,
|
|
528
|
+
SUM(i.qty - COALESCE(i.locked_qty, 0)) - COALESCE(
|
|
529
|
+
(
|
|
530
|
+
SELECT SUM(oi.release_qty) FROM order_inventories oi
|
|
531
|
+
WHERE (
|
|
532
|
+
oi.status = 'PENDING'
|
|
533
|
+
OR oi.status = 'PENDING_RECEIVE'
|
|
534
|
+
OR oi.status = 'PENDING_WORKSHEET'
|
|
535
|
+
OR oi.status = 'PENDING_SPLIT'
|
|
536
|
+
)
|
|
537
|
+
AND oi.inventory_id IS null
|
|
538
|
+
AND oi.product_id = i.product_id::uuid
|
|
539
|
+
AND oi.packing_type = i.packing_type
|
|
540
|
+
AND oi.uom = i.uom
|
|
541
|
+
AND oi.domain_id = $1
|
|
542
|
+
AND oi.bizplace_id = $2
|
|
543
|
+
), 0) as "remain_qty",
|
|
544
|
+
SUM(i.uom_value - COALESCE(i.locked_uom_value, 0)) - COALESCE(
|
|
545
|
+
(
|
|
546
|
+
SELECT SUM(oi.release_uom_value) FROM order_inventories oi
|
|
547
|
+
WHERE (
|
|
548
|
+
oi.status = 'PENDING'
|
|
549
|
+
OR oi.status = 'PENDING_RECEIVE'
|
|
550
|
+
OR oi.status = 'PENDING_WORKSHEET'
|
|
551
|
+
OR oi.status = 'PENDING_SPLIT'
|
|
552
|
+
)
|
|
553
|
+
AND oi.inventory_id IS null
|
|
554
|
+
AND oi.product_id = i.product_id::uuid
|
|
555
|
+
AND oi.packing_type = i.packing_type
|
|
556
|
+
AND oi.uom = i.uom
|
|
557
|
+
AND oi.domain_id = $1
|
|
558
|
+
AND oi.bizplace_id = $2
|
|
559
|
+
), 0) as "remain_uom_value"
|
|
560
|
+
FROM inventories i
|
|
561
|
+
INNER JOIN (
|
|
562
|
+
SELECT top.product_id, top.sku, top.packing_type, top.packing_size, top.uom
|
|
563
|
+
FROM temp_order_products top
|
|
564
|
+
GROUP BY top.product_id, top.sku, top.packing_type, top.packing_size, top.uom
|
|
565
|
+
) AS foo
|
|
566
|
+
ON i.product_id = foo.product_id::uuid
|
|
567
|
+
AND i.packing_type = foo.packing_type
|
|
568
|
+
AND i.packing_size = foo.packing_size
|
|
569
|
+
AND i.uom = foo.uom
|
|
570
|
+
AND i.domain_id = $1
|
|
571
|
+
AND i.bizplace_id = $2
|
|
572
|
+
GROUP BY i.product_id, foo.sku, i.batch_id, i.packing_type, i.packing_size, i.uom
|
|
573
|
+
ORDER BY foo.sku, remain_qty
|
|
574
|
+
`,
|
|
575
|
+
[domain.id, bizplaceId]
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
await tx.query('DROP TABLE temp_order_products')
|
|
579
|
+
|
|
580
|
+
availableItems = availableItems.map(item => {
|
|
581
|
+
return {
|
|
582
|
+
productId: item.product_id,
|
|
583
|
+
sku: item.sku,
|
|
584
|
+
batchId: item.batch_id,
|
|
585
|
+
packingType: item.packing_type,
|
|
586
|
+
packingSize: item.packing_size,
|
|
587
|
+
uom: item.uom,
|
|
588
|
+
remainQty: item.remain_qty,
|
|
589
|
+
remainUomValue: item.remain_uom_value
|
|
590
|
+
}
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
return _extractData(rawReleaseGoods, availableItems)
|
|
594
|
+
}
|
|
595
|
+
|
|
466
596
|
@FieldResolver(type => Domain)
|
|
467
597
|
async domain(@Root() releaseGood: ReleaseGood): Promise<Domain> {
|
|
468
598
|
return await getRepository(Domain).findOne(releaseGood.domainId)
|
|
@@ -559,6 +689,71 @@ async function dropOITempTable(domain: Domain, tx: EntityManager) {
|
|
|
559
689
|
await tx.query(`DROP TABLE oi`)
|
|
560
690
|
}
|
|
561
691
|
|
|
692
|
+
function _extractData(rawData, validatedData) {
|
|
693
|
+
return rawData.map(raw => {
|
|
694
|
+
const idx = validatedData.findIndex(val => {
|
|
695
|
+
const comparison = ['packingType', 'packingSize', 'uom']
|
|
696
|
+
|
|
697
|
+
let a: any = {},
|
|
698
|
+
b: any = {}
|
|
699
|
+
|
|
700
|
+
comparison.forEach(cc => {
|
|
701
|
+
if (raw[cc]) {
|
|
702
|
+
a[cc] = raw[cc]
|
|
703
|
+
b[cc] = val[cc]
|
|
704
|
+
}
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
a = JSON.stringify(Object.fromEntries(Object.entries(a).sort()))
|
|
708
|
+
b = JSON.stringify(Object.fromEntries(Object.entries(b).sort()))
|
|
709
|
+
|
|
710
|
+
return val.sku == raw.sku && a === b
|
|
711
|
+
})
|
|
712
|
+
|
|
713
|
+
let releaseUomValue = 0
|
|
714
|
+
|
|
715
|
+
// if sku is matched, assign qty and product id
|
|
716
|
+
if (idx >= 0) {
|
|
717
|
+
// assign qty to rawData as much as possible
|
|
718
|
+
releaseUomValue =
|
|
719
|
+
(Math.round((validatedData[idx]?.remainUomValue / validatedData[idx]?.remainQty) * 100) / 100) * raw.releaseQty
|
|
720
|
+
|
|
721
|
+
raw.assignedQty =
|
|
722
|
+
validatedData[idx].remainQty >= raw.releaseQty
|
|
723
|
+
? raw.releaseQty > 0
|
|
724
|
+
? raw.releaseQty
|
|
725
|
+
: 0
|
|
726
|
+
: validatedData[idx].remainQty
|
|
727
|
+
|
|
728
|
+
raw.assignedUomValue =
|
|
729
|
+
validatedData[idx].remainUomValue >= releaseUomValue
|
|
730
|
+
? releaseUomValue > 0
|
|
731
|
+
? releaseUomValue
|
|
732
|
+
: 0
|
|
733
|
+
: validatedData[idx].remainUomValue
|
|
734
|
+
|
|
735
|
+
// deduct qty & uomValue from validateData
|
|
736
|
+
validatedData[idx].remainQty -= raw.assignedQty
|
|
737
|
+
validatedData[idx].remainUomValue -= raw.assignedUomValue
|
|
738
|
+
|
|
739
|
+
raw.productId = validatedData[idx].productId
|
|
740
|
+
raw.packingType = validatedData[idx].packingType
|
|
741
|
+
raw.packingSize = validatedData[idx].packingSize
|
|
742
|
+
raw.uom = validatedData[idx].uom
|
|
743
|
+
raw.batchId = validatedData[idx].batchId
|
|
744
|
+
} else {
|
|
745
|
+
raw.assignedQty = 0
|
|
746
|
+
raw.assignedUomValue = 0
|
|
747
|
+
raw.productId = null
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
return {
|
|
751
|
+
...raw,
|
|
752
|
+
releaseUomValue
|
|
753
|
+
}
|
|
754
|
+
})
|
|
755
|
+
}
|
|
756
|
+
|
|
562
757
|
function getConditionValues(
|
|
563
758
|
conditions: Filter[]
|
|
564
759
|
): {
|
|
@@ -121,10 +121,19 @@ export class InventoryInfos {
|
|
|
121
121
|
|
|
122
122
|
@Field({ nullable: true })
|
|
123
123
|
remark?: string
|
|
124
|
+
|
|
125
|
+
@Field({ nullable: true })
|
|
126
|
+
lockedQty?: number
|
|
127
|
+
|
|
128
|
+
@Field({ nullable: true })
|
|
129
|
+
lockedUomValue?: number
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
@ObjectType()
|
|
127
133
|
export class ShippingOrderInfo {
|
|
134
|
+
@Field({ nullable: true })
|
|
135
|
+
id?: string
|
|
136
|
+
|
|
128
137
|
@Field({ nullable: true })
|
|
129
138
|
containerNo?: string
|
|
130
139
|
|
|
@@ -272,11 +281,11 @@ export class NewReleaseGood {
|
|
|
272
281
|
@Field(type => ObjectRef, { nullable: true })
|
|
273
282
|
shippingOrder: ObjectRef
|
|
274
283
|
|
|
275
|
-
@Field(type => NewOrderInventory, { nullable: true })
|
|
276
|
-
orderInventories: [
|
|
284
|
+
@Field(type => [NewOrderInventory], { nullable: true })
|
|
285
|
+
orderInventories: NewOrderInventory[]
|
|
277
286
|
|
|
278
|
-
@Field(type => NewOrderVas, { nullable: true })
|
|
279
|
-
orderVass: [
|
|
287
|
+
@Field(type => [NewOrderVas], { nullable: true })
|
|
288
|
+
orderVass: NewOrderVas[]
|
|
280
289
|
|
|
281
290
|
@Field({ nullable: true })
|
|
282
291
|
status: string
|
|
@@ -295,6 +304,21 @@ export class NewReleaseGood {
|
|
|
295
304
|
|
|
296
305
|
@Field({ nullable: true })
|
|
297
306
|
partnerBizplaceId: string
|
|
307
|
+
|
|
308
|
+
@Field({ nullable: true })
|
|
309
|
+
sku: string
|
|
310
|
+
|
|
311
|
+
@Field({ nullable: true })
|
|
312
|
+
packingType: string
|
|
313
|
+
|
|
314
|
+
@Field({ nullable: true })
|
|
315
|
+
packingSize: string
|
|
316
|
+
|
|
317
|
+
@Field({ nullable: true })
|
|
318
|
+
uom: string
|
|
319
|
+
|
|
320
|
+
@Field({ nullable: true })
|
|
321
|
+
releaseQty: string
|
|
298
322
|
}
|
|
299
323
|
|
|
300
324
|
@InputType()
|
|
@@ -372,13 +396,13 @@ export class ReleaseGoodPatch {
|
|
|
372
396
|
shippingOrder: ObjectRef
|
|
373
397
|
|
|
374
398
|
@Field(type => [ObjectRef], { nullable: true })
|
|
375
|
-
deliveryOrders: [
|
|
399
|
+
deliveryOrders: ObjectRef[]
|
|
376
400
|
|
|
377
401
|
@Field(type => [ObjectRef], { nullable: true })
|
|
378
|
-
orderInventories: [
|
|
402
|
+
orderInventories: ObjectRef[]
|
|
379
403
|
|
|
380
404
|
@Field(type => [ObjectRef], { nullable: true })
|
|
381
|
-
orderVass: [
|
|
405
|
+
orderVass: ObjectRef[]
|
|
382
406
|
|
|
383
407
|
@Field({ nullable: true })
|
|
384
408
|
status: string
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
ArrivalNotice,
|
|
24
24
|
DeliveryOrder,
|
|
25
25
|
InventoryInfos,
|
|
26
|
+
Manifest,
|
|
26
27
|
OrderInventory,
|
|
27
28
|
OrderProduct,
|
|
28
29
|
OrderVas,
|
|
@@ -37,6 +38,11 @@ export enum ReleaseOrderType {
|
|
|
37
38
|
B2B = 'b2b',
|
|
38
39
|
B2C = 'b2c'
|
|
39
40
|
}
|
|
41
|
+
|
|
42
|
+
export enum DispatchmentStatus {
|
|
43
|
+
READY_TO_DISPATCH = 'READY_TO_DISPATCH',
|
|
44
|
+
DISPATCHED = 'DISPATCHED'
|
|
45
|
+
}
|
|
40
46
|
@Entity()
|
|
41
47
|
@Index('ix_release-good_0', (releaseGood: ReleaseGood) => [releaseGood.domain, releaseGood.name], { unique: true })
|
|
42
48
|
@ObjectType()
|
|
@@ -59,6 +65,10 @@ export class ReleaseGood {
|
|
|
59
65
|
@RelationId((releaseGood: ReleaseGood) => releaseGood.bizplace)
|
|
60
66
|
bizplaceId: string
|
|
61
67
|
|
|
68
|
+
@ManyToOne(type => Manifest)
|
|
69
|
+
@Field(type => Manifest, { nullable: true })
|
|
70
|
+
manifest: Manifest
|
|
71
|
+
|
|
62
72
|
@Column({ nullable: true })
|
|
63
73
|
@Field({ nullable: true })
|
|
64
74
|
name: string
|
|
@@ -143,6 +153,18 @@ export class ReleaseGood {
|
|
|
143
153
|
@Field()
|
|
144
154
|
status: string
|
|
145
155
|
|
|
156
|
+
@Column({
|
|
157
|
+
type:
|
|
158
|
+
DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
159
|
+
? 'enum'
|
|
160
|
+
: DATABASE_TYPE == 'oracle'
|
|
161
|
+
? 'varchar2'
|
|
162
|
+
: 'smallint',
|
|
163
|
+
enum: DispatchmentStatus,
|
|
164
|
+
default: DispatchmentStatus.READY_TO_DISPATCH
|
|
165
|
+
})
|
|
166
|
+
dispatchmentStatus: DispatchmentStatus
|
|
167
|
+
|
|
146
168
|
@Column({ nullable: true })
|
|
147
169
|
@Field({ nullable: true })
|
|
148
170
|
releaseDateTime: Date
|
|
@@ -267,6 +289,10 @@ export class ReleaseGood {
|
|
|
267
289
|
@Field({ nullable: true })
|
|
268
290
|
invoice: string
|
|
269
291
|
|
|
292
|
+
@Column({ type: 'int', nullable: true })
|
|
293
|
+
@Field({ nullable: true })
|
|
294
|
+
noOfItems: number
|
|
295
|
+
|
|
270
296
|
@CreateDateColumn()
|
|
271
297
|
@Field()
|
|
272
298
|
createdAt: Date
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
2
|
import { Equal, In, Not } from 'typeorm'
|
|
3
3
|
|
|
4
|
-
import { Bizplace,
|
|
4
|
+
import { Bizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
5
5
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
6
6
|
import {
|
|
7
7
|
Inventory,
|
|
8
|
-
InventoryPatch,
|
|
9
8
|
INVENTORY_STATUS,
|
|
10
9
|
INVENTORY_TRANSACTION_TYPE,
|
|
10
|
+
InventoryHistory,
|
|
11
11
|
InventoryNoGenerator,
|
|
12
|
+
InventoryPatch,
|
|
12
13
|
InventoryUtil,
|
|
13
14
|
Location,
|
|
14
15
|
LOCATION_TYPE,
|
|
@@ -51,20 +52,26 @@ export class ReverseKittingOrderMutation {
|
|
|
51
52
|
|
|
52
53
|
// 2. Create Reverse Kitting Order Items
|
|
53
54
|
reverseKittingOrderOIs = await Promise.all(
|
|
54
|
-
reverseKittingOrderOIs.map(async (
|
|
55
|
-
if (
|
|
56
|
-
|
|
55
|
+
reverseKittingOrderOIs.map(async (reverseKittingOI: any) => {
|
|
56
|
+
if (reverseKittingOI?.inventory?.id) {
|
|
57
|
+
const foundInv: Inventory = await tx.getRepository(Inventory).findOne(reverseKittingOI.inventory.id)
|
|
58
|
+
reverseKittingOI.inventory = foundInv
|
|
59
|
+
|
|
60
|
+
foundInv.lockedQty = Number(foundInv.lockedQty) + reverseKittingOI.qty
|
|
61
|
+
foundInv.lockedUomValue = Number(foundInv.lockedUomValue) + reverseKittingOI.uomValue
|
|
62
|
+
foundInv.updater = user
|
|
63
|
+
|
|
64
|
+
await tx.getRepository(Inventory).save(foundInv)
|
|
57
65
|
}
|
|
58
66
|
return {
|
|
59
|
-
...
|
|
67
|
+
...reverseKittingOI,
|
|
60
68
|
domain,
|
|
61
69
|
name: OrderNoGenerator.orderVas(),
|
|
62
70
|
reverseKittingOrder: createdReverseKittingOrder,
|
|
63
71
|
bizplace: customerBizplace,
|
|
64
72
|
type: ORDER_TYPES.VAS_ORDER,
|
|
65
73
|
status: ORDER_VAS_STATUS.PENDING,
|
|
66
|
-
creator: user
|
|
67
|
-
updater: user
|
|
74
|
+
creator: user
|
|
68
75
|
}
|
|
69
76
|
})
|
|
70
77
|
)
|
|
@@ -113,7 +120,7 @@ export class ReverseKittingOrderMutation {
|
|
|
113
120
|
relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
|
|
114
121
|
})
|
|
115
122
|
|
|
116
|
-
let
|
|
123
|
+
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
117
124
|
|
|
118
125
|
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
119
126
|
|
|
@@ -124,10 +131,10 @@ export class ReverseKittingOrderMutation {
|
|
|
124
131
|
updater: user
|
|
125
132
|
})
|
|
126
133
|
|
|
127
|
-
|
|
128
|
-
return { ...
|
|
134
|
+
reverseKittingOIs = reverseKittingOIs.map((reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
135
|
+
return { ...reverseKittingOI, status: ORDER_VAS_STATUS.READY_TO_PROCESS }
|
|
129
136
|
})
|
|
130
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(
|
|
137
|
+
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
131
138
|
|
|
132
139
|
return reverseKitting
|
|
133
140
|
}
|
|
@@ -150,14 +157,15 @@ export class ReverseKittingOrderMutation {
|
|
|
150
157
|
|
|
151
158
|
if (!foundReverseKittingOrder) throw new Error(foundReverseKittingOrder.name + ` not found`)
|
|
152
159
|
|
|
153
|
-
let
|
|
154
|
-
foundReverseKittingOrder.reverseKittingOrderInventories
|
|
160
|
+
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
155
161
|
|
|
156
162
|
await Promise.all(
|
|
157
|
-
|
|
163
|
+
reverseKittingOIs.map(async reverseKittingOI => {
|
|
158
164
|
let inventory: Inventory = reverseKittingOI.inventory
|
|
159
165
|
inventory.qty = inventory.qty - reverseKittingOI.qty
|
|
166
|
+
inventory.lockedQty = inventory.lockedQty - reverseKittingOI.qty
|
|
160
167
|
inventory.uomValue = inventory.uomValue - reverseKittingOI.uomValue
|
|
168
|
+
inventory.lockedUomValue = inventory.lockedUomValue - reverseKittingOI.uomValue
|
|
161
169
|
|
|
162
170
|
await InventoryUtil.transactionInventory(
|
|
163
171
|
inventory,
|
|
@@ -171,7 +179,7 @@ export class ReverseKittingOrderMutation {
|
|
|
171
179
|
})
|
|
172
180
|
)
|
|
173
181
|
|
|
174
|
-
|
|
182
|
+
reverseKittingOIs = reverseKittingOIs.map(reverseKittingOI => {
|
|
175
183
|
return {
|
|
176
184
|
...reverseKittingOI,
|
|
177
185
|
status: ORDER_VAS_STATUS.TERMINATED,
|
|
@@ -179,7 +187,7 @@ export class ReverseKittingOrderMutation {
|
|
|
179
187
|
}
|
|
180
188
|
})
|
|
181
189
|
|
|
182
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(
|
|
190
|
+
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
183
191
|
|
|
184
192
|
foundReverseKittingOrder.status = ORDER_STATUS.DONE
|
|
185
193
|
foundReverseKittingOrder.updater = user
|
|
@@ -196,27 +204,109 @@ export class ReverseKittingOrderMutation {
|
|
|
196
204
|
|
|
197
205
|
const foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
198
206
|
where: { domain, name, status: ORDER_STATUS.READY_TO_EXECUTE },
|
|
199
|
-
relations: [
|
|
207
|
+
relations: [
|
|
208
|
+
'bizplace',
|
|
209
|
+
'reverseKittingOrderInventories',
|
|
210
|
+
'reverseKittingOrderInventories.inventory',
|
|
211
|
+
'creator',
|
|
212
|
+
'updater'
|
|
213
|
+
]
|
|
200
214
|
})
|
|
201
215
|
|
|
202
|
-
let
|
|
216
|
+
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
203
217
|
|
|
204
218
|
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
205
219
|
|
|
220
|
+
// 1. Reverse Kitting Order Status change (PENDING => PENDING_RECEIVE)
|
|
206
221
|
const reverseKitting: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).save({
|
|
207
222
|
...foundReverseKittingOrder,
|
|
208
223
|
status: ORDER_STATUS.CANCELLED,
|
|
209
224
|
updater: user
|
|
210
225
|
})
|
|
211
226
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
227
|
+
reverseKittingOIs = await Promise.all(
|
|
228
|
+
reverseKittingOIs.map(async (reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
229
|
+
if (reverseKittingOI?.inventory?.id) {
|
|
230
|
+
reverseKittingOI.inventory = await tx.getRepository(Inventory).findOne(reverseKittingOI.inventory.id)
|
|
231
|
+
|
|
232
|
+
await tx.getRepository(Inventory).save({
|
|
233
|
+
...reverseKittingOI.inventory,
|
|
234
|
+
lockedQty: reverseKittingOI.inventory.lockedQty - reverseKittingOI.qty,
|
|
235
|
+
lockedUomValue: reverseKittingOI.inventory.lockedUomValue - reverseKittingOI.uomValue,
|
|
236
|
+
updater: user
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return { ...reverseKittingOI, status: ORDER_VAS_STATUS.CANCELLED }
|
|
241
|
+
})
|
|
242
|
+
)
|
|
243
|
+
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
216
244
|
|
|
217
245
|
return reverseKitting
|
|
218
246
|
}
|
|
219
247
|
|
|
248
|
+
@Directive('@transaction')
|
|
249
|
+
@Mutation(returns => Boolean, { description: 'To undo the execution of reverse kitting order' })
|
|
250
|
+
async undoReverseKittingInventory(
|
|
251
|
+
@Arg('reverseKittingOIName') reverseKittingOIName: string,
|
|
252
|
+
@Arg('palletId') palletId: string,
|
|
253
|
+
@Ctx() context: any
|
|
254
|
+
): Promise<boolean> {
|
|
255
|
+
const { tx, domain, user } = context.state
|
|
256
|
+
|
|
257
|
+
//@sumjoekin please add stricter validation. It is dangerous without strict validation. Unexpected behaviour will cause accidental deletion of inventory.
|
|
258
|
+
|
|
259
|
+
const reverseKittingOI: ReverseKittingOrderInventory = await tx
|
|
260
|
+
.getRepository(ReverseKittingOrderInventory)
|
|
261
|
+
.findOne({
|
|
262
|
+
where: { domain, name: reverseKittingOIName },
|
|
263
|
+
relations: ['bizplace', 'reverseKittingOrder']
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
const bizplace: Bizplace = reverseKittingOI.bizplace
|
|
267
|
+
const reverseKittingOrder: ReverseKittingOrder = reverseKittingOI.reverseKittingOrder
|
|
268
|
+
let foundInventory: Inventory = await tx.getRepository(Inventory).findOne({
|
|
269
|
+
where: { domain, bizplace, orderVasId: reverseKittingOI.id, palletId },
|
|
270
|
+
relations: ['bizplace', 'product']
|
|
271
|
+
})
|
|
272
|
+
if (!foundInventory) throw new Error(`There's no results matched with condition ${foundInventory.palletId}`)
|
|
273
|
+
|
|
274
|
+
let operationGuide: any = JSON.parse(reverseKittingOI.operationGuide)
|
|
275
|
+
let productCombinationSets: any[] = operationGuide.data.productCombinationSets
|
|
276
|
+
productCombinationSets = productCombinationSets.map(item => {
|
|
277
|
+
if (foundInventory.product.id == item.productId) {
|
|
278
|
+
item.actualQty -= foundInventory.qty
|
|
279
|
+
}
|
|
280
|
+
return item
|
|
281
|
+
})
|
|
282
|
+
operationGuide.data.productCombinationSets = productCombinationSets
|
|
283
|
+
|
|
284
|
+
await tx
|
|
285
|
+
.getRepository(ReverseKittingOrderInventory)
|
|
286
|
+
.update({ id: reverseKittingOI.id }, { operationGuide: operationGuide })
|
|
287
|
+
|
|
288
|
+
foundInventory.lastSeq++
|
|
289
|
+
foundInventory.status = INVENTORY_STATUS.DELETED
|
|
290
|
+
foundInventory = await InventoryUtil.transactionInventory(
|
|
291
|
+
foundInventory,
|
|
292
|
+
reverseKittingOrder,
|
|
293
|
+
-foundInventory.qty,
|
|
294
|
+
-foundInventory.uomValue,
|
|
295
|
+
INVENTORY_TRANSACTION_TYPE.UNDO_REVERSE_KITTING,
|
|
296
|
+
user,
|
|
297
|
+
tx
|
|
298
|
+
)
|
|
299
|
+
foundInventory.qty = 0
|
|
300
|
+
foundInventory.uomValue = 0
|
|
301
|
+
foundInventory.updater = user
|
|
302
|
+
|
|
303
|
+
await tx.getRepository(InventoryHistory).update({ inventory: foundInventory }, { inventory: null })
|
|
304
|
+
|
|
305
|
+
await tx.getRepository(Inventory).delete({ id: foundInventory.id })
|
|
306
|
+
|
|
307
|
+
return true
|
|
308
|
+
}
|
|
309
|
+
|
|
220
310
|
@Directive('@transaction')
|
|
221
311
|
@Mutation(returns => ReverseKittingOrder, { description: 'To activate reverse kitting order' })
|
|
222
312
|
async activateReverseKittingOrder(@Arg('name') name: string, @Ctx() context: any): Promise<ReverseKittingOrder> {
|
|
@@ -227,7 +317,7 @@ export class ReverseKittingOrderMutation {
|
|
|
227
317
|
relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
|
|
228
318
|
})
|
|
229
319
|
|
|
230
|
-
let
|
|
320
|
+
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
231
321
|
|
|
232
322
|
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
233
323
|
|
|
@@ -238,10 +328,10 @@ export class ReverseKittingOrderMutation {
|
|
|
238
328
|
updater: user
|
|
239
329
|
})
|
|
240
330
|
|
|
241
|
-
|
|
242
|
-
return { ...
|
|
331
|
+
reverseKittingOIs = reverseKittingOIs.map((reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
332
|
+
return { ...reverseKittingOI, status: ORDER_VAS_STATUS.PROCESSING }
|
|
243
333
|
})
|
|
244
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(
|
|
334
|
+
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
245
335
|
|
|
246
336
|
return reverseKitting
|
|
247
337
|
}
|
|
@@ -268,13 +358,9 @@ export class ReverseKittingOrderMutation {
|
|
|
268
358
|
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
269
359
|
|
|
270
360
|
const customerBizplace: Bizplace = foundReverseKittingOrder.bizplace
|
|
271
|
-
const customerCompanyBizplace: Bizplace = await getCompanyBizplace(null, null, customerBizplace.id)
|
|
272
361
|
|
|
273
362
|
const productDetail: ProductDetail = await tx.getRepository(ProductDetail).findOne({
|
|
274
|
-
where: {
|
|
275
|
-
domain: customerCompanyBizplace.domain,
|
|
276
|
-
id: inventory.productDetailId
|
|
277
|
-
},
|
|
363
|
+
where: { id: inventory.productDetailId },
|
|
278
364
|
relations: ['product']
|
|
279
365
|
})
|
|
280
366
|
|
|
@@ -318,6 +404,7 @@ export class ReverseKittingOrderMutation {
|
|
|
318
404
|
newInventory.warehouse = warehouse
|
|
319
405
|
newInventory.location = location
|
|
320
406
|
newInventory.zone = zone
|
|
407
|
+
newInventory.refInventory = reverseKittingOI.inventory
|
|
321
408
|
newInventory.status = INVENTORY_STATUS.STORED
|
|
322
409
|
newInventory.domain = domain
|
|
323
410
|
newInventory.creator = user
|
|
@@ -337,7 +424,7 @@ export class ReverseKittingOrderMutation {
|
|
|
337
424
|
let productCombinationSets: any[] = operationGuide.data.productCombinationSets
|
|
338
425
|
operationGuide.data.productCombinationSets = productCombinationSets.map(item => {
|
|
339
426
|
if (item.productDetailId == inventory.productDetailId) {
|
|
340
|
-
item.actualQty
|
|
427
|
+
item.actualQty += qty
|
|
341
428
|
}
|
|
342
429
|
return item
|
|
343
430
|
})
|
|
@@ -350,16 +437,39 @@ export class ReverseKittingOrderMutation {
|
|
|
350
437
|
@Directive('@transaction')
|
|
351
438
|
@Mutation(returns => Boolean, { description: 'To delete ReverseKittingOrder' })
|
|
352
439
|
async deleteReverseKittingOrder(@Arg('name') name: string, @Ctx() context: any): Promise<boolean> {
|
|
353
|
-
const { domain, tx } = context.state
|
|
440
|
+
const { domain, tx, user } = context.state
|
|
354
441
|
let foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
355
442
|
where: { domain, name },
|
|
356
|
-
relations: [
|
|
443
|
+
relations: [
|
|
444
|
+
'bizplace',
|
|
445
|
+
'reverseKittingOrderInventories',
|
|
446
|
+
'reverseKittingOrderInventories.inventory',
|
|
447
|
+
'creator',
|
|
448
|
+
'updater'
|
|
449
|
+
]
|
|
357
450
|
})
|
|
358
451
|
|
|
359
452
|
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
360
453
|
|
|
361
454
|
const reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
362
455
|
|
|
456
|
+
// Delete order reverse kittings by ids
|
|
457
|
+
await Promise.all(
|
|
458
|
+
reverseKittingOIs.map(async (reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
459
|
+
if (reverseKittingOI?.inventory?.id) {
|
|
460
|
+
reverseKittingOI.inventory = await tx.getRepository(Inventory).findOne(reverseKittingOI.inventory.id)
|
|
461
|
+
|
|
462
|
+
await tx.getRepository(Inventory).save({
|
|
463
|
+
...reverseKittingOI.inventory,
|
|
464
|
+
lockedQty: reverseKittingOI.inventory.lockedQty - reverseKittingOI.qty,
|
|
465
|
+
lockedUomValue: reverseKittingOI.inventory.lockedUomValue - reverseKittingOI.uomValue,
|
|
466
|
+
updater: user
|
|
467
|
+
})
|
|
468
|
+
}
|
|
469
|
+
return reverseKittingOI
|
|
470
|
+
})
|
|
471
|
+
)
|
|
472
|
+
|
|
363
473
|
// 1. delete order reverse kittings
|
|
364
474
|
const productIds = reverseKittingOIs.map((ork: ReverseKittingOrderInventory) => ork.id)
|
|
365
475
|
if (productIds.length) {
|