Merge branch 'main' into #22-vacation-calendar

This commit is contained in:
Adrian Hopek 2022-02-07 12:31:27 +01:00
commit 072fa6d432
44 changed files with 925 additions and 134 deletions

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Toby\Domain;
use Carbon\CarbonInterface;
use Carbon\CarbonPeriod;
use Illuminate\Support\Collection;
use Toby\Eloquent\Models\YearPeriod;
class VacationDaysCalculator
{
public function calculateDays(YearPeriod $yearPeriod, CarbonInterface $from, CarbonInterface $to): Collection
{
$period = CarbonPeriod::create($from, $to);
$holidays = $yearPeriod->holidays()->pluck("date");
$validDays = collect();
foreach ($period as $day) {
if ($this->passes($day, $holidays)) {
$validDays->add($day);
}
}
return $validDays;
}
protected function passes(CarbonInterface $day, Collection $holidays): bool
{
if ($day->isWeekend()) {
return false;
}
if ($holidays->contains($day)) {
return false;
}
return true;
}
}

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Closure;
use Toby\Eloquent\Models\VacationRequest;
class ApprovedVacationDaysInSameRange implements VacationRequestRule
{
public function check(VacationRequest $vacationRequest, Closure $next)
{
return $next($vacationRequest);
}
}

View File

@ -4,13 +4,23 @@ declare(strict_types=1);
namespace Toby\Domain\Validation\Rules; namespace Toby\Domain\Validation\Rules;
use Closure; use Toby\Domain\VacationTypeConfigRetriever;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
class DoesNotExceedLimitRule implements VacationRequestRule class DoesNotExceedLimitRule implements VacationRequestRule
{ {
public function check(VacationRequest $vacationRequest, Closure $next) public function __construct(
protected VacationTypeConfigRetriever $configRetriever,
) {
}
public function check(VacationRequest $vacationRequest): bool
{ {
return $next($vacationRequest); return true;
}
public function errorMessage(): string
{
return __("You have exceeded your vacation limit.");
} }
} }

View File

