@things-factory/sales-base 4.3.46 → 4.3.50

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 (37) hide show
  1. package/dist-server/constants/order.js +2 -1
  2. package/dist-server/constants/order.js.map +1 -1
  3. package/dist-server/controllers/ecommerce/sellercraft-controller.js +102 -94
  4. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
  5. package/dist-server/service/arrival-notice/arrival-notice-mutation.js +93 -21
  6. package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
  7. package/dist-server/service/draft-release-good/draft-release-good.js +5 -0
  8. package/dist-server/service/draft-release-good/draft-release-good.js.map +1 -1
  9. package/dist-server/service/manifest/manifest-mutation.js +78 -1
  10. package/dist-server/service/manifest/manifest-mutation.js.map +1 -1
  11. package/dist-server/service/manifest/manifest-query.js +47 -12
  12. package/dist-server/service/manifest/manifest-query.js.map +1 -1
  13. package/dist-server/service/manifest/manifest-type.js +8 -0
  14. package/dist-server/service/manifest/manifest-type.js.map +1 -1
  15. package/dist-server/service/manifest/manifest.js +5 -0
  16. package/dist-server/service/manifest/manifest.js.map +1 -1
  17. package/dist-server/service/purchase-order/purchase-order-mutation.js +8 -4
  18. package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
  19. package/dist-server/service/release-good/release-good-mutation.js +2 -16
  20. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  21. package/dist-server/service/release-good/release-good-query.js +70 -58
  22. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  23. package/package.json +13 -13
  24. package/server/constants/order.ts +2 -1
  25. package/server/controllers/ecommerce/sellercraft-controller.ts +124 -107
  26. package/server/service/arrival-notice/arrival-notice-mutation.ts +110 -22
  27. package/server/service/draft-release-good/draft-release-good.ts +7 -3
  28. package/server/service/manifest/manifest-mutation.ts +78 -3
  29. package/server/service/manifest/manifest-query.ts +68 -18
  30. package/server/service/manifest/manifest-type.ts +6 -0
  31. package/server/service/manifest/manifest.ts +6 -2
  32. package/server/service/purchase-order/purchase-order-mutation.ts +10 -5
  33. package/server/service/release-good/release-good-mutation.ts +23 -30
  34. package/server/service/release-good/release-good-query.ts +81 -65
  35. package/translations/en.json +4 -0
  36. package/translations/ko.json +6 -2
  37. package/translations/ms.json +5 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/sales-base",
3
- "version": "4.3.46",
3
+ "version": "4.3.50",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,17 +24,17 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/attachment-base": "^4.3.46",
28
- "@things-factory/auth-base": "^4.3.46",
29
- "@things-factory/biz-base": "^4.3.46",
30
- "@things-factory/code-base": "^4.3.46",
31
- "@things-factory/integration-sftp": "^4.3.46",
32
- "@things-factory/notification": "^4.3.46",
33
- "@things-factory/product-base": "^4.3.46",
34
- "@things-factory/setting-base": "^4.3.46",
35
- "@things-factory/shell": "^4.3.46",
36
- "@things-factory/transport-base": "^4.3.46",
37
- "@things-factory/warehouse-base": "^4.3.46"
27
+ "@things-factory/attachment-base": "^4.3.47",
28
+ "@things-factory/auth-base": "^4.3.47",
29
+ "@things-factory/biz-base": "^4.3.47",
30
+ "@things-factory/code-base": "^4.3.47",
31
+ "@things-factory/integration-sftp": "^4.3.50",
32
+ "@things-factory/notification": "^4.3.47",
33
+ "@things-factory/product-base": "^4.3.47",
34
+ "@things-factory/setting-base": "^4.3.47",
35
+ "@things-factory/shell": "^4.3.47",
36
+ "@things-factory/transport-base": "^4.3.47",
37
+ "@things-factory/warehouse-base": "^4.3.50"
38
38
  },
