feat: Add DelayedGood model factory and seeder, and integrate it into the main DatabaseSeeder.
This commit is contained in:
parent
556618c929
commit
a1d01654d5
41
database/factories/DelayedGoodFactory.php
Normal file
41
database/factories/DelayedGoodFactory.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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
|
||||
{
|
||||
$quantity = fake()->numberBetween(1, 100);
|
||||
$unitPrice = fake()->numberBetween(5000, 20000);
|
||||
$totalAmount = $quantity * $unitPrice;
|
||||
$isPaid = fake()->boolean();
|
||||
$paidAmount = $isPaid ? $totalAmount : fake()->numberBetween(0, $totalAmount);
|
||||
$storedDate = fake()->dateTimeBetween('-1 month', 'now');
|
||||
|
||||
return [
|
||||
'customer_id' => Customer::factory(),
|
||||
'unit_id' => Unit::factory(),
|
||||
'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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -25,6 +25,7 @@ public function run(): void
|
||||
CustomerSeeder::class,
|
||||
EggPriceSeeder::class,
|
||||
OrderSeeder::class,
|
||||
DelayedGoodSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
31
database/seeders/DelayedGoodSeeder.php
Normal file
31
database/seeders/DelayedGoodSeeder.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DelayedGoodSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$customers = \App\Models\Customer::all();
|
||||
$units = \App\Models\Unit::all();
|
||||
|
||||
if ($customers->isEmpty()) {
|
||||
$customers = \App\Models\Customer::factory()->count(10)->create();
|
||||
}
|
||||
|
||||
if ($units->isEmpty()) {
|
||||
$units = \App\Models\Unit::factory()->count(5)->create();
|
||||
}
|
||||
|
||||
\App\Models\DelayedGood::factory()
|
||||
->count(50)
|
||||
->recycle($customers)
|
||||
->recycle($units)
|
||||
->create();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user