- change document numbering system (#106)

This commit is contained in:
Adrian Hopek
2022-04-04 15:02:22 +02:00
committed by GitHub
parent 1ae23bd7cb
commit 3ab02f1df4
6 changed files with 84 additions and 5 deletions

View File

@@ -0,0 +1,34 @@
<?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++;
}
}
}
}