*/ class PayrollFactory extends Factory { /** * Define the model's default state. * * @return array */ 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, ]; } }