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'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user