190 lines
7.2 KiB
PHP
190 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Barangay;
|
|
use App\Models\CollectionTeam;
|
|
use App\Models\DriverProfile;
|
|
use App\Models\DropOffPoint;
|
|
use App\Models\Dumpsite;
|
|
use App\Models\HelperProfile;
|
|
use App\Models\NotificationPreference;
|
|
use App\Models\PartnerStore;
|
|
use App\Models\Route as CollectionRoute;
|
|
use App\Models\RouteStop;
|
|
use App\Models\ScannerProfile;
|
|
use App\Models\StoreInventory;
|
|
use App\Models\StorePartnerProfile;
|
|
use App\Models\TeamMember;
|
|
use App\Models\Tenant;
|
|
use App\Models\Trip;
|
|
use App\Models\TripStop;
|
|
use App\Models\Truck;
|
|
use App\Models\User;
|
|
use App\Tenancy\Tenancy;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
use MatanYadaev\EloquentSpatial\Objects\Point;
|
|
|
|
class DevelopmentSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$password = Hash::make('password1');
|
|
|
|
// 1. Create the LGU (Tenant)
|
|
$tenant = Tenant::firstOrCreate(
|
|
['code' => 'SPB'],
|
|
[
|
|
'name' => 'San Pascual, Batangas',
|
|
'status' => Tenant::STATUS_ACTIVE,
|
|
'qr_retail_price_centavos' => 1000,
|
|
'uuid' => (string) Str::uuid(),
|
|
]
|
|
);
|
|
Tenancy::setCurrent($tenant);
|
|
|
|
// 2. Create the Single Admin
|
|
$admin = User::firstOrCreate(
|
|
['email' => 'admin@verde.local'],
|
|
[
|
|
'phone' => '+639000000001',
|
|
'password' => $password,
|
|
'first_name' => 'Verde',
|
|
'last_name' => 'Admin',
|
|
'role' => User::ROLE_ADMIN,
|
|
'status' => User::STATUS_ACTIVE,
|
|
'tenant_id' => $tenant->id,
|
|
'email_verified_at' => now(),
|
|
]
|
|
);
|
|
$admin->syncRoles([User::ROLE_ADMIN]);
|
|
|
|
// 3. Infrastructure (Barangay, DOP, Dumpsite)
|
|
$barangay = Barangay::first() ?? Barangay::create(['name' => 'Poblacion', 'code' => '001']);
|
|
|
|
$dop = DropOffPoint::firstOrCreate(
|
|
['name' => 'Poblacion Plaza'],
|
|
[
|
|
'uuid' => (string) Str::uuid(),
|
|
'tenant_id' => $tenant->id,
|
|
'code' => 'DOP-001',
|
|
'barangay_id' => $barangay->id,
|
|
'address_line' => 'Main Square',
|
|
'coordinates' => new Point(14.65, 121.06),
|
|
]
|
|
);
|
|
|
|
$dumpsite = Dumpsite::firstOrCreate(
|
|
['name' => 'LGU Sanitary Landfill'],
|
|
[
|
|
'uuid' => (string) Str::uuid(),
|
|
'tenant_id' => $tenant->id,
|
|
'address_line' => 'Industrial Zone',
|
|
'coordinates' => new Point(14.67, 121.08),
|
|
]
|
|
);
|
|
|
|
// 4. Staff
|
|
$driver = $this->createStaff('driver@verde.local', '+639180000001', 'Carlos', 'Driver', User::ROLE_DRIVER, $tenant, $password);
|
|
$helper = $this->createStaff('helper@verde.local', '+639180000002', 'Mario', 'Helper', User::ROLE_HELPER, $tenant, $password);
|
|
$scanner = $this->createStaff('scanner@verde.local', '+639180000003', 'Imelda', 'Scanner', User::ROLE_SCANNER, $tenant, $password);
|
|
|
|
DriverProfile::updateOrCreate(['user_id' => $driver->id], ['license_number' => 'L-123', 'verification_status' => 'approved', 'verified_at' => now()]);
|
|
HelperProfile::updateOrCreate(['user_id' => $helper->id], ['verification_status' => 'approved', 'verified_at' => now()]);
|
|
ScannerProfile::updateOrCreate(['user_id' => $scanner->id], ['verification_status' => 'approved', 'verified_at' => now()]);
|
|
|
|
// 5. Assets (Truck, Team)
|
|
$truck = Truck::firstOrCreate(
|
|
['plate_number' => 'VRD-777'],
|
|
[
|
|
'uuid' => (string) Str::uuid(),
|
|
'tenant_id' => $tenant->id,
|
|
'model' => 'Isuzu Elf',
|
|
'capacity_kg' => 3000,
|
|
'status' => Truck::STATUS_ACTIVE,
|
|
]
|
|
);
|
|
|
|
$team = CollectionTeam::firstOrCreate(
|
|
['name' => 'Morning Crew'],
|
|
[
|
|
'uuid' => (string) Str::uuid(),
|
|
'tenant_id' => $tenant->id,
|
|
'driver_id' => $driver->id,
|
|
'scanner_id' => $scanner->id,
|
|
'truck_id' => $truck->id,
|
|
'status' => CollectionTeam::STATUS_ACTIVE,
|
|
]
|
|
);
|
|
TeamMember::updateOrCreate(['team_id' => $team->id, 'user_id' => $helper->id], ['role_in_team' => 'helper']);
|
|
|
|
// 6. Route & Trip
|
|
$route = CollectionRoute::firstOrCreate(
|
|
['code' => 'RT-001'],
|
|
[
|
|
'uuid' => (string) Str::uuid(),
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Main City Route',
|
|
'default_dumpsite_id' => $dumpsite->id,
|
|
'default_team_id' => $team->id,
|
|
'status' => CollectionRoute::STATUS_ACTIVE,
|
|
]
|
|
);
|
|
RouteStop::updateOrCreate(['route_id' => $route->id, 'drop_off_point_id' => $dop->id], ['sequence' => 1, 'estimated_duration_at_stop_minutes' => 15]);
|
|
|
|
$trip = Trip::create([
|
|
'uuid' => (string) Str::uuid(),
|
|
'tenant_id' => $tenant->id,
|
|
'trip_number' => 'TRIP-' . date('Ymd') . '-001',
|
|
'route_id' => $route->id,
|
|
'team_id' => $team->id,
|
|
'truck_id' => $truck->id,
|
|
'dumpsite_id' => $dumpsite->id,
|
|
'scheduled_date' => date('Y-m-d'),
|
|
'status' => Trip::STATUS_SCHEDULED,
|
|
]);
|
|
TripStop::create(['trip_id' => $trip->id, 'drop_off_point_id' => $dop->id, 'sequence' => 1, 'status' => 'pending', 'total_scans' => 0, 'estimated_load_added_kg' => 0]);
|
|
|
|
// 7. Store
|
|
$storeOwner = $this->createStaff('store@verde.local', '+639190000001', 'Sari', 'Store', User::ROLE_STORE_PARTNER, $tenant, $password);
|
|
StorePartnerProfile::updateOrCreate(['user_id' => $storeOwner->id], ['business_name' => 'Verde Express Store', 'verification_status' => 'approved', 'verified_at' => now()]);
|
|
|
|
$store = PartnerStore::firstOrCreate(
|
|
['owner_user_id' => $storeOwner->id],
|
|
[
|
|
'uuid' => (string) Str::uuid(),
|
|
'tenant_id' => $tenant->id,
|
|
'business_name' => 'Verde Express Store',
|
|
'business_permit_number' => 'BP-12345',
|
|
'address_line' => 'Market Road',
|
|
'barangay_id' => $barangay->id,
|
|
'coordinates' => new Point(14.651, 121.061),
|
|
'status' => PartnerStore::STATUS_ACTIVE,
|
|
]
|
|
);
|
|
StoreInventory::updateOrCreate(['store_id' => $store->id], ['current_code_balance' => 100]);
|
|
}
|
|
|
|
private function createStaff($email, $phone, $first, $last, $role, $tenant, $password): User
|
|
{
|
|
$u = User::firstOrCreate(
|
|
['email' => $email],
|
|
[
|
|
'phone' => $phone,
|
|
'password' => $password,
|
|
'first_name' => $first,
|
|
'last_name' => $last,
|
|
'role' => $role,
|
|
'status' => User::STATUS_ACTIVE,
|
|
'tenant_id' => $tenant->id,
|
|
'email_verified_at' => now(),
|
|
]
|
|
);
|
|
$u->syncRoles([$role]);
|
|
NotificationPreference::firstOrCreate(['user_id' => $u->id]);
|
|
return $u;
|
|
}
|
|
}
|