@things-factory/sales-base 4.0.39 → 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 (91) 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 +40 -33
  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 +88 -76
  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.js +28 -22
  44. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  45. package/dist-server/service/order-product/order-product.js +26 -21
  46. package/dist-server/service/order-product/order-product.js.map +1 -1
  47. package/dist-server/service/order-vas/order-vas.js +34 -27
  48. package/dist-server/service/order-vas/order-vas.js.map +1 -1
  49. package/dist-server/service/purchase-order/purchase-order-mutation.js +23 -36
  50. package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
  51. package/dist-server/service/release-good/release-good-mutation.js +64 -74
  52. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  53. package/dist-server/service/release-good/release-good-query.js +5 -5
  54. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  55. package/dist-server/service/release-good/release-good.js +2 -0
  56. package/dist-server/service/release-good/release-good.js.map +1 -1
  57. package/dist-server/service/return-order/return-order-mutation.js +3 -3
  58. package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
  59. package/dist-server/utils/order-no-generator.js +7 -0
  60. package/dist-server/utils/order-no-generator.js.map +1 -1
  61. package/package.json +12 -12
  62. package/server/controllers/ecommerce/sellercraft-controller.ts +2 -1
  63. package/server/service/arrival-notice/arrival-notice-mutation.ts +9 -13
  64. package/server/service/arrival-notice/arrival-notice-query.ts +92 -76
  65. package/server/service/arrival-notice/arrival-notice-types.ts +6 -0
  66. package/server/service/arrival-notice/arrival-notice.ts +6 -1
  67. package/server/service/delivery-order/delivery-order-mutation.ts +4 -8
  68. package/server/service/delivery-order/delivery-order-query.ts +4 -4
  69. package/server/service/delivery-order/delivery-order-summary-report.ts +152 -0
  70. package/server/service/delivery-order/delivery-order.ts +4 -1
  71. package/server/service/delivery-order/index.ts +3 -1
  72. package/server/service/index.ts +20 -12
  73. package/server/service/invoice/invoice-mutation.ts +45 -7
  74. package/server/service/invoice/invoice-query.ts +6 -6
  75. package/server/service/invoice/invoice-types.ts +231 -18
  76. package/server/service/invoice/invoice.ts +154 -20
  77. package/server/service/invoice-product/index.ts +9 -0
  78. package/server/service/invoice-product/invoice-product-mutation.ts +54 -0
  79. package/server/service/invoice-product/invoice-product-query.ts +55 -0
  80. package/server/service/invoice-product/invoice-product-types.ts +80 -0
  81. package/server/service/invoice-product/invoice-product.ts +93 -0
  82. package/server/service/order-inventory/order-inventory-query.ts +3 -1
  83. package/server/service/order-inventory/order-inventory.ts +7 -9
  84. package/server/service/order-product/order-product.ts +13 -13
  85. package/server/service/order-vas/order-vas.ts +15 -15
  86. package/server/service/purchase-order/purchase-order-mutation.ts +19 -21
  87. package/server/service/release-good/release-good-mutation.ts +28 -45
  88. package/server/service/release-good/release-good-query.ts +9 -16
  89. package/server/service/release-good/release-good.ts +2 -0
  90. package/server/service/return-order/return-order-mutation.ts +5 -4
  91. package/server/utils/order-no-generator.ts +11 -0
