Skip to content

Commit ee51cb7

Browse files
committed
fix: division by zero error
1 parent 40120c7 commit ee51cb7

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

app/Models/DailyChange.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ public function scopeWithDailyPerformance($query)
9999
'tx1.quantity',
100100
])
101101
->selectRaw("(CASE
102-
WHEN tx1.transaction_type = 'BUY'
103-
THEN COALESCE(cr.rate, 1)
102+
WHEN
103+
tx1.transaction_type = 'BUY'
104+
OR SUM(tx1.cost_basis_base) = 0
105+
THEN
106+
COALESCE(cr.rate, 1)
104107
ELSE (
105108
SELECT
106109
SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base)

app/Models/Holding.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,11 @@ public function scopeWithPortfolioMetrics($query, $currency = null): mixed
302302
])
303303
->selectRaw(
304304
"(CASE
305-
WHEN transactions.transaction_type = 'BUY'
306-
THEN COALESCE(cr.rate, 1)
305+
WHEN
306+
transactions.transaction_type = 'BUY'
307+
OR SUM(transactions.cost_basis_base) = 0
308+
THEN
309+
COALESCE(cr.rate, 1)
307310
ELSE (
308311
SELECT
309312
SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base)

0 commit comments

Comments
 (0)