@things-factory/warehouse-base 4.3.256 → 4.3.261
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/warehouse-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.261",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@things-factory/product-base": "^4.3.253",
|
|
32
32
|
"@things-factory/setting-base": "^4.3.253"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "c085fa97b4a7a9abd06aab1820d4e7dbc4ed83ad"
|
|
35
35
|
}
|
|
@@ -5,6 +5,7 @@ import { Powrup, PowrupAPI, Platform } from '@things-factory/integration-powrup'
|
|
|
5
5
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
6
6
|
import { INVENTORY_STATUS, LOCATION_TYPE } from '../../constants'
|
|
7
7
|
import { Inventory } from '../../service/inventory/inventory'
|
|
8
|
+
import { ProductDetailStock } from '../../service/product-detail-stock/product-detail-stock'
|
|
8
9
|
import { Domain, User } from '@things-factory/shell'
|
|
9
10
|
|
|
10
11
|
export class PowrupController {
|
|
@@ -71,12 +72,16 @@ export class PowrupController {
|
|
|
71
72
|
}
|
|
72
73
|
})
|
|
73
74
|
|
|
75
|
+
const productDetailStock: ProductDetailStock = await trxMgr
|
|
76
|
+
.getRepository(ProductDetailStock)
|
|
77
|
+
.findOne({ productDetail })
|
|
78
|
+
|
|
74
79
|
const powrupInvs: any[] = [
|
|
75
80
|
{
|
|
76
81
|
refCode: productDetail.refCode,
|
|
77
82
|
stock: {
|
|
78
83
|
quantityTotal: inventoryTotalQty || 0,
|
|
79
|
-
quantityReserved: inventoryTotalLockedQty || 0,
|
|
84
|
+
quantityReserved: inventoryTotalLockedQty + (productDetailStock.unassignedQty || 0) || 0,
|
|
80
85
|
quantityBuffer: inventoryBufferQty || 0
|
|
81
86
|
}
|
|
82
87
|
}
|
|
@@ -236,13 +236,12 @@ export class InventoryQuery {
|
|
|
236
236
|
|
|
237
237
|
let bizplaceQuery = ''
|
|
238
238
|
if (permittedBizplaceIds.length > 0) {
|
|
239
|
-
bizplaceQuery = `
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
)`
|
|
239
|
+
bizplaceQuery = `
|
|
240
|
+
select bizplace_id::uuid from (VALUES ${permittedBizplaceIds.map(id => `('${id}')`).join(',')})
|
|
241
|
+
as bizFilter(bizplace_id)
|
|
242
|
+
`
|
|
244
243
|
} else {
|
|
245
|
-
bizplaceQuery = `
|
|
244
|
+
bizplaceQuery = `select null as bizplace_id`
|
|
246
245
|
}
|
|
247
246
|
|
|
248
247
|
let productQuery = ''
|
|
@@ -255,13 +254,10 @@ export class InventoryQuery {
|
|
|
255
254
|
})
|
|
256
255
|
.join(',')
|
|
257
256
|
productQuery = `AND (
|
|
258
|
-
Lower("
|
|
259
|
-
OR Lower("
|
|
260
|
-
OR Lower("
|
|
261
|
-
OR Lower("
|
|
262
|
-
OR Lower("ProductRef"."name") LIKE ANY(ARRAY[${productValue}])
|
|
263
|
-
OR Lower("ProductRef"."sku") LIKE ANY(ARRAY[${productValue}])
|
|
264
|
-
OR Lower("ProductRef"."description") LIKE ANY(ARRAY[${productValue}])
|
|
257
|
+
Lower("p"."name") LIKE ANY(ARRAY[${productValue}])
|
|
258
|
+
OR Lower("p"."sku") LIKE ANY(ARRAY[${productValue}])
|
|
259
|
+
OR Lower("p"."brand") LIKE ANY(ARRAY[${productValue}])
|
|
260
|
+
OR Lower("p"."description") LIKE ANY(ARRAY[${productValue}])
|
|
265
261
|
)`
|
|
266
262
|
}
|
|
267
263
|
|
|
@@ -276,7 +272,7 @@ export class InventoryQuery {
|
|
|
276
272
|
productQuery =
|
|
277
273
|
productQuery +
|
|
278
274
|
` AND (
|
|
279
|
-
Lower("
|
|
275
|
+
Lower("p"."type") LIKE ANY(ARRAY[${productTypeValue}])
|
|
280
276
|
)`
|
|
281
277
|
}
|
|
282
278
|
|
|
@@ -297,7 +293,8 @@ export class InventoryQuery {
|
|
|
297
293
|
}
|
|
298
294
|
|
|
299
295
|
if (availableStockFilter?.value) {
|
|
300
|
-
availableStockQuery = ` AND SUM(
|
|
296
|
+
//availableStockQuery = ` AND SUM(coalesce(i."qty",0)) >= 0`
|
|
297
|
+
availableStockQuery = ` AND "availableQty" > 0`
|
|
301
298
|
}
|
|
302
299
|
|
|
303
300
|
if (availableStockFilter?.value && quarantineStockFilter?.value) {
|
|
@@ -364,91 +361,102 @@ export class InventoryQuery {
|
|
|
364
361
|
`
|
|
365
362
|
create temp table temp_inv_history AS
|
|
366
363
|
(
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
"
|
|
370
|
-
|
|
371
|
-
"
|
|
372
|
-
"
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
364
|
+
select p."id" as "id", pd."id" as "productDetailId", p."sku" as "sku", p."brand" as "brand", p."name" as "name", p."type" as "type", p."description" as "description",
|
|
365
|
+
coalesce(i."packing_type", pd."packing_type") as "packingType", p."weight" as "weight",
|
|
366
|
+
pd."aux_unit_1" as "auxUnit1", pd."aux_value_1" as "auxValue1", pd."aux_unit_2" as "auxUnit2", pd."aux_value_2" as "auxValue2",
|
|
367
|
+
pd."aux_unit_3" as "auxUnit3", pd."aux_value_3" as "auxValue3", pd."aux_unit_4" as "auxUnit4", pd."aux_value_4" as "auxValue4",
|
|
368
|
+
pd."aux_unit_5" as "auxUnit5", pd."aux_value_5" as "auxValue5", coalesce(inv_bz."id", bz2."id") as "bizplaceId", coalesce(inv_bz."name", bz2."name") as "bizplaceName",
|
|
369
|
+
COALESCE(pdbs."min_qty", p."min_qty",0) as "minQty", COALESCE(pdbs."max_qty", p."max_qty",0) as "maxQty",
|
|
370
|
+
(
|
|
371
|
+
case when sum(coalesce(i."qty",0)) > 0 then sum(coalesce(i."unit_cost", 0) * coalesce(i."qty",0))/ sum(coalesce(i."qty",0))
|
|
372
|
+
else 0 end
|
|
373
|
+
) as "averageUnitCost",
|
|
374
|
+
(
|
|
375
|
+
case when inv_loc."type" NOT IN ('QUARANTINE','RESERVE') and
|
|
376
|
+
case when i."expiration_date" is not null and p."shelf_life" is not null then CURRENT_DATE < i."expiration_date" - p."shelf_life" else true end
|
|
377
|
+
and i."obsolete" is false
|
|
378
|
+
then
|
|
379
|
+
case when sum(coalesce(i."qty",0)) > 0 then sum(coalesce(i."qty",0)) else 0 end
|
|
380
|
+
else 0 end
|
|
381
|
+
) as "qty",
|
|
382
|
+
(
|
|
383
|
+
case when inv_loc."type" NOT IN ('QUARANTINE','RESERVE')
|
|
384
|
+
and case when i."expiration_date" is not null and p."shelf_life" is not null then CURRENT_DATE < i."expiration_date" - p."shelf_life" else true end
|
|
385
|
+
and i."obsolete" is false
|
|
386
|
+
then
|
|
387
|
+
case when sum(coalesce(i."qty",0)) > 0 then sum(coalesce(i."qty",0)) else 0 end - sum(COALESCE(i."locked_qty", 0))
|
|
388
|
+
else 0 end
|
|
389
|
+
) as "availableQty",
|
|
390
|
+
(
|
|
391
|
+
case when inv_loc."type" = 'QUARANTINE'
|
|
392
|
+
then case when sum(coalesce(i."qty",0)) > 0
|
|
393
|
+
then sum(coalesce(i."qty",0))-sum(COALESCE(i."locked_qty", 0))
|
|
394
|
+
else 0 end
|
|
395
|
+
else 0 end
|
|
396
|
+
) as "quarantineQty",
|
|
397
|
+
(
|
|
398
|
+
case when inv_loc."type" = 'RESERVE'
|
|
399
|
+
then
|
|
400
|
+
case when sum(coalesce(i."qty",0)) > 0
|
|
401
|
+
then sum(coalesce(i."qty",0))-sum(COALESCE(i."locked_qty", 0))
|
|
402
|
+
else 0 end
|
|
403
|
+
else 0 end
|
|
404
|
+
) as "reserveQty",
|
|
405
|
+
(
|
|
406
|
+
case when inv_loc."type" = 'BIN'
|
|
407
|
+
then sum(coalesce(i."qty",0))
|
|
408
|
+
else 0
|
|
409
|
+
end
|
|
410
|
+
)as "binQty",
|
|
411
|
+
(
|
|
412
|
+
case when i."obsolete" is true or
|
|
413
|
+
case when i."expiration_date" is not null and p."shelf_life" is not null then CURRENT_DATE > i."expiration_date" - p."shelf_life" else false end
|
|
414
|
+
then
|
|
415
|
+
case when sum(coalesce(i."qty",0)) > 0 then sum(coalesce(i."qty",0)) else 0 end
|
|
416
|
+
else 0 end
|
|
417
|
+
) as "obsoleteQty",
|
|
418
|
+
(
|
|
419
|
+
case when inv_loc."type" = 'DAMAGE'
|
|
420
|
+
then
|
|
421
|
+
case when sum(coalesce(i."qty",0)) > 0
|
|
422
|
+
then sum(coalesce(i."qty",0))
|
|
423
|
+
else 0 end
|
|
424
|
+
else 0 end
|
|
425
|
+
) as "damageQty",
|
|
426
|
+
(
|
|
427
|
+
case when inv_loc."type" = 'STORAGE'
|
|
428
|
+
then
|
|
429
|
+
case when sum(coalesce(i."qty",0)) > 0
|
|
430
|
+
then sum(coalesce(i."qty",0))-sum(COALESCE(i."locked_qty", 0))
|
|
431
|
+
else 0 end
|
|
432
|
+
else 0 end
|
|
433
|
+
) as "storageQty",
|
|
434
|
+
(
|
|
435
|
+
case when i."transfer_qty" > 0
|
|
436
|
+
then
|
|
437
|
+
sum(i."transfer_qty")
|
|
438
|
+
else 0 end
|
|
439
|
+
) as "transferQty",
|
|
440
|
+
sum(coalesce(i."locked_qty", 0)) as "locked_qty"
|
|
441
|
+
from (
|
|
442
|
+
${bizplaceQuery}
|
|
443
|
+
) b
|
|
444
|
+
inner join bizplaces bz on bz.id = b.bizplace_id
|
|
445
|
+
inner join companies c on c.id = bz.company_id
|
|
446
|
+
inner join bizplaces bz2 on bz2.domain_id = c.domain_id
|
|
447
|
+
inner join products p on (p.bizplace_id = b.bizplace_id::uuid or p.bizplace_id = bz2.id)
|
|
448
|
+
inner join product_details pd on pd.product_id = p.id and pd.is_default
|
|
449
|
+
left join product_detail_bizplace_settings pdbs on pdbs.product_detail_id = pd.id
|
|
450
|
+
left join inventories i on i.bizplace_id =b.bizplace_id and i.product_id = p.id and i.qty >= 0 and i.status <> 'MISSING' and i.status <> 'PUTTING_AWAY' and
|
|
451
|
+
i.domain_id = $1
|
|
452
|
+
left join product_detail_stocks pds on pds.product_detail_id = pd.id and pds.domain_id = i.domain_id
|
|
453
|
+
left join bizplaces inv_bz on inv_bz.id = i.bizplace_id
|
|
454
|
+
left join locations inv_loc on inv_loc.id = i.location_id
|
|
455
|
+
where 1=1
|
|
456
|
+
${productQuery}
|
|
457
|
+
group by p."id", coalesce(inv_bz."id", bz2."id"), coalesce(inv_bz."name", bz2."name"), pdbs."id", pd."id",
|
|
458
|
+
i."packing_type", i."packing_size", i."uom", i."transfer_qty", i."expiration_date", i."obsolete",
|
|
459
|
+
inv_loc."type"
|
|
452
460
|
)`,
|
|
453
461
|
[domain.id]
|
|
454
462
|
)
|
|
@@ -464,7 +472,7 @@ export class InventoryQuery {
|
|
|
464
472
|
SUM("quarantineQty") AS "quarantineQty",
|
|
465
473
|
SUM("reserveQty") AS "reserveQty",
|
|
466
474
|
COALESCE("opd"."total_release_qty", 0) as "draftQty",
|
|
467
|
-
SUM("tih"."locked_qty") + "pds"."unassigned_qty" as "releaseQty",
|
|
475
|
+
SUM(COALESCE("tih"."locked_qty",0)) + COALESCE("pds"."unassigned_qty",0) as "releaseQty",
|
|
468
476
|
COALESCE("opd"."total_release_qty", 0) - SUM("availableQty") - COALESCE("putawayinv"."putaway_qty", 0) AS "insufficientQty",
|
|
469
477
|
SUM("availableQty") + COALESCE("putawayinv"."putaway_qty", 0) - COALESCE("pds"."unassigned_qty",0) AS "availableQty",
|
|
470
478
|
SUM("quarantineQty" + "reserveQty" + "availableQty") + COALESCE("putawayinv"."putaway_qty", 0) - COALESCE("opd"."total_release_qty", 0) AS "warehouseQty",
|
|
@@ -486,7 +494,7 @@ export class InventoryQuery {
|
|
|
486
494
|
GROUP BY "op"."product_id","op"."packing_type" ,"op"."packing_size", "op"."uom"
|
|
487
495
|
) AS "opd"
|
|
488
496
|
ON "tih"."id" = "opd"."product_id"
|
|
489
|
-
|
|
497
|
+
AND "tih"."packingType" = "opd"."packing_type"
|
|
490
498
|
LEFT JOIN
|
|
491
499
|
(
|
|
492
500
|
SELECT SUM(i.qty) as "putaway_qty", i.product_id, i.packing_type, i.packing_size, i.uom FROM "inventories" i
|
|
@@ -505,6 +513,8 @@ export class InventoryQuery {
|
|
|
505
513
|
const results: any = await tx.query(
|
|
506
514
|
`
|
|
507
515
|
SELECT * FROM grouped_inventories_product
|
|
516
|
+
WHERE 1 = 1
|
|
517
|
+
${availableStockQuery}
|
|
508
518
|
ORDER BY "bizplaceName", "sku"
|
|
509
519
|
OFFSET $1 LIMIT $2
|
|
510
520
|
`,
|