@things-factory/sales-base 4.3.79-alpha.1 → 4.3.79

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/service/arrival-notice/arrival-notice.js +0 -5
  2. package/dist-server/service/arrival-notice/arrival-notice.js.map +1 -1
  3. package/dist-server/service/draft-release-good/draft-release-good-mutation.js +8 -3
  4. package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
  5. package/dist-server/service/draft-release-good/draft-release-good-query.js +7 -4
  6. package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
  7. package/dist-server/service/draft-release-good/draft-release-good.js +0 -5
  8. package/dist-server/service/draft-release-good/draft-release-good.js.map +1 -1
  9. package/dist-server/service/invoice-product/invoice-product.js +3 -8
  10. package/dist-server/service/invoice-product/invoice-product.js.map +1 -1
  11. package/dist-server/service/order-inventory/order-inventory-types.js +10 -18
  12. package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
  13. package/dist-server/service/order-inventory/order-inventory.js +3 -8
  14. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  15. package/dist-server/service/order-product/order-product-query.js +0 -1
  16. package/dist-server/service/order-product/order-product-query.js.map +1 -1
  17. package/dist-server/service/order-product/order-product-types.js +10 -14
  18. package/dist-server/service/order-product/order-product-types.js.map +1 -1
  19. package/dist-server/service/order-vas/order-vas.js +3 -8
  20. package/dist-server/service/order-vas/order-vas.js.map +1 -1
  21. package/dist-server/service/others/other-query.js +32 -21
  22. package/dist-server/service/others/other-query.js.map +1 -1
  23. package/dist-server/service/others/other-types.js +0 -4
  24. package/dist-server/service/others/other-types.js.map +1 -1
  25. package/dist-server/service/purchase-order/purchase-order-mutation.js +2 -10
  26. package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
  27. package/dist-server/service/purchase-order/purchase-order-query.js +0 -1
  28. package/dist-server/service/purchase-order/purchase-order-query.js.map +1 -1
  29. package/dist-server/service/release-good/release-good-mutation.js +49 -187
  30. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  31. package/dist-server/service/release-good/release-good-query.js +6 -4
  32. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  33. package/dist-server/service/release-good/release-good-types.js +4 -8
  34. package/dist-server/service/release-good/release-good-types.js.map +1 -1
  35. package/dist-server/service/release-good/release-good.js +0 -5
  36. package/dist-server/service/release-good/release-good.js.map +1 -1
  37. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +3 -8
  38. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -1
  39. package/dist-server/utils/inventory-util.js +102 -33
  40. package/dist-server/utils/inventory-util.js.map +1 -1
  41. package/package.json +13 -13
  42. package/server/service/arrival-notice/arrival-notice.ts +0 -4
  43. package/server/service/draft-release-good/draft-release-good-mutation.ts +12 -10
  44. package/server/service/draft-release-good/draft-release-good-query.ts +5 -5
  45. package/server/service/draft-release-good/draft-release-good.ts +0 -4
  46. package/server/service/invoice-product/invoice-product.ts +1 -5
  47. package/server/service/order-inventory/order-inventory-types.ts +0 -6
  48. package/server/service/order-inventory/order-inventory.ts +1 -5
  49. package/server/service/order-product/order-product-query.ts +0 -1
  50. package/server/service/order-product/order-product-types.ts +0 -3
  51. package/server/service/order-vas/order-vas.ts +1 -6
  52. package/server/service/others/other-query.ts +43 -34
  53. package/server/service/others/other-types.ts +0 -3
  54. package/server/service/purchase-order/purchase-order-mutation.ts +1 -10
  55. package/server/service/purchase-order/purchase-order-query.ts +0 -1
  56. package/server/service/release-good/release-good-mutation.ts +50 -221
  57. package/server/service/release-good/release-good-query.ts +7 -4
  58. package/server/service/release-good/release-good-types.ts +3 -4
  59. package/server/service/release-good/release-good.ts +6 -8
  60. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +1 -5
  61. package/server/utils/inventory-util.ts +147 -67
