@things-factory/sales-base 4.0.36 → 4.0.40

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 (106) hide show
  1. package/dist-server/controllers/ecommerce/sellercraft-controller.js +4 -3
  2. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
  3. package/dist-server/service/arrival-notice/arrival-notice-mutation.js +42 -35
  4. package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
  5. package/dist-server/service/arrival-notice/arrival-notice-query.js +91 -79
  6. package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
  7. package/dist-server/service/arrival-notice/arrival-notice-types.js +8 -0
  8. package/dist-server/service/arrival-notice/arrival-notice-types.js.map +1 -1
  9. package/dist-server/service/arrival-notice/arrival-notice.js +20 -15
  10. package/dist-server/service/arrival-notice/arrival-notice.js.map +1 -1
  11. package/dist-server/service/delivery-order/delivery-order-mutation.js +28 -26
  12. package/dist-server/service/delivery-order/delivery-order-mutation.js.map +1 -1
  13. package/dist-server/service/delivery-order/delivery-order-query.js +14 -14
  14. package/dist-server/service/delivery-order/delivery-order-query.js.map +1 -1
  15. package/dist-server/service/delivery-order/delivery-order-summary-report.js +145 -0
  16. package/dist-server/service/delivery-order/delivery-order-summary-report.js.map +1 -0
  17. package/dist-server/service/delivery-order/delivery-order.js +16 -13
  18. package/dist-server/service/delivery-order/delivery-order.js.map +1 -1
  19. package/dist-server/service/delivery-order/index.js +3 -1
  20. package/dist-server/service/delivery-order/index.js.map +1 -1
  21. package/dist-server/service/index.js +12 -4
  22. package/dist-server/service/index.js.map +1 -1
  23. package/dist-server/service/invoice/invoice-mutation.js +21 -3
  24. package/dist-server/service/invoice/invoice-mutation.js.map +1 -1
  25. package/dist-server/service/invoice/invoice-query.js +5 -7
  26. package/dist-server/service/invoice/invoice-query.js.map +1 -1
  27. package/dist-server/service/invoice/invoice-types.js +302 -20
  28. package/dist-server/service/invoice/invoice-types.js.map +1 -1
  29. package/dist-server/service/invoice/invoice.js +190 -26
  30. package/dist-server/service/invoice/invoice.js.map +1 -1
  31. package/dist-server/service/invoice-product/index.js +21 -0
  32. package/dist-server/service/invoice-product/index.js.map +1 -0
  33. package/dist-server/service/invoice-product/invoice-product-mutation.js +70 -0
  34. package/dist-server/service/invoice-product/invoice-product-mutation.js.map +1 -0
  35. package/dist-server/service/invoice-product/invoice-product-query.js +95 -0
  36. package/dist-server/service/invoice-product/invoice-product-query.js.map +1 -0
  37. package/dist-server/service/invoice-product/invoice-product-types.js +125 -0
  38. package/dist-server/service/invoice-product/invoice-product-types.js.map +1 -0
  39. package/dist-server/service/invoice-product/invoice-product.js +117 -0
  40. package/dist-server/service/invoice-product/invoice-product.js.map +1 -0
  41. package/dist-server/service/order-inventory/order-inventory-query.js +9 -7
  42. package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
  43. package/dist-server/service/order-inventory/order-inventory-types.js +11 -11
  44. package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
  45. package/dist-server/service/order-inventory/order-inventory.js +31 -25
  46. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  47. package/dist-server/service/order-product/order-product.js +26 -21
  48. package/dist-server/service/order-product/order-product.js.map +1 -1
  49. package/dist-server/service/order-vas/order-vas.js +34 -27
  50. package/dist-server/service/order-vas/order-vas.js.map +1 -1
  51. package/dist-server/service/others/other-query.js +4 -2
  52. package/dist-server/service/others/other-query.js.map +1 -1
  53. package/dist-server/service/others/other-types.js +42 -0
  54. package/dist-server/service/others/other-types.js.map +1 -1
  55. package/dist-server/service/purchase-order/purchase-order-mutation.js +23 -36
  56. package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
  57. package/dist-server/service/release-good/release-good-mutation.js +84 -82
  58. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  59. package/dist-server/service/release-good/release-good-query.js +8 -9
  60. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  61. package/dist-server/service/release-good/release-good.js +2 -0
  62. package/dist-server/service/release-good/release-good.js.map +1 -1
  63. package/dist-server/service/return-order/return-order-mutation.js +21 -6
  64. package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
  65. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.js +9 -5
  66. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.js.map +1 -1
  67. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +3 -2
  68. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -1
  69. package/dist-server/utils/order-no-generator.js +7 -0
  70. package/dist-server/utils/order-no-generator.js.map +1 -1
  71. package/package.json +12 -12
  72. package/server/controllers/ecommerce/sellercraft-controller.ts +2 -1
  73. package/server/service/arrival-notice/arrival-notice-mutation.ts +11 -15
  74. package/server/service/arrival-notice/arrival-notice-query.ts +94 -78
  75. package/server/service/arrival-notice/arrival-notice-types.ts +6 -0
  76. package/server/service/arrival-notice/arrival-notice.ts +6 -1
  77. package/server/service/delivery-order/delivery-order-mutation.ts +4 -8
  78. package/server/service/delivery-order/delivery-order-query.ts +4 -4
  79. package/server/service/delivery-order/delivery-order-summary-report.ts +152 -0
  80. package/server/service/delivery-order/delivery-order.ts +4 -1
  81. package/server/service/delivery-order/index.ts +3 -1
  82. package/server/service/index.ts +20 -12
  83. package/server/service/invoice/invoice-mutation.ts +45 -7
  84. package/server/service/invoice/invoice-query.ts +6 -6
  85. package/server/service/invoice/invoice-types.ts +231 -18
  86. package/server/service/invoice/invoice.ts +154 -20
  87. package/server/service/invoice-product/index.ts +9 -0
  88. package/server/service/invoice-product/invoice-product-mutation.ts +54 -0
  89. package/server/service/invoice-product/invoice-product-query.ts +55 -0
  90. package/server/service/invoice-product/invoice-product-types.ts +80 -0
  91. package/server/service/invoice-product/invoice-product.ts +93 -0
  92. package/server/service/order-inventory/order-inventory-query.ts +3 -1
  93. package/server/service/order-inventory/order-inventory-types.ts +11 -11
  94. package/server/service/order-inventory/order-inventory.ts +11 -13
  95. package/server/service/order-product/order-product.ts +13 -13
  96. package/server/service/order-vas/order-vas.ts +15 -15
  97. package/server/service/others/other-query.ts +9 -15
  98. package/server/service/others/other-types.ts +31 -0
  99. package/server/service/purchase-order/purchase-order-mutation.ts +19 -21
  100. package/server/service/release-good/release-good-mutation.ts +64 -58
  101. package/server/service/release-good/release-good-query.ts +6 -12
  102. package/server/service/release-good/release-good.ts +2 -0
  103. package/server/service/return-order/return-order-mutation.ts +30 -6
  104. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.ts +8 -5
  105. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +3 -2
  106. package/server/utils/order-no-generator.ts +11 -0
