@things-factory/sales-base 8.0.0-beta.1 → 8.0.0-beta.4

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 (177) hide show
  1. package/package.json +13 -13
  2. package/server/constants/attachment-type.ts +0 -9
  3. package/server/constants/index.ts +0 -7
  4. package/server/constants/load-type.ts +0 -4
  5. package/server/constants/order.ts +0 -203
  6. package/server/constants/product-group-type.ts +0 -4
  7. package/server/constants/release-good.ts +0 -9
  8. package/server/constants/transfer-order-type.ts +0 -6
  9. package/server/constants/validation-error-code.ts +0 -3
  10. package/server/constants/vas-target-type.ts +0 -25
  11. package/server/controllers/ecommerce/ecommerce-controller.ts +0 -122
  12. package/server/controllers/ecommerce/index.ts +0 -2
  13. package/server/controllers/ecommerce/sellercraft-controller.ts +0 -182
  14. package/server/controllers/index.ts +0 -2
  15. package/server/controllers/order-controller.ts +0 -296
  16. package/server/errors/index.ts +0 -1
  17. package/server/errors/validation-error.ts +0 -25
  18. package/server/index.ts +0 -5
  19. package/server/migrations/index.ts +0 -9
  20. package/server/service/arrival-notice/arrival-notice-mutation.ts +0 -1152
  21. package/server/service/arrival-notice/arrival-notice-query.ts +0 -549
  22. package/server/service/arrival-notice/arrival-notice-types.ts +0 -310
  23. package/server/service/arrival-notice/arrival-notice.ts +0 -202
  24. package/server/service/arrival-notice/index.ts +0 -9
  25. package/server/service/claim/claim-mutation.ts +0 -308
  26. package/server/service/claim/claim-query.ts +0 -122
  27. package/server/service/claim/claim-types.ts +0 -130
  28. package/server/service/claim/claim.ts +0 -140
  29. package/server/service/claim/index.ts +0 -9
  30. package/server/service/claim-detail/claim-detail-mutation.ts +0 -102
  31. package/server/service/claim-detail/claim-detail-query.ts +0 -55
  32. package/server/service/claim-detail/claim-detail-types.ts +0 -47
  33. package/server/service/claim-detail/claim-detail.ts +0 -69
  34. package/server/service/claim-detail/index.ts +0 -9
  35. package/server/service/claim-order/claim-order-mutation.ts +0 -101
  36. package/server/service/claim-order/claim-order-query.ts +0 -47
  37. package/server/service/claim-order/claim-order-types.ts +0 -35
  38. package/server/service/claim-order/claim-order.ts +0 -81
  39. package/server/service/claim-order/index.ts +0 -9
  40. package/server/service/collection-order/collection-order-mutation.ts +0 -245
  41. package/server/service/collection-order/collection-order-query.ts +0 -97
  42. package/server/service/collection-order/collection-order-types.ts +0 -165
  43. package/server/service/collection-order/collection-order.ts +0 -135
  44. package/server/service/collection-order/index.ts +0 -9
  45. package/server/service/delivery-order/delivery-order-mutation.ts +0 -967
  46. package/server/service/delivery-order/delivery-order-query.ts +0 -631
  47. package/server/service/delivery-order/delivery-order-types.ts +0 -268
  48. package/server/service/delivery-order/delivery-order.ts +0 -258
  49. package/server/service/delivery-order/index.ts +0 -9
  50. package/server/service/draft-release-good/draft-release-good-mutation.ts +0 -765
  51. package/server/service/draft-release-good/draft-release-good-query.ts +0 -354
  52. package/server/service/draft-release-good/draft-release-good-type.ts +0 -261
  53. package/server/service/draft-release-good/draft-release-good.ts +0 -284
  54. package/server/service/draft-release-good/index.ts +0 -9
  55. package/server/service/goods-receival-note/goods-receival-note-mutation.ts +0 -129
  56. package/server/service/goods-receival-note/goods-receival-note-query.ts +0 -280
  57. package/server/service/goods-receival-note/goods-receival-note-types.ts +0 -105
  58. package/server/service/goods-receival-note/goods-receival-note.ts +0 -127
  59. package/server/service/goods-receival-note/index.ts +0 -9
  60. package/server/service/index.ts +0 -238
  61. package/server/service/inventory-check/index.ts +0 -9
  62. package/server/service/inventory-check/inventory-check-mutation.ts +0 -149
  63. package/server/service/inventory-check/inventory-check-query.ts +0 -48
  64. package/server/service/inventory-check/inventory-check-types.ts +0 -48
  65. package/server/service/inventory-check/inventory-check.ts +0 -90
  66. package/server/service/invoice/index.ts +0 -9
  67. package/server/service/invoice/invoice-mutation.ts +0 -95
  68. package/server/service/invoice/invoice-query.ts +0 -53
  69. package/server/service/invoice/invoice-types.ts +0 -279
  70. package/server/service/invoice/invoice.ts +0 -230
  71. package/server/service/invoice-product/index.ts +0 -9
  72. package/server/service/invoice-product/invoice-product-mutation.ts +0 -54
  73. package/server/service/invoice-product/invoice-product-query.ts +0 -54
  74. package/server/service/invoice-product/invoice-product-types.ts +0 -84
  75. package/server/service/invoice-product/invoice-product.ts +0 -92
  76. package/server/service/job-sheet/index.ts +0 -9
  77. package/server/service/job-sheet/job-sheet-mutation.ts +0 -92
  78. package/server/service/job-sheet/job-sheet-query.ts +0 -112
  79. package/server/service/job-sheet/job-sheet-types.ts +0 -78
  80. package/server/service/job-sheet/job-sheet.ts +0 -102
  81. package/server/service/manifest/index.ts +0 -6
  82. package/server/service/manifest/manifest-mutation.ts +0 -190
  83. package/server/service/manifest/manifest-query.ts +0 -149
  84. package/server/service/manifest/manifest-type.ts +0 -84
  85. package/server/service/manifest/manifest.ts +0 -114
  86. package/server/service/order-inventory/index.ts +0 -9
  87. package/server/service/order-inventory/order-inventory-mutation.ts +0 -54
  88. package/server/service/order-inventory/order-inventory-query.ts +0 -722
  89. package/server/service/order-inventory/order-inventory-types.ts +0 -238
  90. package/server/service/order-inventory/order-inventory.ts +0 -401
  91. package/server/service/order-product/index.ts +0 -9
  92. package/server/service/order-product/order-product-mutation.ts +0 -48
  93. package/server/service/order-product/order-product-query.ts +0 -89
  94. package/server/service/order-product/order-product-types.ts +0 -335
  95. package/server/service/order-product/order-product.ts +0 -362
  96. package/server/service/order-tote/index.ts +0 -9
  97. package/server/service/order-tote/order-tote-mutation.ts +0 -31
  98. package/server/service/order-tote/order-tote-query.ts +0 -112
  99. package/server/service/order-tote/order-tote-types.ts +0 -47
  100. package/server/service/order-tote/order-tote.ts +0 -73
  101. package/server/service/order-tote-item/index.ts +0 -9
  102. package/server/service/order-tote-item/order-tote-item-mutation.ts +0 -31
  103. package/server/service/order-tote-item/order-tote-item-query.ts +0 -82
  104. package/server/service/order-tote-item/order-tote-item-types.ts +0 -56
  105. package/server/service/order-tote-item/order-tote-item.ts +0 -72
  106. package/server/service/order-tote-seal/index.ts +0 -9
  107. package/server/service/order-tote-seal/order-tote-seal-mutation.ts +0 -31
  108. package/server/service/order-tote-seal/order-tote-seal-query.ts +0 -59
  109. package/server/service/order-tote-seal/order-tote-seal-types.ts +0 -41
  110. package/server/service/order-tote-seal/order-tote-seal.ts +0 -46
  111. package/server/service/order-vas/index.ts +0 -9
  112. package/server/service/order-vas/order-vas-mutation.ts +0 -20
  113. package/server/service/order-vas/order-vas-query.ts +0 -72
  114. package/server/service/order-vas/order-vas-types.ts +0 -159
  115. package/server/service/order-vas/order-vas.ts +0 -207
  116. package/server/service/others/index.ts +0 -5
  117. package/server/service/others/other-query.ts +0 -563
  118. package/server/service/others/other-types.ts +0 -115
  119. package/server/service/purchase-order/index.ts +0 -9
  120. package/server/service/purchase-order/purchase-order-mutation.ts +0 -458
  121. package/server/service/purchase-order/purchase-order-query.ts +0 -90
  122. package/server/service/purchase-order/purchase-order-types.ts +0 -154
  123. package/server/service/purchase-order/purchase-order.ts +0 -172
  124. package/server/service/purchase-order-other-charge/index.ts +0 -9
  125. package/server/service/purchase-order-other-charge/purchase-order-other-charge-mutation.ts +0 -31
  126. package/server/service/purchase-order-other-charge/purchase-order-other-charge-query.ts +0 -52
  127. package/server/service/purchase-order-other-charge/purchase-order-other-charge-types.ts +0 -44
  128. package/server/service/purchase-order-other-charge/purchase-order-other-charge.ts +0 -68
  129. package/server/service/release-good/index.ts +0 -9
  130. package/server/service/release-good/release-good-mutation.ts +0 -1686
  131. package/server/service/release-good/release-good-query.ts +0 -980
  132. package/server/service/release-good/release-good-types.ts +0 -662
  133. package/server/service/release-good/release-good.ts +0 -490
  134. package/server/service/retail-replenishment-order/index.ts +0 -9
  135. package/server/service/retail-replenishment-order/retail-replenishment-order-mutation.ts +0 -382
  136. package/server/service/retail-replenishment-order/retail-replenishment-order-query.ts +0 -54
  137. package/server/service/retail-replenishment-order/retail-replenishment-order-types.ts +0 -101
  138. package/server/service/retail-replenishment-order/retail-replenishment-order.ts +0 -115
  139. package/server/service/return-order/index.ts +0 -9
  140. package/server/service/return-order/return-order-mutation.ts +0 -516
  141. package/server/service/return-order/return-order-query.ts +0 -226
  142. package/server/service/return-order/return-order-types.ts +0 -196
  143. package/server/service/return-order/return-order.ts +0 -127
  144. package/server/service/reverse-kitting-order/index.ts +0 -9
  145. package/server/service/reverse-kitting-order/reverse-kitting-order-mutation.ts +0 -500
  146. package/server/service/reverse-kitting-order/reverse-kitting-order-query.ts +0 -197
  147. package/server/service/reverse-kitting-order/reverse-kitting-order-type.ts +0 -173
  148. package/server/service/reverse-kitting-order/reverse-kitting-order.ts +0 -121
  149. package/server/service/reverse-kitting-order-inventory/index.ts +0 -9
  150. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.ts +0 -129
  151. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-query.ts +0 -52
  152. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.ts +0 -95
  153. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +0 -143
  154. package/server/service/shipping-order/index.ts +0 -9
  155. package/server/service/shipping-order/shipping-order-mutation.ts +0 -61
  156. package/server/service/shipping-order/shipping-order-query.ts +0 -61
  157. package/server/service/shipping-order/shipping-order-types.ts +0 -89
  158. package/server/service/shipping-order/shipping-order.ts +0 -129
  159. package/server/service/transfer-order/index.ts +0 -9
  160. package/server/service/transfer-order/transfer-order-mutation.ts +0 -309
  161. package/server/service/transfer-order/transfer-order-query.ts +0 -66
  162. package/server/service/transfer-order/transfer-order-types.ts +0 -97
  163. package/server/service/transfer-order/transfer-order.ts +0 -117
  164. package/server/service/vas/index.ts +0 -9
  165. package/server/service/vas/vas-mutation.ts +0 -106
  166. package/server/service/vas/vas-query.ts +0 -60
  167. package/server/service/vas/vas-types.ts +0 -71
  168. package/server/service/vas/vas.ts +0 -77
  169. package/server/service/vas-order/index.ts +0 -9
  170. package/server/service/vas-order/vas-order-mutation.ts +0 -259
  171. package/server/service/vas-order/vas-order-query.ts +0 -119
  172. package/server/service/vas-order/vas-order-types.ts +0 -49
  173. package/server/service/vas-order/vas-order.ts +0 -81
  174. package/server/utils/datetime-util.ts +0 -54
  175. package/server/utils/index.ts +0 -3
  176. package/server/utils/inventory-util.ts +0 -1155
  177. package/server/utils/order-no-generator.ts +0 -146
