created invoice seeder
This commit is contained in:
parent
7e2a22e016
commit
1b891f8350
@ -18,6 +18,7 @@ class Invoice extends Model
|
|||||||
'total',
|
'total',
|
||||||
'gst',
|
'gst',
|
||||||
'pst',
|
'pst',
|
||||||
|
'paid',
|
||||||
'date',
|
'date',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Customer;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
@ -12,11 +13,15 @@ class InvoiceFactory extends Factory
|
|||||||
|
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
|
$customer = Customer::all()->shuffle()->first();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'created_at' => Carbon::now(),
|
'created_at' => Carbon::now(),
|
||||||
'gst' => true,
|
'gst' => true,
|
||||||
'pst' => $this->faker->boolean(25),
|
'pst' => $this->faker->boolean(25),
|
||||||
'updated_at' => Carbon::now(),
|
'paid' => $this->faker->boolean(),
|
||||||
|
'customer_id' => $customer->id,
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public function run(): void
|
|||||||
ProductServiceSeeder::class,
|
ProductServiceSeeder::class,
|
||||||
ServiceFileSeeder::class,
|
ServiceFileSeeder::class,
|
||||||
QuoteSeeder::class,
|
QuoteSeeder::class,
|
||||||
InvoiceSeeder::class,
|
// InvoiceSeeder::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Enums\OrderStatus;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Order;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class InvoiceSeeder extends Seeder
|
class InvoiceSeeder extends Seeder
|
||||||
@ -11,8 +14,19 @@ class InvoiceSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
// foreach (Order::where('status', OrderStatus::INVOICED->value)->get() as $order) {
|
$orders = Order::all()->where('status', OrderStatus::INVOICED);
|
||||||
// Invoice::factory()->for($order)->create();
|
|
||||||
// }
|
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…
x
Reference in New Issue
Block a user