From 83abdd41692f2c857ec9b7030888aba7d4658b39 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Wed, 18 Sep 2024 22:42:09 -0500 Subject: [PATCH] wip --- app/Models/Holding.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Holding.php b/app/Models/Holding.php index 7b497bb..6860080 100644 --- a/app/Models/Holding.php +++ b/app/Models/Holding.php @@ -173,7 +173,7 @@ class Holding extends Model 'symbol' => $this->symbol, ])->selectRaw('SUM(CASE WHEN transaction_type = "BUY" THEN quantity ELSE 0 END) AS `qty_purchases`') ->selectRaw('SUM(CASE WHEN transaction_type = "SELL" THEN quantity ELSE 0 END) AS `qty_sales`') - ->selectRaw('SUM(CASE WHEN transaction_type = "BUY" THEN (quantity * cost_basis) ELSE 0 END) AS `cost_basis`') + ->selectRaw('SUM(CASE WHEN transaction_type = "BUY" THEN (quantity * cost_basis) ELSE 0 END) AS `total_cost_basis`') ->selectRaw('SUM(CASE WHEN transaction_type = "SELL" THEN ((sale_price - cost_basis) * quantity) ELSE 0 END) AS `realized_gains`') ->first(); @@ -183,7 +183,7 @@ class Holding extends Model $query->qty_purchases > 0 && $total_quantity > 0 ) - ? $query->cost_basis / $query->qty_purchases + ? $query->total_cost_basis / $query->qty_purchases : 0; // pull dividend data joined with holdings/transactions