@@ -1,4 +1,8 @@
1
- import { Attachment, createAttachments, deleteAttachment } from '@things-factory/attachment-base'
1
+ import { FileUpload, GraphQLUpload } from 'graphql-upload'
2
+ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
3
+ import { EntityManager, getRepository, Repository } from 'typeorm'
4
+
5
+ import { Attachment, createAttachments, deleteAttachmentsByRef } from '@things-factory/attachment-base'
2
6
  import { User } from '@things-factory/auth-base'
3
7
  import { Bizplace, ContactPoint, getPermittedBizplaces } from '@things-factory/biz-base'
4
8
  import { generateId } from '@things-factory/id-rule-base'
@@ -6,9 +10,7 @@ import { Product } from '@things-factory/product-base'
6
10
  import { Setting } from '@things-factory/setting-base'
7
11
  import { Domain } from '@things-factory/shell'
8
12
  import { Location } from '@things-factory/warehouse-base'
9
- import { FileUpload, GraphQLUpload } from 'graphql-upload'
10
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
11
- import { EntityManager, getRepository, Repository } from 'typeorm'
13
+
12
14
  import {
13
15
  ArrivalNotice,
14
16
  NewPurchaseOrder,
@@ -40,14 +42,14 @@ export class PurchaseOrderMutation {
40
42
  async upsertPurchaseOrder(
41
43
  @Ctx() context: any,
42
44
  @Arg('purchaseOrder', type => PurchaseOrderPatch) purchaseOrder: PurchaseOrderPatch,
43
- @Arg('file', type => [GraphQLUpload], { nullable: true }) file?: FileUpload
45
+ @Arg('files', type => [GraphQLUpload], { nullable: true }) files?: FileUpload
44
46
  ): Promise<PurchaseOrder> {
45
47
  try {
46
48
  const { tx }: { tx: EntityManager } = context.state
47
49
  const createdPurchaseOrder: PurchaseOrder = await upsertPurchaseOrderFunction(
48
50
  null,
49
51
  purchaseOrder,
50
- file,
52
+ files,
51
53
  context,
52
54
  tx
53
55
  )
@@ -197,17 +199,14 @@ export class PurchaseOrderMutation {
197
199
  export async function upsertPurchaseOrderFunction(
198
200
  _: any,
199
201
  purchaseOrder: any,
200
- file: Attachment,
202
+ files: FileUpload[],
201
203
  context: any,
202
204
  tx?: EntityManager
203
205
  ): Promise<PurchaseOrder> {
204
- const { domain, user }: { domain: Domain; user: User } = context.state
205
- let orderProducts: OrderProduct[] = purchaseOrder.orderProducts
206
-
207
206
  if (!purchaseOrder.id) {
208
- purchaseOrder = await createPurchaseOrderFunction(_, purchaseOrder, file, context, tx)
207
+ purchaseOrder = await createPurchaseOrderFunction(_, purchaseOrder, files, context, tx)
209
208
  } else {
210
- purchaseOrder = await updatePurchaseOrderFunction(_, purchaseOrder, file, context, tx)
209
+ purchaseOrder = await updatePurchaseOrderFunction(_, purchaseOrder, files, context, tx)
211
210
  }
212
211
 
213
212
  return purchaseOrder
@@ -216,7 +215,7 @@ export async function upsertPurchaseOrderFunction(
216
215
  export async function createPurchaseOrderFunction(
217
216
  _: any,
218
217
  purchaseOrder: any,
219
- file: Attachment,
218
+ files: FileUpload[],
220
219
  context: any,
221
220
  tx?: EntityManager
222
221
  ): Promise<PurchaseOrder> {
@@ -297,8 +296,8 @@ export async function createPurchaseOrderFunction(
297
296
  }
298
297
 
299
298
  // // 4. Create Attacments
300
- if (file?.length) {
301
- const attachments: Attachment[] = file.map(attachment => {
299
+ if (files?.length) {
300
+ const attachments: Attachment[] = files.map(attachment => {
302
301
  return {
303
302
  file: attachment,
304
303
  refBy: createdPurchaseOrder.id,
@@ -314,7 +313,7 @@ export async function createPurchaseOrderFunction(
314
313
  export async function updatePurchaseOrderFunction(
315
314
  _: any,
316
315
  purchaseOrder: any,
317
- file: Attachment,
316
+ files: FileUpload[],
318
317
  context: any,
319
318
  tx?: EntityManager
320
319
  ): Promise<PurchaseOrder> {
@@ -386,14 +385,13 @@ export async function updatePurchaseOrderFunction(
386
385
  })
387
386
 
388
387
  // // 6. Remove All Attachment
389
- for await (const file of foundAttachments.filter(attachment => !file.find(file => file.id == attachment.id))) {
390
- await deleteAttachment(_, { id: file.id }, context)
388
+ if (foundAttachments?.length) {
389
+ await deleteAttachmentsByRef(_, { refBys: foundAttachments.map(file => file.refBy) }, context)
391
390
  }
392
391
 
393
392
  // // 7. Add New Attachment
394
- const newAttachments = file.filter(attachment => !attachment.id)
395
- if (newAttachments.length > 0) {
396
- const attachments: Attachment[] = newAttachments.map(attachment => {
393
+ if (files?.length > 0) {
394
+ const attachments: Attachment[] = files.map(attachment => {
397
395
  return {
398
396
  file: attachment,
399
397
  refBy: updatePurchaseOrder.id,
@@ -21,17 +21,6 @@ import { PartnerSetting, Setting } from '@things-factory/setting-base'
21
21
  import { Domain } from '@things-factory/shell'
22
22
  import { Inventory } from '@things-factory/warehouse-base'
23
23
 
24
- import {
25
- ArrivalNotice,
26
- NewReleaseGood,
27
- OrderInventory,
28
- OrderProduct,
29
- OrderVas,
30
- ReleaseGoodPatch,
31
- ShippingOrder,
32
- ShippingOrderPatch,
33
- Vas
34
- } from '../'
35
24
  import {
36
25
  ATTACHMENT_TYPE,
37
26
  ORDER_INVENTORY_STATUS,
@@ -46,7 +35,15 @@ import {
46
35
  import { EcommerceController, SellercraftController } from '../../controllers'
47
36
  import { ValidationError } from '../../errors'
48
37
  import { InventoryUtil, OrderNoGenerator } from '../../utils'
38
+ import { ArrivalNotice } from '../arrival-notice/arrival-notice'
49
39
  import { confirmArrivalNoticeFunction, deleteArrivalNotice } from '../arrival-notice/arrival-notice-mutation'
40
+ import { OrderInventory } from '../order-inventory/order-inventory'
41
+ import { OrderProduct } from '../order-product/order-product'
42
+ import { OrderVas } from '../order-vas/order-vas'
43
+ import { NewReleaseGood, ReleaseGoodPatch } from '../release-good/release-good-types'
44
+ import { ShippingOrder } from '../shipping-order/shipping-order'
45
+ import { ShippingOrderPatch } from '../shipping-order/shipping-order-types'
46
+ import { Vas } from '../vas/vas'
50
47
  import { ReleaseGood } from './release-good'
51
48
  import { bulkReleaseGoodsAvailableItemsFunction } from './release-good-query'
52
49
 
@@ -76,7 +73,7 @@ export class ReleaseGoodMutation {
76
73
 
77
74
  let releaseGoods: Partial<ReleaseGood[]> = extractRawReleaseGoods(rawReleaseGoods)
78
75
 
79
- let errorsFound: any[] = []
76
+ let errorsCaught: any[] = []
80
77
  for (let i = 0, l = releaseGoods.length; i < l; i++) {
81
78
  // generate release good by group to avoid duplication
82
79
  // if this function is called simultaneously by different users
@@ -90,7 +87,7 @@ export class ReleaseGoodMutation {
90
87
  domain
91
88
  }
92
89
  })
93
- if (existingReleaseGood) throw new Error('release good order is already exist in the system')
90
+ if (existingReleaseGood) throw new Error('this order is already exist in the system')
94
91
 
95
92
  let availableItems: any[] = await bulkReleaseGoodsAvailableItemsFunction(
96
93
  [...releaseGoods[i].orderInventories],
@@ -119,25 +116,30 @@ export class ReleaseGoodMutation {
119
116
 
120
117
  createdReleaseGoods.push(createdReleaseGood)
121
118
  })
122
- } catch (e) {
123
- errorsFound.push(e)
119
+ } catch (error) {
120
+ let rawReleaseGoods = formRawReleaseGoods(releaseGoods[i], error.message)
121
+ errorsCaught.push(...rawReleaseGoods)
124
122
  }
125
123
  }
126
124
 
127
125
  let confirmedReleaseGoods: ReleaseGood[] = []
128
- try {
129
- confirmedReleaseGoods = await bulkConfirmReleaseGoods(
130
- createdReleaseGoods.map(rg => rg.name),
131
- domain,
132
- user,
133
- context,
134
- tx
135
- )
136
- } catch (e) {
137
- errorsFound.push(e)
138
- }
139
126
 
140
- // if (errorsFound.length) { then ?? }
127
+ if (createdReleaseGoods.length)
128
+ try {
129
+ confirmedReleaseGoods = await bulkConfirmReleaseGoods(
130
+ createdReleaseGoods.map(rg => rg.name),
131
+ domain,
132
+ user,
133
+ context,
134
+ tx
135
+ )
136
+ } catch (error) {}
137
+
138
+ if (errorsCaught.length)
139
+ throw new ValidationError({
140
+ ...ValidationError.ERROR_CODES.INVALID_DATA_FOUND,
141
+ detail: { data: JSON.stringify(errorsCaught) }
142
+ })
141
143
 
142
144
  return confirmedReleaseGoods
143
145
  }
@@ -815,11 +817,9 @@ export async function confirmReleaseGood(name: string, context: any, tx?: Entity
815
817
  if (foundMarketplaceProductVariations) {
816
818
  await Promise.all(
817
819
  foundMarketplaceProductVariations.map(async variation => {
818
- if (variation.marketplaceProduct.marketplaceStore.id != matchedMarketplaceStore.id) {
819
- variation.reserveQty -= oi.releaseQty
820
+ variation.reserveQty -= oi.releaseQty
820
821
 
821
- await tx.getRepository(MarketplaceProductVariation).save(variation)
822
- }
822
+ await tx.getRepository(MarketplaceProductVariation).save(variation)
823
823
  })
824
824
  )
825
825
  }
@@ -1252,29 +1252,15 @@ export async function bulkConfirmReleaseGoods(
1252
1252
  ): Promise<ReleaseGood[]> {
1253
1253
  let foundReleaseGoods: ReleaseGood[] = await tx.getRepository(ReleaseGood).find({
1254
1254
  where: { name: In(releaseGoodsNo), status: ORDER_STATUS.PENDING },
1255
- relations: [
1256
- 'domain',
1257
- 'bizplace',
1258
- 'bizplace.domain',
1259
- 'bizplace.company',
1260
- 'bizplace.company.domain',
1261
- 'orderProducts',
1262
- 'orderProducts.product',
1263
- 'orderInventories',
1264
- 'orderInventories.product',
1265
- 'orderVass'
1266
- ]
1255
+ relations: ['bizplace']
1267
1256
  })
1268
1257
 
1269
1258
  if (!foundReleaseGoods.length) throw new Error(`release good order doesn't exists.`)
1270
1259
  let customerBizplace: Bizplace = foundReleaseGoods[0].bizplace
1271
1260
 
1272
- let foundOrderInventories: OrderInventory[] = foundReleaseGoods
1273
- .map((releaseGood: ReleaseGood) => releaseGood.orderInventories)
1274
- .reduce((orderInventories, currOIs) => {
1275
- orderInventories.push(...currOIs)
1276
- return orderInventories
1277
- }, [])
1261
+ let foundOrderInventories: OrderInventory[] = await tx.getRepository(OrderInventory).find({
1262
+ where: { domain, releaseGood: In(foundReleaseGoods.map((rg: ReleaseGood) => rg.id)) }
1263
+ })
1278
1264
 
1279
1265
  await tx
1280
1266
  .getRepository(ReleaseGood)
@@ -1307,7 +1293,7 @@ export async function bulkConfirmReleaseGoods(
1307
1293
  // send notification to Office Admin Users
1308
1294
  if (users?.length) {
1309
1295
  const receivers: any[] = users.map(user => user.id)
1310
- const msg = {
1296
+ const message = {
1311
1297
  title: `New Release Order from ${customerBizplace.name}`,
1312
1298
  body: `New incoming bulk release orders are pending for receiving`,
1313
1299
  url: context.header.referer,
@@ -1315,18 +1301,21 @@ export async function bulkConfirmReleaseGoods(
1315
1301
  }
1316
1302
  await sendNotification({
1317
1303
  receivers,
1318
- message: { ...msg }
1304
+ message
1319
1305
  })
1320
1306
  }
1321
1307
  }
1322
1308
 
1323
- return foundReleaseGoods.map((releaseGood: ReleaseGood) => {
1324
- return {
1325
- ...releaseGood,
1326
- status: ORDER_STATUS.PENDING_RECEIVE,
1327
- updater: user
1328
- }
1329
- })
1309
+ return Promise.all(
1310
+ foundReleaseGoods.map(async (releaseGood: ReleaseGood) => {
1311
+ return {
1312
+ ...releaseGood,
1313
+ orderInventories: await tx.getRepository(OrderInventory).find({ where: releaseGood }),
1314
+ status: ORDER_STATUS.PENDING_RECEIVE,
1315
+ updater: user
1316
+ }
1317
+ })
1318
+ )
1330
1319
  }
1331
1320
 
1332
1321
  function extractRawReleaseGoods(rawReleaseGoods): Partial<ReleaseGood[]> {
@@ -1413,3 +1402,20 @@ function extractRawReleaseGoods(rawReleaseGoods): Partial<ReleaseGood[]> {
1413
1402
  return releaseGoods
1414
1403
  }, [])
1415
1404
  }
1405
+
1406
+ function formRawReleaseGoods(releaseGood, errorMsg) {
1407
+ let rawReleaseGoods = []
1408
+ for (let i = 0, l = releaseGood.orderInventories.length; i < l; i++) {
1409
+ let rawReleaseGood = {
1410
+ ...releaseGood,
1411
+ ...releaseGood.orderInventories[i],
1412
+ errorMsg
1413
+ }
1414
+
1415
+ delete rawReleaseGood.orderInventories
1416
+ delete rawReleaseGood.product
1417
+
1418
+ rawReleaseGoods.push(rawReleaseGood)
1419
+ }
1420
+ return rawReleaseGoods
1421
+ }
@@ -9,16 +9,11 @@ import { Product } from '@things-factory/product-base'
9
9
  import { buildQuery, Domain, Filter, ListParam, Pagination, Sorting } from '@things-factory/shell'
10
10
  import { Inventory, LOCATION_TYPE } from '@things-factory/warehouse-base'
11
11
 
12
- import {
13
- InventoryInfos,
14
- NewReleaseGood,
15
- OrderInventory,
16
- ReleasableInventoryList,
17
- ReleaseGoodList,
18
- ShippingOrder
19
- } from '../'
20
12
  import { ATTACHMENT_TYPE, ORDER_INVENTORY_STATUS, ORDER_STATUS } from '../../constants'
13
+ import { OrderInventory } from '../order-inventory/order-inventory'
14
+ import { ShippingOrder } from '../shipping-order/shipping-order'
21
15
  import { ReleaseGood } from './release-good'
16
+ import { InventoryInfos, NewReleaseGood, ReleasableInventoryList, ReleaseGoodList } from './release-good-types'
22
17
 
23
18
  @Resolver(ReleaseGood)
24
19
  export class ReleaseGoodQuery {
@@ -648,7 +643,7 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
648
643
  let availableItems = await tx.query(
649
644
  `
650
645
  WITH inv AS (
651
- SELECT i.product_id, foo.product_detail_id, foo.sku, foo.product_info, i.batch_id, i.packing_type, i.packing_size, i.uom,
646
+ SELECT i.product_id, foo.product_detail_id, foo.sku, foo.product_info, i.packing_type, i.packing_size, i.uom,
652
647
  SUM(i.qty - COALESCE(i.locked_qty, 0)) - COALESCE(
653
648
  (
654
649
  SELECT SUM(oi.release_qty) FROM order_inventories oi
@@ -686,7 +681,7 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
686
681
  AND i.domain_id = $1
687
682
  AND i.bizplace_id = $2
688
683
  WHERE l.type NOT IN ($3, $4)
689
- GROUP BY i.product_id, foo.product_detail_id, foo.sku,foo.product_info, i.batch_id, i.packing_type, i.packing_size, i.uom
684
+ GROUP BY i.product_id, foo.product_detail_id, foo.sku,foo.product_info, i.packing_type, i.packing_size, i.uom
690
685
  ORDER BY foo.sku, remain_qty
691
686
  ) SELECT * FROM inv WHERE remain_qty > 0
692
687
  `,
@@ -701,7 +696,6 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
701
696
  productDetailId: item.product_detail_id,
702
697
  productInfo: item.product_info,
703
698
  sku: item.sku,
704
- batchId: item.batch_id,
705
699
  packingType: item.packing_type,
706
700
  packingSize: Number(item.packing_size || 0),
707
701
  uom: item.uom,
@@ -762,10 +756,10 @@ function _extractData(rawData, validatedData) {
762
756
 
763
757
  raw.productId = validatedData[idx].productId
764
758
  raw.productDetailId = validatedData[idx].productDetailId
759
+ raw.productInfo = validatedData[idx].productInfo
765
760
  raw.packingType = validatedData[idx].packingType
766
761
  raw.packingSize = validatedData[idx].packingSize
767
762
  raw.uom = validatedData[idx].uom
768
- raw.batchId = validatedData[idx].batchId
769
763
  } else {
770
764
  raw.assignedQty = 0
771
765
  raw.assignedUomValue = 0
@@ -45,6 +45,8 @@ export enum DispatchmentStatus {
45
45
  }
46
46
  @Entity()
47
47
  @Index('ix_release-good_0', (releaseGood: ReleaseGood) => [releaseGood.domain, releaseGood.name], { unique: true })
48
+ @Index('ix_release-good_1', (releaseGood: ReleaseGood) => [releaseGood.domain, releaseGood.refNo])
49
+ @Index('ix_release-good_2', (releaseGood: ReleaseGood) => [releaseGood.domain, releaseGood.refNo2])
48
50
  @ObjectType()
49
51
  export class ReleaseGood {
50
52
  @PrimaryGeneratedColumn('uuid')
@@ -1,3 +1,7 @@
1
+ import { FileUpload, GraphQLUpload } from 'graphql-upload'
2
+ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
3
+ import { EntityManager, In } from 'typeorm'
4
+
1
5
  import { Attachment, createAttachments } from '@things-factory/attachment-base'
2
6
  import { Role, User } from '@things-factory/auth-base'
3
7
  import { Bizplace, getDomainUsers } from '@things-factory/biz-base'
@@ -5,9 +9,7 @@ import { sendNotification } from '@things-factory/notification'
5
9
  import { Product } from '@things-factory/product-base'
6
10
  import { Domain } from '@things-factory/shell'
7
11
  import { Inventory } from '@things-factory/warehouse-base'
8
- import { FileUpload, GraphQLUpload } from 'graphql-upload'
9
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
10
- import { EntityManager, In } from 'typeorm'
12
+
11
13
  import { NewOrderInventory, NewReturnOrder, OrderInventory, OrderVas, ReturnOrderPatch } from '../'
12
14
  import { ATTACHMENT_TYPE, ORDER_INVENTORY_STATUS, ORDER_STATUS, ORDER_VAS_STATUS } from '../../constants'
13
15
  import { OrderNoGenerator } from '../../utils'
@@ -48,9 +50,31 @@ export class ReturnOrderMutation {
48
50
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
49
51
 
50
52
  const bizplace: Bizplace = await tx.getRepository(Bizplace).findOne(returnOrder.customerBizplaceId)
53
+
51
54
  let orderInventories: NewOrderInventory[] = returnOrder.orderInventories
52
55
  let foundInv = Inventory
53
56
 
57
+ const mergedOrderInventories = orderInventories.reduce((acc, curr) => {
58
+ let existingItem = acc.find(
59
+ itm =>
60
+ itm.product.id === curr.product.id &&
61
+ itm.packingType === curr.packingType &&
62
+ itm.batchId === curr.batchId &&
63
+ itm.packingSize === curr.packingSize
64
+ )
65
+
66
+ if (!existingItem) {
67
+ acc.push(curr)
68
+ } else {
69
+ existingItem.returnQty = existingItem.returnQty + curr.returnQty
70
+ existingItem.returnUomValue = existingItem.returnUomValue + curr.returnUomValue
71
+ }
72
+
73
+ return acc
74
+ }, [])
75
+
76
+ returnOrder.orderInventories = mergedOrderInventories
77
+
54
78
  let newReturnOrder: NewReturnOrder = {
55
79
  ...returnOrder,
56
80
  name: OrderNoGenerator.returnOrder(),
@@ -67,14 +91,14 @@ export class ReturnOrderMutation {
67
91
 
68
92
  let createdReturnOrder: ReturnOrder = await tx.getRepository(ReturnOrder).save(newReturnOrder)
69
93
 
70
- for (let oi of orderInventories) {
71
- let newOrderInv: OrderInventory = Object.assign({}, oi) as any
94
+ for (let moi of mergedOrderInventories) {
95
+ let newOrderInv: OrderInventory = Object.assign({}, moi) as any
72
96
  newOrderInv.domain = domain
73
97
  newOrderInv.bizplace = bizplace
74
98
  newOrderInv.status = ORDER_INVENTORY_STATUS.PENDING
75
99
  newOrderInv.name = OrderNoGenerator.orderInventory()
76
100
  newOrderInv.returnOrder = createdReturnOrder
77
- newOrderInv.product = await tx.getRepository(Product).findOne(oi.product.id)
101
+ newOrderInv.product = await tx.getRepository(Product).findOne(moi.product.id)
78
102
  newOrderInv.creator = user
79
103
  newOrderInv.updater = user
80
104
 
@@ -48,10 +48,10 @@ export class ReverseKittingOrderInventoryPatch {
48
48
  @Field(type => ID, { nullable: true })
49
49
  id?: string
50
50
 
51
- @Field()
51
+ @Field({ nullable: true })
52
52
  name: string
53
53
 
54
- @Field(type => Int)
54
+ @Field(type => Int, { nullable: true })
55
55
  set: number
56
56
 
57
57
  @Field({ nullable: true })
@@ -69,17 +69,20 @@ export class ReverseKittingOrderInventoryPatch {
69
69
  @Field(type => Float, { nullable: true })
70
70
  uomValue?: number
71
71
 
72
- @Field(type => ObjectRef)
72
+ @Field(type => ObjectRef, { nullable: true })
73
73
  reverseKittingOrder: ObjectRef
74
74
 
75
- @Field(type => ObjectRef)
75
+ @Field(type => ObjectRef, { nullable: true })
76
76
  inventory: ObjectRef
77
77
 
78
78
  @Field({ nullable: true })
79
79
  status: string
80
80
 
81
- @Field()
81
+ @Field({ nullable: true })
82
82
  cuFlag: string
83
+
84
+ @Field({ nullable: true })
85
+ issue: string
83
86
  }
84
87
 
85
88
  @ObjectType()
@@ -12,12 +12,12 @@ import {
12
12
 
13
13
  import { User } from '@things-factory/auth-base'
14
14
  import { Bizplace } from '@things-factory/biz-base'
15
+ import { Product } from '@things-factory/product-base'
15
16
  import { Domain } from '@things-factory/shell'
16
17
  import { Inventory } from '@things-factory/warehouse-base'
17
- import { Product } from '@things-factory/product-base'
18
- import { Vas } from '../vas/vas'
19
18
 
20
19
  import { ReverseKittingOrder } from '../reverse-kitting-order/reverse-kitting-order'
20
+ import { Vas } from '../vas/vas'
21
21
 
22
22
  @Entity()
23
23
  @Index(
@@ -115,6 +115,7 @@ export class ReverseKittingOrderInventory {
115
115
  @Field({ nullable: true })
116
116
  description?: string
117
117
 
118
+ @Column({ nullable: true })
118
119
  @Field({ nullable: true })
119
120
  issue?: string
120
121
 
@@ -58,6 +58,10 @@ export class OrderNoGenerator {
58
58
  return `OP-${uuid()}`
59
59
  }
60
60
 
61
+ static invoiceProduct() {
62
+ return `IP-${uuid()}`
63
+ }
64
+
61
65
  static orderVas() {
62
66
  return `OV-${uuid()}`
63
67
  }
@@ -121,4 +125,11 @@ export class OrderNoGenerator {
121
125
  currentDate.getMonth() + 1
122
126
  }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
123
127
  }
128
+
129
+ static invoice() {
130
+ const currentDate = new Date()
131
+ return `INV-${currentDate.getFullYear()}${
132
+ currentDate.getMonth() + 1
133
+ }${currentDate.getDate()}${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}${currentDate.getMilliseconds()}`
134
+ }
124
135
  }