@things-factory/sales-base 8.0.2 → 8.0.5
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/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/server/constants/attachment-type.ts +0 -9
- package/server/constants/index.ts +0 -7
- package/server/constants/load-type.ts +0 -4
- package/server/constants/order.ts +0 -203
- package/server/constants/product-group-type.ts +0 -4
- package/server/constants/release-good.ts +0 -9
- package/server/constants/transfer-order-type.ts +0 -6
- package/server/constants/validation-error-code.ts +0 -3
- package/server/constants/vas-target-type.ts +0 -25
- package/server/controllers/ecommerce/ecommerce-controller.ts +0 -122
- package/server/controllers/ecommerce/index.ts +0 -2
- package/server/controllers/ecommerce/sellercraft-controller.ts +0 -182
- package/server/controllers/index.ts +0 -2
- package/server/controllers/order-controller.ts +0 -296
- package/server/errors/index.ts +0 -1
- package/server/errors/validation-error.ts +0 -25
- package/server/index.ts +0 -5
- package/server/migrations/index.ts +0 -9
- package/server/service/arrival-notice/arrival-notice-mutation.ts +0 -1152
- package/server/service/arrival-notice/arrival-notice-query.ts +0 -549
- package/server/service/arrival-notice/arrival-notice-types.ts +0 -310
- package/server/service/arrival-notice/arrival-notice.ts +0 -202
- package/server/service/arrival-notice/index.ts +0 -9
- package/server/service/claim/claim-mutation.ts +0 -308
- package/server/service/claim/claim-query.ts +0 -122
- package/server/service/claim/claim-types.ts +0 -130
- package/server/service/claim/claim.ts +0 -140
- package/server/service/claim/index.ts +0 -9
- package/server/service/claim-detail/claim-detail-mutation.ts +0 -102
- package/server/service/claim-detail/claim-detail-query.ts +0 -55
- package/server/service/claim-detail/claim-detail-types.ts +0 -47
- package/server/service/claim-detail/claim-detail.ts +0 -69
- package/server/service/claim-detail/index.ts +0 -9
- package/server/service/claim-order/claim-order-mutation.ts +0 -101
- package/server/service/claim-order/claim-order-query.ts +0 -47
- package/server/service/claim-order/claim-order-types.ts +0 -35
- package/server/service/claim-order/claim-order.ts +0 -81
- package/server/service/claim-order/index.ts +0 -9
- package/server/service/collection-order/collection-order-mutation.ts +0 -245
- package/server/service/collection-order/collection-order-query.ts +0 -97
- package/server/service/collection-order/collection-order-types.ts +0 -165
- package/server/service/collection-order/collection-order.ts +0 -135
- package/server/service/collection-order/index.ts +0 -9
- package/server/service/delivery-order/delivery-order-mutation.ts +0 -967
- package/server/service/delivery-order/delivery-order-query.ts +0 -631
- package/server/service/delivery-order/delivery-order-types.ts +0 -268
- package/server/service/delivery-order/delivery-order.ts +0 -258
- package/server/service/delivery-order/index.ts +0 -9
- package/server/service/draft-release-good/draft-release-good-mutation.ts +0 -765
- package/server/service/draft-release-good/draft-release-good-query.ts +0 -354
- package/server/service/draft-release-good/draft-release-good-type.ts +0 -261
- package/server/service/draft-release-good/draft-release-good.ts +0 -284
- package/server/service/draft-release-good/index.ts +0 -9
- package/server/service/goods-receival-note/goods-receival-note-mutation.ts +0 -129
- package/server/service/goods-receival-note/goods-receival-note-query.ts +0 -280
- package/server/service/goods-receival-note/goods-receival-note-types.ts +0 -105
- package/server/service/goods-receival-note/goods-receival-note.ts +0 -127
- package/server/service/goods-receival-note/index.ts +0 -9
- package/server/service/index.ts +0 -238
- package/server/service/inventory-check/index.ts +0 -9
- package/server/service/inventory-check/inventory-check-mutation.ts +0 -149
- package/server/service/inventory-check/inventory-check-query.ts +0 -48
- package/server/service/inventory-check/inventory-check-types.ts +0 -48
- package/server/service/inventory-check/inventory-check.ts +0 -90
- package/server/service/invoice/index.ts +0 -9
- package/server/service/invoice/invoice-mutation.ts +0 -95
- package/server/service/invoice/invoice-query.ts +0 -53
- package/server/service/invoice/invoice-types.ts +0 -279
- package/server/service/invoice/invoice.ts +0 -230
- package/server/service/invoice-product/index.ts +0 -9
- package/server/service/invoice-product/invoice-product-mutation.ts +0 -54
- package/server/service/invoice-product/invoice-product-query.ts +0 -54
- package/server/service/invoice-product/invoice-product-types.ts +0 -84
- package/server/service/invoice-product/invoice-product.ts +0 -92
- package/server/service/job-sheet/index.ts +0 -9
- package/server/service/job-sheet/job-sheet-mutation.ts +0 -92
- package/server/service/job-sheet/job-sheet-query.ts +0 -112
- package/server/service/job-sheet/job-sheet-types.ts +0 -78
- package/server/service/job-sheet/job-sheet.ts +0 -102
- package/server/service/manifest/index.ts +0 -6
- package/server/service/manifest/manifest-mutation.ts +0 -190
- package/server/service/manifest/manifest-query.ts +0 -149
- package/server/service/manifest/manifest-type.ts +0 -84
- package/server/service/manifest/manifest.ts +0 -114
- package/server/service/order-inventory/index.ts +0 -9
- package/server/service/order-inventory/order-inventory-mutation.ts +0 -54
- package/server/service/order-inventory/order-inventory-query.ts +0 -722
- package/server/service/order-inventory/order-inventory-types.ts +0 -238
- package/server/service/order-inventory/order-inventory.ts +0 -401
- package/server/service/order-product/index.ts +0 -9
- package/server/service/order-product/order-product-mutation.ts +0 -48
- package/server/service/order-product/order-product-query.ts +0 -89
- package/server/service/order-product/order-product-types.ts +0 -335
- package/server/service/order-product/order-product.ts +0 -362
- package/server/service/order-tote/index.ts +0 -9
- package/server/service/order-tote/order-tote-mutation.ts +0 -31
- package/server/service/order-tote/order-tote-query.ts +0 -112
- package/server/service/order-tote/order-tote-types.ts +0 -47
- package/server/service/order-tote/order-tote.ts +0 -73
- package/server/service/order-tote-item/index.ts +0 -9
- package/server/service/order-tote-item/order-tote-item-mutation.ts +0 -31
- package/server/service/order-tote-item/order-tote-item-query.ts +0 -82
- package/server/service/order-tote-item/order-tote-item-types.ts +0 -56
- package/server/service/order-tote-item/order-tote-item.ts +0 -72
- package/server/service/order-tote-seal/index.ts +0 -9
- package/server/service/order-tote-seal/order-tote-seal-mutation.ts +0 -31
- package/server/service/order-tote-seal/order-tote-seal-query.ts +0 -59
- package/server/service/order-tote-seal/order-tote-seal-types.ts +0 -41
- package/server/service/order-tote-seal/order-tote-seal.ts +0 -46
- package/server/service/order-vas/index.ts +0 -9
- package/server/service/order-vas/order-vas-mutation.ts +0 -20
- package/server/service/order-vas/order-vas-query.ts +0 -72
- package/server/service/order-vas/order-vas-types.ts +0 -159
- package/server/service/order-vas/order-vas.ts +0 -207
- package/server/service/others/index.ts +0 -5
- package/server/service/others/other-query.ts +0 -563
- package/server/service/others/other-types.ts +0 -115
- package/server/service/purchase-order/index.ts +0 -9
- package/server/service/purchase-order/purchase-order-mutation.ts +0 -458
- package/server/service/purchase-order/purchase-order-query.ts +0 -90
- package/server/service/purchase-order/purchase-order-types.ts +0 -154
- package/server/service/purchase-order/purchase-order.ts +0 -172
- package/server/service/purchase-order-other-charge/index.ts +0 -9
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-mutation.ts +0 -31
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-query.ts +0 -52
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-types.ts +0 -44
- package/server/service/purchase-order-other-charge/purchase-order-other-charge.ts +0 -68
- package/server/service/release-good/index.ts +0 -9
- package/server/service/release-good/release-good-mutation.ts +0 -1686
- package/server/service/release-good/release-good-query.ts +0 -980
- package/server/service/release-good/release-good-types.ts +0 -662
- package/server/service/release-good/release-good.ts +0 -490
- package/server/service/retail-replenishment-order/index.ts +0 -9
- package/server/service/retail-replenishment-order/retail-replenishment-order-mutation.ts +0 -382
- package/server/service/retail-replenishment-order/retail-replenishment-order-query.ts +0 -54
- package/server/service/retail-replenishment-order/retail-replenishment-order-types.ts +0 -101
- package/server/service/retail-replenishment-order/retail-replenishment-order.ts +0 -115
- package/server/service/return-order/index.ts +0 -9
- package/server/service/return-order/return-order-mutation.ts +0 -516
- package/server/service/return-order/return-order-query.ts +0 -226
- package/server/service/return-order/return-order-types.ts +0 -196
- package/server/service/return-order/return-order.ts +0 -127
- package/server/service/reverse-kitting-order/index.ts +0 -9
- package/server/service/reverse-kitting-order/reverse-kitting-order-mutation.ts +0 -500
- package/server/service/reverse-kitting-order/reverse-kitting-order-query.ts +0 -197
- package/server/service/reverse-kitting-order/reverse-kitting-order-type.ts +0 -173
- package/server/service/reverse-kitting-order/reverse-kitting-order.ts +0 -121
- package/server/service/reverse-kitting-order-inventory/index.ts +0 -9
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.ts +0 -129
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-query.ts +0 -52
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.ts +0 -95
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +0 -143
- package/server/service/shipping-order/index.ts +0 -9
- package/server/service/shipping-order/shipping-order-mutation.ts +0 -61
- package/server/service/shipping-order/shipping-order-query.ts +0 -61
- package/server/service/shipping-order/shipping-order-types.ts +0 -89
- package/server/service/shipping-order/shipping-order.ts +0 -129
- package/server/service/transfer-order/index.ts +0 -9
- package/server/service/transfer-order/transfer-order-mutation.ts +0 -309
- package/server/service/transfer-order/transfer-order-query.ts +0 -66
- package/server/service/transfer-order/transfer-order-types.ts +0 -97
- package/server/service/transfer-order/transfer-order.ts +0 -117
- package/server/service/vas/index.ts +0 -9
- package/server/service/vas/vas-mutation.ts +0 -106
- package/server/service/vas/vas-query.ts +0 -60
- package/server/service/vas/vas-types.ts +0 -71
- package/server/service/vas/vas.ts +0 -77
- package/server/service/vas-order/index.ts +0 -9
- package/server/service/vas-order/vas-order-mutation.ts +0 -259
- package/server/service/vas-order/vas-order-query.ts +0 -119
- package/server/service/vas-order/vas-order-types.ts +0 -49
- package/server/service/vas-order/vas-order.ts +0 -81
- package/server/utils/datetime-util.ts +0 -54
- package/server/utils/index.ts +0 -3
- package/server/utils/inventory-util.ts +0 -1155
- package/server/utils/order-no-generator.ts +0 -146
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { Equal, In, Not } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { Bizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
5
|
-
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
6
|
-
import {
|
|
7
|
-
Inventory,
|
|
8
|
-
INVENTORY_STATUS,
|
|
9
|
-
INVENTORY_TRANSACTION_TYPE,
|
|
10
|
-
InventoryHistory,
|
|
11
|
-
InventoryNoGenerator,
|
|
12
|
-
InventoryPatch,
|
|
13
|
-
Location,
|
|
14
|
-
LOCATION_TYPE,
|
|
15
|
-
Warehouse
|
|
16
|
-
} from '@things-factory/warehouse-base'
|
|
17
|
-
|
|
18
|
-
import { ORDER_STATUS, ORDER_TYPES, ORDER_VAS_STATUS } from '../../constants'
|
|
19
|
-
import { InventoryUtil } from '../../utils'
|
|
20
|
-
import { OrderNoGenerator } from '../../utils/order-no-generator'
|
|
21
|
-
import { ReverseKittingOrderInventory } from '../reverse-kitting-order-inventory/reverse-kitting-order-inventory'
|
|
22
|
-
import { ReverseKittingOrder } from './reverse-kitting-order'
|
|
23
|
-
import { NewReverseKittingOrder } from './reverse-kitting-order-type'
|
|
24
|
-
|
|
25
|
-
@Resolver(ReverseKittingOrder)
|
|
26
|
-
export class ReverseKittingOrderMutation {
|
|
27
|
-
@Directive('@transaction')
|
|
28
|
-
@Mutation(returns => ReverseKittingOrder, { description: 'To create new ReverseKittingOrder' })
|
|
29
|
-
async generateReverseKittingOrder(
|
|
30
|
-
@Arg('reverseKittingOrder', type => NewReverseKittingOrder) reverseKittingOrder: NewReverseKittingOrder,
|
|
31
|
-
@Ctx() context: ResolverContext
|
|
32
|
-
): Promise<ReverseKittingOrder> {
|
|
33
|
-
const { tx, domain, user } = context.state
|
|
34
|
-
|
|
35
|
-
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
|
|
36
|
-
where: { id: reverseKittingOrder.customerBizplaceId }
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
if (!customerBizplace) throw new Error('company is not found')
|
|
40
|
-
|
|
41
|
-
let reverseKittingOrderOIs = reverseKittingOrder.reverseKittingOrderInventories
|
|
42
|
-
|
|
43
|
-
// 1. Create reverse kitting order
|
|
44
|
-
const createdReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).save({
|
|
45
|
-
...reverseKittingOrder,
|
|
46
|
-
name: OrderNoGenerator.vasOrder(),
|
|
47
|
-
domain,
|
|
48
|
-
bizplace: customerBizplace,
|
|
49
|
-
status: ORDER_STATUS.PENDING,
|
|
50
|
-
creator: user
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
// 2. Create Reverse Kitting Order Items
|
|
54
|
-
reverseKittingOrderOIs = await Promise.all(
|
|
55
|
-
reverseKittingOrderOIs.map(async (reverseKittingOI: any) => {
|
|
56
|
-
if (reverseKittingOI?.inventory?.id) {
|
|
57
|
-
const foundInv: Inventory = await tx.getRepository(Inventory).findOneBy({ id: 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)
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
...reverseKittingOI,
|
|
68
|
-
domain,
|
|
69
|
-
name: OrderNoGenerator.orderVas(),
|
|
70
|
-
reverseKittingOrder: createdReverseKittingOrder,
|
|
71
|
-
bizplace: customerBizplace,
|
|
72
|
-
type: ORDER_TYPES.VAS_ORDER,
|
|
73
|
-
status: ORDER_VAS_STATUS.PENDING,
|
|
74
|
-
creator: user
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
)
|
|
78
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOrderOIs)
|
|
79
|
-
|
|
80
|
-
return createdReverseKittingOrder
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@Directive('@transaction')
|
|
84
|
-
@Mutation(returns => ReverseKittingOrder, { description: 'To execute reverse kitting order' })
|
|
85
|
-
async executingReverseKittingOrder(
|
|
86
|
-
@Arg('name') name: string,
|
|
87
|
-
@Ctx() context: ResolverContext
|
|
88
|
-
): Promise<ReverseKittingOrder> {
|
|
89
|
-
const { domain, user, tx } = context.state
|
|
90
|
-
|
|
91
|
-
const reverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
92
|
-
where: {
|
|
93
|
-
domain: { id: domain.id },
|
|
94
|
-
name,
|
|
95
|
-
status: ORDER_STATUS.EXECUTING,
|
|
96
|
-
bizplace: { id: In(await getPermittedBizplaceIds(domain, user)) }
|
|
97
|
-
},
|
|
98
|
-
relations: [
|
|
99
|
-
'domain',
|
|
100
|
-
'bizplace',
|
|
101
|
-
'reverseKittingOrderInventories',
|
|
102
|
-
'reverseKittingOrderInventories.inventory',
|
|
103
|
-
'reverseKittingOrderInventories.inventory.product',
|
|
104
|
-
'reverseKittingOrderInventories.inventory.location',
|
|
105
|
-
'reverseKittingOrderInventories.inventory.warehouse',
|
|
106
|
-
'creator',
|
|
107
|
-
'updater'
|
|
108
|
-
]
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
if (!reverseKittingOrder) throw new Error(`Reverse Kitting Order not exists`)
|
|
112
|
-
|
|
113
|
-
return reverseKittingOrder
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
@Directive('@transaction')
|
|
117
|
-
@Mutation(returns => ReverseKittingOrder, { description: 'To confirm reverse kitting order' })
|
|
118
|
-
async confirmReverseKittingOrder(
|
|
119
|
-
@Arg('name') name: string,
|
|
120
|
-
@Ctx() context: ResolverContext
|
|
121
|
-
): Promise<ReverseKittingOrder> {
|
|
122
|
-
const { user, domain, tx } = context.state
|
|
123
|
-
|
|
124
|
-
const foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
125
|
-
where: { domain: { id: domain.id }, name, status: ORDER_STATUS.PENDING },
|
|
126
|
-
relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
130
|
-
|
|
131
|
-
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
132
|
-
|
|
133
|
-
// 1. Reverse Kitting Order Status change (PENDING => READY_TO_EXECUTE)
|
|
134
|
-
const reverseKitting: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).save({
|
|
135
|
-
...foundReverseKittingOrder,
|
|
136
|
-
status: ORDER_STATUS.READY_TO_EXECUTE,
|
|
137
|
-
updater: user
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
reverseKittingOIs = reverseKittingOIs.map((reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
141
|
-
return { ...reverseKittingOI, status: ORDER_VAS_STATUS.READY_TO_PROCESS }
|
|
142
|
-
})
|
|
143
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
144
|
-
|
|
145
|
-
return reverseKitting
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
@Directive('@transaction')
|
|
149
|
-
@Mutation(returns => Boolean, { description: 'To confirm reverse kitting order' })
|
|
150
|
-
async completeReverseKittingOrder(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
151
|
-
const { tx, domain, user } = context.state
|
|
152
|
-
|
|
153
|
-
let foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
154
|
-
where: { domain: { id: domain.id }, name, status: ORDER_STATUS.EXECUTING },
|
|
155
|
-
relations: [
|
|
156
|
-
'bizplace',
|
|
157
|
-
'reverseKittingOrderInventories',
|
|
158
|
-
'reverseKittingOrderInventories.inventory',
|
|
159
|
-
'creator',
|
|
160
|
-
'updater'
|
|
161
|
-
]
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
if (!foundReverseKittingOrder) throw new Error(foundReverseKittingOrder.name + ` not found`)
|
|
165
|
-
|
|
166
|
-
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
167
|
-
|
|
168
|
-
await Promise.all(
|
|
169
|
-
reverseKittingOIs.map(async reverseKittingOI => {
|
|
170
|
-
let inventory: Inventory = reverseKittingOI.inventory
|
|
171
|
-
inventory.qty = inventory.qty - reverseKittingOI.qty
|
|
172
|
-
inventory.lockedQty = inventory.lockedQty - reverseKittingOI.qty
|
|
173
|
-
inventory.uomValue = inventory.uomValue - reverseKittingOI.uomValue
|
|
174
|
-
inventory.lockedUomValue = inventory.lockedUomValue - reverseKittingOI.uomValue
|
|
175
|
-
|
|
176
|
-
await InventoryUtil.transactionInventory(
|
|
177
|
-
inventory,
|
|
178
|
-
foundReverseKittingOrder,
|
|
179
|
-
-reverseKittingOI.qty,
|
|
180
|
-
-reverseKittingOI.uomValue,
|
|
181
|
-
INVENTORY_TRANSACTION_TYPE.REVERSE_KITTING,
|
|
182
|
-
user,
|
|
183
|
-
tx
|
|
184
|
-
)
|
|
185
|
-
})
|
|
186
|
-
)
|
|
187
|
-
|
|
188
|
-
reverseKittingOIs = reverseKittingOIs.map(reverseKittingOI => {
|
|
189
|
-
return {
|
|
190
|
-
...reverseKittingOI,
|
|
191
|
-
status: ORDER_VAS_STATUS.TERMINATED,
|
|
192
|
-
updater: user
|
|
193
|
-
}
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
197
|
-
|
|
198
|
-
foundReverseKittingOrder.status = ORDER_STATUS.DONE
|
|
199
|
-
foundReverseKittingOrder.updater = user
|
|
200
|
-
|
|
201
|
-
await tx.getRepository(ReverseKittingOrder).save(foundReverseKittingOrder)
|
|
202
|
-
|
|
203
|
-
return true
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
@Directive('@transaction')
|
|
207
|
-
@Mutation(returns => ReverseKittingOrder, { description: 'To cancel reverse kitting order' })
|
|
208
|
-
async cancelReverseKittingOrder(
|
|
209
|
-
@Arg('name') name: string,
|
|
210
|
-
@Ctx() context: ResolverContext
|
|
211
|
-
): Promise<ReverseKittingOrder> {
|
|
212
|
-
const { user, domain, tx } = context.state
|
|
213
|
-
|
|
214
|
-
const foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
215
|
-
where: { domain: { id: domain.id }, name, status: ORDER_STATUS.READY_TO_EXECUTE },
|
|
216
|
-
relations: [
|
|
217
|
-
'bizplace',
|
|
218
|
-
'reverseKittingOrderInventories',
|
|
219
|
-
'reverseKittingOrderInventories.inventory',
|
|
220
|
-
'creator',
|
|
221
|
-
'updater'
|
|
222
|
-
]
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
226
|
-
|
|
227
|
-
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
228
|
-
|
|
229
|
-
// 1. Reverse Kitting Order Status change (PENDING => PENDING_RECEIVE)
|
|
230
|
-
const reverseKitting: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).save({
|
|
231
|
-
...foundReverseKittingOrder,
|
|
232
|
-
status: ORDER_STATUS.CANCELLED,
|
|
233
|
-
updater: user
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
reverseKittingOIs = await Promise.all(
|
|
237
|
-
reverseKittingOIs.map(async (reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
238
|
-
if (reverseKittingOI?.inventory?.id) {
|
|
239
|
-
reverseKittingOI.inventory = await tx
|
|
240
|
-
.getRepository(Inventory)
|
|
241
|
-
.findOneBy({ id: reverseKittingOI.inventory.id })
|
|
242
|
-
|
|
243
|
-
await tx.getRepository(Inventory).save({
|
|
244
|
-
...reverseKittingOI.inventory,
|
|
245
|
-
lockedQty: reverseKittingOI.inventory.lockedQty - reverseKittingOI.qty,
|
|
246
|
-
lockedUomValue: reverseKittingOI.inventory.lockedUomValue - reverseKittingOI.uomValue,
|
|
247
|
-
updater: user
|
|
248
|
-
})
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return { ...reverseKittingOI, status: ORDER_VAS_STATUS.CANCELLED }
|
|
252
|
-
})
|
|
253
|
-
)
|
|
254
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
255
|
-
|
|
256
|
-
return reverseKitting
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
@Directive('@transaction')
|
|
260
|
-
@Mutation(returns => Boolean, { description: 'To undo the execution of reverse kitting order' })
|
|
261
|
-
async undoReverseKittingInventory(
|
|
262
|
-
@Arg('reverseKittingOIName') reverseKittingOIName: string,
|
|
263
|
-
@Arg('palletId') palletId: string,
|
|
264
|
-
@Ctx() context: ResolverContext
|
|
265
|
-
): Promise<boolean> {
|
|
266
|
-
const { tx, domain, user } = context.state
|
|
267
|
-
|
|
268
|
-
//@sumjoekin please add stricter validation. It is dangerous without strict validation. Unexpected behaviour will cause accidental deletion of inventory.
|
|
269
|
-
|
|
270
|
-
const reverseKittingOI: ReverseKittingOrderInventory = await tx
|
|
271
|
-
.getRepository(ReverseKittingOrderInventory)
|
|
272
|
-
.findOne({
|
|
273
|
-
where: { domain: { id: domain.id }, name: reverseKittingOIName },
|
|
274
|
-
relations: ['bizplace', 'reverseKittingOrder']
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
const bizplace: Bizplace = reverseKittingOI.bizplace
|
|
278
|
-
const reverseKittingOrder: ReverseKittingOrder = reverseKittingOI.reverseKittingOrder
|
|
279
|
-
let foundInventory: Inventory = await tx.getRepository(Inventory).findOne({
|
|
280
|
-
where: { domain: { id: domain.id }, bizplace: { id: bizplace.id }, orderVasId: reverseKittingOI.id, palletId },
|
|
281
|
-
relations: ['bizplace', 'product']
|
|
282
|
-
})
|
|
283
|
-
if (!foundInventory) throw new Error(`There's no results matched with condition ${foundInventory.palletId}`)
|
|
284
|
-
|
|
285
|
-
let operationGuide: any = JSON.parse(reverseKittingOI.operationGuide)
|
|
286
|
-
let productCombinationSets: any[] = operationGuide.data.productCombinationSets
|
|
287
|
-
productCombinationSets = productCombinationSets.map(item => {
|
|
288
|
-
if (foundInventory.product.id == item.productId) {
|
|
289
|
-
item.actualQty -= foundInventory.qty
|
|
290
|
-
}
|
|
291
|
-
return item
|
|
292
|
-
})
|
|
293
|
-
operationGuide.data.productCombinationSets = productCombinationSets
|
|
294
|
-
|
|
295
|
-
await tx
|
|
296
|
-
.getRepository(ReverseKittingOrderInventory)
|
|
297
|
-
.update({ id: reverseKittingOI.id }, { operationGuide: operationGuide })
|
|
298
|
-
|
|
299
|
-
foundInventory.lastSeq++
|
|
300
|
-
foundInventory.status = INVENTORY_STATUS.DELETED
|
|
301
|
-
foundInventory = await InventoryUtil.transactionInventory(
|
|
302
|
-
foundInventory,
|
|
303
|
-
reverseKittingOrder,
|
|
304
|
-
-foundInventory.qty,
|
|
305
|
-
-foundInventory.uomValue,
|
|
306
|
-
INVENTORY_TRANSACTION_TYPE.UNDO_REVERSE_KITTING,
|
|
307
|
-
user,
|
|
308
|
-
tx
|
|
309
|
-
)
|
|
310
|
-
foundInventory.qty = 0
|
|
311
|
-
foundInventory.uomValue = 0
|
|
312
|
-
foundInventory.updater = user
|
|
313
|
-
|
|
314
|
-
await tx.getRepository(InventoryHistory).update({ inventory: foundInventory }, { inventory: null })
|
|
315
|
-
|
|
316
|
-
await tx.getRepository(Inventory).delete({ id: foundInventory.id })
|
|
317
|
-
|
|
318
|
-
return true
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
@Directive('@transaction')
|
|
322
|
-
@Mutation(returns => ReverseKittingOrder, { description: 'To activate reverse kitting order' })
|
|
323
|
-
async activateReverseKittingOrder(
|
|
324
|
-
@Arg('name') name: string,
|
|
325
|
-
@Ctx() context: ResolverContext
|
|
326
|
-
): Promise<ReverseKittingOrder> {
|
|
327
|
-
const { user, domain, tx } = context.state
|
|
328
|
-
|
|
329
|
-
const foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
330
|
-
where: { domain: { id: domain.id }, name, status: ORDER_STATUS.READY_TO_EXECUTE },
|
|
331
|
-
relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
335
|
-
|
|
336
|
-
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
337
|
-
|
|
338
|
-
// 1. Reverse Kitting Order Status change (PENDING => PENDING_RECEIVE)
|
|
339
|
-
const reverseKitting: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).save({
|
|
340
|
-
...foundReverseKittingOrder,
|
|
341
|
-
status: ORDER_STATUS.EXECUTING,
|
|
342
|
-
updater: user
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
reverseKittingOIs = reverseKittingOIs.map((reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
346
|
-
return { ...reverseKittingOI, status: ORDER_VAS_STATUS.PROCESSING }
|
|
347
|
-
})
|
|
348
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
|
|
349
|
-
|
|
350
|
-
return reverseKitting
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
@Directive('@transaction')
|
|
354
|
-
@Mutation(returns => Boolean, { description: 'To execute reverse kitting order' })
|
|
355
|
-
async executeReverseKitting(
|
|
356
|
-
@Arg('name') name: string,
|
|
357
|
-
@Arg('inventory', type => InventoryPatch) inventory: Partial<Inventory>,
|
|
358
|
-
@Ctx() context: ResolverContext
|
|
359
|
-
): Promise<boolean> {
|
|
360
|
-
const { user, domain, tx } = context.state
|
|
361
|
-
|
|
362
|
-
let reverseKittingOI: ReverseKittingOrderInventory = await tx.getRepository(ReverseKittingOrderInventory).findOne({
|
|
363
|
-
where: {
|
|
364
|
-
name,
|
|
365
|
-
domain: { id: domain.id },
|
|
366
|
-
status: Not(Equal(ORDER_VAS_STATUS.READY_TO_PROCESS))
|
|
367
|
-
},
|
|
368
|
-
relations: ['bizplace', 'reverseKittingOrder', 'reverseKittingOrder.bizplace', 'inventory']
|
|
369
|
-
})
|
|
370
|
-
|
|
371
|
-
const foundReverseKittingOrder: ReverseKittingOrder = reverseKittingOI.reverseKittingOrder
|
|
372
|
-
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
373
|
-
|
|
374
|
-
const customerBizplace: Bizplace = foundReverseKittingOrder.bizplace
|
|
375
|
-
|
|
376
|
-
const productDetail: ProductDetail = await tx.getRepository(ProductDetail).findOne({
|
|
377
|
-
where: { id: (inventory as any).productDetailId },
|
|
378
|
-
relations: ['product']
|
|
379
|
-
})
|
|
380
|
-
|
|
381
|
-
const location: Location = await tx.getRepository(Location).findOne({
|
|
382
|
-
where: {
|
|
383
|
-
domain: { id: domain.id },
|
|
384
|
-
name: (inventory as any).locationName,
|
|
385
|
-
type: In([LOCATION_TYPE.SHELF, LOCATION_TYPE.BUFFER, LOCATION_TYPE.FLOOR])
|
|
386
|
-
},
|
|
387
|
-
relations: ['warehouse']
|
|
388
|
-
})
|
|
389
|
-
if (!location) throw new Error((inventory as any).locationName + ' not exists')
|
|
390
|
-
|
|
391
|
-
const palletId: string = inventory.palletId
|
|
392
|
-
await InventoryUtil.checkPalletDuplication(inventory.palletId, domain, tx)
|
|
393
|
-
|
|
394
|
-
const product: Product = productDetail.product
|
|
395
|
-
const packingType: string = productDetail.packingType
|
|
396
|
-
const packingSize: number = productDetail.packingSize
|
|
397
|
-
const uom: string = productDetail.uom
|
|
398
|
-
const qty: number = inventory.qty
|
|
399
|
-
const uomValue: number = Math.round(qty * productDetail.uomValue * 100) / 100
|
|
400
|
-
const batchId: string = reverseKittingOI.inventory.batchId
|
|
401
|
-
const orderId: string = foundReverseKittingOrder.id
|
|
402
|
-
const warehouse: Warehouse = location.warehouse
|
|
403
|
-
const zone: string = location.zone
|
|
404
|
-
|
|
405
|
-
let newInventory: Partial<Inventory> = new Inventory()
|
|
406
|
-
newInventory.bizplace = customerBizplace
|
|
407
|
-
newInventory.name = InventoryNoGenerator.inventoryName()
|
|
408
|
-
newInventory.orderVasId = reverseKittingOI.id
|
|
409
|
-
newInventory.palletId = palletId
|
|
410
|
-
newInventory.batchId = batchId
|
|
411
|
-
newInventory.product = product
|
|
412
|
-
newInventory.packingType = packingType
|
|
413
|
-
newInventory.packingSize = packingSize
|
|
414
|
-
newInventory.uom = uom
|
|
415
|
-
newInventory.qty = qty
|
|
416
|
-
newInventory.uomValue = uomValue
|
|
417
|
-
newInventory.refOrderId = orderId
|
|
418
|
-
newInventory.warehouse = warehouse
|
|
419
|
-
newInventory.location = location
|
|
420
|
-
newInventory.zone = zone
|
|
421
|
-
newInventory.refInventory = reverseKittingOI.inventory
|
|
422
|
-
newInventory.status = INVENTORY_STATUS.STORED
|
|
423
|
-
newInventory.domain = domain
|
|
424
|
-
newInventory.creator = user
|
|
425
|
-
newInventory.updater = user
|
|
426
|
-
|
|
427
|
-
newInventory = await InventoryUtil.transactionInventory(
|
|
428
|
-
newInventory as any,
|
|
429
|
-
foundReverseKittingOrder,
|
|
430
|
-
newInventory.qty,
|
|
431
|
-
newInventory.uomValue,
|
|
432
|
-
INVENTORY_TRANSACTION_TYPE.REVERSE_KITTING,
|
|
433
|
-
user,
|
|
434
|
-
tx
|
|
435
|
-
)
|
|
436
|
-
|
|
437
|
-
let operationGuide: any = JSON.parse(reverseKittingOI.operationGuide)
|
|
438
|
-
let productCombinationSets: any[] = operationGuide.data.productCombinationSets
|
|
439
|
-
operationGuide.data.productCombinationSets = productCombinationSets.map(item => {
|
|
440
|
-
if (item.productDetailId == (inventory as any).productDetailId) {
|
|
441
|
-
item.actualQty += qty
|
|
442
|
-
}
|
|
443
|
-
return item
|
|
444
|
-
})
|
|
445
|
-
reverseKittingOI.operationGuide = JSON.stringify(operationGuide)
|
|
446
|
-
|
|
447
|
-
await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOI)
|
|
448
|
-
return true
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
@Directive('@transaction')
|
|
452
|
-
@Mutation(returns => Boolean, { description: 'To delete ReverseKittingOrder' })
|
|
453
|
-
async deleteReverseKittingOrder(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
454
|
-
const { domain, tx, user } = context.state
|
|
455
|
-
let foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
|
|
456
|
-
where: { domain: { id: domain.id }, name },
|
|
457
|
-
relations: [
|
|
458
|
-
'bizplace',
|
|
459
|
-
'reverseKittingOrderInventories',
|
|
460
|
-
'reverseKittingOrderInventories.inventory',
|
|
461
|
-
'creator',
|
|
462
|
-
'updater'
|
|
463
|
-
]
|
|
464
|
-
})
|
|
465
|
-
|
|
466
|
-
if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
|
|
467
|
-
|
|
468
|
-
const reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
|
|
469
|
-
|
|
470
|
-
// Delete order reverse kittings by ids
|
|
471
|
-
await Promise.all(
|
|
472
|
-
reverseKittingOIs.map(async (reverseKittingOI: ReverseKittingOrderInventory) => {
|
|
473
|
-
if (reverseKittingOI?.inventory?.id) {
|
|
474
|
-
reverseKittingOI.inventory = await tx
|
|
475
|
-
.getRepository(Inventory)
|
|
476
|
-
.findOneBy({ id: reverseKittingOI.inventory.id })
|
|
477
|
-
|
|
478
|
-
await tx.getRepository(Inventory).save({
|
|
479
|
-
...reverseKittingOI.inventory,
|
|
480
|
-
lockedQty: reverseKittingOI.inventory.lockedQty - reverseKittingOI.qty,
|
|
481
|
-
lockedUomValue: reverseKittingOI.inventory.lockedUomValue - reverseKittingOI.uomValue,
|
|
482
|
-
updater: user
|
|
483
|
-
})
|
|
484
|
-
}
|
|
485
|
-
return reverseKittingOI
|
|
486
|
-
})
|
|
487
|
-
)
|
|
488
|
-
|
|
489
|
-
// 1. delete order reverse kittings
|
|
490
|
-
const productIds = reverseKittingOIs.map((ork: ReverseKittingOrderInventory) => ork.id)
|
|
491
|
-
if (productIds.length) {
|
|
492
|
-
await tx.getRepository(ReverseKittingOrderInventory).delete({ id: In(productIds) })
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// 2. delete Reverse Kitting Order
|
|
496
|
-
await tx.getRepository(ReverseKittingOrder).delete({ domain: { id: domain.id }, name })
|
|
497
|
-
|
|
498
|
-
return true
|
|
499
|
-
}
|
|
500
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import { Bizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
6
|
-
import { generateId } from '@things-factory/id-rule-base'
|
|
7
|
-
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
8
|
-
import { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
|
9
|
-
import { Inventory, INVENTORY_STATUS } from '@things-factory/warehouse-base'
|
|
10
|
-
|
|
11
|
-
import { ORDER_VAS_STATUS } from '../../constants'
|
|
12
|
-
import { ReverseKittingOrderInventory } from '../reverse-kitting-order-inventory/reverse-kitting-order-inventory'
|
|
13
|
-
import { ReverseKittingOrder } from './reverse-kitting-order'
|
|
14
|
-
import { LotInfo, ReverseKittingInventoryDetail, ReverseKittingOrderList } from './reverse-kitting-order-type'
|
|
15
|
-
|
|
16
|
-
@Resolver(ReverseKittingOrder)
|
|
17
|
-
export class ReverseKittingOrderQuery {
|
|
18
|
-
@Query(returns => ReverseKittingOrder, { description: 'To fetch a ReverseKittingOrder' })
|
|
19
|
-
async reverseKittingOrder(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<ReverseKittingOrder> {
|
|
20
|
-
const { domain, user } = context.state
|
|
21
|
-
|
|
22
|
-
return await getRepository(ReverseKittingOrder).findOne({
|
|
23
|
-
where: {
|
|
24
|
-
domain: { id: domain.id },
|
|
25
|
-
name,
|
|
26
|
-
bizplace: { id: In(await getPermittedBizplaceIds(domain, user)) }
|
|
27
|
-
},
|
|
28
|
-
relations: [
|
|
29
|
-
'domain',
|
|
30
|
-
'bizplace',
|
|
31
|
-
'reverseKittingOrderInventories',
|
|
32
|
-
'reverseKittingOrderInventories.vas',
|
|
33
|
-
'reverseKittingOrderInventories.inventory',
|
|
34
|
-
'reverseKittingOrderInventories.inventory.product',
|
|
35
|
-
'reverseKittingOrderInventories.inventory.location',
|
|
36
|
-
'reverseKittingOrderInventories.inventory.warehouse',
|
|
37
|
-
'creator',
|
|
38
|
-
'updater'
|
|
39
|
-
]
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Query(returns => [ReverseKittingOrder], { description: 'To fetch a ReverseKittingOrder' })
|
|
44
|
-
async reverseKittingInventories(
|
|
45
|
-
@Arg('reverseKittingOIName') reverseKittingOIName: string,
|
|
46
|
-
@Arg('productDetailId') productDetailId: string,
|
|
47
|
-
@Ctx() context: ResolverContext
|
|
48
|
-
): Promise<Inventory[]> {
|
|
49
|
-
const { domain } = context.state
|
|
50
|
-
|
|
51
|
-
const productDetail: ProductDetail = await getRepository(ProductDetail).findOne({
|
|
52
|
-
where: { id: productDetailId },
|
|
53
|
-
relations: ['product']
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const product: Product = productDetail.product
|
|
57
|
-
|
|
58
|
-
const foundReverseKittingOI: ReverseKittingOrderInventory = await getRepository(
|
|
59
|
-
ReverseKittingOrderInventory
|
|
60
|
-
).findOne({
|
|
61
|
-
where: {
|
|
62
|
-
domain: { id: domain.id },
|
|
63
|
-
name: reverseKittingOIName,
|
|
64
|
-
status: ORDER_VAS_STATUS.PROCESSING
|
|
65
|
-
},
|
|
66
|
-
relations: ['bizplace', 'reverseKittingOrder', 'inventory']
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if (!foundReverseKittingOI) return
|
|
70
|
-
|
|
71
|
-
const reverseKittingOrder: ReverseKittingOrder = foundReverseKittingOI.reverseKittingOrder
|
|
72
|
-
const customerBizplace: Bizplace = foundReverseKittingOI.bizplace
|
|
73
|
-
return await getRepository(Inventory).find({
|
|
74
|
-
where: {
|
|
75
|
-
domain: { id: domain.id },
|
|
76
|
-
bizplace: { id: customerBizplace } as any,
|
|
77
|
-
refOrderId: reverseKittingOrder.id,
|
|
78
|
-
orderVasId: foundReverseKittingOI.id,
|
|
79
|
-
product: { id: product.id },
|
|
80
|
-
status: INVENTORY_STATUS.STORED
|
|
81
|
-
},
|
|
82
|
-
relations: ['product', 'bizplace', 'location']
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@Query(returns => [ReverseKittingInventoryDetail], {
|
|
87
|
-
description: 'To generate lot id and label for reverse kitting'
|
|
88
|
-
})
|
|
89
|
-
async generateReverseKittingLotId(
|
|
90
|
-
@Arg('targets', type => [LotInfo]) targets: LotInfo[],
|
|
91
|
-
@Arg('type') type: string,
|
|
92
|
-
@Ctx() context: ResolverContext
|
|
93
|
-
): Promise<ReverseKittingInventoryDetail[]> {
|
|
94
|
-
const { tx, domain } = context.state
|
|
95
|
-
// 1. get and set the date
|
|
96
|
-
const today = new Date()
|
|
97
|
-
const year = today.getFullYear()
|
|
98
|
-
const month = today.getMonth()
|
|
99
|
-
const day = today.getDate()
|
|
100
|
-
|
|
101
|
-
const yy = String(year).substr(String(year).length - 2)
|
|
102
|
-
const mm = String(month + 1).padStart(2, '0')
|
|
103
|
-
const dd = String(day).padStart(2, '0')
|
|
104
|
-
|
|
105
|
-
const date = yy + mm + dd
|
|
106
|
-
let results = []
|
|
107
|
-
|
|
108
|
-
// 2. get worksheet detail
|
|
109
|
-
let ids = targets.map(target => target.id)
|
|
110
|
-
|
|
111
|
-
// - getRepository using In(array) to pass the value to defined variable
|
|
112
|
-
const foundOrderReverseKittings: ReverseKittingOrderInventory[] = await tx
|
|
113
|
-
.getRepository(ReverseKittingOrderInventory)
|
|
114
|
-
.find({
|
|
115
|
-
where: {
|
|
116
|
-
domain: { id: domain.id },
|
|
117
|
-
id: In(ids)
|
|
118
|
-
},
|
|
119
|
-
relations: ['domain', 'bizplace']
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
// 3. from worksheet detail get product name, product type, batchid, packing type, bizplace
|
|
123
|
-
|
|
124
|
-
if (foundOrderReverseKittings.length <= 0) throw new Error('Unable to find order reverse kittings')
|
|
125
|
-
else {
|
|
126
|
-
for (let i = 0; i < foundOrderReverseKittings.length; i++) {
|
|
127
|
-
let foundORK = foundOrderReverseKittings[i]
|
|
128
|
-
for (let idx = 0; idx < targets.length; idx++) {
|
|
129
|
-
if (foundORK.id === targets[idx].id) {
|
|
130
|
-
// 4. generate pallet id based on print qty > call generateId resolver
|
|
131
|
-
for (let i = 0; i < targets[idx].printQty; i++) {
|
|
132
|
-
const generatedPalletId = await generateId({
|
|
133
|
-
domain,
|
|
134
|
-
type,
|
|
135
|
-
seed: {
|
|
136
|
-
batchId: foundORK.inventory.batchId,
|
|
137
|
-
date: date
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
// 5. map all data to be returned
|
|
142
|
-
if (foundORK != null) {
|
|
143
|
-
results.push({
|
|
144
|
-
...foundORK,
|
|
145
|
-
palletId: generatedPalletId,
|
|
146
|
-
bizplace: foundORK.bizplace
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return results
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
@Query(returns => ReverseKittingOrderList, { description: 'To fetch multiple ReverseKittingOrders' })
|
|
159
|
-
async reverseKittingOrders(
|
|
160
|
-
@Args(type => ListParam) params: ListParam,
|
|
161
|
-
@Ctx() context: ResolverContext
|
|
162
|
-
): Promise<ReverseKittingOrderList> {
|
|
163
|
-
const { domain, user } = context.state
|
|
164
|
-
|
|
165
|
-
const convertedParams = convertListParams(params)
|
|
166
|
-
convertedParams.where.bizplace = In(await getPermittedBizplaceIds(domain, user))
|
|
167
|
-
|
|
168
|
-
const [items, total] = await getRepository(ReverseKittingOrder).findAndCount({
|
|
169
|
-
...convertedParams,
|
|
170
|
-
relations: [
|
|
171
|
-
'domain',
|
|
172
|
-
'bizplace',
|
|
173
|
-
'reverseKittingOrderInventories',
|
|
174
|
-
'reverseKittingOrderInventories.inventory',
|
|
175
|
-
'reverseKittingOrderInventories.inventory.product',
|
|
176
|
-
'creator',
|
|
177
|
-
'updater'
|
|
178
|
-
]
|
|
179
|
-
})
|
|
180
|
-
return { items, total }
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
@FieldResolver(type => Domain)
|
|
184
|
-
async domain(@Root() reverseKittingOrder: ReverseKittingOrder): Promise<Domain> {
|
|
185
|
-
return await getRepository(Domain).findOneBy({ id: reverseKittingOrder.domainId })
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
@FieldResolver(type => User)
|
|
189
|
-
async updater(@Root() reverseKittingOrder: ReverseKittingOrder): Promise<User> {
|
|
190
|
-
return await getRepository(User).findOneBy({ id: reverseKittingOrder.updaterId })
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
@FieldResolver(type => User)
|
|
194
|
-
async creator(@Root() reverseKittingOrder: ReverseKittingOrder): Promise<User> {
|
|
195
|
-
return await getRepository(User).findOneBy({ id: reverseKittingOrder.creatorId })
|
|
196
|
-
}
|
|
197
|
-
}
|