diff --git a/lib/customers.js b/lib/customers.js index 897e722d..fc5caa21 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -468,11 +468,11 @@ function getCustomersList () { c.sanctions_at, c.sanctions_override, t.tx_class, t.fiat, t.fiat_code, t.created, row_number() over (partition by c.id order by t.created desc) as rn, sum(case when t.id is not null then 1 else 0 end) over (partition by c.id) as total_txs, - coalesce(sum(t.fiat) over (partition by c.id), 0) as total_spent + coalesce(sum(case when error_code is distinct from 'operatorCancel' then t.fiat else 0 end) over (partition by c.id), 0) as total_spent from customers c left outer join ( - select 'cashIn' as tx_class, id, fiat, fiat_code, created, customer_id + select 'cashIn' as tx_class, id, fiat, fiat_code, created, customer_id, error_code from cash_in_txs where send_confirmed = true union - select 'cashOut' as tx_class, id, fiat, fiat_code, created, customer_id + select 'cashOut' as tx_class, id, fiat, fiat_code, created, customer_id, error_code from cash_out_txs where confirmed_at is not null) t on c.id = t.customer_id where c.id != $1 ) as cl where rn = 1 @@ -507,11 +507,11 @@ function getCustomerById (id) { c.sanctions_at, c.sanctions_override, t.tx_class, t.fiat, t.fiat_code, t.created, row_number() over (partition by c.id order by t.created desc) as rn, sum(case when t.id is not null then 1 else 0 end) over (partition by c.id) as total_txs, - sum(t.fiat) over (partition by c.id) as total_spent + sum(case when error_code is distinct from 'operatorCancel' then t.fiat else 0 end) over (partition by c.id) as total_spent from customers c left outer join ( - select 'cashIn' as tx_class, id, fiat, fiat_code, created, customer_id + select 'cashIn' as tx_class, id, fiat, fiat_code, created, customer_id, error_code from cash_in_txs where send_confirmed = true union - select 'cashOut' as tx_class, id, fiat, fiat_code, created, customer_id + select 'cashOut' as tx_class, id, fiat, fiat_code, created, customer_id, error_code from cash_out_txs where confirmed_at is not null) t on c.id = t.customer_id where c.id = $1 ) as cl where rn = 1`