@things-factory/warehouse-base 4.3.677 → 4.3.679
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/inventory-change/inventory-change-mutation.js +52 -27
- package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-query.js +96 -105
- package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -1
- package/package.json +2 -2
- package/server/service/inventory-change/inventory-change-mutation.ts +59 -30
- package/server/service/inventory-history/inventory-history-query.ts +96 -107
|
@@ -235,7 +235,8 @@ export class InventoryHistoryQuery {
|
|
|
235
235
|
OR Lower(prd.description) LIKE ANY(ARRAY[${productValue}])
|
|
236
236
|
OR Lower(prd.brand) LIKE ANY(ARRAY[${productValue}])
|
|
237
237
|
OR Lower(prd.brand_sku) LIKE ANY(ARRAY[${productValue}])
|
|
238
|
-
)
|
|
238
|
+
)
|
|
239
|
+
`
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
let productDescQuery = ''
|
|
@@ -247,12 +248,11 @@ export class InventoryHistoryQuery {
|
|
|
247
248
|
if (hasTransactionOrBalanceFilter && hasTransactionOrBalanceFilter.value) {
|
|
248
249
|
hasTransactionOrBalanceQuery = 'and (src.totalRow > 1 or src.totalQty <> 0)'
|
|
249
250
|
}
|
|
250
|
-
|
|
251
251
|
await tx.query(
|
|
252
252
|
`
|
|
253
253
|
create temp table temp_products AS
|
|
254
254
|
(
|
|
255
|
-
select prd
|
|
255
|
+
select prd.id, prd.sku, prd.name, prd.description, prd.type, prd.aux_value_1 from products prd
|
|
256
256
|
inner join bizplaces b on b.id = prd.bizplace_id
|
|
257
257
|
inner join companies c on c.domain_id = b.domain_id
|
|
258
258
|
inner join bizplaces b2 on b2.company_id = c.id
|
|
@@ -261,20 +261,20 @@ export class InventoryHistoryQuery {
|
|
|
261
261
|
)`,
|
|
262
262
|
[bizplace.id]
|
|
263
263
|
)
|
|
264
|
-
|
|
265
264
|
await tx.query(
|
|
266
265
|
`
|
|
267
266
|
create temp table temp_data_src AS
|
|
268
267
|
(
|
|
269
268
|
SELECT prd.sku as sku, prd.name AS product_name, prd.description AS product_description, prd.type as product_type, prd.aux_value_1 AS product_aux_value_1, trim(invh.batch_id) as batch_id, invh.product_id,
|
|
270
|
-
invh.packing_type, invh.bizplace_id,
|
|
271
|
-
invh.
|
|
269
|
+
invh.packing_type, invh.bizplace_id,
|
|
270
|
+
invh.order_no, invh.order_ref_no, invh.transaction_type, invh.status, invh.created_at,
|
|
272
271
|
TRUNC(CAST(invh.qty AS NUMERIC), 3) as qty, TRUNC(CAST(invh.opening_qty AS NUMERIC), 3) as opening_qty,
|
|
273
272
|
invh.uom, TRUNC(CAST(COALESCE(invh.uom_value, 0) AS NUMERIC), 3) as uom_value, TRUNC(CAST(COALESCE(invh.opening_uom_value, 0) AS NUMERIC), 3) as opening_uom_value
|
|
274
|
-
FROM
|
|
273
|
+
FROM inventory_histories invh
|
|
275
274
|
INNER JOIN temp_products prd ON prd.id = invh.product_id::uuid
|
|
276
275
|
WHERE
|
|
277
|
-
invh.
|
|
276
|
+
(invh.qty <> 0 OR invh.uom_value <> 0)
|
|
277
|
+
AND invh.domain_id = $1
|
|
278
278
|
AND invh.bizplace_id = $2
|
|
279
279
|
AND invh.created_at <= $3::timestamp
|
|
280
280
|
${batchNoQuery}
|
|
@@ -285,105 +285,94 @@ export class InventoryHistoryQuery {
|
|
|
285
285
|
|
|
286
286
|
await tx.query(
|
|
287
287
|
`
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
src.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
288
|
+
CREATE TEMP TABLE temp_inv_history AS (
|
|
289
|
+
SELECT
|
|
290
|
+
src.sku,
|
|
291
|
+
src.product_name,
|
|
292
|
+
src.product_description,
|
|
293
|
+
src.product_type,
|
|
294
|
+
src.product_aux_value_1,
|
|
295
|
+
src.batch_id,
|
|
296
|
+
src.product_id,
|
|
297
|
+
src.packing_type,
|
|
298
|
+
src.uom,
|
|
299
|
+
src.bizplace_id,
|
|
300
|
+
TRUNC(CAST(SUM(COALESCE(src.qty, 0)) AS NUMERIC), 3) AS qty,
|
|
301
|
+
TRUNC(CAST(SUM(COALESCE(src.opening_qty, 0)) AS NUMERIC), 3) AS opening_qty,
|
|
302
|
+
TRUNC(CAST(SUM(COALESCE(src.uom_value, 0)) AS NUMERIC), 3) AS uom_value,
|
|
303
|
+
TRUNC(CAST(SUM(COALESCE(src.opening_uom_value, 0)) AS NUMERIC), 3) AS opening_uom_value,
|
|
295
304
|
'Opening Balance' AS order_name,
|
|
296
305
|
'-' AS ref_no,
|
|
297
|
-
'-'
|
|
306
|
+
'-' AS transaction_type,
|
|
298
307
|
0 AS rn,
|
|
299
|
-
$1::timestamp AS created_at
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
src.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
308
|
+
$1::timestamp AS created_at
|
|
309
|
+
FROM temp_data_src src
|
|
310
|
+
WHERE src.created_at < $1::timestamp
|
|
311
|
+
GROUP BY
|
|
312
|
+
src.sku,
|
|
313
|
+
src.product_name,
|
|
314
|
+
src.product_description,
|
|
315
|
+
src.product_type,
|
|
316
|
+
src.product_aux_value_1,
|
|
317
|
+
src.batch_id,
|
|
318
|
+
src.product_id,
|
|
319
|
+
src.packing_type,
|
|
320
|
+
src.uom,
|
|
321
|
+
src.bizplace_id
|
|
322
|
+
|
|
323
|
+
UNION ALL
|
|
324
|
+
|
|
325
|
+
-- Part 2: All Inventory Movements (combined into a single scan)
|
|
326
|
+
-- This SELECT statement replaces the three separate UNION ALLs for
|
|
327
|
+
-- transaction movements, using CASE statements to handle different
|
|
328
|
+
-- transaction types and statuses in a single pass.
|
|
329
|
+
SELECT
|
|
330
|
+
sku,
|
|
331
|
+
product_name,
|
|
332
|
+
product_description,
|
|
333
|
+
product_type,
|
|
334
|
+
product_aux_value_1,
|
|
335
|
+
batch_id,
|
|
336
|
+
product_id,
|
|
337
|
+
packing_type,
|
|
338
|
+
uom,
|
|
339
|
+
bizplace_id,
|
|
340
|
+
TRUNC(CAST(SUM(
|
|
341
|
+
-- qty and uom_value logic for all cases combined
|
|
342
|
+
CASE
|
|
343
|
+
WHEN transaction_type = 'ADJUSTMENT' AND status = 'MISSING' THEN -opening_qty
|
|
344
|
+
ELSE qty
|
|
345
|
+
END
|
|
346
|
+
) AS NUMERIC), 3) AS qty,
|
|
347
|
+
TRUNC(CAST(SUM(opening_qty) AS NUMERIC), 3) AS opening_qty,
|
|
348
|
+
TRUNC(CAST(SUM(
|
|
349
|
+
CASE
|
|
350
|
+
WHEN transaction_type = 'ADJUSTMENT' AND status = 'MISSING' THEN -opening_uom_value
|
|
351
|
+
ELSE uom_value
|
|
352
|
+
END
|
|
353
|
+
) AS NUMERIC), 3) AS uom_value,
|
|
354
|
+
TRUNC(CAST(SUM(opening_uom_value) AS NUMERIC), 3) AS opening_uom_value,
|
|
335
355
|
CASE
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
(invh.transaction_type = 'ADJUSTMENT'
|
|
357
|
-
OR invh.transaction_type = 'PICKING'
|
|
358
|
-
OR invh.transaction_type = 'CANCEL_ORDER'
|
|
359
|
-
OR invh.transaction_type = 'NEW')
|
|
360
|
-
AND invh.created_at >= $1::timestamp
|
|
361
|
-
) AS inv_movement
|
|
362
|
-
GROUP BY
|
|
363
|
-
sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
364
|
-
domain_id, inv_movement.transaction_type,inv_movement.order_no,order_name, ref_no, rn, created_at
|
|
365
|
-
UNION ALL
|
|
366
|
-
SELECT sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
367
|
-
domain_id, TRUNC(CAST(sum(-opening_qty) AS NUMERIC), 3) as qty, TRUNC(CAST(sum(opening_qty) AS NUMERIC), 3) as opening_qty, TRUNC(CAST(sum(-opening_uom_value) AS NUMERIC), 3) as uom_value, TRUNC(CAST(sum(opening_uom_value) AS NUMERIC), 3) as opening_uom_value,
|
|
368
|
-
order_name, ref_no, transaction_type,1 AS rn, created_at - $2::interval as created_at, created_at::date as created_date
|
|
369
|
-
FROM (
|
|
370
|
-
SELECT invh.sku, invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.uom, invh.bizplace_id,
|
|
371
|
-
invh.domain_id,
|
|
372
|
-
invh.qty, invh.opening_qty, invh.uom_value, invh.opening_uom_value,
|
|
373
|
-
invh.transaction_type as transaction_type,
|
|
374
|
-
invh.transaction_type AS order_name,
|
|
375
|
-
invh.transaction_type AS ref_no,
|
|
376
|
-
invh.created_at,
|
|
377
|
-
invh.created_at:: date as created_date
|
|
378
|
-
FROM temp_data_src invh
|
|
379
|
-
WHERE
|
|
380
|
-
invh.transaction_type = 'ADJUSTMENT'
|
|
381
|
-
AND invh.status = 'MISSING'
|
|
382
|
-
AND invh.created_at >= $1::timestamp
|
|
383
|
-
) AS inv_movement
|
|
384
|
-
GROUP BY sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
385
|
-
domain_id, order_name, ref_no, inv_movement.transaction_type,rn, created_at
|
|
386
|
-
)`,
|
|
356
|
+
WHEN transaction_type IN ('PICKING', 'CANCEL_ORDER') THEN order_no
|
|
357
|
+
WHEN transaction_type IN ('ADJUSTMENT', 'NEW') THEN transaction_type
|
|
358
|
+
ELSE COALESCE(order_no, '-')
|
|
359
|
+
END AS order_name,
|
|
360
|
+
CASE
|
|
361
|
+
WHEN transaction_type IN ('PICKING', 'CANCEL_ORDER') THEN order_ref_no
|
|
362
|
+
WHEN transaction_type IN ('ADJUSTMENT', 'NEW') THEN transaction_type
|
|
363
|
+
ELSE COALESCE(order_ref_no, '-')
|
|
364
|
+
END AS ref_no,
|
|
365
|
+
transaction_type,
|
|
366
|
+
1 AS rn,
|
|
367
|
+
MIN(created_at) - $2::interval AS created_at
|
|
368
|
+
FROM temp_data_src
|
|
369
|
+
WHERE
|
|
370
|
+
created_at >= $1::timestamp
|
|
371
|
+
GROUP BY
|
|
372
|
+
sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id,
|
|
373
|
+
packing_type, uom, bizplace_id,
|
|
374
|
+
order_name, ref_no, transaction_type
|
|
375
|
+
)`,
|
|
387
376
|
[fromDate.value, tzoffset]
|
|
388
377
|
)
|
|
389
378
|
|
|
@@ -393,7 +382,7 @@ export class InventoryHistoryQuery {
|
|
|
393
382
|
result = await tx.query(
|
|
394
383
|
`
|
|
395
384
|
select sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
396
|
-
|
|
385
|
+
qty, opening_qty, round(uom_value::decimal,2) as uom_value, opening_uom_value, order_name, ref_no, transaction_type,created_at::date
|
|
397
386
|
from temp_inv_history invh where
|
|
398
387
|
exists (
|
|
399
388
|
select 1 from (
|
|
@@ -410,10 +399,10 @@ export class InventoryHistoryQuery {
|
|
|
410
399
|
result = await tx.query(
|
|
411
400
|
`
|
|
412
401
|
select sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
413
|
-
|
|
402
|
+
sum(qty) as qty, sum(opening_qty) as opening_qty, sum(uom_value) as uom_value, sum(opening_uom_value) as opening_uom_value, order_name, ref_no, transaction_type, created_at::date
|
|
414
403
|
from(
|
|
415
404
|
select sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
416
|
-
|
|
405
|
+
qty, opening_qty, TRUNC(CAST(uom_value AS NUMERIC), 3) as uom_value, opening_uom_value, order_name, ref_no, transaction_type,created_at
|
|
417
406
|
from temp_inv_history invh where
|
|
418
407
|
exists (
|
|
419
408
|
select 1 from (
|
|
@@ -425,7 +414,7 @@ export class InventoryHistoryQuery {
|
|
|
425
414
|
)
|
|
426
415
|
) foo
|
|
427
416
|
GROUP BY sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
428
|
-
|
|
417
|
+
order_name, ref_no, transaction_type, created_at
|
|
429
418
|
ORDER BY sku asc, product_name asc, product_description asc, packing_type asc, batch_id asc, uom asc, created_at asc,
|
|
430
419
|
CASE
|
|
431
420
|
WHEN transaction_type = 'CANCEL_ORDER' THEN 2
|