diff --git a/lib/trust_level_repo.rb b/lib/trust_level_repo.rb index 61e9925483a5e835e7a7494163362b2aee62a7b2..74fbecbc8df820f3f34e4e97529ceff49647b264 100644 --- a/lib/trust_level_repo.rb +++ b/lib/trust_level_repo.rb @@ -27,7 +27,7 @@ protected def fetch_settled_amount(customer_id) db.query_one(<<~SQL, customer_id, default: {}) - SELECT SUM(amount) AS settled_amount FROM transactions + SELECT COALESCE(SUM(amount), 0) AS settled_amount FROM transactions WHERE customer_id=$1 AND settled_after < LOCALTIMESTAMP AND amount > 0 SQL end