35 lines
1.1 KiB
PHP
Raw Permalink Normal View History

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,
'date' => Carbon::now()->subDays(rand(1, 60)),
2025-01-24 21:37:05 -05:00
'status' => InvoiceStatus::UNPAID->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
];
}
}