fix: division by zero error

This commit is contained in:
hackerESQ
2025-07-12 00:40:37 -05:00
parent 40120c7027
commit ee51cb7e2a
2 changed files with 10 additions and 4 deletions
+5 -2
View File
@@ -99,8 +99,11 @@ class DailyChange extends Model
'tx1.quantity',
])
->selectRaw("(CASE
WHEN tx1.transaction_type = 'BUY'
THEN COALESCE(cr.rate, 1)
WHEN
tx1.transaction_type = 'BUY'
OR SUM(tx1.cost_basis_base) = 0
THEN
COALESCE(cr.rate, 1)
ELSE (
SELECT
SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base)