wip
including working export button
This commit is contained in:
@@ -3,9 +3,6 @@
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Exports\Sheets\DailyChangesSheet;
|
||||
use App\Exports\Sheets\SplitsSheet;
|
||||
use App\Exports\Sheets\DividendsSheet;
|
||||
use App\Exports\Sheets\MarketDataSheet;
|
||||
use App\Exports\Sheets\PortfoliosSheet;
|
||||
use App\Exports\Sheets\TransactionsSheet;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
@@ -23,9 +20,6 @@ class BackupExport implements WithMultipleSheets
|
||||
return [
|
||||
new PortfoliosSheet,
|
||||
new TransactionsSheet,
|
||||
new MarketDataSheet,
|
||||
new DividendsSheet,
|
||||
new SplitsSheet,
|
||||
new DailyChangesSheet
|
||||
];
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ class DailyChangesSheet implements FromCollection, WithHeadings, WithTitle
|
||||
{
|
||||
return [
|
||||
'Date',
|
||||
'User',
|
||||
'Portfolio',
|
||||
'Total Market Value',
|
||||
'Total Cost Basis',
|
||||
'Total Gain Loss',
|
||||
'Total Dividends',
|
||||
'Realized Gains',
|
||||
'Notes'
|
||||
'Annotation'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class DailyChangesSheet implements FromCollection, WithHeadings, WithTitle
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return DailyChange::myDailyChanges()->get();
|
||||
return auth()->user()->daily_changes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sheets;
|
||||
|
||||
use App\Models\Dividend;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
|
||||
class DividendsSheet implements FromCollection, WithHeadings, WithTitle
|
||||
{
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Date',
|
||||
'Symbol',
|
||||
'Amount',
|
||||
'Created',
|
||||
'Updated',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Dividend::get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return 'Dividends';
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sheets;
|
||||
|
||||
use App\Models\MarketData;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
|
||||
class MarketDataSheet implements FromCollection, WithHeadings, WithTitle
|
||||
{
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Symbol',
|
||||
'Name',
|
||||
'Market Value',
|
||||
'52 Week Low',
|
||||
'52 Week High',
|
||||
'Dividend Date',
|
||||
'Splits Synced To Holdings At',
|
||||
'Created',
|
||||
'Updated',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return MarketData::get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return 'Market Data';
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class PortfoliosSheet implements FromCollection, WithHeadings, WithTitle
|
||||
'Notes',
|
||||
'Wishlist',
|
||||
'Created',
|
||||
'Updated',
|
||||
'Updated'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class PortfoliosSheet implements FromCollection, WithHeadings, WithTitle
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Portfolio::myPortfolios()->get();
|
||||
return auth()->user()->portfolios;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Sheets;
|
||||
|
||||
use App\Models\Split;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
|
||||
class SplitsSheet implements FromCollection, WithHeadings, WithTitle
|
||||
{
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Date',
|
||||
'Symbol',
|
||||
'Split',
|
||||
'Created',
|
||||
'Updated',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Split::get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return 'Splits';
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,10 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Transaction ID',
|
||||
'Symbol',
|
||||
'Portfolio',
|
||||
'Transaction',
|
||||
'Portfolio ID',
|
||||
'Transaction Type',
|
||||
'Quantity',
|
||||
'Cost Basis',
|
||||
'Sale Price',
|
||||
@@ -23,6 +23,14 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
|
||||
'Date',
|
||||
'Created',
|
||||
'Updated',
|
||||
'Company Name',
|
||||
'Portfolio Title',
|
||||
'Market Value',
|
||||
'52 Week Low',
|
||||
'52 Week High',
|
||||
'Market Data Refresh Date',
|
||||
'Gain/Loss Dollars',
|
||||
'Owner ID'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -31,7 +39,7 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Transaction::myTransactions()->get();
|
||||
return auth()->user()->transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,6 @@ class PortfolioController extends Controller
|
||||
*/
|
||||
public function show(Portfolio $portfolio)
|
||||
{
|
||||
|
||||
// get portfolio metrics
|
||||
$metrics = cache()->tags(['metrics', 'portfolio', auth()->user()->id, $portfolio->id])->remember(
|
||||
'portfolio-metrics-' . $portfolio->id,
|
||||
|
||||
@@ -32,19 +32,14 @@ class DailyChange extends Model
|
||||
protected $casts = [
|
||||
'date' => 'datetime',
|
||||
];
|
||||
|
||||
public function scopeMyDailyChanges($query)
|
||||
{
|
||||
return $query->where('user_id', auth()->user()->id);
|
||||
}
|
||||
|
||||
public function scopePortfolio($query, $portfolio)
|
||||
{
|
||||
return $query->where('portfolio_id', $portfolio);
|
||||
}
|
||||
|
||||
public function portfolio()
|
||||
{
|
||||
return $this->belongsTo(Portfolio::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ class Portfolio extends Model
|
||||
|
||||
protected $with = ['users', 'transactions'];
|
||||
|
||||
protected $appends = ['owner_id'];
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class)->withPivot('owner');
|
||||
@@ -69,11 +67,6 @@ class Portfolio extends Model
|
||||
return $this->hasMany(DailyChange::class);
|
||||
}
|
||||
|
||||
public function scopeMyPortfolios()
|
||||
{
|
||||
return $this->whereRelation('users', 'id', auth()->user()->id);
|
||||
}
|
||||
|
||||
public function scopeWithoutWishlists()
|
||||
{
|
||||
return $this->where(['wishlist' => false]);
|
||||
|
||||
@@ -97,13 +97,6 @@ class Transaction extends Model
|
||||
return $query->where('symbol', $symbol);
|
||||
}
|
||||
|
||||
public function scopeMyTransactions()
|
||||
{
|
||||
return $this->whereHas('portfolio', function ($query) {
|
||||
return $query->whereRelation('users', 'id', auth()->user()->id);
|
||||
});
|
||||
}
|
||||
|
||||
public function refreshMarketData()
|
||||
{
|
||||
return MarketData::getMarketData($this->attributes['symbol']);
|
||||
|
||||
@@ -54,6 +54,11 @@ class User extends Authenticatable
|
||||
return $this->belongsToMany(Portfolio::class)->withPivot('owner');
|
||||
}
|
||||
|
||||
public function daily_changes()
|
||||
{
|
||||
return $this->hasManyDeep(DailyChange::class, ['portfolio_user', Portfolio::class]);
|
||||
}
|
||||
|
||||
public function holdings(): HasManyDeep
|
||||
{
|
||||
return $this->hasManyDeep(Holding::class, ['portfolio_user', Portfolio::class])
|
||||
|
||||
@@ -18,7 +18,7 @@ class Spotlight
|
||||
return $results;
|
||||
}
|
||||
|
||||
$portfolios = Portfolio::myPortfolios()->where('title', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
|
||||
$portfolios = $request->user()->portfolios()->where('title', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
|
||||
$portfolios->each(function($portfolio) use ($results) {
|
||||
|
||||
$results->push([
|
||||
@@ -29,7 +29,7 @@ class Spotlight
|
||||
]);
|
||||
});
|
||||
|
||||
$holdings = Holding::myHoldings()->where('symbol', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
|
||||
$holdings = $request->user()->holdings()->where('holdings.symbol', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
|
||||
$holdings->each(function($holding) use ($results) {
|
||||
|
||||
$results->push([
|
||||
|
||||
Reference in New Issue
Block a user