2024-10-30 19:28:03 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
2024-11-13 23:34:53 -05:00
|
|
|
use App\Enums\InvoiceStatus;
|
2024-11-11 19:50:11 -05:00
|
|
|
use App\Models\Customer;
|
2024-10-30 19:28:03 -04:00
|
|
|
use App\Models\Invoice;
|
2025-01-14 17:17:04 -05:00
|
|
|
use App\Models\TaxRate;
|
2024-10-30 19:28:03 -04:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
|
|
class InvoiceFactory extends Factory
|
|
|
|
{
|
|
|
|
protected $model = Invoice::class;
|
|
|
|
|
|
|
|
public function definition(): array
|
|
|
|
{
|
2025-01-19 12:51:37 -05:00
|
|
|
$customer = Customer::all()->shuffle()->firstOrFail();
|
2024-11-11 19:50:11 -05:00
|
|
|
|
2024-10-30 19:28:03 -04:00
|
|
|
return [
|
2025-01-16 17:37:32 -05:00
|
|
|
'created_at' => Carbon::now()->subDays(rand(1, 30)),
|
2025-01-21 21:28:41 -05:00
|
|
|
'pst_rate' => TaxRate::where('name', 'PST')->value('value') ?? 0,
|
|
|
|
'gst_rate' => TaxRate::where('name', 'GST')->value('value') ?? 0,
|
|
|
|
'hst_rate' => TaxRate::where('name', 'HST')->value('value') ?? 0,
|
2025-01-16 17:37:32 -05:00
|
|
|
'has_gst' => true,
|
|
|
|
'has_pst' => $this->faker->boolean(40),
|
2025-01-21 21:28:41 -05:00
|
|
|
'has_hst' => false,
|
2024-11-20 20:09:45 -05:00
|
|
|
'date' => Carbon::now()->subDays(rand(1, 60)),
|
2024-11-13 23:34:53 -05:00
|
|
|
'status' => $this->faker->randomElement(InvoiceStatus::cases())->value,
|
2024-11-11 19:50:11 -05:00
|
|
|
'customer_id' => $customer->id,
|
|
|
|
'updated_at' => Carbon::now(),
|
2024-10-30 19:28:03 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|