toby/app/Infrastructure/Console/Commands/RebuildDocumentNumberingSystem.php
2022-04-04 15:02:22 +02:00

35 lines
868 B
PHP

<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Console\Commands;
use Illuminate\Console\Command;
use Toby\Eloquent\Models\YearPeriod;
class RebuildDocumentNumberingSystem extends Command
{
protected $signature = "toby:rebuild-document-numbering-system";
protected $description = "Rebuilds the document numbering system to {number}/{year}";
public function handle(): void
{
$yearPeriods = YearPeriod::all();
foreach ($yearPeriods as $yearPeriod) {
$number = 1;
$vacationRequests = $yearPeriod
->vacationRequests()
->oldest()
->get();
foreach ($vacationRequests as $vacationRequest) {
$vacationRequest->update(["name" => "{$number}/{$yearPeriod->year}"]);
$number++;
}
}
}
}