wip import backup

This commit is contained in:
hackerESQ
2024-08-27 22:41:13 -05:00
parent 12f3003a3a
commit 5e4b30e516
11 changed files with 60 additions and 150 deletions
+2 -5
View File
@@ -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,
];
}
}
-29
View File
@@ -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'],
]);
}
}
}
-35
View File
@@ -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']
]
);
}
}
}
+9 -9
View File
@@ -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();
});
}
-29
View File
@@ -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'],
]);
}
}
}