Skip to content

Commit

Permalink
#444 - cr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Jun 19, 2024
1 parent f5c2628 commit d0f84f0
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 31 deletions.
2 changes: 2 additions & 0 deletions app/Helpers/DateFormats.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class DateFormats
{
public const DATETIME = "Y-m-d H:i";
public const DATE = "Y-m-d";
public const DATETIME_DISPLAY = "d-m-Y H:i";
public const DATE_DISPLAY = "d-m-Y";
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/OvertimeRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@

class OvertimeRequestController extends Controller
{
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): RedirectResponse|Response
{
if ($request->user()->can("listAllRequests")) {
return redirect()->route("overtime.requests.indexForApprovers");
}
$this->authorize("canUseOvertimeRequestFunctionality", $request->user());

$status = $request->get("status", "all");
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use Illuminate\Http\Request;
use Inertia\Middleware;
use Spatie\Permission\Models\Permission;
use Toby\Domain\OvertimeRequestStatesRetriever;
use Toby\Domain\VacationRequestStatesRetriever;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Http\Resources\UserResource;
use Toby\Models\OvertimeRequest;
use Toby\Models\User;
use Toby\Models\VacationRequest;

Expand All @@ -30,6 +32,7 @@ public function share(Request $request): array
"flash" => $this->getFlashData($request),
"years" => $this->getYearsData($request),
"vacationRequestsCount" => $this->getVacationRequestsCount($request),
"overtimeRequestsCount" => $this->getOvertimeRequestsCount($request),
"deployInformation" => $this->getDeployInformation(),
"lastUpdate" => $this->cache->rememberForever("last_update", fn(): string => Carbon::now()->toIso8601String()),
]);
Expand Down Expand Up @@ -80,6 +83,20 @@ protected function getVacationRequestsCount(Request $request): Closure
: null;
}

protected function getOvertimeRequestsCount(Request $request): Closure
{
$user = $request->user();

return fn(): ?int => $user && $user->can("listAllRequests")
? OvertimeRequest::query()
->whereBelongsTo($this->yearPeriodRetriever->selected())
->states(
OvertimeRequestStatesRetriever::waitingForUserActionStates($user),
)
->count()
: null;
}

protected function getDeployInformation(): Closure
{
return fn(): array => [
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Resources/OvertimeRequestResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function toArray($request): array
"name" => $this->name,
"user" => new SimpleUserResource($this->user),
"state" => $this->state,
"from" => $this->from->format(DateFormats::DATETIME),
"to" => $this->to->format(DateFormats::DATETIME),
"from" => $this->from->format(DateFormats::DATETIME_DISPLAY),
"to" => $this->to->format(DateFormats::DATETIME_DISPLAY),
"hours" => $this->hours,
"settlementType" => $this->settlement_type,
"settled" => $this->settled,
"displayDate" => $this->getDate($this->from->toDisplayString(), $this->to->toDisplayString()),
"displayDate" => $this->getDate($this->from->toDisplayString(DateFormats::DATETIME_DISPLAY), $this->to->toDisplayString(DateFormats::DATETIME_DISPLAY)),
"comment" => $this->comment,
"can" => [
"acceptAsTechnical" => $this->resource->state->canTransitionTo(AcceptedByTechnical::class)
Expand Down
2 changes: 1 addition & 1 deletion app/Observers/OvertimeRequestObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function creating(OvertimeRequest $overtime): void
$count = $overtime->yearPeriod->overtimeRequests()->count();
$number = $count + 1;

$overtime->name = "{$number}/{$overtime->yearPeriod->year}";
$overtime->name = "N/{$number}/{$overtime->yearPeriod->year}";
}

public function updating(OvertimeRequest $overtime): void
Expand Down
9 changes: 8 additions & 1 deletion app/States/OvertimeRequest/OvertimeRequestState.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ public static function config(): StateConfig
AcceptedByTechnical::class,
Approved::class,
], Cancelled::class)
->allowTransition(Approved::class, Settled::class);
->allowTransition(Approved::class, Settled::class)
->allowTransition([
Created::class,
WaitingForTechnical::class,
AcceptedByTechnical::class,
Approved::class,
Settled::class,
], Cancelled::class);
}