39
- "gitHead": "83ecc645c3cc602bdae8941bc10b8f17b7d6c279"
39
+ "gitHead": "4be34f9fc5e863e89894a44501e6194a3b74c21e"
40
40
  }
@@ -45,7 +45,8 @@ export const DISPATCHMENT_STATUS = {
45
45
 
46
46
  export const MANIFEST_STATUS = {
47
47
  OPEN: 'OPEN',
48
- CLOSED: 'CLOSED'
48
+ CLOSED: 'CLOSED',
49
+ IN_QUEUE: 'IN_QUEUE'
49
50
  }
50
51
 
51
52
  export const ORDER_INVENTORY_TYPE = {
@@ -11,134 +11,151 @@ import { OrderController } from '../order-controller'
11
11
 
12
12
  export class SellercraftController extends OrderController {
13
13
  async packOrder(sellercraft: Sellercraft, releaseGood: ReleaseGood): Promise<ReleaseGood> {
14
- const orderProducts: OrderProduct[] = releaseGood.orderProducts
15
- let sellercraftOPs: any[] = []
14
+ let sellercraftSetting: any = sellercraft.sellercraftSetting
15
+ let disablePackOrder: boolean =
16
+ sellercraftSetting?.disablePackOrder && sellercraftSetting?.disablePackOrder == 1 ? true : false
16
17
 
17
- sellercraftOPs = orderProducts.map(orderProduct => {
18
- const product: Product = orderProduct.product
18
+ if (!disablePackOrder) {
19
+ const orderProducts: OrderProduct[] = releaseGood.orderProducts
20
+ let sellercraftOPs: any[] = []
19
21
 
20
- return {
21
- sku: product.sku,
22
- releaseQty: orderProduct.releaseQty,
23
- uom: 'EA'
22
+ sellercraftOPs = orderProducts.map(orderProduct => {
23
+ const product: Product = orderProduct.product
24
+
25
+ return {
26
+ sku: product.sku,
27
+ releaseQty: orderProduct.releaseQty,
28
+ uom: 'EA'
29
+ }
30
+ })
31
+
32
+ const orderInformation: any = {
33
+ accountId: sellercraft.accountId,
34
+ orderId: releaseGood.refNo2,
35
+ sellercraftOPs
24
36
  }
25
- })
37
+ const packageId: string = await SellercraftAPI.packMarketplaceOrder(sellercraft, {
38
+ ...orderInformation,
39
+ context: { state: { domain: this?.domain, user: this?.user } }
40
+ })
26
41
 
27
- const orderInformation: any = {
28
- accountId: sellercraft.accountId,
29
- orderId: releaseGood.refNo2,
30
- sellercraftOPs
42
+ releaseGood.packageId = packageId
43
+ releaseGood.updater = this.user
31
44
  }
32
- const packageId: string = await SellercraftAPI.packMarketplaceOrder(sellercraft, {
33
- ...orderInformation,
34
- context: { state: { domain: this?.domain, user: this?.user } }
35
- })
36
45
 
37
- releaseGood.packageId = packageId
38
- releaseGood.updater = this.user
39
46
  return releaseGood
40
47
  }
41
48
 
42
49
  async updateSellercraftStock(sellercraft: Sellercraft, orderProducts: OrderProduct[], type: string): Promise<void> {
43
- for (var i = 0; i < orderProducts.length; i++) {
44
- const orderProduct: OrderProduct = orderProducts[i]
45
-
46
- const product: Product = orderProduct.product
47
- const pendingAssignOPs: OrderProduct[] = await this.trxMgr.getRepository(OrderProduct).find({
48
- where: {
49
- domain: this.domain,
50
- bizplace: orderProduct.bizplace,
51
- product,
52
- status: ORDER_PRODUCT_STATUS.PENDING_ASSIGN
53
- }
54
- })
50
+ let sellercraftSetting: any = sellercraft.sellercraftSetting
51
+ let disableUpdateStock: boolean =
52
+ sellercraftSetting?.disableUpdateStock && sellercraftSetting?.disableUpdateStock == 1 ? true : false
53
+
54
+ if (!disableUpdateStock) {
55
+ for (var i = 0; i < orderProducts.length; i++) {
56
+ const orderProduct: OrderProduct = orderProducts[i]
57
+
58
+ const product: Product = orderProduct.product
59
+ const pendingAssignOPs: OrderProduct[] = await this.trxMgr.getRepository(OrderProduct).find({
60
+ where: {
61
+ domain: this.domain,
62
+ bizplace: orderProduct.bizplace,
63
+ product,
64
+ status: ORDER_PRODUCT_STATUS.PENDING_ASSIGN
65
+ }
66
+ })
55
67
 
56
- const productDetails: ProductDetail[] = product.productDetails
68
+ const productDetails: ProductDetail[] = product.productDetails
57
69
 
58
- let totalUnassignReleaseQty: number = 0
59
- if (pendingAssignOPs?.length) {
60
- totalUnassignReleaseQty = pendingAssignOPs.reduce((total, currentValue) => {
61
- total += currentValue.releaseQty
70
+ let totalUnassignReleaseQty: number = 0
71
+ if (pendingAssignOPs?.length) {
72
+ totalUnassignReleaseQty = pendingAssignOPs.reduce((total, currentValue) => {
73
+ total += currentValue.releaseQty
74
+ return total
75
+ }, 0)
76
+ }
77
+
78
+ let qb = await this.trxMgr.getRepository(Inventory).createQueryBuilder('inv')
79
+ qb.leftJoinAndSelect('inv.location', 'loc')
80
+ .andWhere('"inv"."domain_id" = :domainId')
81
+ .andWhere('"inv"."product_id" = :productId')
82
+ .andWhere('"inv"."bizplace_id" = :bizplaceId')
83
+ .andWhere('"inv"."status" = :status')
84
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
85
+ .setParameters({
86
+ domainId: this.domain.id,
87
+ productId: product.id,
88
+ bizplaceId: orderProduct.bizplace.id,
89
+ status: INVENTORY_STATUS.STORED,
90
+ locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
91
+ })
92
+
93
+ let inventories: Inventory[] = await qb.getMany()
94
+
95
+ let defaultProductDetail: ProductDetail
96
+ const sellercraftInvs: any[] = await Promise.all(
97
+ inventories.map(async (inventory: Inventory) => {
98
+ const inventoryPackingType: string = inventory.packingType
99
+ defaultProductDetail = product.productDetails.find(productDetail => productDetail.isDefault)
100
+
101
+ let packingSize: number = 1
102
+ if (inventoryPackingType !== defaultProductDetail.packingType) {
103
+ const unmatchingProductDetail: ProductDetail = product.productDetails.find(
104
+ productDetail => productDetail.packingType === inventoryPackingType
105
+ )
106
+
107
+ packingSize = await this.getChildPackingSize(
108
+ productDetails,
109
+ defaultProductDetail,
110
+ unmatchingProductDetail
111
+ )
112
+ if (packingSize == 0) packingSize = 1
113
+ }
114
+
115
+ return { totalQty: inventory.qty * packingSize, totalLockedQty: inventory.lockedQty * packingSize }
116
+ })
117
+ )
118
+
119
+ let inventoryTotalQty: number = sellercraftInvs.reduce((total, currentValue) => {
120
+ total += currentValue.totalQty
62
121
  return total
63
122
  }, 0)
64
- }
65
123
 
66
- let qb = await this.trxMgr.getRepository(Inventory).createQueryBuilder('inv')
67
- qb.leftJoinAndSelect('inv.location', 'loc')
68
- .andWhere('"inv"."domain_id" = :domainId')
69
- .andWhere('"inv"."product_id" = :productId')
70
- .andWhere('"inv"."bizplace_id" = :bizplaceId')
71
- .andWhere('"inv"."status" = :status')
72
- .andWhere('"loc"."type" NOT IN (:...locationTypes)')
73
- .setParameters({
74
- domainId: this.domain.id,
75
- productId: product.id,
76
- bizplaceId: orderProduct.bizplace.id,
77
- status: INVENTORY_STATUS.STORED,
78
- locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
79
- })
80
-
81
- let inventories: Inventory[] = await qb.getMany()
82
-
83
- let defaultProductDetail: ProductDetail
84
- const sellercraftInvs: any[] = await Promise.all(
85
- inventories.map(async (inventory: Inventory) => {
86
- const inventoryPackingType: string = inventory.packingType
87
- defaultProductDetail = product.productDetails.find(productDetail => productDetail.isDefault)
124
+ let inventoryTotalLockedQty: number = sellercraftInvs.reduce((total, currentValue) => {
125
+ total += currentValue.totalLockedQty
126
+ return total
127
+ }, 0)
88
128
 
89
- let packingSize: number = 1
90
- if (inventoryPackingType !== defaultProductDetail.packingType) {
91
- const unmatchingProductDetail: ProductDetail = product.productDetails.find(
92
- productDetail => productDetail.packingType === inventoryPackingType
93
- )
129
+ switch (type) {
130
+ case 'CONFIRM_ORDER':
131
+ inventoryTotalQty -= totalUnassignReleaseQty
132
+ break
133
+ }
94
134
 
95
- packingSize = await this.getChildPackingSize(productDetails, defaultProductDetail, unmatchingProductDetail)
96
- if (packingSize == 0) packingSize = 1
135
+ const sellercraftInv: any[] = [
136
+ {
137
+ sku: product.sku,
138
+ gtin: defaultProductDetail.gtin,
139
+ stock: {
140
+ quantity_total: inventoryTotalQty,
141
+ quantity_reserved: inventoryTotalLockedQty,
142
+ unit_of_measure: 'EA'
143
+ },
144
+ package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,
145
+ package_dimensions: {
146
+ length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,
147
+ width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,
148
+ height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height
149
+ }
97
150
  }
151
+ ]
98
152
 
99
- return { totalQty: inventory.qty * packingSize, totalLockedQty: inventory.lockedQty * packingSize }
153
+ await SellercraftAPI.updateProduct(sellercraft, {
154
+ context: { state: { domain: this?.domain, user: this?.user } },
155
+ accountId: sellercraft.accountId,
156
+ sellercraftInv
100
157
  })
101
- )
102
-
103
- let inventoryTotalQty: number = sellercraftInvs.reduce((total, currentValue) => {
104
- total += currentValue.totalQty
105
- return total
106
- }, 0)
107
-
108
- let inventoryTotalLockedQty: number = sellercraftInvs.reduce((total, currentValue) => {
109
- total += currentValue.totalLockedQty
110
- return total
111
- }, 0)
112
-
113
- switch (type) {
114
- case 'CONFIRM_ORDER':
115
- inventoryTotalQty -= totalUnassignReleaseQty
116
- break
117
158
  }
118
-
119
- const sellercraftInv: any[] = [
120
- {
121
- sku: product.sku,
122
- gtin: defaultProductDetail.gtin,
123
- stock: {
124
- quantity_total: inventoryTotalQty,
125
- quantity_reserved: inventoryTotalLockedQty,
126
- unit_of_measure: 'EA'
127
- },
128
- package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,
129
- package_dimensions: {
130
- length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,
131
- width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,
132
- height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height
133
- }
134
- }
135
- ]
136
-
137
- await SellercraftAPI.updateProduct(sellercraft, {
138
- context: { state: { domain: this?.domain, user: this?.user } },
139
- accountId: sellercraft.accountId,
140
- sellercraftInv
141
- })
142
159
  }
143
160
  }
144
161
 
@@ -14,7 +14,7 @@ import {
14
14
  import { generateId } from '@things-factory/id-rule-base'
15
15
  import { sendNotification } from '@things-factory/notification'
16
16
  import { Product } from '@things-factory/product-base'
17
- import { Setting } from '@things-factory/setting-base'
17
+ import { PartnerSetting, Setting } from '@things-factory/setting-base'
18
18
  import { Domain } from '@things-factory/shell'
19
19
 
20
20
  import {
@@ -66,6 +66,7 @@ export class ArrivalNoticeMutation {
66
66
  const createdArrivalNotice: ArrivalNotice = await generateArrivalNoticeFunction(
67
67
  null,
68
68
  arrivalNotice,
69
+ false,
69
70
  files,
70
71
  context,
71
72
  tx
@@ -198,7 +199,7 @@ export class ArrivalNoticeMutation {
198
199
  @Arg('file', type => GraphQLUpload, { nullable: true }) file?: FileUpload
199
200
  ): Promise<ArrivalNotice> {
200
201
  const { tx }: { tx: EntityManager } = context.state
201
- const createdGAN: ArrivalNotice = await generateArrivalNoticeFunction(null, arrivalNotice, file, context, tx)
202
+ const createdGAN: ArrivalNotice = await generateArrivalNoticeFunction(null, arrivalNotice, false, file, context, tx)
202
203
 
203
204
  debug('createdGAN', createdGAN)
204
205
 
@@ -235,15 +236,20 @@ export class ArrivalNoticeMutation {
235
236
  async bulkGenerateArrivalNotices(
236
237
  @Ctx() context: any,
237
238
  @Arg('rawArrivalNotices', type => [NewArrivalNotice], { nullable: true }) rawArrivalNotices: NewArrivalNotice[],
238
- @Arg('bizplaceId', type => String) bizplaceId: string
239
+ @Arg('bizplaceId', type => String) bizplaceId: string,
240
+ @Arg('bufferLocation', type => String, { nullable: true }) bufferLocation: string
239
241
  ): Promise<ArrivalNoticeList> {
240
242
  const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
241
243
  let createdArrivalNoticeIds: string[] = [],
242
244
  createdOrderProductIds: string[] = [],
243
245
  errorsCaught: any[] = [],
244
246
  finalArrivalNoticeList: ArrivalNotice[] = []
247
+ let opStatus = ORDER_PRODUCT_STATUS.PENDING_RECEIVE
248
+ let anStatus = ORDER_STATUS.PENDING_RECEIVE
245
249
 
246
- const foundBizplace: Bizplace = await tx.getRepository(Bizplace).findOne(bizplaceId)
250
+ const foundBizplace: Bizplace = await tx
251
+ .getRepository(Bizplace)
252
+ .findOne({ where: { id: bizplaceId }, relations: ['domain'] })
247
253
 
248
254
  if (!foundBizplace) throw new Error('company not found')
249
255
 
@@ -262,6 +268,27 @@ export class ArrivalNoticeMutation {
262
268
  }
263
269
  })
264
270
 
271
+ const ganProcessingSetting: Setting = await tx.getRepository(Setting).findOne({
272
+ where: { domain, category: 'id-rule', name: 'gan-order-processing' }
273
+ })
274
+
275
+ const partnerGanProcessingSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
276
+ where: { setting: ganProcessingSetting, domain, partnerDomain: foundBizplace.domain.id }
277
+ })
278
+
279
+ // If status of GAN is PENDING_RECEIVE then directly to assign warehouse
280
+ if (ganProcessingSetting) {
281
+ let setting = !isNaN(partnerGanProcessingSetting?.value)
282
+ ? partnerGanProcessingSetting?.value
283
+ : ganProcessingSetting.value
284
+
285
+ // CONFIRM to assign if setting value is 1
286
+ if (setting == 1) {
287
+ opStatus = ORDER_PRODUCT_STATUS.ARRIVED
288
+ anStatus = ORDER_STATUS.ARRIVED
289
+ }
290
+ }
291
+
265
292
  // extract rawArrivalNotices data into normal ArrivalNotice format
266
293
  let arrivalNotices: Partial<ArrivalNotice[]> = extractArrivalNotices(validatedArrivalNotices)
267
294
 
@@ -336,12 +363,12 @@ export class ArrivalNoticeMutation {
336
363
  // update arrivalNotices status to PENDING_RECEIVE
337
364
  await childTx
338
365
  .getRepository(ArrivalNotice)
339
- .update({ id: In(createdArrivalNoticeIds) }, { status: ORDER_STATUS.PENDING_RECEIVE, updater: user })
366
+ .update({ id: In(createdArrivalNoticeIds) }, { status: anStatus, updater: user })
340
367
 
341
368
  // update orderProducts status to PENDING_RECEIVE
342
369
  await childTx
343
370
  .getRepository(OrderProduct)
344
- .update({ id: In(createdOrderProductIds) }, { status: ORDER_PRODUCT_STATUS.PENDING_RECEIVE, updater: user })
371
+ .update({ id: In(createdOrderProductIds) }, { status: opStatus, updater: user })
345
372
 
346
373
  finalArrivalNoticeList = await childTx.getRepository(ArrivalNotice).find({
347
374
  where: { id: In(createdArrivalNoticeIds) },
@@ -423,6 +450,7 @@ export async function deleteArrivalNotice(
423
450
  export async function generateArrivalNoticeFunction(
424
451
  _: any,
425
452
  arrivalNotice: any,
453
+ fromPo: Boolean,
426
454
  files: FileUpload[],
427
455
  context: any,
428
456
  tx?: EntityManager
@@ -474,7 +502,7 @@ export async function generateArrivalNoticeFunction(
474
502
  domain,
475
503
  bizplace: myBizplace,
476
504
  looseItem: arrivalNotice?.looseItem ? arrivalNotice.looseItem : false,
477
- status: ORDER_STATUS.PENDING,
505
+ status: fromPo ? ORDER_STATUS.INTRANSIT : ORDER_STATUS.PENDING,
478
506
  creator: user,
479
507
  updater: user
480
508
  })
@@ -484,7 +512,7 @@ export async function generateArrivalNoticeFunction(
484
512
  domain,
485
513
  createdArrivalNotice,
486
514
  orderProducts.map((op: OrderProduct) => {
487
- return { ...op, status: ORDER_PRODUCT_STATUS.PENDING }
515
+ return { ...op, status: fromPo ? ORDER_PRODUCT_STATUS.INTRANSIT : ORDER_PRODUCT_STATUS.PENDING }
488
516
  }),
489
517
  user,
490
518
  tx
@@ -508,7 +536,7 @@ export async function generateArrivalNoticeFunction(
508
536
  vas: await tx.getRepository(Vas).findOne({ domain, id: ov.vas.id }),
509
537
  type: ORDER_TYPES.ARRIVAL_NOTICE,
510
538
  arrivalNotice: createdArrivalNotice,
511
- status: ORDER_VAS_STATUS.PENDING,
539
+ status: fromPo ? ORDER_VAS_STATUS.INTRANSIT : ORDER_VAS_STATUS.PENDING,
512
540
  creator: user,
513
541
  updater: user
514
542
  }
@@ -542,6 +570,7 @@ export async function confirmArrivalNoticeFunction(
542
570
  where: { domain, name, status: ORDER_STATUS.PENDING },
543
571
  relations: [
544
572
  'bizplace',
573
+ 'bizplace.domain',
545
574
  'releaseGood',
546
575
  'orderProducts',
547
576
  'orderProducts.product',
@@ -555,25 +584,56 @@ export async function confirmArrivalNoticeFunction(
555
584
  let foundOPs: OrderProduct[] = foundArrivalNotice.orderProducts
556
585
  let foundOVs: OrderVas[] = foundArrivalNotice.orderVass
557
586
  let customerBizplace: Bizplace = foundArrivalNotice.bizplace
587
+ let opStatus = ORDER_PRODUCT_STATUS.PENDING_RECEIVE
588
+ let anStatus = ORDER_STATUS.PENDING_RECEIVE
589
+ let ovStatus = ORDER_VAS_STATUS.PENDING_RECEIVE
590
+ let acceptedByUser = null
591
+ let acceptedTime = null
592
+
593
+ const ganProcessingSetting: Setting = await tx.getRepository(Setting).findOne({
594
+ where: { domain, category: 'id-rule', name: 'gan-order-processing' }
595
+ })
596
+
597
+ const partnerGanProcessingSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
598
+ where: { setting: ganProcessingSetting, domain, partnerDomain: customerBizplace?.domain }
599
+ })
600
+
601
+ // If status of GAN is PENDING_RECEIVE then directly to assign warehouse
602
+ if (ganProcessingSetting) {
603
+ let setting = !isNaN(partnerGanProcessingSetting?.value)
604
+ ? partnerGanProcessingSetting?.value
605
+ : ganProcessingSetting.value
606
+
607
+ // CONFIRM to assign if setting value is 1
608
+ if (setting == 1) {
609
+ opStatus = ORDER_PRODUCT_STATUS.ARRIVED
610
+ anStatus = ORDER_STATUS.ARRIVED
611
+ ovStatus = ORDER_VAS_STATUS.ARRIVED
612
+ acceptedByUser = user
613
+ acceptedTime = new Date()
614
+ }
615
+ }
558
616
 
559
617
  if (!foundArrivalNotice) throw new Error(`Arrival notice doesn't exists.`)
560
618
 
561
619
  // 1. GAN Status change (PENDING => PENDING_RECEIVE)
562
- const arrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).save({
620
+ let arrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).save({
563
621
  ...foundArrivalNotice,
564
- status: ORDER_STATUS.PENDING_RECEIVE,
565
- updater: user
622
+ status: anStatus,
623
+ updater: user,
624
+ acceptedBy: acceptedByUser,
625
+ acceptedAt: acceptedTime
566
626
  })
567
627
 
568
628
  foundOPs = foundOPs.map((op: OrderProduct) => {
569
- return { ...op, status: ORDER_PRODUCT_STATUS.PENDING_RECEIVE }
629
+ return { ...op, status: opStatus }
570
630
  })
571
631
  await tx.getRepository(OrderProduct).save(foundOPs)
572
632
 
573
633
  // 2. Update order vas status if it exists.
574
634
  if (foundOVs && foundOVs.length) {
575
635
  foundOVs = foundOVs.map((ov: OrderVas) => {
576
- return { ...ov, status: ORDER_VAS_STATUS.PENDING_RECEIVE }
636
+ return { ...ov, status: ovStatus }
577
637
  })
578
638
 
579
639
  await tx.getRepository(OrderVas).save(foundOVs)
@@ -623,22 +683,50 @@ export async function receiveArrivalNoticeFunction(_: any, name: String, context
623
683
  try {
624
684
  const foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
625
685
  where: { domain, name, status: ORDER_STATUS.PENDING_RECEIVE },
626
- relations: ['bizplace', 'collectionOrders', 'orderProducts', 'orderVass']
686
+ relations: ['bizplace', 'bizplace.domain', 'collectionOrders', 'orderProducts', 'orderVass']
627
687
  })
628
688
 
629
- if (!foundArrivalNotice) throw new Error(`Arrival notice doesn't exists.`)
630
-
631
689
  let foundOPs: OrderProduct[] = foundArrivalNotice.orderProducts
632
690
  let foundOVs: OrderVas[] = foundArrivalNotice.orderVass
633
691
  let foundCOs: CollectionOrder[] = await tx.getRepository(CollectionOrder).find({
634
692
  where: { domain, refNo: foundArrivalNotice.name }
635
693
  })
694
+ let customerBizplace: Bizplace = foundArrivalNotice.bizplace
695
+ let opStatus = ORDER_PRODUCT_STATUS.INTRANSIT
696
+ let anStatus = ORDER_STATUS.INTRANSIT
697
+ let ovStatus = ORDER_VAS_STATUS.INTRANSIT
698
+ let coStatus = ORDER_STATUS.READY_TO_DISPATCH
699
+
700
+ const ganProcessingSetting: Setting = await tx.getRepository(Setting).findOne({
701
+ where: { domain, category: 'id-rule', name: 'gan-order-processing' }
702
+ })
703
+
704
+ const partnerGanProcessingSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
705
+ where: { setting: ganProcessingSetting, domain, partnerDomain: customerBizplace?.domain }
706
+ })
707
+
708
+ // If status of GAN is INTRANSIT then directly to assign warehouse
709
+ if (ganProcessingSetting) {
710
+ let setting = !isNaN(partnerGanProcessingSetting?.value)
711
+ ? partnerGanProcessingSetting?.value
712
+ : ganProcessingSetting.value
713
+
714
+ // RECEIVE to assign if setting value is 2
715
+ if (setting == 2) {
716
+ opStatus = ORDER_PRODUCT_STATUS.ARRIVED
717
+ anStatus = ORDER_STATUS.ARRIVED
718
+ ovStatus = ORDER_VAS_STATUS.ARRIVED
719
+ coStatus = ORDER_STATUS.READY_TO_DISPATCH
720
+ }
721
+ }
722
+
723
+ if (!foundArrivalNotice) throw new Error(`Arrival notice doesn't exists.`)
636
724
 
637
725
  // 1. Update status of order products (PENDING_RECEIVE => INTRANSIT)
638
726
  foundOPs = foundOPs.map((op: OrderProduct) => {
639
727
  return {
640
728
  ...op,
641
- status: ORDER_PRODUCT_STATUS.INTRANSIT,
729
+ status: opStatus,
642
730
  updater: user
643
731
  }
644
732
  })
@@ -649,7 +737,7 @@ export async function receiveArrivalNoticeFunction(_: any, name: String, context
649
737
  foundOVs = foundOVs.map((ov: OrderVas) => {
650
738
  return {
651
739
  ...ov,
652
- status: ORDER_VAS_STATUS.INTRANSIT,
740
+ status: ovStatus,
653
741
  updater: user
654
742
  }
655
743
  })
@@ -661,7 +749,7 @@ export async function receiveArrivalNoticeFunction(_: any, name: String, context
661
749
  foundCOs = foundCOs.map((co: CollectionOrder) => {
662
750
  return {
663
751
  ...co,
664
- status: ORDER_STATUS.READY_TO_DISPATCH,
752
+ status: coStatus,
665
753
  updater: user
666
754
  }
667
755
  })
@@ -686,9 +774,9 @@ export async function receiveArrivalNoticeFunction(_: any, name: String, context
686
774
  }
687
775
 
688
776
  // 4. Update status of arrival notice (PENDING_RECEIVE => INTRANSIT)
689
- await tx.getRepository(ArrivalNotice).save({
777
+ let rcvArrivalNotice = await tx.getRepository(ArrivalNotice).save({
690
778
  ...foundArrivalNotice,
691
- status: ORDER_STATUS.INTRANSIT,
779
+ status: anStatus,
692
780
  acceptedBy: user,
693
781
  acceptedAt: new Date(),
694
782
  updater: user
@@ -1,4 +1,4 @@
1
- import { Field, ID, Float, ObjectType, registerEnumType } from 'type-graphql'
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
2
  import {
3
3
  Column,
4
4
  CreateDateColumn,
@@ -98,8 +98,8 @@ export class DraftReleaseGood {
98
98
  DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
99
99
  ? 'enum'
100
100
  : DATABASE_TYPE == 'oracle'
101
- ? 'varchar2'
102
- : 'smallint',
101
+ ? 'varchar2'
102
+ : 'smallint',
103
103
  enum: ReleaseOrderType,
104
104
  default: ReleaseOrderType.B2B
105
105
  })
@@ -233,6 +233,10 @@ export class DraftReleaseGood {
233
233
  @Field({ nullable: true })
234
234
  email: string
235
235
 
236
+ @Column({ nullable: true })
237
+ @Field({ nullable: true })
238
+ packageId: string
239
+
236
240
  @ManyToOne(type => ContactPoint)
237
241
  @Field(type => ContactPoint, { nullable: true })
238
242
  deliverTo: ContactPoint