diff --git a/app/Models/DailyChange.php b/app/Models/DailyChange.php index 8adf726..b574d4b 100644 --- a/app/Models/DailyChange.php +++ b/app/Models/DailyChange.php @@ -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) diff --git a/app/Models/Holding.php b/app/Models/Holding.php index ad53740..6ffa077 100644 --- a/app/Models/Holding.php +++ b/app/Models/Holding.php @@ -302,8 +302,11 @@ class Holding extends Model ]) ->selectRaw( "(CASE - WHEN transactions.transaction_type = 'BUY' - THEN COALESCE(cr.rate, 1) + WHEN + transactions.transaction_type = 'BUY' + OR SUM(transactions.cost_basis_base) = 0 + THEN + COALESCE(cr.rate, 1) ELSE ( SELECT SUM(COALESCE(cr2.rate, 1) * buy.cost_basis_base)