49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
|
use App\Modules\TimeTracking\Infrastructure\Persistence\Eloquent\TimeEntryModel;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<TimeEntryModel>
|
|
*/
|
|
class TimeEntryFactory extends Factory
|
|
{
|
|
protected $model = TimeEntryModel::class;
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'user_id' => User::factory(),
|
|
'task_id' => TaskModel::factory(),
|
|
'customer_job_id' => fn (array $attributes) => TaskModel::query()->findOrFail($attributes['task_id'])->customer_job_id,
|
|
'work_type_id' => fn (array $attributes) => TaskModel::query()->findOrFail($attributes['task_id'])->work_type_id,
|
|
'worked_on' => now()->toDateString(),
|
|
'hours' => 2,
|
|
'note' => fake()->sentence(3),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* An entry without a billing note, which keeps its week from being approved.
|
|
*/
|
|
public function withoutNote(): static
|
|
{
|
|
return $this->state(['note' => null]);
|
|
}
|
|
|
|
public function approved(?User $by = null): static
|
|
{
|
|
return $this->state(fn (array $attributes): array => [
|
|
'approved_at' => now(),
|
|
'approved_by' => $by->id ?? $attributes['user_id'],
|
|
]);
|
|
}
|
|
}
|