@ -4,13 +4,25 @@ declare(strict_types=1);
namespace Toby\Domain\Validation\Rules; namespace Toby\Domain\Validation\Rules;
use Closure; use Toby\Domain\VacationDaysCalculator;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
class MinimumOneVacationDayRule implements VacationRequestRule class MinimumOneVacationDayRule implements VacationRequestRule
{ {
public function check(VacationRequest $vacationRequest, Closure $next) public function __construct(
protected VacationDaysCalculator $vacationDaysCalculator,
) {
}
public function check(VacationRequest $vacationRequest): bool
{ {
return $next($vacationRequest); return $this->vacationDaysCalculator
->calculateDays($vacationRequest->yearPeriod, $vacationRequest->from, $vacationRequest->to)
->isNotEmpty();
}
public function errorMessage(): string
{
return __("Vacation needs minimum one day.");
} }
} }

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Toby\Domain\Enums\VacationRequestState;
use Toby\Eloquent\Models\VacationRequest;
class NoApprovedVacationRequestsInRange implements VacationRequestRule
{
public function check(VacationRequest $vacationRequest): bool
{
return !$vacationRequest
->user
->vacationRequests()
->overlapsWith($vacationRequest)
->states(VacationRequestState::successStates())
->exists();
}
public function errorMessage(): string
{
return __("You have approved vacation request in this range.");
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Toby\Domain\Enums\VacationRequestState;
use Toby\Eloquent\Models\VacationRequest;
class NoPendingVacationRequestInRange implements VacationRequestRule
{
public function check(VacationRequest $vacationRequest): bool
{
return !$vacationRequest
->user
->vacationRequests()
->overlapsWith($vacationRequest)
->states(VacationRequestState::pendingStates())
->exists();
}
public function errorMessage(): string
{
return __("You have pending vacation request in this range.");
}
}

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Closure;
use Toby\Eloquent\Models\VacationRequest;
class PendingVacationRequestInSameRange implements VacationRequestRule
{
public function check(VacationRequest $vacationRequest, Closure $next)
{
return $next($vacationRequest);
}
}

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Closure;
use Toby\Eloquent\Models\VacationRequest;
class UsedVacationDaysInSameRange
{
public function check(VacationRequest $vacationRequest, Closure $next)
{
return $next($vacationRequest);
}
}

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Toby\Eloquent\Models\VacationRequest;
class VacationRangeIsInTheSameYearRule implements VacationRequestRule
{
public function check(VacationRequest $vacationRequest): bool
{
return $vacationRequest->from->isSameYear($vacationRequest->to);
}
public function errorMessage(): string
{
return __("The vacation request cannot be created at the turn of the year.");
}
}

View File

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Toby\Domain\Validation\Rules; namespace Toby\Domain\Validation\Rules;
use Closure;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
interface VacationRequestRule interface VacationRequestRule
{ {
public function check(VacationRequest $vacationRequest, Closure $next); public function check(VacationRequest $vacationRequest): bool;
public function errorMessage(): string;
} }

View File

@ -4,32 +4,49 @@ declare(strict_types=1);
namespace Toby\Domain\Validation; namespace Toby\Domain\Validation;
use Illuminate\Pipeline\Pipeline; use Illuminate\Contracts\Container\Container;
use Toby\Domain\Validation\Rules\ApprovedVacationDaysInSameRange; use Illuminate\Validation\ValidationException;
use Toby\Domain\Validation\Rules\DoesNotExceedLimitRule; use Toby\Domain\Validation\Rules\DoesNotExceedLimitRule;
use Toby\Domain\Validation\Rules\MinimumOneVacationDayRule; use Toby\Domain\Validation\Rules\MinimumOneVacationDayRule;
use Toby\Domain\Validation\Rules\PendingVacationRequestInSameRange; use Toby\Domain\Validation\Rules\NoApprovedVacationRequestsInRange;
use Toby\Domain\Validation\Rules\NoPendingVacationRequestInRange;
use Toby\Domain\Validation\Rules\VacationRangeIsInTheSameYearRule;
use Toby\Domain\Validation\Rules\VacationRequestRule;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
class VacationRequestValidator class VacationRequestValidator
{ {
protected array $rules = [ protected array $rules = [
VacationRangeIsInTheSameYearRule::class,
MinimumOneVacationDayRule::class, MinimumOneVacationDayRule::class,
DoesNotExceedLimitRule::class, DoesNotExceedLimitRule::class,
PendingVacationRequestInSameRange::class, NoPendingVacationRequestInRange::class,
ApprovedVacationDaysInSameRange::class, NoApprovedVacationRequestsInRange::class,
]; ];
public function __construct( public function __construct(
protected Pipeline $pipeline, protected Container $container,
) { ) {
} }
/**
* @throws ValidationException
*/
public function validate(VacationRequest $vacationRequest): void public function validate(VacationRequest $vacationRequest): void
{ {
$this->pipeline foreach ($this->rules as $rule) {
->send($vacationRequest) $rule = $this->makeRule($rule);
->through($this->rules)
->via("check"); if (!$rule->check($vacationRequest)) {
throw ValidationException::withMessages([
"vacationRequest" => $rule->errorMessage(),
]);
}
}
}
protected function makeRule(string $class): VacationRequestRule
{
return $this->container->make($class);
} }
} }

View File

@ -22,6 +22,7 @@ use Toby\Domain\Enums\Role;
* @property string $last_name * @property string $last_name
* @property string $email * @property string $email
* @property string $avatar * @property string $avatar
* @property string $position
* @property Role $role * @property Role $role
* @property EmploymentForm $employment_form * @property EmploymentForm $employment_form
* @property Carbon $employment_date * @property Carbon $employment_date

View File

@ -21,9 +21,13 @@ use Toby\Domain\Enums\VacationType;
* @property VacationRequestState $state * @property VacationRequestState $state
* @property Carbon $from * @property Carbon $from
* @property Carbon $to * @property Carbon $to
* @property int $estimated_days
* @property string $comment * @property string $comment
* @property User $user * @property User $user
* @property YearPeriod $yearPeriod
* @property Collection $activities * @property Collection $activities
* @property Carbon $created_at
* @property Carbon $updated_at
*/ */
class VacationRequest extends Model class VacationRequest extends Model
{ {
@ -43,6 +47,11 @@ class VacationRequest extends Model
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
} }
public function yearPeriod(): BelongsTo
{
return $this->belongsTo(YearPeriod::class);
}
public function activities(): HasMany public function activities(): HasMany
{ {
return $this->hasMany(VacationRequestActivity::class); return $this->hasMany(VacationRequestActivity::class);
@ -60,6 +69,12 @@ class VacationRequest extends Model
return $query->whereIn("state", $states); return $query->whereIn("state", $states);
} }
public function scopeOverlapsWith(Builder $query, self $vacationRequest): Builder
{
return $query->where("from", "<=", $vacationRequest->to)
->where("to", ">=", $vacationRequest->from);
}
protected static function newFactory(): VacationRequestFactory protected static function newFactory(): VacationRequestFactory
{ {
return VacationRequestFactory::new(); return VacationRequestFactory::new();

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers\Api;
use Illuminate\Http\JsonResponse;
use Toby\Domain\VacationDaysCalculator;
use Toby\Infrastructure\Http\Controllers\Controller;
use Toby\Infrastructure\Http\Requests\Api\CalculateVacationDaysRequest;
class CalculateVacationDaysController extends Controller
{
public function __invoke(CalculateVacationDaysRequest $request, VacationDaysCalculator $calculator): JsonResponse
{
$days = $calculator->calculateDays($request->yearPeriod(), $request->from(), $request->to());
return new JsonResponse($days->all());
}
}

View File

@ -4,13 +4,17 @@ declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers; namespace Toby\Infrastructure\Http\Controllers;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response as LaravelResponse;
use Inertia\Response; use Inertia\Response;
use Toby\Domain\Enums\VacationRequestState; use Toby\Domain\Enums\VacationRequestState;
use Toby\Domain\Enums\VacationType; use Toby\Domain\Enums\VacationType;
use Toby\Domain\VacationDaysCalculator;
use Toby\Domain\VacationRequestStateManager; use Toby\Domain\VacationRequestStateManager;
use Toby\Domain\Validation\VacationRequestValidator; use Toby\Domain\Validation\VacationRequestValidator;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
use Toby\Infrastructure\Http\Requests\VacationRequestRequest; use Toby\Infrastructure\Http\Requests\VacationRequestRequest;
use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource; use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource;
@ -18,12 +22,13 @@ use Toby\Infrastructure\Http\Resources\VacationRequestResource;
class VacationRequestController extends Controller class VacationRequestController extends Controller
{ {
public function index(Request $request): Response public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
{ {
$status = $request->get("status", "all"); $status = $request->get("status", "all");
$vacationRequests = $request->user() $vacationRequests = $request->user()
->vacationRequests() ->vacationRequests()
->where("year_period_id", $yearPeriodRetriever->selected()->id)
->latest() ->latest()
->states(VacationRequestState::filterByStatus($status)) ->states(VacationRequestState::filterByStatus($status))
->paginate(); ->paginate();
@ -44,6 +49,15 @@ class VacationRequestController extends Controller
]); ]);
} }
public function download(VacationRequest $vacationRequest): LaravelResponse
{
$pdf = PDF::loadView("pdf.vacation-request", [
"vacationRequest" => $vacationRequest,
]);
return $pdf->stream();
}
public function create(): Response public function create(): Response
{ {
return inertia("VacationRequest/Create", [ return inertia("VacationRequest/Create", [
@ -55,9 +69,15 @@ class VacationRequestController extends Controller
VacationRequestRequest $request, VacationRequestRequest $request,
VacationRequestValidator $vacationRequestValidator, VacationRequestValidator $vacationRequestValidator,
VacationRequestStateManager $stateManager, VacationRequestStateManager $stateManager,
VacationDaysCalculator $vacationDaysCalculator,
): RedirectResponse { ): RedirectResponse {
/** @var VacationRequest $vacationRequest */ /** @var VacationRequest $vacationRequest */
$vacationRequest = $request->user()->vacationRequests()->make($request->data()); $vacationRequest = $request->user()->vacationRequests()->make($request->data());
$vacationRequest->estimated_days = $vacationDaysCalculator->calculateDays(
$vacationRequest->yearPeriod,
$vacationRequest->from,
$vacationRequest->to,
)->count();
$vacationRequestValidator->validate($vacationRequest); $vacationRequestValidator->validate($vacationRequest);

View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Requests\Api;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Carbon;
use Toby\Eloquent\Models\YearPeriod;
use Toby\Infrastructure\Http\Rules\YearPeriodExists;
class CalculateVacationDaysRequest extends FormRequest
{
public function rules(): array
{
return [
"from" => ["required", "date_format:Y-m-d", new YearPeriodExists()],
"to" => ["required", "date_format:Y-m-d", new YearPeriodExists()],
];
}
public function from(): Carbon
{
return Carbon::create($this->request->get("from"));
}
public function to(): Carbon
{
return Carbon::create($this->request->get("to"));
}
public function yearPeriod(): YearPeriod
{
return YearPeriod::findByYear(Carbon::create($this->request->get("from"))->year);
}
}

View File

@ -19,6 +19,7 @@ class UserRequest extends FormRequest
"lastName" => ["required", "min:3", "max:80"], "lastName" => ["required", "min:3", "max:80"],
"email" => ["required", "email", Rule::unique("users", "email")->ignore($this->user)], "email" => ["required", "email", Rule::unique("users", "email")->ignore($this->user)],
"role" => ["required", new Enum(Role::class)], "role" => ["required", new Enum(Role::class)],
"position" => ["required"],
"employmentForm" => ["required", new Enum(EmploymentForm::class)], "employmentForm" => ["required", new Enum(EmploymentForm::class)],
"employmentDate" => ["required", "date_format:Y-m-d"], "employmentDate" => ["required", "date_format:Y-m-d"],
]; ];
@ -30,6 +31,7 @@ class UserRequest extends FormRequest
"first_name" => $this->get("firstName"), "first_name" => $this->get("firstName"),
"last_name" => $this->get("lastName"), "last_name" => $this->get("lastName"),
"email" => $this->get("email"), "email" => $this->get("email"),
"position" => $this->get("position"),
"role" => $this->get("role"), "role" => $this->get("role"),
"employment_form" => $this->get("employmentForm"), "employment_form" => $this->get("employmentForm"),
"employment_date" => $this->get("employmentDate"), "employment_date" => $this->get("employmentDate"),

View File

@ -5,8 +5,10 @@ declare(strict_types=1);
namespace Toby\Infrastructure\Http\Requests; namespace Toby\Infrastructure\Http\Requests;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Carbon;
use Illuminate\Validation\Rules\Enum; use Illuminate\Validation\Rules\Enum;
use Toby\Domain\Enums\VacationType; use Toby\Domain\Enums\VacationType;
use Toby\Eloquent\Models\YearPeriod;
use Toby\Infrastructure\Http\Rules\YearPeriodExists; use Toby\Infrastructure\Http\Rules\YearPeriodExists;
class VacationRequestRequest extends FormRequest class VacationRequestRequest extends FormRequest
@ -23,10 +25,13 @@ class VacationRequestRequest extends FormRequest
public function data(): array public function data(): array
{ {
$from = $this->get("from");
return [ return [
"type" => $this->get("type"), "type" => $this->get("type"),
"from" => $this->get("from"), "from" => $from,
"to" => $this->get("to"), "to" => $this->get("to"),
"year_period_id" => YearPeriod::findByYear(Carbon::create($from)->year)->id,
"comment" => $this->get("comment"), "comment" => $this->get("comment"),
]; ];
} }

View File

@ -18,6 +18,7 @@ class UserFormDataResource extends JsonResource
"lastName" => $this->last_name, "lastName" => $this->last_name,
"email" => $this->email, "email" => $this->email,
"role" => $this->role, "role" => $this->role,
"position" => $this->position,
"employmentForm" => $this->employment_form, "employmentForm" => $this->employment_form,
"employmentDate" => $this->employment_date->toDateString(), "employmentDate" => $this->employment_date->toDateString(),
]; ];

View File

@ -17,6 +17,7 @@ class UserResource extends JsonResource
"name" => $this->fullName, "name" => $this->fullName,
"email" => $this->email, "email" => $this->email,
"role" => $this->role->label(), "role" => $this->role->label(),
"position" => $this->position,
"avatar" => asset($this->avatar), "avatar" => asset($this->avatar),
"deleted" => $this->trashed(), "deleted" => $this->trashed(),
"employmentForm" => $this->employment_form->label(), "employmentForm" => $this->employment_form->label(),

View File

@ -20,6 +20,7 @@ class VacationRequestResource extends JsonResource
"state" => $this->state->label(), "state" => $this->state->label(),
"from" => $this->from->toDisplayString(), "from" => $this->from->toDisplayString(),
"to" => $this->to->toDisplayString(), "to" => $this->to->toDisplayString(),
"estimatedDays" => $this->estimated_days,
"comment" => $this->comment, "comment" => $this->comment,
]; ];
} }

