wip
This commit is contained in:
@@ -2,18 +2,17 @@
|
||||
|
||||
namespace App\Imports\Sheets;
|
||||
|
||||
use App\Models\DailyChange;
|
||||
use Exception;
|
||||
use App\Models\DailyChange;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithValidation;
|
||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||
|
||||
class DailyChangesSheet implements ToCollection, WithHeadingRow, WithValidation, SkipsEmptyRows
|
||||
class DailyChangesSheet implements ToCollection, WithHeadingRow, WithValidation, SkipsEmptyRows, WithChunkReading
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
public function collection(Collection $dailyChanges)
|
||||
{
|
||||
|
||||
@@ -27,22 +26,25 @@ class DailyChangesSheet implements ToCollection, WithHeadingRow, WithValidation,
|
||||
}
|
||||
});
|
||||
|
||||
foreach ($dailyChanges as $dailyChange) {
|
||||
DailyChange::withoutEvents(function () use ($dailyChanges) {
|
||||
|
||||
foreach ($dailyChanges as $dailyChange) {
|
||||
|
||||
DailyChange::updateOrCreate([
|
||||
'date' => $dailyChange['date'],
|
||||
'portfolio_id' => $dailyChange['portfolio_id'],
|
||||
],[
|
||||
'portfolio_id' => $dailyChange['portfolio_id'],
|
||||
'date' => $dailyChange['date'],
|
||||
'total_market_value' => $dailyChange['total_market_value'],
|
||||
'total_cost_basis' => $dailyChange['total_cost_basis'],
|
||||
'total_gain' => $dailyChange['total_gain'],
|
||||
'total_dividends' => $dailyChange['total_dividends'],
|
||||
'realized_gains' => $dailyChange['realized_gains'],
|
||||
'annotation' => $dailyChange['annotation'],
|
||||
]);
|
||||
}
|
||||
DailyChange::updateOrCreate([
|
||||
'date' => $dailyChange['date'],
|
||||
'portfolio_id' => $dailyChange['portfolio_id'],
|
||||
],[
|
||||
'portfolio_id' => $dailyChange['portfolio_id'],
|
||||
'date' => $dailyChange['date'],
|
||||
'total_market_value' => $dailyChange['total_market_value'],
|
||||
'total_cost_basis' => $dailyChange['total_cost_basis'],
|
||||
'total_gain' => $dailyChange['total_gain'],
|
||||
'total_dividends' => $dailyChange['total_dividends'],
|
||||
'realized_gains' => $dailyChange['realized_gains'],
|
||||
'annotation' => $dailyChange['annotation'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
@@ -58,4 +60,9 @@ class DailyChangesSheet implements ToCollection, WithHeadingRow, WithValidation,
|
||||
'annotation' => ['sometimes', 'nullable', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
public function chunkSize(): int
|
||||
{
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user