@things-factory/sales-base 4.0.7 → 4.0.12

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.
Files changed (77) hide show
  1. package/dist-server/constants/order.js +9 -1
  2. package/dist-server/constants/order.js.map +1 -1
  3. package/dist-server/constants/validation-error-code.js +2 -1
  4. package/dist-server/constants/validation-error-code.js.map +1 -1
  5. package/dist-server/controllers/ecommerce/sellercraft-controller.js +3 -3
  6. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
  7. package/dist-server/service/arrival-notice/arrival-notice-mutation.js +21 -0
  8. package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
  9. package/dist-server/service/arrival-notice/arrival-notice-query.js +74 -76
  10. package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
  11. package/dist-server/service/delivery-order/delivery-order-query.js +21 -5
  12. package/dist-server/service/delivery-order/delivery-order-query.js.map +1 -1
  13. package/dist-server/service/goods-receival-note/goods-receival-note-query.js +93 -43
  14. package/dist-server/service/goods-receival-note/goods-receival-note-query.js.map +1 -1
  15. package/dist-server/service/index.js +4 -0
  16. package/dist-server/service/index.js.map +1 -1
  17. package/dist-server/service/manifest/index.js +9 -0
  18. package/dist-server/service/manifest/index.js.map +1 -0
  19. package/dist-server/service/manifest/manifest-mutation.js +120 -0
  20. package/dist-server/service/manifest/manifest-mutation.js.map +1 -0
  21. package/dist-server/service/manifest/manifest-query.js +87 -0
  22. package/dist-server/service/manifest/manifest-query.js.map +1 -0
  23. package/dist-server/service/manifest/manifest-type.js +85 -0
  24. package/dist-server/service/manifest/manifest-type.js.map +1 -0
  25. package/dist-server/service/manifest/manifest.js +117 -0
  26. package/dist-server/service/manifest/manifest.js.map +1 -0
  27. package/dist-server/service/order-inventory/order-inventory-mutation.js +24 -0
  28. package/dist-server/service/order-inventory/order-inventory-mutation.js.map +1 -1
  29. package/dist-server/service/order-inventory/order-inventory-query.js +20 -19
  30. package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
  31. package/dist-server/service/order-inventory/order-inventory-types.js +17 -13
  32. package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
  33. package/dist-server/service/order-inventory/order-inventory.js +24 -2
  34. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  35. package/dist-server/service/others/other-query.js +1 -0
  36. package/dist-server/service/others/other-query.js.map +1 -1
  37. package/dist-server/service/release-good/release-good-mutation.js +33 -0
  38. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  39. package/dist-server/service/release-good/release-good.js +28 -1
  40. package/dist-server/service/release-good/release-good.js.map +1 -1
  41. package/dist-server/service/reverse-kitting-order/reverse-kitting-order-mutation.js +56 -23
  42. package/dist-server/service/reverse-kitting-order/reverse-kitting-order-mutation.js.map +1 -1
  43. package/dist-server/service/reverse-kitting-order/reverse-kitting-order-query.js +76 -15
  44. package/dist-server/service/reverse-kitting-order/reverse-kitting-order-query.js.map +1 -1
  45. package/dist-server/utils/inventory-util.js +26 -7
  46. package/dist-server/utils/inventory-util.js.map +1 -1
  47. package/dist-server/utils/order-no-generator.js +35 -31
  48. package/dist-server/utils/order-no-generator.js.map +1 -1
  49. package/package.json +12 -12
  50. package/server/constants/index.ts +1 -1
  51. package/server/constants/order.ts +10 -0
  52. package/server/constants/validation-error-code.ts +3 -2
  53. package/server/controllers/ecommerce/sellercraft-controller.ts +4 -3
  54. package/server/service/arrival-notice/arrival-notice-mutation.ts +20 -0
  55. package/server/service/arrival-notice/arrival-notice-query.ts +82 -76
  56. package/server/service/delivery-order/delivery-order-query.ts +26 -7
  57. package/server/service/goods-receival-note/goods-receival-note-query.ts +116 -53
  58. package/server/service/index.ts +4 -0
  59. package/server/service/manifest/index.ts +6 -0
  60. package/server/service/manifest/manifest-mutation.ts +112 -0
  61. package/server/service/manifest/manifest-query.ts +43 -0
  62. package/server/service/manifest/manifest-type.ts +51 -0
  63. package/server/service/manifest/manifest.ts +98 -0
  64. package/server/service/order-inventory/order-inventory-mutation.ts +26 -1
  65. package/server/service/order-inventory/order-inventory-query.ts +17 -18
  66. package/server/service/order-inventory/order-inventory-types.ts +15 -10
  67. package/server/service/order-inventory/order-inventory.ts +24 -5
  68. package/server/service/others/other-query.ts +2 -6
  69. package/server/service/release-good/release-good-mutation.ts +45 -0
  70. package/server/service/release-good/release-good.ts +26 -0
  71. package/server/service/reverse-kitting-order/reverse-kitting-order-mutation.ts +76 -27
  72. package/server/service/reverse-kitting-order/reverse-kitting-order-query.ts +85 -17
  73. package/server/utils/inventory-util.ts +30 -7
  74. package/server/utils/order-no-generator.ts +43 -36
  75. package/dist-server/middlewares/index.js +0 -1
  76. package/dist-server/middlewares/index.js.map +0 -1
  77. package/server/middlewares/index.ts +0 -0
