Add audited Graphs stock balances
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m33s

This commit is contained in:
Cauê Faleiros
2026-08-24 14:34:25 -03:00
parent 71c80fd5d4
commit 7e18772a8a
7 changed files with 450 additions and 20 deletions

View File

@@ -285,9 +285,10 @@ const listProjectDemandRows = async () => {
COALESCE(period_orders.produto_id, stock.produto_id) AS product_id,
COALESCE(NULLIF(period_orders.product_name, ''), NULLIF(stock.nome, ''), 'Produto sem nome') AS product_name,
COALESCE(period_orders.quantity_sold, 0)::numeric AS quantity_sold,
COALESCE(stock.saldo, 0)::numeric AS stock_quantity
COALESCE(graphs.balance, stock.saldo, 0)::numeric AS stock_quantity
FROM period_orders
FULL OUTER JOIN stock ON stock.produto_id = period_orders.produto_id
LEFT JOIN stock_graphs_balances graphs ON graphs.produto_id = stock.produto_id
WHERE COALESCE(period_orders.produto_id, stock.produto_id, '') <> ''
ORDER BY quantity_sold DESC, product_name;
`, [DEFAULT_SUPPLY_LOOKBACK_DAYS]);
@@ -356,9 +357,15 @@ const listCompositionRows = async () => {
const listTinyStockRows = async () => {
const result = await pool.query(`
SELECT produto_id, nome, COALESCE(saldo, 0)::numeric AS saldo
SELECT
stock.produto_id,
stock.nome,
COALESCE(stock.saldo, 0)::numeric AS tiny_saldo,
graphs.balance::numeric AS graphs_balance,
COALESCE(graphs.balance, stock.saldo, 0)::numeric AS saldo
FROM stock
WHERE COALESCE(produto_id, '') <> '' OR COALESCE(nome, '') <> '';
LEFT JOIN stock_graphs_balances graphs ON graphs.produto_id = stock.produto_id
WHERE COALESCE(stock.produto_id, '') <> '' OR COALESCE(stock.nome, '') <> '';
`);
return result.rows;
};