wip
This commit is contained in:
@@ -15,10 +15,12 @@ class HoldingController extends Controller
|
|||||||
public function show(Request $request, Portfolio $portfolio, String $symbol)
|
public function show(Request $request, Portfolio $portfolio, String $symbol)
|
||||||
{
|
{
|
||||||
|
|
||||||
$holding = Holding::where([
|
$holding = $request->user()
|
||||||
'portfolio_id' => $portfolio->id,
|
->holdings()
|
||||||
'symbol' => $symbol
|
->where([
|
||||||
])->firstOrFail();
|
'holdings.portfolio_id' => $portfolio->id,
|
||||||
|
'holdings.symbol' => $symbol
|
||||||
|
])->firstOrFail();
|
||||||
|
|
||||||
$market_data = $holding->market_data;
|
$market_data = $holding->market_data;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ class Holding extends Model
|
|||||||
'dividends_synced_at' => 'datetime',
|
'dividends_synced_at' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $attributes = [
|
||||||
|
'realized_gain_dollars' => 0,
|
||||||
|
'dividends_earned' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Market data for holding
|
* Market data for holding
|
||||||
*
|
*
|
||||||
@@ -106,7 +111,7 @@ class Holding extends Model
|
|||||||
->selectRaw('@total_market_value:=COALESCE(SUM(holdings.quantity * market_data.market_value),0) AS total_market_value')
|
->selectRaw('@total_market_value:=COALESCE(SUM(holdings.quantity * market_data.market_value),0) AS total_market_value')
|
||||||
->selectRaw('@sum_total_cost_basis:=COALESCE(SUM(holdings.total_cost_basis),0) AS total_cost_basis')
|
->selectRaw('@sum_total_cost_basis:=COALESCE(SUM(holdings.total_cost_basis),0) AS total_cost_basis')
|
||||||
->selectRaw('@total_gain_dollars:=COALESCE((@total_market_value - @sum_total_cost_basis),0) AS total_gain_dollars')
|
->selectRaw('@total_gain_dollars:=COALESCE((@total_market_value - @sum_total_cost_basis),0) AS total_gain_dollars')
|
||||||
->selectRaw('COALESCE((@total_gain_dollars / @sum_total_cost_basis) * 100,0) AS total_gain_percent')
|
// ->selectRaw('COALESCE((@total_gain_dollars / @sum_total_cost_basis) * 100,0) AS total_gain_percent')
|
||||||
->join('market_data', 'market_data.symbol', 'holdings.symbol');
|
->join('market_data', 'market_data.symbol', 'holdings.symbol');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class Portfolio extends Model
|
|||||||
->withAggregate('market_data', 'updated_at')
|
->withAggregate('market_data', 'updated_at')
|
||||||
->selectRaw('COALESCE(market_data.market_value * holdings.quantity, 0) AS total_market_value')
|
->selectRaw('COALESCE(market_data.market_value * holdings.quantity, 0) AS total_market_value')
|
||||||
->selectRaw('COALESCE((market_data.market_value - holdings.average_cost_basis) * holdings.quantity, 0) AS market_gain_dollars')
|
->selectRaw('COALESCE((market_data.market_value - holdings.average_cost_basis) * holdings.quantity, 0) AS market_gain_dollars')
|
||||||
->selectRaw('COALESCE(((market_data.market_value - holdings.average_cost_basis) / holdings.average_cost_basis) * 100, 0) AS market_gain_percent')
|
->selectRaw('COALESCE(((market_data.market_value - holdings.average_cost_basis) / holdings.average_cost_basis), 0) AS market_gain_percent')
|
||||||
->join('market_data', 'holdings.symbol', 'market_data.symbol');
|
->join('market_data', 'holdings.symbol', 'market_data.symbol');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -64,7 +64,7 @@ class User extends Authenticatable
|
|||||||
->withAggregate('market_data', 'updated_at')
|
->withAggregate('market_data', 'updated_at')
|
||||||
->selectRaw('COALESCE(market_data.market_value * holdings.quantity, 0) AS total_market_value')
|
->selectRaw('COALESCE(market_data.market_value * holdings.quantity, 0) AS total_market_value')
|
||||||
->selectRaw('COALESCE((market_data.market_value - holdings.average_cost_basis) * holdings.quantity, 0) AS market_gain_dollars')
|
->selectRaw('COALESCE((market_data.market_value - holdings.average_cost_basis) * holdings.quantity, 0) AS market_gain_dollars')
|
||||||
->selectRaw('COALESCE(((market_data.market_value - holdings.average_cost_basis) / holdings.average_cost_basis) * 100, 0) AS market_gain_percent')
|
->selectRaw('COALESCE(((market_data.market_value - holdings.average_cost_basis) / holdings.average_cost_basis), 0) AS market_gain_percent')
|
||||||
->join('market_data', 'holdings.symbol', 'market_data.symbol');
|
->join('market_data', 'holdings.symbol', 'market_data.symbol');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ class User extends Authenticatable
|
|||||||
->selectRaw('COALESCE(transactions.cost_basis * transactions.quantity, 0) AS total_cost_basis')
|
->selectRaw('COALESCE(transactions.cost_basis * transactions.quantity, 0) AS total_cost_basis')
|
||||||
->selectRaw('COALESCE(market_data.market_value * transactions.quantity, 0) AS total_market_value')
|
->selectRaw('COALESCE(market_data.market_value * transactions.quantity, 0) AS total_market_value')
|
||||||
->selectRaw('COALESCE((market_data.market_value - transactions.cost_basis) * transactions.quantity, 0) AS market_gain_dollars')
|
->selectRaw('COALESCE((market_data.market_value - transactions.cost_basis) * transactions.quantity, 0) AS market_gain_dollars')
|
||||||
->selectRaw('COALESCE(((market_data.market_value - transactions.cost_basis) / transactions.cost_basis) * 100, 0) AS market_gain_percent')
|
->selectRaw('COALESCE(((market_data.market_value - transactions.cost_basis) / transactions.cost_basis), 0) AS market_gain_percent')
|
||||||
->join('market_data', 'transactions.symbol', 'market_data.symbol');;
|
->join('market_data', 'transactions.symbol', 'market_data.symbol');;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<span
|
||||||
|
class=""
|
||||||
|
style="width:90em;overflow: hidden; white-space: nowrap;"
|
||||||
|
title="{{ Number::currency($low) }} - {{ Number::currency($high) }}"
|
||||||
|
>
|
||||||
|
|
||||||
|
@for ($x = 0; $x < 10; $x++)
|
||||||
|
@if ((($current - $low) * 100) / ($high - $low) > ($x * 10))
|
||||||
|
|
||||||
|
●
|
||||||
|
|
||||||
|
@else
|
||||||
|
|
||||||
|
○
|
||||||
|
@endif
|
||||||
|
@endfor
|
||||||
|
</span>
|
||||||
@@ -20,7 +20,23 @@
|
|||||||
|
|
||||||
<p class="font-bold text-2xl pb-2">
|
<p class="font-bold text-2xl pb-2">
|
||||||
{{ Number::currency($market_data->market_value) }}
|
{{ Number::currency($market_data->market_value) }}
|
||||||
<span class="text-base font-normal">▲ 9%</span>
|
|
||||||
|
@if ($holding->average_cost_basis)
|
||||||
|
|
||||||
|
@php
|
||||||
|
$isUp = $holding->average_cost_basis <= $market_data->market_value;
|
||||||
|
$percent = ($market_data->market_value - $holding->average_cost_basis) / $holding->average_cost_basis
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<span class="text-base font-normal" style="color: {{ $isUp ? 'rgb(0, 200, 0)' : 'rgb(255, 20, 0)' }};">
|
||||||
|
{!! $isUp ? '▲' :'▼' !!}
|
||||||
|
{{ Number::percentage(
|
||||||
|
$percent,
|
||||||
|
$percent < 1 ? 2 : 1
|
||||||
|
) }}
|
||||||
|
</span>
|
||||||
|
@endif
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@@ -30,27 +46,33 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="font-bold">{{ __('Average Cost Basis') }}: </span>
|
<span class="font-bold">{{ __('Average Cost Basis') }}: </span>
|
||||||
{{ $holding->average_cost_basis }}
|
{{ Number::currency($holding->average_cost_basis) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="font-bold">{{ __('Total Cost Basis') }}: </span>
|
<span class="font-bold">{{ __('Total Cost Basis') }}: </span>
|
||||||
{{ $holding->total_cost_basis }}
|
{{ Number::currency($holding->total_cost_basis) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="font-bold">{{ __('Realized Gain/Loss') }}: </span>
|
<span class="font-bold">{{ __('Realized Gain/Loss') }}: </span>
|
||||||
{{ $holding->realized_gain_dollars }}
|
{{ Number::currency($holding->realized_gain_dollars) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="font-bold">{{ __('Dividends Earned') }}: </span>
|
<span class="font-bold">{{ __('Dividends Earned') }}: </span>
|
||||||
{{ $holding->dividends_earned }}
|
{{ Number::currency($holding->dividends_earned) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="font-bold">{{ __('52 week') }}: </span>
|
<span class="font-bold">{{ __('52 week') }}: </span>
|
||||||
● ● ● ● ● ● ● ● ● ●
|
|
||||||
|
<x-fifty-two-week-range
|
||||||
|
:low="$market_data->fifty_two_week_low"
|
||||||
|
:high="$market_data->fifty_two_week_high"
|
||||||
|
:current="$market_data->market_value"
|
||||||
|
/>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="pt-2 text-sm">
|
<p class="pt-2 text-sm">
|
||||||
|
|||||||
Reference in New Issue
Block a user