61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\IsPaid;
|
|
use App\Models\Payroll;
|
|
use App\Models\User;
|
|
use DateTime;
|
|
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);
|
|
|
|
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::NOT_PAID,
|
|
];
|
|
}
|
|
|
|
public function withPaidAt(?DateTime $paidAt = null): Factory
|
|
{
|
|
return $this->state(fn () => [
|
|
'is_paid' => IsPaid::PAID,
|
|
'paid_at' => $paidAt ?? now(),
|
|
]);
|
|
}
|
|
|
|
public function withPeriodMonth(string $periodMonth): Factory
|
|
{
|
|
return $this->state(fn () => ['period_month' => $periodMonth]);
|
|
}
|
|
|
|
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,
|
|
]);
|
|
}
|
|
}
|