@@ -195,7 +195,6 @@ export class DraftReleaseGoodMutation {
195
195
  relations: [
196
196
  'orderProducts',
197
197
  'orderProducts.product',
198
- 'orderProducts.productDetail',
199
198
  'orderProducts.productBundle',
200
199
  'shippingOrder',
201
200
  'bizplace',
@@ -263,14 +262,13 @@ export class DraftReleaseGoodMutation {
263
262
  draftOrder.orderProducts = draftOrder.orderProducts.map(itm => {
264
263
  let foundProductInv = productInventory.items.find(
265
264
  i =>
266
- (i.productDetailId == itm?.productDetail?.id || i.productId == itm?.productBundle?.id) &&
265
+ (i.productId == itm?.product?.id || i.productId == itm?.productBundle?.id) &&
266
+ i.packingType == itm.packingType &&
267
+ i.packingSize == itm.packingSize &&
268
+ i.uom == itm.uom &&
267
269
  itm.releaseQty <= i.remainQty
268
270
  )
269
- return {
270
- ...itm,
271
- releaseUomValue: (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty,
272
- status: foundProductInv ? 'suffice' : 'insufficient'
273
- }
271
+ return { ...itm, releaseUomValue: (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty, status: foundProductInv ? 'suffice' : 'insufficient' }
274
272
  })
275
273
 
276
274
  let insufficient = draftOrder.orderProducts.find(op => op.status == 'insufficient')
@@ -279,6 +277,10 @@ export class DraftReleaseGoodMutation {
279
277
  let releaseGood = { ...draftOrder }
280
278
  delete releaseGood.id
281
279
  delete releaseGood.name
280
+ delete releaseGood.createdAt
281
+ delete releaseGood.createdBy
282
+ delete releaseGood.updatedAt
283
+ delete releaseGood.updatedBy
282
284
 
283
285
  let orderInventories = []
284
286
 
@@ -495,6 +497,7 @@ export async function createDraftReleaseGoodFunction(
495
497
  updater: user
496
498
  })
497
499
 
500
+
498
501
  // // 3. Create draft release good product
499
502
  await upsertDraftReleaseGoodProducts(
500
503
  domain,
@@ -629,7 +632,6 @@ export async function upsertDraftReleaseGoodProducts(
629
632
  relations: [
630
633
  'orderProducts',
631
634
  'orderProducts.product',
632
- 'orderProducts.productDetail',
633
635
  'orderProducts.productBundle',
634
636
  'orderProducts.creator',
635
637
  'orderProducts.updater'
@@ -731,8 +733,8 @@ export async function upsertDraftReleaseGoodProducts(
731
733
  updatePatch['packingType'] = op?.packingType
732
734
  ? op.packingType
733
735
  : product?.packingType
734
- ? product.packingType
735
- : productBundle.packingType
736
+ ? product.packingType
737
+ : productBundle.packingType
736
738
  updatePatch['uom'] = op?.uom ? op.uom : product?.primaryUnit ? product.primaryUnit : 'UNIT'
737
739
  updatePatch['uomValue'] = op?.uomValue ? op.uomValue : product?.primaryValue ? product.primaryValue : 0
738
740
 
@@ -255,7 +255,6 @@ export async function getDraftReleaseGoodFunction(_: any, name: any, context: an
255
255
  'releaseGood',
256
256
  'orderProducts',
257
257
  'orderProducts.product',
258
- 'orderProducts.productDetail',
259
258
  'orderProducts.productBundle',
260
259
  'shippingOrder',
261
260
  'bizplace',
@@ -317,7 +316,11 @@ export async function getDraftReleaseGoodFunction(_: any, name: any, context: an
317
316
 
318
317
  result.orderProducts = result.orderProducts.map(itm => {
319
318
  let foundProductInv = productInventory?.items.find(
320
- i => i.productDetailId == itm?.productDetail?.id || i.productId == itm?.productBundle?.id
319
+ i =>
320
+ (i.productId == itm?.product?.id || i.productId == itm?.productBundle?.id) &&
321
+ i.packingType == itm.packingType &&
322
+ i.packingSize == itm.packingSize &&
323
+ i.uom == itm.uom
321
324
  )
322
325
  return {
323
326
  ...itm,
@@ -327,9 +330,6 @@ export async function getDraftReleaseGoodFunction(_: any, name: any, context: an
327
330
  brand: foundProductInv.productBrand,
328
331
  sku: foundProductInv.productSKU
329
332
  },
330
- productDetail: itm.productDetail || {
331
- id: foundProductInv.productDetailId
332
- },
333
333
  groupType: foundProductInv ? foundProductInv.groupType : 'SINGLE',
334
334
  remainQty: foundProductInv ? foundProductInv.remainQty : 0,
335
335
  remainUomValue: foundProductInv ? foundProductInv.remainUomValue : 0,
@@ -237,10 +237,6 @@ export class DraftReleaseGood {
237
237
  @Field({ nullable: true })
238
238
  packageId: string
239
239
 
240
- @Column({ nullable: true })
241
- @Field({ nullable: true })
242
- source: string
243
-
244
240
  @ManyToOne(type => ContactPoint)
245
241
  @Field(type => ContactPoint, { nullable: true })
246
242
  deliverTo: ContactPoint
@@ -11,7 +11,7 @@ import {
11
11
  } from 'typeorm'
12
12
 
13
13
  import { User } from '@things-factory/auth-base'
14
- import { Product, ProductDetail } from '@things-factory/product-base'
14
+ import { Product } from '@things-factory/product-base'
15
15
  import { Domain } from '@things-factory/shell'
16
16
 
17
17
  import { Invoice } from '../invoice/invoice'
@@ -77,10 +77,6 @@ export class InvoiceProduct {
77
77
  @Field({ nullable: true })
78
78
  shippingFeePaidByCustomer: number
79
79
 
80
- @ManyToOne(type => ProductDetail, { nullable: true })
81
- @Field({ nullable: true })
82
- productDetail: ProductDetail
83
-
84
80
  @CreateDateColumn()
85
81
  @Field()
86
82
  createdAt: Date
@@ -41,9 +41,6 @@ export class NewOrderInventory {
41
41
  @Field(type => NewProduct, { nullable: true })
42
42
  product: NewProduct
43
43
 
44
- @Field(type => ObjectRef, { nullable: true })
45
- productDetail: ObjectRef
46
-
47
44
  @Field({ nullable: true })
48
45
  productSKU: string
49
46
 
@@ -203,9 +200,6 @@ export class OrderInventoryPatch {
203
200
  @Field({ nullable: true })
204
201
  productId: string
205
202
 
206
- @Field({ nullable: true })
207
- productDetailId: string
208
-
209
203
  @Field({ nullable: true })
210
204
  orderProductId: string
211
205
 
@@ -13,7 +13,7 @@ import {
13
13
 
14
14
  import { User } from '@things-factory/auth-base'
15
15
  import { Bizplace } from '@things-factory/biz-base'
16
- import { Product, ProductDetail} from '@things-factory/product-base'
16
+ import { Product } from '@things-factory/product-base'
17
17
  import { Domain } from '@things-factory/shell'
18
18
  import { Inventory, Location } from '@things-factory/warehouse-base'
19
19
 
@@ -341,10 +341,6 @@ export class OrderInventory {
341
341
  @Field({ nullable: true })
342
342
  loadedAt: Date
343
343
 
344
- @ManyToOne(type => ProductDetail, { nullable: true })
345
- @Field({ nullable: true })
346
- productDetail: ProductDetail
347
-
348
344
  @Field({ nullable: true })
349
345
  dispatchedAt: Date
350
346
 
@@ -26,7 +26,6 @@ export class OrderProductQuery {
26
26
 
27
27
  let qb: SelectQueryBuilder<OrderProduct> = await getRepository(OrderProduct).createQueryBuilder('op')
28
28
  qb.leftJoinAndSelect('op.product', 'product')
29
- .leftJoinAndSelect('op.productDetail', 'productDetail')
30
29
  .leftJoinAndSelect('op.domain', 'domain')
31
30
  .leftJoinAndSelect('op.bizplace', 'bizplace')
32
31
  .leftJoinAndSelect('bizplace.company', 'company')
@@ -84,9 +84,6 @@ export class OrderProductPatch {
84
84
  @Field(type => ObjectRef, { nullable: true })
85
85
  toInventory: ObjectRef
86
86
 
87
- @Field(type => ObjectRef, { nullable: true })
88
- productDetail: ObjectRef
89
-
90
87
  @Field(type => InboundProduct, { nullable: true })
91
88
  product: InboundProduct
92
89
 
@@ -12,7 +12,7 @@ import {
12
12
 
13
13
  import { User } from '@things-factory/auth-base'
14
14
  import { Bizplace } from '@things-factory/biz-base'
15
- import { Product, ProductDetail } from '@things-factory/product-base'
15
+ import { Product } from '@things-factory/product-base'
16
16
  import { Domain } from '@things-factory/shell'
17
17
  import { Inventory } from '@things-factory/warehouse-base'
18
18
 
@@ -200,10 +200,6 @@ export class OrderVas {
200
200
  @Field()
201
201
  updatedAt: Date
202
202
 
203
- @ManyToOne(type => ProductDetail, { nullable: true })
204
- @Field({ nullable: true })
205
- productDetail: ProductDetail
206
-
207
203
  @ManyToOne(type => User)
208
204
  @Field(type => User, { nullable: true })
209
205
  creator: User
@@ -217,5 +213,4 @@ export class OrderVas {
217
213
 
218
214
  @RelationId((orderVas: OrderVas) => orderVas.updater)
219
215
  updaterId: string
220
-
221
216
  }
@@ -195,49 +195,59 @@ export class OtherQuery {
195
195
 
196
196
  const { items, total } = await InventoryUtil.bizplaceInventoryProductGroup(bizplaces, params, context, tx)
197
197
 
198
- let packageUomValue = total > 0 ? items[0].remainUomValue / items[0].remainQty : null
198
+ // Filter to find for item with enough remain qty
199
+ const availableItems = items.filter(item => item.remainQty >= orderInventory.releaseQty)
200
+ let availableItem
199
201
 
202
+ if (availableItems.length > 0) {
203
+ availableItem = availableItems[0]
204
+ }
205
+
206
+ let packageUomValue = availableItem ? availableItem.remainUomValue / availableItem.remainQty : null
200
207
  const newOrderInventory: any = {
201
- product:
202
- total > 0 ? { id: items[0].productId, sku: items[0].productSKU, name: items[0].productName } : { id: null },
203
- productDetail: total > 0 ? { id: items[0].productDetailId } : { id: null },
204
- inventory:
205
- total > 0
206
- ? {
207
- ...items[0],
208
- remainQty: total > 0 ? items[0].remainQty : null,
209
- remainUomValue: total > 0 ? items[0].remainUomValue : null,
210
- remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : ''
211
- }
212
- : null,
213
- productId: total > 0 ? items[0].productId : null,
214
- productDetailID: total > 0 ? items[0].productDetailId : null,
215
- productSKU: total > 0 ? items[0].productSKU : orderInventory.productSKU,
216
- productName: total > 0 ? items[0].productName : null,
217
- uom: total > 0 ? items[0].uom : null,
218
- remainQty: total > 0 ? items[0].remainQty : null,
219
- remainUomValue: total > 0 ? items[0].remainUomValue : null,
220
- remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : '',
221
- batchId: total > 0 ? items[0].batchId : null,
222
- batchIdRef: total > 0 ? items[0].batchIdRef : null,
223
- packingType: total > 0 ? items[0].packingType : orderInventory.packingType,
224
- packingSize: total > 0 ? items[0].packingSize : 1,
208
+ product: availableItem
209
+ ? {
210
+ id: availableItem.productId,
211
+ sku: availableItem.productSKU,
212
+ name: availableItem.productName
213
+ }
214
+ : { id: null },
215
+ inventory: availableItem
216
+ ? {
217
+ ...availableItem,
218
+ remainQty: availableItem ? availableItem.remainQty : null,
219
+ remainUomValue: availableItem ? availableItem.remainUomValue : null,
220
+ remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : ''
221
+ }
222
+ : null,
223
+ productId: availableItem ? availableItem.productId : null,
224
+ productSKU: availableItem ? availableItem.productSKU : orderInventory.productSKU,
225
+ productName: availableItem ? availableItem.productName : null,
226
+ uom: availableItem ? availableItem.uom : null,
227
+ remainQty: availableItem ? availableItem.remainQty : null,
228
+ remainUomValue: availableItem ? availableItem.remainUomValue : null,
229
+ remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : '',
230
+ batchId: availableItem ? availableItem.batchId : null,
231
+ batchIdRef: availableItem ? availableItem.batchIdRef : null,
232
+ packingType: availableItem ? availableItem.packingType : orderInventory.packingType,
233
+ packingSize: availableItem ? availableItem.packingSize : 1,
225
234
  releaseQty: orderInventory.releaseQty
226
235
  ? Number.isInteger(orderInventory.releaseQty)
227
236
  ? orderInventory.releaseQty
228
237
  : null
229
238
  : null,
230
- releaseUomValue:
231
- total > 0
232
- ? Number.isInteger(orderInventory.releaseQty)
233
- ? parseFloat((orderInventory.releaseQty * packageUomValue).toFixed(2))
234
- : null
235
- : null,
236
- groupType: total > 0 ? items[0].groupType : null,
237
- isError: total <= 0 ? true : false
239
+ releaseUomValue: availableItem
240
+ ? Number.isInteger(orderInventory.releaseQty)
241
+ ? parseFloat((orderInventory.releaseQty * packageUomValue).toFixed(2))
242
+ : null
243
+ : null,
244
+ groupType: availableItem ? availableItem.groupType : null,
245
+ isError: !availableItem ? true : false
238
246
  }
239
247
 
240
248
  newOrderInventories.push(newOrderInventory)
249
+
250
+ // end loop
241
251
  }
242
252
 
243
253
  try {
@@ -518,7 +528,6 @@ export class OtherQuery {
518
528
  primaryUnit: productDetail?.uom ? productDetail.uom : null,
519
529
  primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
520
530
  },
521
- productDetail,
522
531
  totalUomValue:
523
532
  orderProduct.packQty > 0
524
533
  ? uomValue
@@ -19,9 +19,6 @@ export class InventoryProductGroup {
19
19
  @Field({ nullable: true })
20
20
  productId: string
21
21
 
22
- @Field({ nullable: true })
23
- productDetailId: string
24
-
25
22
  @Field({ nullable: true })
26
23
  batchId: string
27
24
 
@@ -69,14 +69,7 @@ export class PurchaseOrderMutation {
69
69
 
70
70
  const findPurchaseOrder: PurchaseOrder = await getRepository(PurchaseOrder).findOne({
71
71
  where: { domain, id },
72
- relations: [
73
- 'orderProducts',
74
- 'orderProducts.product',
75
- 'orderProducts.productDetail',
76
- 'bufferLocation',
77
- 'bizplace',
78
- 'domain'
79
- ]
72
+ relations: ['orderProducts', 'orderProducts.product', 'bufferLocation', 'bizplace', 'domain']
80
73
  })
81
74
 
82
75
  // const findPurchaseOrder: PurchaseOrder = await tx.getRepository(PurchaseOrder).findOne({id}, { relations:['bizplace']})
@@ -425,7 +418,6 @@ export async function upsertPurchaseOrderProducts(
425
418
  const bizplaceRepo: Repository<Product> = tx?.getRepository(Bizplace) || getRepository(Bizplace)
426
419
  const orderProductRepo: Repository<OrderProduct> = tx?.getRepository(OrderProduct) || getRepository(OrderProduct)
427
420
  const productRepo: Repository<Product> = tx?.getRepository(Product) || getRepository(Product)
428
- const productDetailRepo: Repository<Product> = tx?.getRepository(ProductDetail) || getRepository(ProductDetail)
429
421
 
430
422
  // // Remove all existing order products that do not exist in current input
431
423
  let removeOP = purchaseOrder.orderProducts.filter(
@@ -451,7 +443,6 @@ export async function upsertPurchaseOrderProducts(
451
443
  bizplace: bizplace,
452
444
  name: op?.id ? op.name : OrderNoGenerator.orderProduct(),
453
445
  product: await productRepo.findOne(op.product.id),
454
- productDetail: await productDetailRepo.findOne(op.productDetail.id),
455
446
  packingSize: foundProductDetail?.packingSize || 1,
456
447
  purchaseOrder: purchaseOrder,
457
448
  status: purchaseOrder.status,
@@ -62,7 +62,6 @@ export async function getPurchaseOrderFunction(_: any, name: any, context: any,
62
62
  'supplier',
63
63
  'orderProducts',
64
64
  'orderProducts.product',
65
- 'orderProducts.productDetail',
66
65
  'otherCharges',
67
66
  'bufferLocation',
68
67
  'bizplace',