* #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:
@@ -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}";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user