- small changes (#98)
* - added some test * - cr fix * wip * wip * Update resources/js/Shared/MainMenu.vue Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
33
app/Domain/Actions/CreateUserAction.php
Normal file
33
app/Domain/Actions/CreateUserAction.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Actions;
|
||||
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CreateUserAction
|
||||
{
|
||||
public function execute(array $data): User
|
||||
{
|
||||
$user = new User($data);
|
||||
|
||||
$user->save();
|
||||
|
||||
$this->createVacationLimitsFor($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function createVacationLimitsFor(User $user): void
|
||||
{
|
||||
$yearPeriods = YearPeriod::all();
|
||||
|
||||
foreach ($yearPeriods as $yearPeriod) {
|
||||
$user->vacationLimits()->create([
|
||||
"year_period_id" => $yearPeriod->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
53
app/Domain/Actions/CreateYearPeriodAction.php
Normal file
53
app/Domain/Actions/CreateYearPeriodAction.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Actions;
|
||||
|
||||
use Toby\Domain\PolishHolidaysRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CreateYearPeriodAction
|
||||
{
|
||||
public function __construct(
|
||||
protected PolishHolidaysRetriever $polishHolidaysRetriever,
|
||||
) {}
|
||||
|
||||
public function execute(int $year): YearPeriod
|
||||
{
|
||||
$yearPeriod = new YearPeriod([
|
||||
"year" => $year,
|
||||
]);
|
||||
|
||||
$yearPeriod->save();
|
||||
|
||||
$this->createVacationLimitsFor($yearPeriod);
|
||||
$this->createHolidaysFor($yearPeriod);
|
||||
|
||||
return $yearPeriod;
|
||||
}
|
||||
|
||||
protected function createVacationLimitsFor(YearPeriod $yearPeriod): void
|
||||
{
|
||||
$users = User::all();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$yearPeriod->vacationLimits()->create([
|
||||
"user_id" => $user->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createHolidaysFor(YearPeriod $yearPeriod): void
|
||||
{
|
||||
$holidays = $this->polishHolidaysRetriever->getForYearPeriod($yearPeriod);
|
||||
|
||||
foreach ($holidays as $holiday) {
|
||||
$yearPeriod->holidays()->create([
|
||||
"name" => $holiday["name"],
|
||||
"date" => $holiday["date"],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Toby\Domain;
|
||||
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
@@ -55,7 +54,7 @@ class CalendarGenerator
|
||||
{
|
||||
return Vacation::query()
|
||||
->whereBetween("date", [$period->start, $period->end])
|
||||
->whereRelation("vacationRequest", fn(Builder $query) => $query->states(VacationRequestStatesRetriever::successStates()))
|
||||
->approved()
|
||||
->with("vacationRequest")
|
||||
->get()
|
||||
->groupBy(fn(Vacation $vacation) => $vacation->date->toDateString());
|
||||
|
@@ -25,7 +25,6 @@ use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\States\VacationRequest\Approved;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
@@ -189,7 +188,7 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
|
||||
return $user->vacations()
|
||||
->with("vacationRequest")
|
||||
->whereBetween("date", [$period->start, $period->end])
|
||||
->whereRelation("vacationRequest", "state", Approved::$name)
|
||||
->approved()
|
||||
->get()
|
||||
->groupBy(
|
||||
[
|
||||
|
@@ -88,7 +88,7 @@ class UserVacationStatsRetriever
|
||||
$limit = $user->vacationLimits()
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->first()
|
||||
->days;
|
||||
?->days;
|
||||
|
||||
return $limit ?? 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user