wip import backup
This commit is contained in:
@@ -29,8 +29,7 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
|
||||
'52 Week Low',
|
||||
'52 Week High',
|
||||
'Market Data Refresh Date',
|
||||
'Gain/Loss Dollars',
|
||||
'Owner ID'
|
||||
'Gain/Loss Dollars'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,8 @@ class BackupImport implements WithMultipleSheets
|
||||
{
|
||||
return [
|
||||
'Portfolios' => new PortfoliosSheet,
|
||||
'Transactions' => new TransactionsSheet,
|
||||
'Market Data' => new MarketDataSheet,
|
||||
'Dividends' => new DividendsSheet,
|
||||
'Splits' => new SplitsSheet,
|
||||
'Daily Changes' => new DailyChangesSheet,
|
||||
// 'Transactions' => new TransactionsSheet,
|
||||
// 'Daily Changes' => new DailyChangesSheet,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sheets;
|
||||
|
||||
use App\Models\Dividend;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class DividendsSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
public function collection(Collection $dividend)
|
||||
{
|
||||
foreach ($dividend->sortBy('date') as $row) {
|
||||
|
||||
Dividend::updateOrCreate([
|
||||
'symbol' => $row['symbol'],
|
||||
'date' => $row['date'],
|
||||
],[
|
||||
'symbol' => $row['symbol'],
|
||||
'dividend_amount' => $row['amount'] ?? 0,
|
||||
'date' => $row['date'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sheets;
|
||||
|
||||
use App\Models\MarketData;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class MarketDataSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
public function collection(Collection $market_data)
|
||||
{
|
||||
foreach ($market_data->sortBy('symbol') as $row) {
|
||||
|
||||
MarketData::updateOrCreate(
|
||||
[
|
||||
'symbol' => $row['symbol']
|
||||
],
|
||||
[
|
||||
'symbol' => $row['symbol'],
|
||||
'name' => $row['name'],
|
||||
'market_value' => $row['market_value'],
|
||||
'fifty_two_week_low' => $row['52_week_low'],
|
||||
'fifty_two_week_high' => $row['52_week_high'],
|
||||
'dividend_date' => $row['dividend_date'],
|
||||
'splits_synced_to_holdings_at' => $row['splits_synced_to_holdings_at']
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,18 +14,18 @@ class PortfoliosSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
|
||||
public function collection(Collection $portfolios)
|
||||
{
|
||||
foreach ($portfolios->sortBy('date') as $row) {
|
||||
foreach ($portfolios->sortBy('date') as $portfolio) {
|
||||
|
||||
Portfolio::myPortfolios()
|
||||
->where(['id' => $row['id']])
|
||||
->orWhere(['title' => $row['title']])
|
||||
->firstOr(function () use ($row) {
|
||||
auth()->user()->portfolios()
|
||||
->where(['id' => $portfolio['id']])
|
||||
->orWhere(['title' => $portfolio['title']])
|
||||
->firstOr(function () use ($portfolio) {
|
||||
|
||||
return Portfolio::make()->forceFill([
|
||||
'id' => $row['id'] ?? null,
|
||||
'title' => $row['title'],
|
||||
'wishlist' => $row['wishlist'] ?? false,
|
||||
'notes' => $row['notes'],
|
||||
'id' => $portfolio['id'] ?? null,
|
||||
'title' => $portfolio['title'],
|
||||
'wishlist' => $portfolio['wishlist'] ?? false,
|
||||
'notes' => $portfolio['notes'],
|
||||
])->save();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sheets;
|
||||
|
||||
use App\Models\Split;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class SplitsSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
public function collection(Collection $dividend)
|
||||
{
|
||||
foreach ($dividend->sortBy('date') as $row) {
|
||||
|
||||
Split::updateOrCreate([
|
||||
'symbol' => $row['symbol'],
|
||||
'date' => $row['date'],
|
||||
],[
|
||||
'symbol' => $row['symbol'],
|
||||
'split_amount' => $row['split'],
|
||||
'date' => $row['date'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@
|
||||
"Upload or recover your Investbrain portfolio and holdings.": "Upload or recover your Investbrain portfolio and holdings.",
|
||||
"Download all of your portfolios and transactions.": "Download all of your portfolios and transactions.",
|
||||
"Import / Export Data": "Import / Export Data",
|
||||
"Successfully imported!": "Successfully imported!",
|
||||
"Select a file": "Select a file",
|
||||
"Download Export": "Download Export",
|
||||
"Your email address is unverified.": "Your email address is unverified.",
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
"Upload or recover your Investbrain portfolio and holdings.": "Sube o recupera tu portafolio y participaciones de Investbrain.",
|
||||
"Download all of your portfolios and transactions.": "Descarga todos tus portafolios y transacciones.",
|
||||
"Import / Export Data": "Importar / Exportar Datos",
|
||||
"Successfully imported!": "¡Importado con éxito!",
|
||||
"Select a file": "Seleccionar un archivo",
|
||||
"Download Export": "Descargar Exportación",
|
||||
"Your email address is unverified.": "Tu dirección de correo electrónico no está verificada.",
|
||||
|
||||
@@ -73,6 +73,15 @@
|
||||
{{ Number::currency($holding->dividends_earned ?? 0) }}
|
||||
</p>
|
||||
|
||||
<p class="pt-2 text-sm">
|
||||
{{ __('Market Data Age') }}:
|
||||
{{ \Carbon\Carbon::parse($market_data->updated_at)->diffForHumans() }}
|
||||
</p>
|
||||
|
||||
</x-ib-card>
|
||||
|
||||
<x-ib-card title="{{ __('Fundamentals') }}" class="md:col-span-4">
|
||||
|
||||
<p>
|
||||
<span class="font-bold">{{ __('52 week') }}: </span>
|
||||
|
||||
@@ -83,16 +92,7 @@
|
||||
/>
|
||||
|
||||
</p>
|
||||
|
||||
<p class="pt-2 text-sm">
|
||||
{{ __('Market Data Age') }}:
|
||||
{{ \Carbon\Carbon::parse($market_data->updated_at)->diffForHumans() }}
|
||||
</p>
|
||||
|
||||
</x-ib-card>
|
||||
|
||||
<x-ib-card title="{{ __('Fundamentals') }}" class="md:col-span-4">
|
||||
|
||||
|
||||
<p>
|
||||
<span class="font-bold">{{ __('Forward PE') }}: </span>
|
||||
{{ $market_data->forward_pe }}
|
||||
|
||||
@@ -1,37 +1,14 @@
|
||||
<x-app-layout>
|
||||
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<x-forms.form-section submit="updateProfileInformation">
|
||||
<x-slot name="title">
|
||||
{{ __('Import') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="description">
|
||||
{{ __('Upload or recover your Investbrain portfolio and holdings.') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="form">
|
||||
|
||||
<!-- Name -->
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
@livewire('import-portfolios-field')
|
||||
</div>
|
||||
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="actions">
|
||||
|
||||
<x-button type="submit">
|
||||
{{ __('Import') }}
|
||||
</x-button>
|
||||
</x-slot>
|
||||
</x-forms.form-section>
|
||||
|
||||
@livewire('import-portfolios-field')
|
||||
|
||||
<x-section-border />
|
||||
</div>
|
||||
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<x-forms.action-section submit="updateProfileInformation">
|
||||
<x-forms.action-section>
|
||||
<x-slot name="title">
|
||||
{{ __('Export') }}
|
||||
</x-slot>
|
||||
@@ -42,11 +19,9 @@
|
||||
|
||||
<x-slot name="content">
|
||||
|
||||
<!-- Name -->
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
@livewire('export-portfolios-button')
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</x-slot>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use Livewire\WithFileUploads;
|
||||
use Livewire\Volt\Component;
|
||||
use Mary\Traits\Toast;
|
||||
use App\Imports\BackupImport;
|
||||
|
||||
new class extends Component {
|
||||
use Toast;
|
||||
@@ -12,12 +13,41 @@ new class extends Component {
|
||||
public $file;
|
||||
|
||||
// methods
|
||||
public function mount()
|
||||
public function import()
|
||||
{
|
||||
|
||||
//
|
||||
$import = (new BackupImport)->import($this->file);
|
||||
|
||||
$this->success(__('Successfully imported!'));
|
||||
|
||||
// Artisan::queue(RefreshHoldingData::class);
|
||||
}
|
||||
|
||||
}; ?>
|
||||
|
||||
<x-file wire:model="file" label="{{ __('Select a file') }}" hint="" accept="application/pdf" required />
|
||||
<x-forms.form-section submit="import">
|
||||
<x-slot name="title">
|
||||
{{ __('Import') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="description">
|
||||
{{ __('Upload or recover your Investbrain portfolio and holdings.') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="form">
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<x-file wire:model="file" label="{{ __('Select a file') }}" hint="" accept=".xlsx" required />
|
||||
</div>
|
||||
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="actions">
|
||||
|
||||
<x-button type="submit">
|
||||
{{ __('Import') }}
|
||||
</x-button>
|
||||
</x-slot>
|
||||
</x-forms.form-section>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user