*/ class DelayedGoodFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { $unit = Unit::whereIn('alias', ['butir', 'kg'])->inRandomOrder()->first() ?? Unit::where('alias', 'butir')->first() ?? Unit::factory()->create(); if ($unit->alias === 'butir') { $quantity = fake()->numberBetween(10, 100); $unitPrice = fake()->numberBetween(1500, 2500); } else { $quantity = fake()->randomFloat(2, 1, 15); $unitPrice = fake()->numberBetween(25000, 32000); } $totalAmount = $quantity * $unitPrice; $isPaid = fake()->boolean(); $paidAmount = $isPaid ? $totalAmount : fake()->numberBetween(0, $totalAmount); $storedDate = fake()->dateTimeBetween('-1 month', 'now'); return [ 'customer_id' => Customer::inRandomOrder()->first()?->id ?? Customer::factory(), 'unit_id' => $unit->id, 'quantity' => $quantity, 'unit_price' => $unitPrice, 'total_amount' => $totalAmount, 'paid_amount' => $paidAmount, 'stored_date' => $storedDate, 'is_paid' => $isPaid, 'payment_date' => $isPaid ? fake()->dateTimeBetween($storedDate, 'now') : null, 'notes' => fake()->optional()->sentence(), ]; } }