diff --git a/app/Policies/StoreSalePolicy.php b/app/Policies/StoreSalePolicy.php index 79123fe..6daa01a 100644 --- a/app/Policies/StoreSalePolicy.php +++ b/app/Policies/StoreSalePolicy.php @@ -4,7 +4,6 @@ namespace App\Policies; use App\Models\StoreSale; use App\Models\User; -use Illuminate\Auth\Access\Response; class StoreSalePolicy { diff --git a/app/Services/Qr/BatchGenerator.php b/app/Services/Qr/BatchGenerator.php index 9de28e0..8f7a3c1 100644 --- a/app/Services/Qr/BatchGenerator.php +++ b/app/Services/Qr/BatchGenerator.php @@ -2,12 +2,14 @@ namespace App\Services\Qr; +use App\Models\Household; +use App\Models\PartnerStore; use App\Models\QrCode; use App\Models\QrCodeBatch; use App\Models\ServiceArea; use App\Models\User; -use App\States\QrCode\Unassigned; use App\States\QrCode\Active; +use App\States\QrCode\Unassigned; use App\Tenancy\Tenancy; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; @@ -40,11 +42,11 @@ class BatchGenerator ) { $tenantId = null; if ($householdId) { - $tenantId = \App\Models\Household::find($householdId)?->tenant_id; + $tenantId = Household::find($householdId)?->tenant_id; } elseif ($targetArea) { $tenantId = $targetArea->tenant_id; } elseif ($targetStoreId) { - $tenantId = \App\Models\PartnerStore::find($targetStoreId)?->tenant_id; + $tenantId = PartnerStore::find($targetStoreId)?->tenant_id; } if (empty($tenantId)) { diff --git a/app/Services/Qr/QrAllocator.php b/app/Services/Qr/QrAllocator.php index 9d183fd..91d1bcd 100644 --- a/app/Services/Qr/QrAllocator.php +++ b/app/Services/Qr/QrAllocator.php @@ -196,16 +196,16 @@ class QrAllocator } $now = now(); - + // Update the QR codes QrCode::whereIn('id', $eligibleCodeIds)->update([ 'status' => Active::$name, 'assigned_to_household_id' => $household->id, - 'allocated_at' => DB::raw('COALESCE(allocated_at, "' . $now . '")'), + 'allocated_at' => DB::raw('COALESCE(allocated_at, "'.$now.'")'), 'activated_at' => $now, 'updated_at' => $now, ]); - + // If the batch itself wasn't assigned to this household, update it if ($batch->household_id === null) { $batch->update([ diff --git a/app/Services/Store/StoreOperations.php b/app/Services/Store/StoreOperations.php index c3e6027..f51cde1 100644 --- a/app/Services/Store/StoreOperations.php +++ b/app/Services/Store/StoreOperations.php @@ -7,6 +7,7 @@ use App\Models\PartnerStore; use App\Models\QrCode; use App\Models\QrCodeBatch; use App\Models\StoreInventory; +use App\Models\StoreInventoryAdjustment; use App\Models\StorePurchase; use App\Models\StoreSale; use App\Models\StoreSettlement; @@ -16,7 +17,6 @@ use App\Services\Qr\BatchGenerator; use App\States\QrCode\Active; use App\States\QrCode\Allocated; use App\States\QrCode\Unassigned; -use App\Models\StoreInventoryAdjustment; use App\States\QrCode\Voided; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Notification; @@ -68,7 +68,7 @@ class StoreOperations 'is_prepaid' => $isPrepaid, ]); - $this->logAdjustment($store, StoreInventoryAdjustment::TYPE_PURCHASE, $quantity, null, "Wholesale purchase: Batch #{$batch->batch_number}" . ($isPrepaid ? ' (Prepaid)' : ''), $userId); + $this->logAdjustment($store, StoreInventoryAdjustment::TYPE_PURCHASE, $quantity, null, "Wholesale purchase: Batch #{$batch->batch_number}".($isPrepaid ? ' (Prepaid)' : ''), $userId); $this->updateBalance($store, $quantity, $isPrepaid); return $purchase; @@ -130,7 +130,7 @@ class StoreOperations 'is_prepaid' => $usePrepaid, ]); - $this->logAdjustment($store, StoreInventoryAdjustment::TYPE_SALE, -$quantity, null, "Sold to Household #{$household->id}" . ($usePrepaid ? ' (Prepaid)' : ''), null); + $this->logAdjustment($store, StoreInventoryAdjustment::TYPE_SALE, -$quantity, null, "Sold to Household #{$household->id}".($usePrepaid ? ' (Prepaid)' : ''), null); $this->updateBalance($store, -$quantity, $usePrepaid); // Notify the household head — fire after commit so the receiver @@ -159,7 +159,7 @@ class StoreOperations ->lockForUpdate() ->first(); - if (!$qrCode) { + if (! $qrCode) { throw new \DomainException("QR code {$serial} not found in store inventory or already used."); } @@ -233,7 +233,7 @@ class StoreOperations $netPayable = $store->sales() ->where('is_prepaid', false) ->sum(DB::raw('retail_price_centavos - commission_centavos')); - + $totalPaid = $store->settlements()->sum('amount_centavos'); return max(0, (int) $netPayable - (int) $totalPaid); @@ -258,7 +258,7 @@ class StoreOperations 'quantity' => $quantity, 'qr_code_id' => $qrCodeId, 'reason' => $reason, - 'adjusted_by_user_id' => $userId instanceof \App\Models\User ? $userId->id : $userId, + 'adjusted_by_user_id' => $userId instanceof User ? $userId->id : $userId, ]); } @@ -266,7 +266,7 @@ class StoreOperations { $inventory = StoreInventory::firstOrCreate(['store_id' => $store->id], [ 'current_code_balance' => 0, - 'prepaid_balance' => 0 + 'prepaid_balance' => 0, ]); if ($isPrepaid) { diff --git a/database/factories/QrCodeBatchFactory.php b/database/factories/QrCodeBatchFactory.php index 7145427..7f87d0a 100644 --- a/database/factories/QrCodeBatchFactory.php +++ b/database/factories/QrCodeBatchFactory.php @@ -3,8 +3,9 @@ namespace Database\Factories; use App\Models\QrCodeBatch; +use App\Models\Tenant; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Str; class QrCodeBatchFactory extends Factory { @@ -13,11 +14,11 @@ class QrCodeBatchFactory extends Factory public function definition(): array { return [ - 'tenant_id' => \App\Models\Tenant::factory(), + 'tenant_id' => Tenant::factory(), 'batch_number' => (string) rand(1000, 9999), 'quantity' => 100, 'purpose' => 'store_inventory', - 'created_by_admin_id' => \App\Models\User::factory(), + 'created_by_admin_id' => User::factory(), ]; } } diff --git a/database/factories/QrCodeFactory.php b/database/factories/QrCodeFactory.php index 03d8c81..40334b0 100644 --- a/database/factories/QrCodeFactory.php +++ b/database/factories/QrCodeFactory.php @@ -4,6 +4,7 @@ namespace Database\Factories; use App\Models\QrCode; use App\Models\QrCodeBatch; +use App\Models\Tenant; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; @@ -13,9 +14,10 @@ class QrCodeFactory extends Factory public function definition(): array { - $serial = 'VERDE-' . strtoupper(Str::random(4)) . '-' . strtoupper(Str::random(4)); + $serial = 'VERDE-'.strtoupper(Str::random(4)).'-'.strtoupper(Str::random(4)); + return [ - 'tenant_id' => \App\Models\Tenant::factory(), + 'tenant_id' => Tenant::factory(), 'serial' => $serial, 'barcode_value' => $serial, 'batch_id' => QrCodeBatch::factory(), diff --git a/database/factories/TenantFactory.php b/database/factories/TenantFactory.php index 3322fd6..a9a2402 100644 --- a/database/factories/TenantFactory.php +++ b/database/factories/TenantFactory.php @@ -14,7 +14,7 @@ class TenantFactory extends Factory { return [ 'uuid' => (string) Str::uuid(), - 'code' => 'T' . rand(100, 999), + 'code' => 'T'.rand(100, 999), 'name' => $this->faker->company(), 'timezone' => 'Asia/Manila', 'theme_color' => '#10B981', diff --git a/database/migrations/2026_07_02_114152_update_collection_teams_status_enum.php b/database/migrations/2026_07_02_114152_update_collection_teams_status_enum.php index 22f01c5..13005d1 100644 --- a/database/migrations/2026_07_02_114152_update_collection_teams_status_enum.php +++ b/database/migrations/2026_07_02_114152_update_collection_teams_status_enum.php @@ -1,8 +1,6 @@ prefix('me')->name('api.v1.me.')->group(funct Route::post('/notifications/mark-all-read', [MyNotificationsController::class, 'markAllRead'])->name('notifications.mark-all-read'); Route::post('/notifications/{id}/read', [MyNotificationsController::class, 'markRead'])->name('notifications.mark-read'); - Route::get('/sales', [\App\Http\Controllers\Api\V1\Me\MySalesController::class, 'index'])->name('sales.index'); - Route::get('/sales/{sale}/receipt', [\App\Http\Controllers\Api\V1\Me\MySalesController::class, 'downloadReceipt'])->name('sales.receipt'); + Route::get('/sales', [MySalesController::class, 'index'])->name('sales.index'); + Route::get('/sales/{sale}/receipt', [MySalesController::class, 'downloadReceipt'])->name('sales.receipt'); Route::get('/live/trucks', [MyLiveTrucksController::class, 'trucks'])->name('live.trucks'); }); @@ -135,8 +137,8 @@ Route::get('/tenants/lookup', [TenantLookupController::class, 'lookup'])->name(' // Driver telemetry Route::middleware(['auth:sanctum', 'role:driver'])->prefix('driver')->name('api.v1.driver.')->group(function () { Route::post('/trucks/{truck}/location', [DriverLocationController::class, 'store'])->name('trucks.location'); - Route::post('/trips/{trip}/detour', [\App\Http\Controllers\Api\V1\Driver\TripDetourController::class, 'start'])->name('trips.detour.start'); - Route::post('/trips/{trip}/resume', [\App\Http\Controllers\Api\V1\Driver\TripDetourController::class, 'resume'])->name('trips.detour.resume'); + Route::post('/trips/{trip}/detour', [TripDetourController::class, 'start'])->name('trips.detour.start'); + Route::post('/trips/{trip}/resume', [TripDetourController::class, 'resume'])->name('trips.detour.resume'); }); // Store Portal diff --git a/routes/web.php b/routes/web.php index 443c3d1..8a0c937 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ group(function () { }); Route::prefix('store')->name('store.')->group(function () { - Route::get('/dashboard', [\App\Http\Controllers\Store\StoreDashboardController::class, 'index'])->name('dashboard'); - Route::get('/sales', [\App\Http\Controllers\Store\StoreDashboardController::class, 'sales'])->name('sales'); - Route::get('/inventory', [\App\Http\Controllers\Store\StoreDashboardController::class, 'inventory'])->name('inventory'); - Route::get('/financials', [\App\Http\Controllers\Store\StoreDashboardController::class, 'financials'])->name('financials'); + Route::get('/dashboard', [StoreDashboardController::class, 'index'])->name('dashboard'); + Route::get('/sales', [StoreDashboardController::class, 'sales'])->name('sales'); + Route::get('/inventory', [StoreDashboardController::class, 'inventory'])->name('inventory'); + Route::get('/financials', [StoreDashboardController::class, 'financials'])->name('financials'); }); diff --git a/test.php b/test.php index f6f90aa..2d40256 100644 --- a/test.php +++ b/test.php @@ -1 +1,9 @@ -make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); dump(App\Models\Household::all()->toArray()); +make(Kernel::class)->bootstrap(); +dump(Household::all()->toArray()); diff --git a/test_household.php b/test_household.php index 60e715c..95e09f1 100644 --- a/test_household.php +++ b/test_household.php @@ -1 +1,15 @@ -make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); $req = Illuminate\Http\Request::create('/api/v1/me/household', 'GET'); $req->setUserResolver(function() { return App\Models\User::find(6); }); dump(app()->make(App\Http\Controllers\Api\V1\Me\MyHouseholdController::class)->show($req)->getContent()); +make(Kernel::class)->bootstrap(); +$req = Request::create('/api/v1/me/household', 'GET'); +$req->setUserResolver(function () { + return User::find(6); +}); +dump(app()->make(MyHouseholdController::class)->show($req)->getContent()); diff --git a/test_users.php b/test_users.php index 4487bdd..68ad789 100644 --- a/test_users.php +++ b/test_users.php @@ -1 +1,9 @@ -make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); dump(App\Models\User::where('first_name', 'Juan')->get(['id', 'email', 'tenant_id'])->toArray()); +make(Kernel::class)->bootstrap(); +dump(User::where('first_name', 'Juan')->get(['id', 'email', 'tenant_id'])->toArray()); diff --git a/tests/Feature/Api/V1/Admin/AdminTruckCrudTest.php b/tests/Feature/Api/V1/Admin/AdminTruckCrudTest.php index cfe46a8..2e16fb7 100644 --- a/tests/Feature/Api/V1/Admin/AdminTruckCrudTest.php +++ b/tests/Feature/Api/V1/Admin/AdminTruckCrudTest.php @@ -3,12 +3,15 @@ namespace Tests\Feature\Api\V1\Admin; use App\Models\CollectionTeam; +use App\Models\Dumpsite; +use App\Models\Route; use App\Models\Trip; use App\Models\Truck; use App\Models\User; use Database\Seeders\RoleSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Laravel\Sanctum\Sanctum; +use MatanYadaev\EloquentSpatial\Objects\Point; use Tests\TestCase; class AdminTruckCrudTest extends TestCase @@ -96,15 +99,15 @@ class AdminTruckCrudTest extends TestCase $truck->update(['assigned_team_id' => $team->id]); - $dumpsite = \App\Models\Dumpsite::create([ + $dumpsite = Dumpsite::create([ 'name' => 'Dumpsite A', 'code' => 'DS-A', 'address_line' => 'Test Address', - 'coordinates' => new \MatanYadaev\EloquentSpatial\Objects\Point(14.7155, 121.1083, 4326), - 'status' => \App\Models\Dumpsite::STATUS_ACTIVE, + 'coordinates' => new Point(14.7155, 121.1083, 4326), + 'status' => Dumpsite::STATUS_ACTIVE, ]); - $route = \App\Models\Route::create([ + $route = Route::create([ 'name' => 'Route A', 'code' => 'RT-A', 'default_dumpsite_id' => $dumpsite->id, diff --git a/tests/Feature/Api/V1/Admin/AdminUserCrudTest.php b/tests/Feature/Api/V1/Admin/AdminUserCrudTest.php index 7f9c882..0e93d3f 100644 --- a/tests/Feature/Api/V1/Admin/AdminUserCrudTest.php +++ b/tests/Feature/Api/V1/Admin/AdminUserCrudTest.php @@ -2,12 +2,17 @@ namespace Tests\Feature\Api\V1\Admin; +use App\Models\Barangay; use App\Models\DriverProfile; +use App\Models\Household; +use App\Models\HouseholdMember; use App\Models\ResidentProfile; use App\Models\User; use Database\Seeders\RoleSeeder; +use Database\Seeders\SamplePsgcSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Laravel\Sanctum\Sanctum; +use MatanYadaev\EloquentSpatial\Objects\Point; use Tests\TestCase; class AdminUserCrudTest extends TestCase @@ -192,14 +197,14 @@ class AdminUserCrudTest extends TestCase ->assertStatus(422) ->assertJsonFragment(['message' => 'Resident household must have coordinates pinned before activation']); - $household = \App\Models\Household::factory()->create([ + $household = Household::factory()->create([ 'head_user_id' => $resident->id, - 'coordinates' => new \MatanYadaev\EloquentSpatial\Objects\Point(14.5995, 120.9842, 4326), + 'coordinates' => new Point(14.5995, 120.9842, 4326), ]); - \App\Models\HouseholdMember::create([ + HouseholdMember::create([ 'household_id' => $household->id, 'user_id' => $resident->id, - 'relationship' => \App\Models\HouseholdMember::RELATIONSHIP_HEAD, + 'relationship' => HouseholdMember::RELATIONSHIP_HEAD, 'full_name' => $resident->full_name, ]); @@ -217,7 +222,7 @@ class AdminUserCrudTest extends TestCase 'status' => User::STATUS_PENDING, ]); - $household = \App\Models\Household::factory()->create(); + $household = Household::factory()->create(); $response = $this->postJson("/api/v1/admin/users/{$resident->uuid}/group-into-household", [ 'household_id' => $household->id, @@ -229,15 +234,15 @@ class AdminUserCrudTest extends TestCase $this->assertDatabaseHas('household_members', [ 'household_id' => $household->id, 'user_id' => $resident->id, - 'relationship' => \App\Models\HouseholdMember::RELATIONSHIP_OTHER, + 'relationship' => HouseholdMember::RELATIONSHIP_OTHER, ]); } public function test_admin_can_group_resident_into_new_household(): void { Sanctum::actingAs($this->admin); - $this->seed(\Database\Seeders\SamplePsgcSeeder::class); - $barangay = \App\Models\Barangay::firstOrFail(); + $this->seed(SamplePsgcSeeder::class); + $barangay = Barangay::firstOrFail(); $resident = User::factory()->create([ 'role' => User::ROLE_RESIDENT, @@ -264,7 +269,7 @@ class AdminUserCrudTest extends TestCase $this->assertDatabaseHas('household_members', [ 'user_id' => $resident->id, - 'relationship' => \App\Models\HouseholdMember::RELATIONSHIP_HEAD, + 'relationship' => HouseholdMember::RELATIONSHIP_HEAD, ]); } @@ -277,18 +282,18 @@ class AdminUserCrudTest extends TestCase 'status' => User::STATUS_ACTIVE, ]); - $oldHousehold = \App\Models\Household::factory()->create([ + $oldHousehold = Household::factory()->create([ 'head_user_id' => $resident->id, ]); - $oldMember = \App\Models\HouseholdMember::create([ + $oldMember = HouseholdMember::create([ 'household_id' => $oldHousehold->id, 'user_id' => $resident->id, - 'relationship' => \App\Models\HouseholdMember::RELATIONSHIP_HEAD, + 'relationship' => HouseholdMember::RELATIONSHIP_HEAD, 'full_name' => $resident->full_name, ]); - $newHousehold = \App\Models\Household::factory()->create(); + $newHousehold = Household::factory()->create(); $response = $this->postJson("/api/v1/admin/users/{$resident->uuid}/group-into-household", [ 'household_id' => $newHousehold->id, @@ -300,7 +305,7 @@ class AdminUserCrudTest extends TestCase $this->assertDatabaseHas('household_members', [ 'household_id' => $newHousehold->id, 'user_id' => $resident->id, - 'relationship' => \App\Models\HouseholdMember::RELATIONSHIP_OTHER, + 'relationship' => HouseholdMember::RELATIONSHIP_OTHER, ]); // Check old membership deleted diff --git a/tests/Feature/Api/V1/Auth/EmailVerificationTest.php b/tests/Feature/Api/V1/Auth/EmailVerificationTest.php index 2ac5294..b53705e 100644 --- a/tests/Feature/Api/V1/Auth/EmailVerificationTest.php +++ b/tests/Feature/Api/V1/Auth/EmailVerificationTest.php @@ -2,11 +2,13 @@ namespace Tests\Feature\Api\V1\Auth; +use App\Models\Barangay; use App\Models\User; use App\Notifications\VerifyEmailNotification; use App\Services\Sms\FakeSmsService; use App\Services\Sms\SmsService; use Database\Seeders\RoleSeeder; +use Database\Seeders\SamplePsgcSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\URL; @@ -20,14 +22,14 @@ class EmailVerificationTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->seed([RoleSeeder::class, \Database\Seeders\SamplePsgcSeeder::class]); + $this->seed([RoleSeeder::class, SamplePsgcSeeder::class]); $this->app->instance(SmsService::class, new FakeSmsService); } public function test_register_sends_verification_email(): void { Notification::fake(); - $barangay = \App\Models\Barangay::firstOrFail(); + $barangay = Barangay::firstOrFail(); $this->postJson('/api/v1/auth/register', [ 'first_name' => 'Em', 'last_name' => 'Ail', diff --git a/tests/Feature/Api/V1/Auth/RegisterTest.php b/tests/Feature/Api/V1/Auth/RegisterTest.php index 01636b3..6eed6f5 100644 --- a/tests/Feature/Api/V1/Auth/RegisterTest.php +++ b/tests/Feature/Api/V1/Auth/RegisterTest.php @@ -2,11 +2,13 @@ namespace Tests\Feature\Api\V1\Auth; +use App\Models\Barangay; use App\Models\OtpCode; use App\Models\User; use App\Services\Sms\FakeSmsService; use App\Services\Sms\SmsService; use Database\Seeders\RoleSeeder; +use Database\Seeders\SamplePsgcSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -15,15 +17,16 @@ class RegisterTest extends TestCase use RefreshDatabase; private FakeSmsService $fakeSms; - private \App\Models\Barangay $barangay; + + private Barangay $barangay; protected function setUp(): void { parent::setUp(); - $this->seed([RoleSeeder::class, \Database\Seeders\SamplePsgcSeeder::class]); + $this->seed([RoleSeeder::class, SamplePsgcSeeder::class]); $this->fakeSms = new FakeSmsService; $this->app->instance(SmsService::class, $this->fakeSms); - $this->barangay = \App\Models\Barangay::firstOrFail(); + $this->barangay = Barangay::firstOrFail(); } public function test_resident_can_register(): void diff --git a/tests/Feature/Api/V1/DropOff/DropOffPointTest.php b/tests/Feature/Api/V1/DropOff/DropOffPointTest.php index 66840ed..6d112d3 100644 --- a/tests/Feature/Api/V1/DropOff/DropOffPointTest.php +++ b/tests/Feature/Api/V1/DropOff/DropOffPointTest.php @@ -3,12 +3,14 @@ namespace Tests\Feature\Api\V1\DropOff; use App\Models\DropOffPoint; +use App\Models\Household; use App\Models\User; use Database\Seeders\RoleSeeder; use Database\Seeders\SampleDropOffPointsSeeder; use Database\Seeders\SamplePsgcSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Laravel\Sanctum\Sanctum; +use MatanYadaev\EloquentSpatial\Objects\Point; use Tests\TestCase; class DropOffPointTest extends TestCase @@ -160,12 +162,12 @@ class DropOffPointTest extends TestCase $dop1 = DropOffPoint::where('status', DropOffPoint::STATUS_ACTIVE)->first(); - $household = \App\Models\Household::create([ + $household = Household::create([ 'tenant_id' => $dop1->tenant_id, 'head_user_id' => User::factory()->create()->id, 'barangay_id' => $dop1->barangay_id, 'address_line' => '123 Test St', - 'coordinates' => new \MatanYadaev\EloquentSpatial\Objects\Point(14.6539, 121.0685, 4326), + 'coordinates' => new Point(14.6539, 121.0685, 4326), 'household_size' => 3, 'assigned_drop_off_point_id' => $dop1->id, 'verification_status' => 'approved', diff --git a/tests/Feature/Api/V1/Dumpsite/DumpsiteCrudTest.php b/tests/Feature/Api/V1/Dumpsite/DumpsiteCrudTest.php index 103342c..637c4fa 100644 --- a/tests/Feature/Api/V1/Dumpsite/DumpsiteCrudTest.php +++ b/tests/Feature/Api/V1/Dumpsite/DumpsiteCrudTest.php @@ -2,7 +2,12 @@ namespace Tests\Feature\Api\V1\Dumpsite; +use App\Models\CollectionTeam; use App\Models\Dumpsite; +use App\Models\Route; +use App\Models\Tenant; +use App\Models\Trip; +use App\Models\Truck; use App\Models\User; use Database\Seeders\RoleSeeder; use Database\Seeders\SamplePsgcSeeder; @@ -172,26 +177,26 @@ class DumpsiteCrudTest extends TestCase { Sanctum::actingAs($this->admin); - $tenantId = $this->admin->tenant_id ?? \App\Models\Tenant::value('id'); + $tenantId = $this->admin->tenant_id ?? Tenant::value('id'); $dumpsite = Dumpsite::factory()->create([ 'status' => Dumpsite::STATUS_ACTIVE, ]); - $route = \App\Models\Route::create([ + $route = Route::create([ 'tenant_id' => $tenantId, 'name' => 'Route A', 'code' => 'R-A', 'status' => 'active', ]); - $team = \App\Models\CollectionTeam::create([ + $team = CollectionTeam::create([ 'tenant_id' => $tenantId, 'name' => 'Team A', 'status' => 'active', ]); - $truck = \App\Models\Truck::create([ + $truck = Truck::create([ 'tenant_id' => $tenantId, 'plate_number' => 'XYZ-123', 'brand' => 'Isz', @@ -201,24 +206,24 @@ class DumpsiteCrudTest extends TestCase 'status' => 'active', ]); - $trip1 = \App\Models\Trip::create([ + $trip1 = Trip::create([ 'trip_number' => 'TRIP-DS-1', 'route_id' => $route->id, 'team_id' => $team->id, 'truck_id' => $truck->id, 'dumpsite_id' => $dumpsite->id, 'scheduled_date' => now()->toDateString(), - 'status' => \App\Models\Trip::STATUS_IN_PROGRESS, + 'status' => Trip::STATUS_IN_PROGRESS, ]); - $trip2 = \App\Models\Trip::create([ + $trip2 = Trip::create([ 'trip_number' => 'TRIP-DS-2', 'route_id' => $route->id, 'team_id' => $team->id, 'truck_id' => $truck->id, 'dumpsite_id' => $dumpsite->id, 'scheduled_date' => now()->toDateString(), - 'status' => \App\Models\Trip::STATUS_COMPLETED, + 'status' => Trip::STATUS_COMPLETED, ]); $response = $this->patchJson("/api/v1/admin/dumpsites/{$dumpsite->uuid}", [ @@ -230,8 +235,8 @@ class DumpsiteCrudTest extends TestCase $trip1->refresh(); $trip2->refresh(); - $this->assertEquals(\App\Models\Trip::STATUS_CANCELLED, $trip1->status); + $this->assertEquals(Trip::STATUS_CANCELLED, $trip1->status); $this->assertStringContainsString('System: Trip cancelled because the dumpsite was moved to maintenance status', $trip1->notes); - $this->assertEquals(\App\Models\Trip::STATUS_COMPLETED, $trip2->status); + $this->assertEquals(Trip::STATUS_COMPLETED, $trip2->status); } } diff --git a/tests/Feature/Api/V1/Helper/HelperAssignmentTest.php b/tests/Feature/Api/V1/Helper/HelperAssignmentTest.php index 13c2c15..493c3db 100644 --- a/tests/Feature/Api/V1/Helper/HelperAssignmentTest.php +++ b/tests/Feature/Api/V1/Helper/HelperAssignmentTest.php @@ -15,6 +15,7 @@ class HelperAssignmentTest extends TestCase use RefreshDatabase; private User $helper; + private CollectionTeam $team; protected function setUp(): void diff --git a/tests/Feature/Api/V1/Household/HouseholdProofTest.php b/tests/Feature/Api/V1/Household/HouseholdProofTest.php index 566d52c..3f5e3e3 100644 --- a/tests/Feature/Api/V1/Household/HouseholdProofTest.php +++ b/tests/Feature/Api/V1/Household/HouseholdProofTest.php @@ -3,7 +3,6 @@ namespace Tests\Feature\Api\V1\Household; use App\Models\Household; -use App\Models\Tenant; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\UploadedFile; @@ -15,12 +14,13 @@ class HouseholdProofTest extends TestCase use RefreshDatabase; private User $user; + private Household $household; protected function setUp(): void { parent::setUp(); - + $this->user = User::factory()->create(['role' => User::ROLE_RESIDENT]); $this->household = Household::factory()->create([ 'head_user_id' => $this->user->id, @@ -31,7 +31,7 @@ class HouseholdProofTest extends TestCase public function test_it_allows_head_of_household_to_upload_proof() { Storage::fake('local'); - + $file = UploadedFile::fake()->create('bill.jpg', 100, 'image/jpeg'); $response = $this->actingAs($this->user) @@ -41,7 +41,7 @@ class HouseholdProofTest extends TestCase $response->assertStatus(200); $response->assertJsonPath('success', true); - + $this->household->refresh(); $this->assertNotNull($this->household->proof_of_residency_path); Storage::disk('local')->assertExists($this->household->proof_of_residency_path); @@ -50,7 +50,7 @@ class HouseholdProofTest extends TestCase public function test_it_rejects_invalid_file_types() { Storage::fake('local'); - + $file = UploadedFile::fake()->create('malware.exe', 100, 'application/x-msdownload'); $response = $this->actingAs($this->user) @@ -65,7 +65,7 @@ class HouseholdProofTest extends TestCase public function test_it_rejects_files_over_8mb() { Storage::fake('local'); - + // 8MB = 8192 KB, so let's make it 8193 KB $file = UploadedFile::fake()->create('huge.jpg', 8193, 'image/jpeg'); @@ -81,10 +81,10 @@ class HouseholdProofTest extends TestCase public function test_it_prevents_unauthorized_users_from_uploading_proof() { Storage::fake('local'); - + // Create another user $otherUser = User::factory()->create(['role' => User::ROLE_RESIDENT]); - + $file = UploadedFile::fake()->create('bill.jpg', 100, 'image/jpeg'); $response = $this->actingAs($otherUser) @@ -99,12 +99,12 @@ class HouseholdProofTest extends TestCase public function test_it_resets_rejection_status_when_new_proof_uploaded() { Storage::fake('local'); - + $this->household->update([ 'verification_status' => Household::VERIFICATION_REJECTED, 'rejection_reason' => 'Blurry photo', ]); - + $file = UploadedFile::fake()->create('clear_bill.jpg', 100, 'image/jpeg'); $response = $this->actingAs($this->user) @@ -113,7 +113,7 @@ class HouseholdProofTest extends TestCase ]); $response->assertStatus(200); - + $this->household->refresh(); $this->assertEquals(Household::VERIFICATION_PENDING, $this->household->verification_status); $this->assertNull($this->household->rejection_reason); diff --git a/tests/Feature/Api/V1/Me/MySalesControllerTest.php b/tests/Feature/Api/V1/Me/MySalesControllerTest.php index c6257c0..8c82e77 100644 --- a/tests/Feature/Api/V1/Me/MySalesControllerTest.php +++ b/tests/Feature/Api/V1/Me/MySalesControllerTest.php @@ -24,12 +24,12 @@ class MySalesControllerTest extends TestCase $user = User::factory()->create(['role' => 'resident']); $household = Household::factory()->create(['head_user_id' => $user->id]); $store = PartnerStore::factory()->create(); - + StoreSale::factory()->count(3)->create([ 'household_id' => $household->id, 'store_id' => $store->id, 'retail_price_centavos' => 2500, - 'quantity' => 1 + 'quantity' => 1, ]); $response = $this->actingAs($user) @@ -37,7 +37,7 @@ class MySalesControllerTest extends TestCase $response->assertOk() ->assertJsonCount(3, 'data'); - + $this->assertNotNull($response->json('data.0.receipt_url')); } @@ -48,7 +48,7 @@ class MySalesControllerTest extends TestCase $store = PartnerStore::factory()->create(); $sale = StoreSale::factory()->create([ 'household_id' => $household->id, - 'store_id' => $store->id + 'store_id' => $store->id, ]); $response = $this->actingAs($user) @@ -62,14 +62,14 @@ class MySalesControllerTest extends TestCase { $user1 = User::factory()->create(['role' => 'resident']); $household1 = Household::factory()->create(['head_user_id' => $user1->id]); - + $user2 = User::factory()->create(['role' => 'resident']); $household2 = Household::factory()->create(['head_user_id' => $user2->id]); - + $store = PartnerStore::factory()->create(); $saleOfUser2 = StoreSale::factory()->create([ 'household_id' => $household2->id, - 'store_id' => $store->id + 'store_id' => $store->id, ]); $response = $this->actingAs($user1) diff --git a/tests/Feature/Api/V1/Store/PartnerStoreSettlementTest.php b/tests/Feature/Api/V1/Store/PartnerStoreSettlementTest.php index 854851e..68ad19c 100644 --- a/tests/Feature/Api/V1/Store/PartnerStoreSettlementTest.php +++ b/tests/Feature/Api/V1/Store/PartnerStoreSettlementTest.php @@ -4,9 +4,7 @@ namespace Tests\Feature\Api\V1\Store; use App\Models\PartnerStore; use App\Models\QrCode; -use App\Models\QrCodeBatch; use App\Models\StoreSale; -use App\Models\Tenant; use App\Models\User; use App\Services\Store\StoreOperations; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -17,7 +15,9 @@ class PartnerStoreSettlementTest extends TestCase use RefreshDatabase; protected User $admin; + protected PartnerStore $store; + protected StoreOperations $ops; protected function setUp(): void @@ -38,7 +38,7 @@ class PartnerStoreSettlementTest extends TestCase public function test_calculate_balance_due_consignment_model() { // 1. Issue inventory (already in setup) - + // 2. Record sales (Retail Price 100, Commission 10%) // Total Sold: 2 codes @ 100 each = 200 Gross // Commission: 10% of 200 = 20 @@ -46,7 +46,7 @@ class PartnerStoreSettlementTest extends TestCase StoreSale::factory()->count(2)->create([ 'store_id' => $this->store->id, 'retail_price_centavos' => 10000, - 'commission_centavos' => 1000 + 'commission_centavos' => 1000, ]); $balance = $this->ops->calculateBalanceDue($this->store); @@ -57,9 +57,9 @@ class PartnerStoreSettlementTest extends TestCase ->postJson("/api/v1/admin/partner-stores/{$this->store->uuid}/settle", [ 'amount_pesos' => 100, 'payment_method' => 'cash', - 'reference_number' => 'REF123' - ]); - $response->assertSuccessful(); + 'reference_number' => 'REF123', + ]) + ->assertSuccessful(); // 4. Check new balance: 180 - 100 = 80 $newBalance = $this->ops->calculateBalanceDue($this->store); @@ -72,7 +72,7 @@ class PartnerStoreSettlementTest extends TestCase $qr = QrCode::factory()->create([ 'tenant_id' => $this->defaultTenant->id, 'assigned_to_store_id' => $this->store->id, - 'status' => 'allocated' + 'status' => 'allocated', ]); \App\Models\StoreInventory::create([ @@ -84,7 +84,7 @@ class PartnerStoreSettlementTest extends TestCase $this->actingAs($this->admin) ->postJson("/api/v1/admin/partner-stores/{$this->store->uuid}/report-issue", [ 'serial' => $qr->serial, - 'reason' => 'Defective Adhesive' + 'reason' => 'Defective Adhesive', ]) ->assertSuccessful(); @@ -108,14 +108,14 @@ class PartnerStoreSettlementTest extends TestCase $qr = QrCode::factory()->create([ 'tenant_id' => $this->defaultTenant->id, 'assigned_to_store_id' => $this->store->id, - 'status' => 'voided' + 'status' => 'voided', ]); - + $replacement = QrCode::factory()->create([ 'tenant_id' => $this->defaultTenant->id, 'assigned_to_store_id' => $this->store->id, 'status' => 'allocated', - 'replacement_for_id' => $qr->id + 'replacement_for_id' => $qr->id, ]); $this->actingAs($this->admin) @@ -130,7 +130,7 @@ class PartnerStoreSettlementTest extends TestCase StoreSale::factory()->create([ 'store_id' => $this->store->id, 'retail_price_centavos' => 10000, - 'commission_centavos' => 1000 + 'commission_centavos' => 1000, ]); $this->actingAs($this->admin) @@ -138,7 +138,7 @@ class PartnerStoreSettlementTest extends TestCase ->assertSuccessful() ->assertJsonFragment([ 'balance_due_pesos' => '90.00', - 'total_settled_pesos' => '0.00' + 'total_settled_pesos' => '0.00', ]); } } diff --git a/tests/Feature/Api/V1/Store/PartnerStoreTest.php b/tests/Feature/Api/V1/Store/PartnerStoreTest.php index 6babe03..cd21749 100644 --- a/tests/Feature/Api/V1/Store/PartnerStoreTest.php +++ b/tests/Feature/Api/V1/Store/PartnerStoreTest.php @@ -156,10 +156,10 @@ class PartnerStoreTest extends TestCase { Sanctum::actingAs($this->admin); $store = PartnerStore::factory()->create(['status' => 'active', 'commission_rate_percent' => 10]); - + // Issue wholesale (creates purchase) app(StoreOperations::class)->issueWholesale($store, 20, 100000); - + // Sell to household (creates sale) $household = Household::factory()->create(); app(StoreOperations::class)->sellToHousehold($store, $household, 5, 1000); @@ -193,7 +193,7 @@ class PartnerStoreTest extends TestCase 'balance_due_pesos' => '45.00', 'total_issued_codes' => 20, 'total_sold_codes' => 5, - ] + ], ]); } @@ -202,7 +202,7 @@ class PartnerStoreTest extends TestCase Sanctum::actingAs($this->admin); $store = PartnerStore::factory()->create(['status' => 'active']); app(StoreOperations::class)->issueWholesale($store, 10, 50000); - + $qrCode = QrCode::where('assigned_to_store_id', $store->id)->first(); $response = $this->postJson("/api/v1/admin/partner-stores/{$store->uuid}/report-issue", [ @@ -215,7 +215,7 @@ class PartnerStoreTest extends TestCase $this->assertEquals('voided', (string) $qrCode->fresh()->status); $this->assertNull($qrCode->fresh()->assigned_to_store_id); - + $this->assertDatabaseHas('store_inventory_adjustments', [ 'store_id' => $store->id, 'type' => 'defective', @@ -251,14 +251,14 @@ class PartnerStoreTest extends TestCase { Sanctum::actingAs($this->admin); $store = PartnerStore::factory()->create(['status' => 'active']); - + // 1. Issue (Purchase) app(StoreOperations::class)->issueWholesale($store, 50, 250000); - + // 2. Sale $household = Household::factory()->create(); app(StoreOperations::class)->sellToHousehold($store, $household, 5, 1000); - + // 3. Defective $qrCode = QrCode::where('assigned_to_store_id', $store->id)->first(); app(StoreOperations::class)->reportDefective($store, $qrCode->serial, 'Damaged', $this->admin); diff --git a/tests/Feature/Api/V1/Store/StorePortalEnhancementsTest.php b/tests/Feature/Api/V1/Store/StorePortalEnhancementsTest.php index d979a13..f4cc7d2 100644 --- a/tests/Feature/Api/V1/Store/StorePortalEnhancementsTest.php +++ b/tests/Feature/Api/V1/Store/StorePortalEnhancementsTest.php @@ -52,10 +52,10 @@ class StorePortalEnhancementsTest extends TestCase { $user1 = User::factory()->create(['role' => User::ROLE_STORE_PARTNER]); $store1 = PartnerStore::factory()->create(['owner_user_id' => $user1->id, 'tenant_id' => $user1->tenant_id]); - + $user2 = User::factory()->create(['role' => User::ROLE_STORE_PARTNER]); $store2 = PartnerStore::factory()->create(['owner_user_id' => $user2->id, 'tenant_id' => $user2->tenant_id]); - + $saleFromStore2 = StoreSale::factory()->create(['store_id' => $store2->id]); $response = $this->actingAs($user1) diff --git a/tests/Feature/Api/V1/Trip/TripTenancyTest.php b/tests/Feature/Api/V1/Trip/TripTenancyTest.php index 52e5f4e..63bbe8b 100644 --- a/tests/Feature/Api/V1/Trip/TripTenancyTest.php +++ b/tests/Feature/Api/V1/Trip/TripTenancyTest.php @@ -18,9 +18,13 @@ class TripTenancyTest extends TestCase use RefreshDatabase; private User $superAdmin; + private User $tenantAdmin; + private User $driver; + private CollectionTeam $team; + private Route $route; protected function setUp(): void