View File

@ -8,6 +8,7 @@
"php": "^8.1", "php": "^8.1",
"ext-pdo": "*", "ext-pdo": "*",
"azuyalabs/yasumi": "^2.4", "azuyalabs/yasumi": "^2.4",
"barryvdh/laravel-dompdf": "^1.0",
"fruitcake/laravel-cors": "^2.0", "fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1", "guzzlehttp/guzzle": "^7.0.1",
"inertiajs/inertia-laravel": "^0.5.1", "inertiajs/inertia-laravel": "^0.5.1",

289
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "bf5f7d8f40ecadea64ae8564a3df3110", "content-hash": "c2f475e65f84bdff45169e4443d9ef4f",
"packages": [ "packages": [
{ {
"name": "asm89/stack-cors", "name": "asm89/stack-cors",
@ -135,6 +135,82 @@
], ],
"time": "2022-01-30T07:43:17+00:00" "time": "2022-01-30T07:43:17+00:00"
}, },
{
"name": "barryvdh/laravel-dompdf",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-dompdf.git",
"reference": "e3f429e97087b2ef19b83e5ed313f080f2477685"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/e3f429e97087b2ef19b83e5ed313f080f2477685",
"reference": "e3f429e97087b2ef19b83e5ed313f080f2477685",
"shasum": ""
},
"require": {
"dompdf/dompdf": "^1",
"illuminate/support": "^6|^7|^8|^9",
"php": "^7.2 || ^8.0"
},
"require-dev": {
"nunomaduro/larastan": "^1|^2",
"orchestra/testbench": "^4|^5|^6|^7",
"phpro/grumphp": "^1",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"laravel": {
"providers": [
"Barryvdh\\DomPDF\\ServiceProvider"
],
"aliases": {
"PDF": "Barryvdh\\DomPDF\\Facade\\Pdf"
}
}
},
"autoload": {
"psr-4": {
"Barryvdh\\DomPDF\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "A DOMPDF Wrapper for Laravel",
"keywords": [
"dompdf",
"laravel",
"pdf"
],
"support": {
"issues": "https://github.com/barryvdh/laravel-dompdf/issues",
"source": "https://github.com/barryvdh/laravel-dompdf/tree/v1.0.0"
},
"funding": [
{
"url": "https://fruitcake.nl",
"type": "custom"
},
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2022-01-29T08:02:59+00:00"
},
{ {
"name": "brick/math", "name": "brick/math",
"version": "0.9.3", "version": "0.9.3",
@ -437,6 +513,73 @@
], ],
"time": "2022-01-12T08:27:12+00:00" "time": "2022-01-12T08:27:12+00:00"
}, },
{
"name": "dompdf/dompdf",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/dompdf/dompdf.git",
"reference": "de4aad040737a89fae2129cdeb0f79c45513128d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/de4aad040737a89fae2129cdeb0f79c45513128d",
"reference": "de4aad040737a89fae2129cdeb0f79c45513128d",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-mbstring": "*",
"phenx/php-font-lib": "^0.5.2",
"phenx/php-svg-lib": "^0.3.3",
"php": "^7.1 || ^8.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^7.5 || ^8 || ^9",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"ext-gd": "Needed to process images",
"ext-gmagick": "Improves image processing performance",
"ext-imagick": "Improves image processing performance",
"ext-zlib": "Needed for pdf stream compression"
},
"type": "library",
"autoload": {
"psr-4": {
"Dompdf\\": "src/"
},
"classmap": [
"lib/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
},
{
"name": "Brian Sweeney",
"email": "eclecticgeek@gmail.com"
},
{
"name": "Gabriel Bull",
"email": "me@gabrielbull.com"
}
],
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
"homepage": "https://github.com/dompdf/dompdf",
"support": {
"issues": "https://github.com/dompdf/dompdf/issues",
"source": "https://github.com/dompdf/dompdf/tree/v1.1.1"
},
"time": "2021-11-24T00:45:04+00:00"
},
{ {
"name": "dragonmantank/cron-expression", "name": "dragonmantank/cron-expression",
"version": "v3.3.1", "version": "v3.3.1",
@ -2846,6 +2989,95 @@
], ],
"time": "2021-07-19T03:43:32+00:00" "time": "2021-07-19T03:43:32+00:00"
}, },
{
"name": "phenx/php-font-lib",
"version": "0.5.4",
"source": {
"type": "git",
"url": "https://github.com/dompdf/php-font-lib.git",
"reference": "dd448ad1ce34c63d09baccd05415e361300c35b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/dd448ad1ce34c63d09baccd05415e361300c35b4",
"reference": "dd448ad1ce34c63d09baccd05415e361300c35b4",
"shasum": ""
},
"require": {
"ext-mbstring": "*"
},
"require-dev": {
"symfony/phpunit-bridge": "^3 || ^4 || ^5"
},
"type": "library",
"autoload": {
"psr-4": {
"FontLib\\": "src/FontLib"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
}
],
"description": "A library to read, parse, export and make subsets of different types of font files.",
"homepage": "https://github.com/PhenX/php-font-lib",
"support": {
"issues": "https://github.com/dompdf/php-font-lib/issues",
"source": "https://github.com/dompdf/php-font-lib/tree/0.5.4"
},
"time": "2021-12-17T19:44:54+00:00"
},
{
"name": "phenx/php-svg-lib",
"version": "0.3.4",
"source": {
"type": "git",
"url": "https://github.com/PhenX/php-svg-lib.git",
"reference": "f627771eb854aa7f45f80add0f23c6c4d67ea0f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/f627771eb854aa7f45f80add0f23c6c4d67ea0f2",
"reference": "f627771eb854aa7f45f80add0f23c6c4d67ea0f2",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"sabberworm/php-css-parser": "^8.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Svg\\": "src/Svg"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
}
],
"description": "A library to read, parse and export to PDF SVG files.",
"homepage": "https://github.com/PhenX/php-svg-lib",
"support": {
"issues": "https://github.com/PhenX/php-svg-lib/issues",
"source": "https://github.com/PhenX/php-svg-lib/tree/0.3.4"
},
"time": "2021-10-18T02:13:32+00:00"
},
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
"version": "1.8.1", "version": "1.8.1",
@ -3572,6 +3804,59 @@
], ],
"time": "2021-09-25T23:10:38+00:00" "time": "2021-09-25T23:10:38+00:00"
}, },
{
"name": "sabberworm/php-css-parser",
"version": "8.4.0",
"source": {
"type": "git",
"url": "https://github.com/sabberworm/PHP-CSS-Parser.git",
"reference": "e41d2140031d533348b2192a83f02d8dd8a71d30"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/e41d2140031d533348b2192a83f02d8dd8a71d30",
"reference": "e41d2140031d533348b2192a83f02d8dd8a71d30",
"shasum": ""
},
"require": {
"ext-iconv": "*",
"php": ">=5.6.20"
},
"require-dev": {
"codacy/coverage": "^1.4",
"phpunit/phpunit": "^4.8.36"
},
"suggest": {
"ext-mbstring": "for parsing UTF-8 CSS"
},
"type": "library",
"autoload": {
"psr-4": {
"Sabberworm\\CSS\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Raphael Schweikert"
}
],
"description": "Parser for CSS Files written in PHP",
"homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser",
"keywords": [
"css",
"parser",
"stylesheet"
],
"support": {
"issues": "https://github.com/sabberworm/PHP-CSS-Parser/issues",
"source": "https://github.com/sabberworm/PHP-CSS-Parser/tree/8.4.0"
},
"time": "2021-12-11T13:40:54+00:00"
},
{ {
"name": "swiftmailer/swiftmailer", "name": "swiftmailer/swiftmailer",
"version": "v6.3.0", "version": "v6.3.0",
@ -10027,5 +10312,5 @@
"ext-pdo": "*" "ext-pdo": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.1.0" "plugin-api-version": "2.2.0"
} }

