mock up import export

This commit is contained in:
hackerESQ
2024-08-07 18:29:23 -05:00
parent b090908d09
commit 991d484152
19 changed files with 1085 additions and 2 deletions
+38
View File
@@ -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'],
]);
}
}
}