@things-factory/sales-base 4.0.24 → 4.0.25

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 (44) hide show
  1. package/dist-server/controllers/ecommerce/ecommerce-controller.js +7 -4
  2. package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
  3. package/dist-server/controllers/ecommerce/sellercraft-controller.js +59 -0
  4. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
  5. package/dist-server/controllers/order-controller.js +40 -1
  6. package/dist-server/controllers/order-controller.js.map +1 -1
  7. package/dist-server/service/arrival-notice/arrival-notice-mutation.js +180 -0
  8. package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
  9. package/dist-server/service/arrival-notice/arrival-notice-query.js +193 -1
  10. package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
  11. package/dist-server/service/arrival-notice/arrival-notice-types.js +160 -2
  12. package/dist-server/service/arrival-notice/arrival-notice-types.js.map +1 -1
  13. package/dist-server/service/delivery-order/delivery-order-types.js +1 -1
  14. package/dist-server/service/delivery-order/delivery-order-types.js.map +1 -1
  15. package/dist-server/service/goods-receival-note/goods-receival-note.js +5 -0
  16. package/dist-server/service/goods-receival-note/goods-receival-note.js.map +1 -1
  17. package/dist-server/service/order-inventory/order-inventory.js +22 -1
  18. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  19. package/dist-server/service/release-good/release-good-mutation.js +242 -81
  20. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  21. package/dist-server/service/release-good/release-good-types.js +8 -0
  22. package/dist-server/service/release-good/release-good-types.js.map +1 -1
  23. package/dist-server/service/release-good/release-good.js +4 -0
  24. package/dist-server/service/release-good/release-good.js.map +1 -1
  25. package/dist-server/service/return-order/return-order-mutation.js +1 -1
  26. package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
  27. package/dist-server/utils/inventory-util.js +89 -1
  28. package/dist-server/utils/inventory-util.js.map +1 -1
  29. package/package.json +12 -12
  30. package/server/controllers/ecommerce/ecommerce-controller.ts +15 -6
  31. package/server/controllers/ecommerce/sellercraft-controller.ts +77 -1
  32. package/server/controllers/order-controller.ts +55 -2
  33. package/server/service/arrival-notice/arrival-notice-mutation.ts +237 -1
  34. package/server/service/arrival-notice/arrival-notice-query.ts +214 -4
  35. package/server/service/arrival-notice/arrival-notice-types.ts +120 -1
  36. package/server/service/delivery-order/delivery-order-types.ts +1 -1
  37. package/server/service/goods-receival-note/goods-receival-note.ts +4 -0
  38. package/server/service/order-inventory/order-inventory.ts +17 -1
  39. package/server/service/release-good/release-good-mutation.ts +310 -119
  40. package/server/service/release-good/release-good-types.ts +6 -0
  41. package/server/service/release-good/release-good.ts +3 -0
  42. package/server/service/return-order/return-order-mutation.ts +1 -1
  43. package/server/utils/index.ts +1 -1
  44. package/server/utils/inventory-util.ts +129 -1
@@ -1,13 +1,13 @@
1
1
  import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
- import { getRepository, In, SelectQueryBuilder } from 'typeorm'
2
+ import { EntityManager, getRepository, In, SelectQueryBuilder } from 'typeorm'
3
3
 
4
4
  import { Attachment } from '@things-factory/attachment-base'