View File

@ -43,5 +43,6 @@ return [
Toby\Architecture\Providers\RouteServiceProvider::class, Toby\Architecture\Providers\RouteServiceProvider::class,
Toby\Architecture\Providers\TelescopeServiceProvider::class, Toby\Architecture\Providers\TelescopeServiceProvider::class,
Toby\Architecture\Providers\ObserverServiceProvider::class, Toby\Architecture\Providers\ObserverServiceProvider::class,
Barryvdh\DomPDF\ServiceProvider::class,
], ],
]; ];

View File

@ -10,5 +10,5 @@ return [
"allowed_headers" => ["*"], "allowed_headers" => ["*"],
"exposed_headers" => [], "exposed_headers" => [],
"max_age" => 0, "max_age" => 0,
"supports_credentials" => false, "supports_credentials" => true,
]; ];

View File

@ -22,6 +22,7 @@ class UserFactory extends Factory
"last_name" => $this->faker->lastName(), "last_name" => $this->faker->lastName(),
"email" => $this->faker->unique()->safeEmail(), "email" => $this->faker->unique()->safeEmail(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()), "employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"position" => $this->faker->jobTitle(),
"role" => Role::EMPLOYEE, "role" => Role::EMPLOYEE,
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(), "employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),

View File

@ -4,29 +4,50 @@ declare(strict_types=1);
namespace Database\Factories; namespace Database\Factories;
use Carbon\CarbonImmutable;
use Carbon\CarbonPeriod;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Toby\Domain\Enums\VacationRequestState; use Toby\Domain\Enums\VacationRequestState;
use Toby\Domain\Enums\VacationType; use Toby\Domain\Enums\VacationType;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
use Toby\Eloquent\Models\YearPeriod;
class VacationRequestFactory extends Factory class VacationRequestFactory extends Factory
{ {
protected $model = VacationRequest::class; protected $model = VacationRequest::class;
private static int $number = 1;
public function definition(): array public function definition(): array
{ {
$number = $this->faker->numberBetween(1, 20); $from = CarbonImmutable::create($this->faker->dateTimeThisYear);
$year = $this->faker->year; $days = $this->faker->numberBetween(0, 20);
return [ return [
"user_id" => User::factory(), "user_id" => User::factory(),
"name" => "{$number}/{$year}", "year_period_id" => YearPeriod::factory(),
"name" => fn(array $attributes) => $this->generateName($attributes),
"type" => $this->faker->randomElement(VacationType::cases()), "type" => $this->faker->randomElement(VacationType::cases()),
"state" => $this->faker->randomElement(VacationRequestState::cases()), "state" => $this->faker->randomElement(VacationRequestState::cases()),
"from" => $this->faker->date, "from" => $from,
"to" => $this->faker->date, "to" => $from->addDays($days),
"estimated_days" => fn(array $attributes) => $this->estimateDays($attributes),
"comment" => $this->faker->boolean ? $this->faker->paragraph() : null, "comment" => $this->faker->boolean ? $this->faker->paragraph() : null,
]; ];
} }
protected function generateName(array $attributes): string
{
$year = YearPeriod::find($attributes["year_period_id"])->year;
$number = static::$number++;
return "{$number}/{$year}";
}
protected function estimateDays(array $attributes): int
{
$period = CarbonPeriod::create($attributes["from"], $attributes["to"]);
return $period->count();
}
} }

