created invoice seeder

orders
Nisse Lommerde 2 weeks ago
parent 7e2a22e016
commit 1b891f8350

@ -18,6 +18,7 @@ class Invoice extends Model
'total',
'gst',
'pst',
'paid',
'date',
];

@ -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(),
];
}
}

@ -24,7 +24,7 @@ class DatabaseSeeder extends Seeder
ProductServiceSeeder::class,
ServiceFileSeeder::class,
QuoteSeeder::class,
InvoiceSeeder::class,
// InvoiceSeeder::class,
]);
User::factory()->create([

@ -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());
}
}

Loading…
Cancel
Save