@@ -1,563 +0,0 @@
1
- import orderBy from 'lodash/orderBy'
2
- import { Arg, Args, Ctx, Directive, Query, Resolver } from 'type-graphql'
3
- import { EntityManager } from 'typeorm'
4
-
5
- import { User } from '@things-factory/auth-base'
6
- import { Bizplace, getPermittedBizplaces } from '@things-factory/biz-base'
7
- import { Product, ProductDetail } from '@things-factory/product-base'
8
- import { PartnerSetting, Setting } from '@things-factory/setting-base'
9
- import { Domain, ListParam } from '@things-factory/shell'
10
-
11
- import {
12
- InventoryProductGroup,
13
- InventoryProductGroupList,
14
- NewOrderInventory,
15
- NewOrderProduct,
16
- OrderInventory,
17
- OrderProduct
18
- } from '../'
19
- import { InventoryUtil } from '../../utils'
20
-
21
- @Resolver()
22
- export class OtherQuery {
23
- @Directive('@privilege(category: "inventory", privilege: "query", domainOwnerGranted: true)')
24
- @Directive('@transaction')
25
- @Query(returns => InventoryProductGroupList)
26
- async allBizplaceProductInventory(
27
- @Ctx() context: ResolverContext,
28
- @Args(type => ListParam) params: ListParam
29
- ): Promise<InventoryProductGroupList> {
30
- const { domain, user, tx, bizplace } = context.state
31
-
32
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
33
-
34
- let bizplaceId: any = params.filters.find(filter => filter.name === 'bizplace_id').value
35
- let foundPermittedBizplace: Bizplace
36
- let companyBizplace: Bizplace
37
-
38
- if (bizplaceId) {
39
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == bizplaceId)
40
-
41
- if (foundPermittedBizplace) {
42
- if (!foundPermittedBizplace.company?.id) {
43
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
44
- where: { id: foundPermittedBizplace.id },
45
- relations: ['company', 'company.domain']
46
- })
47
- }
48
- const companyDomain: Domain = foundPermittedBizplace.company.domain
49
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
50
- }
51
- }
52
-
53
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
54
- if (bizplace) bizplaces.push(bizplace)
55
-
56
- const { items, total } = await InventoryUtil.bizplaceProductInventory(bizplaces, params, context, tx)
57
-
58
- return { items, total }
59
- }
60
-
61
- @Directive('@privilege(category: "inventory", privilege: "query", domainOwnerGranted: true)')
62
- @Directive('@transaction')
63
- @Query(returns => InventoryProductGroupList)
64
- async inventoryProductGroup(
65
- @Ctx() context: ResolverContext,
66
- @Args(type => ListParam) params: ListParam
67
- ): Promise<InventoryProductGroupList> {
68
- const { domain, user, tx, bizplace } = context.state
69
-
70
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
71
-
72
- let bizplaceId: any = params.filters.find(filter => filter.name === 'bizplace_id').value
73
- let foundPermittedBizplace: Bizplace
74
- let companyBizplace: Bizplace
75
-
76
- if (bizplaceId) {
77
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == bizplaceId)
78
-
79
- if (foundPermittedBizplace) {
80
- if (!foundPermittedBizplace.company?.id) {
81
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
82
- where: { id: foundPermittedBizplace.id },
83
- relations: ['company', 'company.domain']
84
- })
85
- }
86
- const companyDomain: Domain = foundPermittedBizplace.company.domain
87
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: { id: companyDomain.id } } })
88
- }
89
- }
90
-
91
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
92
- if (bizplace) bizplaces.push(bizplace)
93
-
94
- const { items, total } = await InventoryUtil.bizplaceInventoryProductGroup(bizplaces, params, context, tx)
95
-
96
- return { items, total }
97
- }
98
-
99
- @Directive('@transaction')
100
- @Query(returns => InventoryProductGroupList)
101
- async inventoryProductGroupOpenAPI(
102
- @Ctx() context: ResolverContext,
103
- @Args(type => ListParam) params: ListParam
104
- ): Promise<InventoryProductGroupList> {
105
- const { domain, user, tx, bizplace } = context.state
106
-
107
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
108
-
109
- let bizplaceId: any = params.filters.find(filter => filter.name === 'bizplace_id').value
110
- let foundPermittedBizplace: Bizplace
111
- let companyBizplace: Bizplace
112
-
113
- if (bizplaceId) {
114
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == bizplaceId)
115
-
116
- if (foundPermittedBizplace) {
117
- if (!foundPermittedBizplace.company?.id) {
118
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
119
- where: { id: foundPermittedBizplace.id },
120
- relations: ['company', 'company.domain']
121
- })
122
- }
123
- const companyDomain: Domain = foundPermittedBizplace.company.domain
124
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: { id: companyDomain.id } } })
125
- }
126
- }
127
-
128
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
129
- if (bizplace) bizplaces.push(bizplace)
130
-
131
- const { items, total } = await InventoryUtil.inventoryProductGroupOpenAPI(bizplaces, params, context, tx)
132
-
133
- return { items, total }
134
- }
135
-
136
- @Directive('@privilege(category: "order_customer", privilege: "query", domainOwnerGranted: true)')
137
- @Directive('@transaction')
138
- @Query(returns => [OrderInventory])
139
- async bulkUploadValidateWarehousePartnersProductsQuantity(
140
- @Ctx() context: ResolverContext,
141
- @Arg('partnerBizplaceId') partnerBizplaceId: string,
142
- @Arg('orderInventories', type => [NewOrderInventory], { nullable: true }) orderInventories?: NewOrderInventory[]
143
- ): Promise<OrderInventory[]> {
144
- const { domain, user, tx, bizplace } = context.state
145
-
146
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
147
- let foundPermittedBizplace: Bizplace
148
- let companyBizplace: Bizplace
149
-
150
- const partnerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
151
- where: {
152
- id: partnerBizplaceId
153
- },
154
- relations: ['company', 'company.domain']
155
- })
156
-
157
- if (partnerBizplaceId) {
158
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
159
-
160
- if (foundPermittedBizplace) {
161
- if (!foundPermittedBizplace.company?.id) {
162
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
163
- where: { id: foundPermittedBizplace.id },
164
- relations: ['company', 'company.domain']
165
- })
166
- }
167
- const companyDomain: Domain = foundPermittedBizplace.company.domain
168
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: { id: companyDomain.id } } })
169
- }
170
- }
171
-
172
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
173
- if (bizplace) bizplaces.push(bizplace)
174
-
175
- let newOrderInventories: any[] = []
176
-
177
- for (var i = 0; i < orderInventories.length; i++) {
178
- const orderInventory: any = orderInventories[i]
179
-
180
- let filters: any[] = [
181
- {
182
- name: 'productName',
183
- operator: 'eq',
184
- value: orderInventory.productSKU
185
- }
186
- ]
187
-
188
- if (orderInventory?.packingType != null) {
189
- filters.push({
190
- name: 'packingType',
191
- operator: 'eq',
192
- value: orderInventory.packingType
193
- })
194
- }
195
-
196
- const params: any = {
197
- filters: [...filters]
198
- }
199
-
200
- const { items, total } = await InventoryUtil.bizplaceInventoryProductGroup(bizplaces, params, context, tx)
201
-
202
- // Filter to find for item with enough remain qty
203
- const availableItems = items.filter(item => item.remainQty >= orderInventory.releaseQty)
204
- let availableItem
205
-
206
- if (availableItems.length > 0) {
207
- availableItem = availableItems[0]
208
- }
209
-
210
- let packageUomValue = availableItem ? availableItem.remainUomValue / availableItem.remainQty : null
211
- const newOrderInventory: any = {
212
- product: availableItem
213
- ? {
214
- id: availableItem.productId,
215
- sku: availableItem.productSKU,
216
- name: availableItem.productName
217
- }
218
- : { id: null },
219
- inventory: availableItem
220
- ? {
221
- ...availableItem,
222
- remainQty: availableItem ? availableItem.remainQty : null,
223
- remainUomValue: availableItem ? availableItem.remainUomValue : null,
224
- remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : ''
225
- }
226
- : null,
227
- productId: availableItem ? availableItem.productId : null,
228
- productSKU: availableItem ? availableItem.productSKU : orderInventory.productSKU,
229
- productName: availableItem ? availableItem.productName : null,
230
- uom: availableItem ? availableItem.uom : null,
231
- remainQty: availableItem ? availableItem.remainQty : null,
232
- remainUomValue: availableItem ? availableItem.remainUomValue : null,
233
- remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : '',
234
- batchId: availableItem ? availableItem.batchId : null,
235
- batchIdRef: availableItem ? availableItem.batchIdRef : null,
236
- packingType: availableItem ? availableItem.packingType : orderInventory.packingType,
237
- packingSize: availableItem ? availableItem.packingSize : 1,
238
- releaseQty: orderInventory.releaseQty
239
- ? Number.isInteger(orderInventory.releaseQty)
240
- ? orderInventory.releaseQty
241
- : null
242
- : null,
243
- releaseUomValue: availableItem
244
- ? Number.isInteger(orderInventory.releaseQty)
245
- ? parseFloat((orderInventory.releaseQty * packageUomValue).toFixed(2))
246
- : null
247
- : null,
248
- groupType: availableItem ? availableItem.groupType : null,
249
- isError: !availableItem ? true : false
250
- }
251
-
252
- newOrderInventories.push(newOrderInventory)
253
-
254
- // end loop
255
- }
256
-
257
- try {
258
- await InventoryUtil.validateWarehousePartnersProductsQuantity(
259
- domain,
260
- partnerBizplace,
261
- newOrderInventories,
262
- context,
263
- tx
264
- )
265
- } catch (e) {
266
- const errorData = JSON.parse(e.detail.data)
267
-
268
- errorData.forEach(dt => {
269
- let idx = newOrderInventories.findIndex(
270
- x =>
271
- x.product?.id && x.product.id == dt.productId && x.batchId == dt.batchId && x.packingType == dt.packingType
272
- )
273
-
274
- if (idx >= 0) {
275
- newOrderInventories[idx].remainQty = dt.availableQty
276
- newOrderInventories[idx].remainUomValue = dt.availableUomValue
277
- newOrderInventories[idx].isError =
278
- dt.availableQty == null
279
- ? newOrderInventories[idx].releaseQty > 0
280
- : newOrderInventories[idx].releaseQty > dt.availableQty
281
- newOrderInventories[idx].remainUomValueWithUom =
282
- dt.availableUomValue == null ? '' : `${dt.availableUomValue} ${dt.uom}`
283
- if (newOrderInventories[idx].inventory != null) {
284
- newOrderInventories[idx].inventory.remainQty = dt.availableQty
285
- newOrderInventories[idx].inventory.remainUomValue = dt.availableUomValue
286
- newOrderInventories[idx].inventory.remainUomValueWithUom = `${dt.availableUomValue} ${dt.uom}` || ''
287
- }
288
- }
289
- })
290
- }
291
-
292
- return orderBy(newOrderInventories, ['isError'], ['desc'])
293
- }
294
-
295
- @Directive('@privilege(category: "order_customer", privilege: "query", domainOwnerGranted: true)')
296
- @Directive('@transaction')
297
- @Query(returns => [InventoryProductGroup])
298
- async bulkUploadValidateOrderProducts(
299
- @Ctx() context: ResolverContext,
300
- @Arg('partnerBizplaceId') partnerBizplaceId: string,
301
- @Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
302
- ): Promise<OrderProduct[]> {
303
- const { domain, user, tx, bizplace } = context.state
304
-
305
- const productDetailRepo = tx.getRepository(ProductDetail)
306
-
307
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
308
- let foundPermittedBizplace: Bizplace
309
- let companyBizplace: Bizplace
310
-
311
- if (partnerBizplaceId) {
312
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
313
-
314
- if (foundPermittedBizplace) {
315
- if (!foundPermittedBizplace.company?.id) {
316
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
317
- where: { id: foundPermittedBizplace.id },
318
- relations: ['domain', 'company', 'company.domain']
319
- })
320
- }
321
- const companyDomain: Domain = foundPermittedBizplace.company.domain
322
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: { id: companyDomain.id } } })
323
- }
324
- }
325
-
326
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
327
- if (bizplace) bizplaces.push(bizplace)
328
-
329
- let strictProduct: any = false
330
-
331
- const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
332
- where: { domain: { id: domain.id }, category: 'id-rule', name: 'strict-product-selection' }
333
- })
334
-
335
- if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
336
-
337
- const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
338
- where: {
339
- setting: { id: strictProductSelectionSetting.id },
340
- domain: { id: domain.id },
341
- partnerDomain: { id: foundPermittedBizplace?.domain?.id }
342
- }
343
- })
344
-
345
- if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
346
-
347
- let newOrderProducts: any[] = []
348
-
349
- for (var i = 0; i < orderProducts.length; i++) {
350
- const orderProduct = orderProducts[i]
351
- const productSKU: string = orderProduct.productSKU
352
- const foundProduct: Product = await tx.getRepository(Product).findOne({
353
- where: {
354
- sku: productSKU,
355
- bizplace: { id: companyBizplace.id }
356
- }
357
- })
358
-
359
- let newOrderProduct: any
360
-
361
- if (foundProduct) {
362
- let productDetail: ProductDetail
363
- const hasConditions: boolean = Boolean(
364
- (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
365
- (orderProduct?.uom && orderProduct?.uom.trim() != '')
366
- )
367
- let productDetailCondition: any = { product: foundProduct }
368
-
369
- if (hasConditions) {
370
- if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
371
- productDetailCondition.packingType = orderProduct.packingType.trim()
372
-
373
- if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
374
- } else {
375
- productDetailCondition.isDefault = true
376
- }
377
-
378
- productDetail = await productDetailRepo.findOne({
379
- where: productDetailCondition
380
- })
381
-
382
- const uomValue: number =
383
- strictProduct == true
384
- ? productDetail?.uomValue
385
- ? productDetail.uomValue
386
- : null
387
- : orderProduct?.uomValue
388
- ? orderProduct.uomValue
389
- : productDetail.uomValue
390
-
391
- newOrderProduct = {
392
- ...orderProduct,
393
- packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
394
- packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
395
- uom: productDetail?.uom ? productDetail.uom : null,
396
- uomValue: uomValue,
397
- productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
398
- productBrand: foundProduct?.brand ? foundProduct.brand : null,
399
- isError: productDetail ? false : true,
400
- product: {
401
- id: foundProduct.id,
402
- name: foundProduct.name,
403
- sku: foundProduct.sku,
404
- type: foundProduct.type,
405
- brand: foundProduct.brand,
406
- primaryUnit: productDetail?.uom ? productDetail.uom : null,
407
- primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
408
- },
409
- totalUomValue:
410
- orderProduct.packQty > 0
411
- ? uomValue
412
- ? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
413
- : null
414
- : null
415
- }
416
- } else {
417
- newOrderProduct = {
418
- ...orderProduct,
419
- productName: orderProduct.productSKU,
420
- isError: true
421
- }
422
- }
423
-
424
- newOrderProducts.push(newOrderProduct)
425
- }
426
-
427
- return newOrderProducts
428
- }
429
- @Directive('@privilege(category: "order_customer", privilege: "query", domainOwnerGranted: true)')
430
- @Directive('@transaction')
431
- @Query(returns => [InventoryProductGroup])
432
- async bulkUploadValidatePoOrderProducts(
433
- @Ctx() context: ResolverContext,
434
- @Arg('partnerBizplaceId') partnerBizplaceId: string,
435
- @Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
436
- ): Promise<OrderProduct[]> {
437
- const { domain, user, tx, bizplace } = context.state
438
-
439
- const productDetailRepo = tx.getRepository(ProductDetail)
440
-
441
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
442
- let foundPermittedBizplace: Bizplace
443
- let companyBizplace: Bizplace
444
-
445
- if (partnerBizplaceId) {
446
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
447
-
448
- if (foundPermittedBizplace) {
449
- if (!foundPermittedBizplace.company?.id) {
450
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
451
- where: { id: foundPermittedBizplace.id },
452
- relations: ['domain', 'company', 'company.domain']
453
- })
454
- }
455
- const companyDomain: Domain = foundPermittedBizplace.company.domain
456
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: { id: companyDomain.id } } })
457
- }
458
- }
459
-
460
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
461
- if (bizplace) bizplaces.push(bizplace)
462
-
463
- let strictProduct: any = false
464
-
465
- const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
466
- where: { domain: { id: domain.id }, category: 'id-rule', name: 'strict-product-selection' }
467
- })
468
-
469
- if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
470
-
471
- const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
472
- where: {
473
- setting: { id: strictProductSelectionSetting.id },
474
- domain: { id: domain.id },
475
- partnerDomain: { id: foundPermittedBizplace?.domain?.id }
476
- }
477
- })
478
-
479
- if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
480
-
481
- let newOrderProducts: any[] = []
482
-
483
- for (var i = 0; i < orderProducts.length; i++) {
484
- const orderProduct = orderProducts[i]
485
- const productSKU: string = orderProduct.productSKU
486
- const foundProduct: Product = await tx.getRepository(Product).findOne({
487
- where: {
488
- sku: productSKU,
489
- bizplace: { id: companyBizplace.id }
490
- }
491
- })
492
-
493
- let newOrderProduct: any
494
-
495
- if (foundProduct) {
496
- let productDetail: ProductDetail
497
- const hasConditions: boolean = Boolean(
498
- (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
499
- (orderProduct?.uom && orderProduct?.uom.trim() != '')
500
- )
501
- let productDetailCondition: any = { product: foundProduct }
502
-
503
- if (hasConditions) {
504
- if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
505
- productDetailCondition.packingType = orderProduct.packingType.trim()
506
-
507
- if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
508
- } else {
509
- productDetailCondition.isDefault = true
510
- }
511
-
512
- productDetail = await productDetailRepo.findOne({
513
- where: productDetailCondition
514
- })
515
-
516
- const uomValue: number =
517
- strictProduct == true
518
- ? productDetail?.uomValue
519
- ? productDetail.uomValue
520
- : null
521
- : orderProduct?.uomValue
522
- ? orderProduct.uomValue
523
- : productDetail.uomValue
524
-
525
- newOrderProduct = {
526
- ...orderProduct,
527
- packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
528
- packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
529
- uom: productDetail?.uom ? productDetail.uom : null,
530
- uomValue: uomValue,
531
- productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
532
- productBrand: foundProduct?.brand ? foundProduct.brand : null,
533
- isError: productDetail ? false : true,
534
- product: {
535
- id: foundProduct.id,
536
- name: foundProduct.name,
537
- sku: foundProduct.sku,
538
- type: foundProduct.type,
539
- brand: foundProduct.brand,
540
- primaryUnit: productDetail?.uom ? productDetail.uom : null,
541
- primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
542
- },
543
- totalUomValue:
544
- orderProduct.packQty > 0
545
- ? uomValue
546
- ? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
547
- : null
548
- : null
549
- }
550
- } else {
551
- newOrderProduct = {
552
- ...orderProduct,
553
- productName: orderProduct.productSKU,
554
- isError: true
555
- }
556
- }
557
-
558
- newOrderProducts.push(newOrderProduct)
559
- }
560
-
561
- return newOrderProducts
562
- }
563
- }
@@ -1,115 +0,0 @@
1
- import { Field, Float, Int, ObjectType } from 'type-graphql'
2
-
3
- import { Product } from '@things-factory/product-base'
4
- import { ScalarDate } from '@things-factory/shell'
5
-
6
- @ObjectType()
7
- export class InventoryProductGroupList {
8
- @Field(type => [InventoryProductGroup], { nullable: true })
9
- items: InventoryProductGroup[]
10
-
11
- @Field(type => Int, { nullable: true })
12
- total: number
13
- }
14
-
15
- @ObjectType()
16
- export class InventoryProductGroup {
17
- @Field({ nullable: true })
18
- id: string
19
-
20
- @Field({ nullable: true })
21
- productId: string
22
-
23
- @Field({ nullable: true })
24
- batchId: string
25
-
26
- @Field({ nullable: true })
27
- batchIdRef: string
28
-
29
- @Field({ nullable: true })
30
- productSKU: string
31
-
32
- @Field({ nullable: true })
33
- productName: string
34
-
35
- @Field({ nullable: true })
36
- productBrand: string
37
-
38
- @Field({ nullable: true })
39
- packingType: string
40
-
41
- @Field(type => Float, { nullable: true })
42
- packingSize: number
43
-
44
- @Field({ nullable: true })
45
- palletId: string
46
-
47
- @Field({ nullable: true })
48
- createdAt: Date
49
-
50
- @Field(type => Float, { nullable: true })
51
- packQty: number
52
-
53
- @Field(type => Int, { nullable: true })
54
- totalQty: number
55
-
56
- @Field(type => Int, { nullable: true })
57
- totalLockedQty: number
58
-
59
- @Field(type => Int, { nullable: true })
60
- totalLockedUomValue: number
61
-
62
- @Field(type => Int, { nullable: true })
63
- palletQty: number
64
-
65
- @Field(type => Float, { nullable: true })
66
- remainQty: number
67
-
68
- @Field(type => Float, { nullable: true })
69
- remainWeight: number
70
-
71
- @Field(type => Float, { nullable: true })
72
- remainUomValue: number
73
-
74
- @Field({ nullable: true })
75
- remainUomValueWithUom: string
76
-
77
- @Field({ nullable: true })
78
- uom: string
79
-
80
- @Field(type => Float, { nullable: true })
81
- uomValue: number
82
-
83
- @Field({ nullable: true })
84
- totalUomValue: String
85
-
86
- @Field({ nullable: true })
87
- groupType: string
88
-
89
- @Field(type => ScalarDate, { nullable: true })
90
- manufactureDate: Date
91
-
92
- @Field(type => Float, { nullable: true })
93
- unitPrice: number
94
-
95
- @Field({ nullable: true })
96
- remark: string
97
-
98
- @Field(type => Float, { nullable: true })
99
- discountAmt: number
100
-
101
- @Field(type => Float, { nullable: true })
102
- miscAmt: number
103
-
104
- @Field(type => Float, { nullable: true })
105
- taxRate: number
106
-
107
- @Field(type => Float, { nullable: true })
108
- isError: Boolean
109
-
110
- @Field(type => Product, { nullable: true })
111
- product: Product
112
-
113
- @Field(type => ScalarDate, { nullable: true })
114
- expirationDate: Date
115
- }
@@ -1,9 +0,0 @@
1
- import { PurchaseOrder } from './purchase-order'
2
- import { PurchaseOrderMutation } from './purchase-order-mutation'
3
- import { PurchaseOrderQuery } from './purchase-order-query'
4
-
5
- export const entities = [PurchaseOrder]
6
- export const resolvers = [PurchaseOrderQuery, PurchaseOrderMutation]
7
-
8
- export * from './purchase-order-mutation'
9
- export * from './purchase-order-query'