View File

@ -17,6 +17,7 @@ return new class() extends Migration {
$table->string("email")->unique(); $table->string("email")->unique();
$table->string("avatar")->nullable(); $table->string("avatar")->nullable();
$table->string("role")->default(Role::EMPLOYEE->value); $table->string("role")->default(Role::EMPLOYEE->value);
$table->string("position");
$table->string("employment_form"); $table->string("employment_form");
$table->date("employment_date"); $table->date("employment_date");
$table->rememberToken(); $table->rememberToken();

View File

@ -6,6 +6,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
return new class() extends Migration { return new class() extends Migration {
public function up(): void public function up(): void
@ -14,8 +15,10 @@ return new class() extends Migration {
$table->id(); $table->id();
$table->string("name"); $table->string("name");
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete(); $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
$table->string("type"); $table->string("type");
$table->string("state")->nullable(); $table->string("state")->nullable();
$table->integer("estimated_days");
$table->date("from"); $table->date("from");
$table->date("to"); $table->date("to");
$table->text("comment")->nullable(); $table->text("comment")->nullable();

View File

@ -31,7 +31,6 @@ class DatabaseSeeder extends Seeder
User::factory([ User::factory([
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"), "email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
]) ])
->hasVacationRequests(5)
->create(); ->create();
$users = User::all(); $users = User::all();
@ -70,6 +69,18 @@ class DatabaseSeeder extends Seeder
} }
}) })
->create(); ->create();
$yearPeriods = YearPeriod::all();
foreach ($users as $user) {
VacationRequest::factory()
->count(10)
->for($user)
->sequence(fn() => [
"year_period_id" => $yearPeriods->random()->id,
])
->create();
}
} }
protected function generateAvatarsForUsers(Collection $users): void protected function generateAvatarsForUsers(Collection $users): void

37
package-lock.json generated
View File

@ -1,5 +1,5 @@
{ {
"name": "application", "name": "toby",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
@ -15,6 +15,7 @@
"@tailwindcss/typography": "^0.5.0", "@tailwindcss/typography": "^0.5.0",
"@vue/compiler-sfc": "^3.2.26", "@vue/compiler-sfc": "^3.2.26",
"autoprefixer": "^10.4.2", "autoprefixer": "^10.4.2",
"axios": "^0.25.0",
"echarts": "^5.2.2", "echarts": "^5.2.2",
"flatpickr": "^4.6.9", "flatpickr": "^4.6.9",
"laravel-mix": "^6.0.6", "laravel-mix": "^6.0.6",
@ -1741,6 +1742,14 @@
"vue": "^3.0.0" "vue": "^3.0.0"
} }
}, },
"node_modules/@inertiajs/inertia/node_modules/axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"dependencies": {
"follow-redirects": "^1.14.0"
}
},
"node_modules/@inertiajs/progress": { "node_modules/@inertiajs/progress": {
"version": "0.2.7", "version": "0.2.7",
"resolved": "https://registry.npmjs.org/@inertiajs/progress/-/progress-0.2.7.tgz", "resolved": "https://registry.npmjs.org/@inertiajs/progress/-/progress-0.2.7.tgz",
@ -2642,11 +2651,11 @@
} }
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "0.21.4", "version": "0.25.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==",
"dependencies": { "dependencies": {
"follow-redirects": "^1.14.0" "follow-redirects": "^1.14.7"
} }
}, },
"node_modules/babel-loader": { "node_modules/babel-loader": {
@ -10664,6 +10673,16 @@
"axios": "^0.21.1", "axios": "^0.21.1",
"deepmerge": "^4.0.0", "deepmerge": "^4.0.0",
"qs": "^6.9.0" "qs": "^6.9.0"
},
"dependencies": {
"axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"requires": {
"follow-redirects": "^1.14.0"
}
}
} }
}, },
"@inertiajs/inertia-vue3": { "@inertiajs/inertia-vue3": {
@ -11468,11 +11487,11 @@
} }
}, },
"axios": { "axios": {
"version": "0.21.4", "version": "0.25.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==",
"requires": { "requires": {
"follow-redirects": "^1.14.0" "follow-redirects": "^1.14.7"
} }
}, },
"babel-loader": { "babel-loader": {

View File

@ -22,6 +22,7 @@
"@tailwindcss/typography": "^0.5.0", "@tailwindcss/typography": "^0.5.0",
"@vue/compiler-sfc": "^3.2.26", "@vue/compiler-sfc": "^3.2.26",
"autoprefixer": "^10.4.2", "autoprefixer": "^10.4.2",
"axios": "^0.25.0",
"echarts": "^5.2.2", "echarts": "^5.2.2",
"flatpickr": "^4.6.9", "flatpickr": "^4.6.9",
"laravel-mix": "^6.0.6", "laravel-mix": "^6.0.6",

View File

@ -82,6 +82,29 @@
</p> </p>
</div> </div>
</div> </div>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="position"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Stanowisko
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<input
id="position"
v-model="form.position"
type="text"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.position, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.position }"
>
<p
v-if="form.errors.position"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.position }}
</p>
</div>
</div>
<Listbox <Listbox
v-model="form.role" v-model="form.role"
as="div" as="div"
@ -270,6 +293,7 @@ export default {
email: null, email: null,
employmentForm: props.employmentForms[0], employmentForm: props.employmentForms[0],
role: props.roles[0], role: props.roles[0],
position: null,
employmentDate: null, employmentDate: null,
}) })

View File

