52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\Unit;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\DelayedGood>
|
|
*/
|
|
class DelayedGoodFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
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(),
|
|
];
|
|
}
|
|
}
|