diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 4503aa9..f88ba20 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -18,6 +18,7 @@ class Invoice extends Model 'total', 'gst', 'pst', + 'paid', 'date', ]; diff --git a/database/factories/InvoiceFactory.php b/database/factories/InvoiceFactory.php index 8d7c50c..cae6a74 100644 --- a/database/factories/InvoiceFactory.php +++ b/database/factories/InvoiceFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Customer; use App\Models\Invoice; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Carbon; @@ -12,11 +13,15 @@ class InvoiceFactory extends Factory public function definition(): array { + $customer = Customer::all()->shuffle()->first(); + return [ - 'created_at' => Carbon::now(), - 'gst' => true, - 'pst' => $this->faker->boolean(25), - 'updated_at' => Carbon::now(), + 'created_at' => Carbon::now(), + 'gst' => true, + 'pst' => $this->faker->boolean(25), + 'paid' => $this->faker->boolean(), + 'customer_id' => $customer->id, + 'updated_at' => Carbon::now(), ]; } } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 37e71e6..51d4816 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -24,7 +24,7 @@ class DatabaseSeeder extends Seeder ProductServiceSeeder::class, ServiceFileSeeder::class, QuoteSeeder::class, - InvoiceSeeder::class, +// InvoiceSeeder::class, ]); User::factory()->create([ diff --git a/database/seeders/InvoiceSeeder.php b/database/seeders/InvoiceSeeder.php index c50fb81..52390c6 100644 --- a/database/seeders/InvoiceSeeder.php +++ b/database/seeders/InvoiceSeeder.php @@ -2,6 +2,9 @@ namespace Database\Seeders; +use App\Enums\OrderStatus; +use App\Models\Invoice; +use App\Models\Order; use Illuminate\Database\Seeder; class InvoiceSeeder extends Seeder @@ -11,8 +14,19 @@ class InvoiceSeeder extends Seeder */ public function run(): void { - // foreach (Order::where('status', OrderStatus::INVOICED->value)->get() as $order) { - // Invoice::factory()->for($order)->create(); - // } + $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()); } }