- directory refactor (#32)
* - directory refactor * - readme.md update * Update readme.md Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
44
app/Infrastructure/Jobs/CheckYearPeriod.php
Normal file
44
app/Infrastructure/Jobs/CheckYearPeriod.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CheckYearPeriod implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use Queueable;
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
if ($currentYearPeriod === null) {
|
||||
$this->createCurrentYearPeriod();
|
||||
}
|
||||
|
||||
if (YearPeriod::query()->max("year") === Carbon::now()->year) {
|
||||
$this->createNextYearPeriod();
|
||||
}
|
||||
}
|
||||
|
||||
protected function createCurrentYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createNextYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year + 1,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user