#62 - vacation request list for approvers (#69)

* 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

* #62 - wip

* #62 - wip

* #62 - wip

* #62 - fix

* #62 - fix

* #62 - fix

* #62 - fix

* #62 - fix

* #62 - ecs fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
Adrian Hopek
2022-03-08 09:25:24 +01:00
committed by GitHub
parent af6f747aa2
commit db4be79c91
28 changed files with 753 additions and 146 deletions

View File

@@ -11,7 +11,6 @@ class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Carbon::macro("toDisplayString", fn() => $this->translatedFormat("j F Y"));
Carbon::macro("toDisplayDate", fn() => $this->translatedFormat("d.m.Y"));
Carbon::macro("toDisplayString", fn() => $this->translatedFormat("d.m.Y"));
}
}

View File

@@ -45,8 +45,8 @@ class VacationRequestApprovedNotification extends Notification
$user = $this->user->first_name;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayDate();
$to = $this->vacationRequest->to->toDisplayDate();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
$requester = $this->vacationRequest->user->fullName;

View File

@@ -45,8 +45,8 @@ class VacationRequestCancelledNotification extends Notification
$user = $this->user->first_name;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayDate();
$to = $this->vacationRequest->to->toDisplayDate();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
$requester = $this->vacationRequest->user->fullName;

View File

@@ -42,8 +42,8 @@ class VacationRequestCreatedNotification extends Notification
$user = $this->vacationRequest->user->first_name;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayDate();
$to = $this->vacationRequest->to->toDisplayDate();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
$appName = config("app.name");

View File

@@ -43,8 +43,8 @@ class VacationRequestCreatedOnEmployeeBehalf extends Notification
$user = $this->vacationRequest->user->first_name;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayDate();
$to = $this->vacationRequest->to->toDisplayDate();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
$appName = config("app.name");

View File

@@ -45,8 +45,8 @@ class VacationRequestRejectedNotification extends Notification
$user = $this->user->first_name;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayDate();
$to = $this->vacationRequest->to->toDisplayDate();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
$requester = $this->vacationRequest->user->fullName;

View File

@@ -46,8 +46,8 @@ class VacationRequestWaitsForAdminApprovalNotification extends Notification
$requester = $this->vacationRequest->user->fullName;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayDate();
$to = $this->vacationRequest->to->toDisplayDate();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
return (new MailMessage())

View File

@@ -46,8 +46,8 @@ class VacationRequestWaitsForTechApprovalNotification extends Notification
$requester = $this->vacationRequest->user->fullName;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayDate();
$to = $this->vacationRequest->to->toDisplayDate();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
return (new MailMessage())

View File

@@ -10,6 +10,11 @@ use Toby\Eloquent\Models\VacationRequest;
class VacationRequestPolicy
{
public function listAll(User $user): bool
{
return in_array($user->role, [Role::AdministrativeApprover, Role::TechnicalApprover], true);
}
public function createOnBehalfOfEmployee(User $user): bool
{
return $user->role === Role::AdministrativeApprover;

View File

@@ -24,8 +24,8 @@ use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Toby\Domain\Enums\VacationRequestState;
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 +189,7 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
return $user->vacations()
->with("vacationRequest")
->whereBetween("date", [$period->start, $period->end])
->whereRelation("vacationRequest", "state", VacationRequestState::Approved->value)
->whereRelation("vacationRequest", "state", Approved::$name)
->get()
->groupBy(
[

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Toby\Domain;
use Toby\Domain\Enums\Role;
use Toby\Domain\States\VacationRequest\AcceptedByAdministrative;
use Toby\Domain\States\VacationRequest\AcceptedByTechnical;
use Toby\Domain\States\VacationRequest\Approved;
@@ -12,6 +13,7 @@ use Toby\Domain\States\VacationRequest\Created;
use Toby\Domain\States\VacationRequest\Rejected;
use Toby\Domain\States\VacationRequest\WaitingForAdministrative;
use Toby\Domain\States\VacationRequest\WaitingForTechnical;
use Toby\Eloquent\Models\User;
class VacationRequestStatesRetriever
{
@@ -39,6 +41,16 @@ class VacationRequestStatesRetriever
];
}
public static function waitingForUserActionStates(User $user): array
{
return match ($user->role) {
Role::AdministrativeApprover => [WaitingForAdministrative::class],
Role::TechnicalApprover => [WaitingForTechnical::class],
Role::Administrator => [WaitingForAdministrative::class, WaitingForTechnical::class],
default => [],
};
}
public static function all(): array
{
return [
@@ -48,12 +60,13 @@ class VacationRequestStatesRetriever
];
}
public static function filterByStatus(string $filter): array
public static function filterByStatusGroup(string $filter, ?User $user = null): array
{
return match ($filter) {
"pending" => self::pendingStates(),
"success" => self::successStates(),
"failed" => self::failedStates(),
"waiting_for_action" => self::waitingForUserActionStates($user),
default => self::all(),
};
}

View File

@@ -35,10 +35,18 @@ class DashboardController extends Controller
)
->get();
$vacationRequests = VacationRequest::query()
->latest("updated_at")
->limit(3)
->get();
if ($user->can("listAll", VacationRequest::class)) {
$vacationRequests = VacationRequest::query()
->states(VacationRequestStatesRetriever::waitingForUserActionStates($user))
->latest("updated_at")
->limit(3)
->get();
} else {
$vacationRequests = $user->vacationRequests()
->latest("updated_at")
->limit(3)
->get();
}
$holidays = Holiday::query()
->whereDate("date", ">=", $now)
@@ -63,6 +71,9 @@ class DashboardController extends Controller
"pending" => $pending,
"other" => $other,
],
"can" => [
"listAllVacationRequests" => $user->can("listAll", VacationRequest::class),
],
]);
}
}