@@ -1,14 +1,14 @@
1
1
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
2
  import { Equal, In, Not } from 'typeorm'
3
3
 
4
- import { Bizplace, getCompanyBizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
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,
11
10
  InventoryNoGenerator,
11
+ InventoryPatch,
12
12
  InventoryUtil,
13
13
  Location,
14
14
  LOCATION_TYPE,
@@ -53,7 +53,14 @@ export class ReverseKittingOrderMutation {
53
53
  reverseKittingOrderOIs = await Promise.all(
54
54
  reverseKittingOrderOIs.map(async (ork: any) => {
55
55
  if (ork?.inventory?.id) {
56
- ork.inventory = await tx.getRepository(Inventory).findOne(ork.inventory.id)
56
+ const foundInv: Inventory = await tx.getRepository(Inventory).findOne(ork.inventory.id)
57
+ ork.inventory = foundInv
58
+
59
+ foundInv.lockedQty = Number(foundInv.lockedQty) + ork.qty
60
+ foundInv.lockedUomValue = Number(foundInv.lockedUomValue) + ork.uomValue
61
+ foundInv.updater = user
62
+
63
+ await tx.getRepository(Inventory).save(foundInv)
57
64
  }
58
65
  return {
59
66
  ...ork,
@@ -63,8 +70,7 @@ export class ReverseKittingOrderMutation {
63
70
  bizplace: customerBizplace,
64
71
  type: ORDER_TYPES.VAS_ORDER,
65
72
  status: ORDER_VAS_STATUS.PENDING,
66
- creator: user,
67
- updater: user
73
+ creator: user
68
74
  }
69
75
  })
70
76
  )
@@ -113,7 +119,7 @@ export class ReverseKittingOrderMutation {
113
119
  relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
114
120
  })
115
121
 
116
- let foundORKs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
122
+ let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
117
123
 
118
124
  if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
119
125
 
@@ -124,10 +130,10 @@ export class ReverseKittingOrderMutation {
124
130
  updater: user
125
131
  })
126
132
 
127
- foundORKs = foundORKs.map((ork: ReverseKittingOrderInventory) => {
133
+ reverseKittingOIs = reverseKittingOIs.map((ork: ReverseKittingOrderInventory) => {
128
134
  return { ...ork, status: ORDER_VAS_STATUS.READY_TO_PROCESS }
129
135
  })
130
- await tx.getRepository(ReverseKittingOrderInventory).save(foundORKs)
136
+ await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
131
137
 
132
138
  return reverseKitting
133
139
  }
@@ -150,14 +156,15 @@ export class ReverseKittingOrderMutation {
150
156
 
151
157
  if (!foundReverseKittingOrder) throw new Error(foundReverseKittingOrder.name + ` not found`)
152
158
 
153
- let reverseKittingOrderInventories: ReverseKittingOrderInventory[] =
154
- foundReverseKittingOrder.reverseKittingOrderInventories
159
+ let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
155
160
 
156
161
  await Promise.all(
157
- reverseKittingOrderInventories.map(async reverseKittingOI => {
162
+ reverseKittingOIs.map(async reverseKittingOI => {
158
163
  let inventory: Inventory = reverseKittingOI.inventory
159
164
  inventory.qty = inventory.qty - reverseKittingOI.qty
165
+ inventory.lockedQty = inventory.lockedQty - reverseKittingOI.qty
160
166
  inventory.uomValue = inventory.uomValue - reverseKittingOI.uomValue
167
+ inventory.lockedUomValue = inventory.lockedUomValue - reverseKittingOI.uomValue
161
168
 
162
169
  await InventoryUtil.transactionInventory(
163
170
  inventory,
@@ -171,7 +178,7 @@ export class ReverseKittingOrderMutation {
171
178
  })
172
179
  )
173
180
 
174
- reverseKittingOrderInventories = reverseKittingOrderInventories.map(reverseKittingOI => {
181
+ reverseKittingOIs = reverseKittingOIs.map(reverseKittingOI => {
175
182
  return {
176
183
  ...reverseKittingOI,
177
184
  status: ORDER_VAS_STATUS.TERMINATED,
@@ -179,7 +186,7 @@ export class ReverseKittingOrderMutation {
179
186
  }
180
187
  })
181
188
 
182
- await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOrderInventories)
189
+ await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
183
190
 
184
191
  foundReverseKittingOrder.status = ORDER_STATUS.DONE
185
192
  foundReverseKittingOrder.updater = user
@@ -196,23 +203,43 @@ export class ReverseKittingOrderMutation {
196
203
 
197
204
  const foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
198
205
  where: { domain, name, status: ORDER_STATUS.READY_TO_EXECUTE },
199
- relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
206
+ relations: [
207
+ 'bizplace',
208
+ 'reverseKittingOrderInventories',
209
+ 'reverseKittingOrderInventories.inventory',
210
+ 'creator',
211
+ 'updater'
212
+ ]
200
213
  })
201
214
 
202
- let foundKOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
215
+ let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
203
216
 
204
217
  if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
205
218
 
219
+ // 1. Reverse Kitting Order Status change (PENDING => PENDING_RECEIVE)
206
220
  const reverseKitting: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).save({
207
221
  ...foundReverseKittingOrder,
208
222
  status: ORDER_STATUS.CANCELLED,
209
223
  updater: user
210
224
  })
211
225
 
212
- foundKOIs = foundKOIs.map((ork: ReverseKittingOrderInventory) => {
213
- return { ...ork, status: ORDER_VAS_STATUS.CANCELLED }
214
- })
215
- await tx.getRepository(ReverseKittingOrderInventory).save(foundKOIs)
226
+ reverseKittingOIs = await Promise.all(
227
+ reverseKittingOIs.map(async (reverseKittingOI: ReverseKittingOrderInventory) => {
228
+ if (reverseKittingOI?.inventory?.id) {
229
+ reverseKittingOI.inventory = await tx.getRepository(Inventory).findOne(reverseKittingOI.inventory.id)
230
+
231
+ await tx.getRepository(Inventory).save({
232
+ ...reverseKittingOI.inventory,
233
+ lockedQty: reverseKittingOI.inventory.lockedQty - reverseKittingOI.qty,
234
+ lockedUomValue: reverseKittingOI.inventory.lockedUomValue - reverseKittingOI.uomValue,
235
+ updater: user
236
+ })
237
+ }
238
+
239
+ return { ...reverseKittingOI, status: ORDER_VAS_STATUS.CANCELLED }
240
+ })
241
+ )
242
+ await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
216
243
 
217
244
  return reverseKitting
218
245
  }
@@ -227,7 +254,7 @@ export class ReverseKittingOrderMutation {
227
254
  relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
228
255
  })
229
256
 
230
- let foundKOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
257
+ let reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
231
258
 
232
259
  if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
233
260
 
@@ -238,10 +265,10 @@ export class ReverseKittingOrderMutation {
238
265
  updater: user
239
266
  })
240
267
 
241
- foundKOIs = foundKOIs.map((ork: ReverseKittingOrderInventory) => {
268
+ reverseKittingOIs = reverseKittingOIs.map((ork: ReverseKittingOrderInventory) => {
242
269
  return { ...ork, status: ORDER_VAS_STATUS.PROCESSING }
243
270
  })
244
- await tx.getRepository(ReverseKittingOrderInventory).save(foundKOIs)
271
+ await tx.getRepository(ReverseKittingOrderInventory).save(reverseKittingOIs)
245
272
 
246
273
  return reverseKitting
247
274
  }
@@ -268,11 +295,9 @@ export class ReverseKittingOrderMutation {
268
295
  if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
269
296
 
270
297
  const customerBizplace: Bizplace = foundReverseKittingOrder.bizplace
271
- const customerCompanyBizplace: Bizplace = await getCompanyBizplace(null, null, customerBizplace.id)
272
298
 
273
299
  const productDetail: ProductDetail = await tx.getRepository(ProductDetail).findOne({
274
300
  where: {
275
- domain: customerCompanyBizplace.domain,
276
301
  id: inventory.productDetailId
277
302
  },
278
303
  relations: ['product']
@@ -318,6 +343,7 @@ export class ReverseKittingOrderMutation {
318
343
  newInventory.warehouse = warehouse
319
344
  newInventory.location = location
320
345
  newInventory.zone = zone
346
+ newInventory.refInventory = reverseKittingOI.inventory
321
347
  newInventory.status = INVENTORY_STATUS.STORED
322
348
  newInventory.domain = domain
323
349
  newInventory.creator = user
@@ -337,7 +363,7 @@ export class ReverseKittingOrderMutation {
337
363
  let productCombinationSets: any[] = operationGuide.data.productCombinationSets
338
364
  operationGuide.data.productCombinationSets = productCombinationSets.map(item => {
339
365
  if (item.productDetailId == inventory.productDetailId) {
340
- item.actualQty++
366
+ item.actualQty += qty
341
367
  }
342
368
  return item
343
369
  })
@@ -350,16 +376,39 @@ export class ReverseKittingOrderMutation {
350
376
  @Directive('@transaction')
351
377
  @Mutation(returns => Boolean, { description: 'To delete ReverseKittingOrder' })
352
378
  async deleteReverseKittingOrder(@Arg('name') name: string, @Ctx() context: any): Promise<boolean> {
353
- const { domain, tx } = context.state
379
+ const { domain, tx, user } = context.state
354
380
  let foundReverseKittingOrder: ReverseKittingOrder = await tx.getRepository(ReverseKittingOrder).findOne({
355
381
  where: { domain, name },
356
- relations: ['bizplace', 'reverseKittingOrderInventories', 'creator', 'updater']
382
+ relations: [
383
+ 'bizplace',
384
+ 'reverseKittingOrderInventories',
385
+ 'reverseKittingOrderInventories.inventory',
386
+ 'creator',
387
+ 'updater'
388
+ ]
357
389
  })
358
390
 
359
391
  if (!foundReverseKittingOrder) throw new Error(`Reverse kitting order doesn't exists.`)
360
392
 
361
393
  const reverseKittingOIs: ReverseKittingOrderInventory[] = foundReverseKittingOrder.reverseKittingOrderInventories
362
394
 
395
+ // Delete order reverse kittings by ids
396
+ await Promise.all(
397
+ reverseKittingOIs.map(async (ork: ReverseKittingOrderInventory) => {
398
+ if (ork?.inventory?.id) {
399
+ ork.inventory = await tx.getRepository(Inventory).findOne(ork.inventory.id)
400
+
401
+ await tx.getRepository(Inventory).save({
402
+ ...ork.inventory,
403
+ lockedQty: ork.inventory.lockedQty - ork.qty,
404
+ lockedUomValue: ork.inventory.lockedUomValue - ork.uomValue,
405
+ updater: user
406
+ })
407
+ }
408
+ return ork
409
+ })
410
+ )
411
+
363
412
  // 1. delete order reverse kittings
364
413
  const productIds = reverseKittingOIs.map((ork: ReverseKittingOrderInventory) => ork.id)
365
414
  if (productIds.length) {
@@ -26,13 +26,13 @@ export class ReverseKittingOrderQuery {
26
26
  relations: [
27
27
  'domain',
28
28
  'bizplace',
29
- 'orderReverseKittings',
30
- 'orderReverseKittings.vas',
31
- 'orderReverseKittings.inventory',
32
- 'orderReverseKittings.inventory.product',
33
- 'orderReverseKittings.inventory.location',
34
- 'orderReverseKittings.inventory.warehouse',
35
- 'orderReverseKittings.targetProduct',
29
+ 'reverseKittingOrderInventories',
30
+ 'reverseKittingOrderInventories.vas',
31
+ 'reverseKittingOrderInventories.inventory',
32
+ 'reverseKittingOrderInventories.inventory.product',
33
+ 'reverseKittingOrderInventories.inventory.location',
34
+ 'reverseKittingOrderInventories.inventory.warehouse',
35
+ 'reverseKittingOrderInventories.targetProduct',
36
36
  'creator',
37
37
  'updater'
38
38
  ]
@@ -45,9 +45,7 @@ export class ReverseKittingOrderQuery {
45
45
  @Ctx() context: any
46
46
  ): Promise<Inventory[]> {
47
47
  const { domain } = context.state
48
- const foundOrderReverseKitting: ReverseKittingOrderInventory = await getRepository(
49
- ReverseKittingOrderInventory
50
- ).findOne({
48
+ const reverseKittingOI: ReverseKittingOrderInventory = await getRepository(ReverseKittingOrderInventory).findOne({
51
49
  where: {
52
50
  domain,
53
51
  name: orderReverseKittingName,
@@ -56,16 +54,16 @@ export class ReverseKittingOrderQuery {
56
54
  relations: ['bizplace', 'reverseKittingOrder', 'inventory']
57
55
  })
58
56
 
59
- if (!foundOrderReverseKitting) return
57
+ if (!reverseKittingOI) return
60
58
 
61
- const reverseKittingOrder: ReverseKittingOrder = foundOrderReverseKitting.reverseKittingOrder
62
- const customerBizplace: Bizplace = foundOrderReverseKitting.bizplace
59
+ const reverseKittingOrder: ReverseKittingOrder = reverseKittingOI.reverseKittingOrder
60
+ const customerBizplace: Bizplace = reverseKittingOI.bizplace
63
61
  return await getRepository(Inventory).find({
64
62
  where: {
65
63
  domain,
66
64
  bizplace: customerBizplace,
67
65
  refOrderId: reverseKittingOrder.id,
68
- orderVasId: foundOrderReverseKitting.id,
66
+ orderVasId: reverseKittingOI.id,
69
67
  status: INVENTORY_STATUS.STORED
70
68
  },
71
69
  relations: ['product', 'bizplace']
@@ -84,9 +82,9 @@ export class ReverseKittingOrderQuery {
84
82
  relations: [
85
83
  'domain',
86
84
  'bizplace',
87
- 'orderReverseKittings',
88
- 'orderReverseKittings.inventory',
89
- 'orderReverseKittings.inventory.product',
85
+ 'reverseKittingOrderInventories',
86
+ 'reverseKittingOrderInventories.inventory',
87
+ 'reverseKittingOrderInventories.inventory.product',
90
88
  'creator',
91
89
  'updater'
92
90
  ]
@@ -94,6 +92,76 @@ export class ReverseKittingOrderQuery {
94
92
  return { items, total }
95
93
  }
96
94
 
95
+ // @Query(returns => [InventoryDetail], { description: 'To generate reverse kitting order lot id' })
96
+ // async generateReverseKittingPalletId(
97
+ // @Arg('targets') targets: [PalletInfo],
98
+ // @Arg('type') type: string,
99
+ // @Ctx() context: any
100
+ // ): Promise<InventoryDetail[]> {
101
+ // const { tx, domain } = context.state
102
+ // // 1. get and set the date
103
+ // const today = new Date()
104
+ // const year = today.getFullYear()
105
+ // const month = today.getMonth()
106
+ // const day = today.getDate()
107
+
108
+ // const yy = String(year).substr(String(year).length - 2)
109
+ // const mm = String(month + 1).padStart(2, '0')
110
+ // const dd = String(day).padStart(2, '0')
111
+
112
+ // const date = yy + mm + dd
113
+ // let results = []
114
+
115
+ // // 2. get worksheet detail
116
+ // let ids = targets.map(target => target.id)
117
+
118
+ // // - getRepository using In(array) to pass the value to defined variable
119
+ // const reverseKittingOIs: ReverseKittingOrderInventory[] = await tx
120
+ // .getRepository(ReverseKittingOrderInventory)
121
+ // .find({
122
+ // where: {
123
+ // domain,
124
+ // id: In(ids)
125
+ // },
126
+ // relations: ['domain', 'bizplace']
127
+ // })
128
+
129
+ // // 3. from worksheet detail get product name, product type, batchid, packing type, bizplace
130
+
131
+ // if (reverseKittingOIs.length <= 0) throw new Error('Unable to find order reverse kittings')
132
+ // else {
133
+ // for (let i = 0; i < reverseKittingOIs.length; i++) {
134
+ // let reverseKittingOI = reverseKittingOIs[i]
135
+ // for (let idx = 0; idx < targets.length; idx++) {
136
+ // if (reverseKittingOI.id === targets[idx].id) {
137
+ // // 4. generate pallet id based on print qty > call generateId resolver
138
+ // for (let i = 0; i < targets[idx].printQty; i++) {
139
+ // const generatedPalletId = await generateId({
140
+ // domain,
141
+ // type,
142
+ // seed: {
143
+ // batchId: reverseKittingOI.inventory.batchId,
144
+ // date: date
145
+ // }
146
+ // })
147
+
148
+ // // 5. map all data to be returned
149
+ // if (reverseKittingOI != null) {
150
+ // results.push({
151
+ // ...reverseKittingOI,
152
+ // palletId: generatedPalletId,
153
+ // bizplace: reverseKittingOI.bizplace
154
+ // })
155
+ // }
156
+ // }
157
+ // }
158
+ // }
159
+ // }
160
+ // }
161
+
162
+ // return results
163
+ // }
164
+
97
165
  @FieldResolver(type => Domain)
98
166
  async domain(@Root() reverseKittingOrder: ReverseKittingOrder): Promise<Domain> {
99
167
  return await getRepository(Domain).findOne(reverseKittingOrder.domainId)
@@ -11,6 +11,7 @@ import {
11
11
  InventoryNoGenerator,
12
12
  Location,
13
13
  LOCATION_STATUS,
14
+ LOCATION_TYPE,
14
15
  Pallet
15
16
  } from '@things-factory/warehouse-base'
16
17
 
@@ -67,7 +68,8 @@ export const InventoryUtil = {
67
68
  oi.product_id,
68
69
  p.name AS product_name,
69
70
  oi.packing_type,
70
- oi.packing_size
71
+ oi.packing_size,
72
+ oi.uom
71
73
  FROM
72
74
  order_inventories oi
73
75
  LEFT JOIN
@@ -80,12 +82,14 @@ export const InventoryUtil = {
80
82
  AND oi.product_id NOTNULL
81
83
  AND oi.packing_type NOTNULL
82
84
  AND oi.packing_size NOTNULL
85
+ AND oi.inventory_id IS NULL
83
86
  GROUP BY
84
87
  oi.batch_id,
85
88
  oi.batch_id_ref,
86
89
  oi.product_id,
87
90
  oi.packing_type,
88
91
  oi.packing_size,
92
+ oi.uom,
89
93
  p.name
90
94
  )
91
95
  SELECT
@@ -96,6 +100,7 @@ export const InventoryUtil = {
96
100
  i.uom AS "uom",
97
101
  concat(p.name, ' (', p.description, ')') AS "productName",
98
102
  coalesce(p.sku, '') AS "productSKU",
103
+ coalesce(p.brand, '') AS "productBrand",
99
104
  p.id AS "productId",
100
105
  SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)) AS "remainQty",
101
106
  SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) AS "remainUomValue",
@@ -104,7 +109,8 @@ export const InventoryUtil = {
104
109
  FROM
105
110
  inventories i
106
111
  LEFT JOIN products p ON i.product_id = p.id
107
- LEFT JOIN oi ON i.batch_id = oi.batch_id AND p.name = oi.product_name AND i.packing_type = oi.packing_type AND i.packing_size = oi.packing_size
112
+ LEFT JOIN oi ON i.batch_id = oi.batch_id AND p.name = oi.product_name AND i.packing_type = oi.packing_type AND i.packing_size = oi.packing_size AND i.uom = oi.uom
113
+ LEFT JOIN locations l2 ON i.location_id = l2.id AND i.domain_id = l2.domain_id
108
114
  LEFT JOIN (
109
115
  SELECT pbs.product_id, SUM(pbs.bundle_qty * src.release_qty) AS bundle_product_release_qty, SUM(pbs.bundle_qty * src.release_uom_value) AS bundle_product_release_uom_value
110
116
  FROM product_bundle_settings pbs
@@ -112,6 +118,7 @@ export const InventoryUtil = {
112
118
  GROUP BY pbs.product_id
113
119
  ) bp on i.product_id = bp.product_id
114
120
  WHERE i.domain_id = $1
121
+ AND l2.type NOT IN ('${LOCATION_TYPE.QUARANTINE}', '${LOCATION_TYPE.RESERVE}')
115
122
  ${productWhereClause}
116
123
  GROUP BY
117
124
  i.batch_id,
@@ -121,7 +128,7 @@ export const InventoryUtil = {
121
128
  i.packing_size,
122
129
  i.uom
123
130
  UNION
124
- SELECT 'BUNDLE' AS "batchId", null as "batchIdRef", packing_type, packing_size,'UNIT' AS "uom", name AS "productName", sku AS "productSKU", id AS "productId",
131
+ SELECT 'BUNDLE' AS "batchId", null as "batchIdRef", packing_type, packing_size,'UNIT' AS "uom", name AS "productName", sku AS "productSKU", 'brand' AS "productBrand", id AS "productId",
125
132
  MIN(FLOOR(pbs."availableQty")) AS "remainQty",
126
133
  MIN(FLOOR(pbs."availableUomValue")) AS "remainUomValue",
127
134
  CONCAT(MIN(FLOOR(pbs."availableUomValue")),' UNIT') AS "remainUomValueWithUom",
@@ -189,14 +196,15 @@ export const InventoryUtil = {
189
196
  product_id: x.product.id,
190
197
  batch_id: x.batchId,
191
198
  packing_type: x.packingType,
192
- release_qty: x.releaseQty
199
+ release_qty: x.releaseQty,
200
+ uom: x.uom
193
201
  }
194
202
  })
195
203
  )
196
204
 
197
205
  let resultQb = await trxMgr.query(
198
206
  `
199
- select joi.product_id as "productId", joi.batch_id as "batchId", joi.packing_type as "packingType", joi.release_qty as "releaseQty",
207
+ select joi.product_id as "productId", joi.batch_id as "batchId", joi.packing_type as "packingType", joi.uom as "uom", joi.release_qty as "releaseQty",
200
208
  sum(i.qty - coalesce(i.locked_qty,0)) - coalesce(
201
209
  (
202
210
  select sum(oi.release_qty) from order_inventories oi
@@ -205,6 +213,7 @@ export const InventoryUtil = {
205
213
  and oi.product_id = joi.product_id
206
214
  and oi.batch_id = joi.batch_id
207
215
  and oi.packing_type = joi.packing_type
216
+ and oi.uom = joi.uom
208
217
  and oi.domain_id = $1
209
218
  and oi.bizplace_id = $2
210
219
  ),0) as "availableQty",
@@ -216,16 +225,18 @@ export const InventoryUtil = {
216
225
  and oi.product_id = joi.product_id
217
226
  and oi.batch_id = joi.batch_id
218
227
  and oi.packing_type = joi.packing_type
228
+ and oi.uom = joi.uom
219
229
  and oi.domain_id = $1
220
230
  and oi.bizplace_id = $2
221
- ),0) as "availableUomValue", i.uom
231
+ ),0) as "availableUomValue"
222
232
  from json_populate_recordset(NULL::order_inventories,'${json_oi}') joi
223
233
  left join inventories i on joi.product_id = i.product_id
224
234
  and joi.batch_id = i.batch_id
225
235
  and joi.packing_type = i.packing_type and i.status ='STORED'
236
+ and joi.uom = i.uom
226
237
  and i.domain_id = $1
227
238
  and i.bizplace_id = $2
228
- group by joi.product_id, joi.batch_id, joi.packing_type, joi.release_qty, i.uom
239
+ group by joi.product_id, joi.batch_id, joi.packing_type, joi.release_qty, joi.uom
229
240
  `,
230
241
  [warehouseDomain.id, partnerBizplace.id]
231
242
  )
@@ -325,6 +336,14 @@ async function getConditions(
325
336
  whereClause += `AND LOWER("batchId") LIKE '${value.toLowerCase()}'`
326
337
  break
327
338
 
339
+ case 'batchIdRef':
340
+ whereClause += `AND LOWER("batchIdRef") LIKE '${value.toLowerCase()}'`
341
+ break
342
+
343
+ case 'productBrand':
344
+ whereClause += `AND LOWER("productBrand") LIKE '${value.toLowerCase()}'`
345
+ break
346
+
328
347
  case 'productName':
329
348
  const products: Product[] = await trxMgr.getRepository(Product).find({
330
349
  select: ['id'],
@@ -406,6 +425,10 @@ async function getConditions(
406
425
  whereClause += `AND LOWER("groupType") LIKE 'bundle'`
407
426
  break
408
427
 
428
+ case 'hideBundle':
429
+ whereClause += `AND LOWER("groupType") LIKE 'single'`
430
+ break
431
+
409
432
  case 'batch_product':
410
433
  productWhereClause += `
411
434
  AND (i.batch_id, p.id, i.packing_type) ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
@@ -8,51 +8,63 @@ export class OrderNoGenerator {
8
8
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
9
9
  }
10
10
 
11
- static purchaseOrder() {
11
+ static collectionOrder() {
12
12
  const currentDate = new Date()
13
- return `PO-${currentDate.getFullYear()}${
13
+ return `CO-${currentDate.getFullYear()}${
14
14
  currentDate.getMonth() + 1
15
15
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
16
16
  }
17
17
 
18
- static jobSheet(domainName) {
18
+ static cycleCount() {
19
19
  const currentDate = new Date()
20
- return `${domainName}-${currentDate.getFullYear()}${
20
+ return `CC-${currentDate.getFullYear()}${
21
21
  currentDate.getMonth() + 1
22
22
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
23
23
  }
24
24
 
25
- static goodsReceiveNote() {
25
+ static deliveryOrder() {
26
26
  const currentDate = new Date()
27
- return `GRN-${currentDate.getFullYear()}${
27
+ return `DO-${currentDate.getFullYear()}${
28
28
  currentDate.getMonth() + 1
29
29
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
30
30
  }
31
31
 
32
- static cycleCount() {
32
+ static goodsReceiveNote() {
33
33
  const currentDate = new Date()
34
- return `CC-${currentDate.getFullYear()}${
34
+ return `GRN-${currentDate.getFullYear()}${
35
35
  currentDate.getMonth() + 1
36
36
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
37
37
  }
38
38
 
39
- static stockTake() {
39
+ static jobSheet(domainName) {
40
40
  const currentDate = new Date()
41
- return `ST-${currentDate.getFullYear()}${
41
+ return `${domainName}-${currentDate.getFullYear()}${
42
42
  currentDate.getMonth() + 1
43
43
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
44
44
  }
45
45
 
46
- static shippingOrder() {
46
+ static manifest() {
47
47
  const currentDate = new Date()
48
- return `SO-${currentDate.getFullYear()}${
48
+ return `LM-${currentDate.getFullYear()}${
49
49
  currentDate.getMonth() + 1
50
50
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
51
51
  }
52
52
 
53
- static returnOrder() {
53
+ static orderInventory() {
54
+ return uuid()
55
+ }
56
+
57
+ static orderProduct() {
58
+ return `OP-${uuid()}`
59
+ }
60
+
61
+ static orderVas() {
62
+ return `OV-${uuid()}`
63
+ }
64
+
65
+ static purchaseOrder() {
54
66
  const currentDate = new Date()
55
- return `RTO-${currentDate.getFullYear()}${
67
+ return `PO-${currentDate.getFullYear()}${
56
68
  currentDate.getMonth() + 1
57
69
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
58
70
  }
@@ -64,46 +76,34 @@ export class OrderNoGenerator {
64
76
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
65
77
  }
66
78
 
67
- static orderProduct() {
68
- return `OP-${uuid()}`
79
+ static releaseVas() {
80
+ return uuid()
69
81
  }
70
82
 
71
- static collectionOrder() {
83
+ static retailReplenishmentOrder() {
72
84
  const currentDate = new Date()
73
- return `CO-${currentDate.getFullYear()}${
85
+ return `RR-${currentDate.getFullYear()}${
74
86
  currentDate.getMonth() + 1
75
87
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
76
88
  }
77
89
 
78
- static deliveryOrder() {
90
+ static returnOrder() {
79
91
  const currentDate = new Date()
80
- return `DO-${currentDate.getFullYear()}${
92
+ return `RTO-${currentDate.getFullYear()}${
81
93
  currentDate.getMonth() + 1
82
94
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
83
95
  }
84
96
 
85
- static orderInventory() {
86
- return uuid()
87
- }
88
-
89
- static releaseVas() {
90
- return uuid()
91
- }
92
-
93
- static vasOrder() {
97
+ static shippingOrder() {
94
98
  const currentDate = new Date()
95
- return `VO-${currentDate.getFullYear()}${
99
+ return `SO-${currentDate.getFullYear()}${
96
100
  currentDate.getMonth() + 1
97
101
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
98
102
  }
99
103
 
100
- static orderVas() {
101
- return `OV-${uuid()}`
102
- }
103
-
104
- static retailReplenishmentOrder() {
104
+ static stockTake() {
105
105
  const currentDate = new Date()
106
- return `RR-${currentDate.getFullYear()}${
106
+ return `ST-${currentDate.getFullYear()}${
107
107
  currentDate.getMonth() + 1
108
108
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
109
109
  }
@@ -114,4 +114,11 @@ export class OrderNoGenerator {
114
114
  currentDate.getMonth() + 1
115
115
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
116
116
  }
117
+
118
+ static vasOrder() {
119
+ const currentDate = new Date()
120
+ return `VO-${currentDate.getFullYear()}${
121
+ currentDate.getMonth() + 1
122
+ }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
123
+ }
117
124
  }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":""}
File without changes