@things-factory/sales-base 4.3.239 → 4.3.244

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 (61) 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/index.js +1 -0
  4. package/dist-server/controllers/ecommerce/index.js.map +1 -1
  5. package/dist-server/controllers/ecommerce/powrup-controller.js +211 -0
  6. package/dist-server/controllers/ecommerce/powrup-controller.js.map +1 -0
  7. package/dist-server/index.js +1 -0
  8. package/dist-server/index.js.map +1 -1
  9. package/dist-server/service/delivery-order/delivery-order-query.js +2 -2
  10. package/dist-server/service/delivery-order/delivery-order-query.js.map +1 -1
  11. package/dist-server/service/index.js +4 -0
  12. package/dist-server/service/index.js.map +1 -1
  13. package/dist-server/service/order-inventory/order-inventory-query.js +2 -1
  14. package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
  15. package/dist-server/service/order-vas/order-vas-mutation.js +85 -0
  16. package/dist-server/service/order-vas/order-vas-mutation.js.map +1 -1
  17. package/dist-server/service/order-vas/order-vas-query.js +4 -1
  18. package/dist-server/service/order-vas/order-vas-query.js.map +1 -1
  19. package/dist-server/service/order-vas/order-vas-types.js +54 -10
  20. package/dist-server/service/order-vas/order-vas-types.js.map +1 -1
  21. package/dist-server/service/order-vas/order-vas.js +103 -21
  22. package/dist-server/service/order-vas/order-vas.js.map +1 -1
  23. package/dist-server/service/order-vas-item/index.js +9 -0
  24. package/dist-server/service/order-vas-item/index.js.map +1 -0
  25. package/dist-server/service/order-vas-item/order-vas-item-mutation.js +120 -0
  26. package/dist-server/service/order-vas-item/order-vas-item-mutation.js.map +1 -0
  27. package/dist-server/service/order-vas-item/order-vas-item-query.js +99 -0
  28. package/dist-server/service/order-vas-item/order-vas-item-query.js.map +1 -0
  29. package/dist-server/service/order-vas-item/order-vas-item-type.js +111 -0
  30. package/dist-server/service/order-vas-item/order-vas-item-type.js.map +1 -0
  31. package/dist-server/service/order-vas-item/order-vas-item.js +146 -0
  32. package/dist-server/service/order-vas-item/order-vas-item.js.map +1 -0
  33. package/dist-server/service/release-good/release-good-mutation.js +28 -25
  34. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  35. package/dist-server/service/release-good/release-good-query.js +6 -1
  36. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  37. package/dist-server/service/vas/vas.js +8 -6
  38. package/dist-server/service/vas/vas.js.map +1 -1
  39. package/dist-server/service/vas-order/vas-order-mutation.js +2 -2
  40. package/dist-server/service/vas-order/vas-order-mutation.js.map +1 -1
  41. package/package.json +4 -3
  42. package/server/constants/order.ts +2 -1
  43. package/server/controllers/ecommerce/index.ts +1 -0
  44. package/server/controllers/ecommerce/powrup-controller.ts +301 -0
  45. package/server/index.ts +1 -0
  46. package/server/service/delivery-order/delivery-order-query.ts +19 -19
  47. package/server/service/index.ts +4 -0
  48. package/server/service/order-inventory/order-inventory-query.ts +2 -1
  49. package/server/service/order-vas/order-vas-mutation.ts +94 -1
  50. package/server/service/order-vas/order-vas-query.ts +4 -1
  51. package/server/service/order-vas/order-vas-types.ts +34 -1
  52. package/server/service/order-vas/order-vas.ts +89 -10
  53. package/server/service/order-vas-item/index.ts +6 -0
  54. package/server/service/order-vas-item/order-vas-item-mutation.ts +112 -0
  55. package/server/service/order-vas-item/order-vas-item-query.ts +58 -0
  56. package/server/service/order-vas-item/order-vas-item-type.ts +71 -0
  57. package/server/service/order-vas-item/order-vas-item.ts +128 -0
  58. package/server/service/release-good/release-good-mutation.ts +30 -26
  59. package/server/service/release-good/release-good-query.ts +56 -87
  60. package/server/service/vas/vas.ts +11 -5
  61. package/server/service/vas-order/vas-order-mutation.ts +2 -2
