better way to import daily changes
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Imports\Sheets;
|
namespace App\Imports\Sheets;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use App\Models\DailyChange;
|
use App\Models\DailyChange;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||||
@@ -20,22 +19,26 @@ class DailyChangesSheet implements ToCollection, WithHeadingRow, WithValidation,
|
|||||||
{
|
{
|
||||||
$this->validatePortfolioPermissions($dailyChanges);
|
$this->validatePortfolioPermissions($dailyChanges);
|
||||||
|
|
||||||
foreach ($dailyChanges as $dailyChange) {
|
$chunkSize = 180;
|
||||||
|
|
||||||
DailyChange::updateOrCreate([
|
$dailyChanges->chunk($chunkSize)->each(function ($chunk) {
|
||||||
'date' => $dailyChange['date'],
|
|
||||||
'portfolio_id' => $dailyChange['portfolio_id'],
|
DailyChange::upsert(
|
||||||
],[
|
$chunk->toArray(),
|
||||||
'portfolio_id' => $dailyChange['portfolio_id'],
|
[
|
||||||
'date' => $dailyChange['date'],
|
'portfolio_id',
|
||||||
'total_market_value' => $dailyChange['total_market_value'],
|
'date'
|
||||||
'total_cost_basis' => $dailyChange['total_cost_basis'],
|
],
|
||||||
'total_gain' => $dailyChange['total_gain'],
|
[
|
||||||
'total_dividends_earned' => $dailyChange['total_dividends'],
|
'total_market_value',
|
||||||
'realized_gains' => $dailyChange['realized_gains'],
|
'total_cost_basis',
|
||||||
'annotation' => $dailyChange['annotation'],
|
'total_gain',
|
||||||
]);
|
'total_dividends_earned',
|
||||||
}
|
'realized_gains',
|
||||||
|
'annotation'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
|
|||||||
Reference in New Issue
Block a user