diff --git a/app/Domain/VacationDaysCalculator.php b/app/Domain/VacationDaysCalculator.php new file mode 100644 index 0000000..fcbc9e8 --- /dev/null +++ b/app/Domain/VacationDaysCalculator.php @@ -0,0 +1,42 @@ +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; + } +} diff --git a/app/Domain/Validation/Rules/ApprovedVacationDaysInSameRange.php b/app/Domain/Validation/Rules/ApprovedVacationDaysInSameRange.php deleted file mode 100644 index eb39bf4..0000000 --- a/app/Domain/Validation/Rules/ApprovedVacationDaysInSameRange.php +++ /dev/null @@ -1,16 +0,0 @@ -vacationDaysCalculator + ->calculateDays($vacationRequest->yearPeriod, $vacationRequest->from, $vacationRequest->to) + ->isNotEmpty(); + } + + public function errorMessage(): string + { + return __("Vacation needs minimum one day."); } } diff --git a/app/Domain/Validation/Rules/NoApprovedVacationRequestsInRange.php b/app/Domain/Validation/Rules/NoApprovedVacationRequestsInRange.php new file mode 100644 index 0000000..d06fd95 --- /dev/null +++ b/app/Domain/Validation/Rules/NoApprovedVacationRequestsInRange.php @@ -0,0 +1,26 @@ +user + ->vacationRequests() + ->overlapsWith($vacationRequest) + ->states(VacationRequestState::successStates()) + ->exists(); + } + + public function errorMessage(): string + { + return __("You have approved vacation request in this range."); + } +} diff --git a/app/Domain/Validation/Rules/NoPendingVacationRequestInRange.php b/app/Domain/Validation/Rules/NoPendingVacationRequestInRange.php new file mode 100644 index 0000000..3031b56 --- /dev/null +++ b/app/Domain/Validation/Rules/NoPendingVacationRequestInRange.php @@ -0,0 +1,26 @@ +user + ->vacationRequests() + ->overlapsWith($vacationRequest) + ->states(VacationRequestState::pendingStates()) + ->exists(); + } + + public function errorMessage(): string + { + return __("You have pending vacation request in this range."); + } +} diff --git a/app/Domain/Validation/Rules/PendingVacationRequestInSameRange.php b/app/Domain/Validation/Rules/PendingVacationRequestInSameRange.php deleted file mode 100644 index a0081b6..0000000 --- a/app/Domain/Validation/Rules/PendingVacationRequestInSameRange.php +++ /dev/null @@ -1,16 +0,0 @@ -from->isSameYear($vacationRequest->to); + } + + public function errorMessage(): string + { + return __("The vacation request cannot be created at the turn of the year."); + } +} diff --git a/app/Domain/Validation/Rules/VacationRequestRule.php b/app/Domain/Validation/Rules/VacationRequestRule.php index e50c92b..07af8d2 100644 --- a/app/Domain/Validation/Rules/VacationRequestRule.php +++ b/app/Domain/Validation/Rules/VacationRequestRule.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Toby\Domain\Validation\Rules; -use Closure; use Toby\Eloquent\Models\VacationRequest; interface VacationRequestRule { - public function check(VacationRequest $vacationRequest, Closure $next); + public function check(VacationRequest $vacationRequest): bool; + public function errorMessage(): string; } diff --git a/app/Domain/Validation/VacationRequestValidator.php b/app/Domain/Validation/VacationRequestValidator.php index f3cfa23..2bc39e6 100644 --- a/app/Domain/Validation/VacationRequestValidator.php +++ b/app/Domain/Validation/VacationRequestValidator.php @@ -4,32 +4,49 @@ declare(strict_types=1); namespace Toby\Domain\Validation; -use Illuminate\Pipeline\Pipeline; -use Toby\Domain\Validation\Rules\ApprovedVacationDaysInSameRange; +use Illuminate\Contracts\Container\Container; +use Illuminate\Validation\ValidationException; use Toby\Domain\Validation\Rules\DoesNotExceedLimitRule; 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; class VacationRequestValidator { protected array $rules = [ + VacationRangeIsInTheSameYearRule::class, MinimumOneVacationDayRule::class, DoesNotExceedLimitRule::class, - PendingVacationRequestInSameRange::class, - ApprovedVacationDaysInSameRange::class, + NoPendingVacationRequestInRange::class, + NoApprovedVacationRequestsInRange::class, ]; public function __construct( - protected Pipeline $pipeline, + protected Container $container, ) { } + /** + * @throws ValidationException + */ public function validate(VacationRequest $vacationRequest): void { - $this->pipeline - ->send($vacationRequest) - ->through($this->rules) - ->via("check"); + foreach ($this->rules as $rule) { + $rule = $this->makeRule($rule); + + if (!$rule->check($vacationRequest)) { + throw ValidationException::withMessages([ + "vacationRequest" => $rule->errorMessage(), + ]); + } + } + } + + protected function makeRule(string $class): VacationRequestRule + { + return $this->container->make($class); } } diff --git a/app/Eloquent/Models/User.php b/app/Eloquent/Models/User.php index 7c6fd93..6a7c4db 100644 --- a/app/Eloquent/Models/User.php +++ b/app/Eloquent/Models/User.php @@ -22,6 +22,7 @@ use Toby\Domain\Enums\Role; * @property string $last_name * @property string $email * @property string $avatar + * @property string $position * @property Role $role * @property EmploymentForm $employment_form * @property Carbon $employment_date diff --git a/app/Eloquent/Models/VacationRequest.php b/app/Eloquent/Models/VacationRequest.php index 528759d..0a81620 100644 --- a/app/Eloquent/Models/VacationRequest.php +++ b/app/Eloquent/Models/VacationRequest.php @@ -21,9 +21,13 @@ use Toby\Domain\Enums\VacationType; * @property VacationRequestState $state * @property Carbon $from * @property Carbon $to + * @property int $estimated_days * @property string $comment * @property User $user + * @property YearPeriod $yearPeriod * @property Collection $activities + * @property Carbon $created_at + * @property Carbon $updated_at */ class VacationRequest extends Model { @@ -43,6 +47,11 @@ class VacationRequest extends Model return $this->belongsTo(User::class); } + public function yearPeriod(): BelongsTo + { + return $this->belongsTo(YearPeriod::class); + } + public function activities(): HasMany { return $this->hasMany(VacationRequestActivity::class); @@ -60,6 +69,12 @@ class VacationRequest extends Model 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 { return VacationRequestFactory::new(); diff --git a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php new file mode 100644 index 0000000..b8a8c33 --- /dev/null +++ b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php @@ -0,0 +1,20 @@ +calculateDays($request->yearPeriod(), $request->from(), $request->to()); + + return new JsonResponse($days->all()); + } +} diff --git a/app/Infrastructure/Http/Controllers/VacationRequestController.php b/app/Infrastructure/Http/Controllers/VacationRequestController.php index 8166905..f864bc0 100644 --- a/app/Infrastructure/Http/Controllers/VacationRequestController.php +++ b/app/Infrastructure/Http/Controllers/VacationRequestController.php @@ -4,13 +4,17 @@ declare(strict_types=1); namespace Toby\Infrastructure\Http\Controllers; +use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response as LaravelResponse; use Inertia\Response; use Toby\Domain\Enums\VacationRequestState; use Toby\Domain\Enums\VacationType; +use Toby\Domain\VacationDaysCalculator; use Toby\Domain\VacationRequestStateManager; use Toby\Domain\Validation\VacationRequestValidator; +use Toby\Eloquent\Helpers\YearPeriodRetriever; use Toby\Eloquent\Models\VacationRequest; use Toby\Infrastructure\Http\Requests\VacationRequestRequest; use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource; @@ -18,12 +22,13 @@ use Toby\Infrastructure\Http\Resources\VacationRequestResource; class VacationRequestController extends Controller { - public function index(Request $request): Response + public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response { $status = $request->get("status", "all"); $vacationRequests = $request->user() ->vacationRequests() + ->where("year_period_id", $yearPeriodRetriever->selected()->id) ->latest() ->states(VacationRequestState::filterByStatus($status)) ->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 { return inertia("VacationRequest/Create", [ @@ -55,9 +69,15 @@ class VacationRequestController extends Controller VacationRequestRequest $request, VacationRequestValidator $vacationRequestValidator, VacationRequestStateManager $stateManager, + VacationDaysCalculator $vacationDaysCalculator, ): RedirectResponse { /** @var VacationRequest $vacationRequest */ $vacationRequest = $request->user()->vacationRequests()->make($request->data()); + $vacationRequest->estimated_days = $vacationDaysCalculator->calculateDays( + $vacationRequest->yearPeriod, + $vacationRequest->from, + $vacationRequest->to, + )->count(); $vacationRequestValidator->validate($vacationRequest); diff --git a/app/Infrastructure/Http/Requests/Api/CalculateVacationDaysRequest.php b/app/Infrastructure/Http/Requests/Api/CalculateVacationDaysRequest.php new file mode 100644 index 0000000..72e37de --- /dev/null +++ b/app/Infrastructure/Http/Requests/Api/CalculateVacationDaysRequest.php @@ -0,0 +1,36 @@ + ["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); + } +} diff --git a/app/Infrastructure/Http/Requests/UserRequest.php b/app/Infrastructure/Http/Requests/UserRequest.php index 2f7ed8c..e46e5f0 100644 --- a/app/Infrastructure/Http/Requests/UserRequest.php +++ b/app/Infrastructure/Http/Requests/UserRequest.php @@ -19,6 +19,7 @@ class UserRequest extends FormRequest "lastName" => ["required", "min:3", "max:80"], "email" => ["required", "email", Rule::unique("users", "email")->ignore($this->user)], "role" => ["required", new Enum(Role::class)], + "position" => ["required"], "employmentForm" => ["required", new Enum(EmploymentForm::class)], "employmentDate" => ["required", "date_format:Y-m-d"], ]; @@ -30,6 +31,7 @@ class UserRequest extends FormRequest "first_name" => $this->get("firstName"), "last_name" => $this->get("lastName"), "email" => $this->get("email"), + "position" => $this->get("position"), "role" => $this->get("role"), "employment_form" => $this->get("employmentForm"), "employment_date" => $this->get("employmentDate"), diff --git a/app/Infrastructure/Http/Requests/VacationRequestRequest.php b/app/Infrastructure/Http/Requests/VacationRequestRequest.php index eeea29b..3fd9e9f 100644 --- a/app/Infrastructure/Http/Requests/VacationRequestRequest.php +++ b/app/Infrastructure/Http/Requests/VacationRequestRequest.php @@ -5,8 +5,10 @@ declare(strict_types=1); namespace Toby\Infrastructure\Http\Requests; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Support\Carbon; use Illuminate\Validation\Rules\Enum; use Toby\Domain\Enums\VacationType; +use Toby\Eloquent\Models\YearPeriod; use Toby\Infrastructure\Http\Rules\YearPeriodExists; class VacationRequestRequest extends FormRequest @@ -23,10 +25,13 @@ class VacationRequestRequest extends FormRequest public function data(): array { + $from = $this->get("from"); + return [ "type" => $this->get("type"), - "from" => $this->get("from"), + "from" => $from, "to" => $this->get("to"), + "year_period_id" => YearPeriod::findByYear(Carbon::create($from)->year)->id, "comment" => $this->get("comment"), ]; } diff --git a/app/Infrastructure/Http/Resources/UserFormDataResource.php b/app/Infrastructure/Http/Resources/UserFormDataResource.php index 451fda2..6847362 100644 --- a/app/Infrastructure/Http/Resources/UserFormDataResource.php +++ b/app/Infrastructure/Http/Resources/UserFormDataResource.php @@ -18,6 +18,7 @@ class UserFormDataResource extends JsonResource "lastName" => $this->last_name, "email" => $this->email, "role" => $this->role, + "position" => $this->position, "employmentForm" => $this->employment_form, "employmentDate" => $this->employment_date->toDateString(), ]; diff --git a/app/Infrastructure/Http/Resources/UserResource.php b/app/Infrastructure/Http/Resources/UserResource.php index bdff955..5e3107f 100644 --- a/app/Infrastructure/Http/Resources/UserResource.php +++ b/app/Infrastructure/Http/Resources/UserResource.php @@ -17,6 +17,7 @@ class UserResource extends JsonResource "name" => $this->fullName, "email" => $this->email, "role" => $this->role->label(), + "position" => $this->position, "avatar" => asset($this->avatar), "deleted" => $this->trashed(), "employmentForm" => $this->employment_form->label(), diff --git a/app/Infrastructure/Http/Resources/VacationRequestResource.php b/app/Infrastructure/Http/Resources/VacationRequestResource.php index 859dfea..009eeb6 100644 --- a/app/Infrastructure/Http/Resources/VacationRequestResource.php +++ b/app/Infrastructure/Http/Resources/VacationRequestResource.php @@ -20,6 +20,7 @@ class VacationRequestResource extends JsonResource "state" => $this->state->label(), "from" => $this->from->toDisplayString(), "to" => $this->to->toDisplayString(), + "estimatedDays" => $this->estimated_days, "comment" => $this->comment, ]; } diff --git a/composer.json b/composer.json index f2962a5..ebd3f96 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "php": "^8.1", "ext-pdo": "*", "azuyalabs/yasumi": "^2.4", + "barryvdh/laravel-dompdf": "^1.0", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", "inertiajs/inertia-laravel": "^0.5.1", diff --git a/composer.lock b/composer.lock index 066cfc9..a7e5000 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bf5f7d8f40ecadea64ae8564a3df3110", + "content-hash": "c2f475e65f84bdff45169e4443d9ef4f", "packages": [ { "name": "asm89/stack-cors", @@ -135,6 +135,82 @@ ], "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", "version": "0.9.3", @@ -437,6 +513,73 @@ ], "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", "version": "v3.3.1", @@ -2846,6 +2989,95 @@ ], "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", "version": "1.8.1", @@ -3572,6 +3804,59 @@ ], "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", "version": "v6.3.0", @@ -10027,5 +10312,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.2.0" } diff --git a/config/app.php b/config/app.php index cbd96cb..a5d12a9 100644 --- a/config/app.php +++ b/config/app.php @@ -43,5 +43,6 @@ return [ Toby\Architecture\Providers\RouteServiceProvider::class, Toby\Architecture\Providers\TelescopeServiceProvider::class, Toby\Architecture\Providers\ObserverServiceProvider::class, + Barryvdh\DomPDF\ServiceProvider::class, ], ]; diff --git a/config/cors.php b/config/cors.php index c025685..34e1c4f 100644 --- a/config/cors.php +++ b/config/cors.php @@ -10,5 +10,5 @@ return [ "allowed_headers" => ["*"], "exposed_headers" => [], "max_age" => 0, - "supports_credentials" => false, + "supports_credentials" => true, ]; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 5e4086a..c6a5d93 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -22,6 +22,7 @@ class UserFactory extends Factory "last_name" => $this->faker->lastName(), "email" => $this->faker->unique()->safeEmail(), "employment_form" => $this->faker->randomElement(EmploymentForm::cases()), + "position" => $this->faker->jobTitle(), "role" => Role::EMPLOYEE, "employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(), "remember_token" => Str::random(10), diff --git a/database/factories/VacationRequestFactory.php b/database/factories/VacationRequestFactory.php index 839e2b7..3939367 100644 --- a/database/factories/VacationRequestFactory.php +++ b/database/factories/VacationRequestFactory.php @@ -4,29 +4,50 @@ declare(strict_types=1); namespace Database\Factories; +use Carbon\CarbonImmutable; +use Carbon\CarbonPeriod; use Illuminate\Database\Eloquent\Factories\Factory; use Toby\Domain\Enums\VacationRequestState; use Toby\Domain\Enums\VacationType; use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\VacationRequest; +use Toby\Eloquent\Models\YearPeriod; class VacationRequestFactory extends Factory { protected $model = VacationRequest::class; + private static int $number = 1; public function definition(): array { - $number = $this->faker->numberBetween(1, 20); - $year = $this->faker->year; + $from = CarbonImmutable::create($this->faker->dateTimeThisYear); + $days = $this->faker->numberBetween(0, 20); return [ "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()), "state" => $this->faker->randomElement(VacationRequestState::cases()), - "from" => $this->faker->date, - "to" => $this->faker->date, + "from" => $from, + "to" => $from->addDays($days), + "estimated_days" => fn(array $attributes) => $this->estimateDays($attributes), "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(); + } } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index cc11d89..5f09111 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -17,6 +17,7 @@ return new class() extends Migration { $table->string("email")->unique(); $table->string("avatar")->nullable(); $table->string("role")->default(Role::EMPLOYEE->value); + $table->string("position"); $table->string("employment_form"); $table->date("employment_date"); $table->rememberToken(); diff --git a/database/migrations/2022_01_26_100039_create_vacation_requests_table.php b/database/migrations/2022_01_26_100039_create_vacation_requests_table.php index a7e4cd7..b3f4e48 100644 --- a/database/migrations/2022_01_26_100039_create_vacation_requests_table.php +++ b/database/migrations/2022_01_26_100039_create_vacation_requests_table.php @@ -6,6 +6,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Toby\Eloquent\Models\User; +use Toby\Eloquent\Models\YearPeriod; return new class() extends Migration { public function up(): void @@ -14,8 +15,10 @@ return new class() extends Migration { $table->id(); $table->string("name"); $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete(); + $table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete(); $table->string("type"); $table->string("state")->nullable(); + $table->integer("estimated_days"); $table->date("from"); $table->date("to"); $table->text("comment")->nullable(); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index af9ac30..205246a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -31,7 +31,6 @@ class DatabaseSeeder extends Seeder User::factory([ "email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"), ]) - ->hasVacationRequests(5) ->create(); $users = User::all(); @@ -70,6 +69,18 @@ class DatabaseSeeder extends Seeder } }) ->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 diff --git a/package-lock.json b/package-lock.json index 64ebfd5..7795438 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "application", + "name": "toby", "lockfileVersion": 2, "requires": true, "packages": { @@ -15,6 +15,7 @@ "@tailwindcss/typography": "^0.5.0", "@vue/compiler-sfc": "^3.2.26", "autoprefixer": "^10.4.2", + "axios": "^0.25.0", "echarts": "^5.2.2", "flatpickr": "^4.6.9", "laravel-mix": "^6.0.6", @@ -1741,6 +1742,14 @@ "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": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/@inertiajs/progress/-/progress-0.2.7.tgz", @@ -2642,11 +2651,11 @@ } }, "node_modules/axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz", + "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", "dependencies": { - "follow-redirects": "^1.14.0" + "follow-redirects": "^1.14.7" } }, "node_modules/babel-loader": { @@ -10664,6 +10673,16 @@ "axios": "^0.21.1", "deepmerge": "^4.0.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": { @@ -11468,11 +11487,11 @@ } }, "axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz", + "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", "requires": { - "follow-redirects": "^1.14.0" + "follow-redirects": "^1.14.7" } }, "babel-loader": { diff --git a/package.json b/package.json index 6a0d9af..c69812f 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@tailwindcss/typography": "^0.5.0", "@vue/compiler-sfc": "^3.2.26", "autoprefixer": "^10.4.2", + "axios": "^0.25.0", "echarts": "^5.2.2", "flatpickr": "^4.6.9", "laravel-mix": "^6.0.6", diff --git a/resources/js/Pages/Users/Create.vue b/resources/js/Pages/Users/Create.vue index 5347b60..b871b93 100644 --- a/resources/js/Pages/Users/Create.vue +++ b/resources/js/Pages/Users/Create.vue @@ -82,6 +82,29 @@
++ {{ form.errors.position }} +
++ {{ form.errors.position }} +
+- {{ form.errors.vacationType }} + {{ form.errors.type }}
- {{ form.errors.dateFrom }} + {{ form.errors.from }}
- {{ form.errors.dateTo }} + {{ form.errors.to }}