wip
This commit is contained in:
@@ -27,6 +27,6 @@ class PortfolioController extends Controller
|
|||||||
$portfolio->realizedGainLoss = rand(-200, 3999);
|
$portfolio->realizedGainLoss = rand(-200, 3999);
|
||||||
$portfolio->dividendsEarned = rand(-200, 3999);
|
$portfolio->dividendsEarned = rand(-200, 3999);
|
||||||
|
|
||||||
return view('portfolio.show', compact('portfolio'));
|
return view('portfolio.show', compact(['portfolio']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Portfolio;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
|
||||||
|
class TransactionController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
|
||||||
|
return view('transaction.index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,4 +63,9 @@ class DailyChange extends Model
|
|||||||
return $query->where('user_id', auth()->user()->id);
|
return $query->where('user_id', auth()->user()->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function portfolio()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Portfolio::class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class Portfolio extends Model
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $with = ['users'];
|
protected $with = ['users', 'transactions'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that should be appended.
|
* The attributes that should be appended.
|
||||||
@@ -70,15 +70,20 @@ class Portfolio extends Model
|
|||||||
return $this->belongsToMany(User::class)->withPivot('owner');
|
return $this->belongsToMany(User::class)->withPivot('owner');
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function holdings()
|
public function holdings()
|
||||||
// {
|
{
|
||||||
// return $this->hasMany(Holding::class, 'portfolio_id', 'id');
|
return $this->hasMany(Holding::class, 'portfolio_id', 'id');
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public function transactions()
|
public function transactions()
|
||||||
// {
|
{
|
||||||
// return $this->hasMany(Transaction::class);
|
return $this->hasMany(Transaction::class);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
public function daily_change()
|
||||||
|
{
|
||||||
|
return $this->hasMany(DailyChange::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeMyPortfolios()
|
public function scopeMyPortfolios()
|
||||||
{
|
{
|
||||||
|
|||||||
+29
-16
@@ -4,11 +4,13 @@ namespace App\Models;
|
|||||||
|
|
||||||
use App\Models\MarketData;
|
use App\Models\MarketData;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
class Transaction extends Model
|
class Transaction extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
use HasUuids;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
@@ -53,33 +55,44 @@ class Transaction extends Model
|
|||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
static::saved(function ($model) {
|
static::saving(function ($transaction) {
|
||||||
|
|
||||||
static::syncHolding($model);
|
// if sale, move cost basis to sale price
|
||||||
|
if ($transaction->transaction_type == 'SELL') {
|
||||||
|
|
||||||
|
$transaction->sale_price = $transaction->cost_basis;
|
||||||
|
$transaction->cost_basis = $transaction->holding->average_cost_basis ?? $transaction->cost_basis;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
static::deleted(function ($model) {
|
static::saved(function ($transaction) {
|
||||||
static::syncHolding($model);
|
|
||||||
|
// static::syncHolding($transaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
static::deleted(function ($transaction) {
|
||||||
|
|
||||||
|
// static::syncHolding($transaction);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function syncHolding($model) {
|
public static function syncHolding($transaction) {
|
||||||
// get the holding for a symbol and portfolio (or create one)
|
// get the holding for a symbol and portfolio (or create one)
|
||||||
$holding = Holding::firstOrNew([
|
$holding = Holding::firstOrNew([
|
||||||
'portfolio_id' => $model->portfolio_id,
|
'portfolio_id' => $transaction->portfolio_id,
|
||||||
'symbol' => $model->symbol
|
'symbol' => $transaction->symbol
|
||||||
], [
|
], [
|
||||||
'portfolio_id' => $model->portfolio_id,
|
'portfolio_id' => $transaction->portfolio_id,
|
||||||
'symbol' => $model->symbol,
|
'symbol' => $transaction->symbol,
|
||||||
'quantity' => $model->quantity,
|
'quantity' => $transaction->quantity,
|
||||||
'average_cost_basis' => $model->cost_basis,
|
'average_cost_basis' => $transaction->cost_basis,
|
||||||
'total_cost_basis' => $model->quantity * $model->cost_basis,
|
'total_cost_basis' => $transaction->quantity * $transaction->cost_basis,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// pull existing transaction data
|
// pull existing transaction data
|
||||||
$query = self::where([
|
$query = self::where([
|
||||||
'portfolio_id' => $model->portfolio_id,
|
'portfolio_id' => $transaction->portfolio_id,
|
||||||
'symbol' => $model->symbol,
|
'symbol' => $transaction->symbol,
|
||||||
])->selectRaw('SUM(CASE WHEN transaction_type = "BUY" THEN quantity ELSE 0 END) AS `qty_purchases`')
|
])->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 = "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 `cost_basis`')
|
||||||
@@ -102,10 +115,10 @@ class Transaction extends Model
|
|||||||
$holding->save();
|
$holding->save();
|
||||||
|
|
||||||
// load market data while we're here
|
// load market data while we're here
|
||||||
$model->refreshMarketData();
|
$transaction->refreshMarketData();
|
||||||
|
|
||||||
// sync dividends to holding
|
// sync dividends to holding
|
||||||
$model->syncDividendsToHolding();
|
$transaction->syncDividendsToHolding();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSymbolAttribute($value)
|
public function setSymbolAttribute($value)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@props(['id' => null, 'maxWidth' => null])
|
@props(['id' => null, 'maxWidth' => null])
|
||||||
|
|
||||||
<x-modal :id="$id" :maxWidth="$maxWidth" {{ $attributes }}>
|
<x-modal :id="$id" :maxWidth="$maxWidth" {{ $attributes }}>
|
||||||
<div class="px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
|
<div class="p-4">
|
||||||
<div class="sm:flex sm:items-start">
|
<div class="sm:flex sm:items-start">
|
||||||
<div class="mx-auto shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
|
<div class="mx-auto shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
|
||||||
<svg class="h-6 w-6 text-red-600 dark:text-red-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
<svg class="h-6 w-6 text-red-600 dark:text-red-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<div class="grow"></div>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
@props([
|
||||||
|
'key' => 'modal',
|
||||||
|
'showClose' => true,
|
||||||
|
'closeOnEscape' => true,
|
||||||
|
'title' => null,
|
||||||
|
'subtitle' => null
|
||||||
|
])
|
||||||
|
|
||||||
|
<div
|
||||||
|
x-data="{ open: false }"
|
||||||
|
x-on:toggle-{{ $key }}.window="open = !open"
|
||||||
|
class="relative z-50 w-auto h-auto"
|
||||||
|
@if($closeOnEscape)
|
||||||
|
@keydown.window.escape="open = false"
|
||||||
|
@endif
|
||||||
|
>
|
||||||
|
<template x-teleport="body">
|
||||||
|
<div x-transition.opacity x-show="open" class="fixed top-0 left-0 z-[99] flex items-center justify-center w-full h-full" x-cloak>
|
||||||
|
<div
|
||||||
|
@click="open=false"
|
||||||
|
class="absolute inset-0 w-full h-full bg-black bg-opacity-40"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<x-card
|
||||||
|
x-trap.inert.noscroll="open"
|
||||||
|
:title="$title"
|
||||||
|
:subtitle="$subtitle"
|
||||||
|
{{ $attributes->merge(['class' => 'relative transform overflow-hidden rounded-md ext-left shadow-xl w-full sm:w-2/3 lg:w-1/3 m-2 sm:m-0']) }}
|
||||||
|
>
|
||||||
|
@if ($showClose)
|
||||||
|
<x-button
|
||||||
|
icon="o-x-mark"
|
||||||
|
class="absolute top-4 right-4 btn-ghost btn-circle btn-sm"
|
||||||
|
@click="open = false"
|
||||||
|
/>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
{{ $slot }}
|
||||||
|
|
||||||
|
</x-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
@@ -1,23 +1,23 @@
|
|||||||
<x-menu activate-by-route>
|
<x-menu activate-by-route>
|
||||||
|
|
||||||
<x-menu-item title="{{ __('Dashboard') }}" icon="o-home" link="{{ @route('dashboard') }}" />
|
<x-menu-item title="{{ __('Dashboard') }}" icon="o-home" link="{{ route('dashboard') }}" />
|
||||||
<x-menu-sub title="{{ __('Portfolios') }}" icon="o-document-duplicate">
|
<x-menu-sub title="{{ __('Portfolios') }}" icon="o-document-duplicate">
|
||||||
@foreach (auth()->user()->portfolios as $portfolio)
|
@foreach (auth()->user()->portfolios as $portfolio)
|
||||||
<x-menu-item icon="o-document" link="{{ route('portfolio.show', ['portfolio' => $portfolio->id ]) }}" exact>
|
<x-menu-item icon="o-document" link="{{ route('portfolio.show', ['portfolio' => $portfolio->id ]) }}" >
|
||||||
<x-slot:title>
|
<x-slot:title>
|
||||||
{{ $portfolio->title }}
|
{{ $portfolio->title }}
|
||||||
@if($portfolio->wishlist)
|
@if($portfolio->wishlist)
|
||||||
<x-badge value="{{ __('Wishlist') }}" class="badge-primary badge-sm ml-2" />
|
<x-badge value="{{ __('Wishlist') }}" class="badge-secondary badge-sm ml-2" />
|
||||||
@endif
|
@endif
|
||||||
</x-slot:title>
|
</x-slot:title>
|
||||||
|
|
||||||
</x-menu-item>
|
</x-menu-item>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
<x-menu-item title="{{ __('Create Portfolio') }}" icon="o-document-plus" link="{{ @route('portfolio.create') }}" />
|
<x-menu-item title="{{ __('Create Portfolio') }}" icon="o-document-plus" link="{{ route('portfolio.create') }}" />
|
||||||
</x-menu-sub>
|
</x-menu-sub>
|
||||||
<x-menu-item title="{{ __('Transactions') }}" icon="o-banknotes" link="####" />
|
<x-menu-item title="{{ __('Transactions') }}" icon="o-banknotes" link="{{ route('transaction.index') }}" />
|
||||||
<x-menu-item title="{{ __('Reporting') }}" icon="o-chart-bar-square" link="####" />
|
{{-- <x-menu-item title="{{ __('Reporting') }}" icon="o-chart-bar-square" link="####" /> --}}
|
||||||
|
|
||||||
</x-menu>
|
</x-menu>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<x-app-layout>
|
<x-app-layout>
|
||||||
|
|
||||||
@livewire('portfolio-performance-cards', [
|
@livewire('portfolio-performance-chart', [
|
||||||
'name' => 'dashboard'
|
'name' => 'dashboard'
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
<x-slot:value>
|
<x-slot:value>
|
||||||
{{ $portfolio->title }}
|
{{ $portfolio->title }}
|
||||||
@if($portfolio->wishlist)
|
@if($portfolio->wishlist)
|
||||||
<x-badge value="{{ __('Wishlist') }}" class="badge-primary badge-sm ml-2" />
|
<x-badge value="{{ __('Wishlist') }}" class="badge-secondary badge-sm ml-2" />
|
||||||
@endif
|
@endif
|
||||||
</x-slot:value>
|
</x-slot:value>
|
||||||
</x-list-item>
|
</x-list-item>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (!$user->portfolios->isEmpty())
|
{{-- @if (!$user->portfolios->isEmpty())
|
||||||
<x-ib-card title="{{ __('Top headlines') }}" class="md:col-span-3">
|
<x-ib-card title="{{ __('Top headlines') }}" class="md:col-span-3">
|
||||||
|
|
||||||
@php
|
@php
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
@endif
|
@endif --}}
|
||||||
|
|
||||||
@if (!$user->portfolios->isEmpty())
|
@if (!$user->portfolios->isEmpty())
|
||||||
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-4">
|
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-4">
|
||||||
|
|||||||
@@ -7,14 +7,11 @@
|
|||||||
|
|
||||||
<title>{{ config('app.name', 'Laravel') }}</title>
|
<title>{{ config('app.name', 'Laravel') }}</title>
|
||||||
|
|
||||||
<!-- Fonts -->
|
|
||||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||||
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
|
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
|
||||||
|
|
||||||
<!-- Scripts -->
|
|
||||||
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
||||||
|
|
||||||
<!-- Styles -->
|
|
||||||
@livewireStyles
|
@livewireStyles
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ new class extends Component {
|
|||||||
|
|
||||||
$this->portfolio->delete();
|
$this->portfolio->delete();
|
||||||
|
|
||||||
$this->success(__('Portfolio deleted'), redirectTo: "/dashboard");
|
$this->success(__('Portfolio deleted'), redirectTo: route('dashboard'));
|
||||||
}
|
}
|
||||||
}; ?>
|
}; ?>
|
||||||
|
|
||||||
@@ -92,10 +92,11 @@ new class extends Component {
|
|||||||
<x-slot:actions>
|
<x-slot:actions>
|
||||||
@if ($portfolio)
|
@if ($portfolio)
|
||||||
<x-button
|
<x-button
|
||||||
class="ms-3 btn-error btn-outline text-white"
|
class="ms-3 btn btn-ghost text-error"
|
||||||
wire:click="$toggle('confirmingPortfolioDeletion')"
|
wire:click="$toggle('confirmingPortfolioDeletion')"
|
||||||
wire:loading.attr="disabled"
|
wire:loading.attr="disabled"
|
||||||
icon="o-trash"
|
label="{{ __('Delete') }}"
|
||||||
|
title="{{ __('Delete Portfolio') }}"
|
||||||
/>
|
/>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Transaction;
|
||||||
|
use App\Models\Portfolio;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Livewire\Attributes\Rule;
|
||||||
|
use Livewire\Volt\Component;
|
||||||
|
use Mary\Traits\Toast;
|
||||||
|
use Livewire\Attributes\Computed;
|
||||||
|
|
||||||
|
new class extends Component {
|
||||||
|
use Toast;
|
||||||
|
|
||||||
|
// props
|
||||||
|
public ?Portfolio $portfolio;
|
||||||
|
public ?Transaction $transaction;
|
||||||
|
|
||||||
|
#[Rule('required|string|max:15')]
|
||||||
|
public String $symbol;
|
||||||
|
|
||||||
|
#[Rule('required|string|in:BUY,SELL')]
|
||||||
|
public String $transaction_type;
|
||||||
|
|
||||||
|
#[Rule('required|date')]
|
||||||
|
public String $date;
|
||||||
|
|
||||||
|
#[Rule('required|numeric')]
|
||||||
|
public String $quantity;
|
||||||
|
|
||||||
|
#[Rule('required|numeric')]
|
||||||
|
public String $cost_basis;
|
||||||
|
|
||||||
|
public Bool $confirmingTransactionDeletion = false;
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function cost_basis_label()
|
||||||
|
{
|
||||||
|
if (isset($this->transaction_type) && $this->transaction_type == 'SELL') {
|
||||||
|
return __('Sale Price');
|
||||||
|
}
|
||||||
|
|
||||||
|
return __('Cost Basis');
|
||||||
|
}
|
||||||
|
|
||||||
|
// methods
|
||||||
|
public function mount()
|
||||||
|
{
|
||||||
|
if (isset($this->transaction)) {
|
||||||
|
|
||||||
|
$this->symbol = $this->transaction->symbol;
|
||||||
|
$this->transaction_type = $this->transaction->transaction_type;
|
||||||
|
$this->date = $this->transaction->date->format('Y-m-d');
|
||||||
|
$this->quantity = $this->transaction->quantity;
|
||||||
|
$this->cost_basis = $this->transaction_type == 'SELL'
|
||||||
|
? $this->transaction->sale_price
|
||||||
|
: $this->transaction->cost_basis;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->transaction_type = 'BUY';
|
||||||
|
$this->date = now()->format('Y-m-d');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->transaction->update($this->validate());
|
||||||
|
// $this->transaction->owner_id = auth()->user()->id;
|
||||||
|
$this->transaction->save();
|
||||||
|
|
||||||
|
$this->success(__('Transaction updated'), redirectTo: route('portfolio.show', ['portfolio' => $this->portfolio->id]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
|
||||||
|
$transaction = $this->portfolio->transactions()->create($this->validate());
|
||||||
|
$transaction->save();
|
||||||
|
|
||||||
|
$this->success(__('Transaction created'), redirectTo: route('portfolio.show', ['portfolio' => $this->portfolio->id]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->transaction->delete();
|
||||||
|
|
||||||
|
$this->success(__('Transaction deleted'), redirectTo: route('portfolio.show', ['portfolio' => $this->portfolio->id]));
|
||||||
|
}
|
||||||
|
}; ?>
|
||||||
|
|
||||||
|
<div class="">
|
||||||
|
<x-form wire:submit="{{ $transaction ? 'update' : 'save' }}" class="">
|
||||||
|
|
||||||
|
<x-input label="{{ __('Symbol') }}" wire:model="symbol" required />
|
||||||
|
|
||||||
|
<x-select label="{{ __('Transaction Type') }}" :options="[
|
||||||
|
['id' => 'BUY', 'name' => 'Buy'],
|
||||||
|
['id' => 'SELL', 'name' => 'Sell']
|
||||||
|
]" wire:model.live="transaction_type" />
|
||||||
|
|
||||||
|
<x-datetime label="{{ __('Transaction Date') }}" wire:model="date" required />
|
||||||
|
|
||||||
|
<x-input label="{{ __('Quantity') }}" type="number" step="any" wire:model="quantity" required />
|
||||||
|
|
||||||
|
<x-input
|
||||||
|
label="{{ $this->cost_basis_label }}"
|
||||||
|
wire:model="cost_basis"
|
||||||
|
required
|
||||||
|
prefix="USD"
|
||||||
|
money
|
||||||
|
type="number"
|
||||||
|
step="any"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<x-slot:actions>
|
||||||
|
@if ($transaction)
|
||||||
|
<x-button
|
||||||
|
class="ms-3 btn btn-ghost text-error"
|
||||||
|
wire:click="$toggle('confirmingTransactionDeletion')"
|
||||||
|
wire:loading.attr="disabled"
|
||||||
|
label="{{ __('Delete') }}"
|
||||||
|
title="{{ __('Delete Transaction') }}"
|
||||||
|
/>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<x-button label="{{ $transaction ? 'Update' : 'Create' }}" type="submit" icon="o-paper-airplane" class="btn-primary" spinner="save" />
|
||||||
|
</x-slot:actions>
|
||||||
|
</x-form>
|
||||||
|
|
||||||
|
<x-confirmation-modal wire:model.live="confirmingTransactionDeletion">
|
||||||
|
<x-slot name="title">
|
||||||
|
{{ __('Delete Transaction') }}
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
|
<x-slot name="content">
|
||||||
|
{{ __('Are you sure you want to delete this transaction?') }}
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
|
<x-slot name="footer">
|
||||||
|
<x-button class="btn-outline" wire:click="$toggle('confirmingTransactionDeletion')" wire:loading.attr="disabled">
|
||||||
|
{{ __('Cancel') }}
|
||||||
|
</x-secondary-button>
|
||||||
|
|
||||||
|
<x-button class="ms-3 btn-error text-white" wire:click="delete" wire:loading.attr="disabled">
|
||||||
|
{{ __('Delete Transaction') }}
|
||||||
|
</x-button>
|
||||||
|
</x-slot>
|
||||||
|
</x-confirmation-modal>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Portfolio;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Livewire\Volt\Component;
|
||||||
|
|
||||||
|
new class extends Component {
|
||||||
|
|
||||||
|
// props
|
||||||
|
public ?Collection $transactions;
|
||||||
|
public Portfolio $portfolio;
|
||||||
|
public ?Transaction $editingTransaction;
|
||||||
|
|
||||||
|
// methods
|
||||||
|
public function showTransactionDialog($transactionId)
|
||||||
|
{
|
||||||
|
$this->editingTransaction = Transaction::findOrFail($transactionId);
|
||||||
|
$this->dispatch('toggle-manage-transaction');
|
||||||
|
}
|
||||||
|
|
||||||
|
}; ?>
|
||||||
|
|
||||||
|
<div class="">
|
||||||
|
|
||||||
|
@foreach($transactions as $transaction)
|
||||||
|
<div x-data="{ loading: false, timeout: null }">
|
||||||
|
<x-list-item
|
||||||
|
no-separator
|
||||||
|
:item="$transaction"
|
||||||
|
class="cursor-pointer"
|
||||||
|
@click="
|
||||||
|
timeout = setTimeout(() => { loading = true }, 200);
|
||||||
|
$wire.showTransactionDialog('{{ $transaction->id }}').then(() => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
loading = false;
|
||||||
|
})
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<x-slot:value class="flex items-center">
|
||||||
|
<x-badge
|
||||||
|
:value="$transaction->transaction_type"
|
||||||
|
class="{{ $transaction->transaction_type == 'BUY' ? 'badge-success' : 'badge-error' }} badge-sm mr-3"
|
||||||
|
/>
|
||||||
|
{{ $transaction->date->format('M j, Y') }}
|
||||||
|
{{ $transaction->symbol }}
|
||||||
|
({{ $transaction->quantity }}
|
||||||
|
@ {{ Number::currency($transaction->cost_basis) }})
|
||||||
|
|
||||||
|
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
|
||||||
|
</x-slot:value>
|
||||||
|
</x-list-item>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
<x-ib-modal
|
||||||
|
key="manage-transaction"
|
||||||
|
title="Manage Transaction"
|
||||||
|
>
|
||||||
|
@livewire('manage-transaction-form', [
|
||||||
|
'portfolio' => $portfolio,
|
||||||
|
'transaction' => $editingTransaction,
|
||||||
|
], key($editingTransaction->id ?? 'new'))
|
||||||
|
|
||||||
|
</x-ib-modal>
|
||||||
|
</div>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<x-app-layout>
|
<x-app-layout>
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<x-ib-toolbar title="Create Portfolio" />
|
<x-ib-toolbar title="{{ __('Create Portfolio') }}" />
|
||||||
|
|
||||||
@livewire('manage-portfolio-form')
|
@livewire('manage-portfolio-form')
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
<x-app-layout>
|
<x-app-layout>
|
||||||
<div x-data>
|
<div x-data>
|
||||||
|
|
||||||
|
<x-ib-modal
|
||||||
|
key="new-transaction"
|
||||||
|
title="New Transaction"
|
||||||
|
>
|
||||||
|
@livewire('manage-transaction-form', [
|
||||||
|
'portfolio' => $portfolio,
|
||||||
|
])
|
||||||
|
|
||||||
|
</x-ib-modal>
|
||||||
|
|
||||||
<x-ib-drawer
|
<x-ib-drawer
|
||||||
key="manage-portfolio"
|
key="manage-portfolio"
|
||||||
title="{{ $portfolio->title }}"
|
title="{{ $portfolio->title }}"
|
||||||
>
|
>
|
||||||
|
|
||||||
@livewire('manage-portfolio-form', [
|
@livewire('manage-portfolio-form', [
|
||||||
'portfolio' => $portfolio,
|
'portfolio' => $portfolio,
|
||||||
'hideCancel' => true
|
'hideCancel' => true
|
||||||
@@ -16,7 +25,7 @@
|
|||||||
<x-ib-toolbar :title="$portfolio->title">
|
<x-ib-toolbar :title="$portfolio->title">
|
||||||
|
|
||||||
@if($portfolio->wishlist)
|
@if($portfolio->wishlist)
|
||||||
<x-badge value="{{ __('Wishlist') }}" class="badge-primary mr-3" />
|
<x-badge value="{{ __('Wishlist') }}" class="badge-secondary mr-3" />
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<x-button
|
<x-button
|
||||||
@@ -25,9 +34,19 @@
|
|||||||
class="btn-circle btn-ghost btn-sm text-secondary"
|
class="btn-circle btn-ghost btn-sm text-secondary"
|
||||||
@click="$dispatch('toggle-manage-portfolio')"
|
@click="$dispatch('toggle-manage-portfolio')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<x-ib-flex-spacer />
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<x-button
|
||||||
|
label="{{ __('Create Transaction') }}"
|
||||||
|
class="btn-sm btn-primary"
|
||||||
|
@click="$dispatch('toggle-new-transaction')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</x-ib-toolbar>
|
</x-ib-toolbar>
|
||||||
|
|
||||||
@livewire('portfolio-performance-cards', [
|
@livewire('portfolio-performance-chart', [
|
||||||
'name' => 'portfolio-'.$portfolio->id,
|
'name' => 'portfolio-'.$portfolio->id,
|
||||||
'portfolio' => $portfolio
|
'portfolio' => $portfolio
|
||||||
])
|
])
|
||||||
@@ -64,7 +83,7 @@
|
|||||||
|
|
||||||
<div class="mt-6 grid md:grid-cols-7 gap-5">
|
<div class="mt-6 grid md:grid-cols-7 gap-5">
|
||||||
|
|
||||||
<x-ib-card title="All portfolio holdings" class="md:col-span-4">
|
<x-ib-card title="{{ __('Holdings') }}" class="md:col-span-4">
|
||||||
|
|
||||||
@php
|
@php
|
||||||
$users = App\Models\User::take(3)->get();
|
$users = App\Models\User::take(3)->get();
|
||||||
@@ -76,7 +95,7 @@
|
|||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
|
|
||||||
<x-ib-card title="Top performers" class="md:col-span-3">
|
<x-ib-card title="{{ __('Top performers') }}" class="md:col-span-3">
|
||||||
|
|
||||||
@php
|
@php
|
||||||
$users = App\Models\User::take(3)->get();
|
$users = App\Models\User::take(3)->get();
|
||||||
@@ -88,7 +107,7 @@
|
|||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
|
|
||||||
<x-ib-card title="Top headlines" class="md:col-span-3">
|
{{-- <x-ib-card title="{{ __('Top headlines') }}" class="md:col-span-3">
|
||||||
|
|
||||||
@php
|
@php
|
||||||
$users = App\Models\User::take(3)->get();
|
$users = App\Models\User::take(3)->get();
|
||||||
@@ -98,21 +117,17 @@
|
|||||||
<x-list-item no-separator :item="$user" avatar="profile_photo_url" link="/docs/installation" />
|
<x-list-item no-separator :item="$user" avatar="profile_photo_url" link="/docs/installation" />
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card> --}}
|
||||||
|
|
||||||
<x-ib-card title="Recent activity" class="md:col-span-4">
|
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-4">
|
||||||
|
|
||||||
@php
|
@livewire('transactions-list', [
|
||||||
$users = App\Models\User::take(3)->get();
|
'transactions' => $portfolio->transactions,
|
||||||
@endphp
|
'portfolio' => $portfolio
|
||||||
|
])
|
||||||
@foreach($users as $user)
|
|
||||||
<x-list-item no-separator :item="$user" avatar="profile_photo_url" link="/docs/installation" />
|
|
||||||
@endforeach
|
|
||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</x-app-layout>
|
</x-app-layout>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<x-app-layout>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<x-ib-toolbar title="{{ __('All Transactions') }}" />
|
||||||
|
|
||||||
|
{{-- @livewire('manage-transaction-form', ['portfolio' => $portfolio]) --}}
|
||||||
|
</div>
|
||||||
|
</x-app-layout>
|
||||||
+3
-1
@@ -3,6 +3,7 @@
|
|||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\DashboardController;
|
use App\Http\Controllers\DashboardController;
|
||||||
use App\Http\Controllers\PortfolioController;
|
use App\Http\Controllers\PortfolioController;
|
||||||
|
use App\Http\Controllers\TransactionController;
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('welcome');
|
return view('welcome');
|
||||||
@@ -13,7 +14,8 @@ Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified']
|
|||||||
Route::get('/dashboard', [DashboardController::class, 'show'])->name('dashboard');
|
Route::get('/dashboard', [DashboardController::class, 'show'])->name('dashboard');
|
||||||
Route::view('/import-export', 'import-export')->name('import-export');
|
Route::view('/import-export', 'import-export')->name('import-export');
|
||||||
|
|
||||||
Route::redirect('/portfolio', '/portfolio/create', 301);
|
|
||||||
Route::get('/portfolio/create', [PortfolioController::class, 'create'])->name('portfolio.create');
|
Route::get('/portfolio/create', [PortfolioController::class, 'create'])->name('portfolio.create');
|
||||||
Route::get('/portfolio/{portfolio}', [PortfolioController::class, 'show'])->name('portfolio.show');
|
Route::get('/portfolio/{portfolio}', [PortfolioController::class, 'show'])->name('portfolio.show');
|
||||||
|
|
||||||
|
Route::get('/transactions', [TransactionController::class, 'index'])->name('transaction.index');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user