@things-factory/sales-base 4.3.323 → 4.3.327

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.
@@ -8,8 +8,8 @@ import {
8
8
  OneToMany,
9
9
  PrimaryGeneratedColumn,
10
10
  RelationId,
11
- UpdateDateColumn
12
- } from 'typeorm'
11
+ UpdateDateColumn
12
+ } from 'typeorm'
13
13
 
14
14
  import { User } from '@things-factory/auth-base'
15
15
  import { Bizplace } from '@things-factory/biz-base'
@@ -69,6 +69,7 @@ import { Replenishment } from '../replenishment/replenishment'
69
69
  @Index('ix_order-inventory_6', (orderInventory: OrderInventory) => [orderInventory.id], {
70
70
  unique: true
71
71
  })
72
+ @Index('ix_order-inventory_7', (orderInventory: OrderInventory) => [orderInventory.arrivalNotice])
72
73
  @ObjectType()
73
74
  export class OrderInventory {
74
75
  @PrimaryGeneratedColumn('uuid')
@@ -136,6 +137,26 @@ export class OrderInventory {
136
137
  @Field({ nullable: true })
137
138
  packingType: string
138
139
 
140
+ @Column({ nullable: true })
141
+ @Field({ nullable: true })
142
+ unloadedAt: Date
143
+
144
+ @Column({ nullable: true })
145
+ @Field({ nullable: true })
146
+ putawayAt: Date
147
+
148
+ @ManyToOne(type => User)
149
+ @Field(type => User, { nullable: true })
150
+ unloadedBy: User
151
+
152
+ @ManyToOne(type => User)
153
+ @Field(type => User, { nullable: true })
154
+ putawayBy: User
155
+
156
+ @Column({ nullable: true })
157
+ @Field({ nullable: true })
158
+ actualPackUomValue: number
159
+
139
160
  @Column('float', { default: 1 })
140
161
  @Field({ nullable: true })
141
162
  packingSize?: number
@@ -62,8 +62,9 @@ import { Replenishment } from '../replenishment/replenishment'
62
62
  { unique: true }
63
63
  )
64
64
  @Index('ix_order-product_4', (orderProduct: OrderProduct) => [orderProduct.draftReleaseGood], { unique: false })
65
+ @Index('ix_order-product_5', (orderProduct: OrderProduct) => [orderProduct.arrivalNotice])
65
66
  @ObjectType()
66
- export class OrderProduct {
67
+ export class OrderProduct {
67
68
  @PrimaryGeneratedColumn('uuid')
68
69
  @Field(type => ID)
69
70
  id: string
@@ -1,34 +1,9 @@
1
- import {
2
- FileUpload,
3
- GraphQLUpload
4
- } from 'graphql-upload'
5
- import {
6
- Arg,
7
- Ctx,
8
- Directive,
9
- Mutation,
10
- Resolver
11
- } from 'type-graphql'
12
- import {
13
- EntityManager,
14
- getConnection,
15
- getRepository,
16
- In,
17
- Not,
18
- Repository
19
- } from 'typeorm'
1
+ import { FileUpload, GraphQLUpload } from 'graphql-upload'
2
+ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
3
+ import { EntityManager, getConnection, getRepository, In, Not, Repository } from 'typeorm'
20
4
 
21
- import {
22
- Attachment,
23
- createAttachments
24
- } from '@things-factory/attachment-base'
25
- import {
26
- Application,
27
- ApplicationType,
28
- Partner,
29
- Role,
30
- User
31
- } from '@things-factory/auth-base'
5
+ import { Attachment, createAttachments } from '@things-factory/attachment-base'
6
+ import { Application, ApplicationType, Partner, Role, User } from '@things-factory/auth-base'
32
7
  import {
33
8
  Bizplace,
34
9
  getCompanyBizplace,
@@ -40,26 +15,14 @@ import {
40
15
  import { GeoCountry } from '@things-factory/geography'
41
16
  import { generateId } from '@things-factory/id-rule-base'
42
17
  import { MarketplaceStore } from '@things-factory/integration-marketplace'
43
- import {
44
- Sellercraft,
45
- SellercraftStatus
46
- } from '@things-factory/integration-sellercraft'
18
+ import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
47
19
  import { MarketplaceOrder } from '@things-factory/marketplace-base'
48
20
  // import { sendNotification } from '@things-factory/notification'
49
- import {
50
- Product,
51
- ProductBundleSetting,
52
- ProductDetail
53
- } from '@things-factory/product-base'
54
- import {
55
- PartnerSetting,
56
- Setting
57
- } from '@things-factory/setting-base'
21
+ import { Product, ProductBundleSetting, ProductDetail } from '@things-factory/product-base'
22
+ import { PartnerSetting, Setting } from '@things-factory/setting-base'
58
23
  import { Domain } from '@things-factory/shell'
59
- import {
60
- Inventory,
61
- ProductDetailStock
62
- } from '@things-factory/warehouse-base'
24
+ import { Inventory, ProductDetailStock } from '@things-factory/warehouse-base'
25
+ import { editVas } from '../vas'
63
26
 
64
27
  // import { NewOrderProduct } from '../order-product/order-product-types'
65
28
  import {
@@ -74,36 +37,23 @@ import {
74
37
  ORDER_VAS_STATUS,
75
38
  PRODUCT_GROUP_TYPE
76
39
  } from '../../constants'
77
- import {
78
- EcommerceController,
79
- PowrupController,
80
- SellercraftController
81
- } from '../../controllers'
40
+ import { EcommerceController, PowrupController, SellercraftController } from '../../controllers'
82
41
  import { ValidationError } from '../../errors'
83
- import {
84
- InventoryUtil,
85
- OrderNoGenerator
86
- } from '../../utils'
42
+ import { InventoryUtil, OrderNoGenerator } from '../../utils'
87
43
  import { ArrivalNotice } from '../arrival-notice/arrival-notice'
88
- import {
89
- confirmArrivalNoticeFunction,
90
- deleteArrivalNotice
91
- } from '../arrival-notice/arrival-notice-mutation'
44
+ import { confirmArrivalNoticeFunction, deleteArrivalNotice } from '../arrival-notice/arrival-notice-mutation'
92
45
  import { OrderInventory } from '../order-inventory/order-inventory'
93
46
  import { OrderPackage } from '../order-package/order-package'
94
47
  import { OrderProduct } from '../order-product/order-product'
95
48
  import { OrderVasItem } from '../order-vas-item/order-vas-item'
96
49
  import { OrderVas } from '../order-vas/order-vas'
97
- import {
98
- NewReleaseGood,
99
- ReleaseGoodPatch,
100
- ShippingOrderInfoPatch
101
- } from '../release-good/release-good-types'
50
+ import { NewReleaseGood, ReleaseGoodPatch, ShippingOrderInfoPatch } from '../release-good/release-good-types'
102
51
  import { ShippingOrder } from '../shipping-order/shipping-order'
103
52
  import { ShippingOrderPatch } from '../shipping-order/shipping-order-types'
104
53
  import { Vas } from '../vas/vas'
105
54
  import { ReleaseGood } from './release-good'
106
55
  import { bulkReleaseGoodsAvailableItemsFunction } from './release-good-query'
56
+ import { OrderVasPatch } from '../order-vas/order-vas-types'
107
57
 
108
58
  @Resolver(ReleaseGood)
109
59
  export class ReleaseGoodMutation {
@@ -254,6 +204,7 @@ export class ReleaseGoodMutation {
254
204
  @Ctx() context: any,
255
205
  @Arg('attachments', type => [GraphQLUpload], { nullable: true }) attachments?: FileUpload[],
256
206
  @Arg('releaseGood', type => NewReleaseGood, { nullable: true }) releaseGood?: NewReleaseGood,
207
+ @Arg('orderVasPatch', type => [OrderVasPatch], { nullable: true }) orderVasPatch?: OrderVasPatch[],
257
208
  @Arg('shippingOrder', type => ShippingOrderPatch, { nullable: true }) shippingOrder?: ShippingOrderPatch,
258
209
  @Arg('shippingOrderInfo', type => ShippingOrderInfoPatch, { nullable: true })
259
210
  shippingOrderInfo?: ShippingOrderInfoPatch
@@ -266,7 +217,8 @@ export class ReleaseGoodMutation {
266
217
  shippingOrderInfo,
267
218
  attachments,
268
219
  context,
269
- tx
220
+ tx,
221
+ orderVasPatch
270
222
  )
271
223
 
272
224
  return createdReleaseGood
@@ -396,7 +348,8 @@ export class ReleaseGoodMutation {
396
348
  shippingOrder,
397
349
  file,
398
350
  context,
399
- tx
351
+ tx,
352
+ null
400
353
  )
401
354
 
402
355
  const confirmedRO: ReleaseGood = await confirmReleaseGood(createdRO.name, context, tx)
@@ -547,7 +500,8 @@ export async function generateReleaseGoodFunction(
547
500
  shippingOrderInfo: any,
548
501
  attachments: FileUpload[],
549
502
  context: any,
550
- tx?: EntityManager
503
+ tx?: EntityManager,
504
+ orderVasPatch?: OrderVasPatch[]
551
505
  ): Promise<ReleaseGood> {
552
506
  try {
553
507
  const { domain, user }: { domain: Domain; user: User } = context.state
@@ -938,36 +892,40 @@ export async function generateReleaseGoodFunction(
938
892
  }
939
893
 
940
894
  // VAS
941
- if (orderVass?.length) {
942
- orderVass = await Promise.all(
943
- orderVass.map(async orderVas => {
944
- if (orderVas?.targetProduct?.id) {
945
- orderVas.targetProduct = await tx.getRepository(Product).findOne(orderVas.targetProduct.id)
946
- }
947
-
948
- let newOrderVas: OrderVas = {
949
- ...orderVas,
950
- domain: warehouseDomain,
951
- bizplace,
952
- name: OrderNoGenerator.releaseVas(),
953
- vas: await tx.getRepository(Vas).findOne(orderVas.vas.id),
954
- type: ORDER_TYPES.RELEASE_OF_GOODS,
955
- releaseGood: newReleaseGood,
956
- status: ORDER_VAS_STATUS.PENDING,
957
- creator: user,
958
- updater: user
959
- }
960
-
961
- if (orderVas?.inventory?.id) {
962
- newOrderVas.inventory = await tx.getRepository(Inventory).findOne(orderVas.inventory.id)
963
- }
964
-
965
- return newOrderVas
966
- })
967
- )
968
-
969
- await tx.getRepository(OrderVas).save(orderVass)
970
- }
895
+ orderVasPatch = orderVasPatch.map(itm => {
896
+ return { ...itm, releaseGood: newReleaseGood }
897
+ })
898
+ await editVas(orderVasPatch, null, context)
899
+ // if (orderVass?.length) {
900
+ // orderVass = await Promise.all(
901
+ // orderVass.map(async orderVas => {
902
+ // if (orderVas?.targetProduct?.id) {
903
+ // orderVas.targetProduct = await tx.getRepository(Product).findOne(orderVas.targetProduct.id)
904
+ // }
905
+
906
+ // let newOrderVas: OrderVas = {
907
+ // ...orderVas,
908
+ // domain: warehouseDomain,
909
+ // bizplace,
910
+ // name: OrderNoGenerator.releaseVas(),
911
+ // vas: await tx.getRepository(Vas).findOne(orderVas.vas.id),
912
+ // type: ORDER_TYPES.RELEASE_OF_GOODS,
913
+ // releaseGood: newReleaseGood,
914
+ // status: ORDER_VAS_STATUS.PENDING,
915
+ // creator: user,
916
+ // updater: user
917
+ // }
918
+
919
+ // if (orderVas?.inventory?.id) {
920
+ // newOrderVas.inventory = await tx.getRepository(Inventory).findOne(orderVas.inventory.id)
921
+ // }
922
+
923
+ // return newOrderVas
924
+ // })
925
+ // )
926
+
927
+ // await tx.getRepository(OrderVas).save(orderVass)
928
+ // }
971
929
 
972
930
  if (attachments?.length > 0) {
973
931
  const files: Attachment[] = attachments.map(attachment => {
@@ -1157,7 +1115,7 @@ export async function confirmReleaseGood(name: string, context: any, tx?: Entity
1157
1115
 
1158
1116
  if (application) {
1159
1117
  const powrupController: PowrupController = new PowrupController()
1160
- await powrupController.updateStock(foundOPs, customerDomain, user, tx)
1118
+ powrupController.updateStock(foundOPs, customerDomain, user, tx)
1161
1119
  }
1162
1120
  }
1163
1121
 
@@ -1403,7 +1361,7 @@ export async function rejectReleaseGood(
1403
1361
 
1404
1362
  if (application) {
1405
1363
  const powrupController: PowrupController = new PowrupController()
1406
- await powrupController.updateStock(foundOPs, customerDomain, user, tx)
1364
+ powrupController.updateStock(foundOPs, customerDomain, user, tx)
1407
1365
  }
1408
1366
  }
1409
1367
 
@@ -2,8 +2,9 @@ import { User } from '@things-factory/auth-base'
2
2
  import { Domain } from '@things-factory/shell'
3
3
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
4
4
  import { EntityManager } from 'typeorm'
5
- import { NewVas, VasPatch } from '../'
5
+ import { NewVas, VasPatch, OrderVasPatch, OrderVasItemPatch, ReleaseGood, OrderVas, OrderVasItem } from '../'
6
6
  import { Vas } from './vas'
7
+ import { v4 as uuidv4 } from 'uuid'
7
8
 
8
9
  @Resolver(Vas)
9
10
  export class VasMutation {
@@ -105,4 +106,155 @@ export class VasMutation {
105
106
  await tx.getRepository(Vas).delete(ids)
106
107
  return true
107
108
  }
109
+
110
+ @Directive('@privilege(category: "vas", privilege: "mutation")')
111
+ @Directive('@transaction')
112
+ @Mutation(returns => Boolean)
113
+ async editVas(
114
+ @Arg('orderVasItemPatch', type => [OrderVasItemPatch], { nullable: true }) orderVasItemPatch: OrderVasItemPatch[],
115
+ @Arg('orderVasPatch', type => [OrderVasPatch]) orderVasPatch: OrderVasPatch[],
116
+ @Ctx() context: any
117
+ ): Promise<Boolean> {
118
+ const response = await editVas(orderVasPatch, orderVasItemPatch, context)
119
+
120
+ return response
121
+ }
122
+ }
123
+
124
+ export async function editVas(
125
+ orderVasPatch: OrderVasPatch[],
126
+ orderVasItemPatch?: OrderVasItemPatch[],
127
+ context?: any
128
+ ): Promise<Boolean> {
129
+ const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
130
+ let results = []
131
+ const orderVasRepo = tx.getRepository(OrderVas)
132
+ const orderVasItemRepo = tx.getRepository(OrderVasItem)
133
+ // Order Vas
134
+ if (orderVasPatch.length > 0) {
135
+ const _deleteRecords = orderVasPatch.filter((patch: any) => patch.cuFlag.toUpperCase() === '-')
136
+ const _createRecords = orderVasPatch.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
137
+ const _updateRecords = orderVasPatch.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
138
+
139
+ if (_deleteRecords.length > 0) {
140
+ for (let i = 0; i < _deleteRecords.length; i++) {
141
+ const deleteRecord = _deleteRecords[i]
142
+ await orderVasItemRepo.delete({ orderVas: { id: deleteRecord.id } })
143
+ await orderVasRepo.delete(deleteRecord.id)
144
+ }
145
+ }
146
+
147
+ if (_createRecords.length > 0) {
148
+ for (let i = 0; i < _createRecords.length; i++) {
149
+ const newRecord = _createRecords[i]
150
+
151
+ const result = await orderVasRepo.save({
152
+ ...newRecord,
153
+ id: uuidv4(),
154
+ name: `${_createRecords[i].product.name} - ${new Date()}`,
155
+ domain: domain,
156
+ creator: user,
157
+ updater: user
158
+ })
159
+
160
+ results.push({ ...result, cuFlag: '+' })
161
+
162
+ // create new ovi
163
+ for (let ii = 0; ii < newRecord.orderVasItemsPatch.length; ii++) {
164
+ await orderVasItemRepo.save({
165
+ orderVas: result.id,
166
+ name: `${newRecord.orderVasItemsPatch[ii].vas.name} (${newRecord.orderVasItemsPatch[ii].vas.description})- ${result.id}`,
167
+ vas: newRecord.orderVasItemsPatch[ii].vas,
168
+ vasQty: newRecord.orderVasItemsPatch[ii].vasQty,
169
+ domain: domain,
170
+ creator: user,
171
+ createdAt: new Date()
172
+ })
173
+ }
174
+ }
175
+ }
176
+
177
+ if (_updateRecords.length > 0) {
178
+ for (let i = 0; i < _updateRecords.length; i++) {
179
+ const newRecord = _updateRecords[i]
180
+ const orderVas: OrderVas = await orderVasRepo.findOne({
181
+ where: { domain, id: newRecord.id },
182
+ relations: ['product', 'productDetail', 'newProduct', 'newProductDetail', 'releaseGood', 'orderVasItems']
183
+ })
184
+
185
+ const result = await orderVasRepo.save({
186
+ ...orderVas,
187
+ ...newRecord,
188
+ updater: user
189
+ })
190
+
191
+ results.push({ ...result, cuFlag: 'M' })
192
+
193
+ for (let ii = 0; ii < newRecord.orderVasItemsPatch.length; ii++) {
194
+ await orderVasItemRepo.update(
195
+ { id: newRecord.orderVasItemsPatch[ii].id },
196
+ {
197
+ orderVas: { id: result.id },
198
+ name: `${newRecord.orderVasItemsPatch[ii].vas.name}- ${result.id}`,
199
+ vas: newRecord.orderVasItemsPatch[ii].vas,
200
+ vasQty: newRecord.orderVasItemsPatch[ii].vasQty,
201
+ domain: domain,
202
+ creator: user,
203
+ createdAt: new Date()
204
+ }
205
+ )
206
+ }
207
+ }
208
+ }
209
+ }
210
+
211
+ // order Vas Item
212
+ if (orderVasItemPatch?.length > 0) {
213
+ const _deleteRecords = orderVasItemPatch.filter((patch: any) => patch.cuFlag.toUpperCase() === '-')
214
+ const _createRecords = orderVasItemPatch.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
215
+ const _updateRecords = orderVasItemPatch.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
216
+
217
+ if (_deleteRecords.length > 0) {
218
+ for (let i = 0; i < _deleteRecords.length; i++) {
219
+ const deleteRecord = _deleteRecords[i]
220
+ if (deleteRecord.id) {
221
+ await orderVasItemRepo.delete(deleteRecord.id)
222
+ }
223
+ }
224
+ }
225
+
226
+ if (_createRecords.length > 0) {
227
+ for (let i = 0; i < _createRecords.length; i++) {
228
+ const newRecord = _createRecords[i]
229
+ const result = await orderVasItemRepo.save({
230
+ id: uuidv4(),
231
+ orderVas: newRecord.orderVas.id,
232
+ name: `${newRecord.vas.name}- ${newRecord.orderVas.id}`,
233
+ vas: newRecord.vas,
234
+ vasQty: newRecord.vasQty,
235
+ domain: domain,
236
+ creator: user,
237
+ createdAt: new Date()
238
+ })
239
+ results.push({ ...result, cuFlag: '+' })
240
+ }
241
+ }
242
+
243
+ if (_updateRecords.length > 0) {
244
+ for (let i = 0; i < _updateRecords.length; i++) {
245
+ const newRecord = _updateRecords[i]
246
+
247
+ const result = await tx.getRepository(OrderVasItem).update(
248
+ {
249
+ id: newRecord.id
250
+ },
251
+ { vasQty: newRecord.vasQty, updater: user.id, updatedAt: new Date() }
252
+ )
253
+
254
+ results.push({ ...result, cuFlag: 'M' })
255
+ }
256
+ }
257
+ }
258
+
259
+ return results ? true : false
108
260
  }