* wip * wip * wip * wip * wip * wip * wip * #5 - bump dependencies * #43 - wip * #43 - add composer script * #43 - fix * #43 - fix * #43 - wip * #43 - ecs fix * #43 - cr fix * #43 - cr fix * #43 - fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
@@ -16,8 +16,7 @@ class CalendarGenerator
|
||||
{
|
||||
public function __construct(
|
||||
protected YearPeriodRetriever $yearPeriodRetriever,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function generate(Carbon $month): array
|
||||
{
|
||||
|
@@ -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";
|
||||
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestAcceptedByAdministrative
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestAcceptedByTechnical
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestApproved
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestCancelled
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestCreated
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestRejected
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -20,6 +20,5 @@ class VacationRequestStateChanged
|
||||
public ?VacationRequestState $from,
|
||||
public VacationRequestState $to,
|
||||
public ?User $user = null,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestWaitsForAdminApproval
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -15,6 +15,5 @@ class VacationRequestWaitsForTechApproval
|
||||
|
||||
public function __construct(
|
||||
public VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
@@ -11,8 +11,7 @@ class HandleAcceptedByAdministrativeVacationRequest
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationRequestStateManager $stateManager,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestAcceptedByAdministrative $event): void
|
||||
{
|
||||
|
@@ -13,8 +13,7 @@ class HandleAcceptedByTechnicalVacationRequest
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationRequestStateManager $stateManager,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestAcceptedByTechnical $event): void
|
||||
{
|
||||
|
@@ -13,8 +13,7 @@ class HandleCreatedVacationRequest
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationRequestStateManager $stateManager,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestCreated $event): void
|
||||
{
|
||||
|
@@ -13,8 +13,7 @@ use Toby\Eloquent\Models\User;
|
||||
class SendApprovedVacationRequestNotification
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestApproved $event): void
|
||||
{
|
||||
|
@@ -13,8 +13,7 @@ use Toby\Eloquent\Models\User;
|
||||
class SendCancelledVacationRequestNotification
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestCancelled $event): void
|
||||
{
|
||||
|
@@ -11,8 +11,7 @@ use Toby\Domain\Notifications\VacationRequestCreatedOnEmployeeBehalf;
|
||||
class SendCreatedVacationRequestNotification
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestCreated $event): void
|
||||
{
|
||||
|
@@ -13,8 +13,7 @@ use Toby\Eloquent\Models\User;
|
||||
class SendRejectedVacationRequestNotification
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestRejected $event): void
|
||||
{
|
||||
|
@@ -13,8 +13,7 @@ use Toby\Eloquent\Models\User;
|
||||
class SendWaitedForAdministrativeVacationRequestNotification
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestWaitsForAdminApproval $event): void
|
||||
{
|
||||
|
@@ -13,8 +13,7 @@ use Toby\Eloquent\Models\User;
|
||||
class SendWaitedForTechnicalVacationRequestNotification
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function handle(VacationRequestWaitsForTechApproval $event): void
|
||||
{
|
||||
|
@@ -18,8 +18,7 @@ class VacationRequestApprovedNotification extends Notification
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
protected User $user,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
|
@@ -18,8 +18,7 @@ class VacationRequestCancelledNotification extends Notification
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
protected User $user,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
|
@@ -16,8 +16,7 @@ class VacationRequestCreatedNotification extends Notification
|
||||
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
|
@@ -16,8 +16,7 @@ class VacationRequestCreatedOnEmployeeBehalf extends Notification
|
||||
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
|
@@ -18,8 +18,7 @@ class VacationRequestRejectedNotification extends Notification
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
protected User $user,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
|
@@ -18,8 +18,7 @@ class VacationRequestWaitsForAdminApprovalNotification extends Notification
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
protected User $user,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
|
@@ -18,8 +18,7 @@ class VacationRequestWaitsForTechApprovalNotification extends Notification
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
protected User $user,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
|
@@ -41,8 +41,7 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
|
||||
public function __construct(
|
||||
protected User $user,
|
||||
protected Carbon $month,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
|
93
app/Domain/UserVacationStatsRetriever.php
Normal file
93
app/Domain/UserVacationStatsRetriever.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class UserVacationStatsRetriever
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
) {}
|
||||
|
||||
public function getUsedVacationDays(User $user, YearPeriod $yearPeriod): int
|
||||
{
|
||||
return $user
|
||||
->vacations()
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query
|
||||
->whereIn("type", $this->getLimitableVacationTypes())
|
||||
->states(VacationRequestStatesRetriever::successStates()),
|
||||
)
|
||||
->count();
|
||||
}
|
||||
|
||||
public function getPendingVacationDays(User $user, YearPeriod $yearPeriod): int
|
||||
{
|
||||
return $user
|
||||
->vacations()
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query
|
||||
->whereIn("type", $this->getLimitableVacationTypes())
|
||||
->states(VacationRequestStatesRetriever::pendingStates()),
|
||||
)
|
||||
->count();
|
||||
}
|
||||
|
||||
public function getOtherApprovedVacationDays(User $user, YearPeriod $yearPeriod): int
|
||||
{
|
||||
return $user
|
||||
->vacations()
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query
|
||||
->whereIn("type", $this->getNotLimitableVacationTypes())
|
||||
->states(VacationRequestStatesRetriever::successStates()),
|
||||
)
|
||||
->count();
|
||||
}
|
||||
|
||||
public function getRemainingVacationDays(User $user, YearPeriod $yearPeriod): int
|
||||
{
|
||||
$limit = $this->getVacationDaysLimit($user, $yearPeriod);
|
||||
$used = $this->getUsedVacationDays($user, $yearPeriod);
|
||||
$pending = $this->getPendingVacationDays($user, $yearPeriod);
|
||||
|
||||
return $limit - $used - $pending;
|
||||
}
|
||||
|
||||
public function getVacationDaysLimit(User $user, YearPeriod $yearPeriod): int
|
||||
{
|
||||
$limit = $user->vacationLimits()
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->first()
|
||||
->days;
|
||||
|
||||
return $limit ?? 0;
|
||||
}
|
||||
|
||||
protected function getLimitableVacationTypes(): Collection
|
||||
{
|
||||
$types = new Collection(VacationType::cases());
|
||||
|
||||
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
|
||||
}
|
||||
|
||||
protected function getNotLimitableVacationTypes(): Collection
|
||||
{
|
||||
$types = new Collection(VacationType::cases());
|
||||
|
||||
return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type));
|
||||
}
|
||||
}
|
@@ -31,8 +31,7 @@ class VacationRequestStateManager
|
||||
public function __construct(
|
||||
protected Auth $auth,
|
||||
protected Dispatcher $dispatcher,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function markAsCreated(VacationRequest $vacationRequest, ?User $user = null): void
|
||||
{
|
||||
|
@@ -16,8 +16,7 @@ class VacationTypeConfigRetriever
|
||||
|
||||
public function __construct(
|
||||
protected Repository $config,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function needsTechnicalApproval(VacationType $type): bool
|
||||
{
|
||||
|
@@ -19,8 +19,7 @@ class DoesNotExceedLimitRule implements VacationRequestRule
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationDaysCalculator $vacationDaysCalculator,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function check(VacationRequest $vacationRequest): bool
|
||||
{
|
||||
|
@@ -11,8 +11,7 @@ class MinimumOneVacationDayRule implements VacationRequestRule
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationDaysCalculator $vacationDaysCalculator,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function check(VacationRequest $vacationRequest): bool
|
||||
{
|
||||
|
@@ -26,8 +26,7 @@ class VacationRequestValidator
|
||||
|
||||
public function __construct(
|
||||
protected Container $container,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
|
Reference in New Issue
Block a user