@things-factory/warehouse-base 4.3.159 → 4.3.162

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 (37) hide show
  1. package/dist-server/constants/adjustment-code.js +13 -0
  2. package/dist-server/constants/adjustment-code.js.map +1 -0
  3. package/dist-server/constants/index.js +1 -0
  4. package/dist-server/constants/index.js.map +1 -1
  5. package/dist-server/constants/inventory.js +2 -1
  6. package/dist-server/constants/inventory.js.map +1 -1
  7. package/dist-server/service/inventory/inventory-query.js +2 -0
  8. package/dist-server/service/inventory/inventory-query.js.map +1 -1
  9. package/dist-server/service/inventory/inventory-types.js +16 -0
  10. package/dist-server/service/inventory/inventory-types.js.map +1 -1
  11. package/dist-server/service/inventory/inventory.js +18 -0
  12. package/dist-server/service/inventory/inventory.js.map +1 -1
  13. package/dist-server/service/inventory-change/inventory-change-mutation.js +59 -9
  14. package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
  15. package/dist-server/service/inventory-change/inventory-change-query.js +28 -0
  16. package/dist-server/service/inventory-change/inventory-change-query.js.map +1 -1
  17. package/dist-server/service/inventory-change/inventory-change-types.js +8 -0
  18. package/dist-server/service/inventory-change/inventory-change-types.js.map +1 -1
  19. package/dist-server/service/inventory-change/inventory-change.js +15 -0
  20. package/dist-server/service/inventory-change/inventory-change.js.map +1 -1
  21. package/dist-server/service/inventory-history/inventory-history-mutation.js +1 -1
  22. package/dist-server/service/inventory-history/inventory-history-mutation.js.map +1 -1
  23. package/dist-server/utils/inventory-util.js +3 -0
  24. package/dist-server/utils/inventory-util.js.map +1 -1
  25. package/package.json +5 -5
  26. package/server/constants/adjustment-code.ts +9 -0
  27. package/server/constants/index.ts +1 -0
  28. package/server/constants/inventory.ts +2 -1
  29. package/server/service/inventory/inventory-query.ts +4 -0
  30. package/server/service/inventory/inventory-types.ts +12 -0
  31. package/server/service/inventory/inventory.ts +18 -15
  32. package/server/service/inventory-change/inventory-change-mutation.ts +106 -19
  33. package/server/service/inventory-change/inventory-change-query.ts +30 -0
  34. package/server/service/inventory-change/inventory-change-types.ts +6 -0
  35. package/server/service/inventory-change/inventory-change.ts +12 -0
  36. package/server/service/inventory-history/inventory-history-mutation.ts +1 -1
  37. package/server/utils/inventory-util.ts +3 -0
@@ -1,14 +1,34 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { EntityManager, In, MoreThan, Not } from 'typeorm'
1
+ import {
2
+ Arg,
3
+ Ctx,
4
+ Directive,
5
+ Mutation,
6
+ Resolver
7
+ } from 'type-graphql'
8
+ import {
9
+ EntityManager,
10
+ In,
11
+ MoreThan,
12
+ Not
13
+ } from 'typeorm'
3
14
 
4
15
  import { User } from '@things-factory/auth-base'
5
16
  import { Bizplace } from '@things-factory/biz-base'
6
17
  import { generateId } from '@things-factory/id-rule-base'
7
18
  import { Account } from '@things-factory/integration-accounting'
8
19
  import { MarketplaceStore } from '@things-factory/integration-marketplace'
9
- import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
10
- import { Product, ProductDetail } from '@things-factory/product-base'
11
- import { PartnerSetting, Setting } from '@things-factory/setting-base'
20
+ import {
21
+ Sellercraft,
22
+ SellercraftStatus
23
+ } from '@things-factory/integration-sellercraft'
24
+ import {
25
+ Product,
26
+ ProductDetail
27
+ } from '@things-factory/product-base'
28
+ import {
29
+ PartnerSetting,
30
+ Setting
31
+ } from '@things-factory/setting-base'
12
32
  import { Domain } from '@things-factory/shell'