@@ -0,0 +1,301 @@
1
+ import { getRepository, EntityManager } from 'typeorm'
2
+
3
+ import { Bizplace } from '@things-factory/biz-base'
4
+ import { logger } from '@things-factory/env'
5
+ import { Powrup, PowrupAPI, Platform } from '@things-factory/integration-powrup'
6
+ import { Product, ProductDetail } from '@things-factory/product-base'
7
+ import { Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
8
+ import { Domain, User } from '@things-factory/shell'
9
+
10
+ import { DateTimeDifference } from '../../utils/datetime-util'
11
+ import { ORDER_STATUS } from '../../constants'
12
+ import { OrderNoGenerator } from '../../utils'
13
+ import { OrderPackage } from '../../service/order-package/order-package'
14
+ import { OrderPackageItem } from '../../service/order-package-item/order-package-item'
15
+ import { OrderProduct } from '../../service/order-product/order-product'
16
+ import { ReleaseGood } from '../../service/release-good/release-good'
17
+
18
+ export class PowrupController {
19
+ async packOrder(
20
+ powrup: Powrup,
21
+ releaseGood: ReleaseGood,
22
+ domain?: Domain,
23
+ user?: User,
24
+ trxMgr?: EntityManager
25
+ ): Promise<ReleaseGood> {
26
+ try {
27
+ const orderProducts: OrderProduct[] = releaseGood.orderProducts
28
+ const orderInformation: any = {
29
+ refOrderId: releaseGood.refOrderId
30
+ }
31
+
32
+ if (
33
+ releaseGood?.lastMarketPackCall &&
34
+ DateTimeDifference.timeDifferenceInSeconds(releaseGood.lastMarketPackCall, new Date()) <= 5
35
+ ) {
36
+ return
37
+ }
38
+
39
+ await getRepository(ReleaseGood).update(
40
+ { id: releaseGood.id },
41
+ {
42
+ lastMarketPackCall: new Date()
43
+ }
44
+ )
45
+
46
+ const orderPack: any = await PowrupAPI.packOrder(powrup, {
47
+ ...orderInformation,
48
+ context: { state: { domain: domain || null, user: user || null } }
49
+ })
50
+
51
+ if (orderPack?.packages) {
52
+ const packages: any[] = orderPack.packages
53
+
54
+ await Promise.all(
55
+ packages.map(async pkg => {
56
+ const items = pkg.items
57
+ const orderPackage: any = {
58
+ name: OrderNoGenerator.orderPackage(),
59
+ packageId: pkg.packageId,
60
+ status: ORDER_STATUS.PROCESSING,
61
+ releaseGood,
62
+ domain: releaseGood.domain,
63
+ bizplace: releaseGood.bizplace,
64
+ creator: releaseGood.creator,
65
+ updater: releaseGood.updater
66
+ }
67
+
68
+ let savedOrderPackage: OrderPackage = await trxMgr.getRepository(OrderPackage).save(orderPackage)
69
+
70
+ const orderPackageItems: OrderPackageItem[] = items.map(itm => {
71
+ const { refCode, qty } = itm
72
+ const matchedOrderProduct: OrderProduct = orderProducts.find(op => op.productDetail.refCode == refCode)
73
+
74
+ return {
75
+ name: OrderNoGenerator.orderPackageItem(),
76
+ orderProduct: matchedOrderProduct,
77
+ status: ORDER_STATUS.PROCESSING,
78
+ releaseQty: qty,
79
+ orderPackage: savedOrderPackage,
80
+ domain: releaseGood.domain,
81
+ bizplace: releaseGood.bizplace,
82
+ creator: releaseGood.creator,
83
+ updater: releaseGood.updater
84
+ }
85
+ })
86
+
87
+ await trxMgr.getRepository(OrderPackageItem).save(orderPackageItems)
88
+ })
89
+ )
90
+
91
+ await trxMgr.getRepository(ReleaseGood).update(
92
+ { id: releaseGood.id },
93
+ {
94
+ packageId: packages[0].packageId,
95
+ marketPackCallSuccess: new Date(),
96
+ lastMarketPackCall: new Date(),
97
+ updatedAt: new Date()
98
+ }
99
+ )
100
+ }
101
+ } catch (error) {
102
+ logger.error(`powrup-controller[packOrder]: ${error}`)
103
+ throw error
104
+ }
105
+
106
+ return releaseGood
107
+ }
108
+
109
+ async updateStock(
110
+ inventories: Inventory[],
111
+ customerDomain: Domain,
112
+ user?: User,
113
+ trxMgr?: EntityManager
114
+ ): Promise<void> {
115
+ const bizplace: Bizplace = await trxMgr.getRepository(Bizplace).findOne({ domain: customerDomain })
116
+ const powrup: Powrup = await trxMgr
117
+ .getRepository(Powrup)
118
+ .findOne({ where: { platform: Platform.POWRUP, active: true } })
119
+
120
+ if (powrup) {
121
+ for (let inventory of inventories) {
122
+ let product: Product = inventory.product
123
+ const productDetail: ProductDetail = inventory.productDetail
124
+ const warehouseDomainId: string = inventory.domainId
125
+ let qb = await trxMgr.getRepository(Inventory).createQueryBuilder('inv')
126
+ qb.leftJoinAndSelect('inv.location', 'loc')
127
+ .andWhere('"inv"."domain_id" = :domainId')
128
+ .andWhere('"inv"."bizplace_id" = :bizplaceId')
129
+ .andWhere('"inv"."product_id" = :productId')
130
+ .andWhere('"inv"."product_detail_id" = :productDetailId')
131
+ .andWhere('"inv"."status" = :status')
132
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
133
+ .setParameters({
134
+ domainId: warehouseDomainId,
135
+ bizplaceId: bizplace.id,
136
+ productId: product.id,
137
+ productDetailId: productDetail.id,
138
+ status: INVENTORY_STATUS.STORED,
139
+ locationTypes: [LOCATION_TYPE.QUARANTINE]
140
+ })
141
+
142
+ let inventories: Inventory[] = await qb.getMany()
143
+ let inventoryTotalQty: number = 0
144
+ let inventoryTotalLockedQty: number = 0
145
+ let inventoryBufferQty: number = 0
146
+
147
+ inventories.forEach((inventory: Inventory) => {
148
+ const { qty, lockedQty } = inventory
149
+ inventoryTotalQty += qty
150
+ inventoryTotalLockedQty += lockedQty
151
+ if (inventory.location.type === LOCATION_TYPE.RESERVE) {
152
+ inventoryBufferQty += qty
153
+ }
154
+ })
155
+
156
+ const powrupInvs: any[] = [
157
+ {
158
+ refCode: productDetail.refCode,
159
+ stock: {
160
+ quantityTotal: inventoryTotalQty - inventoryTotalLockedQty - inventoryBufferQty || 0,
161
+ quantityReserved: inventoryTotalLockedQty - inventoryBufferQty || 0,
162
+ quantityBuffer: inventoryBufferQty || 0
163
+ }
164
+ }
165
+ ]
166
+
167
+ await PowrupAPI.updateStock(powrup, {
168
+ context: { state: { domain: customerDomain || null, user: user || user } },
169
+ warehouseDomainId,
170
+ powrupInvs
171
+ })
172
+ }
173
+ }
174
+ }
175
+
176
+ async initiateShipment(
177
+ powrup: Powrup,
178
+ releaseGood: ReleaseGood,
179
+ domain?: Domain,
180
+ user?: User,
181
+ trxMgr?: EntityManager
182
+ ): Promise<void> {
183
+ try {
184
+ let orderPackages: OrderPackage[] = await trxMgr
185
+ .getRepository(OrderPackage)
186
+ .find({ where: { releaseGood, bizplace: releaseGood.bizplace } })
187
+
188
+ if (orderPackages?.length) {
189
+ await Promise.all(
190
+ orderPackages
191
+ .filter(op => op?.marketRtsCallSuccess == undefined)
192
+ .map(async op => {
193
+ if (!op?.packageId) throw new Error('Order package id is not found')
194
+ if (releaseGood.lmdOption && !op?.parcelId) return
195
+
196
+ let orderInformation: any = {
197
+ refOrderId: releaseGood.refOrderId,
198
+ packageId: op.packageId
199
+ }
200
+ if (releaseGood.lmdOption) {
201
+ let releaseGoodQuery: ReleaseGood = await getRepository(ReleaseGood).findOne({
202
+ where: { id: releaseGood.id },
203
+ relations: ['lastMileDelivery']
204
+ })
205
+ orderInformation = {
206
+ ...orderInformation,
207
+ awb: op.airwayBill,
208
+ trackingNo: op.trackingNo,
209
+ lmdOption: releaseGood.lmdOption,
210
+ shipperName: releaseGoodQuery.lastMileDelivery.platform
211
+ }
212
+ }
213
+
214
+ try {
215
+ await PowrupAPI.initiateShipment(powrup, {
216
+ ...orderInformation,
217
+ context: { state: { domain, user } }
218
+ })
219
+ await getRepository(OrderPackage).update({ id: op.id }, { marketRtsCallSuccess: new Date() })
220
+ } catch (error) {
221
+ logger.error(
222
+ `powrup-controller[initiateShipment]: ${JSON.stringify({
223
+ ...orderInformation,
224
+ context: { state: { domain: domain || null, user: user || null } },
225
+ error: error
226
+ })}`
227
+ )
228
+ }
229
+ })
230
+ )
231
+ }
232
+ } catch (error) {
233
+ throw error
234
+ }
235
+ }
236
+
237
+ async fetchDocument(
238
+ powrup: Powrup,
239
+ releaseGood: ReleaseGood,
240
+ domain?: Domain,
241
+ user?: User,
242
+ trxMgr?: EntityManager
243
+ ): Promise<ReleaseGood> {
244
+ if (releaseGood?.ownTransport && releaseGood?.lmdOption) {
245
+ return
246
+ }
247
+ try {
248
+ let orderPackages: OrderPackage[] = await trxMgr
249
+ .getRepository(OrderPackage)
250
+ .find({ where: { releaseGood, bizplace: releaseGood.bizplace } })
251
+
252
+ if (orderPackages?.length) {
253
+ await Promise.all(
254
+ orderPackages.map(async op => {
255
+ if (!op?.packageId) throw new Error('Order package id is not found')
256
+
257
+ const orderInformation: any = {
258
+ refOrderId: releaseGood.refOrderId,
259
+ packageId: op.packageId
260
+ }
261
+
262
+ const {
263
+ documents,
264
+ trackingNo,
265
+ transporter
266
+ }: { documents: any[]; trackingNo: string; transporter: string } = await PowrupAPI.fetchDocument(powrup, {
267
+ ...orderInformation,
268
+ context: { state: { domain: domain || null, user: user || null } }
269
+ })
270
+
271
+ let updateInfo: any
272
+ if (documents?.length) {
273
+ documents.map(document => {
274
+ if (document.type === 'invoice') {
275
+ updateInfo = { ...updateInfo, invoice: document.download_url }
276
+ } else if (document.type === 'airway_bill') {
277
+ updateInfo = { ...updateInfo, airwayBill: document.download_url }
278
+ }
279
+ })
280
+
281
+ updateInfo = {
282
+ ...updateInfo,
283
+ trackingNo: trackingNo,
284
+ transporter: transporter,
285
+ updater: user
286
+ }
287
+
288
+ await trxMgr.getRepository(OrderPackage).update({ id: op.id }, { ...updateInfo })
289
+ }
290
+ })
291
+ )
292
+
293
+ releaseGood = await trxMgr.getRepository(ReleaseGood).findOne({ id: releaseGood.id })
294
+ }
295
+
296
+ return releaseGood
297
+ } catch (error) {
298
+ throw error
299
+ }
300
+ }
301
+ }
package/server/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from './migrations'
3
3
  export * from './utils'
4
4
  export * from './constants'
5
5
  export * from './controllers/ecommerce/sellercraft-controller'
6
+ export * from './controllers/ecommerce/powrup-controller'
@@ -143,8 +143,8 @@ export class DeliveryOrderQuery {
143
143
  [arrChildSortData.indexOf(sort.name) >= 0
144
144
  ? 'releaseGood.' + sort.name
145
145
  : arrNameSortData.indexOf(sort.name) >= 0
146
- ? sort.name + '.name'
147
- : 'do.' + sort.name]: sort.desc ? 'DESC' : 'ASC'
146
+ ? sort.name + '.name'
147
+ : 'do.' + sort.name]: sort.desc ? 'DESC' : 'ASC'
148
148
  }),
