#40 - generate pdf for vacation request (#46)

* #40 - wip

* #40 - generate pdf

* #40 - fix

* Update resources/js/Pages/VacationRequest/Show.vue

Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* #40 - fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
Adrian Hopek
2022-02-04 10:57:11 +01:00
committed by GitHub
parent 067b343f24
commit 41c769d4ab
22 changed files with 544 additions and 10 deletions

View File

@@ -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),

View File

@@ -4,11 +4,13 @@ declare(strict_types=1);
namespace Database\Factories;
use Carbon\CarbonImmutable;
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
{
@@ -16,17 +18,30 @@ class VacationRequestFactory extends Factory
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),
"comment" => $this->faker->boolean ? $this->faker->paragraph() : null,
];
}
protected function generateName(array $attributes): string
{
$year = YearPeriod::find($attributes["year_period_id"])->year;
$user = User::find($attributes["user_id"]);
$number = $user->vacationRequests()
->whereYear("from", $year)
->count() + 1;
return "{$number}/{$year}";
}
}