View File

@@ -40,7 +40,7 @@ class VacationRequestController extends Controller
->with("vacations")
->where("year_period_id", $yearPeriodRetriever->selected()->id)
->latest()
->states(VacationRequestStatesRetriever::filterByStatus($status))
->states(VacationRequestStatesRetriever::filterByStatusGroup($status, $request->user()))
->paginate();
return inertia("VacationRequest/Index", [
@@ -51,6 +51,45 @@ class VacationRequestController extends Controller
]);
}
public function indexForApprovers(
Request $request,
YearPeriodRetriever $yearPeriodRetriever,
): RedirectResponse|Response {
if ($request->user()->cannot("listAll", VacationRequest::class)) {
return redirect()->route("vacation.requests.index");
}
$yearPeriod = $yearPeriodRetriever->selected();
$status = $request->get("status");
$user = $request->get("user");
$vacationRequests = VacationRequest::query()
->with(["user", "vacations"])
->where("year_period_id", $yearPeriod->id)
->when($user !== null, fn(Builder $query) => $query->where("user_id", $user))
->when($status !== null, fn(Builder $query) => $query->states(VacationRequestStatesRetriever::filterByStatusGroup($status, $request->user())))
->latest()
->paginate();
$users = User::query()
->whereRelation(
"vacationlimits",
fn(Builder $query) => $query->where("year_period_id", $yearPeriod->id)->whereNotNull("days"),
)
->orderBy("last_name")
->orderBy("first_name")
->get();
return inertia("VacationRequest/IndexForApprovers", [
"requests" => VacationRequestResource::collection($vacationRequests),
"users" => UserResource::collection($users),
"filters" => [
"status" => $status,
"user" => $user,
],
]);
}
/**
* @throws AuthorizationException
*/

View File

@@ -7,6 +7,7 @@ namespace Toby\Infrastructure\Http\Middleware;
use Illuminate\Http\Request;
use Inertia\Middleware;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\VacationRequest;
use Toby\Infrastructure\Http\Resources\UserResource;
class HandleInertiaRequests extends Middleware
@@ -25,6 +26,7 @@ class HandleInertiaRequests extends Middleware
"can" => [
"manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false,
"manageUsers" => $user ? $user->can("manageUsers") : false,
"listAllVacationRequests" => $user ? $user->can("listAll", VacationRequest::class) : false,
],
],
"flash" => fn() => [

View File

@@ -13,7 +13,7 @@ class VacationRequestActivityResource extends JsonResource
public function toArray($request): array
{
return [
"date" => $this->created_at->toDisplayDate(),
"date" => $this->created_at->toDisplayString(),
"time" => $this->created_at->format("H:i"),
"user" => $this->user ? $this->user->fullName : __("System"),
"state" => $this->to,