mock up import export
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sheets;
|
||||
|
||||
use App\Models\DailyChange;
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class DailyChangesSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
public function collection(Collection $dailyChanges)
|
||||
{
|
||||
foreach ($dailyChanges->sortBy('date') as $row) {
|
||||
if ($row['user'] != auth()->user()->id) {
|
||||
throw new Exception('Can\'t do that.');
|
||||
}
|
||||
|
||||
DailyChange::updateOrCreate([
|
||||
'date' => $row['date'],
|
||||
'user_id' => $row['user'],
|
||||
],[
|
||||
'user_id' => $row['user'],
|
||||
'date' => $row['date'],
|
||||
'total_market_value' => $row['total_market_value'],
|
||||
'total_cost_basis' => $row['total_cost_basis'],
|
||||
'total_gain_loss' => $row['total_gain_loss'],
|
||||
'total_dividends' => $row['total_dividends'],
|
||||
'realized_gains' => $row['realized_gains'],
|
||||
'notes' => $row['notes'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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']
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sheets;
|
||||
|
||||
use App\Models\Portfolio;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class PortfoliosSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
public function collection(Collection $portfolios)
|
||||
{
|
||||
foreach ($portfolios->sortBy('date') as $row) {
|
||||
|
||||
Portfolio::myPortfolios()
|
||||
->where(['id' => $row['id']])
|
||||
->orWhere(['title' => $row['title']])
|
||||
->firstOr(function () use ($row) {
|
||||
|
||||
return Portfolio::make()->forceFill([
|
||||
'id' => $row['id'] ?? null,
|
||||
'title' => $row['title'],
|
||||
'wishlist' => $row['wishlist'] ?? false,
|
||||
'notes' => $row['notes'],
|
||||
])->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Sheets;
|
||||
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class TransactionsSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
public function collection(Collection $transactions)
|
||||
{
|
||||
foreach ($transactions->sortBy('date') as $row) {
|
||||
|
||||
Transaction::updateOrCreate([
|
||||
'id' => $row['id'],
|
||||
],[
|
||||
'id' => $row['id'],
|
||||
'symbol' => $row['symbol'],
|
||||
'portfolio_id' => $row['portfolio'],
|
||||
'transaction_type' => $row['transaction'],
|
||||
'quantity' => $row['quantity'],
|
||||
'cost_basis' => $row['cost_basis'] ?? 0,
|
||||
'sale_price' => $row['sale_price'],
|
||||
'split' => $row['split'] ?? null,
|
||||
'date' => $row['date'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user