You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
use App\Enums\OrderStatus;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Order;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class InvoiceSeeder extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*/
|
|
|
|
public function run(): void
|
|
|
|
{
|
|
|
|
$orders = Order::all()->where('status', OrderStatus::INVOICED);
|
|
|
|
|
|
|
|
for ($i = count($orders); $i > 4; $i -= 5) {
|
|
|
|
$invoice = Invoice::factory()->create();
|
|
|
|
|
|
|
|
for ($o = 0; $o < 5; $o++) {
|
|
|
|
$invoice->orders()->save(Order::findOrFail($i + $o));
|
|
|
|
$invoice->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
$invoice->calculateTotals();
|
|
|
|
}
|
|
|
|
|
|
|
|
\Log::debug(Invoice::all());
|
|
|
|
}
|
|
|
|
}
|