From dc1042e73676fde51e3e95739445cc42ea0e12ff Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Thu, 19 Sep 2024 21:32:10 -0500 Subject: [PATCH] update realized gain calculation --- app/Models/Holding.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Holding.php b/app/Models/Holding.php index c80caa6..479e9ef 100644 --- a/app/Models/Holding.php +++ b/app/Models/Holding.php @@ -210,7 +210,7 @@ class Holding extends Model 'quantity' => $total_quantity, 'average_cost_basis' => $average_cost_basis, 'total_cost_basis' => $total_quantity * $average_cost_basis, - 'realized_gain_dollars' => $query->total_sale_price > 0 ? $query->total_sale_price - $query->total_cost_basis : 0, + 'realized_gain_dollars' => $query->total_sale_price > 0 ? $query->total_sale_price - ($query->qty_sales * ($query->total_cost_basis / $query->qty_purchases)) : 0, 'dividends_earned' => $dividends->sum('total_received') ]);