Re-worked seeders

orders
Nisse Lommerde 1 month ago
parent 2361ec0b88
commit e79d1839fe

@ -145,11 +145,9 @@ class OrderResource extends Resource
Cluster::make([
TextInput::make('serviceFileWidth')
->prefix('w')
->placeholder('Width'),
->prefix('w'),
TextInput::make('serviceFileHeight')
->prefix('h')
->placeholder('Height'),
->prefix('h'),
])
->label('Dimensions')
->columnSpan(4),

@ -0,0 +1,57 @@
<?php
namespace Database\Seeders;
use App\Models\Contact;
use App\Models\Customer;
use Illuminate\Database\Seeder;
class ContactSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
foreach (Customer::all() as $customer) {
if ($customer->company_name == 'Genumark') {
$customer->contacts()->createMany([
[
'first_name' => 'Tammy',
'last_name' => 'Bookbinder',
'email' => 'tbookbinder@genumark.com',
'phone' => '+1 778 229 5668',
],
[
'first_name' => 'Kathlyn',
'last_name' => 'Wood',
'email' => 'kwood@genumark.com',
'phone' => '+1 604 294 2376',
'notes' => 'Always CC, unless SOF order',
],
[
'first_name' => 'Jane',
'last_name' => 'Wellman',
'email' => 'jwellman@genumark.com',
'phone' => '+1 604 742 5584',
'notes' => 'Deals with SOF orders',
],
[
'first_name' => 'Trisha',
'last_name' => 'Miller',
'email' => 'tmiller@genumark.com',
'phone' => '+1 604 802 8486',
],
[
'first_name' => 'Brenda',
'last_name' => 'Kuepfer',
'email' => 'bkuepfer@genumark.com',
'phone' => '+1 604 305 5002',
],
]);
} else {
Contact::factory(rand(1, 4))->for($customer);
}
}
}
}

@ -2,99 +2,35 @@
namespace Database\Seeders;
use App\Models\Contact;
use App\Models\Customer;
use App\Models\Order;
use App\Models\OrderProduct;
use App\Models\PackingSlip;
use App\Models\ProductService;
use App\Models\ProductSize;
use App\Models\ServiceFile;
use App\Models\ShippingEntry;
use Illuminate\Database\Seeder;
class CustomerSeeder extends Seeder
{
public function run(): void
{
for ($i = 0; $i < 5; $i++) {
Customer::factory()
->has(Contact::factory(rand(1, 5)))
->has(ShippingEntry::factory(rand(1, 3)))
->has(Order::factory(rand(5, 10))
->has(OrderProduct::factory(rand(1, 3)))
->has(ProductService::factory(rand(1, 5), [
'service_file_id' => ServiceFile::factory(),
]))
->has(PackingSlip::factory(rand(0, 2))))
->create();
}
Customer::factory(5)->create();
Customer::factory(['company_name' => 'Genumark'])->create();
Customer::factory([
'company_name' => 'Genumark',
'internal_name' => 'genumark',
'shipping_address' => '',
'billing_address' => '',
])
->has(Contact::factory([
'first_name' => 'Tammy',
'last_name' => 'Bookbinder',
'email' => 'tbookbinder@genumark.com',
'phone' => '+1 778 229 5668',
]))
->has(Contact::factory([
'first_name' => 'Kathlyn',
'last_name' => 'Wood',
'email' => 'kwood@genumark.com',
'phone' => '+1 604 294 2376',
'notes' => 'Always CC, unless SOF order',
]))
->has(Contact::factory([
'first_name' => 'Jane',
'last_name' => 'Wellman',
'email' => 'jwellman@genumark.com',
'phone' => '+1 604 742 5584',
'notes' => 'Deals with SOF orders',
]))
->has(Contact::factory([
'first_name' => 'Trisha',
'last_name' => 'Miller',
'email' => 'tmiller@genumark.com',
'phone' => '+1 604 802 8486',
]))
->has(Contact::factory([
'first_name' => 'Brenda',
'last_name' => 'Kuepfer',
'email' => 'bkuepfer@genumark.com',
'phone' => '+1 604 305 5002',
]))
->has(PackingSlip::factory(20))
->has(ShippingEntry::factory([
'account_title' => 'Genumark',
'courier' => 'UPS CampusShip',
'contact' => 'https://www.ups.com/lasso/login',
'account_username' => 'GenumarkTopNotch',
'account_password' => 'TopNotch@13579',
'info_needed' => 'Put PO on box',
'notify' => 'Various reps, CC Kathlyn Wood',
'notes' => 'For Save On Foods orders, see Genumark SOF',
]))
->has(ShippingEntry::factory([
'account_title' => 'Genumark Save-On-Foods',
'courier' => 'UPS CampusShip',
'contact' => 'https://www.ups.com/lasso/login',
'account_username' => 'GenumarkTopNotch',
'account_password' => 'TopNotch@13579',
'info_needed' => 'Put PO on box',
'notify' => 'Jane Wellman',
'notes' => 'Don\'t CC Kathlyn for SOF orders',
]))
->has(Order::factory(rand(2, 10))
->has(OrderProduct::factory(rand(1, 10))
->has(productSize::factory(rand(1, 8))))
->has(ProductService::factory(rand(1, 10), [
'service_file_id' => ServiceFile::factory(),
])))
->create();
// ->has(ShippingEntry::factory([
// 'account_title' => 'Genumark',
// 'courier' => 'UPS CampusShip',
// 'contact' => 'https://www.ups.com/lasso/login',
// 'account_username' => 'GenumarkTopNotch',
// 'account_password' => 'TopNotch@13579',
// 'info_needed' => 'Put PO on box',
// 'notify' => 'Various reps, CC Kathlyn Wood',
// 'notes' => 'For Save On Foods orders, see Genumark SOF',
// ]))
// ->has(ShippingEntry::factory([
// 'account_title' => 'Genumark Save-On-Foods',
// 'courier' => 'UPS CampusShip',
// 'contact' => 'https://www.ups.com/lasso/login',
// 'account_username' => 'GenumarkTopNotch',
// 'account_password' => 'TopNotch@13579',
// 'info_needed' => 'Put PO on box',
// 'notify' => 'Jane Wellman',
// 'notes' => 'Don\'t CC Kathlyn for SOF orders',
// ]))
}
}

