wip
This commit is contained in:
parent
5ded4008c7
commit
7381556f31
@ -7,7 +7,7 @@ namespace Toby\Domain\Enums;
|
||||
enum EmploymentForm: string
|
||||
{
|
||||
case EmploymentContract = "employment_contract";
|
||||
case ComissionContract = "commission_contract";
|
||||
case CommissionContract = "commission_contract";
|
||||
case B2bContract = "b2b_contract";
|
||||
case BoardMemberContract = "board_member_contract";
|
||||
|
||||
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\VacationRequestActivityFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
@ -17,6 +19,8 @@ use Toby\Domain\Enums\VacationRequestState;
|
||||
*/
|
||||
class VacationRequestActivity extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
@ -33,4 +37,9 @@ class VacationRequestActivity extends Model
|
||||
{
|
||||
return $this->belongsTo(VacationRequest::class);
|
||||
}
|
||||
|
||||
protected static function newFactory(): VacationRequestActivityFactory
|
||||
{
|
||||
return VacationRequestActivityFactory::new();
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class DashboardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected YearPeriodRetriever $yearPeriodRetriever
|
||||
protected YearPeriodRetriever $yearPeriodRetriever,
|
||||
) {
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ class DashboardController extends Controller
|
||||
->whereDate("date", Carbon::now())
|
||||
->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query->states(VacationRequestState::successStates())
|
||||
fn(Builder $query) => $query->states(VacationRequestState::successStates()),
|
||||
)
|
||||
->get();
|
||||
|
||||
@ -51,10 +51,10 @@ class DashboardController extends Controller
|
||||
->get();
|
||||
|
||||
$limit = $request->user()
|
||||
->vacationLimits()
|
||||
->where("year_period_id", $this->yearPeriodRetriever->current()->id)
|
||||
->first()
|
||||
->days ?? 0;
|
||||
->vacationLimits()
|
||||
->where("year_period_id", $this->yearPeriodRetriever->current()->id)
|
||||
->first()
|
||||
->days ?? 0;
|
||||
|
||||
$used = $request->user()
|
||||
->vacations()
|
||||
@ -62,7 +62,7 @@ class DashboardController extends Controller
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query
|
||||
->whereIn("type", $this->getLimitableVacationTypes())
|
||||
->noStates(VacationRequestState::successStates()),
|
||||
->states(VacationRequestState::successStates()),
|
||||
)
|
||||
->count();
|
||||
|
||||
@ -72,7 +72,7 @@ class DashboardController extends Controller
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query
|
||||
->whereIn("type", $this->getLimitableVacationTypes())
|
||||
->noStates(VacationRequestState::pendingStates()),
|
||||
->states(VacationRequestState::pendingStates()),
|
||||
)
|
||||
->count();
|
||||
|
||||
@ -82,7 +82,7 @@ class DashboardController extends Controller
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query
|
||||
->whereIn("type", $this->getNotLimitableVacationTypes())
|
||||
->noStates(VacationRequestState::successStates()),
|
||||
->states(VacationRequestState::successStates()),
|
||||
)
|
||||
->count();
|
||||
|
||||
|
22
database/factories/VacationRequestActivityFactory.php
Normal file
22
database/factories/VacationRequestActivityFactory.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Eloquent\Models\VacationRequestActivity;
|
||||
|
||||
class VacationRequestActivityFactory extends Factory
|
||||
{
|
||||
protected $model = VacationRequestActivity::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
"from" => $this->faker->randomElement(VacationRequestState::cases()),
|
||||
"to" => $this->faker->randomElement(VacationRequestState::cases()),
|
||||
];
|
||||
}
|
||||
}
|
225
database/seeders/DemoSeeder.php
Normal file
225
database/seeders/DemoSeeder.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\PolishHolidaysRetriever;
|
||||
use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Eloquent\Helpers\UserAvatarGenerator;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\VacationRequestActivity;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class DemoSeeder extends Seeder
|
||||
{
|
||||
public function __construct(
|
||||
protected UserAvatarGenerator $avatarGenerator,
|
||||
) {
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
User::unsetEventDispatcher();
|
||||
YearPeriod::unsetEventDispatcher();
|
||||
VacationRequest::unsetEventDispatcher();
|
||||
|
||||
$employee1 = User::factory([
|
||||
"first_name" => "Jan",
|
||||
"last_name" => "Kowalski",
|
||||
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "programista",
|
||||
"role" => Role::Employee,
|
||||
"employment_date" => Carbon::createFromDate(2021, 12, 31),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->create();
|
||||
|
||||
$employee2 = User::factory([
|
||||
"first_name" => "Anna",
|
||||
"last_name" => "Nowak",
|
||||
"email" => "anna.nowak@example.com",
|
||||
"employment_form" => EmploymentForm::CommissionContract,
|
||||
"position" => "tester",
|
||||
"role" => Role::Employee,
|
||||
"employment_date" => Carbon::createFromDate(2021, 5, 10),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->create();
|
||||
|
||||
$employee3 = User::factory([
|
||||
"first_name" => "Tola",
|
||||
"last_name" => "Sawicka",
|
||||
"email" => "tola.sawicka@example.com",
|
||||
"employment_form" => EmploymentForm::B2bContract,
|
||||
"position" => "programista",
|
||||
"role" => Role::Employee,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->create();
|
||||
|
||||
$technicalApprover = User::factory([
|
||||
"first_name" => "Maciej",
|
||||
"last_name" => "Ziółkowski",
|
||||
"email" => "maciej.ziolkowski@example.com",
|
||||
"employment_form" => EmploymentForm::BoardMemberContract,
|
||||
"position" => "programista",
|
||||
"role" => Role::TechnicalApprover,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->create();
|
||||
|
||||
$administrativeApprover = User::factory([
|
||||
"first_name" => "Katarzyna",
|
||||
"last_name" => "Zając",
|
||||
"email" => "katarzyna.zajac@example.com",
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "dyrektor",
|
||||
"role" => Role::AdministrativeApprover,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->create();
|
||||
|
||||
$admin = User::factory([
|
||||
"first_name" => "Miłosz",
|
||||
"last_name" => "Borowski",
|
||||
"email" => "milosz.borowski@example.com",
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "administrator",
|
||||
"role" => Role::Administrator,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->create();
|
||||
|
||||
$users = User::all();
|
||||
|
||||
$this->generateAvatarsForUsers($users);
|
||||
|
||||
$year = 2021;
|
||||
|
||||
YearPeriod::factory()
|
||||
->count(2)
|
||||
->sequence(
|
||||
[
|
||||
"year" => Carbon::createFromDate($year)->year,
|
||||
],
|
||||
[
|
||||
"year" => Carbon::createFromDate($year + 1)->year,
|
||||
],
|
||||
)
|
||||
->afterCreating(function (YearPeriod $yearPeriod) use ($users): void {
|
||||
foreach ($users as $user) {
|
||||
VacationLimit::factory([
|
||||
"days" => $user->employment_form === EmploymentForm::EmploymentContract ? 26 : null,
|
||||
])
|
||||
->for($yearPeriod)
|
||||
->for($user)
|
||||
->create();
|
||||
}
|
||||
})
|
||||
->afterCreating(function (YearPeriod $yearPeriod): void {
|
||||
$polishHolidaysRetriever = new PolishHolidaysRetriever();
|
||||
|
||||
foreach ($polishHolidaysRetriever->getForYearPeriod($yearPeriod) as $holiday) {
|
||||
$yearPeriod->holidays()->create([
|
||||
"name" => $holiday["name"],
|
||||
"date" => $holiday["date"],
|
||||
]);
|
||||
}
|
||||
})
|
||||
->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::query()->where("year", 2022)->first();
|
||||
|
||||
/** @var VacationRequest $vacationRequest */
|
||||
$vacationRequest = VacationRequest::factory([
|
||||
"type" => VacationType::Vacation->value,
|
||||
"state" => VacationRequestState::Created,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 1, 31)->toDateString(),
|
||||
"to" => Carbon::create($currentYearPeriod->year, 2, 4)->toDateString(),
|
||||
"comment" => "Komentarz do wniosku urlopowego.",
|
||||
])
|
||||
->for($employee1)
|
||||
->for($employee1, "creator")
|
||||
->for($currentYearPeriod)
|
||||
->afterCreating(function (VacationRequest $vacationRequest): void {
|
||||
$days = app(VacationDaysCalculator::class)->calculateDays(
|
||||
$vacationRequest->yearPeriod,
|
||||
$vacationRequest->from,
|
||||
$vacationRequest->to,
|
||||
);
|
||||
|
||||
foreach ($days as $day) {
|
||||
$vacationRequest->vacations()->create([
|
||||
"date" => $day,
|
||||
"user_id" => $vacationRequest->user->id,
|
||||
"year_period_id" => $vacationRequest->yearPeriod->id,
|
||||
]);
|
||||
}
|
||||
})
|
||||
->create();
|
||||
|
||||
VacationRequestActivity::factory([
|
||||
"from" => null,
|
||||
"to" => VacationRequestState::Created,
|
||||
])->for($vacationRequest)
|
||||
->for($employee1)
|
||||
->create();
|
||||
|
||||
VacationRequestActivity::factory([
|
||||
"from" => VacationRequestState::Created,
|
||||
"to" => VacationRequestState::WaitingForTechnical,
|
||||
])->for($vacationRequest)
|
||||
->create();
|
||||
|
||||
VacationRequestActivity::factory([
|
||||
"from" => VacationRequestState::WaitingForTechnical,
|
||||
"to" => VacationRequestState::AcceptedByTechnical,
|
||||
])->for($vacationRequest)
|
||||
->for($technicalApprover)
|
||||
->create();
|
||||
|
||||
VacationRequestActivity::factory([
|
||||
"from" => VacationRequestState::AcceptedByTechnical,
|
||||
"to" => VacationRequestState::WaitingForAdministrative,
|
||||
])->for($vacationRequest)
|
||||
->create();
|
||||
|
||||
VacationRequestActivity::factory([
|
||||
"from" => VacationRequestState::WaitingForAdministrative,
|
||||
"to" => VacationRequestState::AcceptedByAdministrative,
|
||||
])->for($vacationRequest)
|
||||
->for($administrativeApprover)
|
||||
->create();
|
||||
|
||||
VacationRequestActivity::factory([
|
||||
"from" => VacationRequestState::AcceptedByAdministrative,
|
||||
"to" => VacationRequestState::Approved,
|
||||
])->for($vacationRequest)
|
||||
->create();
|
||||
|
||||
$vacationRequest->changeStateTo(VacationRequestState::Approved);
|
||||
}
|
||||
|
||||
protected function generateAvatarsForUsers(Collection $users): void
|
||||
{
|
||||
foreach ($users as $user) {
|
||||
$user->saveAvatar($this->avatarGenerator->generateFor($user));
|
||||
}
|
||||
}
|
||||
}
|
@ -221,7 +221,7 @@ export default {
|
||||
default: () => ({
|
||||
used: 0,
|
||||
pending: 0,
|
||||
other: 0,
|
||||
remaining: 0,
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user