149
149
  params.sortings.length < 1 ? { rank: 'ASC', 'do.createdAt': 'DESC' } : {}
150
150
  )
@@ -251,13 +251,13 @@ export class DeliveryOrderQuery {
251
251
 
252
252
  let [items, total] = await getRepository(OrderInventory).findAndCount({
253
253
  where: { domain, deliveryOrder },
254
- relations: ['inventory', 'inventory.product', 'inventory.reusablePallet']
254
+ relations: ['product', 'productDetail', 'inventory', 'inventory.product', 'inventory.reusablePallet']
255
255
  })
256
256
 
257
257
  items = items
258
258
  .map((oi: OrderInventory) => {
259
259
  const inventory: Inventory = oi.inventory
260
- const product: Product = inventory.product
260
+ const product: Product = oi.product
261
261
  return {
262
262
  inventory: inventory,
263
263
  productName: `${product.name} (${product.description})`,
@@ -321,12 +321,12 @@ export class DeliveryOrderQuery {
321
321
  systemRemark: prod?.remark
322
322
  ? prod.remark
323
323
  : prod.crossDocking
324
- ? prod.pallet === ''
325
- ? `${prod.palletQty} PALLET(S) [C/D]`
326
- : `${prod.palletQty} PALLET(S) (${prod.pallet}) [C/D]`
327
- : prod.pallet === ''
328
- ? `${prod.palletQty} PALLET(S)`
329
- : `${prod.palletQty} PALLET(S) (${prod.pallet})`
324
+ ? prod.pallet === ''
325
+ ? `${prod.palletQty} PALLET(S) [C/D]`
326
+ : `${prod.palletQty} PALLET(S) (${prod.pallet}) [C/D]`
327
+ : prod.pallet === ''
328
+ ? `${prod.palletQty} PALLET(S)`
329
+ : `${prod.palletQty} PALLET(S) (${prod.pallet})`
330
330
  }
331
331
  })
332
332
 
@@ -413,12 +413,12 @@ export class DeliveryOrderQuery {
413
413
  systemRemark: prod?.remark
414
414
  ? prod.remark
415
415
  : prod.crossDocking
416
- ? prod.pallet === ''
417
- ? `${prod.palletQty} PALLET(S) [C/D]`
418
- : `${prod.palletQty} PALLET(S) (${prod.pallet}) [C/D]`
419
- : prod.pallet === ''
420
- ? `${prod.palletQty} PALLET(S)`
421
- : `${prod.palletQty} PALLET(S) (${prod.pallet})`
416
+ ? prod.pallet === ''
417
+ ? `${prod.palletQty} PALLET(S) [C/D]`
418
+ : `${prod.palletQty} PALLET(S) (${prod.pallet}) [C/D]`
419
+ : prod.pallet === ''
420
+ ? `${prod.palletQty} PALLET(S)`
421
+ : `${prod.palletQty} PALLET(S) (${prod.pallet})`
422
422
  }
423
423
  })
