dress/database/factories/PayrollFactory.php

39 lines
1.1 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Payroll;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Payroll>
*/
class PayrollFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$baseSalary = fake()->numberBetween(2500000, 5000000);
$bonus = fake()->optional(0.7, 0)->passthrough(fake()->numberBetween(100000, 500000));
$deduction = fake()->optional(0.3, 0)->passthrough(fake()->numberBetween(50000, 200000));
$totalSalary = $baseSalary + $bonus - $deduction;
$isPaid = fake()->boolean(80);
return [
'user_id' => User::factory(),
'period_month' => fake()->dateTimeBetween('-1 year', 'now')->format('Y-m'),
'base_salary' => $baseSalary,
'bonus' => $bonus,
'deduction' => $deduction,
'total_salary' => $totalSalary,
'is_paid' => $isPaid,
'paid_at' => $isPaid ? fake()->dateTimeBetween('-1 month', 'now') : null,
];
}
}