public function label(): string
Expand Down
3 changes: 3 additions & 0 deletions lang/pl/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
"birthday" => [
"before" => "Data urodzenia musi być datą wcześniejszą od dzisiaj.",
],
"to" => [
"after" => "Data końcowa musi być datą późniejszą od daty początkowej.",
],
],
"attributes" => [
"to" => "do",
Expand Down
41 changes: 24 additions & 17 deletions resources/js/Pages/OvertimeRequest/ApproversIndex.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import { CheckIcon, ChevronRightIcon, ChevronUpDownIcon } from '@heroicons/vue/24/solid'
import Status from '@/Shared/Status.vue'
import { watch, reactive } from 'vue'
import { reactive, watch } from 'vue'
import { debounce } from 'lodash'
import { Inertia } from '@inertiajs/inertia'
import { Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions } from '@headlessui/vue'
Expand All @@ -10,6 +10,7 @@ import EmptyState from '@/Shared/Feedbacks/EmptyState.vue'
import SettlementType from '@/Shared/SettlementType.vue'
const props = defineProps({
auth: Object,
requests: Object,
users: Object,
filters: Object,
Expand Down Expand Up @@ -62,10 +63,16 @@ watch(form, debounce(() => {
<InertiaHead title="Wnioski" />
<div class="bg-white shadow-md">
<div class="flex justify-between items-center p-4 sm:px-6">
<div>
<h2 class="text-lg font-medium leading-6 text-gray-900">
Lista wniosków
</h2>
<h2 class="text-lg font-medium leading-6 text-gray-900">
Lista wniosków
</h2>
<div v-if="props.auth.overtimeEnabled">
<InertiaLink
class="inline-flex items-center py-3 px-4 text-sm font-medium leading-4 text-white bg-blumilk-600 hover:bg-blumilk-700 rounded-md border border-transparent focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm"
href="/overtime/requests/create"
>
Dodaj wniosek
</InertiaLink>
</div>
</div>
<div class="border-t border-gray-200">
Expand Down Expand Up @@ -109,8 +116,8 @@ watch(form, debounce(() => {
>
<ListboxOption
v-slot="{ active }"
as="template"
:value="null"
as="template"
>
<li
:class="[active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']"
Expand All @@ -131,8 +138,8 @@ watch(form, debounce(() => {
v-for="user in users.data"
:key="user.id"
v-slot="{ active }"
as="template"
:value="user"
as="template"
>
<li
:class="[active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']"
Expand Down Expand Up @@ -191,8 +198,8 @@ watch(form, debounce(() => {
v-for="status in statuses"
:key="status.value"
v-slot="{ active, selected }"
as="template"
:value="status"
as="template"
>
<li
:class="[active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default truncate select-none relative py-2 pl-3 pr-9']"
Expand All @@ -218,44 +225,44 @@ watch(form, debounce(() => {
<thead class="bg-gray-50">
<tr>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
scope="col"
>
Numer
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
scope="col"
>
Pracownik
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
scope="col"
>
Od
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
scope="col"
>
Do
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
scope="col"
>
Liczba godzin
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
scope="col"
>
Sposób rozliczenia
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
scope="col"
>
Status
</th>
Expand All @@ -266,8 +273,8 @@ watch(form, debounce(() => {
<InertiaLink
v-for="request in requests.data"
:key="request.id"
as="tr"
:href="`/overtime/requests/${request.id}`"
as="tr"
class="relative hover:bg-blumilk-25 hover:cursor-pointer"
>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
Expand Down Expand Up @@ -319,8 +326,8 @@ watch(form, debounce(() => {
</InertiaLink>
<tr v-if="! requests.data.length">
<td
colspan="100%"
class="py-4 text-xl leading-5 text-center text-gray-700"
colspan="100%"
>
<EmptyState>
<template #title>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/OvertimeRequest/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ defineProps({
</h3>
<div class="mt-2 max-w-xl text-sm text-gray-500">
<p>
Rozliczenie nadgodzin oznaczy nadgodziny jako rozliczone.
Rozliczenie nadgodzin spowoduje oznaczenie ich jako rozliczone.
</p>
</div>
<div class="mt-5">
Expand Down
2 changes: 2 additions & 0 deletions resources/js/Shared/Layout/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const props = defineProps({
auth: Object,
years: Object,
vacationRequestsCount: Number,
overtimeRequestsCount: Number,
deployInformation: Object,
lastUpdate: String,
})
Expand Down Expand Up @@ -51,6 +52,7 @@ function vacationPageOpened() {
:auth="auth"
:show-refresh-button="isUpdated"
:vacation-requests-count="vacationRequestsCount"
:overtime-requests-count="overtimeRequestsCount"
:years="years"
@open="vacationPageOpened"
/>
Expand Down
16 changes: 9 additions & 7 deletions resources/js/Shared/MainMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const props = defineProps({
auth: Object,
years: Object,
vacationRequestsCount: Number,
overtimeRequestsCount: Number,
showRefreshButton: Boolean,
lastUpdate: String,
})
Expand All @@ -54,13 +55,6 @@ const vacationNavigation = computed(() =>
icon: DocumentTextIcon,
can: !props.auth.can.listAllRequests,
},
{
name: 'Moje nadgodziny',
href: '/overtime/requests/me',
section: 'OvertimeRequest/Index',
icon: ClockIcon,
can: props.auth.overtimeEnabled,
},
{
name: 'Wnioski',
href: '/vacation/requests',
Expand All @@ -75,6 +69,14 @@ const vacationNavigation = computed(() =>
section: 'OvertimeRequest/ApproversIndex',
icon: ClockIcon,
can: props.auth.can.listAllRequests,
badge: props.overtimeRequestsCount,
},
{
name: 'Moje nadgodziny',
href: '/overtime/requests/me',
section: 'OvertimeRequest/ApproversIndex',
icon: ClockIcon,
can: !props.auth.can.listAllRequests && props.auth.overtimeEnabled,
},
{
name: 'Kalendarz',
Expand Down

0 comments on commit d0f84f0

Please sign in to comment.