@ -3,9 +3,10 @@
namespace Database\Seeders;
use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
class DatabaseSeeder extends Seeder
{
/**
@ -15,6 +16,13 @@ class DatabaseSeeder extends Seeder
{
$this->call([
CustomerSeeder::class,
ContactSeeder::class,
ShippingEntrySeeder::class,
OrderSeeder::class,
OrderProductSeeder::class,
ProductSizeSeeder::class,
ProductServiceSeeder::class,
ServiceFileSeeder::class,
]);
User::factory()->create([

@ -0,0 +1,20 @@
<?php
namespace Database\Seeders;
use App\Models\Order;
use App\Models\OrderProduct;
use Illuminate\Database\Seeder;
class OrderProductSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
foreach (Order::all() as $order) {
OrderProduct::factory(rand(1, 3), ['order_id' => $order->id])->create();
}
}
}

@ -0,0 +1,20 @@
<?php
namespace Database\Seeders;
use App\Models\Customer;
use App\Models\Order;
use Illuminate\Database\Seeder;
class OrderSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
foreach (Customer::all() as $customer) {
Order::factory(rand(2, 10), ['customer_id' => $customer])->create();
}
}
}

@ -0,0 +1,20 @@
<?php
namespace Database\Seeders;
use App\Models\Order;
use App\Models\ProductService;
use Illuminate\Database\Seeder;
class ProductServiceSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
foreach (Order::all() as $order) {
ProductService::factory(rand(1, 4), ['order_id' => $order->id])->create();
}
}
}

@ -0,0 +1,29 @@
<?php
namespace Database\Seeders;
use App\Models\OrderProduct;
use Illuminate\Database\Seeder;
class ProductSizeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$sizes = ['xs', 's', 'm', 'l', 'xl', '2xl', '3xl'];
foreach (OrderProduct::all() as $service) {
foreach ($sizes as $size) {
if (rand(0, 1)) {
$service->productSizes()->create([
'size' => $size,
'amount' => ceil(rand(1, 200) / 10) * 10,
'order_product_id' => $service->id,
]);
}
}
}
}
}

@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\ProductService;
use App\Models\ServiceFile;
use Illuminate\Database\Seeder;
class ServiceFileSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
foreach (ProductService::all() as $product) {
$file = ServiceFile::factory()->create();
$file->productServices()->save($product);
}
}
}

@ -0,0 +1,20 @@
<?php
namespace Database\Seeders;
use App\Models\Customer;
use App\Models\ShippingEntry;
use Illuminate\Database\Seeder;
class ShippingEntrySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
foreach (Customer::all() as $customer) {
ShippingEntry::factory(5, ['customer_id' => $customer->id])->create();
}
}
}

Binary file not shown.
Loading…
Cancel
Save