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,
|
||||
|
||||
@@ -33,18 +33,13 @@ class DailyChange extends Model
|
||||
'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([
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"Save": "Save",
|
||||
"Close": "Close",
|
||||
|
||||
"Hang on! You're doing that too much.": "Hang on! You're doing that too much.",
|
||||
"Delete Account": "Delete Account",
|
||||
"Permanently delete your account.": "Permanently delete your account.",
|
||||
"Once your account is deleted, all of its resources and data will be permanently deleted. Before deleting your account, please download any data or information that you wish to retain.": "Once your account is deleted, all of its resources and data will be permanently deleted. Before deleting your account, please download any data or information that you wish to retain.",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"Save": "Guardar",
|
||||
"Close": "Cerrar",
|
||||
|
||||
"Hang on! You're doing that too much.": "¡Por favor espere un momento!",
|
||||
"Delete Account": "Eliminar Cuenta",
|
||||
"Permanently delete your account.": "Elimina tu cuenta de forma permanente.",
|
||||
"Once your account is deleted, all of its resources and data will be permanently deleted. Before deleting your account, please download any data or information that you wish to retain.": "Una vez que tu cuenta sea eliminada, todos sus recursos y datos serán eliminados de forma permanente. Antes de eliminar tu cuenta, descarga cualquier dato o información que desees conservar.",
|
||||
|
||||
@@ -2,25 +2,31 @@
|
||||
|
||||
use Livewire\Volt\Component;
|
||||
use Mary\Traits\Toast;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\BackupExport;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
||||
new class extends Component {
|
||||
use Toast;
|
||||
|
||||
// props
|
||||
|
||||
|
||||
// methods
|
||||
public function mount()
|
||||
public function export()
|
||||
{
|
||||
if (!RateLimiter::attempt('export:'.auth()->user()->id, $perMinute = 3, fn()=>null)) {
|
||||
|
||||
//
|
||||
$this->error(__('Hang on! You\'re doing that too much.'));
|
||||
return;
|
||||
}
|
||||
|
||||
return Excel::download(new BackupExport, now()->format('Y_m_d') . '_investbrain_backup.xlsx');
|
||||
}
|
||||
|
||||
|
||||
}; ?>
|
||||
|
||||
<div>
|
||||
<x-button type="submit">
|
||||
<x-button type="submit" @click="$wire.export">
|
||||
{{ __('Download Export') }}
|
||||
</x-button>
|
||||
</div>
|
||||
Reference in New Issue
Block a user