2025-10-20 08:57:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
|
use App\Models\LineItem;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Invoice>
|
|
|
|
|
*/
|
|
|
|
|
class InvoiceFactory extends Factory
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Define the model's default state.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, mixed>
|
|
|
|
|
*/
|
|
|
|
|
public function definition(): array
|
|
|
|
|
{
|
2025-10-30 15:38:41 +01:00
|
|
|
$payment_status = $this->faker->randomElement(['draft', 'issued', 'paid', 'due', 'reminded', 'cancelled']);
|
2025-10-20 08:57:51 +02:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'nr' => ($payment_status == 'draft') ? null : $this->faker->unique()->numerify('RE-###'),
|
|
|
|
|
'invoice_date' => $this->faker->date(),
|
|
|
|
|
'due_date' => $this->faker->date(),
|
|
|
|
|
'service_start_date' => $this->faker->date(),
|
|
|
|
|
'service_end_date' => $this->faker->date(),
|
|
|
|
|
'is_recurring' => $this->faker->boolean(30),
|
|
|
|
|
'is_partial_service' => $this->faker->boolean(30),
|
|
|
|
|
'customer_id' => Customer::factory(),
|
|
|
|
|
'payment_status' => $payment_status,
|
|
|
|
|
'total_amount' => $this->faker->randomFloat(2, 100, 1000),
|
|
|
|
|
'title' => $this->faker->text(50),
|
|
|
|
|
'text' => $this->faker->paragraph(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Configure the factory to create related line items after creating an invoice.
|
|
|
|
|
*/
|
|
|
|
|
public function configure()
|
|
|
|
|
{
|
|
|
|
|
return $this->afterCreating(function ($invoice) {
|
|
|
|
|
LineItem::factory(rand(2, 5))->create([
|
|
|
|
|
'invoice_id' => $invoice->id,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|