424
424
 
@@ -442,7 +442,7 @@ export class DeliveryOrderQuery {
442
442
 
443
443
  const releaseGoodParam = params.filters.find(param => param.name === 'releaseGoodNo')
444
444
  if (releaseGoodParam) {
445
- let arrFilters = []
445
+ let arrFilters = []
446
446
  params.filters.splice(
447
447
  params.filters.findIndex(item => item.name == 'releaseGoodNo'),
448
448
  1
@@ -546,8 +546,8 @@ export class DeliveryOrderQuery {
546
546
  [arrChildSortData.indexOf(sort.name) >= 0
547
547
  ? 'releaseGood.' + sort.name
548
548
  : arrNameSortData.indexOf(sort.name) >= 0
549
- ? sort.name + '.name'
550
- : 'do.' + sort.name]: sort.desc ? 'DESC' : 'ASC'
549
+ ? sort.name + '.name'
550
+ : 'do.' + sort.name]: sort.desc ? 'DESC' : 'ASC'
551
551
  }),
552
552
  params.sortings.length < 1 ? { rank: 'ASC', 'do.createdAt': 'DESC' } : {}
553
553
  )
@@ -1,4 +1,5 @@
1
1
  /* IMPORT ENTITIES AND RESOLVERS */
2
+ import { entities as OrderVasItemEntities, resolvers as OrderVasItemResolvers } from './order-vas-item'
2
3
  import { entities as ReplenishmentEntities, resolvers as ReplenishmentResolvers } from './replenishment'