13
33
 
14
34
  import {
@@ -18,7 +38,11 @@ import {
18
38
  LOCATION_STATUS,
19
39
  LOCATION_TYPE
20
40
  } from '../../constants'
21
- import { EcommerceController, PosController, SellercraftController } from '../../controllers'
41
+ import {
42
+ EcommerceController,
43
+ PosController,
44
+ SellercraftController
45
+ } from '../../controllers'
22
46
  import { InventoryNoGenerator } from '../../utils'
23
47
  import { InventoryHistory } from '../inventory-history/inventory-history'
24
48
  import { InventoryItemChange } from '../inventory-item-change/inventory-item-change'
@@ -28,7 +52,11 @@ import { Inventory } from '../inventory/inventory'
28
52
  import { InventoryPatch } from '../inventory/inventory-types'
29
53
  import { Location } from '../location/location'
30
54
  import { InventoryChange } from './inventory-change'
31
- import { InventoryChangeList, InventoryChangePatch, NewInventoryChange } from './inventory-change-types'
55
+ import {
56
+ InventoryChangeList,
57
+ InventoryChangePatch,
58
+ NewInventoryChange
59
+ } from './inventory-change-types'
32
60
 
33
61
  @Resolver(InventoryChange)
34
62
  export class InventoryChangeMutation {
@@ -216,22 +244,26 @@ export class InventoryChangeMutation {
216
244
 
217
245
  var product: Product = await tx.getRepository(Product).findOne(newRecord.product.id)
218
246
  var productDetail: ProductDetail = await tx.getRepository(ProductDetail).findOne({
219
- where: [{
220
- product: { id: newRecord.product.id },
221
- packingType: newRecord.packingType,
222
- packingSize: newRecord.packingSize,
223
- uom: newRecord.uom
224
- },
225
- {
226
- product: { id: newRecord.product.id },
227
- isDefault: true
228
- }],
247
+ where: [
248
+ {
249
+ product: { id: newRecord.product.id },
250
+ packingType: newRecord.packingType,
251
+ packingSize: newRecord.packingSize,
252
+ uom: newRecord.uom
253
+ },
254
+ {
255
+ product: { id: newRecord.product.id },
256
+ isDefault: true
257
+ }
258
+ ],
229
259
  order: { isDefault: 'DESC' }
230
260
  })
231
261
 
232
262
  newRecord.product = product
233
263
  newRecord.productDetail = productDetail
234
-
264
+ if (!newRecord.unitCost) {
265
+ newRecord.unitCost = product.unitCost
266
+ }
235
267
  newRecord.status = 'PENDING'
236
268
  newRecord.transactionType = 'NEW'
237
269
 
@@ -327,7 +359,7 @@ export class InventoryChangeMutation {
327
359
 
328
360
  let existingRecord = await tx.getRepository(Inventory).findOne({
329
361
  where: { domain, palletId: updateRecord?.palletId },
330
- relations: ['location', 'warehouse', 'product', 'bizplace', 'bizplace.domain']
362
+ relations: ['location', 'warehouse', 'product', 'productDetail', 'bizplace', 'bizplace.domain']
331
363
  })
332
364
 
333
365
  if (!existingRecord) {
@@ -342,6 +374,12 @@ export class InventoryChangeMutation {
342
374
  qtyDiff = existingQty == adjustQty ? existingQty - adjustQty : adjustQty - existingQty
343
375
  }
344
376
 
377
+ if (!updateRecord.unitCost) {
378
+ if (existingRecord.unitCost != null) {
379
+ updateRecord.unitCost = existingRecord.unitCost || existingRecord.product?.costPrice
380
+ }
381
+ }
382
+
345
383
  if (!!updateRecord?.location?.id) {
346
384
  var location = await tx.getRepository(Location).findOne({
347
385
  where: { id: updateRecord.location.id },
@@ -361,12 +399,30 @@ export class InventoryChangeMutation {
361
399
  }
362
400
 
363
401
  let product: Product
402
+ let productDetail: ProductDetail
364
403
 
365
404
  if (!!updateRecord?.product?.id) {
366
405
  product = await tx.getRepository(Product).findOne(updateRecord.product.id)
406
+ productDetail = await tx.getRepository(ProductDetail).findOne({
407
+ where: [
408
+ {
409
+ product: { id: updateRecord.product.id },
410
+ packingType: updateRecord?.packingType ? updateRecord.packingType : existingRecord.packingType,
411
+ packingSize: updateRecord?.packingSize ? updateRecord.packingSize : existingRecord.packingSize,
412
+ uom: updateRecord?.uom ? updateRecord.uom : existingRecord.uom
413
+ },
414
+ {
415
+ product: { id: updateRecord.product.id },
416
+ isDefault: true
417
+ }
418
+ ],
419
+ order: { isDefault: 'DESC' }
420
+ })
367
421
  updateRecord.product = product
422
+ updateRecord.productDetail = productDetail
368
423
  } else {
369
424
  product = existingRecord.product
425
+ productDetail = existingRecord.productDetail
370
426
  }
371
427
 
372
428
  updateRecord.transactionType == 'MISSING'
@@ -382,6 +438,7 @@ export class InventoryChangeMutation {
382
438
 
383
439
  const updatedInventoryChange: InventoryChange = await inventoryChangeRepo.save({
384
440
  palletId: existingRecord.palletId,
441
+ cartonId: existingRecord.cartonId,
385
442
  ...updateRecord,
386
443
  id: undefined,
387
444
  name: InventoryNoGenerator.inventoryName(),
@@ -389,6 +446,7 @@ export class InventoryChangeMutation {
389
446
  domain: domain,
390
447
  creator: user,
391
448
  updater: user
449
+ //here?
392
450
  })
393
451
 
394
452
  const prevBizAccount: Account = await tx
@@ -870,6 +928,22 @@ export async function approveInventoryChanges(patches: any, context: any) {
870
928
  statusFilter = (newRecord.qty != null ? newRecord.qty : inventory.qty) > 0 ? 'STORED' : 'TERMINATED'
871
929
  }
872
930
 
931
+ let expirationDate = newRecord?.expirationDate ? newRecord.expirationDate : inventory.expirationDate
932
+ const { shelfLife } = inventory.product
933
+
934
+ if (shelfLife && expirationDate) {
935
+ let date: Date = new Date()
936
+ expirationDate = new Date(expirationDate)
937
+
938
+ const releaseBefore: Date = new Date(expirationDate.setDate(expirationDate.getDate() - shelfLife))
939
+
940
+ if (date > releaseBefore) {
941
+ inventory.obsolete = true
942
+ } else {
943
+ inventory.obsolete = false
944
+ }
945
+ }
946
+
873
947
  delete newRecord.createdAt
874
948
  await tx.getRepository(Inventory).save({
875
949
  ...inventory,
@@ -1028,6 +1102,19 @@ export async function approveInventoryChanges(patches: any, context: any) {
1028
1102
  ? null
1029
1103
  : newRecord.expirationDate
1030
1104
 
1105
+ const { shelfLife } = newRecord.product
1106
+
1107
+ if (shelfLife && expirationDate) {
1108
+ let date: Date = new Date()
1109
+ expirationDate = new Date(expirationDate)
1110
+
1111
+ const releaseBefore: Date = new Date(expirationDate.setDate(expirationDate.getDate() - shelfLife))
1112
+
1113
+ if (date > releaseBefore) {
1114
+ newRecord.obsolete = true
1115
+ }
1116
+ }
1117
+
1031
1118
  let savedInventory = await tx.getRepository(Inventory).save({
1032
1119
  ...newRecord,
1033
1120
  expirationDate,
@@ -32,6 +32,36 @@ export class InventoryChangeQuery {
32
32
  params.filters = [...params.filters.filter(filter => filter.name != 'bizplace')]
33
33
  }
34
34
 
35
+ const fromDateParamIdx = params.filters.findIndex(param => param.name === 'fromDate')
36
+ if (fromDateParamIdx >= 0) {
37
+ let fromDateVal = new Date(params.filters[fromDateParamIdx].value)
38
+ params.filters.splice(fromDateParamIdx, 1)
39
+
40
+ params.filters.push({
41
+ name: 'createdAt',
42
+ operator: 'gte',
43
+ value: fromDateVal.toISOString(),
44
+ relation: false
45
+ })
46
+ } else {
47
+ throw new Error(`Error: Date range not provided correctly.`)
48
+ }
49
+
50
+ const toDateParamIdx = params.filters.findIndex(param => param.name === 'toDate')
51
+ if (toDateParamIdx >= 0) {
52
+ let toDateVal = new Date(params.filters[toDateParamIdx].value)
53
+ params.filters.splice(toDateParamIdx, 1)
54
+
55
+ params.filters.push({
56
+ name: 'createdAt',
57
+ operator: 'lt',
58
+ value: new Date(toDateVal.setDate(toDateVal.getDate() + 1)).toISOString(),
59
+ relation: false
60
+ })
61
+ } else {
62
+ throw new Error(`Error: Date range not provided correctly.`)
63
+ }
64
+
35
65
  const qb: SelectQueryBuilder<InventoryChange> = getRepository(InventoryChange).createQueryBuilder('ic')
36
66
  buildQuery(qb, params, context)
37
67
 
@@ -24,6 +24,12 @@ export class InventoryChangePatch {
24
24
 
25
25
  @Field({ nullable: true })
26
26
  cuFlag?: string
27
+
28
+ @Field({ nullable: true })
29
+ fromDate: string
30
+
31
+ @Field({ nullable: true })
32
+ toDate: string
27
33
  }
28
34
 
29
35
  @InputType()
@@ -104,6 +104,10 @@ export class InventoryChange {
104
104
  @Field({ nullable: true })
105
105
  uom: string
106
106
 
107
+ @Column({ nullable: true })
108
+ @Field({ nullable: true })
109
+ sku: string
110
+
107
111
  @Column('float', { nullable: true })
108
112
  @Field({ nullable: true })
109
113
  weight: number
@@ -120,6 +124,14 @@ export class InventoryChange {
120
124
  @Field({ nullable: true })
121
125
  unitCost: number
122
126
 
127
+ @Column({ nullable: true })
128
+ @Field({ nullable: true })
129
+ adjustmentCode: string
130
+
131
+ @Column({ nullable: true })
132
+ @Field({ nullable: true })
133
+ adjustmentNote: string
134
+
123
135
  @Column()
124
136
  @Field()
125
137
  status: string
@@ -102,7 +102,7 @@ export class InventoryHistoryMutation {
102
102
  return true
103
103
  }
104
104
 
105
- @Directive('transaction')
105
+ @Directive('@transaction')
106
106
  @Mutation(returns => Boolean)
107
107
  async deleteInventoryHistories(
108
108
  @Arg('names', type => [String]) names: string[],
@@ -523,6 +523,7 @@ export async function getInventoriesByStrategy(
523
523
  ) AS rn
524
524
  FROM inventories i
525
525
  INNER JOIN locations l ON i.location_id = l.id
526
+ INNER JOIN products p ON p.id = i.product_id
526
527
  AND l.TYPE NOT IN ($1, $2)
527
528
  INNER JOIN temp_op2 op ON i.product_id = op."productId"::uuid
528
529
  AND i.batch_id = op."batchId"
@@ -532,6 +533,8 @@ export async function getInventoriesByStrategy(
532
533
  WHERE i.domain_id = $3
533
534
  AND i.bizplace_id = $4
534
535
  AND i.status = $5
536
+ AND i.obsolete = false
537
+ AND case when i.expiration_date is not null and p.p.shelf_life is not null then CURRENT_DATE < i.expiration_date - p.p.shelf_life else true end
535
538
  ORDER BY op."productId", rn
536
539
  `,
537
540
  [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE, domainId, bizplaceId, INVENTORY_STATUS.STORED]