5
- import { User } from '@things-factory/auth-base'
6
- import { Bizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
5
+ import { checkUserBelongsDomain, User } from '@things-factory/auth-base'
6
+ import { Bizplace, getCompanyBizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
7
7
  import { ProductDetail } from '@things-factory/product-base'
8
8
  import { buildQuery, Domain, ListParam } from '@things-factory/shell'
9
9
 
10
- import { ArrivalNoticeList } from '../'
10
+ import { ArrivalNoticeList, NewArrivalNotice, RawArrivalNotice } from '../'
11
11
  import { ATTACHMENT_TYPE, ORDER_STATUS } from '../../constants'
12
12
  import { OrderInventory, OrderProduct } from '../../service'
13
13
  import { ArrivalNotice } from './arrival-notice'
@@ -34,6 +34,7 @@ export class ArrivalNoticeQuery {
34
34
  relations: [
35
35
  'domain',
36
36
  'bizplace',
37
+ 'bizplace.domain',
37
38
  'releaseGood',
38
39
  'purchaseOrder',
39
40
  'purchaseOrder.bufferLocation',
@@ -117,6 +118,17 @@ export class ArrivalNoticeQuery {
117
118
  async arrivalNotices(@Ctx() context: any, @Args() params: ListParam): Promise<ArrivalNoticeList> {
118
119
  const { domain, user }: { domain: Domain; user: User } = context.state
119
120
 
121
+ if (await checkUserBelongsDomain(domain, user)) {
122
+ if (!params.filters.some(e => e.name === 'status') && !params.filters.some(e => e.name === 'name')) {
123
+ params.filters.push({
124
+ name: 'status',
125
+ operator: 'notin',
126
+ value: [ORDER_STATUS.PENDING, ORDER_STATUS.EDITING],
127
+ relation: false
128
+ })
129
+ }
130
+ }
131
+
120
132
  if (!params.filters.find((filter: any) => filter.name === 'bizplace')) {
121
133
  params.filters.push({
122
134
  name: 'bizplaceId',
@@ -287,6 +299,17 @@ export class ArrivalNoticeQuery {
287
299
  }
288
300
  }
289
301
 
302
+ @Directive('@transaction')
303
+ @Query(returns => [RawArrivalNotice])
304
+ async validateBulkArrivalNotices(
305
+ @Ctx() context: any,
306
+ @Arg('rawArrivalNotices', type => [NewArrivalNotice], { nullable: true }) rawArrivalNotices: NewArrivalNotice[],
307
+ @Arg('bizplaceId', type => String) bizplaceId: string
308
+ ): Promise<RawArrivalNotice[]> {
309
+ const tx: EntityManager = context.state.tx
310
+ return await validateBulkArrivalNoticesFunction(rawArrivalNotices, bizplaceId, tx)
311
+ }
312
+
290
313
  @FieldResolver(type => Domain)
291
314
  async domain(@Root() arrivalNotice: ArrivalNotice): Promise<Domain> {
292
315
  return await getRepository(Domain).findOne(arrivalNotice.domainId)
@@ -302,3 +325,190 @@ export class ArrivalNoticeQuery {
302
325
  return await getRepository(User).findOne(arrivalNotice.updaterId)
303
326
  }
304
327
  }
328
+
329
+ export async function validateBulkArrivalNoticesFunction(
330
+ rawArrivalNotices: NewArrivalNotice[],
331
+ bizplaceId: string,
332
+ trxMgr: EntityManager
333
+ ): Promise<RawArrivalNotice[]> {
334
+ const companyBizplace: Bizplace = await getCompanyBizplace(null, null, bizplaceId)
335
+
336
+ const json_oi = JSON.stringify(
337
+ rawArrivalNotices.map(raw => {
338
+ return {
339
+ ref_no: raw.refNo || null,
340
+ ref_no_2: raw.refNo2 || null,
341
+ ref_no_3: raw.refNo3 || null,
342
+ eta_date: raw.etaDate || null,
343
+ truck_no: raw.truckNo || null,
344
+ own_transport: !!raw.truckNo || false,
345
+ loose_item: raw.looseItem || false,
346
+ import_cargo: raw.importCargo || false,
347
+ container: (!!raw.containerNo && !!raw.containerSize) || false,
348
+ container_no: raw.containerNo || null,
349
+ container_size: raw.containerSize || null,
350
+ sku: raw.sku || null,
351
+ batch_id: raw.batchId || null,
352
+ packing_type: raw.packingType || null,
353
+ packing_size: raw.packingSize || null,
354
+ uom: raw.uom || null,
355
+ pack_qty: raw.packQty || null,
356
+ pallet_qty: raw.palletQty || null,
357
+ unit_price: raw.unitPrice || null,
358
+ manufacture_year: raw.manufactureYear || null
359
+ }
360
+ })
361
+ )
362
+
363
+ await trxMgr.query(
364
+ `
365
+ CREATE TEMP TABLE temp_order_products(
366
+ ref_no VARCHAR(150),
367
+ ref_no_2 VARCHAR(150),
368
+ ref_no_3 VARCHAR(150),
369
+ eta_date VARCHAR(24),
370
+ truck_no VARCHAR(10),
371
+ own_transport BOOLEAN,
372
+ container BOOLEAN,
373
+ container_no VARCHAR(50),
374
+ container_size VARCHAR(24),
375
+ import_cargo BOOLEAN,
376
+ loose_item BOOLEAN,
377
+ sku VARCHAR(150),
378
+ batch_id VARCHAR(100),
379
+ packing_type VARCHAR(50),
380
+ packing_size INT,
381
+ uom VARCHAR(10),
382
+ pack_qty INT,
383
+ pallet_qty INT,
384
+ unit_price FLOAT8,
385
+ manufacture_year INT4
386
+ );
387
+ `
388
+ )
389
+
390
+ await trxMgr.query(
391
+ `
392
+ INSERT INTO temp_order_products
393
+ SELECT
394
+ js.ref_no,
395
+ js.ref_no_2,
396
+ js.ref_no_3,
397
+ js.eta_date,
398
+ js.truck_no,
399
+ js.own_transport,
400
+ js.container,
401
+ js.container_no,
402
+ js.container_size,
403
+ js.import_cargo,
404
+ js.loose_item,
405
+ js.sku,
406
+ js.batch_id,
407
+ js.packing_type,
408
+ js.packing_size,
409
+ js.uom,
410
+ js.pack_qty,
411
+ js.pallet_qty,
412
+ js.unit_price,
413
+ js.manufacture_year
414
+ FROM
415
+ JSON_POPULATE_RECORDSET(NULL :: temp_order_products, $1) js;
416
+ `,
417
+ [json_oi]
418
+ )
419
+
420
+ let validatedItems = await trxMgr.query(
421
+ `
422
+ SELECT
423
+ tp.ref_no,
424
+ tp.ref_no_2,
425
+ tp.ref_no_3,
426
+ tp.eta_date,
427
+ tp.truck_no,
428
+ tp.own_transport,
429
+ tp.container,
430
+ tp.container_no,
431
+ tp.container_size,
432
+ tp.import_cargo,
433
+ tp.loose_item,
434
+ pr.id AS product_id,
435
+ pd.id AS product_detail_id,
436
+ pr.sku AS sku,
437
+ CASE WHEN pr.description NOT IN (NULL, '', '-') THEN CONCAT(pr.name, '(', pr.description, ')') ELSE pr.name END AS product_info,
438
+ tp.batch_id,
439
+ pd.packing_type,
440
+ pd.packing_size,
441
+ tp.pack_qty,
442
+ pd.uom_value,
443
+ pd.uom,
444
+ CONCAT(COALESCE(ROUND(pd.uom_value :: numeric, 2), 0) * tp.pack_qty, ' ', pd.uom) AS total_uom_value,
445
+ tp.pallet_qty,
446
+ tp.unit_price,
447
+ tp.manufacture_year,
448
+ CASE WHEN an.id NOTNULL THEN CONCAT('duplicated with ', an.name) ELSE CASE WHEN pr.id ISNULL OR pd.id ISNULL OR tp.sku ISNULL THEN 'product not found'
449
+ ELSE CASE WHEN tp.pack_qty <= 0 THEN 'pack qty must be integer'
450
+ ELSE CASE WHEN tp.batch_id ISNULL THEN 'batch no. is required'
451
+ ELSE CASE WHEN tp.ref_no ISNULL OR tp.ref_no = '' THEN 'ref no. is required'
452
+ ELSE CASE WHEN tp.eta_date ISNULL OR tp.eta_date = '' THEN 'eta date is required'
453
+ ELSE CASE WHEN tp.eta_date:: date < timeofday():: date THEN 'backdate is not allowed'
454
+ ELSE CASE WHEN tp.container_no NOTNULL AND tp.container_size ISNULL OR tp.container_no ISNULL AND tp.container_size NOTNULL THEN 'incomplete container information'
455
+ ELSE '' END END END END END END END END AS remark
456
+ FROM
457
+ temp_order_products tp
458
+ LEFT JOIN arrival_notices an ON tp.ref_no = an.ref_no
459
+ AND CASE WHEN tp.ref_no_2 NOTNULL THEN tp.ref_no_2 = an.ref_no_2 ELSE 1 = 1 END
460
+ AND CASE WHEN tp.ref_no_3 NOTNULL THEN tp.ref_no_3 = an.ref_no_3 ELSE 1 = 1 END
461
+ AND CASE WHEN tp.truck_no NOTNULL THEN tp.truck_no = an.truck_no ELSE 1 = 1 END
462
+ AND CASE WHEN tp.own_transport NOTNULL THEN tp.own_transport = an.own_transport ELSE 1 = 1 END
463
+ AND CASE WHEN tp.container NOTNULL THEN tp.container = an.container ELSE 1 = 1 END
464
+ AND CASE WHEN tp.container_no NOTNULL THEN tp.container_no = an.container_no ELSE 1 = 1 END
465
+ AND CASE WHEN tp.container_size NOTNULL THEN tp.container_size = an.container_size ELSE 1 = 1 END
466
+ AND CASE WHEN tp.loose_item NOTNULL THEN tp.loose_item = an.loose_item ELSE 1 = 1 END
467
+ AND CASE WHEN tp.import_cargo NOTNULL THEN tp.import_cargo = an.import_cargo ELSE 1 = 1 END
468
+ LEFT JOIN products pr ON pr.sku = tp.sku
469
+ LEFT JOIN product_details pd ON pr.id = pd.product_id
470
+ AND CASE WHEN tp.packing_type NOTNULL
471
+ AND tp.packing_size NOTNULL
472
+ AND tp.uom NOTNULL THEN pd.packing_type = tp.packing_type
473
+ AND pd.packing_size = tp.packing_size
474
+ AND pd.uom = tp.uom ELSE pd.is_default = TRUE END
475
+ WHERE
476
+ pr.bizplace_id = $1
477
+
478
+ `,
479
+ [companyBizplace.id]
480
+ )
481
+
482
+ await trxMgr.query('DROP TABLE temp_order_products')
483
+
484
+ return validatedItems.map(item => {
485
+ return {
486
+ refNo: item.ref_no,
487
+ refNo2: item.ref_no_2,
488
+ refNo3: item.ref_no_3,
489
+ etaDate: item.eta_date,
490
+ truckNo: item.truck_no,
491
+ ownTransport: !!item.own_transport,
492
+ container: item.container,
493
+ containerNo: item.container_no,
494
+ containerSize: item.container_size,
495
+ importCargo: !!item.import_cargo,
496
+ looseItem: !!item.loose_item,
497
+ productId: item.product_id,
498
+ productDetailId: item.product_detail_id,
499
+ sku: item.sku,
500
+ productInfo: item.product_info,
501
+ batchId: item.batch_id,
502
+ packingType: item.packing_type,
503
+ packingSize: item.packing_size,
504
+ uom: item.uom,
505
+ packQty: item.pack_qty,
506
+ uomValue: item.uom_value,
507
+ totalUomValue: item.total_uom_value,
508
+ palletQty: item.pallet_qty,
509
+ unitPrice: item.unit_price,
510
+ manufactureYear: item.manufacture_year,
511
+ remark: item.remark
512
+ }
513
+ })
514
+ }
@@ -1,5 +1,7 @@
1
+ import { Field, Float, InputType, Int, ObjectType } from 'type-graphql'
2
+
1
3
  import { ObjectRef } from '@things-factory/shell'
2
- import { Field, InputType, Int, ObjectType } from 'type-graphql'
4
+
3
5
  import { NewOrderProduct } from '../order-product/order-product-types'
4
6
  import { NewOrderVas } from '../order-vas/order-vas-types'
5
7
  import { ArrivalNotice } from './arrival-notice'
@@ -89,6 +91,36 @@ export class NewArrivalNotice {
89
91
 
90
92
  @Field({ nullable: true })
91
93
  partnerBizplaceId: string
94
+
95
+ @Field({ nullable: true })
96
+ sku: string
97
+
98
+ @Field({ nullable: true })
99
+ batchId?: string
100
+
101
+ @Field({ nullable: true })
102
+ packingType?: string
103
+
104
+ @Field(type => Float, { nullable: true })
105
+ packingSize?: number
106
+
107
+ @Field(type => Int, { nullable: true })
108
+ packQty?: number
109
+
110
+ @Field(type => Float, { nullable: true })
111
+ uomValue?: number
112
+
113
+ @Field({ nullable: true })
114
+ uom?: string
115
+
116
+ @Field(type => Int, { nullable: true })
117
+ palletQty?: number
118
+
119
+ @Field(type => Float, { nullable: true })
120
+ unitPrice?: number
121
+
122
+ @Field(type => Int, { nullable: true })
123
+ manufactureYear?: number
92
124
  }
93
125
 
94
126
  @InputType()
@@ -171,3 +203,90 @@ export class ArrivalNoticePatch {
171
203
  @Field({ nullable: true })
172
204
  deliveryOrderNo: string
173
205
  }
206
+
207
+ @ObjectType()
208
+ export class RawArrivalNotice {
209
+ @Field({ nullable: true })
210
+ id?: string
211
+
212
+ @Field({ nullable: true })
213
+ name?: string
214
+
215
+ @Field({ nullable: true })
216
+ refNo?: string
217
+
218
+ @Field({ nullable: true })
219
+ refNo2?: string
220
+
221
+ @Field({ nullable: true })
222
+ refNo3?: string
223
+
224
+ @Field({ nullable: true })
225
+ etaDate?: string
226
+
227
+ @Field({ nullable: true })
228
+ truckNo?: string
229
+
230
+ @Field()
231
+ ownTransport: boolean
232
+
233
+ @Field({ nullable: true })
234
+ productId?: string
235
+
236
+ @Field({ nullable: true })
237
+ container?: boolean
238
+
239
+ @Field({ nullable: true })
240
+ containerNo?: string
241
+
242
+ @Field({ nullable: true })
243
+ containerSize?: string
244
+
245
+ @Field({ nullable: true })
246
+ looseItem?: boolean
247
+
248
+ @Field({ nullable: true })
249
+ importCargo?: boolean
250
+
251
+ @Field({ nullable: true })
252
+ productDetailId?: string
253
+
254
+ @Field({ nullable: true })
255
+ sku?: string
256
+
257
+ @Field({ nullable: true })
258
+ productInfo?: string
259
+
260
+ @Field({ nullable: true })
261
+ batchId?: string
262
+
263
+ @Field({ nullable: true })
264
+ packingType?: string
265
+
266
+ @Field(type => Float, { nullable: true })
267
+ packingSize?: number
268
+
269
+ @Field(type => Int, { nullable: true })
270
+ packQty?: number
271
+
272
+ @Field(type => Float, { nullable: true })
273
+ uomValue?: number
274
+
275
+ @Field({ nullable: true })
276
+ totalUomValue?: string
277
+
278
+ @Field({ nullable: true })
279
+ uom?: string
280
+
281
+ @Field(type => Int, { nullable: true })
282
+ palletQty?: number
283
+
284
+ @Field(type => Float, { nullable: true })
285
+ unitPrice?: number
286
+
287
+ @Field(type => Int, { nullable: true })
288
+ manufactureYear?: number
289
+
290
+ @Field({ nullable: true })
291
+ remark?: string
292
+ }
@@ -42,7 +42,7 @@ export class NewDeliveryOrder {
42
42
  @Field({ nullable: true })
43
43
  from: string
44
44
 
45
- @Field(type => Float, { nullable: false })
45
+ @Field(type => Float, { nullable: true })
46
46
  loadWeight: number
47
47
 
48
48
  @Field({ nullable: true })
@@ -1,5 +1,6 @@
1
1
  import { User } from '@things-factory/auth-base'
2
2
  import { Bizplace } from '@things-factory/biz-base'
3
+ import { Attachment } from '@things-factory/attachment-base'
3
4
  import { Domain } from '@things-factory/shell'
4
5
  import { Field, ID, ObjectType } from 'type-graphql'
5
6
  import {
@@ -88,4 +89,7 @@ export class GoodsReceivalNote {
88
89
 
89
90
  @RelationId((grn: GoodsReceivalNote) => grn.updater)
90
91
  updaterId: string
92
+
93
+ @Field(type => [Attachment], { nullable: true })
94
+ attachments: Attachment[]
91
95
  }
@@ -106,6 +106,7 @@ export class OrderInventory {
106
106
  product: Product
107
107
 
108
108
  @RelationId((orderInventory: OrderInventory) => orderInventory.product)
109
+ @Field({ nullable: true })
109
110
  productId: string
110
111
 
111
112
  @Column({ nullable: true })
@@ -138,6 +139,9 @@ export class OrderInventory {
138
139
  @RelationId((orderInventory: OrderInventory) => orderInventory.releaseGood)
139
140
  releaseGoodId: string
140
141
 
142
+ @Field({ nullable: true })
143
+ releaseGoodName: string
144
+
141
145
  @ManyToOne(type => InventoryCheck)
142
146
  @Field(type => InventoryCheck, { nullable: true })
143
147
  inventoryCheck: InventoryCheck
@@ -242,6 +246,9 @@ export class OrderInventory {
242
246
  @Field({ nullable: true })
243
247
  releaseUomValue: number
244
248
 
249
+ @Field({ nullable: true })
250
+ releaseUomValueWithUom: string
251
+
245
252
  @Column({ nullable: true })
246
253
  @Field({ nullable: true })
247
254
  uom: string
@@ -249,9 +256,15 @@ export class OrderInventory {
249
256
  @Field({ nullable: true })
250
257
  productName: string
251
258
 
259
+ @Field({ nullable: true })
260
+ productBrand: string
261
+
252
262
  @Field({ nullable: true })
253
263
  pallet: string
254
264
 
265
+ @Field({ nullable: true })
266
+ palletId: string
267
+
255
268
  @Field({ nullable: true })
256
269
  extraJsonData: string
257
270
 
@@ -275,6 +288,9 @@ export class OrderInventory {
275
288
  @Field({ nullable: true })
276
289
  actualPalletQty: number
277
290
 
291
+ @Field({ nullable: true })
292
+ systemRemark: string
293
+
278
294
  @Column({ nullable: true })
279
295
  @Field({ nullable: true })
280
296
  crossDocking: boolean
@@ -284,7 +300,7 @@ export class OrderInventory {
284
300
  serialNumber: string
285
301
 
286
302
  @Column()
287
- @Field()
303
+ @Field({ nullable: true })
288
304
  status: string
289
305
 
290
306
  @CreateDateColumn()