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