- change document numbering system (#106)
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user