*/ class ExpenseFactory extends Factory { protected $model = ExpenseModel::class; /** * @return array */ public function definition(): array { $cost = fake()->numberBetween(500, 50000); return [ 'customer_job_id' => CustomerJobModel::factory(), 'user_id' => User::factory(), 'recorded_by' => fn (array $attributes): int => $attributes['user_id'], 'category' => ExpenseCategory::Materials, 'paid_by' => ExpensePayer::Company, 'spent_on' => fake()->dateTimeBetween('-1 month')->format('Y-m-d'), 'description' => fake()->words(3, true), 'cost_cents' => $cost, 'kilometers' => null, 'destination' => null, 'purpose' => null, 'is_billable' => true, 'markup_basis_points' => null, 'billed_amount_cents' => $cost, ]; } public function mileage(float $kilometers = 40, int $rateCents = 59): static { $cost = (int) round($kilometers * $rateCents); return $this->state(fn (): array => [ 'category' => ExpenseCategory::Mileage, 'description' => null, 'kilometers' => $kilometers, 'destination' => 'Tampere', 'purpose' => 'Asiakastapaaminen', 'cost_cents' => $cost, 'billed_amount_cents' => $cost, ]); } public function paidByEmployee(): static { return $this->state(fn (): array => ['paid_by' => ExpensePayer::Employee]); } public function notBillable(): static { return $this->state(fn (): array => ['is_billable' => false, 'markup_basis_points' => null, 'billed_amount_cents' => null]); } }