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', 'tx1.quantity',
]) ])
->selectRaw("(CASE ->selectRaw("(CASE
WHEN tx1.transaction_type = 'BUY' WHEN
THEN COALESCE(cr.rate, 1) tx1.transaction_type = 'BUY'
OR SUM(tx1.cost_basis_base) = 0
THEN
COALESCE(cr.rate, 1)
ELSE ( ELSE (
SELECT SELECT
SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base) SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base)
+5 -2
View File
@@ -302,8 +302,11 @@ class Holding extends Model
]) ])
->selectRaw( ->selectRaw(
"(CASE "(CASE
WHEN transactions.transaction_type = 'BUY' WHEN
THEN COALESCE(cr.rate, 1) transactions.transaction_type = 'BUY'
OR SUM(transactions.cost_basis_base) = 0
THEN
COALESCE(cr.rate, 1)
ELSE ( ELSE (
SELECT SELECT
SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base) SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base)