@ -82,6 +82,29 @@
</p> </p>
</div> </div>
</div> </div>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="position"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Stanowisko
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<input
id="position"
v-model="form.position"
type="text"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.position, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.position }"
>
<p
v-if="form.errors.position"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.position }}
</p>
</div>
</div>
<Listbox <Listbox
v-model="form.role" v-model="form.role"
as="div" as="div"
@ -272,6 +295,7 @@ export default {
lastName: props.user.lastName, lastName: props.user.lastName,
email: props.user.email, email: props.user.email,
role: props.roles.find(role => role.value === props.user.role), role: props.roles.find(role => role.value === props.user.role),
position: props.user.position,
employmentForm: props.employmentForms.find(form => form.value === props.user.employmentForm), employmentForm: props.employmentForms.find(form => form.value === props.user.employmentForm),
employmentDate: props.user.employmentDate, employmentDate: props.user.employmentDate,
}) })

View File

@ -49,6 +49,12 @@
> >
Rola Rola
</th> </th>
<th
scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
>
Stanowisko
</th>
<th <th
scope="col" scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider" class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
@ -97,6 +103,9 @@
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ user.role }} {{ user.role }}
</td> </td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ user.position }}
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ user.employmentForm }} {{ user.employmentForm }}
</td> </td>

View File

@ -10,8 +10,26 @@
class="border-t border-gray-200 px-6" class="border-t border-gray-200 px-6"
@submit.prevent="createForm" @submit.prevent="createForm"
> >
<div
v-if="form.errors.vacationRequest"
class="rounded-md bg-red-50 p-4 mt-2"
>
<div class="flex">
<div class="flex-shrink-0">
<XCircleIcon class="h-5 w-5 text-red-400" />
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">
Wniosek nie mógł zostać utworzony
</h3>
<div class="mt-2 text-sm text-red-700">
<span>{{ form.errors.vacationRequest }}</span>
</div>
</div>
</div>
</div>
<Listbox <Listbox
v-model="form.vacationType" v-model="form.type"
as="div" as="div"
class="sm:grid sm:grid-cols-3 py-4 items-center" class="sm:grid sm:grid-cols-3 py-4 items-center"
> >
@ -21,9 +39,9 @@
<div class="mt-1 relative sm:mt-0 sm:col-span-2"> <div class="mt-1 relative sm:mt-0 sm:col-span-2">
<ListboxButton <ListboxButton
class="bg-white relative w-full max-w-lg border rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default sm:text-sm focus:ring-1" class="bg-white relative w-full max-w-lg border rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default sm:text-sm focus:ring-1"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.vacationType, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.vacationType }" :class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.type, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.type }"
> >
<span class="block truncate">{{ form.vacationType.label }}</span> <span class="block truncate">{{ form.type.label }}</span>
<span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none"> <span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
<SelectorIcon class="h-5 w-5 text-gray-400" /> <SelectorIcon class="h-5 w-5 text-gray-400" />
</span> </span>
@ -38,15 +56,15 @@
class="absolute z-10 mt-1 w-full max-w-lg bg-white shadow-lg max-h-60 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm" class="absolute z-10 mt-1 w-full max-w-lg bg-white shadow-lg max-h-60 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
> >
<ListboxOption <ListboxOption
v-for="vacationType in vacationTypes" v-for="type in vacationTypes"
:key="vacationType.value" :key="type.value"
v-slot="{ active, selected }" v-slot="{ active, selected }"
as="template" as="template"
:value="vacationType" :value="type"
> >
<li :class="[active ? 'text-white bg-blumilk-600' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']"> <li :class="[active ? 'text-white bg-blumilk-600' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']">
<span :class="[selected ? 'font-semibold' : 'font-normal', 'block truncate']"> <span :class="[selected ? 'font-semibold' : 'font-normal', 'block truncate']">
{{ vacationType.label }} {{ type.label }}
</span> </span>
<span <span
@ -60,10 +78,10 @@
</ListboxOptions> </ListboxOptions>
</transition> </transition>
<p <p
v-if="form.errors.vacationType" v-if="form.errors.type"
class="mt-2 text-sm text-red-600" class="mt-2 text-sm text-red-600"
> >
{{ form.errors.vacationType }} {{ form.errors.type }}
</p> </p>
</div> </div>
</Listbox> </Listbox>
@ -77,18 +95,18 @@
<div class="mt-1 sm:mt-0 sm:col-span-2"> <div class="mt-1 sm:mt-0 sm:col-span-2">
<FlatPickr <FlatPickr
id="date_from" id="date_from"
v-model="form.dateFrom" v-model="form.from"
:config="fromInputConfig" :config="fromInputConfig"
placeholder="Wybierz datę" placeholder="Wybierz datę"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm" class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.dateFrom, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.dateFrom }" :class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.from, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.from }"
@on-change="onFromChange" @on-change="onFromChange"
/> />
<p <p
v-if="form.errors.dateFrom" v-if="form.errors.from"
class="mt-2 text-sm text-red-600" class="mt-2 text-sm text-red-600"
> >
{{ form.errors.dateFrom }} {{ form.errors.from }}
</p> </p>
</div> </div>
</div> </div>
@ -102,25 +120,25 @@
<div class="mt-1 sm:mt-0 sm:col-span-2"> <div class="mt-1 sm:mt-0 sm:col-span-2">
<FlatPickr <FlatPickr
id="date_to" id="date_to"
v-model="form.dateTo" v-model="form.to"
:config="toInputConfig" :config="toInputConfig"
placeholder="Wybierz datę" placeholder="Wybierz datę"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm" class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.dateTo, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.dateTo }" :class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.to, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.to }"
@on-change="onToChange" @on-change="onToChange"
/> />
<p <p
v-if="form.errors.dateTo" v-if="form.errors.to"
class="mt-2 text-sm text-red-600" class="mt-2 text-sm text-red-600"
> >
{{ form.errors.dateTo }} {{ form.errors.to }}
</p> </p>
</div> </div>
</div> </div>
<div class="sm:grid sm:grid-cols-3 py-4 items-center"> <div class="sm:grid sm:grid-cols-3 py-4 items-center">
<span class="block text-sm font-medium text-gray-700 sm:mt-px">Liczba dni urlopu</span> <span class="block text-sm font-medium text-gray-700 sm:mt-px">Liczba dni urlopu</span>
<div class="mt-1 sm:mt-0 sm:col-span-2 w-full max-w-lg bg-gray-50 border border-gray-300 rounded-md px-4 py-2 inline-flex items-center text-gray-500 sm:text-sm"> <div class="mt-1 sm:mt-0 sm:col-span-2 w-full max-w-lg bg-gray-50 border border-gray-300 rounded-md px-4 py-2 inline-flex items-center text-gray-500 sm:text-sm">
1 {{ estimatedDays.length }}
</div> </div>
</div> </div>
<div class="sm:grid sm:grid-cols-3 py-4 items-center"> <div class="sm:grid sm:grid-cols-3 py-4 items-center">
@ -135,7 +153,7 @@
id="comment" id="comment"
v-model="form.comment" v-model="form.comment"
rows="4" rows="4"
class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full max-w-lg sm:text-sm border-gray-300 rounded-md" class="shadow-sm focus:ring-blumilk-500 focus:border-blumilk-500 block w-full max-w-lg sm:text-sm border-gray-300 rounded-md"
/> />
</div> </div>
</div> </div>
@ -164,8 +182,9 @@
import {useForm} from '@inertiajs/inertia-vue3' import {useForm} from '@inertiajs/inertia-vue3'
import FlatPickr from 'vue-flatpickr-component' import FlatPickr from 'vue-flatpickr-component'
import {Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions} from '@headlessui/vue' import {Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions} from '@headlessui/vue'
import {CheckIcon, SelectorIcon} from '@heroicons/vue/solid' import {CheckIcon, SelectorIcon, XCircleIcon} from '@heroicons/vue/solid'
import {reactive} from 'vue' import {reactive, ref} from 'vue'
import axios from 'axios'
export default { export default {
name: 'VacationRequestCreate', name: 'VacationRequestCreate',
@ -178,6 +197,7 @@ export default {
ListboxOptions, ListboxOptions,
CheckIcon, CheckIcon,
SelectorIcon, SelectorIcon,
XCircleIcon,
}, },
props: { props: {
vacationTypes: { vacationTypes: {
@ -191,12 +211,14 @@ export default {
}, },
setup(props) { setup(props) {
const form = useForm({ const form = useForm({
dateFrom: null, from: null,
dateTo: null, to: null,
vacationType: props.vacationTypes[0], type: props.vacationTypes[0],
comment: null, comment: null,
}) })
const estimatedDays = ref([])
const disableDates = [ const disableDates = [
date => (date.getDay() === 0 || date.getDay() === 6), date => (date.getDay() === 0 || date.getDay() === 6),
] ]
@ -213,6 +235,7 @@ export default {
return { return {
form, form,
estimatedDays,
fromInputConfig, fromInputConfig,
toInputConfig, toInputConfig,
} }
@ -221,18 +244,26 @@ export default {
createForm() { createForm() {
this.form this.form
.transform(data => ({ .transform(data => ({
from: data.dateFrom, ...data,
to: data.dateTo, type: data.type.value,
type: data.vacationType.value,
comment: data.comment,
})) }))
.post('/vacation-requests') .post('/vacation-requests')
}, },
onFromChange(selectedDates, dateStr) { onFromChange(selectedDates, dateStr) {
this.toInputConfig.minDate = dateStr this.toInputConfig.minDate = dateStr
this.refreshEstimatedDays(this.form.from, this.form.to)
}, },
onToChange(selectedDates, dateStr) { onToChange(selectedDates, dateStr) {
this.fromInputConfig.maxDate = dateStr this.fromInputConfig.maxDate = dateStr
this.refreshEstimatedDays(this.form.from, this.form.to)
},
refreshEstimatedDays(from, to) {
if (from && to) {
axios.post('/api/calculate-vacation-days', {from, to})
.then(res => this.estimatedDays = res.data)
}
}, },
}, },

View File

@ -33,40 +33,40 @@
<tr> <tr>
<th <th
scope="col" scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider" class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
> >
Numer Numer
</th> </th>
<th <th
scope="col" scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider" class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
> >
Rodzaj urlopu Rodzaj urlopu
</th> </th>
<th <th
scope="col" scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider" class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
>
Status
</th>
<th
scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
> >
Od Od
</th> </th>
<th <th
scope="col" scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider" class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
> >
Do Do
</th> </th>
<th <th
scope="col" scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider" class="px-4 py-3 text-right text-xs font-semibold text-gray-500 uppercase tracking-wider"
> >
Dni urlopu Dni urlopu
</th> </th>
<th
scope="col"
class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
>
Status
</th>
<th scope="col" /> <th scope="col" />
</tr> </tr>
</thead> </thead>
@ -87,17 +87,17 @@
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ request.type }} {{ request.type }}
</td> </td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ request.state }}
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ request.from }} {{ request.from }}
</td> </td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ request.to }} {{ request.to }}
</td> </td>
<td class="px-4 py-4 whitespace-nowrap text-right text-sm text-gray-500">
{{ request.estimatedDays }}
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
X {{ request.state }}
</td> </td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
<InertiaLink :href="`/vacation-requests/${request.id}`"> <InertiaLink :href="`/vacation-requests/${request.id}`">