3
4
  import { entities as ArrivalNoticeEntity, resolvers as ArrivalNoticeResolvers } from './arrival-notice'
4
5
  import { entities as ClaimEntity, resolvers as ClaimResolvers } from './claim'
@@ -47,6 +48,7 @@ import { entities as VasEntity, resolvers as VasResolvers } from './vas'
47
48
  import { entities as VasOrderEntity, resolvers as VasOrderResolvers } from './vas-order'
48
49
 
49
50
  /* EXPORT ENTITY TYPES */
51
+ export * from './order-vas-item/order-vas-item'
50
52
  export * from './replenishment/replenishment'
51
53
  export * from './replenishment/replenishment'
52
54
  export * from './arrival-notice/arrival-notice'
@@ -179,6 +181,7 @@ export * from './vas/vas-query'
179
181
 
180
182
  export const entities = [
181
183
  /* ENTITIES */
184
+ ...OrderVasItemEntities,
182
185
  ...ReplenishmentEntities,
183
186
  ...ReplenishmentEntities,
184
187
  ...ArrivalNoticeEntity,
@@ -218,6 +221,7 @@ export const entities = [
218
221
  export const schema = {
219
222
  resolverClasses: [
220
223
  /* RESOLVER CLASSES */
224
+ ...OrderVasItemResolvers,
221
225
  ...ReplenishmentResolvers,
222
226
  ...ReplenishmentResolvers,
223
227
  ...ArrivalNoticeResolvers,
@@ -71,7 +71,8 @@ export class OrderInventoryQuery {
71
71
  qb.leftJoinAndSelect('oi.arrivalNotice', 'arrivalNotice')
72
72
  qb.leftJoinAndSelect('oi.orderProduct', 'orderProduct')
73
73
  qb.leftJoinAndSelect('oi.inventory', 'inventory')
74
- qb.leftJoinAndSelect('inventory.product', 'product')
74
+ qb.leftJoinAndSelect('oi.product', 'product')
75
+ qb.leftJoinAndSelect('inventory.product', 'inventoryProduct')
75
76
  qb.leftJoinAndSelect('inventory.location', 'location')
76
77
  qb.leftJoinAndSelect('oi.releaseGood', 'releaseGood')
77
78
  qb.leftJoinAndSelect('oi.deliveryOrder', 'deliveryOrder')
@@ -1,8 +1,9 @@
1
1
  import { Domain } from '@things-factory/shell'
2
2
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
3
- import { EntityManager } from 'typeorm'
3
+ import { EntityManager, getRepository } from 'typeorm'
4
4
  import { OrderVasPatch } from '../'
5
5
  import { OrderVas } from './order-vas'
6
+ // import { WorksheetDetail } from '@things-factory/worksheet-base'
6
7
 
7
8
  @Resolver(OrderVas)
8
9
  export class OrderVasMutation {
@@ -18,4 +19,96 @@ export class OrderVasMutation {
18
19
  let orderVas = await tx.getRepository(OrderVas).findOne(id)
19
20
  return await tx.getRepository(OrderVas).save({ orderVas, ...patch })
20
21
  }
22
+
23
+ @Directive('@transaction')
24
+ @Mutation(returns => [OrderVas])
25
+ async updateMultipleOrderVas(
26
+ @Arg('patches', type => [OrderVasPatch]) patches: OrderVasPatch[],
27
+ @Ctx() context: any
28
+ ): Promise<OrderVasPatch[]> {
29
+ const { domain, user } = context.state
30
+
31
+ let results = []
32
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
33
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
34
+ const orderVasRepo = getRepository(OrderVas)
35
+
36
+ if (_createRecords.length > 0) {
37
+ for (let i = 0; i < _createRecords.length; i++) {
38
+ const newRecord = _createRecords[i]
39
+
40
+ const result = await orderVasRepo.save({
41
+ ...newRecord,
42
+ domain: domain,
43
+ creator: user,
44
+ updater: user
45
+ })
46
+
47
+ results.push({ ...result, cuFlag: '+' })
48
+ }
49
+ }
50
+
51
+ if (_updateRecords.length > 0) {
52
+ for (let i = 0; i < _updateRecords.length; i++) {
53
+ const newRecord = _updateRecords[i]
54
+ const orderVas = await orderVasRepo.findOne({
55
+ where: { domain, id: newRecord.id },
56
+ relations: ['product', 'productDetail', 'newProduct', 'newProductDetail', 'releaseGood', 'orderVasItems']
57
+ })
58
+
59
+ const result = await orderVasRepo.save({
60
+ ...orderVas,
61
+ ...newRecord,
62
+ updater: user
63
+ })
64
+
65
+ results.push({ ...result, cuFlag: 'M' })
66
+ }
67
+ }
68
+
69
+ return results
70
+ }
71
+
72
+ @Directive('@privilege(category: "vas", privilege: "mutation")')
73
+ @Directive('@transaction')
74
+ @Mutation(returns => Boolean)
75
+ async deleteOrderVas(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
76
+ const { tx }: { tx: EntityManager } = context.state
77
+ await tx.getRepository(OrderVas).delete(id)
78
+ return true
79
+ }
80
+
81
+ @Directive('@privilege(category: "vas", privilege: "mutation")')
82
+ @Directive('@transaction')
83
+ @Mutation(returns => Boolean)
84
+ async deleteOrderVass(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
85
+ const { tx }: { tx: EntityManager } = context.state
86
+ // const foundWDs = await tx.getRepository(WorksheetDetail)
87
+ // .createQueryBuilder('wd')
88
+ // .innerJoinAndSelect('wd.targetVas', 'tv')
89
+ // .where('tv.id IN (:...ids)', { ids })
90
+ // .getMany();
91
+
92
+ const foundWDs = await tx.query(
93
+ `
94
+ select wd.*, ov.*
95
+ from worksheet_details wd
96
+ left join order_vass ov on wd.target_vas_id = ov.id
97
+ where ov.id IN ('${ ids }');
98
+ `
99
+ )
100
+
101
+ if (foundWDs.length > 0) {
102
+ await tx.query(
103
+ `
104
+ delete from worksheet_details wd
105
+ left join order_vass or on wd.target_vas_id = ov.id
106
+ where ov.id IN ('${ ids }')
107
+ `
108
+ )
109
+ }
110
+
111
+ await tx.getRepository(OrderVas).delete(ids)
112
+ return true
113
+ }
21
114
  }
@@ -22,7 +22,10 @@ export class OrderVasQuery {
22
22
  'releaseGood',
23
23
  'vasOrder',
24
24
  'shippingOrder',
25
- 'vas',
25
+ 'product',
26
+ 'newProduct',
27
+ 'orderVasItems',
28
+ 'orderVasItems.vas',
26
29
  'inventory',
27
30
  'creator',
28
31
  'updater'
@@ -26,7 +26,7 @@ export class NewOrderVas {
26
26
  targetBatchId: string
27
27
 
28
28
  @Field(type => ObjectRef, { nullable: true })
29
- targetProduct: ObjectRef
29
+ product: ObjectRef
30
30
 
31
31
  @Field({ nullable: true })
32
32
  otherTarget: string
@@ -88,6 +88,9 @@ export class OrderVasPatch {
88
88
  @Field({ nullable: true })
89
89
  id: string
90
90
 
91
+ @Field(type => ObjectRef, { nullable: true })
92
+ bizplace: ObjectRef
93
+
91
94
  @Field({ nullable: true })
92
95
  name: string
93
96
 
@@ -103,12 +106,21 @@ export class OrderVasPatch {
103
106
  @Field(type => ObjectRef, { nullable: true })
104
107
  targetProduct: ObjectRef
105
108
 
109
+ @Field(type => ObjectRef, { nullable: true })
110
+ product: ObjectRef
111
+
112
+ @Field(type => ObjectRef, { nullable: true })
113
+ productDetail: ObjectRef
114
+
106
115
  @Field({ nullable: true })
107
116
  otherTarget: string
108
117
 
109
118
  @Field(type => Int, { nullable: true })
110
119
  qty: number
111
120
 
121
+ @Field({ nullable: true })
122
+ uom: string
123
+
112
124
  @Field(type => Float, { nullable: true })
113
125
  uomValue: number
114
126
 
@@ -145,6 +157,24 @@ export class OrderVasPatch {
145
157
  @Field({ nullable: true })
146
158
  operationGuide: string
147
159
 
160
+ @Field({ nullable: true })
161
+ newProduct: string
162
+
163
+ @Field({ nullable: true })
164
+ newProductDetail: string
165
+
166
+ @Field({ nullable: true })
167
+ newPackingType: string
168
+
169
+ @Field({ nullable: true })
170
+ newUom: string
171
+
172
+ @Field({ nullable: true })
173
+ newUomValue: number
174
+
175
+ @Field({ nullable: true })
176
+ outputQty: number
177
+
148
178
  @Field({ nullable: true })
149
179
  remark: string
150
180
 
@@ -154,6 +184,9 @@ export class OrderVasPatch {
154
184
  @Field({ nullable: true })
155
185
  status: string
156
186
 
187
+ @Field({ nullable: true })
188
+ domain: string
189
+
157
190
  @Field({ nullable: true })
158
191
  cuFlag: string
159
192
  }