52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\IsPaid;
|
|
use App\Models\Payroll;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class PayrollFactory extends Factory
|
|
{
|
|
protected $model = Payroll::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$base = $this->faker->numberBetween(3000000, 8000000);
|
|
$bonus = $this->faker->numberBetween(0, 2000000);
|
|
$deduction = $this->faker->numberBetween(0, 500000);
|
|
|
|
$isPaid = $this->faker->randomElement(IsPaid::cases());
|
|
|
|
return [
|
|
'user_id' => User::factory(),
|
|
'period_month' => $this->faker->date('Y-m'),
|
|
'base_salary' => $base,
|
|
'bonus' => $bonus,
|
|
'deduction' => $deduction,
|
|
'total_salary' => $base + $bonus - $deduction,
|
|
'is_paid' => $isPaid,
|
|
'paid_at' => $isPaid === IsPaid::PAID
|
|
? $this->faker->dateTimeBetween('-3 days', 'now')
|
|
: null,
|
|
];
|
|
}
|
|
|
|
public function paid(): Factory
|
|
{
|
|
return $this->state(fn () => [
|
|
'is_paid' => IsPaid::PAID,
|
|
'paid_at' => $this->faker->dateTimeBetween('-3 days', 'now'),
|
|
]);
|
|
}
|
|
|
|
public function notPaid(): Factory
|
|
{
|
|
return $this->state(fn () => [
|
|
'is_paid' => IsPaid::NOT_PAID,
|
|
'paid_at' => null,
|
|
]);
|
|
}
|
|
}
|