@things-factory/sales-base 4.3.79 → 4.3.80-alpha.0
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/dist-server/service/arrival-notice/arrival-notice-mutation.js +6 -5
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice.js +5 -0
- package/dist-server/service/arrival-notice/arrival-notice.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js +3 -8
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-query.js +4 -7
- package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good.js +5 -0
- package/dist-server/service/draft-release-good/draft-release-good.js.map +1 -1
- package/dist-server/service/invoice-product/invoice-product.js +8 -3
- package/dist-server/service/invoice-product/invoice-product.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-query.js +2 -1
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-types.js +18 -10
- package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory.js +12 -3
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
- package/dist-server/service/order-product/order-product-query.js +1 -0
- package/dist-server/service/order-product/order-product-query.js.map +1 -1
- package/dist-server/service/order-product/order-product-types.js +18 -10
- package/dist-server/service/order-product/order-product-types.js.map +1 -1
- package/dist-server/service/order-vas/order-vas.js +8 -3
- package/dist-server/service/order-vas/order-vas.js.map +1 -1
- package/dist-server/service/others/other-query.js +21 -32
- package/dist-server/service/others/other-query.js.map +1 -1
- package/dist-server/service/others/other-types.js +4 -0
- package/dist-server/service/others/other-types.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-mutation.js +10 -2
- package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-query.js +1 -0
- package/dist-server/service/purchase-order/purchase-order-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +187 -49
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +4 -6
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-types.js +8 -4
- package/dist-server/service/release-good/release-good-types.js.map +1 -1
- package/dist-server/service/release-good/release-good.js +5 -0
- package/dist-server/service/release-good/release-good.js.map +1 -1
- package/dist-server/service/return-order/return-order-mutation.js +2 -0
- package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
- package/dist-server/service/return-order/return-order-types.js.map +1 -1
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +8 -3
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -1
- package/dist-server/utils/inventory-util.js +33 -102
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +13 -13
- package/server/service/arrival-notice/arrival-notice-mutation.ts +6 -3
- package/server/service/arrival-notice/arrival-notice.ts +4 -0
- package/server/service/draft-release-good/draft-release-good-mutation.ts +10 -12
- package/server/service/draft-release-good/draft-release-good-query.ts +5 -5
- package/server/service/draft-release-good/draft-release-good.ts +4 -0
- package/server/service/invoice-product/invoice-product.ts +5 -1
- package/server/service/order-inventory/order-inventory-query.ts +2 -0
- package/server/service/order-inventory/order-inventory-types.ts +6 -0
- package/server/service/order-inventory/order-inventory.ts +8 -1
- package/server/service/order-product/order-product-query.ts +1 -0
- package/server/service/order-product/order-product-types.ts +6 -0
- package/server/service/order-vas/order-vas.ts +6 -1
- package/server/service/others/other-query.ts +34 -43
- package/server/service/others/other-types.ts +3 -0
- package/server/service/purchase-order/purchase-order-mutation.ts +10 -1
- package/server/service/purchase-order/purchase-order-query.ts +1 -0
- package/server/service/release-good/release-good-mutation.ts +221 -50
- package/server/service/release-good/release-good-query.ts +4 -7
- package/server/service/release-good/release-good-types.ts +4 -3
- package/server/service/release-good/release-good.ts +8 -6
- package/server/service/return-order/return-order-mutation.ts +3 -1
- package/server/service/return-order/return-order-types.ts +1 -0
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +5 -1
- package/server/utils/inventory-util.ts +67 -147
|
@@ -2,7 +2,7 @@ import { EntityManager, Equal, getRepository, In, Not, Raw, Repository, SelectQu
|
|
|
2
2
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
-
import { Product, ProductBundle } from '@things-factory/product-base'
|
|
5
|
+
import { Product, ProductBundle, ProductDetail } from '@things-factory/product-base'
|
|
6
6
|
import { Domain, ListParam } from '@things-factory/shell'
|
|
7
7
|
import {
|
|
8
8
|
Inventory,
|
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
Location,
|
|
13
13
|
LOCATION_STATUS,
|
|
14
14
|
LOCATION_TYPE,
|
|
15
|
-
Pallet
|
|
15
|
+
Pallet,
|
|
16
|
+
generateInventoryHistory
|
|
16
17
|
} from '@things-factory/warehouse-base'
|
|
17
18
|
|
|
18
19
|
import { ORDER_TYPES } from '../constants'
|
|
@@ -102,6 +103,7 @@ export const InventoryUtil = {
|
|
|
102
103
|
coalesce(p.sku, '') AS "productSKU",
|
|
103
104
|
coalesce(p.brand, '') AS "productBrand",
|
|
104
105
|
p.id AS "productId",
|
|
106
|
+
pd.id AS "productDetailId",
|
|
105
107
|
COALESCE(SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)),0) AS "remainQty",
|
|
106
108
|
COALESCE(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)),0) AS "remainUomValue",
|
|
107
109
|
concat(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)), ' ', pd.uom) AS "remainUomValueWithUom",
|
|
@@ -114,10 +116,7 @@ export const InventoryUtil = {
|
|
|
114
116
|
WHERE l2.type NOT IN ('${LOCATION_TYPE.QUARANTINE}', '${LOCATION_TYPE.RESERVE}')
|
|
115
117
|
AND i.domain_id = $1 AND i.status = 'STORED'
|
|
116
118
|
${inventoryBizplaceFilter ? `AND i.bizplace_id = '${inventoryBizplaceFilter.value}'` : ``}
|
|
117
|
-
) i ON i.
|
|
118
|
-
AND i.packing_type = pd.packing_type
|
|
119
|
-
and i.packing_size = pd.packing_size
|
|
120
|
-
and i.uom = pd.uom
|
|
119
|
+
) i ON i.product_detail_id = pd.id
|
|
121
120
|
LEFT JOIN oi ON i.batch_id = oi.batch_id AND p.name = oi.product_name AND i.packing_type = oi.packing_type AND i.packing_size = oi.packing_size AND i.uom = oi.uom
|
|
122
121
|
LEFT JOIN (
|
|
123
122
|
SELECT pbs.product_id, SUM(pbs.bundle_qty * src.release_qty) AS bundle_product_release_qty, SUM(pbs.bundle_qty * src.release_uom_value) AS bundle_product_release_uom_value
|
|
@@ -127,22 +126,24 @@ export const InventoryUtil = {
|
|
|
127
126
|
) bp on i.product_id = bp.product_id
|
|
128
127
|
WHERE p.bizplace_id IN (${bizplaceIds})
|
|
129
128
|
${productDetailWhereClause}
|
|
130
|
-
${
|
|
131
|
-
|
|
129
|
+
${
|
|
130
|
+
productFilter
|
|
131
|
+
? `AND (
|
|
132
132
|
lower(p.sku) ilike '${productFilter.value}'
|
|
133
133
|
OR lower(p.name) ilike '${productFilter.value}'
|
|
134
134
|
OR lower(p.description) ilike '${productFilter.value}'
|
|
135
135
|
)
|
|
136
136
|
`
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
: ``
|
|
138
|
+
}
|
|
139
139
|
GROUP BY
|
|
140
140
|
p.id,
|
|
141
|
+
pd.id,
|
|
141
142
|
pd.packing_type,
|
|
142
143
|
pd.packing_size,
|
|
143
144
|
pd.uom
|
|
144
145
|
UNION
|
|
145
|
-
SELECT packing_type, packing_size,'UNIT' AS "uom", name AS "productName", sku AS "productSKU", '-' AS "productBrand", id AS "productId",
|
|
146
|
+
SELECT packing_type, packing_size,'UNIT' AS "uom", name AS "productName", sku AS "productSKU", '-' AS "productBrand", id AS "productId", pbs.product_detail_id AS "productDetailId",
|
|
146
147
|
COALESCE(MIN(FLOOR(pbs."availableQty")),0) AS "remainQty",
|
|
147
148
|
COALESCE(MIN(FLOOR(pbs."availableUomValue")),0) AS "remainUomValue",
|
|
148
149
|
CONCAT(COALESCE(MIN(FLOOR(pbs."availableUomValue")),0),' UNIT') AS "remainUomValueWithUom",
|
|
@@ -151,7 +152,8 @@ export const InventoryUtil = {
|
|
|
151
152
|
LEFT JOIN (
|
|
152
153
|
SELECT pbs.product_id, pbs.product_bundle_id, min(pbs.bundle_qty),
|
|
153
154
|
(SUM(COALESCE(i2.qty, 0)) - SUM(COALESCE(i2.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0))) / min(pbs.bundle_qty) AS "availableQty",
|
|
154
|
-
(SUM(COALESCE(i2.uom_value, 0)) - SUM(COALESCE(i2.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty) AS "availableUomValue"
|
|
155
|
+
(SUM(COALESCE(i2.uom_value, 0)) - SUM(COALESCE(i2.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty) AS "availableUomValue",
|
|
156
|
+
pbs.product_detail_id
|
|
155
157
|
FROM product_bundle_settings pbs
|
|
156
158
|
LEFT JOIN inventories i2 ON i2.product_id = pbs.product_id AND i2.domain_id = $1 AND i2.status = 'STORED'
|
|
157
159
|
INNER JOIN locations l2 ON i2.location_id = l2.id
|
|
@@ -160,25 +162,28 @@ export const InventoryUtil = {
|
|
|
160
162
|
${inventoryBizplaceFilter ? `AND i2.bizplace_id = '${inventoryBizplaceFilter.value}'` : ``}
|
|
161
163
|
GROUP BY
|
|
162
164
|
pbs.product_id,
|
|
163
|
-
pbs.product_bundle_id
|
|
165
|
+
pbs.product_bundle_id,
|
|
166
|
+
pbs.product_detail_id
|
|
164
167
|
) pbs ON pbs.product_bundle_id = pb.id
|
|
165
168
|
${bundleWhereClause}
|
|
166
169
|
AND pb.bizplace_id IN (${bizplaceIds})
|
|
167
|
-
${
|
|
168
|
-
|
|
170
|
+
${
|
|
171
|
+
productFilter
|
|
172
|
+
? `AND (
|
|
169
173
|
lower(pb.sku) ilike '${productFilter.value}'
|
|
170
174
|
OR lower(pb.name) ilike '${productFilter.value}'
|
|
171
175
|
OR lower(pb.description) ilike '${productFilter.value}'
|
|
172
176
|
)
|
|
173
177
|
`
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
: ``
|
|
179
|
+
}
|
|
176
180
|
GROUP BY
|
|
177
181
|
pb.packing_type,
|
|
178
182
|
pb.packing_size,
|
|
179
183
|
pb.name,
|
|
180
184
|
pb.sku,
|
|
181
|
-
pb.id
|
|
185
|
+
pb.id,
|
|
186
|
+
pbs.product_detail_id
|
|
182
187
|
)
|
|
183
188
|
AS inv_prod_grp
|
|
184
189
|
${whereClause}
|
|
@@ -273,6 +278,7 @@ export const InventoryUtil = {
|
|
|
273
278
|
coalesce(p.sku, '') AS "productSKU",
|
|
274
279
|
coalesce(p.brand, '') AS "productBrand",
|
|
275
280
|
p.id AS "productId",
|
|
281
|
+
i.product_detail_id AS "productDetailId",
|
|
276
282
|
SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)) AS "remainQty",
|
|
277
283
|
SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) AS "remainUomValue",
|
|
278
284
|
concat(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)), ' ', i.uom) AS "remainUomValueWithUom",
|
|
@@ -292,6 +298,7 @@ export const InventoryUtil = {
|
|
|
292
298
|
AND l2.type NOT IN ('${LOCATION_TYPE.QUARANTINE}', '${LOCATION_TYPE.RESERVE}')
|
|
293
299
|
${productWhereClause}
|
|
294
300
|
GROUP BY
|
|
301
|
+
i.product_detail_id,
|
|
295
302
|
i.batch_id,
|
|
296
303
|
i.batch_id_ref,
|
|
297
304
|
p.id,
|
|
@@ -299,7 +306,7 @@ export const InventoryUtil = {
|
|
|
299
306
|
i.packing_size,
|
|
300
307
|
i.uom
|
|
301
308
|
UNION
|
|
302
|
-
SELECT 'BUNDLE' AS "batchId", null as "batchIdRef", packing_type, packing_size,'UNIT' AS "uom", name AS "productName", sku AS "productSKU", 'brand' AS "productBrand", id AS "productId",
|
|
309
|
+
SELECT 'BUNDLE' AS "batchId", null as "batchIdRef", packing_type, packing_size,'UNIT' AS "uom", name AS "productName", sku AS "productSKU", 'brand' AS "productBrand", id AS "productId", pbs.product_detail_id AS "productDetailId",
|
|
303
310
|
MIN(FLOOR(pbs."availableQty")) AS "remainQty",
|
|
304
311
|
MIN(FLOOR(pbs."availableUomValue")) AS "remainUomValue",
|
|
305
312
|
CONCAT(MIN(FLOOR(pbs."availableUomValue")),' UNIT') AS "remainUomValueWithUom",
|
|
@@ -308,16 +315,17 @@ export const InventoryUtil = {
|
|
|
308
315
|
INNER JOIN (
|
|
309
316
|
SELECT pbs.product_id, pbs.product_bundle_id, min(pbs.bundle_qty),
|
|
310
317
|
(SUM(COALESCE(i2.qty, 0)) - SUM(COALESCE(i2.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0))) / min(pbs.bundle_qty) AS "availableQty",
|
|
311
|
-
(SUM(COALESCE(i2.uom_value, 0)) - SUM(COALESCE(i2.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty) AS "availableUomValue"
|
|
318
|
+
(SUM(COALESCE(i2.uom_value, 0)) - SUM(COALESCE(i2.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty) AS "availableUomValue",
|
|
319
|
+
pbs.product_detail_id
|
|
312
320
|
FROM product_bundle_settings pbs
|
|
313
321
|
LEFT JOIN inventories i2 ON i2.product_id = pbs.product_id AND i2.domain_id = $1
|
|
314
322
|
AND i2.bizplace_id IN (${bizplaceIds})
|
|
315
323
|
AND i2.status = 'STORED'
|
|
316
324
|
LEFT JOIN oi ON oi.product_id = i2.product_id
|
|
317
|
-
GROUP BY pbs.product_id, pbs.product_bundle_id
|
|
325
|
+
GROUP BY pbs.product_id, pbs.product_bundle_id, pbs.product_detail_id
|
|
318
326
|
) pbs ON pbs.product_bundle_id = pb.id
|
|
319
327
|
${bundleWhereClause}
|
|
320
|
-
GROUP BY pb.packing_type, pb.packing_size, pb.name, pb.sku, pb.id
|
|
328
|
+
GROUP BY pb.packing_type, pb.packing_size, pb.name, pb.sku, pb.id, pbs.product_detail_id
|
|
321
329
|
)
|
|
322
330
|
AS inv_prod_grp
|
|
323
331
|
${whereClause}
|
|
@@ -357,13 +365,15 @@ export const InventoryUtil = {
|
|
|
357
365
|
|
|
358
366
|
if (params?.pagination) {
|
|
359
367
|
items = await trxMgr.query(
|
|
360
|
-
`select * from temp_inventory_product_group ${filterGroupTypeQuery ? filterGroupTypeQuery : ''} ${
|
|
368
|
+
`select * from temp_inventory_product_group ${filterGroupTypeQuery ? filterGroupTypeQuery : ''} ${
|
|
369
|
+
sortingArr.length > 0 ? ' Order by ' + sortedBy.toString() : ''
|
|
361
370
|
} OFFSET $1 LIMIT $2`,
|
|
362
371
|
[(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]
|
|
363
372
|
)
|
|
364
373
|
} else {
|
|
365
374
|
items = await trxMgr.query(
|
|
366
|
-
`select * from temp_inventory_product_group ${filterGroupTypeQuery ? filterGroupTypeQuery : ''} ${
|
|
375
|
+
`select * from temp_inventory_product_group ${filterGroupTypeQuery ? filterGroupTypeQuery : ''} ${
|
|
376
|
+
sortingArr.length > 0 ? ' Order by ' + sortedBy.toString() : ''
|
|
367
377
|
}`
|
|
368
378
|
)
|
|
369
379
|
}
|
|
@@ -486,9 +496,8 @@ export const InventoryUtil = {
|
|
|
486
496
|
let json_oi = JSON.stringify(
|
|
487
497
|
orderInventories.map(x => {
|
|
488
498
|
return {
|
|
489
|
-
|
|
499
|
+
product_detail_id: x.productDetail.id,
|
|
490
500
|
batch_id: x.batchId,
|
|
491
|
-
packing_type: x.packingType,
|
|
492
501
|
release_qty: x.releaseQty,
|
|
493
502
|
uom: x.uom
|
|
494
503
|
}
|
|
@@ -497,15 +506,14 @@ export const InventoryUtil = {
|
|
|
497
506
|
|
|
498
507
|
let resultQb = await trxMgr.query(
|
|
499
508
|
`
|
|
500
|
-
select joi.
|
|
509
|
+
select joi.product_detail_id as "productDetailId", joi.batch_id as "batchId", joi.uom as "uom", joi.release_qty as "releaseQty",
|
|
501
510
|
sum(i.qty - coalesce(i.locked_qty,0)) - coalesce(
|
|
502
511
|
(
|
|
503
512
|
select sum(oi.release_qty) from order_inventories oi
|
|
504
513
|
where (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
505
514
|
and oi.inventory_id IS null
|
|
506
|
-
and oi.
|
|
515
|
+
and oi.product_detail_id = joi.product_detail_id
|
|
507
516
|
and oi.batch_id = joi.batch_id
|
|
508
|
-
and oi.packing_type = joi.packing_type
|
|
509
517
|
and oi.uom = joi.uom
|
|
510
518
|
and oi.domain_id = $1
|
|
511
519
|
and oi.bizplace_id = $2
|
|
@@ -515,21 +523,20 @@ export const InventoryUtil = {
|
|
|
515
523
|
select sum(oi.release_uom_value) from order_inventories oi
|
|
516
524
|
where (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
517
525
|
and oi.inventory_id IS null
|
|
518
|
-
and oi.
|
|
526
|
+
and oi.product_detail_id = joi.product_detail_id
|
|
519
527
|
and oi.batch_id = joi.batch_id
|
|
520
|
-
and oi.packing_type = joi.packing_type
|
|
521
528
|
and oi.uom = joi.uom
|
|
522
529
|
and oi.domain_id = $1
|
|
523
530
|
and oi.bizplace_id = $2
|
|
524
531
|
),0) as "availableUomValue"
|
|
525
532
|
from json_populate_recordset(NULL::order_inventories,'${json_oi}') joi
|
|
526
|
-
left join inventories i on joi.
|
|
533
|
+
left join inventories i on joi.product_detail_id = i.product_detail_id
|
|
527
534
|
and joi.batch_id = i.batch_id
|
|
528
|
-
and
|
|
535
|
+
and i.status ='STORED'
|
|
529
536
|
and joi.uom = i.uom
|
|
530
537
|
and i.domain_id = $1
|
|
531
538
|
and i.bizplace_id = $2
|
|
532
|
-
group by joi.
|
|
539
|
+
group by joi.product_detail_id, joi.batch_id, joi.packing_type, joi.release_qty, joi.uom
|
|
533
540
|
`,
|
|
534
541
|
[warehouseDomain.id, partnerBizplace.id]
|
|
535
542
|
)
|
|
@@ -575,9 +582,9 @@ export const InventoryUtil = {
|
|
|
575
582
|
* @returns orderInventories
|
|
576
583
|
*/
|
|
577
584
|
async autoAssignInventoryForRelease(
|
|
578
|
-
product: Product,
|
|
579
585
|
orderInventory: OrderInventory,
|
|
580
|
-
|
|
586
|
+
product: Product,
|
|
587
|
+
productDetail: ProductDetail,
|
|
581
588
|
locationSortingRules: any = [],
|
|
582
589
|
customerBizplace: Bizplace,
|
|
583
590
|
domain: Domain,
|
|
@@ -588,16 +595,14 @@ export const InventoryUtil = {
|
|
|
588
595
|
qb.leftJoinAndSelect('iv.location', 'loc')
|
|
589
596
|
.andWhere('"iv"."domain_id" = :domainId')
|
|
590
597
|
.andWhere('"iv"."bizplace_id" = :bizplaceId')
|
|
591
|
-
.andWhere('"iv"."
|
|
592
|
-
.andWhere('"iv"."product_id" = :productId')
|
|
598
|
+
.andWhere('"iv"."product_detail_id" = :productDetailId')
|
|
593
599
|
.andWhere('"iv"."status" = :status')
|
|
594
600
|
.andWhere('"iv"."qty" - COALESCE("iv"."locked_qty", 0) > 0')
|
|
595
601
|
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
596
602
|
.setParameters({
|
|
597
603
|
domainId: domain.id,
|
|
598
604
|
bizplaceId: customerBizplace.id,
|
|
599
|
-
|
|
600
|
-
productId: product.id,
|
|
605
|
+
productDetailId: productDetail.id,
|
|
601
606
|
status: INVENTORY_STATUS.STORED,
|
|
602
607
|
locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
|
|
603
608
|
})
|
|
@@ -659,7 +664,7 @@ export const InventoryUtil = {
|
|
|
659
664
|
}
|
|
660
665
|
})
|
|
661
666
|
|
|
662
|
-
return _composeTargetInventories(
|
|
667
|
+
return _composeTargetInventories(productDetail, orderInventory, inventories)
|
|
663
668
|
},
|
|
664
669
|
|
|
665
670
|
/**
|
|
@@ -851,31 +856,32 @@ async function getConditions(
|
|
|
851
856
|
case 'batch_product':
|
|
852
857
|
productWhereClause += `
|
|
853
858
|
AND (i.batch_id, p.id, i.packing_type, i.packing_size) ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
+
.map(
|
|
860
|
+
(v: { batchId: string; productId: string; packingType: string; packingSize: string }) =>
|
|
861
|
+
`('${v.batchId}', '${v.productId}', '${v.packingType}', '${v.packingSize}')`
|
|
862
|
+
)
|
|
863
|
+
.join()})
|
|
859
864
|
`
|
|
860
865
|
break
|
|
861
866
|
|
|
862
867
|
case 'batch_bundle':
|
|
863
868
|
bundleWhereClause += `
|
|
864
869
|
${bundleWhereClause == '' ? 'WHERE' : 'AND'} pb.id ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
|
|
865
|
-
|
|
866
|
-
|
|
870
|
+
.map((v: { productId: string }) => `('${v.productId}')`)
|
|
871
|
+
.join()})
|
|
867
872
|
`
|
|
868
873
|
break
|
|
869
874
|
|
|
870
875
|
case 'product':
|
|
871
876
|
productDetailWhereClause += `
|
|
872
|
-
AND (pd.product_id, pd.packing_type, pd.packing_size, pd.uom) ${
|
|
877
|
+
AND (pd.product_id, pd.packing_type, pd.packing_size, pd.uom) ${
|
|
878
|
+
operator === 'in' ? 'IN' : 'NOT IN'
|
|
873
879
|
} (${value
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
880
|
+
.map(
|
|
881
|
+
(v: { productId: string; packingType: string; packingSize: string; uom: string }) =>
|
|
882
|
+
`('${v.productId}', '${v.packingType}', '${v.packingSize}', '${v.uom}')`
|
|
883
|
+
)
|
|
884
|
+
.join()})
|
|
879
885
|
`
|
|
880
886
|
break
|
|
881
887
|
}
|
|
@@ -927,98 +933,6 @@ async function updateInventory(
|
|
|
927
933
|
return await trxMgr.getRepository(Inventory).save(inventory)
|
|
928
934
|
}
|
|
929
935
|
|
|
930
|
-
async function generateInventoryHistory(
|
|
931
|
-
inventory: Inventory,
|
|
932
|
-
refOrder: any,
|
|
933
|
-
transactionType: string,
|
|
934
|
-
qty: number,
|
|
935
|
-
uomValue: number,
|
|
936
|
-
user: User,
|
|
937
|
-
trxMgr?: EntityManager
|
|
938
|
-
): Promise<InventoryHistory> {
|
|
939
|
-
const invHistoryRepo: Repository<InventoryHistory> =
|
|
940
|
-
trxMgr?.getRepository(InventoryHistory) || getRepository(InventoryHistory)
|
|
941
|
-
const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)
|
|
942
|
-
|
|
943
|
-
if (!inventory?.id) throw new Error(`Can't find out ID of inventory.`)
|
|
944
|
-
if (!refOrder?.id || !refOrder.name) throw new Error(`Can't find out ID or Name of Reference Order`)
|
|
945
|
-
if (
|
|
946
|
-
!inventory?.domain ||
|
|
947
|
-
!inventory?.bizplace ||
|
|
948
|
-
!inventory?.product?.id ||
|
|
949
|
-
!inventory?.warehouse?.id ||
|
|
950
|
-
!inventory?.location?.id
|
|
951
|
-
) {
|
|
952
|
-
inventory = await invRepo.findOne({
|
|
953
|
-
where: { id: inventory.id },
|
|
954
|
-
relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']
|
|
955
|
-
})
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
const domain: Domain = inventory.domain
|
|
959
|
-
const location: Location = inventory.location
|
|
960
|
-
|
|
961
|
-
const seq: number = await invHistoryRepo.count({ domain: inventory.domain, palletId: inventory.palletId })
|
|
962
|
-
let openingQty: number = 0
|
|
963
|
-
let openingUomValue: number = 0
|
|
964
|
-
|
|
965
|
-
if (seq) {
|
|
966
|
-
const lastInvHistory: InventoryHistory = await invHistoryRepo.findOne({
|
|
967
|
-
domain: inventory.domain,
|
|
968
|
-
palletId: inventory.palletId,
|
|
969
|
-
seq: seq - 1
|
|
970
|
-
})
|
|
971
|
-
openingQty = lastInvHistory.openingQty + lastInvHistory.qty
|
|
972
|
-
openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
let inventoryHistory: InventoryHistory = new InventoryHistory()
|
|
976
|
-
inventoryHistory.name = InventoryNoGenerator.inventoryHistoryName()
|
|
977
|
-
inventoryHistory.description = inventory.description
|
|
978
|
-
inventoryHistory.seq = seq
|
|
979
|
-
inventoryHistory.palletId = inventory.palletId
|
|
980
|
-
inventoryHistory.cartonId = inventory.cartonId
|
|
981
|
-
inventoryHistory.batchId = inventory.batchId
|
|
982
|
-
inventoryHistory.batchIdRef = inventory.batchIdRef
|
|
983
|
-
inventoryHistory.status = inventory.status
|
|
984
|
-
inventoryHistory.transactionType = transactionType
|
|
985
|
-
inventoryHistory.refOrderId = refOrder?.id || null
|
|
986
|
-
inventoryHistory.orderNo = refOrder?.name || null
|
|
987
|
-
inventoryHistory.orderRefNo = refOrder?.refNo || null
|
|
988
|
-
inventoryHistory.inventory = inventory
|
|
989
|
-
inventoryHistory.product = inventory.product
|
|
990
|
-
inventoryHistory.reusablePallet = inventory.reusablePallet
|
|
991
|
-
inventoryHistory.zone = inventory.zone
|
|
992
|
-
inventoryHistory.warehouse = inventory.warehouse
|
|
993
|
-
inventoryHistory.location = inventory.location
|
|
994
|
-
inventoryHistory.expirationDate = inventory.expirationDate
|
|
995
|
-
inventoryHistory.packingType = inventory.packingType
|
|
996
|
-
inventoryHistory.packingSize = inventory.packingSize
|
|
997
|
-
inventoryHistory.uom = inventory.uom
|
|
998
|
-
inventoryHistory.qty = qty
|
|
999
|
-
inventoryHistory.openingQty = openingQty
|
|
1000
|
-
inventoryHistory.uomValue = uomValue
|
|
1001
|
-
inventoryHistory.openingUomValue = openingUomValue
|
|
1002
|
-
inventoryHistory.unitCost = inventory.unitCost
|
|
1003
|
-
inventoryHistory.domain = inventory.domain
|
|
1004
|
-
inventoryHistory.bizplace = inventory.bizplace
|
|
1005
|
-
inventoryHistory.creator = user
|
|
1006
|
-
inventoryHistory.updater = user
|
|
1007
|
-
|
|
1008
|
-
inventoryHistory = await invHistoryRepo.save(inventoryHistory)
|
|
1009
|
-
|
|
1010
|
-
if (inventory.lastSeq !== seq) {
|
|
1011
|
-
await invRepo.save({
|
|
1012
|
-
...inventory,
|
|
1013
|
-
lastSeq: inventoryHistory.seq,
|
|
1014
|
-
updater: user
|
|
1015
|
-
})
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
await switchLocationStatus(domain, location, user, trxMgr)
|
|
1019
|
-
return inventoryHistory
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
936
|
/**
|
|
1023
937
|
* @description: Check location emptiness and update status of location
|
|
1024
938
|
* @param domain
|
|
@@ -1057,12 +971,17 @@ export async function switchLocationStatus(
|
|
|
1057
971
|
return location
|
|
1058
972
|
}
|
|
1059
973
|
|
|
1060
|
-
export function _composeTargetInventories(
|
|
974
|
+
export function _composeTargetInventories(
|
|
975
|
+
productDetail: ProductDetail,
|
|
976
|
+
record: any,
|
|
977
|
+
inventories: Inventory[]
|
|
978
|
+
): OrderInventory[] {
|
|
1061
979
|
let leftReleaseQty: number = record.releaseQty
|
|
1062
980
|
let leftReleaseUomValue: number = record.releaseUomValue
|
|
1063
981
|
let compReleaseQty: number = 0
|
|
1064
982
|
let compReleaseUomValue: number = 0
|
|
1065
983
|
let totalInventoryQty: number = inventories.reduce((total, inventory) => total + inventory.remainQty, 0)
|
|
984
|
+
let product = productDetail.product
|
|
1066
985
|
|
|
1067
986
|
if (totalInventoryQty < record.releaseQty) {
|
|
1068
987
|
throw new Error(`invalid release qty for ${product?.sku}`)
|
|
@@ -1115,6 +1034,7 @@ export function _composeTargetInventories(product: Product, record: any, invento
|
|
|
1115
1034
|
batchIdRef,
|
|
1116
1035
|
uom,
|
|
1117
1036
|
product,
|
|
1037
|
+
productDetail,
|
|
1118
1038
|
type: ORDER_TYPES.RELEASE_OF_GOODS
|
|
1119
1039
|
})
|
|
1120
1040
|
|