View File

@ -44,10 +44,10 @@
</div> </div>
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium text-gray-500"> <dt class="text-sm font-medium text-gray-500">
Dni Dni urlopu
</dt> </dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
x {{ request.estimatedDays }}
</dd> </dd>
</div> </div>
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
@ -58,6 +58,30 @@
{{ request.comment }} {{ request.comment }}
</dd> </dd>
</div> </div>
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Załączniki
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
<ul class="border border-gray-200 rounded-md divide-y divide-gray-200">
<li class="pl-3 pr-4 py-3 flex items-center justify-between text-sm">
<div class="w-0 flex-1 flex items-center">
<PaperClipIcon class="flex-shrink-0 h-5 w-5 text-gray-400" />
<span class="ml-2 flex-1 w-0 truncate"> wniosek_urlopowy.pdf </span>
</div>
<div class="ml-4 flex-shrink-0">
<a
:href="`/vacation-requests/${request.id}/download`"
target="_blank"
class="font-medium text-blumilk-600 hover:text-blumilk-500"
>
Pobierz
</a>
</div>
</li>
</ul>
</dd>
</div>
</dl> </dl>
</div> </div>
</div> </div>
@ -196,11 +220,13 @@
<script> <script>
import { ThumbUpIcon } from '@heroicons/vue/outline' import { ThumbUpIcon } from '@heroicons/vue/outline'
import {PaperClipIcon} from '@heroicons/vue/solid'
export default { export default {
name: 'VacationRequestShow', name: 'VacationRequestShow',
components: { components: {
ThumbUpIcon, ThumbUpIcon,
PaperClipIcon,
}, },
props: { props: {
request: { request: {

View File

@ -16,8 +16,8 @@
"sick_vacation": "Zwolnienie lekarskie", "sick_vacation": "Zwolnienie lekarskie",
"employee": "Pracownik", "employee": "Pracownik",
"administrator": "Administrator", "administrator": "Administrator",
"technical_approver": "Techniczny klepacz", "technical_approver": "Techniczny akceptujący",
"administrative_approver": "Administracyjny klepacz", "administrative_approver": "Administracyjny akceptujący",
"created": "Utworzony", "created": "Utworzony",
"canceled": "Anulowany", "canceled": "Anulowany",
"rejected": "Odrzucony", "rejected": "Odrzucony",
@ -25,5 +25,10 @@
"waiting_for_technical": "Czeka na akceptację od technicznego", "waiting_for_technical": "Czeka na akceptację od technicznego",
"waiting_for_administrative": "Czeka na akceptację od administracyjnego", "waiting_for_administrative": "Czeka na akceptację od administracyjnego",
"accepted_by_technical": "Zaakceptowany przez technicznego", "accepted_by_technical": "Zaakceptowany przez technicznego",
"accepted_by_administrative": "Zaakceptowany przez administracyjnego" "accepted_by_administrative": "Zaakceptowany przez administracyjnego",
"You have pending vacation request in this range.": "Masz oczekujący wniosek urlopowy w tym zakresie dat.",
"You have approved vacation request in this range.": "Masz zaakceptowany wniosek urlopowy w tym zakresie dat.",
"You have exceeded your vacation limit.": "Przekroczyłeś/aś limit urlopu.",
"Vacation needs minimum one day.": "Urlop musi być co najmniej na jeden dzień.",
"The vacation request cannot be created at the turn of the year.": "Wniosek urlopowy nie może zostać złożony na przełomie roku."
} }

View File

@ -114,4 +114,15 @@ return [
"uploaded" => "Nie udało się wgrać pliku :attribute.", "uploaded" => "Nie udało się wgrać pliku :attribute.",
"url" => "Format pola :attribute jest nieprawidłowy.", "url" => "Format pola :attribute jest nieprawidłowy.",
"uuid" => "Pole :attribute musi być poprawnym identyfikatorem UUID.", "uuid" => "Pole :attribute musi być poprawnym identyfikatorem UUID.",
"attributes" => [
"to" => "do",
"from" => "od",
"firstName" => "imię",
"lastName" => "nazwisko",
"email" => "e-mail",
"position" => "stanowisko",
"employmentDate" => "data zatrudnienia",
"date" => "data",
"name" => "nazwa",
],
]; ];

View File

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Wniosek urlopowy</title>
<style>
body {
font-family: DejaVu Sans, sans-serif;
}
h2 {
text-align: center;
}
p {
margin: 0;
text-align: center;
}
.container {
margin: 60px 20px;
}
.helper-text {
font-size: 12px;
font-weight: bold;
padding-bottom: 12px;
}
.content {
margin-top: 60px;
line-height: 24px;
text-align: left;
}
.main {
margin-top: 60px;
}
table {
width: 100%;
text-align: center;
}
.signatureTable {
margin-top: 100px;
}
</style>
</head>
<body>
<div class="container">
<div>
<table>
<tbody>
<tr>
<td>{{ $vacationRequest->user->fullName }}</td>
<td>Legnica, {{ $vacationRequest->created_at->format("d.m.Y") }}</td>
</tr>
<tr>
<td class="helper-text">imię i nazwisko</td>
</tr>
<tr>
<td>{{ $vacationRequest->user->position }}</td>
</tr>
<tr>
<td class="helper-text">stanowisko</td>
</tr>
</tbody>
</table>
</div>
<div class="main">
<h2>Wniosek o urlop</h2>
<p class="content">
Proszę o {{ mb_strtolower($vacationRequest->type->label()) }} w okresie od dnia {{ $vacationRequest->from->format("d.m.Y") }}
do dnia {{ $vacationRequest->to->format("d.m.Y") }} włącznie tj. {{ $vacationRequest->estimated_days }} dni roboczych za rok {{ $vacationRequest->yearPeriod->year }}.
</p>
</div>
<table class="signatureTable">
<tbody>
<tr>
<td>........................</td>
<td>........................</td>
</tr>
<tr>
<td class="helper-text">podpis przełożonego</td>
<td class="helper-text">podpis pracownika</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

View File

@ -1,3 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Support\Facades\Route;
use Toby\Infrastructure\Http\Controllers\Api\CalculateVacationDaysController;
Route::middleware("auth:sanctum")->group(function (): void {
Route::post("calculate-vacation-days", CalculateVacationDaysController::class);
});

View File

@ -38,6 +38,8 @@ Route::middleware("auth")->group(function (): void {
->name("vacation.requests.store"); ->name("vacation.requests.store");
Route::get("/vacation-requests/{vacationRequest}", [VacationRequestController::class, "show"]) Route::get("/vacation-requests/{vacationRequest}", [VacationRequestController::class, "show"])
->name("vacation.requests.show"); ->name("vacation.requests.show");
Route::get("/vacation-requests/{vacationRequest}/download", [VacationRequestController::class, "download"])
->name("vacation.requests.download");
Route::post("/vacation-requests/{vacationRequest}/reject", [VacationRequestController::class, "reject"]) Route::post("/vacation-requests/{vacationRequest}/reject", [VacationRequestController::class, "reject"])
->name("vacation.requests.reject"); ->name("vacation.requests.reject");
Route::post("/vacation-requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"]) Route::post("/vacation-requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"])

View File

@ -89,6 +89,7 @@ class UserTest extends FeatureTestCase
"firstName" => "John", "firstName" => "John",
"lastName" => "Doe", "lastName" => "Doe",
"role" => Role::EMPLOYEE->value, "role" => Role::EMPLOYEE->value,
"position" => "Test position",
"email" => "john.doe@example.com", "email" => "john.doe@example.com",
"employmentForm" => EmploymentForm::B2B_CONTRACT->value, "employmentForm" => EmploymentForm::B2B_CONTRACT->value,
"employmentDate" => Carbon::now()->toDateString(), "employmentDate" => Carbon::now()->toDateString(),
@ -99,6 +100,8 @@ class UserTest extends FeatureTestCase
"first_name" => "John", "first_name" => "John",
"last_name" => "Doe", "last_name" => "Doe",
"email" => "john.doe@example.com", "email" => "john.doe@example.com",
"role" => Role::EMPLOYEE->value,
"position" => "Test position",
"employment_form" => EmploymentForm::B2B_CONTRACT->value, "employment_form" => EmploymentForm::B2B_CONTRACT->value,
"employment_date" => Carbon::now()->toDateString(), "employment_date" => Carbon::now()->toDateString(),
]); ]);
@ -125,6 +128,7 @@ class UserTest extends FeatureTestCase
"lastName" => "Doe", "lastName" => "Doe",
"email" => "john.doe@example.com", "email" => "john.doe@example.com",
"role" => Role::EMPLOYEE->value, "role" => Role::EMPLOYEE->value,
"position" => "Test position",
"employmentForm" => EmploymentForm::B2B_CONTRACT->value, "employmentForm" => EmploymentForm::B2B_CONTRACT->value,
"employmentDate" => Carbon::now()->toDateString(), "employmentDate" => Carbon::now()->toDateString(),
]) ])
@ -134,6 +138,8 @@ class UserTest extends FeatureTestCase
"first_name" => "John", "first_name" => "John",
"last_name" => "Doe", "last_name" => "Doe",
"email" => "john.doe@example.com", "email" => "john.doe@example.com",
"role" => Role::EMPLOYEE->value,
"position" => "Test position",
"employment_form" => EmploymentForm::B2B_CONTRACT->value, "employment_form" => EmploymentForm::B2B_CONTRACT->value,
"employment_date" => Carbon::now()->toDateString(), "employment_date" => Carbon::now()->toDateString(),
]); ]);