@@ -0,0 +1,55 @@
1
+ import { Arg, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
+ import { getRepository } from 'typeorm'
3
+
4
+ import { User } from '@things-factory/auth-base'
5
+ import { buildQuery, Domain, Filter, Pagination, Sorting } from '@things-factory/shell'
6
+
7
+ import { InvoiceProduct } from './invoice-product'
8
+ import { InvoiceProductList } from './invoice-product-types'
9
+
10
+ @Resolver(InvoiceProduct)
11
+ export class InvoiceProductQuery {
12
+ @Query(returns => InvoiceProductList)
13
+ async invoiceProducts(
14
+ @Ctx() context: any,
15
+ @Arg('filters', type => [Filter], { nullable: true }) filters?: Filter[],
16
+ @Arg('pagination', type => Pagination, { nullable: true }) pagination?: Pagination,
17
+ @Arg('sortings', type => [Sorting], { nullable: true }) sortings?: Sorting[]
18
+ ): Promise<InvoiceProductList> {
19
+ const queryBuilder = getRepository(InvoiceProduct).createQueryBuilder()
20
+ buildQuery(queryBuilder, { filters, pagination, sortings }, context)
21
+ const [items, total] = await queryBuilder
22
+ .leftJoinAndSelect('InvoiceProduct.domain', 'Domain')
23
+ .leftJoinAndSelect('InvoiceProduct.invoice', 'Invoice')
24
+ .leftJoinAndSelect('InvoiceProduct.creator', 'Creator')
25
+ .leftJoinAndSelect('InvoiceProduct.updater', 'Updater')
26
+ .getManyAndCount()
27
+
28
+ return { items, total }
29
+ }
30
+
31
+ @Query(returns => InvoiceProduct)
32
+ async invoiceProduct(@Arg('name') name: string, @Ctx() context: any): Promise<InvoiceProduct> {
33
+ const { domain }: { domain: Domain } = context.state
34
+
35
+ return await getRepository(InvoiceProduct).findOne({
36
+ where: { domain, name },
37
+ relations: ['domain', 'invoice', 'creator', 'updater']
38
+ })
39
+ }
40
+
41
+ @FieldResolver(type => Domain)
42
+ async domain(@Root() invoiceProduct: InvoiceProduct): Promise<Domain> {
43
+ return await getRepository(Domain).findOne(invoiceProduct.domainId)
44
+ }
45
+
46
+ @FieldResolver(type => User)
47
+ async creator(@Root() invoiceProduct: InvoiceProduct): Promise<User> {
48
+ return await getRepository(User).findOne(invoiceProduct.creatorId)
49
+ }
50
+
51
+ @FieldResolver(type => User)
52
+ async updater(@Root() invoiceProduct: InvoiceProduct): Promise<User> {
53
+ return await getRepository(User).findOne(invoiceProduct.updaterId)
54
+ }
55
+ }
@@ -0,0 +1,80 @@
1
+ import { Field, Float, InputType, Int, ObjectType } from 'type-graphql'
2
+
3
+ import { ObjectRef } from '@things-factory/shell'
4
+
5
+ import { InvoiceProduct } from './invoice-product'
6
+
7
+ @ObjectType()
8
+ export class InvoiceProductList {
9
+ @Field(type => [InvoiceProduct], { nullable: true })
10
+ items: InvoiceProduct[]
11
+
12
+ @Field(type => Int, { nullable: true })
13
+ total: number
14
+ }
15
+
16
+ @InputType()
17
+ export class ProductInput {
18
+ @Field()
19
+ sku: string
20
+ }
21
+
22
+ @InputType()
23
+ export class NewInvoiceProduct {
24
+ @Field({ nullable: true })
25
+ name: string
26
+
27
+ @Field({ nullable: true })
28
+ sku: string
29
+
30
+ @Field({ nullable: true })
31
+ description: string
32
+
33
+ @Field(type => ObjectRef)
34
+ invoice: ObjectRef
35
+
36
+ @Field(type => ProductInput)
37
+ product: ProductInput
38
+
39
+ @Field(type => Int)
40
+ qty: number
41
+
42
+ @Field(type => Float, { nullable: false })
43
+ otherCharges: number
44
+
45
+ @Field(type => Float)
46
+ unitPrice: number
47
+
48
+ @Field(type => Float)
49
+ paidPrice: number
50
+ }
51
+
52
+ @InputType()
53
+ export class InvoiceProductPatch {
54
+ @Field({ nullable: true })
55
+ name: string
56
+
57
+ @Field({ nullable: true })
58
+ sku: string
59
+
60
+ @Field({ nullable: true })
61
+ description: string
62
+
63
+ @Field(type => ObjectRef)
64
+ invoice: ObjectRef
65
+
66
+ @Field(type => ProductInput)
67
+ product: ProductInput
68
+
69
+ @Field(type => Int)
70
+ qty: number
71
+
72
+ @Field(type => Float, { nullable: false })
73
+ otherCharges: number
74
+
75
+ @Field(type => Float)
76
+ unitPrice: number
77
+
78
+ @Field(type => Float)
79
+ paidPrice: number
80
+ }
@@ -0,0 +1,93 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import {
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ Index,
7
+ ManyToOne,
8
+ PrimaryGeneratedColumn,
9
+ RelationId,
10
+ UpdateDateColumn
11
+ } from 'typeorm'
12
+
13
+ import { User } from '@things-factory/auth-base'
14
+ import { Product } from '@things-factory/product-base'
15
+ import { Domain } from '@things-factory/shell'
16
+
17
+ import { Invoice } from '../invoice/invoice'
18
+
19
+ @Entity()
20
+ @Index('ix_invoice_product_0', (invoiceProduct: InvoiceProduct) => [invoiceProduct.id], {
21
+ unique: true
22
+ })
23
+ @ObjectType()
24
+ export class InvoiceProduct {
25
+ @PrimaryGeneratedColumn('uuid')
26
+ @Field(type => ID)
27
+ readonly id: string
28
+
29
+ @ManyToOne(type => Domain)
30
+ @Field(type => Domain, { nullable: true })
31
+ domain: Domain
32
+
33
+ @RelationId((invoiceProduct: InvoiceProduct) => invoiceProduct.domain)
34
+ domainId: string
35
+
36
+ @Column({ nullable: true })
37
+ @Field({ nullable: true })
38
+ sku: string
39
+
40
+ @Column()
41
+ @Field()
42
+ name: string
43
+
44
+ @Column({ nullable: true })
45
+ @Field()
46
+ description: string
47
+
48
+ @ManyToOne(type => Invoice)
49
+ @Field(type => Invoice)
50
+ invoice: Invoice
51
+
52
+ @ManyToOne(type => Product, { nullable: true })
53
+ @Field(type => Product, { nullable: true })
54
+ product: Product
55
+
56
+ @Column('int', { default: 0 })
57
+ @Field()
58
+ qty: number
59
+
60
+ @Column('float', { default: 0 })
61
+ @Field({ nullable: true })
62
+ otherCharges: number
63
+
64
+ @Column('float', { default: 0 })
65
+ @Field()
66
+ unitPrice: number
67
+
68
+ @Column('float', { default: 0 })
69
+ @Field()
70
+ paidPrice: number
71
+
72
+ @CreateDateColumn()
73
+ @Field()
74
+ createdAt: Date
75
+
76
+ @UpdateDateColumn()
77
+ @Field({ nullable: true })
78
+ updatedAt: Date
79
+
80
+ @ManyToOne(type => User, { nullable: true })
81
+ @Field(type => User, { nullable: true })
82
+ creator: User
83
+
84
+ @RelationId((invoiceProduct: InvoiceProduct) => invoiceProduct.creator)
85
+ creatorId: string
86
+
87
+ @ManyToOne(type => User, { nullable: true })
88
+ @Field(type => User, { nullable: true })
89
+ updater: User
90
+
91
+ @RelationId((invoiceProduct: InvoiceProduct) => invoiceProduct.updater)
92
+ updaterId: string
93
+ }
@@ -6,7 +6,9 @@ import { getPermittedBizplaceIds } from '@things-factory/biz-base'
6
6
  import { Product } from '@things-factory/product-base'
7
7
  import { buildQuery, convertListParams, Domain, Filter, ListParam, Pagination, Sorting } from '@things-factory/shell'
8
8
 
9
- import { ArrivalNotice, OrderInventoryList, ReleaseGood } from '../'
9
+ import { ArrivalNotice } from '../arrival-notice/arrival-notice'
10
+ import { OrderInventoryList } from '../order-inventory/order-inventory-types'
11
+ import { ReleaseGood } from '../release-good/release-good'
10
12
  import { OrderInventory } from './order-inventory'
11
13
 
12
14
  interface filterInterface {
@@ -16,15 +16,13 @@ import { Product } from '@things-factory/product-base'
16
16
  import { Domain } from '@things-factory/shell'
17
17
  import { Inventory, Location } from '@things-factory/warehouse-base'
18
18
 
19
- import {
20
- ArrivalNotice,
21
- DeliveryOrder,
22
- InventoryCheck,
23
- OrderProduct,
24
- ReleaseGood,
25
- ReturnOrder,
26
- TransferOrder
27
- } from '../'
19
+ import { ArrivalNotice } from '../arrival-notice/arrival-notice'
20
+ import { DeliveryOrder } from '../delivery-order/delivery-order'
21
+ import { InventoryCheck } from '../inventory-check/inventory-check'
22
+ import { OrderProduct } from '../order-product/order-product'
23
+ import { ReleaseGood } from '../release-good/release-good'
24
+ import { ReturnOrder } from '../return-order/return-order'
25
+ import { TransferOrder } from '../transfer-order/transfer-order'
28
26
 
29
27
  @Entity()
30
28
  @Index('ix_order-inventory_0', (orderInventory: OrderInventory) => [orderInventory.domain, orderInventory.name], {
@@ -1,8 +1,3 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { Bizplace } from '@things-factory/biz-base'
3
- import { Product } from '@things-factory/product-base'
4
- import { Domain } from '@things-factory/shell'
5
- import { Inventory } from '@things-factory/warehouse-base'
6
1
  import { Field, ID, ObjectType } from 'type-graphql'
7
2
  import {
8
3
  Column,
@@ -14,14 +9,19 @@ import {
14
9
  RelationId,
15
10
  UpdateDateColumn
16
11
  } from 'typeorm'
17
- import {
18
- ArrivalNotice,
19
- CollectionOrder,
20
- DeliveryOrder,
21
- PurchaseOrder,
22
- ReleaseGood,
23
- RetailReplenishmentOrder
24
- } from '../'
12
+
13
+ import { User } from '@things-factory/auth-base'
14
+ import { Bizplace } from '@things-factory/biz-base'
15
+ import { Product } from '@things-factory/product-base'
16
+ import { Domain } from '@things-factory/shell'
17
+ import { Inventory } from '@things-factory/warehouse-base'
18
+
19
+ import { ArrivalNotice } from '../arrival-notice/arrival-notice'
20
+ import { CollectionOrder } from '../collection-order/collection-order'
21
+ import { DeliveryOrder } from '../delivery-order/delivery-order'
22
+ import { PurchaseOrder } from '../purchase-order/purchase-order'
23
+ import { ReleaseGood } from '../release-good/release-good'
24
+ import { RetailReplenishmentOrder } from '../retail-replenishment-order/retail-replenishment-order'
25
25
 
26
26
  @Entity()
27
27
  @Index('ix_order-product_0', (orderProduct: OrderProduct) => [orderProduct.domain, orderProduct.name], {
@@ -1,8 +1,3 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { Bizplace } from '@things-factory/biz-base'
3
- import { Product } from '@things-factory/product-base'
4
- import { Domain } from '@things-factory/shell'
5
- import { Inventory } from '@things-factory/warehouse-base'
6
1
  import { Field, ID, ObjectType } from 'type-graphql'
7
2
  import {
8
3
  Column,
@@ -14,16 +9,21 @@ import {
14
9
  RelationId,
15
10
  UpdateDateColumn
16
11
  } from 'typeorm'
17
- import {
18
- ArrivalNotice,
19
- ReleaseGood,
20
- RetailReplenishmentOrder,
21
- ReturnOrder,
22
- ShippingOrder,
23
- TransferOrder,
24
- Vas,
25
- VasOrder
26
- } from '../'
12
+
13
+ import { User } from '@things-factory/auth-base'
14
+ import { Bizplace } from '@things-factory/biz-base'
15
+ import { Product } from '@things-factory/product-base'
16
+ import { Domain } from '@things-factory/shell'
17
+ import { Inventory } from '@things-factory/warehouse-base'
18
+
19
+ import { ArrivalNotice } from '../arrival-notice/arrival-notice'
20
+ import { ReleaseGood } from '../release-good/release-good'
21
+ import { RetailReplenishmentOrder } from '../retail-replenishment-order/retail-replenishment-order'
22
+ import { ReturnOrder } from '../return-order/return-order'
23
+ import { ShippingOrder } from '../shipping-order/shipping-order'
24
+ import { TransferOrder } from '../transfer-order/transfer-order'
25
+ import { VasOrder } from '../vas-order/vas-order'
26
+ import { Vas } from '../vas/vas'
27
27
 
28
28
  @Entity('order_vass')
29
29
  @Index('ix_order-vas_0', (orderVas: OrderVas) => [orderVas.domain, orderVas.name], { unique: true })
@@ -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
 
@@ -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],
@@ -136,8 +133,7 @@ export class ReleaseGoodMutation {
136
133
  context,
137
134
  tx
138
135
  )
139
- } catch (error) {
140
- }
136
+ } catch (error) {}
141
137
 
142
138
  if (errorsCaught.length)
143
139
  throw new ValidationError({
@@ -821,11 +817,9 @@ export async function confirmReleaseGood(name: string, context: any, tx?: Entity
821
817
  if (foundMarketplaceProductVariations) {
822
818
  await Promise.all(
823
819
  foundMarketplaceProductVariations.map(async variation => {
824
- if (variation.marketplaceProduct.marketplaceStore.id != matchedMarketplaceStore.id) {
825
- variation.reserveQty -= oi.releaseQty
820
+ variation.reserveQty -= oi.releaseQty
826
821
 
827
- await tx.getRepository(MarketplaceProductVariation).save(variation)
828
- }
822
+ await tx.getRepository(MarketplaceProductVariation).save(variation)
829
823
  })
830
824
  )
831
825
  }
@@ -1258,29 +1252,15 @@ export async function bulkConfirmReleaseGoods(
1258
1252
  ): Promise<ReleaseGood[]> {
1259
1253
  let foundReleaseGoods: ReleaseGood[] = await tx.getRepository(ReleaseGood).find({
1260
1254
  where: { name: In(releaseGoodsNo), status: ORDER_STATUS.PENDING },
1261
- relations: [
1262
- 'domain',
1263
- 'bizplace',
1264
- 'bizplace.domain',
1265
- 'bizplace.company',
1266
- 'bizplace.company.domain',
1267
- 'orderProducts',
1268
- 'orderProducts.product',
1269
- 'orderInventories',
1270
- 'orderInventories.product',
1271
- 'orderVass'
1272
- ]
1255
+ relations: ['bizplace']
1273
1256
  })
1274
1257
 
1275
1258
  if (!foundReleaseGoods.length) throw new Error(`release good order doesn't exists.`)
1276
1259
  let customerBizplace: Bizplace = foundReleaseGoods[0].bizplace
1277
1260
 
1278
- let foundOrderInventories: OrderInventory[] = foundReleaseGoods
1279
- .map((releaseGood: ReleaseGood) => releaseGood.orderInventories)
1280
- .reduce((orderInventories, currOIs) => {
1281
- orderInventories.push(...currOIs)
1282
- return orderInventories
1283
- }, [])
1261
+ let foundOrderInventories: OrderInventory[] = await tx.getRepository(OrderInventory).find({
1262
+ where: { domain, releaseGood: In(foundReleaseGoods.map((rg: ReleaseGood) => rg.id)) }
1263
+ })
1284
1264
 
1285
1265
  await tx
1286
1266
  .getRepository(ReleaseGood)
@@ -1313,7 +1293,7 @@ export async function bulkConfirmReleaseGoods(
1313
1293
  // send notification to Office Admin Users
1314
1294
  if (users?.length) {
1315
1295
  const receivers: any[] = users.map(user => user.id)
1316
- const msg = {
1296
+ const message = {
1317
1297
  title: `New Release Order from ${customerBizplace.name}`,
1318
1298
  body: `New incoming bulk release orders are pending for receiving`,
1319
1299
  url: context.header.referer,
@@ -1321,18 +1301,21 @@ export async function bulkConfirmReleaseGoods(
1321
1301
  }
1322
1302
  await sendNotification({
1323
1303
  receivers,
1324
- message: { ...msg }
1304
+ message
1325
1305
  })
1326
1306
  }
1327
1307
  }
1328
1308
 
1329
- return foundReleaseGoods.map((releaseGood: ReleaseGood) => {
1330
- return {
1331
- ...releaseGood,
1332
- status: ORDER_STATUS.PENDING_RECEIVE,
1333
- updater: user
1334
- }
1335
- })
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
+ )
1336
1319
  }
1337
1320
 
1338
1321
  function extractRawReleaseGoods(rawReleaseGoods): Partial<ReleaseGood[]> {
@@ -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 {
@@ -371,13 +366,9 @@ export class ReleaseGoodQuery {
371
366
  const PROD_ALIAS = 'PROD'
372
367
  const GAN_ALIAS = 'GAN'
373
368
  const conditions = filters
374
- let {
375
- batchId = null,
376
- containerNo = null,
377
- product = [],
378
- packingType = null,
379
- inventory = []
380
- } = getConditionValues(conditions)
369
+ let { batchId = null, containerNo = null, product = [], packingType = null, inventory = [] } = getConditionValues(
370
+ conditions
371
+ )
381
372
 
382
373
  const SELECT: string = `
383
374
  SELECT
@@ -798,7 +789,9 @@ function _extractData(rawData, validatedData) {
798
789
  })
799
790
  }
800
791
 
801
- function getConditionValues(conditions: Filter[]): {
792
+ function getConditionValues(
793
+ conditions: Filter[]
794
+ ): {
802
795
  batchId?: string
803
796
  containerNo?: string
804
797
  product?: string[]
@@ -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,10 +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 { TransferOrderMutation } from 'server'
10
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
11
- import { EntityManager, In } from 'typeorm'
12
+
12
13
  import { NewOrderInventory, NewReturnOrder, OrderInventory, OrderVas, ReturnOrderPatch } from '../'
13
14
  import { ATTACHMENT_TYPE, ORDER_INVENTORY_STATUS, ORDER_STATUS, ORDER_VAS_STATUS } from '../../constants'
14
15
  import { OrderNoGenerator } from '../../utils'